|
1 /* |
|
2 * Copyright (c) 2002-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: Implementation of WLAN Agent statemachine framework |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 11 % |
|
20 */ |
|
21 |
|
22 #include <comms-infras/dbaccess.h> |
|
23 #include <wdbifwlansettings.h> |
|
24 #include "am_debug.h" |
|
25 #include "wlanagtsm.h" |
|
26 #include "wlanagtstates.h" |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CWlanSM::NewL |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CWlanSM* CWlanSM::NewL( |
|
36 MAgentNotify& aObserver, |
|
37 CDialogProcessor* aDlgPrc, |
|
38 CCommsDbAccess& aDbAccess ) |
|
39 { |
|
40 DEBUG( "CWlanSM::NewL()" ); |
|
41 CWlanSM* self = new (ELeave) CWlanSM(aObserver, aDlgPrc, aDbAccess); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CWlanSM::CWlanSM |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CWlanSM::CWlanSM( |
|
53 MAgentNotify& aObserver, |
|
54 CDialogProcessor* aDlgPrc, |
|
55 CCommsDbAccess& aDbAccess ) : |
|
56 CAgentSMBase( aObserver, aDlgPrc, aDbAccess ), |
|
57 iWlanSettings( NULL ), |
|
58 iServiceId( 0 ), |
|
59 iWLMOverrideSettings( NULL ), |
|
60 iIapId( 0 ), |
|
61 iIsHotSpotAP (EFalse) |
|
62 { |
|
63 DEBUG( "CWlanSM constructor" ); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CWlanSM::ConstructL |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CWlanSM::ConstructL() |
|
71 { |
|
72 DEBUG( "CWlanSM::ConstructL()" ); |
|
73 |
|
74 TRAPD( err, DoConstructL() ); |
|
75 |
|
76 if( err == KErrNone ) |
|
77 { |
|
78 TWlanConnectionState state = iWLMServer.GetConnectionState(); |
|
79 |
|
80 DEBUG1( "CWlanSM::ConstructL() - WLAN engine state is %u", state ); |
|
81 |
|
82 if( state == EWlanStateNotConnected ) |
|
83 { |
|
84 iState = new(ELeave) CWlanStartState( this, iWLMServer ); |
|
85 } |
|
86 else |
|
87 { |
|
88 iState = new(ELeave) CWlanWaitConnectionState( this, iWLMServer ); |
|
89 } |
|
90 } |
|
91 else |
|
92 { |
|
93 #ifdef _DEBUG |
|
94 User::InfoPrint(_L("wlanagt: state machine creation error")); |
|
95 #endif |
|
96 iState = new(ELeave) CWlanErrorState( this, KErrCouldNotConnect ); |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CWlanSM::DoConstructL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CWlanSM::DoConstructL() |
|
105 { |
|
106 DEBUG( "CWlanSM::DoConstructL()" ); |
|
107 User::LeaveIfError(iWLMServer.Connect()); |
|
108 |
|
109 // Check the service type in current IAP, must be LANService. |
|
110 TBuf<KCommsDbSvrMaxFieldLength> serviceType; |
|
111 Db()->GetDesL( TPtrC( IAP ), TPtrC( IAP_SERVICE_TYPE ), serviceType ); |
|
112 if( serviceType != TPtrC( LAN_SERVICE ) ) |
|
113 { |
|
114 User::Leave(KErrCorrupt); |
|
115 } |
|
116 |
|
117 // Get the current IAP id |
|
118 Db()->GetIntL( TPtrC( IAP ), TPtrC( COMMDB_ID ), iIapId ); |
|
119 DEBUG1("iap id:%d", iIapId); |
|
120 |
|
121 // Get the service ID from the IAP table |
|
122 Db()->GetIntL( TPtrC( IAP ), TPtrC( IAP_SERVICE ), iServiceId ); |
|
123 DEBUG1("service id:%d", iServiceId); |
|
124 |
|
125 iWlanSettings = new (ELeave) SWLANSettings; |
|
126 |
|
127 CWLanSettings* wlansettings = new (ELeave) CWLanSettings(); |
|
128 CleanupStack::PushL( wlansettings ); |
|
129 User::LeaveIfError( wlansettings->Connect() ); |
|
130 |
|
131 // Get the "IAP specific WLAN settings" for this LAN service ID |
|
132 TInt err = wlansettings->GetWlanSettingsForService( iServiceId, *iWlanSettings ); |
|
133 wlansettings->Disconnect(); |
|
134 |
|
135 // wlansettings->Disconnect() need to be called also if wlansettings-> |
|
136 // GetWlanSettingsForService() returns an error. This is why we didn't use |
|
137 // User::LeaveIfError() above directly. |
|
138 User::LeaveIfError(err); |
|
139 |
|
140 CleanupStack::PopAndDestroy( wlansettings ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CWlanSM::GetExcessData |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TInt CWlanSM::GetExcessData(TDes8& /*aBuffer*/) |
|
148 { |
|
149 DEBUG( "CWlanSM::GetExcessData()" ); |
|
150 return KErrNone; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CWlanSM::Notification |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 TInt CWlanSM::Notification(TNifToAgentEventType /*aEvent*/, TAny* /*aInfo*/) |
|
158 { |
|
159 DEBUG( "CWlanSM::Notification()" ); |
|
160 return KErrNone; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CWlanSM::SetOverrideSettingsL |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CWlanSM::SetOverrideSettingsL(const TWLMOverrideSettings& aWLMOverrideSettings) |
|
168 { |
|
169 if(!iWLMOverrideSettings) |
|
170 { |
|
171 iWLMOverrideSettings = new (ELeave) TWLMOverrideSettings; |
|
172 } |
|
173 |
|
174 iWLMOverrideSettings->settingsMask = aWLMOverrideSettings.settingsMask; |
|
175 iWLMOverrideSettings->ssid = aWLMOverrideSettings.ssid; |
|
176 iWLMOverrideSettings->bssid = aWLMOverrideSettings.bssid; |
|
177 iWLMOverrideSettings->wep = aWLMOverrideSettings.wep; |
|
178 iWLMOverrideSettings->wpaPsk = aWLMOverrideSettings.wpaPsk; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CWlanSM::~CWlanSM |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 CWlanSM::~CWlanSM() |
|
186 { |
|
187 DEBUG( "CWlanSM destructor" ); |
|
188 |
|
189 delete iWlanSettings; |
|
190 delete iWLMOverrideSettings; |
|
191 |
|
192 iWLMServer.Close(); |
|
193 |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CWlanSM::WlanSettings |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 const SWLANSettings* CWlanSM::WlanSettings() const |
|
201 { |
|
202 return iWlanSettings; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CWlanSM::SettingsId |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TUint32 CWlanSM::SettingsId() const |
|
210 { |
|
211 return iServiceId; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CWlanSM::IapId |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TUint32 CWlanSM::IapId() const |
|
219 { |
|
220 return iIapId; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CWlanSM::SetHotSpotAP |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CWlanSM::SetHotSpotAP(TBool aHotSpotAP) |
|
228 { |
|
229 iIsHotSpotAP = aHotSpotAP; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CWlanSM::IsHotSpotAP |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 TBool CWlanSM::IsHotSpotAP() const |
|
237 { |
|
238 return iIsHotSpotAP; |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CWlanSM::OverrideSettings |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TWLMOverrideSettings* CWlanSM::OverrideSettings() const |
|
246 { |
|
247 return iWLMOverrideSettings; |
|
248 } |
|
249 |