24
|
1 |
// Copyright (c) 2004-2010 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.
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file BcaIoController.cpp
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include <e32uid.h>
|
|
23 |
#include <nifmbuf.h>
|
|
24 |
#include <e32svr.h>
|
|
25 |
#include <u32hal.h>
|
|
26 |
|
|
27 |
#include "Constants.h"
|
|
28 |
#include "BcaIoController.h"
|
|
29 |
#include "Sender.h"
|
|
30 |
#include "Receiver.h"
|
|
31 |
|
|
32 |
const TUint KDefaultSendQueueSize=5;
|
|
33 |
|
|
34 |
#ifdef __EABI__
|
|
35 |
// Patch data is used and KMaxTxIPPacketSize and KMaxRxIPPacketSize can be modified to a different value in RawIpNif.iby file
|
|
36 |
extern const TInt KMaxSendQueueLen = KDefaultSendQueueSize;
|
|
37 |
extern const TInt KMaxTxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
38 |
extern const TInt KMaxRxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
39 |
#endif
|
|
40 |
|
|
41 |
CBcaIoController::CBcaIoController(MControllerObserver& aObserver,
|
|
42 |
CBttLogger* aTheLogger)
|
|
43 |
/**
|
|
44 |
* Constructor.
|
|
45 |
*
|
|
46 |
* @param aObserver Reference to the observer of this state machine
|
|
47 |
* @param aTheLogger The logging object
|
|
48 |
*/
|
|
49 |
: iTheLogger(aTheLogger),
|
|
50 |
iSendState(EIdle),
|
|
51 |
iFlowBlocked(EFalse),
|
|
52 |
iNumPacketsInSendQueue(0),
|
|
53 |
iObserver(aObserver),
|
|
54 |
iMBca(NULL),
|
|
55 |
iSender(NULL),
|
|
56 |
iReceiver(NULL),
|
|
57 |
iLoader(NULL)
|
|
58 |
{
|
|
59 |
}
|
|
60 |
|
|
61 |
CBcaIoController* CBcaIoController::NewL(MControllerObserver& aObserver, CBttLogger* aTheLogger)
|
|
62 |
/**
|
|
63 |
* Two-phase constructor. Creates a new CBcaIoController object, performs
|
|
64 |
* second-phase construction, then returns it.
|
|
65 |
*
|
|
66 |
* @param aObserver The observer, to which events will be reported
|
|
67 |
* @param aTheLogger The logging object
|
|
68 |
* @return A newly constructed CBcaIoController object
|
|
69 |
*/
|
|
70 |
{
|
|
71 |
CBcaIoController* self = new (ELeave) CBcaIoController(aObserver, aTheLogger);
|
|
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 |
|
|
85 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
86 |
iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger);
|
|
87 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
88 |
|
|
89 |
#if defined __EABI__
|
|
90 |
// Default value for queue length
|
|
91 |
iMaxSendQueueLen = KMaxSendQueueLen;
|
|
92 |
// Default value for Tx and Rx packet size
|
|
93 |
iMaxTxPacketSize = KMaxTxIPPacketSize;
|
|
94 |
iMaxRxPacketSize = KMaxRxIPPacketSize;
|
|
95 |
#else // WINS
|
|
96 |
// Set default values in case patch is not present in epocrawip.ini
|
|
97 |
iMaxSendQueueLen = KDefaultSendQueueSize;
|
|
98 |
iMaxTxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
99 |
iMaxRxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
|
|
100 |
|
|
101 |
// for the emulator process is patched via the epocrawip.ini file
|
|
102 |
UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxSendQueueLen",&iMaxSendQueueLen);
|
|
103 |
UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxTxIPPacketSize",&iMaxTxPacketSize);
|
|
104 |
UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize);
|
|
105 |
#endif
|
|
106 |
|
|
107 |
// end note
|
|
108 |
|
|
109 |
iSender = CSender::NewL(*this, iTheLogger, iMaxTxPacketSize);
|
|
110 |
iReceiver = CReceiver::NewL(*this, iTheLogger, iMaxRxPacketSize);
|
|
111 |
iLoader = new (ELeave) CBcaControl(*this, iTheLogger);
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
CBcaIoController::~CBcaIoController()
|
|
116 |
/**
|
|
117 |
* Destructor.
|
|
118 |
*/
|
|
119 |
{
|
|
120 |
iSendQueue.Free();
|
|
121 |
iNumPacketsInSendQueue = 0;
|
|
122 |
|
|
123 |
delete iReceiver;
|
|
124 |
delete iSender;
|
|
125 |
delete iLoader;
|
|
126 |
|
|
127 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
128 |
delete iIPTagHeader;
|
|
129 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
130 |
}
|
|
131 |
|
|
132 |
/** sets the BCA Stack name
|
|
133 |
|
|
134 |
* @param aBcaStack Text composed of bca stack and next bca names
|
|
135 |
*/
|
|
136 |
void CBcaIoController::SetBcaStackAndName(const TDesC& aBcaStack, const TDesC& aBcaName)
|
|
137 |
{
|
|
138 |
iBcaName.Set(aBcaName);
|
|
139 |
iBcaStack.Set(aBcaStack);
|
|
140 |
}
|
|
141 |
|
|
142 |
|
|
143 |
void CBcaIoController::StartL()
|
|
144 |
/**
|
|
145 |
* Used to kick off the initialisation for this module
|
|
146 |
*/
|
|
147 |
{
|
|
148 |
_LOG_L1C1(_L8("CBcaIoController::StartL is called."));
|
|
149 |
|
|
150 |
iLoader->StartLoadL();
|
|
151 |
}
|
|
152 |
|
|
153 |
void CBcaIoController::Stop(TInt aError)
|
|
154 |
/**
|
|
155 |
* Used to shutdown this module. This will cancel all the outstanding
|
|
156 |
* 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
|
|
158 |
*/
|
|
159 |
{
|
|
160 |
_LOG_L1C1(_L8("CBcaIoController::Stop is called."));
|
|
161 |
|
|
162 |
//Stop all the active objects
|
|
163 |
iReceiver->Cancel();
|
|
164 |
|
|
165 |
if (iSendState == ESending)
|
|
166 |
{
|
|
167 |
iSender->Cancel();
|
|
168 |
}
|
|
169 |
|
|
170 |
// Update module state
|
|
171 |
SendState(EShuttingDown);
|
|
172 |
|
|
173 |
iLoader->ShutdownBca(aError);
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
ESock::MLowerDataSender::TSendResult CBcaIoController::Send(RMBufChain& aPdu)
|
|
178 |
/**
|
|
179 |
* This method is called by CRawIPFlow in order to send a packet down
|
|
180 |
* to the BCA.
|
|
181 |
*
|
|
182 |
* @param aPdu a data packet
|
|
183 |
*/
|
|
184 |
{
|
|
185 |
_LOG_L1C1(_L8(">>CBcaIoController::Send"));
|
|
186 |
|
|
187 |
// Check if flow is shutting down
|
|
188 |
if (iSendState == EShuttingDown)
|
|
189 |
{
|
|
190 |
_LOG_L2C1(_L8(" ERROR: Nif is shutting down"));
|
|
191 |
|
|
192 |
// when the flow is destroyed the memory for this packet will be
|
|
193 |
// cleaned up - just tell the layers above to stop sending.
|
|
194 |
aPdu.Free();
|
|
195 |
|
|
196 |
return ESock::MLowerDataSender::ESendBlocked;
|
|
197 |
}
|
|
198 |
|
|
199 |
// check that this packet isnt too big - If it is, we dont want to send it or
|
|
200 |
// add it to our queue
|
|
201 |
if ((aPdu.Length() - aPdu.First()->Length()) > iMaxTxPacketSize)
|
|
202 |
{
|
|
203 |
_LOG_L2C1(_L8("Packet is too large - discarding"));
|
|
204 |
_LOG_L1C1(_L8("<<CSender::Send -> Error"));
|
|
205 |
|
|
206 |
// in debug panic - this should not happen, MTU on the uplink should
|
|
207 |
// be strictly enforced
|
|
208 |
__ASSERT_DEBUG(ETrue,Panic(KFlowInvalidULPacketSize));
|
|
209 |
|
|
210 |
aPdu.Free();
|
|
211 |
|
|
212 |
// may be counter intuitive, however the only options here are either
|
|
213 |
// send accepted or blocked (MLowerDataSender).
|
|
214 |
|
|
215 |
_LOG_L2C1(_L8("<<CBcaIoController::Send - return ContinueSending"));
|
|
216 |
return ESock::MLowerDataSender::ESendAccepted;
|
|
217 |
}
|
|
218 |
|
|
219 |
// transmit flow control.
|
|
220 |
if (iFlowBlocked)
|
|
221 |
{
|
|
222 |
// Transmit is off for this flow - we must have received a block
|
|
223 |
// message from our control. append this message to the queue
|
|
224 |
// and tell the layer above it to kindly stop sending.
|
|
225 |
_LOG_L1C1(_L8(" Sender blocked, appending packet to queue"));
|
|
226 |
|
|
227 |
AppendToSendQueue(aPdu);
|
|
228 |
|
|
229 |
// 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
|
|
231 |
// queue isn't full.
|
|
232 |
|
|
233 |
if (IsSendQueueFull())
|
|
234 |
{
|
|
235 |
_LOG_L2C1(_L8("<<CBcaIoController::Send - return StopSending"));
|
|
236 |
return ESock::MLowerDataSender::ESendBlocked;
|
|
237 |
}
|
|
238 |
else
|
|
239 |
{
|
|
240 |
_LOG_L2C1(_L8("<<CBcaIoController::Send - return ContinueSending"));
|
|
241 |
return ESock::MLowerDataSender::ESendAccepted;
|
|
242 |
}
|
|
243 |
}
|
|
244 |
|
|
245 |
// transmit is on for this flow. send a packet or queue it
|
|
246 |
// if we're already sending one.
|
|
247 |
|
|
248 |
if (iSendState == ESending)
|
|
249 |
// If this happens, it means that TCP/IP has sent us an IP packet
|
|
250 |
// while we're still sending the previous one.
|
|
251 |
{
|
|
252 |
_LOG_L1C1(_L8(" Sender busy, appending packet to queue"));
|
|
253 |
AppendToSendQueue(aPdu);
|
|
254 |
|
|
255 |
if (IsSendQueueFull())
|
|
256 |
{
|
|
257 |
_LOG_L2C1(_L8("<<CBcaIoController::Send - return StopSending"));
|
|
258 |
return ESock::MLowerDataSender::ESendBlocked;
|
|
259 |
}
|
|
260 |
}
|
|
261 |
else
|
|
262 |
{
|
|
263 |
// if we're idle, then we must not be sending. If we're not idle
|
|
264 |
// then the SendComplete() will handle sending any additional
|
|
265 |
// packets that might have been queued onto the send queue.
|
|
266 |
|
|
267 |
// Update module state
|
|
268 |
_LOG_L2C1(_L8(" set State to ESending"));
|
|
269 |
iSendState = ESending;
|
|
270 |
|
|
271 |
iSender->Send(aPdu);
|
|
272 |
}
|
|
273 |
|
|
274 |
// if our send queue isn't full, then the send is accepted
|
|
275 |
// otherwise, block this flow until we have room for the next
|
|
276 |
// packet
|
|
277 |
|
|
278 |
_LOG_L2C1(_L8("<<CBcaIoController::Send - return ContinueSending"));
|
|
279 |
|
|
280 |
return ESock::MLowerDataSender::ESendAccepted;
|
|
281 |
}
|
|
282 |
|
|
283 |
void CBcaIoController::SendComplete()
|
|
284 |
/**
|
|
285 |
* A packet has finished sending - check to see if we need
|
|
286 |
* to process more packets.
|
|
287 |
*/
|
|
288 |
{
|
|
289 |
_LOG_L1C1(_L8(">>CBcaIoController::SendComplete"));
|
|
290 |
|
|
291 |
// if we've been blocked while in the middle of a
|
|
292 |
// send - don't continue sending, this will happen
|
|
293 |
// when the flow is resumed.
|
|
294 |
|
|
295 |
iSendState = EIdle;
|
|
296 |
|
|
297 |
// are we available to transmit?
|
|
298 |
|
|
299 |
if (iFlowBlocked == EFalse)
|
|
300 |
{
|
|
301 |
// flow transmit is on
|
|
302 |
|
|
303 |
TBool resumeSending = EFalse;
|
|
304 |
|
|
305 |
// if the queue is full, it means that while a packet was
|
|
306 |
// outstanding in BCA, we've filled up our send queue and
|
|
307 |
// informed the upper layers to stop sending.
|
|
308 |
|
|
309 |
if (IsSendQueueFull())
|
|
310 |
{
|
|
311 |
resumeSending = ETrue;
|
|
312 |
}
|
|
313 |
|
|
314 |
// if the queue has anything inside it, we need to send the
|
|
315 |
// first packet in the queue. note: the resumeSending check is to
|
|
316 |
// short circuit this so we don't check the queue length twice
|
|
317 |
// in the case that it is full
|
|
318 |
|
|
319 |
if ((resumeSending) || (!IsSendQueueEmpty()))
|
|
320 |
{
|
|
321 |
iSendState = ESending;
|
|
322 |
|
|
323 |
RMBufChain tmpPdu;
|
|
324 |
_LOG_L1C1(_L8(" Packet removed from queue to send"));
|
|
325 |
RemoveFromSendQueue(tmpPdu);
|
|
326 |
|
|
327 |
// Update module state
|
|
328 |
_LOG_L2C1(_L8(" set State to ESending"));
|
|
329 |
|
|
330 |
iSender->Send(tmpPdu);
|
|
331 |
|
|
332 |
// if the queue was full, again, we told the upper layers
|
|
333 |
// to stop sending, we need to resume this flow. order is
|
|
334 |
// important as we don't want to get a packet before we've
|
|
335 |
// given one to BCA to send.
|
|
336 |
if (resumeSending)
|
|
337 |
{
|
|
338 |
iObserver.ResumeSending();
|
|
339 |
}
|
|
340 |
}
|
|
341 |
}
|
|
342 |
|
|
343 |
_LOG_L1C1(_L8("<<CBcaIoController::SendComplete"));
|
|
344 |
}
|
|
345 |
|
|
346 |
|
|
347 |
void CBcaIoController::ResumeSending()
|
|
348 |
/**
|
|
349 |
* Flow is being unblocked this will resume sending.
|
|
350 |
*/
|
|
351 |
{
|
|
352 |
_LOG_L1C1(_L8(">>CBcaIoController::ResumeSending"));
|
|
353 |
|
|
354 |
// allows for normal SendComplete behaviour if there is
|
|
355 |
// a packet outstanding with BCA
|
|
356 |
iFlowBlocked = EFalse;
|
|
357 |
|
|
358 |
// If the send state is idle, then there isn't a packet
|
|
359 |
// outstanding, check the send queue to see if there are
|
|
360 |
// packets to send.
|
|
361 |
|
|
362 |
if (iSendState == EIdle)
|
|
363 |
{
|
|
364 |
// flow transmit is on
|
|
365 |
|
|
366 |
TBool resumeSending = EFalse;
|
|
367 |
|
|
368 |
if (IsSendQueueFull())
|
|
369 |
{
|
|
370 |
resumeSending = ETrue;
|
|
371 |
}
|
|
372 |
|
|
373 |
// if the queue has anything inside it, we need to send the
|
|
374 |
// first packet in the queue. note: the resumeSending check is to
|
|
375 |
// short circuit this so we don't check the queue length twice
|
|
376 |
// in the case that it is full
|
|
377 |
|
|
378 |
if ((resumeSending) || (!IsSendQueueEmpty()))
|
|
379 |
{
|
|
380 |
RMBufChain tmpPdu;
|
|
381 |
_LOG_L1C1(_L8(" Packet removed from queue to send"));
|
|
382 |
RemoveFromSendQueue(tmpPdu);
|
|
383 |
|
|
384 |
// Update module state
|
|
385 |
_LOG_L2C1(_L8(" set State to ESending"));
|
|
386 |
iSendState = ESending;
|
|
387 |
|
|
388 |
iSender->Send(tmpPdu);
|
|
389 |
|
|
390 |
// if the queue was full, again, we told the upper layers
|
|
391 |
// to stop sending, we need to resume this flow. order is
|
|
392 |
// important as we don't want to get a packet before we've
|
|
393 |
// given one to BCA to send.
|
|
394 |
if (resumeSending)
|
|
395 |
{
|
|
396 |
iObserver.ResumeSending();
|
|
397 |
}
|
|
398 |
}
|
|
399 |
}
|
|
400 |
|
|
401 |
_LOG_L1C1(_L8("<<CBcaIoController::ResumeSending"));
|
|
402 |
}
|
|
403 |
|
|
404 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
405 |
void CBcaIoController::SetType(TUint16 aType)
|
|
406 |
{
|
|
407 |
/**
|
|
408 |
* Used to specify the type of the IP header.
|
|
409 |
*/
|
|
410 |
_LOG_L1C1(_L8("CBcaController::SetType"));
|
|
411 |
|
|
412 |
iIPTagHeader->SetType(aType);
|
|
413 |
}
|
|
414 |
|
|
415 |
void CBcaIoController::AddHeader(TDes8& aDes)
|
|
416 |
/**
|
|
417 |
* Used to add the IP header to the packet before sending to the BCA.
|
|
418 |
*/
|
|
419 |
{
|
|
420 |
_LOG_L1C1(_L8("CBcaController::AddHeader"));
|
|
421 |
|
|
422 |
iIPTagHeader->AddHeader(aDes);
|
|
423 |
}
|
|
424 |
|
|
425 |
TUint16 CBcaIoController::RemoveHeader(RMBufChain& aPdu)
|
|
426 |
/**
|
|
427 |
* Used to remove the IP header from the received the packet before sending to the
|
|
428 |
* TCP/IP layer.
|
|
429 |
* @return The IP header that has been removed from the packet
|
|
430 |
*/
|
|
431 |
{
|
|
432 |
_LOG_L1C1(_L8("CBcaController::RemoveHeader"));
|
|
433 |
|
|
434 |
return (iIPTagHeader->RemoveHeader(aPdu));
|
|
435 |
}
|
|
436 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS
|
|
437 |
|
|
438 |
|
|
439 |
CBcaControl::CBcaControl(CBcaIoController& aObserver, CBttLogger* aTheLogger)
|
|
440 |
/**
|
|
441 |
* Constructor. Performs standard active object initialisation.
|
|
442 |
*
|
|
443 |
* @param aObserver Reference to the observer of this state machine
|
|
444 |
* @param aTheLogger The logging object
|
|
445 |
*/
|
|
446 |
: CActive(EPriorityStandard),
|
|
447 |
iObserver(aObserver),
|
|
448 |
iTheLogger(aTheLogger),
|
|
449 |
iMBca(NULL),
|
|
450 |
iState(EIdling),
|
|
451 |
iError(KErrNone)
|
|
452 |
|
|
453 |
{
|
|
454 |
CActiveScheduler::Add(this);
|
|
455 |
}
|
|
456 |
|
|
457 |
CBcaControl::~CBcaControl()
|
|
458 |
/**
|
|
459 |
* Destructor.
|
|
460 |
*/
|
|
461 |
{
|
|
462 |
Cancel();
|
|
463 |
if(iMBca)
|
|
464 |
{
|
|
465 |
//If the Bca is still open, close it
|
|
466 |
if(EBcaOpened == iState)
|
|
467 |
{
|
|
468 |
iMBca->Close();
|
|
469 |
}
|
|
470 |
//delete the BCA instance
|
|
471 |
iMBca->Release();
|
|
472 |
}
|
|
473 |
// Library will be Closed when iBcaDll is destroyed.
|
|
474 |
}
|
|
475 |
|
|
476 |
void CBcaControl::RunL()
|
|
477 |
/**
|
|
478 |
* Called after request is completed.
|
|
479 |
*
|
|
480 |
*/
|
|
481 |
{
|
|
482 |
_LOG_L1C1(_L8("CBcaControl::RunL() called"));
|
|
483 |
switch (iState)
|
|
484 |
{
|
|
485 |
//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 |
// open the BCA (if there's no BCA stack to set), or stop the NIF.
|
|
488 |
case EIdling:
|
|
489 |
{
|
|
490 |
if(iStatus == KErrNone || iStatus == KErrNotSupported)
|
|
491 |
{
|
|
492 |
if(iStatus == KErrNotSupported)
|
|
493 |
{
|
|
494 |
_LOG_L1C1(_L8("This BCA does not support IAPID set"));
|
|
495 |
}
|
|
496 |
else
|
|
497 |
{
|
|
498 |
_LOG_L2C1(_L8("This BCA supports IAPID set"));
|
|
499 |
}
|
|
500 |
|
|
501 |
TPtrC bcaStack = iObserver.BcaStack();
|
|
502 |
if(bcaStack.Length())
|
|
503 |
{
|
|
504 |
TBuf8<KMaxName> remainingBcaStack8;
|
|
505 |
remainingBcaStack8.Copy(bcaStack);
|
|
506 |
iMBca->Ioctl(iStatus, KBcaOptLevelGeneric,KBCASetBcaStack,remainingBcaStack8);
|
|
507 |
}
|
|
508 |
else
|
|
509 |
{
|
|
510 |
TRequestStatus* statusPtr=&iStatus;
|
|
511 |
User::RequestComplete(statusPtr,KErrNone);
|
|
512 |
}
|
|
513 |
iState = EIAPSet;
|
|
514 |
SetActive();
|
|
515 |
}
|
|
516 |
else
|
|
517 |
{
|
|
518 |
_LOG_L1C2(_L8("ERROR in BCA IAPID set = %d"), iStatus.Int());
|
|
519 |
iObserver.Stop(iStatus.Int());
|
|
520 |
}
|
|
521 |
|
|
522 |
break;
|
|
523 |
}
|
|
524 |
|
|
525 |
//in this case, we receive the result of Ioctl call to set Bca Stack.
|
|
526 |
// Check the result of Ioctl, then Open the Bca or stop the NIF
|
|
527 |
case EIAPSet:
|
|
528 |
{
|
|
529 |
if(iStatus == KErrNotSupported || iStatus == KErrNone)
|
|
530 |
{
|
|
531 |
if(iStatus == KErrNotSupported)
|
|
532 |
{
|
|
533 |
_LOG_L1C1(_L8("This BCA does not support BCA stacking"));
|
|
534 |
}
|
|
535 |
else
|
|
536 |
{
|
|
537 |
_LOG_L2C1(_L8("This BCA supports BCA stacking"));
|
|
538 |
}
|
|
539 |
iMBca->Open(iStatus, iObserver.Port());
|
|
540 |
iState = EBcaStackSet;
|
|
541 |
SetActive();
|
|
542 |
}
|
|
543 |
else
|
|
544 |
{
|
|
545 |
_LOG_L2C2(_L8("ERROR in BCA stack set = %d"), iStatus.Int());
|
|
546 |
iObserver.Stop(iStatus.Int());
|
|
547 |
}
|
|
548 |
break;
|
|
549 |
}
|
|
550 |
|
|
551 |
//in this state, BCA Open is called. Checks the result of Open.
|
|
552 |
// If it is successful,then start the NIF. Otherwise stops the NIF.
|
|
553 |
case EBcaStackSet:
|
|
554 |
{
|
|
555 |
if(iStatus != KErrNone && iStatus != KErrAlreadyExists)
|
|
556 |
{
|
|
557 |
_LOG_L2C2(_L8("ERROR in BCA Open = %d"), iStatus.Int());
|
|
558 |
iObserver.Stop(iStatus.Int());
|
|
559 |
}
|
|
560 |
else
|
|
561 |
{
|
|
562 |
iState = EBcaOpened;
|
|
563 |
//Activate the receiver Active Object
|
|
564 |
iObserver.Receiver().StartListening();
|
|
565 |
_LOG_L1C1(_L8("CBcaIoController Is Initialised"));
|
|
566 |
TRAPD(err, iObserver.GetObserver().InitialiseL(MRawIPObserverBase::EBcaController,KErrNone));
|
|
567 |
if(err != KErrNone)
|
|
568 |
{
|
|
569 |
_LOG_L2C2(_L8("ERROR in BCA Open Initialise observer = %d"), err);
|
|
570 |
iObserver.Stop(err);
|
|
571 |
}
|
|
572 |
}
|
|
573 |
break;
|
|
574 |
}
|
|
575 |
|
|
576 |
//in this state, BCA is Shutdown, shutdown the NIF.
|
|
577 |
case EClosing:
|
|
578 |
{
|
|
579 |
// linklayer shutdown
|
|
580 |
iState = EIdling;
|
|
581 |
iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, iError);
|
|
582 |
break;
|
|
583 |
}
|
|
584 |
// Wrong state.
|
|
585 |
default:
|
|
586 |
{
|
|
587 |
_LOG_L1C1(_L8("ERROR CBcaControl::RunL(): Unknown state"));
|
|
588 |
_BTT_PANIC(KNifName, KBcaUnkownState);
|
|
589 |
break;
|
|
590 |
}
|
|
591 |
}
|
|
592 |
|
|
593 |
}
|
|
594 |
|
|
595 |
void CBcaControl::DoCancel()
|
|
596 |
/**
|
|
597 |
* cancel active request.
|
|
598 |
*/
|
|
599 |
{
|
|
600 |
_LOG_L1C1(_L8("CBcaControl::DoCancel called."));
|
|
601 |
_LOG_L2C2(_L8("iState value is %d"), iState);
|
|
602 |
switch (iState)
|
|
603 |
{
|
|
604 |
case EIdling:
|
|
605 |
case EIAPSet:
|
|
606 |
case EBcaStackSet:
|
|
607 |
if(iMBca)
|
|
608 |
{
|
|
609 |
iMBca->CancelIoctl();
|
|
610 |
}
|
|
611 |
iState = EIdling;
|
|
612 |
break;
|
|
613 |
case EClosing:
|
|
614 |
iState = EIdling;
|
|
615 |
break;
|
|
616 |
default:
|
|
617 |
_LOG_L2C1(_L8("ERROR CBcaControl::DoCancel(): Unknown state"));
|
|
618 |
_BTT_PANIC(KNifName, KBcaUnkownState);
|
|
619 |
break;
|
|
620 |
}
|
|
621 |
}
|
|
622 |
|
|
623 |
void CBcaControl::StartLoadL()
|
|
624 |
/**
|
|
625 |
* This method loads the C32BCA library and uses Ioctl to set the Bca iIapId.
|
|
626 |
*/
|
|
627 |
{
|
|
628 |
_LOG_L1C1(_L8("CBcaControl::StartLoad"));
|
|
629 |
|
|
630 |
//iMBca should not be initialized at this point
|
|
631 |
__ASSERT_DEBUG(!iMBca,Panic(KBcaAlreadyExists));
|
|
632 |
|
|
633 |
//We don't expect iMBca here, but if it occurs, we delete previous BCA Instance
|
|
634 |
if(iMBca)
|
|
635 |
{
|
|
636 |
//If the state is still "open", close it first
|
|
637 |
if(EBcaOpened == iState)
|
|
638 |
{
|
|
639 |
iMBca->Close();
|
|
640 |
}
|
|
641 |
iMBca->Release();
|
|
642 |
}
|
|
643 |
|
|
644 |
// Loads Bca Dll and creates a Bca instance;
|
|
645 |
User::LeaveIfError(iBcaDll.iObj.Load(iObserver.BcaName()));
|
|
646 |
|
|
647 |
TNewBcaFactoryL newBcaFactoryProcL = (TNewBcaFactoryL)iBcaDll.iObj.Lookup(1);
|
|
648 |
if (NULL == newBcaFactoryProcL)
|
|
649 |
{
|
|
650 |
_LOG_L1C2(_L8("Library entry point found error %d"), KErrBadLibraryEntryPoint);
|
|
651 |
User::Leave(KErrBadLibraryEntryPoint);
|
|
652 |
}
|
|
653 |
|
|
654 |
MBcaFactory* bcaFactory = (*newBcaFactoryProcL)();
|
|
655 |
|
|
656 |
if(!bcaFactory)
|
|
657 |
{
|
|
658 |
_LOG_L1C2(_L8("BcaFactory creation error %d"), KErrCompletion);
|
|
659 |
User::Leave(KErrCompletion);
|
|
660 |
}
|
|
661 |
CleanupReleasePushL(*bcaFactory);
|
|
662 |
|
|
663 |
iMBca = bcaFactory->NewBcaL();
|
|
664 |
CleanupStack::PopAndDestroy(bcaFactory);
|
|
665 |
|
|
666 |
iObserver.SetBca(iMBca); //Pass BCA pointer.
|
|
667 |
|
|
668 |
TPckg<TUint32> aOpt(iObserver.IapId());
|
|
669 |
iMBca->Ioctl(iStatus,KBcaOptLevelGeneric,KBCASetIapId,aOpt);
|
|
670 |
|
|
671 |
iState = EIdling;
|
|
672 |
SetActive();
|
|
673 |
}
|
|
674 |
|
|
675 |
|
|
676 |
void CBcaControl::ShutdownBca(TInt aError)
|
|
677 |
/**
|
|
678 |
* Bca Shutdown.
|
|
679 |
|
|
680 |
* @param aError the error code to shutdown the NIF.
|
|
681 |
*/
|
|
682 |
{
|
|
683 |
__ASSERT_DEBUG(iMBca,Panic(KBcaNotExist));
|
|
684 |
Cancel();
|
|
685 |
|
|
686 |
//We should only call shutdown or close if we have successfully opened a BCA Channel
|
|
687 |
if((iMBca) && (EBcaOpened == iState))
|
|
688 |
{
|
|
689 |
if(aError == KErrConnectionTerminated )
|
|
690 |
{
|
|
691 |
_LOG_L1C1(_L8("This is an emergency shutdown, it kills the NIF immediately."));
|
|
692 |
// It is a emergency shutdown, it kills the NIF immediately.
|
|
693 |
iMBca->Close();
|
|
694 |
iState = EIdling;
|
|
695 |
iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, aError);
|
|
696 |
}
|
|
697 |
else
|
|
698 |
{
|
|
699 |
_LOG_L1C1(_L8("This is a graceful termination which takes a while."));
|
|
700 |
//It is a graceful termination which takes a while.
|
|
701 |
iError = aError;
|
|
702 |
iState = EClosing;
|
|
703 |
iMBca->Shutdown(iStatus);
|
|
704 |
SetActive();
|
|
705 |
}
|
|
706 |
}
|
|
707 |
else //nothing to shutdown, just notify linklayer down.
|
|
708 |
{
|
|
709 |
_LOG_L1C1(_L8("Bca is not initialized or opened, bring the linklayer down"));
|
|
710 |
iState = EIdling;
|
|
711 |
iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, aError);
|
|
712 |
}
|
|
713 |
|
|
714 |
}
|
|
715 |
|
|
716 |
/** Panic function for RawIpNif
|
|
717 |
|
|
718 |
* @param aPanic panic code */
|
|
719 |
void Panic(TRawIPNifPanic aPanic)
|
|
720 |
{
|
|
721 |
User::Panic(KNifName,aPanic);
|
|
722 |
}
|
|
723 |
|