1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
46 CBttLogger* aTheLogger) |
40 CBttLogger* aTheLogger) |
47 /** |
41 /** |
48 * Constructor. |
42 * Constructor. |
49 */ |
43 */ |
50 : iObserver(aObserver), |
44 : iObserver(aObserver), |
|
45 iTheLogger(aTheLogger), |
51 iTxFlowControl(EFlowControlOff), |
46 iTxFlowControl(EFlowControlOff), |
52 iTxContextActive(ETrue), |
47 iTxContextActive(ETrue), |
53 iSendState(EIdle), |
48 iSendState(EIdle), |
54 iMaxSendQueueLen(KDefaultBufferSize), |
49 iMaxSendQueueLen(KDefaultBufferSize), |
55 iNumPacketsInSendQueue(0) |
50 iNumPacketsInSendQueue(0) |
71 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
66 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
72 } |
67 } |
73 |
68 |
74 void CBcaController::BaseConstructL() |
69 void CBcaController::BaseConstructL() |
75 { |
70 { |
76 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_BASECONSTRUCTL_1, "CBcaController::BaseConstructL"); |
71 _LOG_L1C1(_L8("CBcaController::BaseConstructL")); |
77 |
72 |
78 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
73 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
79 iIPTagHeader = new (ELeave) CIPTagHeader(); |
74 iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger); |
80 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
75 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
81 |
|
82 iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger); |
|
83 |
76 |
84 #if defined (__EABI__) |
77 #if defined (__EABI__) |
85 // Default value for queue length |
78 // Default value for queue length |
86 iMaxSendQueueLen = KMaxSendQueueLen; |
79 iMaxSendQueueLen = KMaxSendQueueLen; |
87 // Default value for Tx and Rx packet size |
80 // Default value for Tx and Rx packet size |
96 // for the emulator process is patched via the epocrawip.ini file |
89 // for the emulator process is patched via the epocrawip.ini file |
97 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxSendQueueLen",&iMaxSendQueueLen); |
90 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxSendQueueLen",&iMaxSendQueueLen); |
98 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxTxIPPacketSize",&iMaxTxPacketSize); |
91 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxTxIPPacketSize",&iMaxTxPacketSize); |
99 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize); |
92 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize); |
100 #endif |
93 #endif |
101 OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_BASECONSTRUCTL_2, "RawIp ini file %S not found. Default values will be used.", KRawIpIniFile); |
|
102 } |
94 } |
103 |
95 |
104 void CBcaController::UpdateInternalFlowFlag(TFlowControl aValue) |
96 void CBcaController::UpdateInternalFlowFlag(TFlowControl aValue) |
105 /** |
97 /** |
106 * Updates Internal Flow flag and resumes the data flow if |
98 * Updates Internal Flow flag and resumes the data flow if |
107 * necessary. |
99 * necessary. |
108 * |
100 * |
109 * @param aValue the new state of iInternalFlow |
101 * @param aValue the new state of iInternalFlow |
110 */ |
102 */ |
111 { |
103 { |
112 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_UPDATEINTERNALFLOWFLAG_1, "CBcaController::UpdateInternalFlowFlag[NewValue=%d, iSendState=%d]",aValue, iSendState); |
104 _LOG_L1C3(_L8("CBcaController::UpdateInternalFlowFlag[NewValue=%d, iSendState=%d]"), |
|
105 aValue, iSendState); |
113 |
106 |
114 if(iTxFlowControl == aValue) |
107 if(iTxFlowControl == aValue) |
115 { |
108 { |
116 // C32 Sent the same indication signal twice. Nif will ignore it. |
109 // C32 Sent the same indication signal twice. Nif will ignore it. |
117 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_UPDATEINTERNALFLOWFLAG_2, "WARNING CBcaController: Received same indication twice"); |
110 _LOG_L2C1(_L8("WARNING CBcaController: Received same indication twice")); |
118 return; |
111 return; |
119 } |
112 } |
120 |
113 |
121 // Update the flag value. |
114 // Update the flag value. |
122 iTxFlowControl = aValue; |
115 iTxFlowControl = aValue; |
144 * necessary. |
137 * necessary. |
145 * |
138 * |
146 * @param aValue the new state of iTxContextState |
139 * @param aValue the new state of iTxContextState |
147 */ |
140 */ |
148 { |
141 { |
149 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_UPDATECONTEXTSTATEFLAG_1, "CBcaController::UpdateContextStateFlag[NewValue=%d, OldValue=%d]",aValue, iTxContextActive); |
142 _LOG_L1C3(_L8("CBcaController::UpdateContextStateFlag[NewValue=%d, OldValue=%d]"), |
|
143 aValue, iTxContextActive); |
150 |
144 |
151 if(iTxContextActive == aValue) |
145 if(iTxContextActive == aValue) |
152 { |
146 { |
153 return; |
147 return; |
154 } |
148 } |
179 * to the BCA. |
173 * to the BCA. |
180 * |
174 * |
181 * @param aPdu a data packet |
175 * @param aPdu a data packet |
182 */ |
176 */ |
183 { |
177 { |
184 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_1, ">>CBcaController::Send"); |
178 _LOG_L1C1(_L8(">>CBcaController::Send")); |
185 |
179 |
186 // Check if NIF is shutting down |
180 // Check if NIF is shutting down |
187 if (iSendState == EShuttingDown) |
181 if (iSendState == EShuttingDown) |
188 { |
182 { |
189 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_2, " ERROR: Nif is shutting down"); |
183 _LOG_L2C1(_L8(" ERROR: Nif is shutting down")); |
190 |
184 |
191 aPdu.Free(); |
185 aPdu.Free(); |
192 |
186 |
193 return KErrDisconnected; |
187 return KErrDisconnected; |
194 } |
188 } |
195 |
189 |
196 // check that this packet isnt too big - If it is, we dont want to send it or |
190 // check that this packet isnt too big - If it is, we dont want to send it or |
197 // add it to our queue |
191 // add it to our queue |
198 if ((aPdu.Length() - aPdu.First()->Length()) > BcaSendBufferLength()) |
192 if ((aPdu.Length() - aPdu.First()->Length()) > BcaSendBufferLength()) |
199 { |
193 { |
200 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_3, "Packet is too large - discarding"); |
194 _LOG_L2C1(_L8("Packet is too large - discarding")); |
201 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_4, "<<CSender::Send -> Error"); |
195 _LOG_L1C1(_L8("<<CSender::Send -> Error")); |
202 |
196 |
203 aPdu.Free(); |
197 aPdu.Free(); |
204 return KErrArgument; |
198 return KErrArgument; |
205 } |
199 } |
206 |
200 |
210 { |
204 { |
211 // check that the queue isnt full NB. this check should not be needed as when the |
205 // check that the queue isnt full NB. this check should not be needed as when the |
212 // queue becomes full the IP layer shouldnt send any more packets until it is told to |
206 // queue becomes full the IP layer shouldnt send any more packets until it is told to |
213 if (!IsSendQueueFull()) |
207 if (!IsSendQueueFull()) |
214 { |
208 { |
215 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_5, " Sender busy, appending packet to queue"); |
209 _LOG_L1C1(_L8(" Sender busy, appending packet to queue")); |
216 //We know that flow control is off and context isnt suspended so can add to queue |
210 //We know that flow control is off and context isnt suspended so can add to queue |
217 AppendToSendQueue(aPdu); |
211 AppendToSendQueue(aPdu); |
218 |
212 |
219 return IsSendQueueFull() ? KStopSending : KContinueSending; |
213 return IsSendQueueFull() ? KStopSending : KContinueSending; |
220 } |
214 } |
221 |
215 |
222 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_6, " Queue is full, upper layer is still sending packets, potential memory problems."); |
216 _LOG_L1C1(_L8(" Queue is full, upper layer is still sending packets, potential memory problems.")); |
223 AppendToSendQueue(aPdu); |
217 AppendToSendQueue(aPdu); |
224 return KStopSending; |
218 return KStopSending; |
225 } |
219 } |
226 |
220 |
227 // If we have got here then a write isnt currently happening |
221 // If we have got here then a write isnt currently happening |
231 if(!IsSendQueueEmpty()) |
225 if(!IsSendQueueEmpty()) |
232 { |
226 { |
233 //make sure that we don't change the order of packets! |
227 //make sure that we don't change the order of packets! |
234 //first send what has already been lined up |
228 //first send what has already been lined up |
235 RMBufChain tmpPdu; |
229 RMBufChain tmpPdu; |
236 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_7, " Packet removed from queue to send"); |
230 _LOG_L1C1(_L8(" Packet removed from queue to send")); |
237 RemoveFromSendQueue(tmpPdu); |
231 RemoveFromSendQueue(tmpPdu); |
238 AppendToSendQueue(aPdu); |
232 AppendToSendQueue(aPdu); |
239 |
233 |
240 // Update module state |
234 // Update module state |
241 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_8, " set State to ESending"); |
235 _LOG_L2C1(_L8(" set State to ESending")); |
242 iSendState = ESending; |
236 iSendState = ESending; |
243 |
237 |
244 BcaSend(tmpPdu); |
238 BcaSend(tmpPdu); |
245 } |
239 } |
246 else |
240 else |
247 { |
241 { |
248 // Update module state |
242 // Update module state |
249 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_9, " set State to ESending"); |
243 _LOG_L2C1(_L8(" set State to ESending")); |
250 iSendState = ESending; |
244 iSendState = ESending; |
251 |
245 |
252 BcaSend(aPdu); |
246 BcaSend(aPdu); |
253 } |
247 } |
254 |
248 |
255 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SEND_10, "<<CBcaController::Send - return StopSending/ContinueSending"); |
249 _LOG_L2C1(_L8("<<CBcaController::Send - return StopSending/ContinueSending")); |
256 return IsSendQueueFull() ? KStopSending : KContinueSending; |
250 return IsSendQueueFull() ? KStopSending : KContinueSending; |
257 } |
251 } |
258 |
252 |
259 void CBcaController::SendComplete() |
253 void CBcaController::SendComplete() |
260 /** |
254 /** |
261 * This method is called after a packet was sent to the board. |
255 * This method is called after a packet was sent to the board. |
262 * If allowed by flow contol flags the NIF can signal the TCP/IP |
256 * If allowed by flow contol flags the NIF can signal the TCP/IP |
263 * protocol indicating that is available to send more packets. |
257 * protocol indicating that is available to send more packets. |
264 */ |
258 */ |
265 { |
259 { |
266 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SENDCOMPLETE_1, "CBcaController::SendComplete"); |
260 _LOG_L1C1(_L8("CBcaController::SendComplete")); |
267 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SENDCOMPLETE_2, " set State to EIdle"); |
261 _LOG_L2C1(_L8(" set State to EIdle")); |
268 |
262 |
269 iSendState = EIdle; |
263 iSendState = EIdle; |
270 |
264 |
271 if (IsTxPossible()) |
265 if (IsTxPossible()) |
272 ResumeSending(); |
266 ResumeSending(); |
277 * This method returns ETrue if both TX flags are set to ETrue |
271 * This method returns ETrue if both TX flags are set to ETrue |
278 * |
272 * |
279 * @return The Flow control state |
273 * @return The Flow control state |
280 */ |
274 */ |
281 { |
275 { |
282 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_ISTXPOSSIBLE_1, "CBcaController::IsTxPossible (contextActive %d, flowcontrol %d)", iTxContextActive, iTxFlowControl); |
276 _LOG_L1C3(_L8("CBcaController::IsTxPossible (contextActive %d, flowcontrol %d)"), |
|
277 iTxContextActive, iTxFlowControl); |
283 |
278 |
284 if(iTxContextActive && (iTxFlowControl == EFlowControlOff)) |
279 if(iTxContextActive && (iTxFlowControl == EFlowControlOff)) |
285 return ETrue; |
280 return ETrue; |
286 else |
281 else |
287 return EFalse; |
282 return EFalse; |
292 * This method will pass on the received data to CBttNifMain. |
287 * This method will pass on the received data to CBttNifMain. |
293 * |
288 * |
294 * @param aPdu a data packet |
289 * @param aPdu a data packet |
295 */ |
290 */ |
296 { |
291 { |
297 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_PROCESS_1, ">>CBcaController::Process"); |
292 _LOG_L1C1(_L8(">>CBcaController::Process")); |
298 |
293 |
299 TInt ret; |
294 TInt ret; |
300 |
295 |
301 // Create a packet object. |
296 // Create a packet object. |
302 RMBufPacket packet; |
297 RMBufPacket packet; |
303 TRAP(ret, packet.CreateL(aPdu)); |
298 TRAP(ret, packet.CreateL(aPdu)); |
304 if (ret != KErrNone) |
299 if (ret != KErrNone) |
305 { |
300 { |
306 // Couldn't create package. Packet will be ignored... |
301 // Couldn't create package. Packet will be ignored... |
307 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_PROCESS_2, "<<CBcaController::Process couldn't create MBuf [ret=%d]", ret); |
302 _LOG_L1C2(_L8("<<CBcaController::Process couldn't create MBuf [ret=%d]"), ret); |
308 return; |
303 return; |
309 } |
304 } |
310 else |
305 else |
311 // Package created... |
306 // Package created... |
312 { |
307 { |
319 packet.Pack(); |
314 packet.Pack(); |
320 // Process the packet |
315 // Process the packet |
321 GetObserver().Process(packet, protocolCode); |
316 GetObserver().Process(packet, protocolCode); |
322 } |
317 } |
323 |
318 |
324 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_PROCESS_3, "<<CBcaController::Process"); |
319 _LOG_L1C1(_L8("<<CBcaController::Process")); |
325 } |
320 } |
326 |
321 |
327 void CBcaController::ResumeSending() |
322 void CBcaController::ResumeSending() |
328 /** |
323 /** |
329 * Used to indicate to the TCP/IP protocol layer that the NIF is ready to |
324 * Used to indicate to the TCP/IP protocol layer that the NIF is ready to |
330 * process more packets. |
325 * process more packets. |
331 */ |
326 */ |
332 { |
327 { |
333 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RESUMESENDING_1, "CBcaIoController::ResumeSending"); |
328 _LOG_L1C1(_L8("CBcaIoController::ResumeSending")); |
334 |
329 |
335 // If there are still some packets in the queue to be sent, then carry |
330 // If there are still some packets in the queue to be sent, then carry |
336 // on sending them. |
331 // on sending them. |
337 // NB. we only want to send more packets from the queue if we are currently EIdle |
332 // NB. we only want to send more packets from the queue if we are currently EIdle |
338 if (iSendState == EIdle) |
333 if (iSendState == EIdle) |
339 { |
334 { |
340 if(!IsSendQueueEmpty()) |
335 if(!IsSendQueueEmpty()) |
341 { |
336 { |
342 RMBufChain tmpPdu; |
337 RMBufChain tmpPdu; |
343 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RESUMESENDING_2, " Packet removed from queue to send"); |
338 _LOG_L1C1(_L8(" Packet removed from queue to send")); |
344 RemoveFromSendQueue(tmpPdu); |
339 RemoveFromSendQueue(tmpPdu); |
345 |
340 |
346 // Update module state |
341 // Update module state |
347 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RESUMESENDING_3, " set State to ESending"); |
342 _LOG_L2C1(_L8(" set State to ESending")); |
348 iSendState = ESending; |
343 iSendState = ESending; |
349 |
344 |
350 BcaSend(tmpPdu); |
345 BcaSend(tmpPdu); |
351 } |
346 } |
352 if(iFullQueueFlag && IsSendQueueEmpty()) |
347 if(iFullQueueFlag && IsSendQueueEmpty()) |
361 void CBcaController::SetType(TUint16 aType) |
356 void CBcaController::SetType(TUint16 aType) |
362 { |
357 { |
363 /** |
358 /** |
364 * Used to specify the type of the IP header. |
359 * Used to specify the type of the IP header. |
365 */ |
360 */ |
366 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_SETTYPE_1, "CBcaController::SetType"); |
361 _LOG_L1C1(_L8("CBcaController::SetType")); |
367 |
362 |
368 iIPTagHeader->SetType(aType); |
363 iIPTagHeader->SetType(aType); |
369 } |
364 } |
370 |
365 |
371 void CBcaController::AddHeader(TDes8& aDes) |
366 void CBcaController::AddHeader(TDes8& aDes) |
372 /** |
367 /** |
373 * Used to add the IP header to the packet before sending to the BCA. |
368 * Used to add the IP header to the packet before sending to the BCA. |
374 */ |
369 */ |
375 { |
370 { |
376 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_ADDHEADER_1, "CBcaController::AddHeader"); |
371 _LOG_L1C1(_L8("CBcaController::AddHeader")); |
377 |
372 |
378 iIPTagHeader->AddHeader(aDes); |
373 iIPTagHeader->AddHeader(aDes); |
379 } |
374 } |
380 |
375 |
381 TUint16 CBcaController::RemoveHeader(RMBufChain& aPdu) |
376 TUint16 CBcaController::RemoveHeader(RMBufChain& aPdu) |
383 * Used to remove the IP header from the received the packet before sending to the |
378 * Used to remove the IP header from the received the packet before sending to the |
384 * TCP/IP layer. |
379 * TCP/IP layer. |
385 * @return The IP header that has been removed from the packet |
380 * @return The IP header that has been removed from the packet |
386 */ |
381 */ |
387 { |
382 { |
388 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_REMOVEHEADER_1, "CBcaController::RemoveHeader"); |
383 _LOG_L1C1(_L8("CBcaController::RemoveHeader")); |
389 |
384 |
390 return (iIPTagHeader->RemoveHeader(aPdu)); |
385 return (iIPTagHeader->RemoveHeader(aPdu)); |
391 } |
386 } |
392 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
387 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
393 |
388 |