blob: b1524f66db0cff19ae9ee928d774b8e137faf0ff [file] [log] [blame]
San Mehatdc266072009-05-06 11:16:52 -07001/*
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 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehatdc266072009-05-06 11:16:52 -070017#ifndef _WIFI_CONTROLLER_H
18#define _WIFI_CONTROLLER_H
19
20#include <sys/types.h>
21
22#include "Controller.h"
San Mehat3aff2d12009-06-15 14:10:44 -070023#include "ScanResult.h"
24#include "WifiNetwork.h"
25#include "ISupplicantEventHandler.h"
San Mehatc4a895b2009-06-23 21:10:57 -070026#include "IWifiStatusPollerHandler.h"
San Mehatdc266072009-05-06 11:16:52 -070027
28class NetInterface;
29class Supplicant;
San Mehat3aff2d12009-06-15 14:10:44 -070030class SupplicantAssociatingEvent;
31class SupplicantAssociatedEvent;
32class SupplicantConnectedEvent;
33class SupplicantScanResultsEvent;
34class SupplicantStateChangeEvent;
35class SupplicantDisconnectedEvent;
San Mehatc4a895b2009-06-23 21:10:57 -070036class WifiStatusPoller;
San Mehat1441e762009-05-07 11:37:10 -070037
San Mehatc4a895b2009-06-23 21:10:57 -070038class WifiController : public Controller,
39 public ISupplicantEventHandler,
40 public IWifiStatusPollerHandler {
San Mehatdc266072009-05-06 11:16:52 -070041
San Mehatc4a895b2009-06-23 21:10:57 -070042 class WifiIntegerProperty : public IntegerProperty {
43 protected:
44 WifiController *mWc;
45 public:
46 WifiIntegerProperty(WifiController *c, const char *name, bool ro,
47 int elements);
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;
San Mehatdc266072009-05-06 11:16:52 -070053
San Mehatc4a895b2009-06-23 21:10:57 -070054 class WifiStringProperty : public StringProperty {
55 protected:
56 WifiController *mWc;
57 public:
58 WifiStringProperty(WifiController *c, const char *name, bool ro,
59 int elements);
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);
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);
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);
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);
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);
101 virtual ~WifiSearchingProperty() {}
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);
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);
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);
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);
133 virtual ~WifiCurrentNetworkProperty() {}
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);
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);
149 virtual ~WifiNetCountProperty() {}
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);
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);
165 virtual ~WifiSupplicantStateProperty() {}
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);
173 virtual ~WifiInterfaceProperty() {}
174 int set(int idx, const char *value) { return -1; }
175 int get(int idx, char *buffer, size_t max);
176 };
177
San Mehatdc266072009-05-06 11:16:52 -0700178 Supplicant *mSupplicant;
179 char mModulePath[255];
180 char mModuleName[64];
181 char mModuleArgs[255];
San Mehat3aff2d12009-06-15 14:10:44 -0700182
San Mehat3aff2d12009-06-15 14:10:44 -0700183 int mSupplicantState;
San Mehatc4a895b2009-06-23 21:10:57 -0700184 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;
San Mehat3aff2d12009-06-15 14:10:44 -0700195
196 ScanResultCollection *mLatestScanResults;
197 pthread_mutex_t mLatestScanResultsLock;
San Mehatc4a895b2009-06-23 21:10:57 -0700198 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;
San Mehat3aff2d12009-06-15 14:10:44 -0700227
San Mehat3c5a6f02009-05-22 15:36:13 -0700228 bool mEnabled;
San Mehatdc266072009-05-06 11:16:52 -0700229
230public:
San Mehat3aff2d12009-06-15 14:10:44 -0700231 WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs);
San Mehatdc266072009-05-06 11:16:52 -0700232 virtual ~WifiController() {}
233
234 int start();
235 int stop();
236
San Mehat3c5a6f02009-05-22 15:36:13 -0700237 WifiNetwork *createNetwork();
San Mehat82a21162009-05-12 17:26:28 -0700238 int removeNetwork(int networkId);
239 WifiNetworkCollection *createNetworkList();
San Mehat1441e762009-05-07 11:37:10 -0700240
San Mehat82a21162009-05-12 17:26:28 -0700241 ScanResultCollection *createScanResults();
San Mehatdc266072009-05-06 11:16:52 -0700242
243 char *getModulePath() { return mModulePath; }
244 char *getModuleName() { return mModuleName; }
245 char *getModuleArgs() { return mModuleArgs; }
246
247 Supplicant *getSupplicant() { return mSupplicant; }
248
San Mehatdc266072009-05-06 11:16:52 -0700249protected:
San Mehat3c5a6f02009-05-22 15:36:13 -0700250 // Move this crap into a 'driver'
San Mehatdc266072009-05-06 11:16:52 -0700251 virtual int powerUp() = 0;
252 virtual int powerDown() = 0;
253 virtual int loadFirmware();
San Mehat1441e762009-05-07 11:37:10 -0700254
255 virtual bool isFirmwareLoaded() = 0;
San Mehatdc266072009-05-06 11:16:52 -0700256 virtual bool isPoweredUp() = 0;
257
San Mehat48765672009-05-20 15:28:43 -0700258private:
San Mehat3c5a6f02009-05-22 15:36:13 -0700259 void sendStatusBroadcast(const char *msg);
San Mehatc4a895b2009-06-23 21:10:57 -0700260 int setActiveScan(bool active);
261 int triggerScan();
San Mehat48765672009-05-20 15:28:43 -0700262 int enable();
263 int disable();
San Mehatc4a895b2009-06-23 21:10:57 -0700264 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);
San Mehat3aff2d12009-06-15 14:10:44 -0700270
271 // ISupplicantEventHandler methods
San Mehatc4a895b2009-06-23 21:10:57 -0700272 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);
San Mehat3aff2d12009-06-15 14:10:44 -0700279#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
San Mehatc4a895b2009-06-23 21:10:57 -0700291 void onStatusPollInterval();
292
293 int verifyNotSuspended();
San Mehatdc266072009-05-06 11:16:52 -0700294};
295
296#endif