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