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 | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 26 | |
| 27 | class NetInterface; |
| 28 | class Supplicant; |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 29 | class WifiScanner; |
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 | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 36 | |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame^] | 37 | class WifiController : public Controller, public ISupplicantEventHandler { |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 38 | public: |
| 39 | static const uint32_t SCAN_ENABLE_MASK = 0x01; |
| 40 | static const uint32_t SCAN_ACTIVE_MASK = 0x02; |
| 41 | static const uint32_t SCAN_REPEAT_MASK = 0x04; |
| 42 | |
| 43 | static const uint32_t SCANMODE_NONE = 0; |
| 44 | static const uint32_t SCANMODE_PASSIVE_ONESHOT = SCAN_ENABLE_MASK; |
| 45 | static const uint32_t SCANMODE_PASSIVE_CONTINUOUS = SCAN_ENABLE_MASK | SCAN_REPEAT_MASK; |
| 46 | static const uint32_t SCANMODE_ACTIVE_ONESHOT = SCAN_ENABLE_MASK | SCAN_ACTIVE_MASK; |
| 47 | static const uint32_t SCANMODE_ACTIVE_CONTINUOUS = SCAN_ENABLE_MASK | SCAN_ACTIVE_MASK | SCAN_REPEAT_MASK; |
| 48 | |
| 49 | private: |
| 50 | Supplicant *mSupplicant; |
| 51 | char mModulePath[255]; |
| 52 | char mModuleName[64]; |
| 53 | char mModuleArgs[255]; |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame^] | 54 | |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 55 | uint32_t mCurrentScanMode; |
| 56 | WifiScanner *mScanner; |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame^] | 57 | int mSupplicantState; |
| 58 | |
| 59 | ScanResultCollection *mLatestScanResults; |
| 60 | pthread_mutex_t mLatestScanResultsLock; |
| 61 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 62 | bool mEnabled; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 63 | |
| 64 | public: |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame^] | 65 | WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 66 | virtual ~WifiController() {} |
| 67 | |
| 68 | int start(); |
| 69 | int stop(); |
| 70 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 71 | WifiNetwork *createNetwork(); |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 72 | int removeNetwork(int networkId); |
| 73 | WifiNetworkCollection *createNetworkList(); |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 74 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 75 | virtual int set(const char *name, const char *value); |
| 76 | virtual const char *get(const char *name, char *buffer, size_t maxlen); |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 77 | |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 78 | ScanResultCollection *createScanResults(); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 79 | |
| 80 | char *getModulePath() { return mModulePath; } |
| 81 | char *getModuleName() { return mModuleName; } |
| 82 | char *getModuleArgs() { return mModuleArgs; } |
| 83 | |
| 84 | Supplicant *getSupplicant() { return mSupplicant; } |
| 85 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 86 | protected: |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 87 | // Move this crap into a 'driver' |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 88 | virtual int powerUp() = 0; |
| 89 | virtual int powerDown() = 0; |
| 90 | virtual int loadFirmware(); |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 91 | |
| 92 | virtual bool isFirmwareLoaded() = 0; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 93 | virtual bool isPoweredUp() = 0; |
| 94 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 95 | private: |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 96 | void sendStatusBroadcast(const char *msg); |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 97 | int setScanMode(uint32_t mode); |
| 98 | int enable(); |
| 99 | int disable(); |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame^] | 100 | |
| 101 | // ISupplicantEventHandler methods |
| 102 | virtual void onAssociatingEvent(SupplicantAssociatingEvent *evt); |
| 103 | virtual void onAssociatedEvent(SupplicantAssociatedEvent *evt); |
| 104 | virtual void onConnectedEvent(SupplicantConnectedEvent *evt); |
| 105 | virtual void onScanResultsEvent(SupplicantScanResultsEvent *evt); |
| 106 | virtual void onStateChangeEvent(SupplicantStateChangeEvent *evt); |
| 107 | virtual void onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt); |
| 108 | virtual void onDisconnectedEvent(SupplicantDisconnectedEvent *evt); |
| 109 | #if 0 |
| 110 | virtual void onTerminatingEvent(SupplicantEvent *evt); |
| 111 | virtual void onPasswordChangedEvent(SupplicantEvent *evt); |
| 112 | virtual void onEapNotificationEvent(SupplicantEvent *evt); |
| 113 | virtual void onEapStartedEvent(SupplicantEvent *evt); |
| 114 | virtual void onEapMethodEvent(SupplicantEvent *evt); |
| 115 | virtual void onEapSuccessEvent(SupplicantEvent *evt); |
| 116 | virtual void onEapFailureEvent(SupplicantEvent *evt); |
| 117 | virtual void onLinkSpeedEvent(SupplicantEvent *evt); |
| 118 | virtual void onDriverStateEvent(SupplicantEvent *evt); |
| 119 | #endif |
| 120 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | #endif |