• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _WIFI_CONTROLLER_H
18 #define _WIFI_CONTROLLER_H
19 
20 #include <sys/types.h>
21 
22 #include "Controller.h"
23 #include "ScanResult.h"
24 #include "WifiNetwork.h"
25 #include "ISupplicantEventHandler.h"
26 #include "IWifiStatusPollerHandler.h"
27 
28 class NetInterface;
29 class Supplicant;
30 class SupplicantAssociatingEvent;
31 class SupplicantAssociatedEvent;
32 class SupplicantConnectedEvent;
33 class SupplicantScanResultsEvent;
34 class SupplicantStateChangeEvent;
35 class SupplicantDisconnectedEvent;
36 class WifiStatusPoller;
37 
38 class WifiController : public Controller,
39                        public ISupplicantEventHandler,
40                        public IWifiStatusPollerHandler {
41 
42     class WifiIntegerProperty : public IntegerProperty {
43     protected:
44         WifiController *mWc;
45     public:
46         WifiIntegerProperty(WifiController *c, const char *name, bool ro,
47                             int elements);
~WifiIntegerProperty()48         virtual ~WifiIntegerProperty() {}
49         virtual int set(int idx, int value) = 0;
50         virtual int get(int idx, int *buffer) = 0;
51     };
52     friend class WifiController::WifiIntegerProperty;
53 
54     class WifiStringProperty : public StringProperty {
55     protected:
56         WifiController *mWc;
57     public:
58         WifiStringProperty(WifiController *c, const char *name, bool ro,
59                             int elements);
~WifiStringProperty()60         virtual ~WifiStringProperty() {}
61         virtual int set(int idx, const char *value) = 0;
62         virtual int get(int idx, char *buffer, size_t max) = 0;
63     };
64     friend class WifiController::WifiStringProperty;
65 
66     class WifiEnabledProperty : public WifiIntegerProperty {
67     public:
68         WifiEnabledProperty(WifiController *c);
~WifiEnabledProperty()69         virtual ~WifiEnabledProperty() {}
70         int set(int idx, int value);
71         int get(int idx, int *buffer);
72     };
73 
74     class WifiScanOnlyProperty : public WifiIntegerProperty {
75     public:
76         WifiScanOnlyProperty(WifiController *c);
~WifiScanOnlyProperty()77         virtual ~WifiScanOnlyProperty() {}
78         int set(int idx, int value);
79         int get(int idx, int *buffer);
80     };
81 
82     class WifiAllowedChannelsProperty : public WifiIntegerProperty {
83     public:
84         WifiAllowedChannelsProperty(WifiController *c);
~WifiAllowedChannelsProperty()85         virtual ~WifiAllowedChannelsProperty() {}
86         int set(int idx, int value);
87         int get(int idx, int *buffer);
88     };
89 
90     class WifiActiveScanProperty : public WifiIntegerProperty {
91     public:
92         WifiActiveScanProperty(WifiController *c);
~WifiActiveScanProperty()93         virtual ~WifiActiveScanProperty() {}
94         int set(int idx, int value);
95         int get(int idx, int *buffer);
96     };
97 
98     class WifiSearchingProperty : public WifiIntegerProperty {
99     public:
100         WifiSearchingProperty(WifiController *c);
~WifiSearchingProperty()101         virtual ~WifiSearchingProperty() {}
set(int idx,int value)102         int set(int idx, int value) { return -1; }
103         int get(int idx, int *buffer);
104     };
105 
106     class WifiPacketFilterProperty : public WifiIntegerProperty {
107     public:
108         WifiPacketFilterProperty(WifiController *c);
~WifiPacketFilterProperty()109         virtual ~WifiPacketFilterProperty() {}
110         int set(int idx, int value);
111         int get(int idx, int *buffer);
112     };
113 
114     class WifiBluetoothCoexScanProperty : public WifiIntegerProperty {
115     public:
116         WifiBluetoothCoexScanProperty(WifiController *c);
~WifiBluetoothCoexScanProperty()117         virtual ~WifiBluetoothCoexScanProperty() {}
118         int set(int idx, int value);
119         int get(int idx, int *buffer);
120     };
121 
122     class WifiBluetoothCoexModeProperty : public WifiIntegerProperty {
123     public:
124         WifiBluetoothCoexModeProperty(WifiController *c);
~WifiBluetoothCoexModeProperty()125         virtual ~WifiBluetoothCoexModeProperty() {}
126         int set(int idx, int value);
127         int get(int idx, int *buffer);
128     };
129 
130     class WifiCurrentNetworkProperty : public WifiIntegerProperty {
131     public:
132         WifiCurrentNetworkProperty(WifiController *c);
~WifiCurrentNetworkProperty()133         virtual ~WifiCurrentNetworkProperty() {}
set(int idx,int value)134         int set(int idx, int value) { return -1; }
135         int get(int idx, int *buffer);
136     };
137 
138     class WifiSuspendedProperty : public WifiIntegerProperty {
139     public:
140         WifiSuspendedProperty(WifiController *c);
~WifiSuspendedProperty()141         virtual ~WifiSuspendedProperty() {}
142         int set(int idx, int value);
143         int get(int idx, int *buffer);
144     };
145 
146     class WifiNetCountProperty : public WifiIntegerProperty {
147     public:
148         WifiNetCountProperty(WifiController *c);
~WifiNetCountProperty()149         virtual ~WifiNetCountProperty() {}
set(int idx,int value)150         int set(int idx, int value) { return -1; }
151         int get(int idx, int *buffer);
152     };
153 
154     class WifiTriggerScanProperty : public WifiIntegerProperty {
155     public:
156         WifiTriggerScanProperty(WifiController *c);
~WifiTriggerScanProperty()157         virtual ~WifiTriggerScanProperty() {}
158         int set(int idx, int value);
159         int get(int idx, int *buffer);
160     };
161 
162     class WifiSupplicantStateProperty : public WifiStringProperty {
163     public:
164         WifiSupplicantStateProperty(WifiController *c);
~WifiSupplicantStateProperty()165         virtual ~WifiSupplicantStateProperty() {}
set(int idx,const char * value)166         int set(int idx, const char *value) { return -1; }
167         int get(int idx, char *buffer, size_t max);
168     };
169 
170     class WifiInterfaceProperty : public WifiStringProperty {
171     public:
172         WifiInterfaceProperty(WifiController *c);
~WifiInterfaceProperty()173         virtual ~WifiInterfaceProperty() {}
set(int idx,const char * value)174         int set(int idx, const char *value) { return -1; }
175         int get(int idx, char *buffer, size_t max);
176     };
177 
178     Supplicant *mSupplicant;
179     char        mModulePath[255];
180     char        mModuleName[64];
181     char        mModuleArgs[255];
182 
183     int         mSupplicantState;
184     bool        mActiveScan;
185     bool        mScanOnly;
186     bool        mPacketFilter;
187     bool        mBluetoothCoexScan;
188     int         mBluetoothCoexMode;
189     int         mCurrentlyConnectedNetworkId;
190     bool        mSuspended;
191     int         mLastRssi;
192     int         mRssiEventThreshold;
193     int         mLastLinkSpeed;
194     int         mNumAllowedChannels;
195 
196     ScanResultCollection *mLatestScanResults;
197     pthread_mutex_t      mLatestScanResultsLock;
198     pthread_mutex_t      mLock;
199     WifiStatusPoller     *mStatusPoller;
200 
201     struct {
202         WifiEnabledProperty         *propEnabled;
203         WifiScanOnlyProperty        *propScanOnly;
204         WifiAllowedChannelsProperty *propAllowedChannels;
205         IntegerPropertyHelper       *propRssiEventThreshold;
206     } mStaticProperties;
207 
208     struct {
209         WifiActiveScanProperty        *propActiveScan;
210         WifiSearchingProperty         *propSearching;
211         WifiPacketFilterProperty      *propPacketFilter;
212         WifiBluetoothCoexScanProperty *propBluetoothCoexScan;
213         WifiBluetoothCoexModeProperty *propBluetoothCoexMode;
214         WifiCurrentNetworkProperty    *propCurrentNetwork;
215         IntegerPropertyHelper         *propRssi;
216         IntegerPropertyHelper         *propLinkSpeed;
217         WifiSuspendedProperty         *propSuspended;
218         WifiNetCountProperty          *propNetCount;
219         WifiSupplicantStateProperty   *propSupplicantState;
220         WifiInterfaceProperty         *propInterface;
221         WifiTriggerScanProperty       *propTriggerScan;
222     } mDynamicProperties;
223 
224     // True if supplicant is currently searching for a network
225     bool mIsSupplicantSearching;
226     int  mNumScanResultsSinceLastStateChange;
227 
228     bool        mEnabled;
229 
230 public:
231     WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs);
~WifiController()232     virtual ~WifiController() {}
233 
234     int start();
235     int stop();
236 
237     WifiNetwork *createNetwork();
238     int removeNetwork(int networkId);
239     WifiNetworkCollection *createNetworkList();
240 
241     ScanResultCollection *createScanResults();
242 
getModulePath()243     char *getModulePath() { return mModulePath; }
getModuleName()244     char *getModuleName() { return mModuleName; }
getModuleArgs()245     char *getModuleArgs() { return mModuleArgs; }
246 
getSupplicant()247     Supplicant *getSupplicant() { return mSupplicant; }
248 
249 protected:
250     // Move this crap into a 'driver'
251     virtual int powerUp() = 0;
252     virtual int powerDown() = 0;
253     virtual int loadFirmware();
254 
255     virtual bool isFirmwareLoaded() = 0;
256     virtual bool isPoweredUp() = 0;
257 
258 private:
259     void sendStatusBroadcast(const char *msg);
260     int setActiveScan(bool active);
261     int triggerScan();
262     int enable();
263     int disable();
264     int setSuspend(bool suspend);
265     bool getSuspended();
266     int setBluetoothCoexistenceScan(bool enable);
267     int setBluetoothCoexistenceMode(int mode);
268     int setPacketFilter(bool enable);
269     int setScanOnly(bool scanOnly);
270 
271     // ISupplicantEventHandler methods
272     void onAssociatingEvent(SupplicantAssociatingEvent *evt);
273     void onAssociatedEvent(SupplicantAssociatedEvent *evt);
274     void onConnectedEvent(SupplicantConnectedEvent *evt);
275     void onScanResultsEvent(SupplicantScanResultsEvent *evt);
276     void onStateChangeEvent(SupplicantStateChangeEvent *evt);
277     void onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt);
278     void onDisconnectedEvent(SupplicantDisconnectedEvent *evt);
279 #if 0
280     virtual void onTerminatingEvent(SupplicantEvent *evt);
281     virtual void onPasswordChangedEvent(SupplicantEvent *evt);
282     virtual void onEapNotificationEvent(SupplicantEvent *evt);
283     virtual void onEapStartedEvent(SupplicantEvent *evt);
284     virtual void onEapMethodEvent(SupplicantEvent *evt);
285     virtual void onEapSuccessEvent(SupplicantEvent *evt);
286     virtual void onEapFailureEvent(SupplicantEvent *evt);
287     virtual void onLinkSpeedEvent(SupplicantEvent *evt);
288     virtual void onDriverStateEvent(SupplicantEvent *evt);
289 #endif
290 
291     void onStatusPollInterval();
292 
293     int verifyNotSuspended();
294 };
295 
296 #endif
297