|
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 |
|
25 #include "Constants.h" |
|
26 #include "BcaController.h" |
|
27 |
|
28 CBcaController::CBcaController(CRawIP2Flow& aRawIPFlow,CBttLogger* aTheLogger) |
|
29 /** |
|
30 * Constructor. Performs standard active object initialisation. |
|
31 * |
|
32 * @param aRawIPFlow Reference to the RawIp2Flow |
|
33 * @param aTheLogger The logging object |
|
34 */ |
|
35 : CActive(EPriorityStandard), |
|
36 iTheLogger(aTheLogger), |
|
37 iMBca(NULL), |
|
38 iState(EIdling), |
|
39 iRawIPFlow(aRawIPFlow), |
|
40 iUpperControl(NULL), |
|
41 iUpperDataReceiver(NULL), |
|
42 iBCAProvisionConfig(NULL), |
|
43 iBcaParams(NULL) |
|
44 { |
|
45 CActiveScheduler::Add(this); |
|
46 } |
|
47 |
|
48 CBcaController* CBcaController::NewL(CRawIP2Flow& aRawIPFlow,CBttLogger* aTheLogger) |
|
49 /** |
|
50 * Two-phase constructor. Creates a new CBcaController object, performs |
|
51 * second-phase construction, then returns it. |
|
52 * |
|
53 * @param aRawIPFlow Reference to the RawIp2Flow |
|
54 * @param aTheLogger The logging object |
|
55 * @return A newly constructed CBcaController object |
|
56 */ |
|
57 { |
|
58 CBcaController* self = new (ELeave) CBcaController(aRawIPFlow,aTheLogger); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(self); |
|
62 return self; |
|
63 } |
|
64 |
|
65 void CBcaController::ConstructL() |
|
66 /** |
|
67 * Second-phase constructor. Creates all the state objects it owns. |
|
68 */ |
|
69 { |
|
70 _LOG_L1C1(_L8("CBcaController::ConstructL")); |
|
71 |
|
72 } |
|
73 |
|
74 |
|
75 CBcaController::~CBcaController() |
|
76 /** |
|
77 * Destructor. |
|
78 */ |
|
79 { |
|
80 Cancel(); |
|
81 if(iMBca) |
|
82 { |
|
83 iMBca->Release(); |
|
84 } |
|
85 delete iBcaParams; |
|
86 // Library will be Closed when iBcaDll is destroyed. |
|
87 } |
|
88 |
|
89 void CBcaController::RunL() |
|
90 /** |
|
91 * AO async callback method. Called after request is completed. |
|
92 * |
|
93 */ |
|
94 { |
|
95 _LOG_L1C1(_L8("CBcaControl::RunL() called")); |
|
96 switch (iState) |
|
97 { |
|
98 //in this state, Ioctl is called to set IAP ID, check the result of |
|
99 // Ioctl, then either set the BCA stack with another Ioctl call, |
|
100 // open the BCA (if there's no BCA stack to set), or stop the NIF. |
|
101 case EIdling: |
|
102 { |
|
103 if(iStatus == KErrNone || iStatus == KErrNotSupported) |
|
104 { |
|
105 if(iStatus == KErrNotSupported) |
|
106 { |
|
107 _LOG_L1C1(_L8("This BCA does not support IAPID set")); |
|
108 } |
|
109 else |
|
110 { |
|
111 _LOG_L2C1(_L8("This BCA supports IAPID set")); |
|
112 } |
|
113 |
|
114 TPtrC bcaStack = iBCAProvisionConfig->GetBCAStack(); |
|
115 if(bcaStack.Length()) |
|
116 { |
|
117 TBuf8<KMaxName> remainingBcaStack8; |
|
118 remainingBcaStack8.Copy(bcaStack); |
|
119 iMBca->Control(iStatus, KBcaOptLevelGeneric,KBCASetBcaStack,remainingBcaStack8); |
|
120 } |
|
121 else |
|
122 { |
|
123 TRequestStatus* statusPtr=&iStatus; |
|
124 User::RequestComplete(statusPtr,KErrNone); |
|
125 } |
|
126 iState = EIAPSet; |
|
127 SetActive(); |
|
128 } |
|
129 else |
|
130 { |
|
131 _LOG_L1C2(_L8("ERROR in BCA IAPID set = %d"), iStatus.Int()); |
|
132 Stop(iStatus.Int()); |
|
133 } |
|
134 |
|
135 break; |
|
136 } |
|
137 //in this case, we receive the result of Ioctl call to set Bca Stack. |
|
138 // Check the result of Ioctl, then Open and start the Bca or stop the NIF |
|
139 case EIAPSet: |
|
140 { |
|
141 if(iStatus == KErrNotSupported || iStatus == KErrNone) |
|
142 { |
|
143 if(iStatus == KErrNotSupported) |
|
144 { |
|
145 _LOG_L1C1(_L8("This BCA does not support BCA stacking")); |
|
146 } |
|
147 else |
|
148 { |
|
149 _LOG_L2C1(_L8("This BCA supports BCA stacking")); |
|
150 } |
|
151 iBcaParams = new(ELeave) MBca2::TBcaParams(const_cast<CBCAProvision*>(iBCAProvisionConfig)->GetCommsPond(), iBCAProvisionConfig->GetPortName()); |
|
152 |
|
153 TInt aErr = iMBca->Open(*iUpperControl,*iUpperDataReceiver,*iBcaParams); |
|
154 if ( aErr != KErrNone) |
|
155 { |
|
156 _LOG_L2C2(_L8("ERROR in BCA Open = %d"), aErr); |
|
157 Stop(iStatus.Int()); |
|
158 iState = EIdling; |
|
159 } |
|
160 else |
|
161 { |
|
162 iMBca->Start(); |
|
163 } |
|
164 } |
|
165 else |
|
166 { |
|
167 _LOG_L2C2(_L8("ERROR in BCA stack set = %d"), iStatus.Int()); |
|
168 Stop(iStatus.Int()); |
|
169 } |
|
170 break; |
|
171 } |
|
172 // Wrong state. |
|
173 default: |
|
174 { |
|
175 _LOG_L1C1(_L8("ERROR CBcaControl::RunL(): Unknown state")); |
|
176 _BTT_PANIC(KNifName, KBcaUnkownState); |
|
177 break; |
|
178 } |
|
179 } |
|
180 |
|
181 } |
|
182 |
|
183 void CBcaController::DoCancel() |
|
184 /** |
|
185 * cancel active request. |
|
186 */ |
|
187 { |
|
188 _LOG_L1C1(_L8("CBcaControl::DoCancel called.")); |
|
189 _LOG_L2C2(_L8("iState value is %d"), iState); |
|
190 switch (iState) |
|
191 { |
|
192 case EIdling: |
|
193 case EIAPSet: |
|
194 if(iMBca) |
|
195 { |
|
196 iMBca->CancelControl(); |
|
197 } |
|
198 iState = EIdling; |
|
199 break; |
|
200 default: |
|
201 _LOG_L2C1(_L8("ERROR CBcaControl::DoCancel(): Unknown state")); |
|
202 _BTT_PANIC(KNifName, KBcaUnkownState); |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 void CBcaController::StartLoadL(const CBCAProvision* aBCAProvisionConfig,MUpperControl* aControl, |
|
208 MUpperDataReceiver* aData) |
|
209 /** |
|
210 * This method loads the C32BCA library and uses Ioctl to set the Bca iIapId. |
|
211 * |
|
212 * @param aBCAProvisionConfig pointer to CBCAProvision for extracting the pond |
|
213 * @param aControl pointer to BasebandChannelAdaptation2::MUpperControl passed to the MBca2 to pass control information up the stack |
|
214 * * @param aData pointer to BasebandChannelAdaptation2::MUpperDataReceiver passed to the MBca2 to push packets up the stack |
|
215 * @return none |
|
216 */ |
|
217 { |
|
218 _LOG_L1C1(_L8("CBcaControl::StartLoad")); |
|
219 |
|
220 iBCAProvisionConfig = aBCAProvisionConfig; |
|
221 iUpperControl = aControl; |
|
222 iUpperDataReceiver = aData; |
|
223 // Loads Bca Dll and creates a Bca instance; |
|
224 User::LeaveIfError(iBcaDll.iObj.Load(iBCAProvisionConfig->GetBCAName())); |
|
225 |
|
226 TNewBca2FactoryL newBca2FactoryProcL = (TNewBca2FactoryL)iBcaDll.iObj.Lookup(1); |
|
227 if (NULL == newBca2FactoryProcL) |
|
228 { |
|
229 _LOG_L1C2(_L8("Library entry point found error %d"), KErrBadLibraryEntryPoint); |
|
230 User::Leave(KErrBadLibraryEntryPoint); |
|
231 } |
|
232 |
|
233 MBca2Factory* bcaFactory = (*newBca2FactoryProcL)(); |
|
234 |
|
235 if(!bcaFactory) |
|
236 { |
|
237 _LOG_L1C2(_L8("BcaFactory creation error %d"), KErrCompletion); |
|
238 User::Leave(KErrCompletion); |
|
239 } |
|
240 CleanupReleasePushL(*bcaFactory); |
|
241 |
|
242 iMBca = bcaFactory->NewBcaL(); |
|
243 CleanupStack::PopAndDestroy(bcaFactory); |
|
244 |
|
245 TPckg<TUint32> aOpt(iBCAProvisionConfig->GetIAPid()); |
|
246 iMBca->Control(iStatus,KBcaOptLevelGeneric,KBCASetIapId,aOpt); |
|
247 |
|
248 iState = EIdling; |
|
249 SetActive(); |
|
250 } |
|
251 |
|
252 void CBcaController::Stop(TInt aError) |
|
253 /** |
|
254 * Used to shutdown this module. This will cancel all the outstanding |
|
255 * requests on the active objects owned by this module and shutdown. |
|
256 */ |
|
257 { |
|
258 _LOG_L1C1(_L8("CBcaController::Stop is called.")); |
|
259 |
|
260 if(iMBca) |
|
261 { |
|
262 iMBca->Close(); |
|
263 } |
|
264 else |
|
265 { |
|
266 _LOG_L1C1(_L8("CBcaController::Stop Bca is not initialized. Bring the link layer down")); |
|
267 iRawIPFlow.LinkLayerDown(aError); |
|
268 } |
|
269 } |
|
270 |
|
271 |
|
272 /** Panic function for RawIpNif |
|
273 |
|
274 * @param aPanic panic code */ |
|
275 void Panic(TRawIP2NifPanic aPanic) |
|
276 { |
|
277 _LOG_L2C2(_L8("Panic code for RawIpNif = %d"), aPanic); |
|
278 User::Panic(KNifName,aPanic); |
|
279 |
|
280 } |
|
281 |