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