24
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Implements the interface to Bca & flow control.
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include <e32uid.h>
|
|
23 |
#include <nifmbuf.h>
|
|
24 |
#include <es_ini.h>
|
|
25 |
#include <e32svr.h>
|
|
26 |
#include <u32hal.h>
|
|
27 |
#include "BcaController.h"
|
|
28 |
|
|
29 |
//In order not to flow off SPUD everytime we set the default to 1
|
|
30 |
const TUint KDefaultBufferSize=1;
|
|
31 |
|
|
32 |
#ifdef __EABI__
|
|
33 |
// Patch data is used and KMaxTxIPPacketSize and KMaxRxIPPacketSize can be modified to a different value in RawIpNif.iby file
|
|
34 |
extern const TInt KMaxSendQueueLen = KDefaultBufferSize;
|
|
35 |
extern const TInt KMaxTxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
36 |
extern const TInt KMaxRxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
37 |
#endif
|
|
38 |
|
|
39 |
CBcaController::CBcaController(MControllerObserver& aObserver,
|
|
40 |
CBttLogger* aTheLogger)
|
|
41 |
/**
|
|
42 |
* Constructor.
|
|
43 |
*/
|
|
44 |
: iObserver(aObserver),
|
|
45 |
iTheLogger(aTheLogger),
|
|
46 |
iTxFlowControl(EFlowControlOff),
|
|
47 |
iTxContextActive(ETrue),
|
|
48 |
iSendState(EIdle),
|
|
49 |
iMaxSendQueueLen(KDefaultBufferSize),
|
|
50 |
iNumPacketsInSendQueue(0)
|
|
51 |
{
|
|
52 |
iSendQueue.Init();
|
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
CBcaController::~CBcaController()
|
|
57 |
/**
|
|
58 |
* Destructor.
|
|
59 |
*/
|
|
60 |
{
|
|
61 |
iSendQueue.Free();
|
|
62 |
iNumPacketsInSendQueue = 0;
|
|
63 |
|
|
64 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
65 |
delete iIPTagHeader;
|
|
66 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
67 |
}
|
|
68 |
|
|
69 |
void CBcaController::BaseConstructL()
|
|
70 |
{
|
|
71 |
_LOG_L1C1(_L8("CBcaController::BaseConstructL"));
|
|
72 |
|
|
73 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
74 |
iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger);
|
|
75 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
76 |
|
|
77 |
#if defined (__EABI__)
|
|
78 |
// Default value for queue length
|
|
79 |
iMaxSendQueueLen = KMaxSendQueueLen;
|
|
80 |
// Default value for Tx and Rx packet size
|
|
81 |
iMaxTxPacketSize = KMaxTxIPPacketSize;
|
|
82 |
iMaxRxPacketSize = KMaxRxIPPacketSize;
|
|
83 |
#else // WINS
|
|
84 |
// Set default values in case patch is not present in epocrawip.ini
|
|
85 |
iMaxSendQueueLen = KDefaultBufferSize;
|
|
86 |
iMaxTxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
87 |
iMaxRxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
88 |
|
|
89 |
// for the emulator process is patched via the epocrawip.ini file
|
|
90 |
UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxSendQueueLen",&iMaxSendQueueLen);
|
|
91 |
UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxTxIPPacketSize",&iMaxTxPacketSize);
|
|
92 |
UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize);
|
|
93 |
#endif
|
|
94 |
}
|
|
95 |
|
|
96 |
void CBcaController::UpdateInternalFlowFlag(TFlowControl aValue)
|
|
97 |
/**
|
|
98 |
* Updates Internal Flow flag and resumes the data flow if
|
|
99 |
* necessary.
|
|
100 |
*
|
|
101 |
* @param aValue the new state of iInternalFlow
|
|
102 |
*/
|
|
103 |
{
|
|
104 |
_LOG_L1C3(_L8("CBcaController::UpdateInternalFlowFlag[NewValue=%d, iSendState=%d]"),
|
|
105 |
aValue, iSendState);
|
|
106 |
|
|
107 |
if(iTxFlowControl == aValue)
|
|
108 |
{
|
|
109 |
// C32 Sent the same indication signal twice. Nif will ignore it.
|
|
110 |
_LOG_L2C1(_L8("WARNING CBcaController: Received same indication twice"));
|
|
111 |
return;
|
|
112 |
}
|
|
113 |
|
|
114 |
// Update the flag value.
|
|
115 |
iTxFlowControl = aValue;
|
|
116 |
|
|
117 |
if(iTxFlowControl == EFlowControlOff)
|
|
118 |
{
|
|
119 |
// If the indication received turned flow control off...
|
|
120 |
if (IsTxPossible() && (iSendState == EIdle))
|
|
121 |
{
|
|
122 |
// ... if the NIF is in the EWaiting state
|
|
123 |
// then the data flow can be resumed.
|
|
124 |
ResumeSending();
|
|
125 |
}
|
|
126 |
}
|
|
127 |
else
|
|
128 |
{
|
|
129 |
// if the Flow Control is on we can remove all queued write requests
|
|
130 |
EmptySendQueue();
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
void CBcaController::UpdateContextStateFlag(TBool aValue)
|
|
135 |
/**
|
|
136 |
* Updates Context State flag and resumes the data flow if
|
|
137 |
* necessary.
|
|
138 |
*
|
|
139 |
* @param aValue the new state of iTxContextState
|
|
140 |
*/
|
|
141 |
{
|
|
142 |
_LOG_L1C3(_L8("CBcaController::UpdateContextStateFlag[NewValue=%d, OldValue=%d]"),
|
|
143 |
aValue, iTxContextActive);
|
|
144 |
|
|
145 |
if(iTxContextActive == aValue)
|
|
146 |
{
|
|
147 |
return;
|
|
148 |
}
|
|
149 |
|
|
150 |
// Update the flag value.
|
|
151 |
iTxContextActive = aValue;
|
|
152 |
|
|
153 |
if(iTxContextActive)
|
|
154 |
{
|
|
155 |
// If the PDP context is active and...
|
|
156 |
if (IsTxPossible() && (iSendState == EIdle))
|
|
157 |
{
|
|
158 |
// ... if the NIF is in the EWaiting state
|
|
159 |
// then the data flow can be resumed.
|
|
160 |
ResumeSending();
|
|
161 |
}
|
|
162 |
}
|
|
163 |
else
|
|
164 |
{
|
|
165 |
// if the PDP context is suspended we can remove all queued write requests
|
|
166 |
EmptySendQueue();
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
TInt CBcaController::Send(RMBufChain& aPdu)
|
|
171 |
/**
|
|
172 |
* This method is called by CRawIPNifMain in order to send a packet down
|
|
173 |
* to the BCA.
|
|
174 |
*
|
|
175 |
* @param aPdu a data packet
|
|
176 |
*/
|
|
177 |
{
|
|
178 |
_LOG_L1C1(_L8(">>CBcaController::Send"));
|
|
179 |
|
|
180 |
// Check if NIF is shutting down
|
|
181 |
if (iSendState == EShuttingDown)
|
|
182 |
{
|
|
183 |
_LOG_L2C1(_L8(" ERROR: Nif is shutting down"));
|
|
184 |
|
|
185 |
aPdu.Free();
|
|
186 |
|
|
187 |
return KErrDisconnected;
|
|
188 |
}
|
|
189 |
|
|
190 |
// check that this packet isnt too big - If it is, we dont want to send it or
|
|
191 |
// add it to our queue
|
|
192 |
if ((aPdu.Length() - aPdu.First()->Length()) > BcaSendBufferLength())
|
|
193 |
{
|
|
194 |
_LOG_L2C1(_L8("Packet is too large - discarding"));
|
|
195 |
_LOG_L1C1(_L8("<<CSender::Send -> Error"));
|
|
196 |
|
|
197 |
aPdu.Free();
|
|
198 |
return KErrArgument;
|
|
199 |
}
|
|
200 |
|
|
201 |
if (iSendState == ESending)
|
|
202 |
// If this happens, it means that TCP/IP has sent us an IP packet
|
|
203 |
// while we're still sending the previous one.
|
|
204 |
{
|
|
205 |
// 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
|
|
207 |
if (!IsSendQueueFull())
|
|
208 |
{
|
|
209 |
_LOG_L1C1(_L8(" Sender busy, appending packet to queue"));
|
|
210 |
//We know that flow control is off and context isnt suspended so can add to queue
|
|
211 |
AppendToSendQueue(aPdu);
|
|
212 |
|
|
213 |
return IsSendQueueFull() ? KStopSending : KContinueSending;
|
|
214 |
}
|
|
215 |
|
|
216 |
_LOG_L1C1(_L8(" Queue is full, upper layer is still sending packets, potential memory problems."));
|
|
217 |
AppendToSendQueue(aPdu);
|
|
218 |
return KStopSending;
|
|
219 |
}
|
|
220 |
|
|
221 |
// If we have got here then a write isnt currently happening
|
|
222 |
// We dont need to check flow control is off and context isnt suspended as the BCA always
|
|
223 |
// has room for one packet, so send the packet
|
|
224 |
|
|
225 |
if(!IsSendQueueEmpty())
|
|
226 |
{
|
|
227 |
//make sure that we don't change the order of packets!
|
|
228 |
//first send what has already been lined up
|
|
229 |
RMBufChain tmpPdu;
|
|
230 |
_LOG_L1C1(_L8(" Packet removed from queue to send"));
|
|
231 |
RemoveFromSendQueue(tmpPdu);
|
|
232 |
AppendToSendQueue(aPdu);
|
|
233 |
|
|
234 |
// Update module state
|
|
235 |
_LOG_L2C1(_L8(" set State to ESending"));
|
|
236 |
iSendState = ESending;
|
|
237 |
|
|
238 |
BcaSend(tmpPdu);
|
|
239 |
}
|
|
240 |
else
|
|
241 |
{
|
|
242 |
// Update module state
|
|
243 |
_LOG_L2C1(_L8(" set State to ESending"));
|
|
244 |
iSendState = ESending;
|
|
245 |
|
|
246 |
BcaSend(aPdu);
|
|
247 |
}
|
|
248 |
|
|
249 |
_LOG_L2C1(_L8("<<CBcaController::Send - return StopSending/ContinueSending"));
|
|
250 |
return IsSendQueueFull() ? KStopSending : KContinueSending;
|
|
251 |
}
|
|
252 |
|
|
253 |
void CBcaController::SendComplete()
|
|
254 |
/**
|
|
255 |
* 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
|
|
257 |
* protocol indicating that is available to send more packets.
|
|
258 |
*/
|
|
259 |
{
|
|
260 |
_LOG_L1C1(_L8("CBcaController::SendComplete"));
|
|
261 |
_LOG_L2C1(_L8(" set State to EIdle"));
|
|
262 |
|
|
263 |
iSendState = EIdle;
|
|
264 |
|
|
265 |
if (IsTxPossible())
|
|
266 |
ResumeSending();
|
|
267 |
}
|
|
268 |
|
|
269 |
TBool CBcaController::IsTxPossible()
|
|
270 |
/**
|
|
271 |
* This method returns ETrue if both TX flags are set to ETrue
|
|
272 |
*
|
|
273 |
* @return The Flow control state
|
|
274 |
*/
|
|
275 |
{
|
|
276 |
_LOG_L1C3(_L8("CBcaController::IsTxPossible (contextActive %d, flowcontrol %d)"),
|
|
277 |
iTxContextActive, iTxFlowControl);
|
|
278 |
|
|
279 |
if(iTxContextActive && (iTxFlowControl == EFlowControlOff))
|
|
280 |
return ETrue;
|
|
281 |
else
|
|
282 |
return EFalse;
|
|
283 |
}
|
|
284 |
|
|
285 |
void CBcaController::Process(TDesC8& aPdu)
|
|
286 |
/**
|
|
287 |
* This method will pass on the received data to CBttNifMain.
|
|
288 |
*
|
|
289 |
* @param aPdu a data packet
|
|
290 |
*/
|
|
291 |
{
|
|
292 |
_LOG_L1C1(_L8(">>CBcaController::Process"));
|
|
293 |
|
|
294 |
TInt ret;
|
|
295 |
|
|
296 |
// Create a packet object.
|
|
297 |
RMBufPacket packet;
|
|
298 |
TRAP(ret, packet.CreateL(aPdu));
|
|
299 |
if (ret != KErrNone)
|
|
300 |
{
|
|
301 |
// Couldn't create package. Packet will be ignored...
|
|
302 |
_LOG_L1C2(_L8("<<CBcaController::Process couldn't create MBuf [ret=%d]"), ret);
|
|
303 |
return;
|
|
304 |
}
|
|
305 |
else
|
|
306 |
// Package created...
|
|
307 |
{
|
|
308 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
309 |
TUint16 protocolCode = iIPTagHeader->RemoveHeader(packet);
|
|
310 |
#else
|
|
311 |
TUint16 protocolCode = 0;
|
|
312 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
313 |
|
|
314 |
packet.Pack();
|
|
315 |
// Process the packet
|
|
316 |
GetObserver().Process(packet, protocolCode);
|
|
317 |
}
|
|
318 |
|
|
319 |
_LOG_L1C1(_L8("<<CBcaController::Process"));
|
|
320 |
}
|
|
321 |
|
|
322 |
void CBcaController::ResumeSending()
|
|
323 |
/**
|
|
324 |
* Used to indicate to the TCP/IP protocol layer that the NIF is ready to
|
|
325 |
* process more packets.
|
|
326 |
*/
|
|
327 |
{
|
|
328 |
_LOG_L1C1(_L8("CBcaIoController::ResumeSending"));
|
|
329 |
|
|
330 |
// If there are still some packets in the queue to be sent, then carry
|
|
331 |
// on sending them.
|
|
332 |
// NB. we only want to send more packets from the queue if we are currently EIdle
|
|
333 |
if (iSendState == EIdle)
|
|
334 |
{
|
|
335 |
if(!IsSendQueueEmpty())
|
|
336 |
{
|
|
337 |
RMBufChain tmpPdu;
|
|
338 |
_LOG_L1C1(_L8(" Packet removed from queue to send"));
|
|
339 |
RemoveFromSendQueue(tmpPdu);
|
|
340 |
|
|
341 |
// Update module state
|
|
342 |
_LOG_L2C1(_L8(" set State to ESending"));
|
|
343 |
iSendState = ESending;
|
|
344 |
|
|
345 |
BcaSend(tmpPdu);
|
|
346 |
}
|
|
347 |
if(iFullQueueFlag && IsSendQueueEmpty())
|
|
348 |
{
|
|
349 |
iObserver.ResumeSending();
|
|
350 |
}
|
|
351 |
}
|
|
352 |
// if iSendState = ESending - do nothing
|
|
353 |
}
|
|
354 |
|
|
355 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
356 |
void CBcaController::SetType(TUint16 aType)
|
|
357 |
{
|
|
358 |
/**
|
|
359 |
* Used to specify the type of the IP header.
|
|
360 |
*/
|
|
361 |
_LOG_L1C1(_L8("CBcaController::SetType"));
|
|
362 |
|
|
363 |
iIPTagHeader->SetType(aType);
|
|
364 |
}
|
|
365 |
|
|
366 |
void CBcaController::AddHeader(TDes8& aDes)
|
|
367 |
/**
|
|
368 |
* Used to add the IP header to the packet before sending to the BCA.
|
|
369 |
*/
|
|
370 |
{
|
|
371 |
_LOG_L1C1(_L8("CBcaController::AddHeader"));
|
|
372 |
|
|
373 |
iIPTagHeader->AddHeader(aDes);
|
|
374 |
}
|
|
375 |
|
|
376 |
TUint16 CBcaController::RemoveHeader(RMBufChain& aPdu)
|
|
377 |
/**
|
|
378 |
* Used to remove the IP header from the received the packet before sending to the
|
|
379 |
* TCP/IP layer.
|
|
380 |
* @return The IP header that has been removed from the packet
|
|
381 |
*/
|
|
382 |
{
|
|
383 |
_LOG_L1C1(_L8("CBcaController::RemoveHeader"));
|
|
384 |
|
|
385 |
return (iIPTagHeader->RemoveHeader(aPdu));
|
|
386 |
}
|
|
387 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
388 |
|
|
389 |
TBool CBcaController::IsSendQueueEmpty()
|
|
390 |
/**
|
|
391 |
* Indicator of whether the BufferQueue is empty
|
|
392 |
* @return TBool. ETrue if bufferQueue is emtpy, EFalse if queue is not empty
|
|
393 |
*/
|
|
394 |
{
|
|
395 |
return iSendQueue.IsEmpty();
|
|
396 |
}
|
|
397 |
|
|
398 |
TBool CBcaController::IsSendQueueFull()
|
|
399 |
/**
|
|
400 |
* Indicator of whether the BufferQueue is full
|
|
401 |
* @return TBool. ETrue if bufferQueue is full, EFalse if queue is not full
|
|
402 |
*/
|
|
403 |
{
|
|
404 |
iFullQueueFlag = iNumPacketsInSendQueue >= iMaxSendQueueLen;
|
|
405 |
return iFullQueueFlag;
|
|
406 |
}
|
|
407 |
|
|
408 |
void CBcaController::AppendToSendQueue(RMBufChain& aPdu)
|
|
409 |
/**
|
|
410 |
* Appends the packet aPdu to the queue.
|
|
411 |
* Increments the packet count. Doesn't do error checking.
|
|
412 |
* @param aChain buffer chain to be added
|
|
413 |
*/
|
|
414 |
{
|
|
415 |
iSendQueue.Append(aPdu);
|
|
416 |
iNumPacketsInSendQueue++;
|
|
417 |
}
|
|
418 |
|
|
419 |
TBool CBcaController::RemoveFromSendQueue(RMBufChain& aPdu)
|
|
420 |
/**
|
|
421 |
* Removes the packet aPdu from the queue.
|
|
422 |
* Decrements the packet count.
|
|
423 |
* @param aChain buffer chain to be added
|
|
424 |
* @return False if chain is empty
|
|
425 |
*/
|
|
426 |
{
|
|
427 |
TBool ret = iSendQueue.Remove(aPdu);
|
|
428 |
if(ret)
|
|
429 |
{
|
|
430 |
iNumPacketsInSendQueue--;
|
|
431 |
}
|
|
432 |
return ret;
|
|
433 |
}
|
|
434 |
|
|
435 |
void CBcaController::EmptySendQueue()
|
|
436 |
/**
|
|
437 |
* Removes all the packets from the send queue. Initializes the
|
|
438 |
* send queue and sets the packet count to 0.
|
|
439 |
*/
|
|
440 |
{
|
|
441 |
iSendQueue.Free();
|
|
442 |
iSendQueue.Init();
|
|
443 |
iNumPacketsInSendQueue = 0;
|
|
444 |
}
|