|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "t_wlanscaninfodata.h" |
|
20 //class CWlanScanInfo |
|
21 #include <wlanmgmtclient.h> |
|
22 #include <e32cmn.h> |
|
23 |
|
24 /*@{*/ |
|
25 //LITs from the ini |
|
26 _LIT(KSsidParam, "DEFAULT_SSID_Ssid"); |
|
27 _LIT(KUid, "WlanScanUid"); |
|
28 /*@}*/ |
|
29 |
|
30 /*@{*/ |
|
31 //LIT's for the commands |
|
32 _LIT(KCmdNewL, "NewL"); |
|
33 _LIT(KCmdDestructor, "~"); |
|
34 _LIT(KCmdInformationElement, "InformationElement"); |
|
35 /*@}*/ |
|
36 |
|
37 /** |
|
38 * Two phase constructor |
|
39 * |
|
40 * @leave system wide error |
|
41 */ |
|
42 CT_WlanScanInfoData* CT_WlanScanInfoData::NewL() |
|
43 { |
|
44 CT_WlanScanInfoData* ret = new(ELeave) CT_WlanScanInfoData(); |
|
45 CleanupStack::PushL(ret); |
|
46 ret->ConstructL(); |
|
47 CleanupStack::Pop(ret); |
|
48 return ret; |
|
49 } |
|
50 |
|
51 /** |
|
52 * Public destructor |
|
53 */ |
|
54 CT_WlanScanInfoData::~CT_WlanScanInfoData() |
|
55 { |
|
56 DestroyData(); |
|
57 } |
|
58 |
|
59 /** |
|
60 * Private constructor. First phase construction |
|
61 */ |
|
62 CT_WlanScanInfoData::CT_WlanScanInfoData() |
|
63 : iData(NULL), |
|
64 iScanInfoInstanceIdentifier(KNullUid) |
|
65 { |
|
66 } |
|
67 |
|
68 |
|
69 /** |
|
70 * Second phase construction |
|
71 * |
|
72 * @internalComponent |
|
73 * |
|
74 * @return N/A |
|
75 * |
|
76 * @pre None |
|
77 * @post None |
|
78 * |
|
79 * @leave system wide error |
|
80 */ |
|
81 void CT_WlanScanInfoData::ConstructL() |
|
82 { |
|
83 } |
|
84 |
|
85 /** |
|
86 * Return a pointer to the object that the data wraps |
|
87 * |
|
88 * @return pointer to the object that the data wraps |
|
89 */ |
|
90 TAny* CT_WlanScanInfoData::GetObject() |
|
91 { |
|
92 return iData; |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 * Process a command read from the Ini file |
|
98 * @param aCommand The command to process |
|
99 * @param aSection The section get from the *.ini file of the project T_Wlan |
|
100 * @param aAsyncErrorIndex Command index dor async calls to returns errors to |
|
101 * @return TBool ETrue if the command is process |
|
102 * @leave system wide error |
|
103 */ |
|
104 TBool CT_WlanScanInfoData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
105 { |
|
106 TBool ret = ETrue; |
|
107 |
|
108 if(aCommand == KCmdNewL) |
|
109 { |
|
110 DoCmdNewL(aSection); |
|
111 } |
|
112 else if(aCommand == KCmdDestructor) |
|
113 { |
|
114 DoCmdDestructor(); |
|
115 } |
|
116 else if(aCommand == KCmdInformationElement) |
|
117 { |
|
118 DoCmdInformationElement(aSection); |
|
119 } |
|
120 else |
|
121 { |
|
122 ret = EFalse; |
|
123 ERR_PRINTF1(_L("Unknown command")); |
|
124 } |
|
125 |
|
126 return ret; |
|
127 } |
|
128 |
|
129 |
|
130 /** |
|
131 * Create an instance of CWlanScanInfo |
|
132 * @param |
|
133 * @return |
|
134 */ |
|
135 void CT_WlanScanInfoData::DoCmdNewL(const TTEFSectionName& aSection) |
|
136 { |
|
137 INFO_PRINTF1(_L("*START* CT_WlanScanInfoData::DoCmdNewL")); |
|
138 DestroyData(); |
|
139 |
|
140 TBool dataOk = ETrue; |
|
141 |
|
142 TInt wsUid; |
|
143 if(!GetHexFromConfig(aSection, KUid, wsUid )) |
|
144 { |
|
145 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUid); |
|
146 SetBlockResult(EFail); |
|
147 dataOk = EFalse; |
|
148 } |
|
149 |
|
150 if (dataOk) |
|
151 { |
|
152 const TUid WsUid = {wsUid}; |
|
153 TAny* interface = NULL; |
|
154 |
|
155 TRAPD(err, interface = REComSession::CreateImplementationL( WsUid, iScanInfoInstanceIdentifier )); |
|
156 if(err == KErrNone) |
|
157 { |
|
158 iData = reinterpret_cast<CWlanScanInfo*>( interface ); |
|
159 |
|
160 if(iData == NULL) |
|
161 { |
|
162 ERR_PRINTF1(_L("CT_WlanScanInfoData::DoCmdNewL() Fail")); |
|
163 SetBlockResult(EFail); |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 ERR_PRINTF2(_L("Create Implementation left with error %d"), err); |
|
169 SetError(err); |
|
170 } |
|
171 } |
|
172 |
|
173 INFO_PRINTF1(_L("*END* CT_WlanScanInfoData::DoCmdNewL")); |
|
174 } |
|
175 |
|
176 /** |
|
177 * Destructor for CWlanScanInfo |
|
178 * @param |
|
179 * @return |
|
180 */ |
|
181 void CT_WlanScanInfoData::DoCmdDestructor() |
|
182 { |
|
183 INFO_PRINTF1(_L("*START* CT_WlanScanInfoData::DoCmdDestructor")); |
|
184 DestroyData(); |
|
185 INFO_PRINTF1(_L("*END* CT_WlanScanInfoData::DoCmdDestructor")); |
|
186 } |
|
187 |
|
188 /** |
|
189 * called from DoCmdDestructor for destroy the object CWlanScanInfo |
|
190 * @param |
|
191 * @return |
|
192 */ |
|
193 void CT_WlanScanInfoData::DestroyData() |
|
194 { |
|
195 // Cannot use "delete" directly because we use a member variable as an |
|
196 // ECom instance identifier |
|
197 REComSession::DestroyedImplementation( iScanInfoInstanceIdentifier ); |
|
198 iData = NULL; |
|
199 } |
|
200 /** |
|
201 * Review if the IAP given in the ini file match with some Wireless Local Area Network (SelectScanInfo). |
|
202 * @param aSection Section in the ini file for this command |
|
203 * @return |
|
204 */ |
|
205 void CT_WlanScanInfoData::DoCmdInformationElement(const TTEFSectionName& aSection) |
|
206 { |
|
207 INFO_PRINTF1(_L("*START* CT_WlanScanInfoData::DoCmdInformationElement")); |
|
208 TBool dataOk = ETrue; |
|
209 |
|
210 TPtrC aSsid; |
|
211 if(!GetStringFromConfig(aSection,KSsidParam, aSsid)) |
|
212 { |
|
213 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSsidParam); |
|
214 SetBlockResult(EFail); |
|
215 dataOk = EFalse; |
|
216 } |
|
217 |
|
218 if(dataOk) |
|
219 { |
|
220 TInt err(KErrNone); |
|
221 // Scan info gives data as "information elements" |
|
222 TUint8 ieLen(0); |
|
223 const TUint8* ieData; |
|
224 TWlanSsid ssid8; |
|
225 TBuf<KWlanMaxSsidLength> ssid; |
|
226 TBool match = EFalse; |
|
227 |
|
228 INFO_PRINTF2(_L("SSID to be checked: %S"),&aSsid); |
|
229 for( iData->First(); !iData->IsDone(); iData->Next() ) |
|
230 { |
|
231 INFO_PRINTF1(_L("found scan info")); |
|
232 err = KErrNotReady; |
|
233 // Information Element ID for SSID as specified in 802.11. |
|
234 const TUint8 KWlan802Dot11SsidIE(0); |
|
235 err = iData->InformationElement( KWlan802Dot11SsidIE, ieLen, &ieData ); |
|
236 if(err != KErrNone) |
|
237 { |
|
238 ERR_PRINTF2(_L("CScanInfo::InformationElement err: [%d]"),err); |
|
239 SetError(err); |
|
240 break; |
|
241 } |
|
242 if(ieLen) |
|
243 { |
|
244 ssid8.Copy( ieData, ieLen ); |
|
245 ssid.Copy( ssid8 ); |
|
246 INFO_PRINTF2(_L("Current information element SSID: %S"),&ssid); |
|
247 // check if this is an expected SSID |
|
248 if( aSsid.Compare( ssid ) == 0 ) |
|
249 { |
|
250 INFO_PRINTF1(_L("SSID match!")); |
|
251 match = ETrue; |
|
252 break; |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 if (err == KErrNone && !match) |
|
258 { |
|
259 ERR_PRINTF2(_L("Given SSID %S NOT FOUND!"),&aSsid); |
|
260 SetBlockResult(EFail); |
|
261 } |
|
262 } |
|
263 |
|
264 INFO_PRINTF1(_L("*END* CT_WlanScanInfoData::DoCmdInformationElement")); |
|
265 } |
|
266 |