San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 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 | */ |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 16 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 17 | #ifndef _WIFI_CONTROLLER_H |
| 18 | #define _WIFI_CONTROLLER_H |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #include "Controller.h" |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 23 | #include "ScanResult.h" |
| 24 | #include "WifiNetwork.h" |
| 25 | #include "ISupplicantEventHandler.h" |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 26 | #include "IWifiStatusPollerHandler.h" |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 27 | |
| 28 | class NetInterface; |
| 29 | class Supplicant; |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 30 | class SupplicantAssociatingEvent; |
| 31 | class SupplicantAssociatedEvent; |
| 32 | class SupplicantConnectedEvent; |
| 33 | class SupplicantScanResultsEvent; |
| 34 | class SupplicantStateChangeEvent; |
| 35 | class SupplicantDisconnectedEvent; |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 36 | class WifiStatusPoller; |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 37 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 38 | class WifiController : public Controller, |
| 39 | public ISupplicantEventHandler, |
| 40 | public IWifiStatusPollerHandler { |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 41 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 42 | 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 Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 53 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 54 | 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 Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 178 | Supplicant *mSupplicant; |
| 179 | char mModulePath[255]; |
| 180 | char mModuleName[64]; |
| 181 | char mModuleArgs[255]; |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 182 | |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 183 | int mSupplicantState; |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 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; |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 195 | |
| 196 | ScanResultCollection *mLatestScanResults; |
| 197 | pthread_mutex_t mLatestScanResultsLock; |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 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; |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 227 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 228 | bool mEnabled; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 229 | |
| 230 | public: |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 231 | WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 232 | virtual ~WifiController() {} |
| 233 | |
| 234 | int start(); |
| 235 | int stop(); |
| 236 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 237 | WifiNetwork *createNetwork(); |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 238 | int removeNetwork(int networkId); |
| 239 | WifiNetworkCollection *createNetworkList(); |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 240 | |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 241 | ScanResultCollection *createScanResults(); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 242 | |
| 243 | char *getModulePath() { return mModulePath; } |
| 244 | char *getModuleName() { return mModuleName; } |
| 245 | char *getModuleArgs() { return mModuleArgs; } |
| 246 | |
| 247 | Supplicant *getSupplicant() { return mSupplicant; } |
| 248 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 249 | protected: |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 250 | // Move this crap into a 'driver' |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 251 | virtual int powerUp() = 0; |
| 252 | virtual int powerDown() = 0; |
| 253 | virtual int loadFirmware(); |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 254 | |
| 255 | virtual bool isFirmwareLoaded() = 0; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 256 | virtual bool isPoweredUp() = 0; |
| 257 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 258 | private: |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 259 | void sendStatusBroadcast(const char *msg); |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 260 | int setActiveScan(bool active); |
| 261 | int triggerScan(); |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 262 | int enable(); |
| 263 | int disable(); |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 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); |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 270 | |
| 271 | // ISupplicantEventHandler methods |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 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); |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 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 | |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 291 | void onStatusPollInterval(); |
| 292 | |
| 293 | int verifyNotSuspended(); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | #endif |