system/corennnnn
Revisão | 82a2116e6b67db910bba22c4874e6ca5efd3eec0 (tree) |
---|---|
Hora | 2009-05-14 01:10:01 |
Autor | San Mehat <san@goog...> |
Commiter | San Mehat |
nexus: Initial support for manipulating wifi networks + change wifi scan notification msgs
Signed-off-by: San Mehat <san@google.com>
@@ -20,6 +20,7 @@ LOCAL_SRC_FILES:= \ | ||
20 | 20 | VpnController.cpp \ |
21 | 21 | ScanResult.cpp \ |
22 | 22 | WifiScanner.cpp \ |
23 | + WifiNetwork.cpp \ | |
23 | 24 | |
24 | 25 | LOCAL_MODULE:= nexus |
25 | 26 |
@@ -33,6 +33,11 @@ CommandListener::CommandListener() : | ||
33 | 33 | registerCmd(new WifiDisableCmd()); |
34 | 34 | registerCmd(new WifiScanCmd()); |
35 | 35 | registerCmd(new WifiScanResultsCmd()); |
36 | + registerCmd(new WifiListNetworksCmd()); | |
37 | + registerCmd(new WifiAddNetworkCmd()); | |
38 | + registerCmd(new WifiRemoveNetworkCmd()); | |
39 | + registerCmd(new WifiSetVarCmd()); | |
40 | + registerCmd(new WifiGetVarCmd()); | |
36 | 41 | |
37 | 42 | registerCmd(new VpnEnableCmd()); |
38 | 43 | registerCmd(new VpnDisableCmd()); |
@@ -70,13 +75,46 @@ int CommandListener::WifiDisableCmd::runCommand(SocketClient *cli, char *data) { | ||
70 | 75 | return 0; |
71 | 76 | } |
72 | 77 | |
78 | +CommandListener::WifiAddNetworkCmd::WifiAddNetworkCmd() : | |
79 | + NexusCommand("wifi_add_network") { | |
80 | +} | |
81 | + | |
82 | +int CommandListener::WifiAddNetworkCmd::runCommand(SocketClient *cli, char *data) { | |
83 | + NetworkManager *nm = NetworkManager::Instance(); | |
84 | + WifiController *wc = (WifiController *) nm->findController("WIFI"); | |
85 | + int networkId; | |
86 | + | |
87 | + if ((networkId = wc->addNetwork()) < 0) | |
88 | + cli->sendMsg(ErrorCode::OperationFailed, "Failed to add network", true); | |
89 | + else { | |
90 | + char tmp[128]; | |
91 | + sprintf(tmp, "Added network id %d.", networkId); | |
92 | + cli->sendMsg(ErrorCode::CommandOkay, tmp, false); | |
93 | + } | |
94 | + return 0; | |
95 | +} | |
96 | + | |
97 | +CommandListener::WifiRemoveNetworkCmd::WifiRemoveNetworkCmd() : | |
98 | + NexusCommand("wifi_remove_network") { | |
99 | +} | |
100 | + | |
101 | +int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli, char *data) { | |
102 | + NetworkManager *nm = NetworkManager::Instance(); | |
103 | + WifiController *wc = (WifiController *) nm->findController("WIFI"); | |
104 | + | |
105 | + if (wc->removeNetwork(atoi(data))) | |
106 | + cli->sendMsg(ErrorCode::OperationFailed, "Failed to remove network", true); | |
107 | + else { | |
108 | + cli->sendMsg(ErrorCode::CommandOkay, "Network removed.", false); | |
109 | + } | |
110 | + return 0; | |
111 | +} | |
112 | + | |
73 | 113 | CommandListener::WifiScanCmd::WifiScanCmd() : |
74 | 114 | NexusCommand("wifi_scan") { |
75 | 115 | } |
76 | 116 | |
77 | 117 | int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) { |
78 | - LOGD("WifiScanCmd(%s)", data); | |
79 | - | |
80 | 118 | WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI"); |
81 | 119 | |
82 | 120 | if (wc->setScanMode(atoi(data))) |
@@ -93,7 +131,6 @@ CommandListener::WifiScanResultsCmd::WifiScanResultsCmd() : | ||
93 | 131 | |
94 | 132 | int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *data) { |
95 | 133 | NetworkManager *nm = NetworkManager::Instance(); |
96 | - | |
97 | 134 | WifiController *wc = (WifiController *) nm->findController("WIFI"); |
98 | 135 | |
99 | 136 | ScanResultCollection *src = wc->createScanResults(); |
@@ -104,7 +141,7 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *dat | ||
104 | 141 | sprintf(buffer, "%s:%u:%d:%s:%s", |
105 | 142 | (*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(), |
106 | 143 | (*it)->getFlags(), (*it)->getSsid()); |
107 | - cli->sendMsg(125, buffer, false); | |
144 | + cli->sendMsg(ErrorCode::WifiScanResult, buffer, false); | |
108 | 145 | delete (*it); |
109 | 146 | it = src->erase(it); |
110 | 147 | } |
@@ -114,6 +151,99 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *dat | ||
114 | 151 | return 0; |
115 | 152 | } |
116 | 153 | |
154 | +CommandListener::WifiListNetworksCmd::WifiListNetworksCmd() : | |
155 | + NexusCommand("wifi_list_networks") { | |
156 | +} | |
157 | + | |
158 | +int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli, char *data) { | |
159 | + NetworkManager *nm = NetworkManager::Instance(); | |
160 | + WifiController *wc = (WifiController *) nm->findController("WIFI"); | |
161 | + | |
162 | + WifiNetworkCollection *src = wc->createNetworkList(); | |
163 | + WifiNetworkCollection::iterator it; | |
164 | + char buffer[256]; | |
165 | + | |
166 | + for(it = src->begin(); it != src->end(); ++it) { | |
167 | + sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid()); | |
168 | + cli->sendMsg(ErrorCode::WifiNetworkList, buffer, false); | |
169 | + delete (*it); | |
170 | + it = src->erase(it); | |
171 | + } | |
172 | + | |
173 | + delete src; | |
174 | + cli->sendMsg(ErrorCode::CommandOkay, "Network listing complete.", false); | |
175 | + return 0; | |
176 | +} | |
177 | + | |
178 | +CommandListener::WifiSetVarCmd::WifiSetVarCmd() : | |
179 | + NexusCommand("wifi_setvar") { | |
180 | +} | |
181 | + | |
182 | +int CommandListener::WifiSetVarCmd::runCommand(SocketClient *cli, char *data) { | |
183 | + WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI"); | |
184 | + | |
185 | + char *bword; | |
186 | + char *last; | |
187 | + char varname[32]; | |
188 | + char val[250]; | |
189 | + int networkId; | |
190 | + | |
191 | + if (!(bword = strtok_r(data, ":", &last))) | |
192 | + goto out_inval; | |
193 | + | |
194 | + networkId = atoi(bword); | |
195 | + | |
196 | + if (!(bword = strtok_r(NULL, ":", &last))) | |
197 | + goto out_inval; | |
198 | + | |
199 | + strncpy(varname, bword, sizeof(varname)); | |
200 | + | |
201 | + if (!(bword = strtok_r(NULL, ":", &last))) | |
202 | + goto out_inval; | |
203 | + | |
204 | + strncpy(val, bword, sizeof(val)); | |
205 | + | |
206 | + LOGD("Network id %d, varname '%s', value '%s'", networkId, varname, val); | |
207 | + | |
208 | + return 0; | |
209 | + | |
210 | +out_inval: | |
211 | + errno = EINVAL; | |
212 | + cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set variable.", true); | |
213 | + return 0; | |
214 | +} | |
215 | + | |
216 | +CommandListener::WifiGetVarCmd::WifiGetVarCmd() : | |
217 | + NexusCommand("wifi_getvar") { | |
218 | +} | |
219 | + | |
220 | +int CommandListener::WifiGetVarCmd::runCommand(SocketClient *cli, char *data) { | |
221 | + WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI"); | |
222 | + | |
223 | + char *bword; | |
224 | + char *last; | |
225 | + char varname[32]; | |
226 | + int networkId; | |
227 | + | |
228 | + if (!(bword = strtok_r(data, ":", &last))) | |
229 | + goto out_inval; | |
230 | + | |
231 | + networkId = atoi(bword); | |
232 | + | |
233 | + if (!(bword = strtok_r(NULL, ":", &last))) | |
234 | + goto out_inval; | |
235 | + | |
236 | + strncpy(varname, bword, sizeof(varname)); | |
237 | + | |
238 | + LOGD("networkId = %d, varname '%s'", networkId, varname); | |
239 | + | |
240 | + return 0; | |
241 | +out_inval: | |
242 | + errno = EINVAL; | |
243 | + cli->sendMsg(ErrorCode::CommandParameterError, "Failed to get variable.", true); | |
244 | + return 0; | |
245 | +} | |
246 | + | |
117 | 247 | /* ------------ |
118 | 248 | * Vpn Commands |
119 | 249 | * ------------ */ |
@@ -53,6 +53,41 @@ private: | ||
53 | 53 | int runCommand(SocketClient *c, char *data); |
54 | 54 | }; |
55 | 55 | |
56 | + class WifiAddNetworkCmd : public NexusCommand { | |
57 | + public: | |
58 | + WifiAddNetworkCmd(); | |
59 | + virtual ~WifiAddNetworkCmd() {} | |
60 | + int runCommand(SocketClient *c, char *data); | |
61 | + }; | |
62 | + | |
63 | + class WifiRemoveNetworkCmd : public NexusCommand { | |
64 | + public: | |
65 | + WifiRemoveNetworkCmd(); | |
66 | + virtual ~WifiRemoveNetworkCmd() {} | |
67 | + int runCommand(SocketClient *c, char *data); | |
68 | + }; | |
69 | + | |
70 | + class WifiListNetworksCmd : public NexusCommand { | |
71 | + public: | |
72 | + WifiListNetworksCmd(); | |
73 | + virtual ~WifiListNetworksCmd() {} | |
74 | + int runCommand(SocketClient *c, char *data); | |
75 | + }; | |
76 | + | |
77 | + class WifiSetVarCmd : public NexusCommand { | |
78 | + public: | |
79 | + WifiSetVarCmd(); | |
80 | + virtual ~WifiSetVarCmd() {} | |
81 | + int runCommand(SocketClient *c, char *data); | |
82 | + }; | |
83 | + | |
84 | + class WifiGetVarCmd : public NexusCommand { | |
85 | + public: | |
86 | + WifiGetVarCmd(); | |
87 | + virtual ~WifiGetVarCmd() {} | |
88 | + int runCommand(SocketClient *c, char *data); | |
89 | + }; | |
90 | + | |
56 | 91 | class VpnEnableCmd : public NexusCommand { |
57 | 92 | public: |
58 | 93 | VpnEnableCmd(); |
@@ -23,6 +23,9 @@ public: | ||
23 | 23 | // before proceeding with a new command. |
24 | 24 | static const int ActionInitiated = 100; |
25 | 25 | |
26 | + static const int WifiScanResult = 125; | |
27 | + static const int WifiNetworkList = 126; | |
28 | + | |
26 | 29 | // 200 series - Requested action has been successfully completed |
27 | 30 | static const int CommandOkay = 200; |
28 | 31 |
@@ -33,6 +36,7 @@ public: | ||
33 | 36 | // 500 series - The command was not accepted and the requested |
34 | 37 | // action did not take place. |
35 | 38 | static const int CommandSyntaxError = 500; |
39 | + static const int CommandParameterError = 501; | |
36 | 40 | |
37 | 41 | // 600 series - Unsolicited broadcasts |
38 | 42 | static const int UnsolicitedInformational = 600; |
@@ -229,7 +229,7 @@ int Supplicant::sendCommand(const char *cmd, char *reply, size_t *reply_len) | ||
229 | 229 | return -1; |
230 | 230 | } |
231 | 231 | |
232 | -// LOGD("sendCommand(): -> '%s'", cmd); | |
232 | + LOGD("sendCommand(): -> '%s'", cmd); | |
233 | 233 | |
234 | 234 | int rc; |
235 | 235 | if ((rc = wpa_ctrl_request(mCtrl, cmd, strlen(cmd), reply, reply_len, NULL)) == -2) { |
@@ -245,7 +245,7 @@ int Supplicant::sendCommand(const char *cmd, char *reply, size_t *reply_len) | ||
245 | 245 | !strncmp(cmd, "SCAN_RESULTS", 12)) |
246 | 246 | reply[*reply_len] = '\0'; |
247 | 247 | |
248 | -// LOGD("sendCommand(): <- '%s'", reply); | |
248 | + LOGD("sendCommand(): <- '%s'", reply); | |
249 | 249 | return 0; |
250 | 250 | } |
251 | 251 |
@@ -355,7 +355,7 @@ int Supplicant::onScanResultsEvent(SupplicantEvent *evt) { | ||
355 | 355 | mLatestScanResults->push_back(new ScanResult(linep)); |
356 | 356 | |
357 | 357 | char tmp[128]; |
358 | - sprintf(tmp, "%d scan results ready", mLatestScanResults->size()); | |
358 | + sprintf(tmp, "Scan results ready (%d)", mLatestScanResults->size()); | |
359 | 359 | NetworkManager::Instance()->getBroadcaster()-> |
360 | 360 | sendBroadcast(ErrorCode::UnsolicitedInformational, tmp, false); |
361 | 361 | pthread_mutex_unlock(&mLatestScanResultsLock); |
@@ -412,6 +412,35 @@ ScanResultCollection *Supplicant::createLatestScanResults() { | ||
412 | 412 | return d; |
413 | 413 | } |
414 | 414 | |
415 | +WifiNetworkCollection *Supplicant::createNetworkList() { | |
416 | + WifiNetworkCollection *d = new WifiNetworkCollection(); | |
417 | + return d; | |
418 | +} | |
419 | + | |
420 | +int Supplicant::addNetwork() { | |
421 | + char reply[32]; | |
422 | + size_t len = sizeof(reply) -1; | |
423 | + | |
424 | + memset(reply, 0, sizeof(reply)); | |
425 | + if (sendCommand("ADD_NETWORK", reply, &len)) | |
426 | + return -1; | |
427 | + | |
428 | + return atoi(reply); | |
429 | +} | |
430 | + | |
431 | +int Supplicant::removeNetwork(int networkId) { | |
432 | + char req[64]; | |
433 | + | |
434 | + sprintf(req, "REMOVE_NETWORK %d", networkId); | |
435 | + char reply[32]; | |
436 | + size_t len = sizeof(reply) -1; | |
437 | + memset(reply, 0, sizeof(reply)); | |
438 | + | |
439 | + if (sendCommand(req, reply, &len)) | |
440 | + return -1; | |
441 | + return 0; | |
442 | +} | |
443 | + | |
415 | 444 | int Supplicant::setupConfig() { |
416 | 445 | char buf[2048]; |
417 | 446 | int srcfd, destfd; |
@@ -23,6 +23,7 @@ class SupplicantEvent; | ||
23 | 23 | #include <pthread.h> |
24 | 24 | |
25 | 25 | #include "ScanResult.h" |
26 | +#include "WifiNetwork.h" | |
26 | 27 | |
27 | 28 | class Supplicant { |
28 | 29 | private: |
@@ -41,10 +42,13 @@ public: | ||
41 | 42 | int start(); |
42 | 43 | int stop(); |
43 | 44 | bool isStarted(); |
44 | - int triggerScan(bool active); | |
45 | 45 | |
46 | + int triggerScan(bool active); | |
46 | 47 | ScanResultCollection *createLatestScanResults(); |
47 | - WifiNetworkCollection *createWifiNetworkList(); | |
48 | + | |
49 | + int addNetwork(); | |
50 | + int removeNetwork(int networkId); | |
51 | + WifiNetworkCollection *createNetworkList(); | |
48 | 52 | |
49 | 53 | |
50 | 54 | int getState() { return mState; } |
@@ -23,7 +23,7 @@ | ||
23 | 23 | #include "WifiController.h" |
24 | 24 | #include "WifiScanner.h" |
25 | 25 | #include "NetworkManager.h" |
26 | -#include "ErrorCode.h"; | |
26 | +#include "ErrorCode.h" | |
27 | 27 | |
28 | 28 | WifiController::WifiController(char *modpath, char *modname, char *modargs) : |
29 | 29 | Controller("WIFI") { |
@@ -151,6 +151,19 @@ int WifiController::setScanMode(uint32_t mode) { | ||
151 | 151 | return rc; |
152 | 152 | } |
153 | 153 | |
154 | +int WifiController::addNetwork() { | |
155 | + return mSupplicant->addNetwork(); | |
156 | +} | |
157 | + | |
158 | +int WifiController::removeNetwork(int networkId) { | |
159 | + return mSupplicant->removeNetwork(networkId); | |
160 | +} | |
161 | + | |
154 | 162 | ScanResultCollection *WifiController::createScanResults() { |
155 | 163 | return mSupplicant->createLatestScanResults(); |
156 | 164 | } |
165 | + | |
166 | +// XXX: This should be a const list | |
167 | +WifiNetworkCollection *WifiController::createNetworkList() { | |
168 | + return mSupplicant->createNetworkList(); | |
169 | +} |
@@ -25,6 +25,7 @@ class Supplicant; | ||
25 | 25 | class WifiScanner; |
26 | 26 | |
27 | 27 | #include "ScanResult.h" |
28 | +#include "WifiNetwork.h" | |
28 | 29 | |
29 | 30 | class WifiController : public Controller { |
30 | 31 | public: |
@@ -56,9 +57,13 @@ public: | ||
56 | 57 | int enable(); |
57 | 58 | int disable(); |
58 | 59 | |
59 | - ScanResultCollection *createScanResults(); | |
60 | + int addNetwork(); | |
61 | + int removeNetwork(int networkId); | |
62 | + WifiNetworkCollection *createNetworkList(); | |
60 | 63 | |
61 | - int getType(); | |
64 | + int getScanMode() { return mCurrentScanMode; } | |
65 | + int setScanMode(uint32_t mode); | |
66 | + ScanResultCollection *createScanResults(); | |
62 | 67 | |
63 | 68 | char *getModulePath() { return mModulePath; } |
64 | 69 | char *getModuleName() { return mModuleName; } |
@@ -66,9 +71,6 @@ public: | ||
66 | 71 | |
67 | 72 | Supplicant *getSupplicant() { return mSupplicant; } |
68 | 73 | |
69 | - int getScanMode() { return mCurrentScanMode; } | |
70 | - int setScanMode(uint32_t mode); | |
71 | - | |
72 | 74 | protected: |
73 | 75 | virtual int powerUp() = 0; |
74 | 76 | virtual int powerDown() = 0; |
@@ -0,0 +1,109 @@ | ||
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 | +#include <errno.h> | |
18 | +#include <string.h> | |
19 | +#include <sys/types.h> | |
20 | + | |
21 | +#include "WifiNetwork.h" | |
22 | +#include "Supplicant.h" | |
23 | + | |
24 | +WifiNetwork::WifiNetwork(Supplicant *suppl) { | |
25 | + mSuppl = suppl; | |
26 | + mNetid = -1; | |
27 | + mSsid = NULL; | |
28 | + mBssid = NULL; | |
29 | + mPsk = NULL; | |
30 | + memset(mWepKeys, 0, sizeof(mWepKeys)); | |
31 | + mDefaultKeyIndex = -1; | |
32 | + mPriority = -1; | |
33 | + mHiddenSsid = NULL; | |
34 | + mAllowedKeyManagement = 0; | |
35 | + mAllowedProtocols = 0; | |
36 | + mAllowedAuthAlgorithms = 0; | |
37 | + mAllowedPairwiseCiphers = 0; | |
38 | + mAllowedGroupCiphers = 0; | |
39 | +} | |
40 | + | |
41 | +WifiNetwork::~WifiNetwork() { | |
42 | + if (mSsid) | |
43 | + free(mSsid); | |
44 | + if (mBssid) | |
45 | + free(mBssid); | |
46 | + if (mPsk) | |
47 | + free(mPsk); | |
48 | + for (int i = 0; i < 4; i++) { | |
49 | + if (mWepKeys[i]) | |
50 | + free(mWepKeys[i]); | |
51 | + } | |
52 | + if (mHiddenSsid) | |
53 | + free(mHiddenSsid); | |
54 | +} | |
55 | + | |
56 | +int WifiNetwork::setSsid(char *ssid) { | |
57 | + errno = ENOSYS; | |
58 | + return -1; | |
59 | +} | |
60 | + | |
61 | +int WifiNetwork::setBssid(char *bssid) { | |
62 | + errno = ENOSYS; | |
63 | + return -1; | |
64 | +} | |
65 | + | |
66 | +int WifiNetwork::setPsk(char *psk) { | |
67 | + errno = ENOSYS; | |
68 | + return -1; | |
69 | +} | |
70 | + | |
71 | +int WifiNetwork::setWepKey(int idx, char *key) { | |
72 | + errno = ENOSYS; | |
73 | + return -1; | |
74 | +} | |
75 | + | |
76 | +int WifiNetwork::setDefaultKeyIndex(int idx) { | |
77 | + errno = ENOSYS; | |
78 | + return -1; | |
79 | +} | |
80 | + | |
81 | +int WifiNetwork::setPriority(int idx) { | |
82 | + errno = ENOSYS; | |
83 | + return -1; | |
84 | +} | |
85 | + | |
86 | +int WifiNetwork::setHiddenSsid(char *ssid) { | |
87 | + errno = ENOSYS; | |
88 | + return -1; | |
89 | +} | |
90 | + | |
91 | +int WifiNetwork::setAllowedKeyManagement(uint32_t mask) { | |
92 | + errno = ENOSYS; | |
93 | + return -1; | |
94 | +} | |
95 | + | |
96 | +int WifiNetwork::setAllowedProtocols(uint32_t mask) { | |
97 | + errno = ENOSYS; | |
98 | + return -1; | |
99 | +} | |
100 | + | |
101 | +int WifiNetwork::setAllowedPairwiseCiphers(uint32_t mask) { | |
102 | + errno = ENOSYS; | |
103 | + return -1; | |
104 | +} | |
105 | + | |
106 | +int WifiNetwork::setAllowedGroupCiphers(uint32_t mask) { | |
107 | + errno = ENOSYS; | |
108 | + return -1; | |
109 | +} |
@@ -0,0 +1,174 @@ | ||
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 | + | |
22 | +#include "../../../frameworks/base/include/utils/List.h" | |
23 | + | |
24 | +class KeyManagementMask { | |
25 | +public: | |
26 | + static const uint32_t NONE = 0; | |
27 | + static const uint32_t WPA_PSK = 0x01; | |
28 | + static const uint32_t WPA_EAP = 0x02; | |
29 | + static const uint32_t IEEE8021X = 0x04; | |
30 | + static const uint32_t ALL = WPA_PSK | WPA_EAP | IEEE8021X; | |
31 | +}; | |
32 | + | |
33 | +class SecurityProtocolMask { | |
34 | +public: | |
35 | + static const uint32_t WPA = 0x01; | |
36 | + static const uint32_t RSN = 0x02; | |
37 | +}; | |
38 | + | |
39 | +class AuthenticationAlgorithmMask { | |
40 | +public: | |
41 | + static const uint32_t OPEN = 0x01; | |
42 | + static const uint32_t SHARED = 0x02; | |
43 | + static const uint32_t LEAP = 0x04; | |
44 | +}; | |
45 | + | |
46 | +class PairwiseCipherMask { | |
47 | +public: | |
48 | + static const uint32_t NONE = 0x00; | |
49 | + static const uint32_t TKIP = 0x01; | |
50 | + static const uint32_t CCMP = 0x02; | |
51 | +}; | |
52 | + | |
53 | +class GroupCipherMask { | |
54 | +public: | |
55 | + static const uint32_t WEP40 = 0x01; | |
56 | + static const uint32_t WEP104 = 0x02; | |
57 | + static const uint32_t TKIP = 0x04; | |
58 | + static const uint32_t CCMP = 0x08; | |
59 | +}; | |
60 | + | |
61 | +class Supplicant; | |
62 | + | |
63 | +class WifiNetwork { | |
64 | + Supplicant *mSuppl; | |
65 | + | |
66 | + /* | |
67 | + * Unique network id - normally provided by supplicant | |
68 | + */ | |
69 | + int mNetid; | |
70 | + | |
71 | + /* | |
72 | + * The networks' SSID. Can either be an ASCII string, | |
73 | + * which must be enclosed in double quotation marks | |
74 | + * (ie: "MyNetwork"), or a string of hex digits which | |
75 | + * are not enclosed in quotes (ie: 01ab7893) | |
76 | + */ | |
77 | + char *mSsid; | |
78 | + | |
79 | + /* | |
80 | + * When set, this entry should only be used | |
81 | + * when associating with the AP having the specified | |
82 | + * BSSID. The value is a string in the format of an | |
83 | + * Ethernet MAC address | |
84 | + */ | |
85 | + char *mBssid; | |
86 | + | |
87 | + /* | |
88 | + * Pre-shared key for use with WPA-PSK | |
89 | + */ | |
90 | + char *mPsk; | |
91 | + | |
92 | + /* | |
93 | + * Up to four WEP keys. Either in ASCII string enclosed in | |
94 | + * double quotes, or a string of hex digits | |
95 | + */ | |
96 | + char *mWepKeys[4]; | |
97 | + | |
98 | + /* | |
99 | + * Default WEP key index, ranging from 0 -> NUM_WEP_KEYS -1 | |
100 | + */ | |
101 | + int mDefaultKeyIndex; | |
102 | + | |
103 | + /* | |
104 | + * Priority determines the preference given to a network by | |
105 | + * supplicant when choosing an access point with which | |
106 | + * to associate | |
107 | + */ | |
108 | + int mPriority; | |
109 | + | |
110 | + /* | |
111 | + * This is a network that does not broadcast it's SSID, so an | |
112 | + * SSID-specific probe request must be used for scans. | |
113 | + */ | |
114 | + char *mHiddenSsid; | |
115 | + | |
116 | + /* | |
117 | + * The set of key management protocols supported by this configuration. | |
118 | + */ | |
119 | + uint32_t mAllowedKeyManagement; | |
120 | + | |
121 | + /* | |
122 | + * The set of security protocols supported by this configuration. | |
123 | + */ | |
124 | + uint32_t mAllowedProtocols; | |
125 | + | |
126 | + /* | |
127 | + * The set of authentication protocols supported by this configuration. | |
128 | + */ | |
129 | + uint32_t mAllowedAuthAlgorithms; | |
130 | + | |
131 | + /* | |
132 | + * The set of pairwise ciphers for WPA supported by this configuration. | |
133 | + */ | |
134 | + uint32_t mAllowedPairwiseCiphers; | |
135 | + | |
136 | + /* | |
137 | + * The set of group ciphers for WPA supported by this configuration. | |
138 | + */ | |
139 | + uint32_t mAllowedGroupCiphers; | |
140 | + | |
141 | +public: | |
142 | + WifiNetwork(Supplicant *suppl); | |
143 | + virtual ~WifiNetwork(); | |
144 | + | |
145 | + int getNetworkId() { return mNetid; } | |
146 | + const char *getSsid() { return mSsid; } | |
147 | + const char *getBssid() { return mBssid; } | |
148 | + const char *getPsk() { return mPsk; } | |
149 | + const char *getWepKey(int idx) { return mWepKeys[idx]; } | |
150 | + int getDefaultKeyIndex() { return mDefaultKeyIndex; } | |
151 | + int getPriority() { return mPriority; } | |
152 | + const char *getHiddenSsid() { return mHiddenSsid; } | |
153 | + uint32_t getAllowedKeyManagement() { return mAllowedKeyManagement; } | |
154 | + uint32_t getAllowedProtocols() { return mAllowedProtocols; } | |
155 | + uint32_t getAllowedAuthAlgorithms() { return mAllowedAuthAlgorithms; } | |
156 | + uint32_t getAllowedPairwiseCiphers() { return mAllowedPairwiseCiphers; } | |
157 | + uint32_t getAllowedGroupCiphers() { return mAllowedGroupCiphers; } | |
158 | + | |
159 | + int setSsid(char *ssid); | |
160 | + int setBssid(char *bssid); | |
161 | + int setPsk(char *psk); | |
162 | + int setWepKey(int idx, char *key); | |
163 | + int setDefaultKeyIndex(int idx); | |
164 | + int setPriority(int pri); | |
165 | + int setHiddenSsid(char *ssid); | |
166 | + int setAllowedKeyManagement(uint32_t mask); | |
167 | + int setAllowedProtocols(uint32_t mask); | |
168 | + int setAllowedPairwiseCiphers(uint32_t mask); | |
169 | + int setAllowedGroupCiphers(uint32_t mask); | |
170 | +}; | |
171 | + | |
172 | +typedef android::List<WifiNetwork *> WifiNetworkCollection; | |
173 | + | |
174 | +#endif |