San Mehat | 82a2116 | 2009-05-12 17:26:28 -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 | */ |
| 16 | |
| 17 | #ifndef _WIFI_NETWORK_H |
| 18 | #define _WIFI_NETWORK_H |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 22 | #include <utils/List.h> |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 23 | |
| 24 | class KeyManagementMask { |
| 25 | public: |
San Mehat | 21e90f0 | 2009-06-01 10:04:21 -0700 | [diff] [blame^] | 26 | static const uint32_t UNKNOWN = 0; |
| 27 | static const uint32_t NONE = 0x01; |
| 28 | static const uint32_t WPA_PSK = 0x02; |
| 29 | static const uint32_t WPA_EAP = 0x04; |
| 30 | static const uint32_t IEEE8021X = 0x08; |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 31 | static const uint32_t ALL = WPA_PSK | WPA_EAP | IEEE8021X; |
| 32 | }; |
| 33 | |
| 34 | class SecurityProtocolMask { |
| 35 | public: |
| 36 | static const uint32_t WPA = 0x01; |
| 37 | static const uint32_t RSN = 0x02; |
| 38 | }; |
| 39 | |
| 40 | class AuthenticationAlgorithmMask { |
| 41 | public: |
| 42 | static const uint32_t OPEN = 0x01; |
| 43 | static const uint32_t SHARED = 0x02; |
| 44 | static const uint32_t LEAP = 0x04; |
| 45 | }; |
| 46 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 47 | class PairwiseCiphersMask { |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 48 | public: |
| 49 | static const uint32_t NONE = 0x00; |
| 50 | static const uint32_t TKIP = 0x01; |
| 51 | static const uint32_t CCMP = 0x02; |
| 52 | }; |
| 53 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 54 | class GroupCiphersMask { |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 55 | public: |
| 56 | static const uint32_t WEP40 = 0x01; |
| 57 | static const uint32_t WEP104 = 0x02; |
| 58 | static const uint32_t TKIP = 0x04; |
| 59 | static const uint32_t CCMP = 0x08; |
| 60 | }; |
| 61 | |
| 62 | class Supplicant; |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 63 | class InterfaceConfig; |
| 64 | class Controller; |
| 65 | class WifiController; |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 66 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 67 | #include "IPropertyProvider.h" |
| 68 | |
| 69 | class WifiNetwork : public IPropertyProvider{ |
| 70 | public: |
| 71 | static const char *PropertyNames[]; |
| 72 | |
| 73 | private: |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 74 | Supplicant *mSuppl; |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 75 | InterfaceConfig *mIfaceCfg; |
| 76 | WifiController *mController; |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Unique network id - normally provided by supplicant |
| 80 | */ |
| 81 | int mNetid; |
| 82 | |
| 83 | /* |
| 84 | * The networks' SSID. Can either be an ASCII string, |
| 85 | * which must be enclosed in double quotation marks |
| 86 | * (ie: "MyNetwork"), or a string of hex digits which |
| 87 | * are not enclosed in quotes (ie: 01ab7893) |
| 88 | */ |
| 89 | char *mSsid; |
| 90 | |
| 91 | /* |
| 92 | * When set, this entry should only be used |
| 93 | * when associating with the AP having the specified |
| 94 | * BSSID. The value is a string in the format of an |
| 95 | * Ethernet MAC address |
| 96 | */ |
| 97 | char *mBssid; |
| 98 | |
| 99 | /* |
| 100 | * Pre-shared key for use with WPA-PSK |
| 101 | */ |
| 102 | char *mPsk; |
| 103 | |
| 104 | /* |
| 105 | * Up to four WEP keys. Either in ASCII string enclosed in |
| 106 | * double quotes, or a string of hex digits |
| 107 | */ |
| 108 | char *mWepKeys[4]; |
| 109 | |
| 110 | /* |
| 111 | * Default WEP key index, ranging from 0 -> NUM_WEP_KEYS -1 |
| 112 | */ |
| 113 | int mDefaultKeyIndex; |
| 114 | |
| 115 | /* |
| 116 | * Priority determines the preference given to a network by |
| 117 | * supplicant when choosing an access point with which |
| 118 | * to associate |
| 119 | */ |
| 120 | int mPriority; |
| 121 | |
| 122 | /* |
| 123 | * This is a network that does not broadcast it's SSID, so an |
| 124 | * SSID-specific probe request must be used for scans. |
| 125 | */ |
| 126 | char *mHiddenSsid; |
| 127 | |
| 128 | /* |
| 129 | * The set of key management protocols supported by this configuration. |
| 130 | */ |
| 131 | uint32_t mAllowedKeyManagement; |
| 132 | |
| 133 | /* |
| 134 | * The set of security protocols supported by this configuration. |
| 135 | */ |
| 136 | uint32_t mAllowedProtocols; |
| 137 | |
| 138 | /* |
| 139 | * The set of authentication protocols supported by this configuration. |
| 140 | */ |
| 141 | uint32_t mAllowedAuthAlgorithms; |
| 142 | |
| 143 | /* |
| 144 | * The set of pairwise ciphers for WPA supported by this configuration. |
| 145 | */ |
| 146 | uint32_t mAllowedPairwiseCiphers; |
| 147 | |
| 148 | /* |
| 149 | * The set of group ciphers for WPA supported by this configuration. |
| 150 | */ |
| 151 | uint32_t mAllowedGroupCiphers; |
| 152 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 153 | /* |
| 154 | * Set if this Network is enabled |
| 155 | */ |
| 156 | bool mEnabled; |
| 157 | |
| 158 | private: |
| 159 | WifiNetwork(); |
| 160 | int registerProperties(); |
| 161 | int unregisterProperties(); |
| 162 | |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 163 | public: |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 164 | WifiNetwork(WifiController *c, Supplicant *suppl, int networkId); |
| 165 | WifiNetwork(WifiController *c, Supplicant *suppl, const char *data); |
| 166 | |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 167 | virtual ~WifiNetwork(); |
| 168 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 169 | WifiNetwork *clone(); |
| 170 | |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 171 | int getNetworkId() { return mNetid; } |
| 172 | const char *getSsid() { return mSsid; } |
| 173 | const char *getBssid() { return mBssid; } |
| 174 | const char *getPsk() { return mPsk; } |
| 175 | const char *getWepKey(int idx) { return mWepKeys[idx]; } |
| 176 | int getDefaultKeyIndex() { return mDefaultKeyIndex; } |
| 177 | int getPriority() { return mPriority; } |
| 178 | const char *getHiddenSsid() { return mHiddenSsid; } |
| 179 | uint32_t getAllowedKeyManagement() { return mAllowedKeyManagement; } |
| 180 | uint32_t getAllowedProtocols() { return mAllowedProtocols; } |
| 181 | uint32_t getAllowedAuthAlgorithms() { return mAllowedAuthAlgorithms; } |
| 182 | uint32_t getAllowedPairwiseCiphers() { return mAllowedPairwiseCiphers; } |
| 183 | uint32_t getAllowedGroupCiphers() { return mAllowedGroupCiphers; } |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 184 | bool getEnabled() { return mEnabled; } |
| 185 | Controller *getController() { return (Controller *) mController; } |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 186 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 187 | int set(const char *name, const char *value); |
| 188 | const char *get(const char *name, char *buffer, size_t maxsize); |
| 189 | |
| 190 | // InterfaceConfig *getIfaceCfg() { return mIfaceCfg; } |
| 191 | |
| 192 | int setEnabled(bool enabled); |
| 193 | int setSsid(const char *ssid); |
| 194 | int setBssid(const char *bssid); |
| 195 | int setPsk(const char *psk); |
| 196 | int setWepKey(int idx, const char *key); |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 197 | int setDefaultKeyIndex(int idx); |
| 198 | int setPriority(int pri); |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 199 | int setHiddenSsid(const char *ssid); |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 200 | int setAllowedKeyManagement(uint32_t mask); |
| 201 | int setAllowedProtocols(uint32_t mask); |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 202 | int setAllowedAuthAlgorithms(uint32_t mask); |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 203 | int setAllowedPairwiseCiphers(uint32_t mask); |
| 204 | int setAllowedGroupCiphers(uint32_t mask); |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 205 | |
| 206 | // XXX:Should this really be exposed?.. meh |
| 207 | int refresh(); |
San Mehat | 82a2116 | 2009-05-12 17:26:28 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | typedef android::List<WifiNetwork *> WifiNetworkCollection; |
| 211 | |
| 212 | #endif |