42 extern const TInt KMaxSendQueueLen = KDefaultSendQueueSize; |
36 extern const TInt KMaxSendQueueLen = KDefaultSendQueueSize; |
43 extern const TInt KMaxTxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength; |
37 extern const TInt KMaxTxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength; |
44 extern const TInt KMaxRxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength; |
38 extern const TInt KMaxRxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength; |
45 #endif |
39 #endif |
46 |
40 |
47 CBcaIoController::CBcaIoController(MControllerObserver& aObserver) |
41 CBcaIoController::CBcaIoController(MControllerObserver& aObserver, |
|
42 CBttLogger* aTheLogger) |
48 /** |
43 /** |
49 * Constructor. |
44 * Constructor. |
50 * |
45 * |
51 * @param aObserver Reference to the observer of this state machine |
46 * @param aObserver Reference to the observer of this state machine |
52 */ |
47 * @param aTheLogger The logging object |
53 : iSendState(EIdle), |
48 */ |
|
49 : iTheLogger(aTheLogger), |
|
50 iSendState(EIdle), |
54 iFlowBlocked(EFalse), |
51 iFlowBlocked(EFalse), |
55 iNumPacketsInSendQueue(0), |
52 iNumPacketsInSendQueue(0), |
56 iObserver(aObserver), |
53 iObserver(aObserver), |
57 iMBca(NULL), |
54 iMBca(NULL), |
58 iSender(NULL), |
55 iSender(NULL), |
59 iReceiver(NULL), |
56 iReceiver(NULL), |
60 iLoader(NULL) |
57 iLoader(NULL) |
61 { |
58 { |
62 } |
59 } |
63 |
60 |
64 CBcaIoController* CBcaIoController::NewL(MControllerObserver& aObserver) |
61 CBcaIoController* CBcaIoController::NewL(MControllerObserver& aObserver, CBttLogger* aTheLogger) |
65 /** |
62 /** |
66 * Two-phase constructor. Creates a new CBcaIoController object, performs |
63 * Two-phase constructor. Creates a new CBcaIoController object, performs |
67 * second-phase construction, then returns it. |
64 * second-phase construction, then returns it. |
68 * |
65 * |
69 * @param aObserver The observer, to which events will be reported |
66 * @param aObserver The observer, to which events will be reported |
|
67 * @param aTheLogger The logging object |
70 * @return A newly constructed CBcaIoController object |
68 * @return A newly constructed CBcaIoController object |
71 */ |
69 */ |
72 { |
70 { |
73 CBcaIoController* self = new (ELeave) CBcaIoController(aObserver); |
71 CBcaIoController* self = new (ELeave) CBcaIoController(aObserver, aTheLogger); |
74 CleanupStack::PushL(self); |
72 CleanupStack::PushL(self); |
75 self->ConstructL(); |
73 self->ConstructL(); |
76 CleanupStack::Pop(self); |
74 CleanupStack::Pop(self); |
77 return self; |
75 return self; |
78 } |
76 } |
79 |
77 |
80 void CBcaIoController::ConstructL() |
78 void CBcaIoController::ConstructL() |
81 /** |
79 /** |
82 * Second-phase constructor. Creates all the state objects it owns. |
80 * Second-phase constructor. Creates all the state objects it owns. |
83 */ |
81 */ |
84 { |
82 { |
85 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_CONSTRUCTL_1, "CBcaIoController::ConstructL"); |
83 _LOG_L1C1(_L8("CBcaIoController::ConstructL")); |
86 |
84 |
87 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
85 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
88 iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger); |
86 iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger); |
89 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
87 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
90 |
88 |
106 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize); |
104 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize); |
107 #endif |
105 #endif |
108 |
106 |
109 // end note |
107 // end note |
110 |
108 |
111 iSender = CSender::NewL(*this, iMaxTxPacketSize); |
109 iSender = CSender::NewL(*this, iTheLogger, iMaxTxPacketSize); |
112 iReceiver = CReceiver::NewL(*this, iMaxRxPacketSize); |
110 iReceiver = CReceiver::NewL(*this, iTheLogger, iMaxRxPacketSize); |
113 iLoader = new (ELeave) CBcaControl(*this); |
111 iLoader = new (ELeave) CBcaControl(*this, iTheLogger); |
114 } |
112 } |
115 |
|
116 |
113 |
117 |
114 |
118 CBcaIoController::~CBcaIoController() |
115 CBcaIoController::~CBcaIoController() |
119 /** |
116 /** |
120 * Destructor. |
117 * Destructor. |
158 * Used to shutdown this module. This will cancel all the outstanding |
155 * Used to shutdown this module. This will cancel all the outstanding |
159 * requests on the active objects owned by this module and shutdown. |
156 * requests on the active objects owned by this module and shutdown. |
160 * @param aError the passed in error code as to why Stop has been called |
157 * @param aError the passed in error code as to why Stop has been called |
161 */ |
158 */ |
162 { |
159 { |
163 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_STOP_1, "CBcaIoController::Stop is called."); |
160 _LOG_L1C1(_L8("CBcaIoController::Stop is called.")); |
164 |
161 |
165 //Stop all the active objects |
162 //Stop all the active objects |
166 iReceiver->Cancel(); |
163 iReceiver->Cancel(); |
167 |
164 |
168 if (iSendState == ESending) |
165 if (iSendState == ESending) |
183 * to the BCA. |
180 * to the BCA. |
184 * |
181 * |
185 * @param aPdu a data packet |
182 * @param aPdu a data packet |
186 */ |
183 */ |
187 { |
184 { |
188 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_1, "<<CBcaIoController::Send"); |
185 _LOG_L1C1(_L8(">>CBcaIoController::Send")); |
189 |
186 |
190 // Check if flow is shutting down |
187 // Check if flow is shutting down |
191 if (iSendState == EShuttingDown) |
188 if (iSendState == EShuttingDown) |
192 { |
189 { |
193 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_2, " ERROR: Nif is shutting down"); |
190 _LOG_L2C1(_L8(" ERROR: Nif is shutting down")); |
194 |
191 |
195 // when the flow is destroyed the memory for this packet will be |
192 // when the flow is destroyed the memory for this packet will be |
196 // cleaned up - just tell the layers above to stop sending. |
193 // cleaned up - just tell the layers above to stop sending. |
197 aPdu.Free(); |
194 aPdu.Free(); |
198 |
195 |
201 |
198 |
202 // check that this packet isnt too big - If it is, we dont want to send it or |
199 // check that this packet isnt too big - If it is, we dont want to send it or |
203 // add it to our queue |
200 // add it to our queue |
204 if ((aPdu.Length() - aPdu.First()->Length()) > iMaxTxPacketSize) |
201 if ((aPdu.Length() - aPdu.First()->Length()) > iMaxTxPacketSize) |
205 { |
202 { |
206 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_3, "Packet is too large - discarding"); |
203 _LOG_L2C1(_L8("Packet is too large - discarding")); |
207 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_4, "<<CSender::Send -> Error"); |
204 _LOG_L1C1(_L8("<<CSender::Send -> Error")); |
208 |
205 |
209 // in debug panic - this should not happen, MTU on the uplink should |
206 // in debug panic - this should not happen, MTU on the uplink should |
210 // be strictly enforced |
207 // be strictly enforced |
211 __ASSERT_DEBUG(ETrue,Panic(KFlowInvalidULPacketSize)); |
208 __ASSERT_DEBUG(ETrue,Panic(KFlowInvalidULPacketSize)); |
212 |
209 |
213 aPdu.Free(); |
210 aPdu.Free(); |
214 |
211 |
215 // may be counter intuitive, however the only options here are either |
212 // may be counter intuitive, however the only options here are either |
216 // send accepted or blocked (MLowerDataSender). |
213 // send accepted or blocked (MLowerDataSender). |
217 |
214 |
218 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_5, "<<CBcaIoController::Send - return ContinueSending"); |
215 _LOG_L2C1(_L8("<<CBcaIoController::Send - return ContinueSending")); |
219 return ESock::MLowerDataSender::ESendAccepted; |
216 return ESock::MLowerDataSender::ESendAccepted; |
220 } |
217 } |
221 |
218 |
222 // transmit flow control. |
219 // transmit flow control. |
223 if (iFlowBlocked) |
220 if (iFlowBlocked) |
224 { |
221 { |
225 // Transmit is off for this flow - we must have received a block |
222 // Transmit is off for this flow - we must have received a block |
226 // message from our control. append this message to the queue |
223 // message from our control. append this message to the queue |
227 // and tell the layer above it to kindly stop sending. |
224 // and tell the layer above it to kindly stop sending. |
228 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_6, " Sender blocked, appending packet to queue"); |
225 _LOG_L1C1(_L8(" Sender blocked, appending packet to queue")); |
229 |
226 |
230 AppendToSendQueue(aPdu); |
227 AppendToSendQueue(aPdu); |
231 |
228 |
232 // may be a bit counter-intuitive, however, even if the flow is blocked |
229 // may be a bit counter-intuitive, however, even if the flow is blocked |
233 // there is no reason not to ask for more data as long as our send |
230 // there is no reason not to ask for more data as long as our send |
234 // queue isn't full. |
231 // queue isn't full. |
235 |
232 |
236 if (IsSendQueueFull()) |
233 if (IsSendQueueFull()) |
237 { |
234 { |
238 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_7, "<<CBcaIoController::Send - return StopSending"); |
235 _LOG_L2C1(_L8("<<CBcaIoController::Send - return StopSending")); |
239 return ESock::MLowerDataSender::ESendBlocked; |
236 return ESock::MLowerDataSender::ESendBlocked; |
240 } |
237 } |
241 else |
238 else |
242 { |
239 { |
243 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_8, "<<CBcaIoController::Send - return ContinueSending"); |
240 _LOG_L2C1(_L8("<<CBcaIoController::Send - return ContinueSending")); |
244 return ESock::MLowerDataSender::ESendAccepted; |
241 return ESock::MLowerDataSender::ESendAccepted; |
245 } |
242 } |
246 } |
243 } |
247 |
244 |
248 // transmit is on for this flow. send a packet or queue it |
245 // transmit is on for this flow. send a packet or queue it |
250 |
247 |
251 if (iSendState == ESending) |
248 if (iSendState == ESending) |
252 // If this happens, it means that TCP/IP has sent us an IP packet |
249 // If this happens, it means that TCP/IP has sent us an IP packet |
253 // while we're still sending the previous one. |
250 // while we're still sending the previous one. |
254 { |
251 { |
255 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_9, " Sender busy, appending packet to queue"); |
252 _LOG_L1C1(_L8(" Sender busy, appending packet to queue")); |
256 AppendToSendQueue(aPdu); |
253 AppendToSendQueue(aPdu); |
257 |
254 |
258 if (IsSendQueueFull()) |
255 if (IsSendQueueFull()) |
259 { |
256 { |
260 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_10, "<<CBcaIoController::Send - return StopSending"); |
257 _LOG_L2C1(_L8("<<CBcaIoController::Send - return StopSending")); |
261 return ESock::MLowerDataSender::ESendBlocked; |
258 return ESock::MLowerDataSender::ESendBlocked; |
262 } |
259 } |
263 } |
260 } |
264 else |
261 else |
265 { |
262 { |
266 // if we're idle, then we must not be sending. If we're not idle |
263 // if we're idle, then we must not be sending. If we're not idle |
267 // then the SendComplete() will handle sending any additional |
264 // then the SendComplete() will handle sending any additional |
268 // packets that might have been queued onto the send queue. |
265 // packets that might have been queued onto the send queue. |
269 |
266 |
270 // Update module state |
267 // Update module state |
271 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_11, " set State to ESending"); |
268 _LOG_L2C1(_L8(" set State to ESending")); |
272 iSendState = ESending; |
269 iSendState = ESending; |
273 |
270 |
274 iSender->Send(aPdu); |
271 iSender->Send(aPdu); |
275 } |
272 } |
276 |
273 |
277 // if our send queue isn't full, then the send is accepted |
274 // if our send queue isn't full, then the send is accepted |
278 // otherwise, block this flow until we have room for the next |
275 // otherwise, block this flow until we have room for the next |
279 // packet |
276 // packet |
280 |
277 |
281 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SEND_12, "<<CBcaIoController::Send - return ContinueSending"); |
278 _LOG_L2C1(_L8("<<CBcaIoController::Send - return ContinueSending")); |
282 |
279 |
283 return ESock::MLowerDataSender::ESendAccepted; |
280 return ESock::MLowerDataSender::ESendAccepted; |
284 } |
281 } |
285 |
282 |
286 void CBcaIoController::SendComplete() |
283 void CBcaIoController::SendComplete() |
287 /** |
284 /** |
288 * A packet has finished sending - check to see if we need |
285 * A packet has finished sending - check to see if we need |
289 * to process more packets. |
286 * to process more packets. |
290 */ |
287 */ |
291 { |
288 { |
292 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SENDCOMPLETE_1, ">>CBcaIoController::SendComplete"); |
289 _LOG_L1C1(_L8(">>CBcaIoController::SendComplete")); |
293 |
290 |
294 // if we've been blocked while in the middle of a |
291 // if we've been blocked while in the middle of a |
295 // send - don't continue sending, this will happen |
292 // send - don't continue sending, this will happen |
296 // when the flow is resumed. |
293 // when the flow is resumed. |
297 |
294 |
298 iSendState = EIdle; |
295 iSendState = EIdle; |
299 |
296 |
300 // are we available to transmit? |
297 // are we available to transmit? |
301 |
298 |
302 if (iFlowBlocked == EFalse) |
299 if (iFlowBlocked == EFalse) |
322 if ((resumeSending) || (!IsSendQueueEmpty())) |
319 if ((resumeSending) || (!IsSendQueueEmpty())) |
323 { |
320 { |
324 iSendState = ESending; |
321 iSendState = ESending; |
325 |
322 |
326 RMBufChain tmpPdu; |
323 RMBufChain tmpPdu; |
327 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SENDCOMPLETE_2, " Packet removed from queue to send"); |
324 _LOG_L1C1(_L8(" Packet removed from queue to send")); |
328 RemoveFromSendQueue(tmpPdu); |
325 RemoveFromSendQueue(tmpPdu); |
329 |
326 |
330 // Update module state |
327 // Update module state |
331 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SENDCOMPLETE_3, " set State to ESending"); |
328 _LOG_L2C1(_L8(" set State to ESending")); |
332 |
329 |
333 iSender->Send(tmpPdu); |
330 iSender->Send(tmpPdu); |
334 |
331 |
335 // if the queue was full, again, we told the upper layers |
332 // if the queue was full, again, we told the upper layers |
336 // to stop sending, we need to resume this flow. order is |
333 // to stop sending, we need to resume this flow. order is |
341 iObserver.ResumeSending(); |
338 iObserver.ResumeSending(); |
342 } |
339 } |
343 } |
340 } |
344 } |
341 } |
345 |
342 |
346 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SENDCOMPLETE_4, "<<CBcaIoController::SendComplete"); |
343 _LOG_L1C1(_L8("<<CBcaIoController::SendComplete")); |
347 } |
344 } |
348 |
345 |
349 |
346 |
350 void CBcaIoController::ResumeSending() |
347 void CBcaIoController::ResumeSending() |
351 /** |
348 /** |
352 * Flow is being unblocked this will resume sending. |
349 * Flow is being unblocked this will resume sending. |
353 */ |
350 */ |
354 { |
351 { |
355 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_RESUMESENDING_1, ">>CBcaIoController::ResumeSending"); |
352 _LOG_L1C1(_L8(">>CBcaIoController::ResumeSending")); |
356 |
353 |
357 // allows for normal SendComplete behaviour if there is |
354 // allows for normal SendComplete behaviour if there is |
358 // a packet outstanding with BCA |
355 // a packet outstanding with BCA |
359 iFlowBlocked = EFalse; |
356 iFlowBlocked = EFalse; |
360 |
357 |
379 // in the case that it is full |
376 // in the case that it is full |
380 |
377 |
381 if ((resumeSending) || (!IsSendQueueEmpty())) |
378 if ((resumeSending) || (!IsSendQueueEmpty())) |
382 { |
379 { |
383 RMBufChain tmpPdu; |
380 RMBufChain tmpPdu; |
384 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_RESUMESENDING_2, " Packet removed from queue to send"); |
381 _LOG_L1C1(_L8(" Packet removed from queue to send")); |
385 RemoveFromSendQueue(tmpPdu); |
382 RemoveFromSendQueue(tmpPdu); |
386 |
383 |
387 // Update module state |
384 // Update module state |
388 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_RESUMESENDING_3, " set State to ESending"); |
385 _LOG_L2C1(_L8(" set State to ESending")); |
389 iSendState = ESending; |
386 iSendState = ESending; |
390 |
387 |
391 iSender->Send(tmpPdu); |
388 iSender->Send(tmpPdu); |
392 |
389 |
393 // if the queue was full, again, we told the upper layers |
390 // if the queue was full, again, we told the upper layers |
399 iObserver.ResumeSending(); |
396 iObserver.ResumeSending(); |
400 } |
397 } |
401 } |
398 } |
402 } |
399 } |
403 |
400 |
404 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_RESUMESENDING_4, "<<CBcaIoController::ResumeSending"); |
401 _LOG_L1C1(_L8("<<CBcaIoController::ResumeSending")); |
405 } |
402 } |
406 |
403 |
407 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
404 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
408 void CBcaIoController::SetType(TUint16 aType) |
405 void CBcaIoController::SetType(TUint16 aType) |
409 { |
406 { |
410 /** |
407 /** |
411 * Used to specify the type of the IP header. |
408 * Used to specify the type of the IP header. |
412 */ |
409 */ |
413 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SETTYPE_1, "CBcaController::SetType"); |
410 _LOG_L1C1(_L8("CBcaController::SetType")); |
414 |
411 |
415 iIPTagHeader->SetType(aType); |
412 iIPTagHeader->SetType(aType); |
416 } |
413 } |
417 |
414 |
418 void CBcaIoController::AddHeader(TDes8& aDes) |
415 void CBcaIoController::AddHeader(TDes8& aDes) |
419 /** |
416 /** |
420 * Used to add the IP header to the packet before sending to the BCA. |
417 * Used to add the IP header to the packet before sending to the BCA. |
421 */ |
418 */ |
422 { |
419 { |
423 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_ADDHEADER_1, "CBcaController::AddHeader"); |
420 _LOG_L1C1(_L8("CBcaController::AddHeader")); |
424 |
421 |
425 iIPTagHeader->AddHeader(aDes); |
422 iIPTagHeader->AddHeader(aDes); |
426 } |
423 } |
427 |
424 |
428 TUint16 CBcaIoController::RemoveHeader(RMBufChain& aPdu) |
425 TUint16 CBcaIoController::RemoveHeader(RMBufChain& aPdu) |
430 * Used to remove the IP header from the received the packet before sending to the |
427 * Used to remove the IP header from the received the packet before sending to the |
431 * TCP/IP layer. |
428 * TCP/IP layer. |
432 * @return The IP header that has been removed from the packet |
429 * @return The IP header that has been removed from the packet |
433 */ |
430 */ |
434 { |
431 { |
435 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_REMOVEHEADER_1, "CBcaController::RemoveHeader"); |
432 _LOG_L1C1(_L8("CBcaController::RemoveHeader")); |
436 |
433 |
437 return (iIPTagHeader->RemoveHeader(aPdu)); |
434 return (iIPTagHeader->RemoveHeader(aPdu)); |
438 } |
435 } |
439 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
436 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
440 |
437 |
441 |
438 |
442 CBcaControl::CBcaControl(CBcaIoController& aObserver) |
439 CBcaControl::CBcaControl(CBcaIoController& aObserver, CBttLogger* aTheLogger) |
443 /** |
440 /** |
444 * Constructor. Performs standard active object initialisation. |
441 * Constructor. Performs standard active object initialisation. |
445 * |
442 * |
446 * @param aObserver Reference to the observer of this state machine |
443 * @param aObserver Reference to the observer of this state machine |
|
444 * @param aTheLogger The logging object |
447 */ |
445 */ |
448 : CActive(EPriorityStandard), |
446 : CActive(EPriorityStandard), |
449 iObserver(aObserver), |
447 iObserver(aObserver), |
|
448 iTheLogger(aTheLogger), |
450 iMBca(NULL), |
449 iMBca(NULL), |
451 iState(EIdling), |
450 iState(EIdling), |
452 iError(KErrNone) |
451 iError(KErrNone) |
453 |
452 |
454 { |
453 { |
478 /** |
477 /** |
479 * Called after request is completed. |
478 * Called after request is completed. |
480 * |
479 * |
481 */ |
480 */ |
482 { |
481 { |
483 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_1, "CBcaControl::RunL() called"); |
482 _LOG_L1C1(_L8("CBcaControl::RunL() called")); |
484 switch (iState) |
483 switch (iState) |
485 { |
484 { |
486 //in this state, Ioctl is called to set IAP ID, check the result of |
485 //in this state, Ioctl is called to set IAP ID, check the result of |
487 // Ioctl, then either set the BCA stack with another Ioctl call, |
486 // Ioctl, then either set the BCA stack with another Ioctl call, |
488 // open the BCA (if there's no BCA stack to set), or stop the NIF. |
487 // open the BCA (if there's no BCA stack to set), or stop the NIF. |
490 { |
489 { |
491 if(iStatus == KErrNone || iStatus == KErrNotSupported) |
490 if(iStatus == KErrNone || iStatus == KErrNotSupported) |
492 { |
491 { |
493 if(iStatus == KErrNotSupported) |
492 if(iStatus == KErrNotSupported) |
494 { |
493 { |
495 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_2, "This BCA does not support IAPID set"); |
494 _LOG_L1C1(_L8("This BCA does not support IAPID set")); |
496 } |
495 } |
497 else |
496 else |
498 { |
497 { |
499 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_3, "This BCA supports IAPID set"); |
498 _LOG_L2C1(_L8("This BCA supports IAPID set")); |
500 } |
499 } |
501 |
500 |
502 TPtrC bcaStack = iObserver.BcaStack(); |
501 TPtrC bcaStack = iObserver.BcaStack(); |
503 if(bcaStack.Length()) |
502 if(bcaStack.Length()) |
504 { |
503 { |
529 { |
528 { |
530 if(iStatus == KErrNotSupported || iStatus == KErrNone) |
529 if(iStatus == KErrNotSupported || iStatus == KErrNone) |
531 { |
530 { |
532 if(iStatus == KErrNotSupported) |
531 if(iStatus == KErrNotSupported) |
533 { |
532 { |
534 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_5, "This BCA does not support BCA stacking"); |
533 _LOG_L1C1(_L8("This BCA does not support BCA stacking")); |
535 } |
534 } |
536 else |
535 else |
537 { |
536 { |
538 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_6, "This BCA supports BCA stacking"); |
537 _LOG_L2C1(_L8("This BCA supports BCA stacking")); |
539 } |
538 } |
540 iMBca->Open(iStatus, iObserver.Port()); |
539 iMBca->Open(iStatus, iObserver.Port()); |
541 iState = EBcaStackSet; |
540 iState = EBcaStackSet; |
542 SetActive(); |
541 SetActive(); |
543 } |
542 } |
544 else |
543 else |
545 { |
544 { |
546 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_7, "ERROR in BCA stack set = %d", iStatus.Int()); |
545 _LOG_L2C2(_L8("ERROR in BCA stack set = %d"), iStatus.Int()); |
547 iObserver.Stop(iStatus.Int()); |
546 iObserver.Stop(iStatus.Int()); |
548 } |
547 } |
549 break; |
548 break; |
550 } |
549 } |
551 |
550 |
553 // If it is successful,then start the NIF. Otherwise stops the NIF. |
552 // If it is successful,then start the NIF. Otherwise stops the NIF. |
554 case EBcaStackSet: |
553 case EBcaStackSet: |
555 { |
554 { |
556 if(iStatus != KErrNone && iStatus != KErrAlreadyExists) |
555 if(iStatus != KErrNone && iStatus != KErrAlreadyExists) |
557 { |
556 { |
558 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_8, "ERROR in BCA Open = %d", iStatus.Int()); |
557 _LOG_L2C2(_L8("ERROR in BCA Open = %d"), iStatus.Int()); |
559 iObserver.Stop(iStatus.Int()); |
558 iObserver.Stop(iStatus.Int()); |
560 } |
559 } |
561 else |
560 else |
562 { |
561 { |
563 iState = EBcaOpened; |
562 iState = EBcaOpened; |
564 //Activate the receiver Active Object |
563 //Activate the receiver Active Object |
565 iObserver.Receiver().StartListening(); |
564 iObserver.Receiver().StartListening(); |
566 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_9, "CBcaIoController Is Initialised"); |
565 _LOG_L1C1(_L8("CBcaIoController Is Initialised")); |
567 TRAPD(err, iObserver.GetObserver().InitialiseL(MRawIPObserverBase::EBcaController,KErrNone)); |
566 TRAPD(err, iObserver.GetObserver().InitialiseL(MRawIPObserverBase::EBcaController,KErrNone)); |
568 if(err != KErrNone) |
567 if(err != KErrNone) |
569 { |
568 { |
570 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_10, "ERROR in BCA Open Initialise observer = %d", err); |
569 _LOG_L2C2(_L8("ERROR in BCA Open Initialise observer = %d"), err); |
571 iObserver.Stop(err); |
570 iObserver.Stop(err); |
572 } |
571 } |
573 } |
572 } |
574 break; |
573 break; |
575 } |
574 } |
614 break; |
612 break; |
615 case EClosing: |
613 case EClosing: |
616 iState = EIdling; |
614 iState = EIdling; |
617 break; |
615 break; |
618 default: |
616 default: |
619 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_3, "ERROR CBcaControl::DoCancel(): Unknown state"); |
617 _LOG_L2C1(_L8("ERROR CBcaControl::DoCancel(): Unknown state")); |
620 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_4, "PANIC: %S %d", KNifName, KBcaUnkownState); |
618 _BTT_PANIC(KNifName, KBcaUnkownState); |
621 User::Panic(KNifName, KBcaUnkownState); |
|
622 break; |
619 break; |
623 } |
620 } |
624 } |
621 } |
625 |
622 |
626 void CBcaControl::StartLoadL() |
623 void CBcaControl::StartLoadL() |
627 /** |
624 /** |
628 * This method loads the C32BCA library and uses Ioctl to set the Bca iIapId. |
625 * This method loads the C32BCA library and uses Ioctl to set the Bca iIapId. |
629 */ |
626 */ |
630 { |
627 { |
631 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_STARTLOADL_1, "CBcaControl::StartLoad"); |
628 _LOG_L1C1(_L8("CBcaControl::StartLoad")); |
632 |
629 |
633 //iMBca should not be initialized at this point |
630 //iMBca should not be initialized at this point |
634 __ASSERT_DEBUG(!iMBca,Panic(KBcaAlreadyExists)); |
631 __ASSERT_DEBUG(!iMBca,Panic(KBcaAlreadyExists)); |
635 |
632 |
636 //We don't expect iMBca here, but if it occurs, we delete previous BCA Instance |
633 //We don't expect iMBca here, but if it occurs, we delete previous BCA Instance |
648 User::LeaveIfError(iBcaDll.iObj.Load(iObserver.BcaName())); |
645 User::LeaveIfError(iBcaDll.iObj.Load(iObserver.BcaName())); |
649 |
646 |
650 TNewBcaFactoryL newBcaFactoryProcL = (TNewBcaFactoryL)iBcaDll.iObj.Lookup(1); |
647 TNewBcaFactoryL newBcaFactoryProcL = (TNewBcaFactoryL)iBcaDll.iObj.Lookup(1); |
651 if (NULL == newBcaFactoryProcL) |
648 if (NULL == newBcaFactoryProcL) |
652 { |
649 { |
653 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_STARTLOADL_2, "Library entry point found error %d", KErrBadLibraryEntryPoint); |
650 _LOG_L1C2(_L8("Library entry point found error %d"), KErrBadLibraryEntryPoint); |
654 User::Leave(KErrBadLibraryEntryPoint); |
651 User::Leave(KErrBadLibraryEntryPoint); |
655 } |
652 } |
656 |
653 |
657 MBcaFactory* bcaFactory = (*newBcaFactoryProcL)(); |
654 MBcaFactory* bcaFactory = (*newBcaFactoryProcL)(); |
658 |
655 |
659 if(!bcaFactory) |
656 if(!bcaFactory) |
660 { |
657 { |
661 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_STARTLOADL_3, "BcaFactory creation error %d", KErrCompletion); |
658 _LOG_L1C2(_L8("BcaFactory creation error %d"), KErrCompletion); |
662 User::Leave(KErrCompletion); |
659 User::Leave(KErrCompletion); |
663 } |
660 } |
664 CleanupReleasePushL(*bcaFactory); |
661 CleanupReleasePushL(*bcaFactory); |
665 |
662 |
666 iMBca = bcaFactory->NewBcaL(); |
663 iMBca = bcaFactory->NewBcaL(); |
689 //We should only call shutdown or close if we have successfully opened a BCA Channel |
686 //We should only call shutdown or close if we have successfully opened a BCA Channel |
690 if((iMBca) && (EBcaOpened == iState)) |
687 if((iMBca) && (EBcaOpened == iState)) |
691 { |
688 { |
692 if(aError == KErrConnectionTerminated ) |
689 if(aError == KErrConnectionTerminated ) |
693 { |
690 { |
694 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_SHUTDOWNBCA_1, "This is an emergency shutdown, it kills the NIF immediately."); |
691 _LOG_L1C1(_L8("This is an emergency shutdown, it kills the NIF immediately.")); |
695 // It is a emergency shutdown, it kills the NIF immediately. |
692 // It is a emergency shutdown, it kills the NIF immediately. |
696 iMBca->Close(); |
693 iMBca->Close(); |
697 iState = EIdling; |
694 iState = EIdling; |
698 iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, aError); |
695 iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, aError); |
699 } |
696 } |
700 else |
697 else |
701 { |
698 { |
702 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_SHUTDOWNBCA_2, "This is a graceful termination which takes a while."); |
699 _LOG_L1C1(_L8("This is a graceful termination which takes a while.")); |
703 //It is a graceful termination which takes a while. |
700 //It is a graceful termination which takes a while. |
704 iError = aError; |
701 iError = aError; |
705 iState = EClosing; |
702 iState = EClosing; |
706 iMBca->Shutdown(iStatus); |
703 iMBca->Shutdown(iStatus); |
707 SetActive(); |
704 SetActive(); |
708 } |
705 } |
709 } |
706 } |
710 else //nothing to shutdown, just notify linklayer down. |
707 else //nothing to shutdown, just notify linklayer down. |
711 { |
708 { |
712 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_SHUTDOWNBCA_3, "Bca is not initialized or opened, bring the linklayer down"); |
709 _LOG_L1C1(_L8("Bca is not initialized or opened, bring the linklayer down")); |
713 iState = EIdling; |
710 iState = EIdling; |
714 iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, aError); |
711 iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, aError); |
715 } |
712 } |
716 |
713 |
717 } |
714 } |