system/corennnnn
修訂 | f8b8288c165166adcd09c4c28b099d583715a569 (tree) |
---|---|
時間 | 2009-06-16 06:42:51 |
作者 | Android (Google) Code Review <android-gerrit@goog...> |
Commiter | The Android Open Source Project |
am 43c16197: Merge change 4228 into donut
Merge commit '43c16197b2a6da3a3125b4a4a9fa6b70f447043e'
* commit '43c16197b2a6da3a3125b4a4a9fa6b70f447043e':
@@ -5,26 +5,35 @@ LOCAL_PATH:= $(call my-dir) | ||
5 | 5 | |
6 | 6 | include $(CLEAR_VARS) |
7 | 7 | |
8 | -LOCAL_SRC_FILES:= \ | |
9 | - main.cpp \ | |
10 | - NetworkManager.cpp \ | |
11 | - CommandListener.cpp \ | |
12 | - Controller.cpp \ | |
13 | - WifiController.cpp \ | |
14 | - LoopController.cpp \ | |
15 | - NexusCommand.cpp \ | |
16 | - TiwlanWifiController.cpp \ | |
17 | - Supplicant.cpp \ | |
18 | - SupplicantEvent.cpp \ | |
19 | - SupplicantListener.cpp \ | |
20 | - VpnController.cpp \ | |
21 | - ScanResult.cpp \ | |
22 | - WifiScanner.cpp \ | |
23 | - WifiNetwork.cpp \ | |
24 | - OpenVpnController.cpp \ | |
25 | - InterfaceConfig.cpp \ | |
26 | - PropertyManager.cpp \ | |
27 | - SupplicantState.cpp | |
8 | +LOCAL_SRC_FILES:= \ | |
9 | + main.cpp \ | |
10 | + NetworkManager.cpp \ | |
11 | + CommandListener.cpp \ | |
12 | + Controller.cpp \ | |
13 | + WifiController.cpp \ | |
14 | + LoopController.cpp \ | |
15 | + NexusCommand.cpp \ | |
16 | + TiwlanWifiController.cpp \ | |
17 | + Supplicant.cpp \ | |
18 | + SupplicantEvent.cpp \ | |
19 | + SupplicantListener.cpp \ | |
20 | + VpnController.cpp \ | |
21 | + ScanResult.cpp \ | |
22 | + WifiScanner.cpp \ | |
23 | + WifiNetwork.cpp \ | |
24 | + OpenVpnController.cpp \ | |
25 | + InterfaceConfig.cpp \ | |
26 | + PropertyManager.cpp \ | |
27 | + SupplicantState.cpp \ | |
28 | + SupplicantEventFactory.cpp \ | |
29 | + SupplicantConnectedEvent.cpp \ | |
30 | + SupplicantAssociatingEvent.cpp \ | |
31 | + SupplicantAssociatedEvent.cpp \ | |
32 | + SupplicantStateChangeEvent.cpp \ | |
33 | + SupplicantScanResultsEvent.cpp \ | |
34 | + SupplicantConnectionTimeoutEvent.cpp \ | |
35 | + SupplicantDisconnectedEvent.cpp \ | |
36 | + SupplicantStatus.cpp | |
28 | 37 | |
29 | 38 | LOCAL_MODULE:= nexus |
30 | 39 |
@@ -53,7 +53,8 @@ CommandListener::WifiCreateNetworkCmd::WifiCreateNetworkCmd() : | ||
53 | 53 | NexusCommand("wifi_create_network") { |
54 | 54 | } |
55 | 55 | |
56 | -int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli, char *data) { | |
56 | +int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli, | |
57 | + int argc, char **argv) { | |
57 | 58 | NetworkManager *nm = NetworkManager::Instance(); |
58 | 59 | WifiController *wc = (WifiController *) nm->findController("WIFI"); |
59 | 60 | WifiNetwork *wn; |
@@ -72,11 +73,12 @@ CommandListener::WifiRemoveNetworkCmd::WifiRemoveNetworkCmd() : | ||
72 | 73 | NexusCommand("wifi_remove_network") { |
73 | 74 | } |
74 | 75 | |
75 | -int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli, char *data) { | |
76 | +int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli, | |
77 | + int argc, char **argv) { | |
76 | 78 | NetworkManager *nm = NetworkManager::Instance(); |
77 | 79 | WifiController *wc = (WifiController *) nm->findController("WIFI"); |
78 | 80 | |
79 | - if (wc->removeNetwork(atoi(data))) | |
81 | + if (wc->removeNetwork(atoi(argv[1]))) | |
80 | 82 | cli->sendMsg(ErrorCode::OperationFailed, "Failed to remove network", true); |
81 | 83 | else { |
82 | 84 | cli->sendMsg(ErrorCode::CommandOkay, "Network removed.", false); |
@@ -88,7 +90,8 @@ CommandListener::WifiScanResultsCmd::WifiScanResultsCmd() : | ||
88 | 90 | NexusCommand("wifi_scan_results") { |
89 | 91 | } |
90 | 92 | |
91 | -int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *data) { | |
93 | +int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, | |
94 | + int argc, char **argv) { | |
92 | 95 | NetworkManager *nm = NetworkManager::Instance(); |
93 | 96 | WifiController *wc = (WifiController *) nm->findController("WIFI"); |
94 | 97 |
@@ -114,7 +117,8 @@ CommandListener::WifiListNetworksCmd::WifiListNetworksCmd() : | ||
114 | 117 | NexusCommand("wifi_list_networks") { |
115 | 118 | } |
116 | 119 | |
117 | -int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli, char *data) { | |
120 | +int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli, | |
121 | + int argc, char **argv) { | |
118 | 122 | NetworkManager *nm = NetworkManager::Instance(); |
119 | 123 | WifiController *wc = (WifiController *) nm->findController("WIFI"); |
120 | 124 |
@@ -144,23 +148,19 @@ CommandListener::GetCmd::GetCmd() : | ||
144 | 148 | NexusCommand("get") { |
145 | 149 | } |
146 | 150 | |
147 | -int CommandListener::GetCmd::runCommand(SocketClient *cli, char *data) { | |
148 | - char *next = data; | |
149 | - char *propname; | |
151 | +int CommandListener::GetCmd::runCommand(SocketClient *cli, int argc, char **argv) { | |
152 | + char val[Property::ValueMaxSize]; | |
150 | 153 | |
151 | - if (!(propname = strsep(&next, ":"))) | |
152 | - goto out_inval; | |
153 | - | |
154 | - char pb[Property::NameMaxSize + 6]; | |
155 | - snprintf(pb, sizeof(pb), "%s:", propname); | |
156 | - | |
157 | - if (!NetworkManager::Instance()->getPropMngr()->get(propname, | |
158 | - &pb[strlen(pb)], | |
159 | - sizeof(pb) - strlen(pb))) { | |
154 | + if (!NetworkManager::Instance()->getPropMngr()->get(argv[1], | |
155 | + val, | |
156 | + sizeof(val))) { | |
160 | 157 | goto out_inval; |
161 | 158 | } |
162 | 159 | |
163 | - cli->sendMsg(ErrorCode::PropertyRead, pb, false); | |
160 | + char *tmp; | |
161 | + asprintf(&tmp, "%s %s", argv[1], val); | |
162 | + cli->sendMsg(ErrorCode::PropertyRead, tmp, false); | |
163 | + free(tmp); | |
164 | 164 | |
165 | 165 | cli->sendMsg(ErrorCode::CommandOkay, "Property read.", false); |
166 | 166 | return 0; |
@@ -174,23 +174,9 @@ CommandListener::SetCmd::SetCmd() : | ||
174 | 174 | NexusCommand("set") { |
175 | 175 | } |
176 | 176 | |
177 | -int CommandListener::SetCmd::runCommand(SocketClient *cli, char *data) { | |
178 | - char *bword; | |
179 | - char *last; | |
180 | - char propname[Property::NameMaxSize]; | |
181 | - char propval[Property::ValueMaxSize]; | |
182 | - | |
183 | - if (!(bword = strtok_r(data, ":", &last))) | |
184 | - goto out_inval; | |
185 | - | |
186 | - strncpy(propname, bword, sizeof(propname)); | |
187 | - | |
188 | - if (!(bword = strtok_r(NULL, ":", &last))) | |
189 | - goto out_inval; | |
190 | - | |
191 | - strncpy(propval, bword, sizeof(propval)); | |
192 | - | |
193 | - if (NetworkManager::Instance()->getPropMngr()->set(propname, propval)) | |
177 | +int CommandListener::SetCmd::runCommand(SocketClient *cli, int argc, | |
178 | + char **argv) { | |
179 | + if (NetworkManager::Instance()->getPropMngr()->set(argv[1], argv[2])) | |
194 | 180 | goto out_inval; |
195 | 181 | |
196 | 182 | cli->sendMsg(ErrorCode::CommandOkay, "Property set.", false); |
@@ -206,7 +192,7 @@ CommandListener::ListCmd::ListCmd() : | ||
206 | 192 | NexusCommand("list") { |
207 | 193 | } |
208 | 194 | |
209 | -int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) { | |
195 | +int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **argv) { | |
210 | 196 | android::List<char *> *pc; |
211 | 197 | |
212 | 198 | if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList())) { |
@@ -227,7 +213,7 @@ int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) { | ||
227 | 213 | } |
228 | 214 | |
229 | 215 | char *buf; |
230 | - if (asprintf(&buf, "%s:%s", (*it), p_v) < 0) { | |
216 | + if (asprintf(&buf, "%s %s", (*it), p_v) < 0) { | |
231 | 217 | LOGE("Failed to allocate memory"); |
232 | 218 | free((*it)); |
233 | 219 | continue; |
@@ -31,56 +31,56 @@ private: | ||
31 | 31 | public: |
32 | 32 | WifiScanCmd(); |
33 | 33 | virtual ~WifiScanCmd() {} |
34 | - int runCommand(SocketClient *c, char *data); | |
34 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
35 | 35 | }; |
36 | 36 | |
37 | 37 | class WifiScanResultsCmd : public NexusCommand { |
38 | 38 | public: |
39 | 39 | WifiScanResultsCmd(); |
40 | 40 | virtual ~WifiScanResultsCmd() {} |
41 | - int runCommand(SocketClient *c, char *data); | |
41 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
42 | 42 | }; |
43 | 43 | |
44 | 44 | class WifiCreateNetworkCmd : public NexusCommand { |
45 | 45 | public: |
46 | 46 | WifiCreateNetworkCmd(); |
47 | 47 | virtual ~WifiCreateNetworkCmd() {} |
48 | - int runCommand(SocketClient *c, char *data); | |
48 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
49 | 49 | }; |
50 | 50 | |
51 | 51 | class WifiRemoveNetworkCmd : public NexusCommand { |
52 | 52 | public: |
53 | 53 | WifiRemoveNetworkCmd(); |
54 | 54 | virtual ~WifiRemoveNetworkCmd() {} |
55 | - int runCommand(SocketClient *c, char *data); | |
55 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
56 | 56 | }; |
57 | 57 | |
58 | 58 | class WifiListNetworksCmd : public NexusCommand { |
59 | 59 | public: |
60 | 60 | WifiListNetworksCmd(); |
61 | 61 | virtual ~WifiListNetworksCmd() {} |
62 | - int runCommand(SocketClient *c, char *data); | |
62 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
63 | 63 | }; |
64 | 64 | |
65 | 65 | class SetCmd : public NexusCommand { |
66 | 66 | public: |
67 | 67 | SetCmd(); |
68 | 68 | virtual ~SetCmd() {} |
69 | - int runCommand(SocketClient *c, char *data); | |
69 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
70 | 70 | }; |
71 | 71 | |
72 | 72 | class GetCmd : public NexusCommand { |
73 | 73 | public: |
74 | 74 | GetCmd(); |
75 | 75 | virtual ~GetCmd() {} |
76 | - int runCommand(SocketClient *c, char *data); | |
76 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
77 | 77 | }; |
78 | 78 | |
79 | 79 | class ListCmd : public NexusCommand { |
80 | 80 | public: |
81 | 81 | ListCmd(); |
82 | 82 | virtual ~ListCmd() {} |
83 | - int runCommand(SocketClient *c, char *data); | |
83 | + int runCommand(SocketClient *c, int argc, char ** argv); | |
84 | 84 | }; |
85 | 85 | }; |
86 | 86 |
@@ -34,9 +34,11 @@ | ||
34 | 34 | extern "C" int init_module(void *, unsigned int, const char *); |
35 | 35 | extern "C" int delete_module(const char *, unsigned int); |
36 | 36 | |
37 | -Controller::Controller(const char *name, PropertyManager *propMngr) { | |
37 | +Controller::Controller(const char *name, PropertyManager *propMngr, | |
38 | + IControllerHandler *handlers) { | |
38 | 39 | mPropMngr = propMngr; |
39 | 40 | mName = strdup(name); |
41 | + mHandlers = handlers; | |
40 | 42 | mBoundInterface = NULL; |
41 | 43 | } |
42 | 44 |
@@ -23,12 +23,12 @@ | ||
23 | 23 | #include <utils/List.h> |
24 | 24 | |
25 | 25 | class PropertyManager; |
26 | +class IControllerHandler; | |
26 | 27 | |
27 | 28 | #include "PropertyManager.h" |
28 | 29 | #include "IPropertyProvider.h" |
29 | 30 | |
30 | 31 | class Controller : public IPropertyProvider { |
31 | -private: | |
32 | 32 | /* |
33 | 33 | * Name of this controller - WIFI/VPN/USBNET/BTNET/BTDUN/LOOP/etc |
34 | 34 | */ |
@@ -42,9 +42,11 @@ private: | ||
42 | 42 | |
43 | 43 | protected: |
44 | 44 | PropertyManager *mPropMngr; |
45 | + IControllerHandler *mHandlers; | |
45 | 46 | |
46 | 47 | public: |
47 | - Controller(const char *name, PropertyManager *propMngr); | |
48 | + Controller(const char *name, PropertyManager *propMngr, | |
49 | + IControllerHandler *handlers); | |
48 | 50 | virtual ~Controller(); |
49 | 51 | |
50 | 52 | virtual int start(); |
@@ -0,0 +1,30 @@ | ||
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 _ICONTROLLER_HANDLER_H | |
18 | +#define _ICONTROLLER_HANDLER_H | |
19 | + | |
20 | +class Controller; | |
21 | +class InterfaceConfig; | |
22 | + | |
23 | +class IControllerHandler { | |
24 | +public: | |
25 | + virtual void onInterfaceStarted(Controller *c, const InterfaceConfig *cfg) = 0; | |
26 | + virtual void onInterfaceStopping(Controller *c, const char *name) = 0; | |
27 | +}; | |
28 | + | |
29 | +#endif | |
30 | + |
@@ -17,21 +17,34 @@ | ||
17 | 17 | #ifndef _ISUPPLICANT_EVENT_HANDLER_H |
18 | 18 | #define _ISUPPLICANT_EVENT_HANDLER_H |
19 | 19 | |
20 | +class SupplicantAssociatingEvent; | |
21 | +class SupplicantAssociatedEvent; | |
22 | +class SupplicantConnectedEvent; | |
23 | +class SupplicantScanResultsEvent; | |
24 | +class SupplicantStateChangeEvent; | |
25 | +class SupplicantConnectionTimeoutEvent; | |
26 | +class SupplicantDisconnectedEvent; | |
27 | + | |
20 | 28 | class ISupplicantEventHandler { |
21 | 29 | public: |
22 | - virtual int onConnectedEvent(SupplicantEvent *evt) = 0; | |
23 | - virtual int onDisconnectedEvent(SupplicantEvent *evt) = 0; | |
24 | - virtual int onTerminatingEvent(SupplicantEvent *evt) = 0; | |
25 | - virtual int onPasswordChangedEvent(SupplicantEvent *evt) = 0; | |
26 | - virtual int onEapNotificationEvent(SupplicantEvent *evt) = 0; | |
27 | - virtual int onEapStartedEvent(SupplicantEvent *evt) = 0; | |
28 | - virtual int onEapMethodEvent(SupplicantEvent *evt) = 0; | |
29 | - virtual int onEapSuccessEvent(SupplicantEvent *evt) = 0; | |
30 | - virtual int onEapFailureEvent(SupplicantEvent *evt) = 0; | |
31 | - virtual int onScanResultsEvent(SupplicantEvent *evt) = 0; | |
32 | - virtual int onStateChangeEvent(SupplicantEvent *evt) = 0; | |
33 | - virtual int onLinkSpeedEvent(SupplicantEvent *evt) = 0; | |
34 | - virtual int onDriverStateEvent(SupplicantEvent *evt) = 0; | |
30 | + virtual void onAssociatingEvent(SupplicantAssociatingEvent *evt) = 0; | |
31 | + virtual void onAssociatedEvent(SupplicantAssociatedEvent *evt) = 0; | |
32 | + virtual void onConnectedEvent(SupplicantConnectedEvent *evt) = 0; | |
33 | + virtual void onScanResultsEvent(SupplicantScanResultsEvent *evt) = 0; | |
34 | + virtual void onStateChangeEvent(SupplicantStateChangeEvent *evt) = 0; | |
35 | + virtual void onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt) = 0; | |
36 | + virtual void onDisconnectedEvent(SupplicantDisconnectedEvent *evt) = 0; | |
37 | +#if 0 | |
38 | + virtual void onTerminatingEvent(SupplicantEvent *evt) = 0; | |
39 | + virtual void onPasswordChangedEvent(SupplicantEvent *evt) = 0; | |
40 | + virtual void onEapNotificationEvent(SupplicantEvent *evt) = 0; | |
41 | + virtual void onEapStartedEvent(SupplicantEvent *evt) = 0; | |
42 | + virtual void onEapMethodEvent(SupplicantEvent *evt) = 0; | |
43 | + virtual void onEapSuccessEvent(SupplicantEvent *evt) = 0; | |
44 | + virtual void onEapFailureEvent(SupplicantEvent *evt) = 0; | |
45 | + virtual void onLinkSpeedEvent(SupplicantEvent *evt) = 0; | |
46 | + virtual void onDriverStateEvent(SupplicantEvent *evt) = 0; | |
47 | +#endif | |
35 | 48 | }; |
36 | 49 | |
37 | 50 | #endif |
@@ -19,8 +19,9 @@ | ||
19 | 19 | #include "LoopController.h" |
20 | 20 | #include "PropertyManager.h" |
21 | 21 | |
22 | -LoopController::LoopController(PropertyManager *propmngr) : | |
23 | - Controller("LOOP", propmngr) { | |
22 | +LoopController::LoopController(PropertyManager *propmngr, | |
23 | + IControllerHandler *handlers) : | |
24 | + Controller("LOOP", propmngr, handlers) { | |
24 | 25 | } |
25 | 26 | |
26 | 27 | int LoopController::set(const char *name, const char *value) { |
@@ -19,10 +19,11 @@ | ||
19 | 19 | |
20 | 20 | #include "Controller.h" |
21 | 21 | |
22 | +class ControllerHandler; | |
22 | 23 | |
23 | 24 | class LoopController : public Controller { |
24 | 25 | public: |
25 | - LoopController(PropertyManager *propmngr); | |
26 | + LoopController(PropertyManager *propmngr, IControllerHandler *h); | |
26 | 27 | virtual ~LoopController() {} |
27 | 28 | |
28 | 29 | int set(const char *name, const char *value); |
@@ -89,23 +89,26 @@ Controller *NetworkManager::findController(const char *name) { | ||
89 | 89 | return NULL; |
90 | 90 | } |
91 | 91 | |
92 | -int NetworkManager::onInterfaceStart(Controller *c, const InterfaceConfig *cfg) { | |
92 | +void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cfg) { | |
93 | 93 | LOGD("Interface %s started by controller %s", c->getBoundInterface(), c->getName()); |
94 | 94 | |
95 | 95 | // Look up the interface |
96 | 96 | |
97 | 97 | if (0) { // already started? |
98 | - errno = EADDRINUSE; | |
99 | - return -1; | |
100 | 98 | } |
101 | 99 | |
102 | - if (cfg->getUseDhcp()) { | |
100 | + if (cfg) { | |
101 | + if (cfg->getUseDhcp()) { | |
102 | + // Launch DHCP thread | |
103 | + } else { | |
104 | + // Static configuration | |
105 | + } | |
103 | 106 | } else { |
107 | + LOGD("No InterfaceConfig for %s:%s - assuming self-managed", | |
108 | + c->getName(), c->getBoundInterface()); | |
104 | 109 | } |
105 | - return 0; | |
106 | 110 | } |
107 | 111 | |
108 | -int NetworkManager::onInterfaceStop(Controller *c, const char *name) { | |
112 | +void NetworkManager::onInterfaceStopping(Controller *c, const char *name) { | |
109 | 113 | LOGD("Interface %s stopped by controller %s", name, c->getName()); |
110 | - return 0; | |
111 | 114 | } |
@@ -20,12 +20,12 @@ | ||
20 | 20 | #include <sysutils/SocketListener.h> |
21 | 21 | |
22 | 22 | #include "Controller.h" |
23 | - | |
24 | 23 | #include "PropertyManager.h" |
24 | +#include "IControllerHandler.h" | |
25 | 25 | |
26 | 26 | class InterfaceConfig; |
27 | 27 | |
28 | -class NetworkManager { | |
28 | +class NetworkManager : public IControllerHandler { | |
29 | 29 | private: |
30 | 30 | static NetworkManager *sInstance; |
31 | 31 |
@@ -55,16 +55,7 @@ private: | ||
55 | 55 | |
56 | 56 | NetworkManager(PropertyManager *propMngr); |
57 | 57 | |
58 | -public: | |
59 | - /* | |
60 | - * Called from a controller when an interface is available/ready for use. | |
61 | - * 'cfg' contains information on how this interface should be configured. | |
62 | - */ | |
63 | - int onInterfaceStart(Controller *c, const InterfaceConfig *cfg); | |
64 | - | |
65 | - /* | |
66 | - * Called from a controller when an interface should be shut down | |
67 | - */ | |
68 | - int onInterfaceStop(Controller *c, const char *name); | |
58 | + void onInterfaceStarted(Controller *c, const InterfaceConfig *cfg); | |
59 | + void onInterfaceStopping(Controller *c, const char *name); | |
69 | 60 | }; |
70 | 61 | #endif |
@@ -30,8 +30,9 @@ | ||
30 | 30 | #define DAEMON_PROP_NAME "vpn.openvpn.status" |
31 | 31 | #define DAEMON_CONFIG_FILE "/data/misc/openvpn/openvpn.conf" |
32 | 32 | |
33 | -OpenVpnController::OpenVpnController(PropertyManager *propmngr) : | |
34 | - VpnController(propmngr) { | |
33 | +OpenVpnController::OpenVpnController(PropertyManager *propmngr, | |
34 | + IControllerHandler *handlers) : | |
35 | + VpnController(propmngr, handlers) { | |
35 | 36 | mServiceManager = new ServiceManager(); |
36 | 37 | } |
37 | 38 |
@@ -40,11 +41,11 @@ OpenVpnController::~OpenVpnController() { | ||
40 | 41 | } |
41 | 42 | |
42 | 43 | int OpenVpnController::start() { |
43 | - return 0; | |
44 | + return VpnController::start(); | |
44 | 45 | } |
45 | 46 | |
46 | 47 | int OpenVpnController::stop() { |
47 | - return 0; | |
48 | + return VpnController::stop(); | |
48 | 49 | } |
49 | 50 | |
50 | 51 | int OpenVpnController::enable() { |
@@ -21,13 +21,14 @@ | ||
21 | 21 | #include "VpnController.h" |
22 | 22 | |
23 | 23 | class ServiceManager; |
24 | +class IControllerHandler; | |
24 | 25 | |
25 | 26 | class OpenVpnController : public VpnController { |
26 | 27 | private: |
27 | 28 | ServiceManager *mServiceManager; |
28 | 29 | |
29 | 30 | public: |
30 | - OpenVpnController(PropertyManager *propmngr); | |
31 | + OpenVpnController(PropertyManager *propmngr, IControllerHandler *handlers); | |
31 | 32 | virtual ~OpenVpnController(); |
32 | 33 | |
33 | 34 | int start(); |
@@ -37,7 +37,8 @@ int PropertyManager::registerProperty(const char *name, IPropertyProvider *pp) { | ||
37 | 37 | for (it = mPropertyPairs->begin(); it != mPropertyPairs->end(); ++it) { |
38 | 38 | if (!strcmp(name, (*it)->getName())) { |
39 | 39 | errno = EADDRINUSE; |
40 | - LOGE("Failed to register property (%s)", strerror(errno)); | |
40 | + LOGE("Failed to register property %s (%s)", | |
41 | + name, strerror(errno)); | |
41 | 42 | pthread_mutex_unlock(&mLock); |
42 | 43 | return -1; |
43 | 44 | } |
@@ -29,13 +29,10 @@ | ||
29 | 29 | |
30 | 30 | #include "Supplicant.h" |
31 | 31 | #include "SupplicantListener.h" |
32 | -#include "SupplicantState.h" | |
33 | -#include "SupplicantEvent.h" | |
34 | -#include "ScanResult.h" | |
35 | -#include "PropertyManager.h" | |
36 | 32 | #include "NetworkManager.h" |
37 | 33 | #include "ErrorCode.h" |
38 | 34 | #include "WifiController.h" |
35 | +#include "SupplicantStatus.h" | |
39 | 36 | |
40 | 37 | #include "libwpa_client/wpa_ctrl.h" |
41 | 38 |
@@ -45,21 +42,16 @@ | ||
45 | 42 | #define SUPP_CONFIG_TEMPLATE "/system/etc/wifi/wpa_supplicant.conf" |
46 | 43 | #define SUPP_CONFIG_FILE "/data/misc/wifi/wpa_supplicant.conf" |
47 | 44 | |
48 | -Supplicant::Supplicant(WifiController *wc, PropertyManager *propmngr) { | |
45 | +Supplicant::Supplicant(WifiController *wc, ISupplicantEventHandler *handlers) { | |
46 | + mHandlers = handlers; | |
49 | 47 | mController = wc; |
50 | - mPropMngr = propmngr; | |
51 | 48 | mInterfaceName = NULL; |
52 | 49 | mCtrl = NULL; |
53 | 50 | mMonitor = NULL; |
54 | 51 | mListener = NULL; |
55 | 52 | |
56 | - mState = SupplicantState::UNKNOWN; | |
57 | - | |
58 | 53 | mServiceManager = new ServiceManager(); |
59 | 54 | |
60 | - mLatestScanResults = new ScanResultCollection(); | |
61 | - pthread_mutex_init(&mLatestScanResultsLock, NULL); | |
62 | - | |
63 | 55 | mNetworks = new WifiNetworkCollection(); |
64 | 56 | pthread_mutex_init(&mNetworksLock, NULL); |
65 | 57 | } |
@@ -92,14 +84,11 @@ int Supplicant::start() { | ||
92 | 84 | return -1; |
93 | 85 | } |
94 | 86 | |
95 | - mPropMngr->registerProperty("wifi.supplicant.state", this); | |
96 | 87 | return 0; |
97 | 88 | } |
98 | 89 | |
99 | 90 | int Supplicant::stop() { |
100 | 91 | |
101 | - mPropMngr->unregisterProperty("wifi.supplicant.state"); | |
102 | - | |
103 | 92 | if (mListener->stopListener()) { |
104 | 93 | LOGW("Unable to stop supplicant listener (%s)", strerror(errno)); |
105 | 94 | return -1; |
@@ -125,6 +114,30 @@ bool Supplicant::isStarted() { | ||
125 | 114 | return mServiceManager->isRunning(SUPPLICANT_SERVICE_NAME); |
126 | 115 | } |
127 | 116 | |
117 | +SupplicantStatus *Supplicant::getStatus() { | |
118 | + char *reply; | |
119 | + size_t len = 4096; | |
120 | + | |
121 | + if (!(reply = (char *) malloc(len))) { | |
122 | + errno = ENOMEM; | |
123 | + return NULL; | |
124 | + } | |
125 | + | |
126 | + if (sendCommand("STATUS", reply, &len)) { | |
127 | + free(reply); | |
128 | + return NULL; | |
129 | + } | |
130 | + | |
131 | + SupplicantStatus *ss = SupplicantStatus::createStatus(reply, len); | |
132 | + | |
133 | + free (reply); | |
134 | + return ss; | |
135 | +} | |
136 | + | |
137 | +/* | |
138 | + * Retrieves the list of networks from Supplicant | |
139 | + * and merge them into our current list | |
140 | + */ | |
128 | 141 | int Supplicant::refreshNetworkList() { |
129 | 142 | char *reply; |
130 | 143 | size_t len = 4096; |
@@ -144,27 +157,59 @@ int Supplicant::refreshNetworkList() { | ||
144 | 157 | |
145 | 158 | if (!strtok_r(reply, "\n", &linep_next)) { |
146 | 159 | LOGW("Malformatted network list\n"); |
147 | - } else { | |
148 | - pthread_mutex_lock(&mNetworksLock); | |
149 | - if (!mNetworks->empty()) { | |
150 | - WifiNetworkCollection::iterator i; | |
151 | - | |
152 | - for (i = mNetworks->begin(); i !=mNetworks->end(); ++i) | |
153 | - delete *i; | |
154 | - mNetworks->clear(); | |
155 | - } | |
160 | + free(reply); | |
161 | + errno = EIO; | |
162 | + return -1; | |
163 | + } | |
156 | 164 | |
157 | - while((linep = strtok_r(NULL, "\n", &linep_next))) { | |
158 | - WifiNetwork *wn = new WifiNetwork(mController, this, linep); | |
159 | - mNetworks->push_back(wn); | |
160 | - if (wn->refresh()) | |
161 | - LOGW("Unable to refresh network id %d", wn->getNetworkId()); | |
165 | + pthread_mutex_lock(&mNetworksLock); | |
166 | + | |
167 | + int num_added = 0; | |
168 | + int num_refreshed = 0; | |
169 | + int num_removed = 0; | |
170 | + while((linep = strtok_r(NULL, "\n", &linep_next))) { | |
171 | + // TODO: Move the decode into a static method so we | |
172 | + // don't create new_wn when we don't have to. | |
173 | + WifiNetwork *new_wn = new WifiNetwork(mController, this, linep); | |
174 | + WifiNetwork *merge_wn; | |
175 | + | |
176 | + if ((merge_wn = this->lookupNetwork_UNLOCKED(new_wn->getNetworkId()))) { | |
177 | + num_refreshed++; | |
178 | + if (merge_wn->refresh()) { | |
179 | + LOGW("Error refreshing network %d (%s)", | |
180 | + merge_wn->getNetworkId(), strerror(errno)); | |
181 | + } | |
182 | + delete new_wn; | |
183 | + } else { | |
184 | + num_added++; | |
185 | + new_wn->registerProperties(); | |
186 | + mNetworks->push_back(new_wn); | |
187 | + if (new_wn->refresh()) { | |
188 | + LOGW("Unable to refresh network id %d (%s)", | |
189 | + new_wn->getNetworkId(), strerror(errno)); | |
190 | + } | |
162 | 191 | } |
192 | + } | |
163 | 193 | |
164 | - LOGD("Loaded %d networks\n", mNetworks->size()); | |
165 | - pthread_mutex_unlock(&mNetworksLock); | |
194 | + if (!mNetworks->empty()) { | |
195 | + // TODO: Add support for detecting removed networks | |
196 | + WifiNetworkCollection::iterator i; | |
197 | + | |
198 | + for (i = mNetworks->begin(); i != mNetworks->end(); ++i) { | |
199 | + if (0) { | |
200 | + num_removed++; | |
201 | + (*i)->unregisterProperties(); | |
202 | + delete (*i); | |
203 | + i = mNetworks->erase(i); | |
204 | + } | |
205 | + } | |
166 | 206 | } |
167 | 207 | |
208 | + | |
209 | + LOGD("Networks added %d, refreshed %d, removed %d\n", | |
210 | + num_added, num_refreshed, num_removed); | |
211 | + pthread_mutex_unlock(&mNetworksLock); | |
212 | + | |
168 | 213 | free(reply); |
169 | 214 | return 0; |
170 | 215 | } |
@@ -192,7 +237,7 @@ int Supplicant::connectToSupplicant() { | ||
192 | 237 | return -1; |
193 | 238 | } |
194 | 239 | |
195 | - mListener = new SupplicantListener(this, mMonitor); | |
240 | + mListener = new SupplicantListener(mHandlers, mMonitor); | |
196 | 241 | |
197 | 242 | if (mListener->startListener()) { |
198 | 243 | LOGE("Error - unable to start supplicant listener"); |
@@ -245,165 +290,6 @@ int Supplicant::triggerScan(bool active) { | ||
245 | 290 | return 0; |
246 | 291 | } |
247 | 292 | |
248 | -int Supplicant::set(const char *name, const char *value) { | |
249 | - const char *n = name + strlen("wifi.supplicant."); | |
250 | - | |
251 | - errno = -EROFS; | |
252 | - return -1; | |
253 | -} | |
254 | - | |
255 | -const char *Supplicant::get(const char *name, char *buffer, size_t max) { | |
256 | - const char *n = name + strlen("wifi.supplicant."); | |
257 | - | |
258 | - if (!strcasecmp(n, "state")) | |
259 | - return SupplicantState::toString(mState, buffer, max); | |
260 | - errno = ENOENT; | |
261 | - return NULL; | |
262 | -} | |
263 | - | |
264 | -int Supplicant::onConnectedEvent(SupplicantEvent *evt) { | |
265 | - LOGD("onConnectedEvent(%s)", evt->getEvent()); | |
266 | - return 0; | |
267 | -} | |
268 | - | |
269 | -int Supplicant::onDisconnectedEvent(SupplicantEvent *evt) { | |
270 | - LOGD("onDisconnectedEvent(%s)", evt->getEvent()); | |
271 | - return 0; | |
272 | -} | |
273 | - | |
274 | -int Supplicant::onTerminatingEvent(SupplicantEvent *evt) { | |
275 | - LOGD("onTerminatingEvent(%s)", evt->getEvent()); | |
276 | - return 0; | |
277 | -} | |
278 | - | |
279 | -int Supplicant::onPasswordChangedEvent(SupplicantEvent *evt) { | |
280 | - LOGD("onPasswordChangedEvent(%s)", evt->getEvent()); | |
281 | - return 0; | |
282 | -} | |
283 | - | |
284 | -int Supplicant::onEapNotificationEvent(SupplicantEvent *evt) { | |
285 | - LOGD("onEapNotificationEvent(%s)", evt->getEvent()); | |
286 | - return 0; | |
287 | -} | |
288 | - | |
289 | -int Supplicant::onEapStartedEvent(SupplicantEvent *evt) { | |
290 | - LOGD("onEapStartedEvent(%s)", evt->getEvent()); | |
291 | - return 0; | |
292 | -} | |
293 | - | |
294 | -int Supplicant::onEapMethodEvent(SupplicantEvent *evt) { | |
295 | - LOGD("onEapMethodEvent(%s)", evt->getEvent()); | |
296 | - return 0; | |
297 | -} | |
298 | - | |
299 | -int Supplicant::onEapSuccessEvent(SupplicantEvent *evt) { | |
300 | - LOGD("onEapSuccessEvent(%s)", evt->getEvent()); | |
301 | - return 0; | |
302 | -} | |
303 | - | |
304 | -int Supplicant::onEapFailureEvent(SupplicantEvent *evt) { | |
305 | - LOGD("onEapFailureEvent(%s)", evt->getEvent()); | |
306 | - return 0; | |
307 | -} | |
308 | - | |
309 | -int Supplicant::onScanResultsEvent(SupplicantEvent *evt) { | |
310 | - if (!strcmp(evt->getEvent(), "Ready")) { | |
311 | - char *reply; | |
312 | - | |
313 | - if (!(reply = (char *) malloc(4096))) { | |
314 | - errno = ENOMEM; | |
315 | - return -1; | |
316 | - } | |
317 | - | |
318 | - size_t len = 4096; | |
319 | - | |
320 | - if (sendCommand("SCAN_RESULTS", reply, &len)) { | |
321 | - LOGW("onScanResultsEvent(%s): Error getting scan results (%s)", | |
322 | - evt->getEvent(), strerror(errno)); | |
323 | - free(reply); | |
324 | - return -1; | |
325 | - } | |
326 | - | |
327 | - pthread_mutex_lock(&mLatestScanResultsLock); | |
328 | - if (!mLatestScanResults->empty()) { | |
329 | - ScanResultCollection::iterator i; | |
330 | - | |
331 | - for (i = mLatestScanResults->begin(); | |
332 | - i !=mLatestScanResults->end(); ++i) { | |
333 | - delete *i; | |
334 | - } | |
335 | - mLatestScanResults->clear(); | |
336 | - } | |
337 | - | |
338 | - char *linep; | |
339 | - char *linep_next = NULL; | |
340 | - | |
341 | - if (!strtok_r(reply, "\n", &linep_next)) { | |
342 | - free(reply); | |
343 | - pthread_mutex_unlock(&mLatestScanResultsLock); | |
344 | - return 0; | |
345 | - } | |
346 | - | |
347 | - while((linep = strtok_r(NULL, "\n", &linep_next))) | |
348 | - mLatestScanResults->push_back(new ScanResult(linep)); | |
349 | - | |
350 | - char tmp[128]; | |
351 | - sprintf(tmp, "Scan results ready (%d)", mLatestScanResults->size()); | |
352 | - NetworkManager::Instance()->getBroadcaster()-> | |
353 | - sendBroadcast(ErrorCode::UnsolicitedInformational, tmp, false); | |
354 | - pthread_mutex_unlock(&mLatestScanResultsLock); | |
355 | - free(reply); | |
356 | - } else { | |
357 | - LOGW("Unknown SCAN_RESULTS event (%s)", evt->getEvent()); | |
358 | - } | |
359 | - return 0; | |
360 | -} | |
361 | - | |
362 | -int Supplicant::onStateChangeEvent(SupplicantEvent *evt) { | |
363 | - char *bword, *last; | |
364 | - char *tmp = strdup(evt->getEvent()); | |
365 | - | |
366 | - if (!(bword = strtok_r(tmp, " ", &last))) { | |
367 | - LOGE("Malformatted state update (%s)", evt->getEvent()); | |
368 | - free(tmp); | |
369 | - return 0; | |
370 | - } | |
371 | - | |
372 | - if (!(bword = strtok_r(NULL, " ", &last))) { | |
373 | - LOGE("Malformatted state update (%s)", evt->getEvent()); | |
374 | - free(tmp); | |
375 | - return 0; | |
376 | - } | |
377 | - | |
378 | - mState = atoi(&bword[strlen("state=")]); | |
379 | - LOGD("State changed to %d", mState); | |
380 | - free(tmp); | |
381 | - return 0; | |
382 | -} | |
383 | - | |
384 | -int Supplicant::onLinkSpeedEvent(SupplicantEvent *evt) { | |
385 | - LOGD("onLinkSpeedEvent(%s)", evt->getEvent()); | |
386 | - return 0; | |
387 | -} | |
388 | - | |
389 | -int Supplicant::onDriverStateEvent(SupplicantEvent *evt) { | |
390 | - LOGD("onDriverStateEvent(%s)", evt->getEvent()); | |
391 | - return 0; | |
392 | -} | |
393 | - | |
394 | -// XXX: Use a cursor + smartptr instead | |
395 | -ScanResultCollection *Supplicant::createLatestScanResults() { | |
396 | - ScanResultCollection *d = new ScanResultCollection(); | |
397 | - ScanResultCollection::iterator i; | |
398 | - | |
399 | - pthread_mutex_lock(&mLatestScanResultsLock); | |
400 | - for (i = mLatestScanResults->begin(); i != mLatestScanResults->end(); ++i) | |
401 | - d->push_back((*i)->clone()); | |
402 | - | |
403 | - pthread_mutex_unlock(&mLatestScanResultsLock); | |
404 | - return d; | |
405 | -} | |
406 | - | |
407 | 293 | WifiNetwork *Supplicant::createNetwork() { |
408 | 294 | char reply[255]; |
409 | 295 | size_t len = sizeof(reply) -1; |
@@ -445,14 +331,18 @@ int Supplicant::removeNetwork(WifiNetwork *wn) { | ||
445 | 331 | |
446 | 332 | WifiNetwork *Supplicant::lookupNetwork(int networkId) { |
447 | 333 | pthread_mutex_lock(&mNetworksLock); |
334 | + WifiNetwork *wn = lookupNetwork_UNLOCKED(networkId); | |
335 | + pthread_mutex_unlock(&mNetworksLock); | |
336 | + return wn; | |
337 | +} | |
338 | + | |
339 | +WifiNetwork *Supplicant::lookupNetwork_UNLOCKED(int networkId) { | |
448 | 340 | WifiNetworkCollection::iterator it; |
449 | 341 | for (it = mNetworks->begin(); it != mNetworks->end(); ++it) { |
450 | 342 | if ((*it)->getNetworkId() == networkId) { |
451 | - pthread_mutex_unlock(&mNetworksLock); | |
452 | 343 | return *it; |
453 | 344 | } |
454 | 345 | } |
455 | - pthread_mutex_unlock(&mNetworksLock); | |
456 | 346 | errno = ENOENT; |
457 | 347 | return NULL; |
458 | 348 | } |
@@ -528,6 +418,12 @@ int Supplicant::setNetworkVar(int networkId, const char *var, const char *val) { | ||
528 | 418 | return -1; |
529 | 419 | } |
530 | 420 | free(tmp); |
421 | + | |
422 | + len = sizeof(reply) -1; | |
423 | + if (sendCommand("SAVE_CONFIG", reply, &len)) { | |
424 | + LOGE("Error saving config after %s = %s", var, val); | |
425 | + return -1; | |
426 | + } | |
531 | 427 | return 0; |
532 | 428 | } |
533 | 429 |
@@ -19,38 +19,31 @@ | ||
19 | 19 | |
20 | 20 | struct wpa_ctrl; |
21 | 21 | class SupplicantListener; |
22 | -class SupplicantEvent; | |
23 | 22 | class ServiceManager; |
24 | -class PropertyManager; | |
25 | 23 | class Controller; |
26 | 24 | class WifiController; |
25 | +class SupplicantStatus; | |
27 | 26 | |
28 | 27 | #include <pthread.h> |
29 | 28 | |
30 | -#include "ScanResult.h" | |
31 | 29 | #include "WifiNetwork.h" |
32 | -#include "IPropertyProvider.h" | |
33 | 30 | #include "ISupplicantEventHandler.h" |
34 | 31 | |
35 | -class Supplicant : public IPropertyProvider, public ISupplicantEventHandler { | |
32 | +class Supplicant { | |
36 | 33 | private: |
37 | 34 | struct wpa_ctrl *mCtrl; |
38 | 35 | struct wpa_ctrl *mMonitor; |
39 | 36 | SupplicantListener *mListener; |
40 | - int mState; | |
41 | 37 | ServiceManager *mServiceManager; |
42 | - PropertyManager *mPropMngr; | |
43 | 38 | WifiController *mController; |
44 | 39 | char *mInterfaceName; |
45 | 40 | |
46 | - ScanResultCollection *mLatestScanResults; | |
47 | - pthread_mutex_t mLatestScanResultsLock; | |
48 | - | |
49 | - WifiNetworkCollection *mNetworks; | |
50 | - pthread_mutex_t mNetworksLock; | |
41 | + WifiNetworkCollection *mNetworks; | |
42 | + pthread_mutex_t mNetworksLock; | |
43 | + ISupplicantEventHandler *mHandlers; | |
51 | 44 | |
52 | 45 | public: |
53 | - Supplicant(WifiController *wc, PropertyManager *propmngr); | |
46 | + Supplicant(WifiController *wc, ISupplicantEventHandler *handlers); | |
54 | 47 | virtual ~Supplicant(); |
55 | 48 | |
56 | 49 | int start(); |
@@ -58,7 +51,6 @@ public: | ||
58 | 51 | bool isStarted(); |
59 | 52 | |
60 | 53 | int triggerScan(bool active); |
61 | - ScanResultCollection *createLatestScanResults(); | |
62 | 54 | |
63 | 55 | WifiNetwork *createNetwork(); |
64 | 56 | WifiNetwork *lookupNetwork(int networkId); |
@@ -71,33 +63,18 @@ public: | ||
71 | 63 | size_t max); |
72 | 64 | int enableNetwork(int networkId, bool enabled); |
73 | 65 | |
74 | - int getState() { return mState; } | |
66 | + SupplicantStatus *getStatus(); | |
67 | + | |
75 | 68 | Controller *getController() { return (Controller *) mController; } |
76 | 69 | const char *getInterfaceName() { return mInterfaceName; } |
77 | 70 | |
78 | - int set(const char *name, const char *value); | |
79 | - const char *get(const char *name, char *buffer, size_t max); | |
71 | + int sendCommand(const char *cmd, char *reply, size_t *reply_len); | |
80 | 72 | |
81 | 73 | private: |
82 | 74 | int connectToSupplicant(); |
83 | - int sendCommand(const char *cmd, char *reply, size_t *reply_len); | |
84 | 75 | int setupConfig(); |
85 | 76 | int retrieveInterfaceName(); |
86 | - | |
87 | - // ISupplicantEventHandler methods | |
88 | - virtual int onConnectedEvent(SupplicantEvent *evt); | |
89 | - virtual int onDisconnectedEvent(SupplicantEvent *evt); | |
90 | - virtual int onTerminatingEvent(SupplicantEvent *evt); | |
91 | - virtual int onPasswordChangedEvent(SupplicantEvent *evt); | |
92 | - virtual int onEapNotificationEvent(SupplicantEvent *evt); | |
93 | - virtual int onEapStartedEvent(SupplicantEvent *evt); | |
94 | - virtual int onEapMethodEvent(SupplicantEvent *evt); | |
95 | - virtual int onEapSuccessEvent(SupplicantEvent *evt); | |
96 | - virtual int onEapFailureEvent(SupplicantEvent *evt); | |
97 | - virtual int onScanResultsEvent(SupplicantEvent *evt); | |
98 | - virtual int onStateChangeEvent(SupplicantEvent *evt); | |
99 | - virtual int onLinkSpeedEvent(SupplicantEvent *evt); | |
100 | - virtual int onDriverStateEvent(SupplicantEvent *evt); | |
77 | + WifiNetwork *lookupNetwork_UNLOCKED(int networkId); | |
101 | 78 | }; |
102 | 79 | |
103 | 80 | #endif |
@@ -0,0 +1,40 @@ | ||
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 <stdlib.h> | |
18 | + | |
19 | +#define LOG_TAG "SupplicantAssociatedEvent" | |
20 | +#include <cutils/log.h> | |
21 | + | |
22 | +#include "SupplicantAssociatedEvent.h" | |
23 | + | |
24 | +SupplicantAssociatedEvent::SupplicantAssociatedEvent(int level, char *event, | |
25 | + size_t len) : | |
26 | + SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATED, | |
27 | + level) { | |
28 | + char *p = event; | |
29 | + | |
30 | + // "00:13:46:40:40:aa" | |
31 | + mBssid = (char *) malloc(18); | |
32 | + strncpy(mBssid, p, 17); | |
33 | + mBssid[17] = '\0'; | |
34 | +} | |
35 | + | |
36 | +SupplicantAssociatedEvent::~SupplicantAssociatedEvent() { | |
37 | + if (mBssid) | |
38 | + free(mBssid); | |
39 | +} | |
40 | + |
@@ -0,0 +1,34 @@ | ||
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 _SupplicantAssociatedEvent_H | |
18 | +#define _SupplicantAssociatedEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantAssociatedEvent : public SupplicantEvent { | |
23 | + char *mBssid; | |
24 | + char *mSsid; | |
25 | + int mFreq; | |
26 | + | |
27 | +public: | |
28 | + SupplicantAssociatedEvent(int level, char *event, size_t len); | |
29 | + virtual ~SupplicantAssociatedEvent(); | |
30 | + | |
31 | + const char *getBssid() { return mBssid; } | |
32 | +}; | |
33 | + | |
34 | +#endif |
@@ -0,0 +1,99 @@ | ||
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 <stdlib.h> | |
18 | + | |
19 | +#define LOG_TAG "SupplicantAssociatingEvent" | |
20 | +#include <cutils/log.h> | |
21 | + | |
22 | +#include "SupplicantAssociatingEvent.h" | |
23 | + | |
24 | +SupplicantAssociatingEvent::SupplicantAssociatingEvent(int level, char *event, | |
25 | + size_t len) : | |
26 | + SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING, | |
27 | + level) { | |
28 | + char *p = event; | |
29 | + | |
30 | + mBssid = NULL; | |
31 | + mSsid = NULL; | |
32 | + | |
33 | + // SSID 'default' | |
34 | + // OR | |
35 | + // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)" | |
36 | + | |
37 | + if (strncmp(event, "SSID", 4)) { | |
38 | + mBssid = (char *) malloc(18); | |
39 | + strncpy(mBssid, p, 17); | |
40 | + mBssid[17] = '\0'; | |
41 | + p += 25; | |
42 | + | |
43 | + // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)" | |
44 | + // ^ | |
45 | + // p | |
46 | + char *q = index(p, '\''); | |
47 | + if (!q) { | |
48 | + LOGE("Unable to decode SSID (p = {%s})\n", p); | |
49 | + return; | |
50 | + } | |
51 | + mSsid = (char *) malloc((q - p) +1); | |
52 | + strncpy(mSsid, p, q-p); | |
53 | + mSsid[q-p] = '\0'; | |
54 | + | |
55 | + p = q + 7; | |
56 | + | |
57 | + // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)" | |
58 | + // ^ | |
59 | + // p | |
60 | + if (!(q = index(p, ' '))) { | |
61 | + LOGE("Unable to decode frequency\n"); | |
62 | + return; | |
63 | + } | |
64 | + *q = '\0'; | |
65 | + mFreq = atoi(p); | |
66 | + } else { | |
67 | + p+= 6; | |
68 | + | |
69 | + // SSID 'default' | |
70 | + // ^ | |
71 | + // p | |
72 | + | |
73 | + char *q = index(p, '\''); | |
74 | + if (!q) { | |
75 | + LOGE("Unable to decode SSID (p = {%s})\n", p); | |
76 | + return; | |
77 | + } | |
78 | + mSsid = (char *) malloc((q - p) +1); | |
79 | + strncpy(mSsid, p, q-p); | |
80 | + mSsid[q-p] = '\0'; | |
81 | + } | |
82 | +} | |
83 | + | |
84 | +SupplicantAssociatingEvent::SupplicantAssociatingEvent(const char *bssid, | |
85 | + const char *ssid, | |
86 | + int freq) : | |
87 | + SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING, -1) { | |
88 | + mBssid = strdup(bssid); | |
89 | + mSsid= strdup(ssid); | |
90 | + mFreq = freq; | |
91 | +} | |
92 | + | |
93 | +SupplicantAssociatingEvent::~SupplicantAssociatingEvent() { | |
94 | + if (mBssid) | |
95 | + free(mBssid); | |
96 | + if (mSsid) | |
97 | + free(mSsid); | |
98 | +} | |
99 | + |
@@ -0,0 +1,37 @@ | ||
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 _SupplicantAssociatingEvent_H | |
18 | +#define _SupplicantAssociatingEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantAssociatingEvent : public SupplicantEvent { | |
23 | + char *mBssid; | |
24 | + char *mSsid; | |
25 | + int mFreq; | |
26 | + | |
27 | +public: | |
28 | + SupplicantAssociatingEvent(int level, char *event, size_t len); | |
29 | + SupplicantAssociatingEvent(const char *bssid, const char *ssid, int freq); | |
30 | + virtual ~SupplicantAssociatingEvent(); | |
31 | + | |
32 | + const char *getBssid() { return mBssid; } | |
33 | + const char *getSsid() { return mSsid; } | |
34 | + int getFreq() { return mFreq;} | |
35 | +}; | |
36 | + | |
37 | +#endif |
@@ -0,0 +1,61 @@ | ||
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 | +#define LOG_TAG "SupplicantConnectedEvent" | |
18 | +#include <cutils/log.h> | |
19 | + | |
20 | +#include "SupplicantConnectedEvent.h" | |
21 | + | |
22 | +SupplicantConnectedEvent::SupplicantConnectedEvent(int level, char *event, | |
23 | + size_t len) : | |
24 | + SupplicantEvent(SupplicantEvent::EVENT_CONNECTED, | |
25 | + level) { | |
26 | + char *p; | |
27 | + | |
28 | + // "- Connection to 00:13:46:40:40:aa completed (auth) [id=1 id_str=], 89" | |
29 | + | |
30 | + if ((p = index(event + 2, ' ')) && (++p = index(p, ' '))) { | |
31 | + mBssid = (char *) malloc(18); | |
32 | + strncpy(mBssid, ++p, 17); | |
33 | + mBssid[17] = '\0'; | |
34 | + | |
35 | + // "- Connection to 00:13:46:40:40:aa completed (auth) [id=1 id_str=], 89" | |
36 | + // ^ | |
37 | + // p | |
38 | + | |
39 | + if ((p = index(p, ' ')) && ((++p = index(p, ' ')))) { | |
40 | + if (!strncmp(++p, "(auth)", 6)) | |
41 | + mReassociated = false; | |
42 | + else | |
43 | + mReassociated = true; | |
44 | + } else | |
45 | + LOGE("Unable to decode re-assocation"); | |
46 | + } else | |
47 | + LOGE("Unable to decode event"); | |
48 | +} | |
49 | + | |
50 | +SupplicantConnectedEvent::SupplicantConnectedEvent(const char *bssid, | |
51 | + bool reassocated) : | |
52 | + SupplicantEvent(SupplicantEvent::EVENT_CONNECTED, -1) { | |
53 | + mBssid = strdup(bssid); | |
54 | + mReassociated = reassocated; | |
55 | +} | |
56 | + | |
57 | +SupplicantConnectedEvent::~SupplicantConnectedEvent() { | |
58 | + if (mBssid) | |
59 | + free(mBssid); | |
60 | +} | |
61 | + |
@@ -0,0 +1,36 @@ | ||
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 _SupplicantConnectedEvent_H | |
18 | +#define _SupplicantConnectedEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantConnectedEvent : public SupplicantEvent { | |
23 | +private: | |
24 | + char *mBssid; | |
25 | + bool mReassociated; | |
26 | + | |
27 | +public: | |
28 | + SupplicantConnectedEvent(int level, char *event, size_t len); | |
29 | + SupplicantConnectedEvent(const char *bssid, bool reassicated); | |
30 | + virtual ~SupplicantConnectedEvent(); | |
31 | + | |
32 | + const char *getBssid() { return mBssid; } | |
33 | + bool getReassociated() { return mReassociated; } | |
34 | +}; | |
35 | + | |
36 | +#endif |
@@ -0,0 +1,36 @@ | ||
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 | +#define LOG_TAG "SupplicantConnectionTimeoutEvent" | |
18 | +#include <cutils/log.h> | |
19 | + | |
20 | +#include "SupplicantConnectionTimeoutEvent.h" | |
21 | + | |
22 | +SupplicantConnectionTimeoutEvent::SupplicantConnectionTimeoutEvent(int level, char *event, | |
23 | + size_t len) : | |
24 | + SupplicantEvent(SupplicantEvent::EVENT_CONNECTIONTIMEOUT, | |
25 | + level) { | |
26 | + // 00:13:46:40:40:aa timed out.' | |
27 | + mBssid = (char *) malloc(18); | |
28 | + strncpy(mBssid, event, 17); | |
29 | + mBssid[17] = '\0'; | |
30 | +} | |
31 | + | |
32 | +SupplicantConnectionTimeoutEvent::~SupplicantConnectionTimeoutEvent() { | |
33 | + if (mBssid) | |
34 | + free(mBssid); | |
35 | +} | |
36 | + |
@@ -0,0 +1,34 @@ | ||
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 _SupplicantConnectionTimeoutEvent_H | |
18 | +#define _SupplicantConnectionTimeoutEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantConnectionTimeoutEvent : public SupplicantEvent { | |
23 | +private: | |
24 | + char *mBssid; | |
25 | + bool mReassociated; | |
26 | + | |
27 | +public: | |
28 | + SupplicantConnectionTimeoutEvent(int level, char *event, size_t len); | |
29 | + virtual ~SupplicantConnectionTimeoutEvent(); | |
30 | + | |
31 | + const char *getBssid() { return mBssid; } | |
32 | +}; | |
33 | + | |
34 | +#endif |
@@ -0,0 +1,33 @@ | ||
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 | +#define LOG_TAG "SupplicantDisconnectedEvent" | |
18 | +#include <cutils/log.h> | |
19 | + | |
20 | +#include "SupplicantDisconnectedEvent.h" | |
21 | + | |
22 | +SupplicantDisconnectedEvent::SupplicantDisconnectedEvent(int level, char *event, | |
23 | + size_t len) : | |
24 | + SupplicantEvent(SupplicantEvent::EVENT_DISCONNECTED, | |
25 | + level) { | |
26 | +} | |
27 | + | |
28 | +SupplicantDisconnectedEvent::SupplicantDisconnectedEvent() : | |
29 | + SupplicantEvent(SupplicantEvent::EVENT_DISCONNECTED, -1) { | |
30 | +} | |
31 | + | |
32 | +SupplicantDisconnectedEvent::~SupplicantDisconnectedEvent() { | |
33 | +} |
@@ -0,0 +1,30 @@ | ||
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 _SupplicantDisconnectedEvent_H | |
18 | +#define _SupplicantDisconnectedEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantDisconnectedEvent : public SupplicantEvent { | |
23 | + | |
24 | +public: | |
25 | + SupplicantDisconnectedEvent(int level, char *event, size_t len); | |
26 | + SupplicantDisconnectedEvent(); | |
27 | + virtual ~SupplicantDisconnectedEvent(); | |
28 | +}; | |
29 | + | |
30 | +#endif |
@@ -23,74 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "libwpa_client/wpa_ctrl.h" |
25 | 25 | |
26 | -SupplicantEvent::SupplicantEvent(char *event, size_t len) { | |
27 | - | |
28 | - if (event[0] == '<') { | |
29 | - char *match = strchr(event, '>'); | |
30 | - if (match) { | |
31 | - char tmp[16]; | |
32 | - | |
33 | - strncpy(tmp, &event[1], (match - event)); | |
34 | - mLevel = atoi(tmp); | |
35 | - event += (match - event) + 1; | |
36 | - } else | |
37 | - LOGW("Unclosed level brace in event"); | |
38 | - } else | |
39 | - LOGW("No level specified in event"); | |
40 | - | |
41 | - /* | |
42 | - * <N>CTRL-EVENT-XXX | |
43 | - * ^ | |
44 | - * +---- event | |
45 | - */ | |
46 | - | |
47 | - if (!strncmp(event, WPA_EVENT_CONNECTED, strlen(WPA_EVENT_CONNECTED))) | |
48 | - mType = SupplicantEvent::EVENT_CONNECTED; | |
49 | - else if (!strncmp(event, WPA_EVENT_DISCONNECTED, strlen(WPA_EVENT_DISCONNECTED))) | |
50 | - mType = SupplicantEvent::EVENT_DISCONNECTED; | |
51 | - else if (!strncmp(event, WPA_EVENT_TERMINATING, strlen(WPA_EVENT_TERMINATING))) | |
52 | - mType = SupplicantEvent::EVENT_TERMINATING; | |
53 | - else if (!strncmp(event, WPA_EVENT_PASSWORD_CHANGED, strlen(WPA_EVENT_PASSWORD_CHANGED))) | |
54 | - mType = SupplicantEvent::EVENT_PASSWORD_CHANGED; | |
55 | - else if (!strncmp(event, WPA_EVENT_EAP_NOTIFICATION, strlen(WPA_EVENT_EAP_NOTIFICATION))) | |
56 | - mType = SupplicantEvent::EVENT_EAP_NOTIFICATION; | |
57 | - else if (!strncmp(event, WPA_EVENT_EAP_STARTED, strlen(WPA_EVENT_EAP_STARTED))) | |
58 | - mType = SupplicantEvent::EVENT_EAP_STARTED; | |
59 | - else if (!strncmp(event, WPA_EVENT_EAP_METHOD, strlen(WPA_EVENT_EAP_METHOD))) | |
60 | - mType = SupplicantEvent::EVENT_EAP_METHOD; | |
61 | - else if (!strncmp(event, WPA_EVENT_EAP_SUCCESS, strlen(WPA_EVENT_EAP_SUCCESS))) | |
62 | - mType = SupplicantEvent::EVENT_EAP_SUCCESS; | |
63 | - else if (!strncmp(event, WPA_EVENT_EAP_FAILURE, strlen(WPA_EVENT_EAP_FAILURE))) | |
64 | - mType = SupplicantEvent::EVENT_EAP_FAILURE; | |
65 | - else if (!strncmp(event, WPA_EVENT_SCAN_RESULTS, strlen(WPA_EVENT_SCAN_RESULTS))) | |
66 | - mType = SupplicantEvent::EVENT_SCAN_RESULTS; | |
67 | - else if (!strncmp(event, WPA_EVENT_STATE_CHANGE, strlen(WPA_EVENT_STATE_CHANGE))) | |
68 | - mType = SupplicantEvent::EVENT_STATE_CHANGE; | |
69 | - else if (!strncmp(event, WPA_EVENT_LINK_SPEED, strlen(WPA_EVENT_LINK_SPEED))) | |
70 | - mType = SupplicantEvent::EVENT_LINK_SPEED; | |
71 | - else if (!strncmp(event, WPA_EVENT_DRIVER_STATE, strlen(WPA_EVENT_DRIVER_STATE))) | |
72 | - mType = SupplicantEvent::EVENT_DRIVER_STATE; | |
73 | - else { | |
74 | - LOGW("Unknown supplicant event '%s'", event); | |
75 | - mType = SupplicantEvent::EVENT_UNKNOWN; | |
76 | - } | |
77 | - | |
78 | - for (event; *event != ' '; event++); | |
79 | - event++; | |
80 | - | |
81 | - /* | |
82 | - * <N>CTRL-EVENT-XXX YYYY | |
83 | - * ^ | |
84 | - * +---- event | |
85 | - */ | |
86 | - | |
87 | - for (event; *event == ' '; event++); | |
88 | - | |
89 | - mEvent = strdup(event); | |
90 | - mLen = len; | |
91 | -} | |
92 | - | |
93 | -SupplicantEvent::~SupplicantEvent() { | |
94 | - if (mEvent) | |
95 | - free(mEvent); | |
26 | +SupplicantEvent::SupplicantEvent(int type, int level) { | |
27 | + mType = type; | |
28 | + mLevel = level; | |
96 | 29 | } |
@@ -22,33 +22,32 @@ | ||
22 | 22 | class SupplicantEvent { |
23 | 23 | private: |
24 | 24 | int mType; |
25 | - char *mEvent; | |
26 | - size_t mLen; | |
27 | 25 | int mLevel; |
28 | 26 | |
29 | 27 | public: |
30 | - static const int EVENT_UNKNOWN = 0; | |
31 | - static const int EVENT_CONNECTED = 1; | |
32 | - static const int EVENT_DISCONNECTED = 2; | |
33 | - static const int EVENT_TERMINATING = 3; | |
34 | - static const int EVENT_PASSWORD_CHANGED = 4; | |
35 | - static const int EVENT_EAP_NOTIFICATION = 5; | |
36 | - static const int EVENT_EAP_STARTED = 6; | |
37 | - static const int EVENT_EAP_METHOD = 7; | |
38 | - static const int EVENT_EAP_SUCCESS = 8; | |
39 | - static const int EVENT_EAP_FAILURE = 9; | |
40 | - static const int EVENT_SCAN_RESULTS = 10; | |
41 | - static const int EVENT_STATE_CHANGE = 11; | |
42 | - static const int EVENT_LINK_SPEED = 12; | |
43 | - static const int EVENT_DRIVER_STATE = 13; | |
28 | + static const int EVENT_UNKNOWN = 0; | |
29 | + static const int EVENT_CONNECTED = 1; | |
30 | + static const int EVENT_DISCONNECTED = 2; | |
31 | + static const int EVENT_TERMINATING = 3; | |
32 | + static const int EVENT_PASSWORD_CHANGED = 4; | |
33 | + static const int EVENT_EAP_NOTIFICATION = 5; | |
34 | + static const int EVENT_EAP_STARTED = 6; | |
35 | + static const int EVENT_EAP_METHOD = 7; | |
36 | + static const int EVENT_EAP_SUCCESS = 8; | |
37 | + static const int EVENT_EAP_FAILURE = 9; | |
38 | + static const int EVENT_SCAN_RESULTS = 10; | |
39 | + static const int EVENT_STATE_CHANGE = 11; | |
40 | + static const int EVENT_LINK_SPEED = 12; | |
41 | + static const int EVENT_DRIVER_STATE = 13; | |
42 | + static const int EVENT_ASSOCIATING = 14; | |
43 | + static const int EVENT_ASSOCIATED = 15; | |
44 | + static const int EVENT_CONNECTIONTIMEOUT = 16; | |
44 | 45 | |
45 | 46 | public: |
46 | - SupplicantEvent(char *event, size_t len); | |
47 | - virtual ~SupplicantEvent(); | |
47 | + SupplicantEvent(int type, int level); | |
48 | + virtual ~SupplicantEvent() {} | |
48 | 49 | |
49 | 50 | int getType() { return mType; } |
50 | - const char *getEvent() { return mEvent; } | |
51 | - int getLen() { return mLen; } | |
52 | 51 | int getLevel() { return mLevel; } |
53 | 52 | }; |
54 | 53 |
@@ -0,0 +1,119 @@ | ||
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 <stdlib.h> | |
18 | + | |
19 | +#define LOG_TAG "SupplicantEventFactory" | |
20 | +#include <cutils/log.h> | |
21 | + | |
22 | +#include "SupplicantEvent.h" | |
23 | +#include "SupplicantEventFactory.h" | |
24 | +#include "SupplicantAssociatingEvent.h" | |
25 | +#include "SupplicantAssociatedEvent.h" | |
26 | +#include "SupplicantConnectedEvent.h" | |
27 | +#include "SupplicantStateChangeEvent.h" | |
28 | +#include "SupplicantScanResultsEvent.h" | |
29 | +#include "SupplicantConnectionTimeoutEvent.h" | |
30 | +#include "SupplicantDisconnectedEvent.h" | |
31 | +#if 0 | |
32 | +#include "SupplicantTerminatingEvent.h" | |
33 | +#include "SupplicantPasswordChangedEvent.h" | |
34 | +#include "SupplicantEapNotificationEvent.h" | |
35 | +#include "SupplicantEapStartedEvent.h" | |
36 | +#include "SupplicantEapMethodEvent.h" | |
37 | +#include "SupplicantEapSuccessEvent.h" | |
38 | +#include "SupplicantEapFailureEvent.h" | |
39 | +#include "SupplicantLinkSpeedEvent.h" | |
40 | +#include "SupplicantDriverStateEvent.h" | |
41 | +#endif | |
42 | + | |
43 | +#include "libwpa_client/wpa_ctrl.h" | |
44 | + | |
45 | +SupplicantEventFactory::SupplicantEventFactory() { | |
46 | +} | |
47 | + | |
48 | +SupplicantEvent *SupplicantEventFactory::createEvent(char *event, size_t len) { | |
49 | + int level = 0; | |
50 | + | |
51 | + if (event[0] == '<') { | |
52 | + char *match = strchr(event, '>'); | |
53 | + if (match) { | |
54 | + char tmp[16]; | |
55 | + | |
56 | + strncpy(tmp, &event[1], (match - event)); | |
57 | + level = atoi(tmp); | |
58 | + event += (match - event) + 1; | |
59 | + } else | |
60 | + LOGW("Unclosed level brace in event"); | |
61 | + } else | |
62 | + LOGW("No level specified in event"); | |
63 | + | |
64 | + /* | |
65 | + * <N>CTRL-EVENT-XXX | |
66 | + * ^ | |
67 | + * +---- event | |
68 | + */ | |
69 | + | |
70 | + if (!strncmp(event, "Authentication with ", 20)) { | |
71 | + if (!strcmp(event + strlen(event) - strlen(" timed out."), | |
72 | + " timed out.")) { | |
73 | + return new SupplicantConnectionTimeoutEvent(level, | |
74 | + event + 20, | |
75 | + len); | |
76 | + } else | |
77 | + return NULL; | |
78 | + | |
79 | + } else if (!strncmp(event, "Associated with ", 16)) | |
80 | + return new SupplicantAssociatedEvent(level, event + 16, len); | |
81 | + else if (!strncmp(event, "Trying to associate with ", 25)) | |
82 | + return new SupplicantAssociatingEvent(level, event + 25, len); | |
83 | + else if (!strncmp(event, WPA_EVENT_CONNECTED, strlen(WPA_EVENT_CONNECTED))) { | |
84 | + return new SupplicantConnectedEvent(level, | |
85 | + event + strlen(WPA_EVENT_CONNECTED), | |
86 | + len); | |
87 | + } else if (!strncmp(event, WPA_EVENT_SCAN_RESULTS, strlen(WPA_EVENT_SCAN_RESULTS))) { | |
88 | + return new SupplicantScanResultsEvent(level, | |
89 | + event + strlen(WPA_EVENT_SCAN_RESULTS), | |
90 | + len); | |
91 | + } else if (!strncmp(event, WPA_EVENT_STATE_CHANGE, strlen(WPA_EVENT_STATE_CHANGE))) { | |
92 | + return new SupplicantStateChangeEvent(level, | |
93 | + event + strlen(WPA_EVENT_STATE_CHANGE), | |
94 | + len); | |
95 | + } | |
96 | + else if (!strncmp(event, WPA_EVENT_DISCONNECTED, strlen(WPA_EVENT_DISCONNECTED))) | |
97 | + return new SupplicantDisconnectedEvent(level, event, len); | |
98 | +#if 0 | |
99 | + else if (!strncmp(event, WPA_EVENT_TERMINATING, strlen(WPA_EVENT_TERMINATING))) | |
100 | + return new SupplicantTerminatingEvent(event, len); | |
101 | + else if (!strncmp(event, WPA_EVENT_PASSWORD_CHANGED, strlen(WPA_EVENT_PASSWORD_CHANGED))) | |
102 | + return new SupplicantPasswordChangedEvent(event, len); | |
103 | + else if (!strncmp(event, WPA_EVENT_EAP_NOTIFICATION, strlen(WPA_EVENT_EAP_NOTIFICATION))) | |
104 | + return new SupplicantEapNotificationEvent(event, len); | |
105 | + else if (!strncmp(event, WPA_EVENT_EAP_STARTED, strlen(WPA_EVENT_EAP_STARTED))) | |
106 | + return new SupplicantEapStartedEvent(event, len); | |
107 | + else if (!strncmp(event, WPA_EVENT_EAP_METHOD, strlen(WPA_EVENT_EAP_METHOD))) | |
108 | + return new SupplicantEapMethodEvent(event, len); | |
109 | + else if (!strncmp(event, WPA_EVENT_EAP_SUCCESS, strlen(WPA_EVENT_EAP_SUCCESS))) | |
110 | + return new SupplicantEapSuccessEvent(event, len); | |
111 | + else if (!strncmp(event, WPA_EVENT_EAP_FAILURE, strlen(WPA_EVENT_EAP_FAILURE))) | |
112 | + return new SupplicantEapFailureEvent(event, len); | |
113 | + else if (!strncmp(event, WPA_EVENT_LINK_SPEED, strlen(WPA_EVENT_LINK_SPEED))) | |
114 | + return new SupplicantLinkSpeedEvent(event, len); | |
115 | + else if (!strncmp(event, WPA_EVENT_DRIVER_STATE, strlen(WPA_EVENT_DRIVER_STATE))) | |
116 | + return new SupplicantDriverStateEvent(event, len); | |
117 | +#endif | |
118 | + return NULL; | |
119 | +} |
@@ -0,0 +1,31 @@ | ||
1 | + | |
2 | +/* | |
3 | + * Copyright (C) 2008 The Android Open Source Project | |
4 | + * | |
5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | + * you may not use this file except in compliance with the License. | |
7 | + * You may obtain a copy of the License at | |
8 | + * | |
9 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + * | |
11 | + * Unless required by applicable law or agreed to in writing, software | |
12 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | + * See the License for the specific language governing permissions and | |
15 | + * limitations under the License. | |
16 | + */ | |
17 | + | |
18 | +#ifndef _SupplicantEventFactory_H | |
19 | +#define _SupplicantEventFactory_H | |
20 | + | |
21 | +class SupplicantEvent; | |
22 | + | |
23 | +class SupplicantEventFactory { | |
24 | +public: | |
25 | + SupplicantEventFactory(); | |
26 | + virtual ~SupplicantEventFactory() {} | |
27 | + | |
28 | + SupplicantEvent *createEvent(char *event, size_t len); | |
29 | +}; | |
30 | + | |
31 | +#endif |
@@ -24,14 +24,21 @@ | ||
24 | 24 | #include "libwpa_client/wpa_ctrl.h" |
25 | 25 | |
26 | 26 | #include "SupplicantListener.h" |
27 | -#include "SupplicantEvent.h" | |
28 | 27 | #include "ISupplicantEventHandler.h" |
28 | +#include "SupplicantEventFactory.h" | |
29 | +#include "SupplicantEvent.h" | |
30 | +#include "SupplicantAssociatingEvent.h" | |
31 | +#include "SupplicantAssociatedEvent.h" | |
32 | +#include "SupplicantConnectedEvent.h" | |
33 | +#include "SupplicantScanResultsEvent.h" | |
34 | +#include "SupplicantStateChangeEvent.h" | |
29 | 35 | |
30 | 36 | SupplicantListener::SupplicantListener(ISupplicantEventHandler *handlers, |
31 | 37 | struct wpa_ctrl *monitor) : |
32 | 38 | SocketListener(wpa_ctrl_get_fd(monitor), false) { |
33 | 39 | mHandlers = handlers; |
34 | 40 | mMonitor = monitor; |
41 | + mFactory = new SupplicantEventFactory(); | |
35 | 42 | } |
36 | 43 | |
37 | 44 | bool SupplicantListener::onDataAvailable(SocketClient *cli) { |
@@ -53,44 +60,50 @@ bool SupplicantListener::onDataAvailable(SocketClient *cli) { | ||
53 | 60 | return false; |
54 | 61 | } |
55 | 62 | |
56 | - SupplicantEvent *evt = new SupplicantEvent(buf, nread); | |
63 | + SupplicantEvent *evt = mFactory->createEvent(buf, nread); | |
64 | + | |
65 | + if (!evt) { | |
66 | + LOGW("Dropping unknown supplicant event '%s'", buf); | |
67 | + return true; | |
68 | + } | |
57 | 69 | |
58 | - // XXX: Make this a factory | |
59 | - // XXX: Instead of calling Supplicant directly | |
60 | - // extract an Interface and use that instead | |
61 | - if (evt->getType() == SupplicantEvent::EVENT_CONNECTED) | |
62 | - rc = mHandlers->onConnectedEvent(evt); | |
70 | + // Call the appropriate handler | |
71 | + if (evt->getType() == SupplicantEvent::EVENT_ASSOCIATING) | |
72 | + mHandlers->onAssociatingEvent((SupplicantAssociatingEvent *) evt); | |
73 | + else if (evt->getType() == SupplicantEvent::EVENT_ASSOCIATED) | |
74 | + mHandlers->onAssociatedEvent((SupplicantAssociatedEvent *) evt); | |
75 | + else if (evt->getType() == SupplicantEvent::EVENT_CONNECTED) | |
76 | + mHandlers->onConnectedEvent((SupplicantConnectedEvent *) evt); | |
77 | + else if (evt->getType() == SupplicantEvent::EVENT_SCAN_RESULTS) | |
78 | + mHandlers->onScanResultsEvent((SupplicantScanResultsEvent *) evt); | |
79 | + else if (evt->getType() == SupplicantEvent::EVENT_STATE_CHANGE) | |
80 | + mHandlers->onStateChangeEvent((SupplicantStateChangeEvent *) evt); | |
81 | + else if (evt->getType() == SupplicantEvent::EVENT_CONNECTIONTIMEOUT) | |
82 | + mHandlers->onConnectionTimeoutEvent((SupplicantConnectionTimeoutEvent *) evt); | |
63 | 83 | else if (evt->getType() == SupplicantEvent::EVENT_DISCONNECTED) |
64 | - rc = mHandlers->onDisconnectedEvent(evt); | |
84 | + mHandlers->onDisconnectedEvent((SupplicantDisconnectedEvent *) evt); | |
85 | + else | |
86 | + LOGW("Whoops - no handler available for event '%s'\n", buf); | |
87 | +#if 0 | |
65 | 88 | else if (evt->getType() == SupplicantEvent::EVENT_TERMINATING) |
66 | - rc = mHandlers->onTerminatingEvent(evt); | |
89 | + mHandlers->onTerminatingEvent(evt); | |
67 | 90 | else if (evt->getType() == SupplicantEvent::EVENT_PASSWORD_CHANGED) |
68 | - rc = mHandlers->onPasswordChangedEvent(evt); | |
91 | + mHandlers->onPasswordChangedEvent(evt); | |
69 | 92 | else if (evt->getType() == SupplicantEvent::EVENT_EAP_NOTIFICATION) |
70 | - rc = mHandlers->onEapNotificationEvent(evt); | |
93 | + mHandlers->onEapNotificationEvent(evt); | |
71 | 94 | else if (evt->getType() == SupplicantEvent::EVENT_EAP_STARTED) |
72 | - rc = mHandlers->onEapStartedEvent(evt); | |
95 | + mHandlers->onEapStartedEvent(evt); | |
73 | 96 | else if (evt->getType() == SupplicantEvent::EVENT_EAP_SUCCESS) |
74 | - rc = mHandlers->onEapSuccessEvent(evt); | |
97 | + mHandlers->onEapSuccessEvent(evt); | |
75 | 98 | else if (evt->getType() == SupplicantEvent::EVENT_EAP_FAILURE) |
76 | - rc = mHandlers->onEapFailureEvent(evt); | |
77 | - else if (evt->getType() == SupplicantEvent::EVENT_SCAN_RESULTS) | |
78 | - rc = mHandlers->onScanResultsEvent(evt); | |
79 | - else if (evt->getType() == SupplicantEvent::EVENT_STATE_CHANGE) | |
80 | - rc = mHandlers->onStateChangeEvent(evt); | |
99 | + mHandlers->onEapFailureEvent(evt); | |
81 | 100 | else if (evt->getType() == SupplicantEvent::EVENT_LINK_SPEED) |
82 | - rc = mHandlers->onLinkSpeedEvent(evt); | |
101 | + mHandlers->onLinkSpeedEvent(evt); | |
83 | 102 | else if (evt->getType() == SupplicantEvent::EVENT_DRIVER_STATE) |
84 | - rc = mHandlers->onDriverStateEvent(evt); | |
85 | - else { | |
86 | - LOGW("Ignoring unknown event"); | |
87 | - } | |
103 | + mHandlers->onDriverStateEvent(evt); | |
104 | +#endif | |
88 | 105 | |
89 | 106 | delete evt; |
90 | 107 | |
91 | - if (rc) { | |
92 | - LOGW("Handler %d (%s) error: %s", evt->getType(), evt->getEvent(), strerror(errno)); | |
93 | - return false; | |
94 | - } | |
95 | 108 | return true; |
96 | 109 | } |
@@ -23,12 +23,13 @@ struct wpa_ctrl; | ||
23 | 23 | class Supplicant; |
24 | 24 | class SocketClient; |
25 | 25 | class ISupplicantEventHandler; |
26 | +class SupplicantEventFactory; | |
26 | 27 | |
27 | 28 | class SupplicantListener: public SocketListener { |
28 | -private: | |
29 | 29 | struct wpa_ctrl *mMonitor; |
30 | 30 | ISupplicantEventHandler *mHandlers; |
31 | - | |
31 | + SupplicantEventFactory *mFactory; | |
32 | + | |
32 | 33 | public: |
33 | 34 | SupplicantListener(ISupplicantEventHandler *handlers, |
34 | 35 | struct wpa_ctrl *monitor); |
@@ -0,0 +1,34 @@ | ||
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 | +#define LOG_TAG "SupplicantScanResultsEvent" | |
18 | +#include <cutils/log.h> | |
19 | + | |
20 | +#include "SupplicantScanResultsEvent.h" | |
21 | + | |
22 | +SupplicantScanResultsEvent::SupplicantScanResultsEvent(int level, char *event, | |
23 | + size_t len) : | |
24 | + SupplicantEvent(SupplicantEvent::EVENT_SCAN_RESULTS, | |
25 | + level) { | |
26 | +} | |
27 | + | |
28 | +SupplicantScanResultsEvent::SupplicantScanResultsEvent() : | |
29 | + SupplicantEvent(SupplicantEvent::EVENT_SCAN_RESULTS, -1) { | |
30 | +} | |
31 | + | |
32 | +SupplicantScanResultsEvent::~SupplicantScanResultsEvent() { | |
33 | +} | |
34 | + |
@@ -0,0 +1,30 @@ | ||
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 _SupplicantScanResultsEvent_H | |
18 | +#define _SupplicantScanResultsEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantScanResultsEvent : public SupplicantEvent { | |
23 | + | |
24 | +public: | |
25 | + SupplicantScanResultsEvent(int level, char *event, size_t len); | |
26 | + SupplicantScanResultsEvent(); | |
27 | + virtual ~SupplicantScanResultsEvent(); | |
28 | +}; | |
29 | + | |
30 | +#endif |
@@ -0,0 +1,45 @@ | ||
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 <stdlib.h> | |
18 | + | |
19 | +#define LOG_TAG "SupplicantStateChangeEvent" | |
20 | +#include <cutils/log.h> | |
21 | + | |
22 | +#include "SupplicantStateChangeEvent.h" | |
23 | + | |
24 | +SupplicantStateChangeEvent::SupplicantStateChangeEvent(int level, char *event, | |
25 | + size_t len) : | |
26 | + SupplicantEvent(SupplicantEvent::EVENT_STATE_CHANGE, | |
27 | + level) { | |
28 | + // XXX: move this stuff into a static creation method | |
29 | + char *p = index(event, ' '); | |
30 | + if (!p) { | |
31 | + LOGW("Bad event '%s'\n", event); | |
32 | + return; | |
33 | + } | |
34 | + | |
35 | + mState = atoi(p + strlen("state=") + 1); | |
36 | +} | |
37 | + | |
38 | +SupplicantStateChangeEvent::SupplicantStateChangeEvent(int state) : | |
39 | + SupplicantEvent(SupplicantEvent::EVENT_STATE_CHANGE, -1) { | |
40 | + mState = state; | |
41 | +} | |
42 | + | |
43 | +SupplicantStateChangeEvent::~SupplicantStateChangeEvent() { | |
44 | +} | |
45 | + |
@@ -0,0 +1,34 @@ | ||
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 _SupplicantStateChangeEvent_H | |
18 | +#define _SupplicantStateChangeEvent_H | |
19 | + | |
20 | +#include "SupplicantEvent.h" | |
21 | + | |
22 | +class SupplicantStateChangeEvent : public SupplicantEvent { | |
23 | +private: | |
24 | + int mState; | |
25 | + | |
26 | +public: | |
27 | + SupplicantStateChangeEvent(int level, char *event, size_t len); | |
28 | + SupplicantStateChangeEvent(int state); | |
29 | + virtual ~SupplicantStateChangeEvent(); | |
30 | + | |
31 | + int getState() { return mState; } | |
32 | +}; | |
33 | + | |
34 | +#endif |
@@ -0,0 +1,72 @@ | ||
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 <stdlib.h> | |
18 | +#include <string.h> | |
19 | + | |
20 | +#define LOG_TAG "SupplicantState" | |
21 | +#include <cutils/log.h> | |
22 | + | |
23 | +#include "SupplicantStatus.h" | |
24 | +#include "SupplicantState.h" | |
25 | + | |
26 | +SupplicantStatus::SupplicantStatus() { | |
27 | + mWpaState = SupplicantState::UNKNOWN; | |
28 | + mId = -1; | |
29 | + mBssid = NULL; | |
30 | + mSsid = NULL; | |
31 | +} | |
32 | + | |
33 | +SupplicantStatus::SupplicantStatus(int state, int id, char *bssid, char *ssid) : | |
34 | + mWpaState(state), mId(id), mBssid(bssid), mSsid(ssid) { | |
35 | + | |
36 | +LOGD("state %d, id %d, bssid %p, ssid %p\n", mWpaState, mId, mBssid, mSsid); | |
37 | +} | |
38 | + | |
39 | +SupplicantStatus::~SupplicantStatus() { | |
40 | + if (mBssid) | |
41 | + free(mBssid); | |
42 | + if (mSsid) | |
43 | + free(mSsid); | |
44 | +} | |
45 | + | |
46 | +SupplicantStatus *SupplicantStatus::createStatus(char *data, int len) { | |
47 | + char *bssid = NULL; | |
48 | + char *ssid = NULL; | |
49 | + int id = -1; | |
50 | + int state = SupplicantState::UNKNOWN; | |
51 | + | |
52 | + char *next = data; | |
53 | + char *line; | |
54 | + while((line = strsep(&next, "\n"))) { | |
55 | + char *token = strsep(&next, "="); | |
56 | + char *value = strsep(&next, "="); | |
57 | + | |
58 | + if (!strcmp(token, "bssid")) | |
59 | + bssid = strdup(value); | |
60 | + else if (!strcmp(token, "ssid")) | |
61 | + ssid = strdup(value); | |
62 | + else if (!strcmp(token, "id")) | |
63 | + id = atoi(value); | |
64 | + else if (!strcmp(token, "wpa_state")) | |
65 | + state = atoi(value); | |
66 | + else | |
67 | + LOGD("Ignoring unsupported status token '%s'", token); | |
68 | + } | |
69 | + | |
70 | + return new SupplicantStatus(state, id, bssid, ssid); | |
71 | + | |
72 | +} |
@@ -0,0 +1,42 @@ | ||
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 _SupplicantStatus_H | |
18 | +#define _SupplicantStatus_H | |
19 | + | |
20 | +class SupplicantStatus { | |
21 | +private: | |
22 | + int mWpaState; | |
23 | + int mId; | |
24 | + char *mBssid; | |
25 | + char *mSsid; | |
26 | + | |
27 | +private: | |
28 | + SupplicantStatus(); | |
29 | + SupplicantStatus(int state, int id, char *bssid, char *ssid); | |
30 | + | |
31 | +public: | |
32 | + virtual ~SupplicantStatus(); | |
33 | + static SupplicantStatus *createStatus(char *data, int len); | |
34 | + | |
35 | + int getWpaState() { return mWpaState; } | |
36 | + int getId() { return mId; } | |
37 | + const char *getBssid() { return mBssid; } | |
38 | + const char *getSsid() { return mSsid; } | |
39 | + | |
40 | +}; | |
41 | + | |
42 | +#endif |
@@ -30,8 +30,12 @@ | ||
30 | 30 | |
31 | 31 | extern "C" int sched_yield(void); |
32 | 32 | |
33 | -TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr, char *modpath, char *modname, char *modargs) : | |
34 | - WifiController(propmngr, modpath, modname, modargs) { | |
33 | +TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr, | |
34 | + IControllerHandler *handlers, | |
35 | + char *modpath, char *modname, | |
36 | + char *modargs) : | |
37 | + WifiController(propmngr, handlers, modpath, modname, | |
38 | + modargs) { | |
35 | 39 | } |
36 | 40 | |
37 | 41 | int TiwlanWifiController::powerUp() { |
@@ -20,9 +20,11 @@ | ||
20 | 20 | #include "PropertyManager.h" |
21 | 21 | #include "WifiController.h" |
22 | 22 | |
23 | +class IControllerHandler; | |
24 | + | |
23 | 25 | class TiwlanWifiController : public WifiController { |
24 | 26 | public: |
25 | - TiwlanWifiController(PropertyManager *propmngr, char *modpath, char *modname, char *modargs); | |
27 | + TiwlanWifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs); | |
26 | 28 | virtual ~TiwlanWifiController() {} |
27 | 29 | |
28 | 30 | virtual int powerUp(); |
@@ -25,18 +25,19 @@ | ||
25 | 25 | #include "PropertyManager.h" |
26 | 26 | #include "VpnController.h" |
27 | 27 | |
28 | -VpnController::VpnController(PropertyManager *propmngr) : | |
29 | - Controller("VPN", propmngr) { | |
28 | +VpnController::VpnController(PropertyManager *propmngr, | |
29 | + IControllerHandler *handlers) : | |
30 | + Controller("VPN", propmngr, handlers) { | |
30 | 31 | mEnabled = false; |
31 | - propmngr->registerProperty("vpn.enabled", this); | |
32 | - propmngr->registerProperty("vpn.gateway", this); | |
33 | 32 | } |
34 | 33 | |
35 | 34 | int VpnController::start() { |
35 | + mPropMngr->registerProperty("vpn.enabled", this); | |
36 | 36 | return 0; |
37 | 37 | } |
38 | 38 | |
39 | 39 | int VpnController::stop() { |
40 | + mPropMngr->unregisterProperty("vpn.enabled"); | |
40 | 41 | return 0; |
41 | 42 | } |
42 | 43 |
@@ -49,8 +50,13 @@ int VpnController::set(const char *name, const char *value) { | ||
49 | 50 | return 0; |
50 | 51 | rc = (en ? enable() : disable()); |
51 | 52 | |
52 | - if (!rc) | |
53 | + if (!rc) { | |
53 | 54 | mEnabled = en; |
55 | + if (en) | |
56 | + mPropMngr->unregisterProperty("vpn.gateway"); | |
57 | + else | |
58 | + mPropMngr->unregisterProperty("vpn.gateway"); | |
59 | + } | |
54 | 60 | return rc; |
55 | 61 | } if (!strcmp(name, "vpn.gateway")) { |
56 | 62 | if (!inet_aton(value, &mVpnGateway)) { |
@@ -21,6 +21,8 @@ | ||
21 | 21 | |
22 | 22 | #include "Controller.h" |
23 | 23 | |
24 | +class IControllerHandler; | |
25 | + | |
24 | 26 | class VpnController : public Controller { |
25 | 27 | bool mEnabled; |
26 | 28 | /* |
@@ -29,7 +31,7 @@ class VpnController : public Controller { | ||
29 | 31 | struct in_addr mVpnGateway; |
30 | 32 | |
31 | 33 | public: |
32 | - VpnController(PropertyManager *propmngr); | |
34 | + VpnController(PropertyManager *propmngr, IControllerHandler *handlers); | |
33 | 35 | virtual ~VpnController() {} |
34 | 36 | |
35 | 37 | virtual int start(); |
@@ -27,34 +27,50 @@ | ||
27 | 27 | #include "NetworkManager.h" |
28 | 28 | #include "ErrorCode.h" |
29 | 29 | #include "WifiNetwork.h" |
30 | - | |
31 | -WifiController::WifiController(PropertyManager *propmngr, char *modpath, char *modname, char *modargs) : | |
32 | - Controller("WIFI", propmngr) { | |
30 | +#include "ISupplicantEventHandler.h" | |
31 | +#include "SupplicantState.h" | |
32 | +#include "SupplicantStatus.h" | |
33 | +#include "SupplicantAssociatingEvent.h" | |
34 | +#include "SupplicantAssociatedEvent.h" | |
35 | +#include "SupplicantConnectedEvent.h" | |
36 | +#include "SupplicantScanResultsEvent.h" | |
37 | +#include "SupplicantStateChangeEvent.h" | |
38 | +#include "SupplicantConnectionTimeoutEvent.h" | |
39 | +#include "SupplicantDisconnectedEvent.h" | |
40 | + | |
41 | +WifiController::WifiController(PropertyManager *mPropMngr, | |
42 | + IControllerHandler *handlers, | |
43 | + char *modpath, char *modname, char *modargs) : | |
44 | + Controller("WIFI", mPropMngr, handlers) { | |
33 | 45 | strncpy(mModulePath, modpath, sizeof(mModulePath)); |
34 | 46 | strncpy(mModuleName, modname, sizeof(mModuleName)); |
35 | 47 | strncpy(mModuleArgs, modargs, sizeof(mModuleArgs)); |
36 | 48 | |
37 | - mSupplicant = new Supplicant(this, propmngr); | |
49 | + mLatestScanResults = new ScanResultCollection(); | |
50 | + pthread_mutex_init(&mLatestScanResultsLock, NULL); | |
51 | + | |
52 | + mSupplicant = new Supplicant(this, this); | |
38 | 53 | mScanner = new WifiScanner(mSupplicant, 10); |
39 | 54 | mCurrentScanMode = 0; |
40 | 55 | |
41 | 56 | mEnabled = false; |
42 | 57 | |
43 | - propmngr->registerProperty("wifi.enabled", this); | |
58 | + mSupplicantState = SupplicantState::UNKNOWN; | |
44 | 59 | } |
45 | 60 | |
46 | 61 | int WifiController::start() { |
62 | + mPropMngr->registerProperty("wifi.enabled", this); | |
47 | 63 | return 0; |
48 | 64 | } |
49 | 65 | |
50 | 66 | int WifiController::stop() { |
51 | - errno = ENOSYS; | |
52 | - return -1; | |
67 | + mPropMngr->unregisterProperty("wifi.enabled"); | |
68 | + return 0; | |
53 | 69 | } |
54 | 70 | |
55 | 71 | int WifiController::enable() { |
56 | 72 | if (!isPoweredUp()) { |
57 | - sendStatusBroadcast("POWERING_UP"); | |
73 | + sendStatusBroadcast("Powering up WiFi hardware"); | |
58 | 74 | if (powerUp()) { |
59 | 75 | LOGE("Powerup failed (%s)", strerror(errno)); |
60 | 76 | return -1; |
@@ -62,7 +78,7 @@ int WifiController::enable() { | ||
62 | 78 | } |
63 | 79 | |
64 | 80 | if (mModuleName[0] != '\0' && !isKernelModuleLoaded(mModuleName)) { |
65 | - sendStatusBroadcast("LOADING_DRIVER"); | |
81 | + sendStatusBroadcast("Loading WiFi driver"); | |
66 | 82 | if (loadKernelModule(mModulePath, mModuleArgs)) { |
67 | 83 | LOGE("Kernel module load failed (%s)", strerror(errno)); |
68 | 84 | goto out_powerdown; |
@@ -70,7 +86,7 @@ int WifiController::enable() { | ||
70 | 86 | } |
71 | 87 | |
72 | 88 | if (!isFirmwareLoaded()) { |
73 | - sendStatusBroadcast("LOADING_FIRMWARE"); | |
89 | + sendStatusBroadcast("Loading WiFI firmware"); | |
74 | 90 | if (loadFirmware()) { |
75 | 91 | LOGE("Firmware load failed (%s)", strerror(errno)); |
76 | 92 | goto out_powerdown; |
@@ -78,7 +94,7 @@ int WifiController::enable() { | ||
78 | 94 | } |
79 | 95 | |
80 | 96 | if (!mSupplicant->isStarted()) { |
81 | - sendStatusBroadcast("STARTING_SUPPLICANT"); | |
97 | + sendStatusBroadcast("Starting WPA Supplicant"); | |
82 | 98 | if (mSupplicant->start()) { |
83 | 99 | LOGE("Supplicant start failed (%s)", strerror(errno)); |
84 | 100 | goto out_unloadmodule; |
@@ -93,6 +109,7 @@ int WifiController::enable() { | ||
93 | 109 | if (mSupplicant->refreshNetworkList()) |
94 | 110 | LOGW("Error getting list of networks (%s)", strerror(errno)); |
95 | 111 | |
112 | + mPropMngr->registerProperty("wifi.supplicant.state", this); | |
96 | 113 | mPropMngr->registerProperty("wifi.scanmode", this); |
97 | 114 | mPropMngr->registerProperty("wifi.interface", this); |
98 | 115 |
@@ -121,8 +138,11 @@ void WifiController::sendStatusBroadcast(const char *msg) { | ||
121 | 138 | int WifiController::disable() { |
122 | 139 | |
123 | 140 | mPropMngr->unregisterProperty("wifi.scanmode"); |
141 | + mPropMngr->unregisterProperty("wifi.supplicant.state"); | |
142 | + mPropMngr->unregisterProperty("wifi.scanmode"); | |
143 | + | |
124 | 144 | if (mSupplicant->isStarted()) { |
125 | - sendStatusBroadcast("STOPPING_SUPPLICANT"); | |
145 | + sendStatusBroadcast("Stopping WPA Supplicant"); | |
126 | 146 | if (mSupplicant->stop()) { |
127 | 147 | LOGE("Supplicant stop failed (%s)", strerror(errno)); |
128 | 148 | return -1; |
@@ -131,7 +151,7 @@ int WifiController::disable() { | ||
131 | 151 | LOGW("disable(): Supplicant not running?"); |
132 | 152 | |
133 | 153 | if (mModuleName[0] != '\0' && isKernelModuleLoaded(mModuleName)) { |
134 | - sendStatusBroadcast("UNLOADING_DRIVER"); | |
154 | + sendStatusBroadcast("Unloading WiFi driver"); | |
135 | 155 | if (unloadKernelModule(mModuleName)) { |
136 | 156 | LOGE("Unable to unload module (%s)", strerror(errno)); |
137 | 157 | return -1; |
@@ -139,7 +159,7 @@ int WifiController::disable() { | ||
139 | 159 | } |
140 | 160 | |
141 | 161 | if (isPoweredUp()) { |
142 | - sendStatusBroadcast("POWERING_DOWN"); | |
162 | + sendStatusBroadcast("Powering down WiFi hardware"); | |
143 | 163 | if (powerDown()) { |
144 | 164 | LOGE("Powerdown failed (%s)", strerror(errno)); |
145 | 165 | return -1; |
@@ -184,7 +204,15 @@ int WifiController::removeNetwork(int networkId) { | ||
184 | 204 | } |
185 | 205 | |
186 | 206 | ScanResultCollection *WifiController::createScanResults() { |
187 | - return mSupplicant->createLatestScanResults(); | |
207 | + ScanResultCollection *d = new ScanResultCollection(); | |
208 | + ScanResultCollection::iterator i; | |
209 | + | |
210 | + pthread_mutex_lock(&mLatestScanResultsLock); | |
211 | + for (i = mLatestScanResults->begin(); i != mLatestScanResults->end(); ++i) | |
212 | + d->push_back((*i)->clone()); | |
213 | + | |
214 | + pthread_mutex_unlock(&mLatestScanResultsLock); | |
215 | + return d; | |
188 | 216 | } |
189 | 217 | |
190 | 218 | WifiNetworkCollection *WifiController::createNetworkList() { |
@@ -207,7 +235,10 @@ int WifiController::set(const char *name, const char *value) { | ||
207 | 235 | return -1; |
208 | 236 | } else if (!strcmp(name, "wifi.scanmode")) |
209 | 237 | return setScanMode((uint32_t) strtoul(value, NULL, 0)); |
210 | - else | |
238 | + else if (!strcmp(name, "wifi.supplicant.state")) { | |
239 | + errno = EROFS; | |
240 | + return -1; | |
241 | + } else | |
211 | 242 | return Controller::set(name, value); |
212 | 243 | return rc; |
213 | 244 | } |
@@ -221,9 +252,158 @@ const char *WifiController::get(const char *name, char *buffer, size_t maxsize) | ||
221 | 252 | (getBoundInterface() ? getBoundInterface() : "none")); |
222 | 253 | } else if (!strcmp(name, "wifi.scanmode")) |
223 | 254 | snprintf(buffer, maxsize, "0x%.8x", mCurrentScanMode); |
255 | + else if (!strcmp(name, "wifi.supplicant.state")) | |
256 | + return SupplicantState::toString(mSupplicantState, buffer, maxsize); | |
224 | 257 | else |
225 | 258 | return Controller::get(name, buffer, maxsize); |
226 | 259 | |
227 | 260 | return buffer; |
228 | 261 | } |
229 | 262 | |
263 | +void WifiController::onAssociatingEvent(SupplicantAssociatingEvent *evt) { | |
264 | + LOGD("onAssociatingEvent(%s, %s, %d)", | |
265 | + (evt->getBssid() ? evt->getBssid() : "n/a"), | |
266 | + (evt->getSsid() ? evt->getSsid() : "n/a"), | |
267 | + evt->getFreq()); | |
268 | +} | |
269 | + | |
270 | +void WifiController::onAssociatedEvent(SupplicantAssociatedEvent *evt) { | |
271 | + LOGD("onAssociatedEvent(%s)", evt->getBssid()); | |
272 | +} | |
273 | + | |
274 | +void WifiController::onConnectedEvent(SupplicantConnectedEvent *evt) { | |
275 | + LOGD("onConnectedEvent(%s, %d)", evt->getBssid(), evt->getReassociated()); | |
276 | + if (!evt->getReassociated()) { | |
277 | + SupplicantStatus *ss = mSupplicant->getStatus(); | |
278 | + WifiNetwork *wn; | |
279 | + | |
280 | + if (ss->getWpaState() != SupplicantState::COMPLETED) { | |
281 | + char tmp[32]; | |
282 | + | |
283 | + LOGW("onConnected() with SupplicantState = %s!", | |
284 | + SupplicantState::toString(ss->getWpaState(), tmp, | |
285 | + sizeof(tmp))); | |
286 | + return; | |
287 | + } | |
288 | + | |
289 | + if (ss->getId() == -1) { | |
290 | + LOGW("onConnected() with id = -1!"); | |
291 | + return; | |
292 | + } | |
293 | + | |
294 | + if (!(wn = mSupplicant->lookupNetwork(ss->getId()))) { | |
295 | + LOGW("Error looking up connected network id %d (%s)", | |
296 | + ss->getId(), strerror(errno)); | |
297 | + return; | |
298 | + } | |
299 | + | |
300 | + delete ss; | |
301 | + mHandlers->onInterfaceStarted(this, wn->getIfaceCfg()); | |
302 | + } | |
303 | +} | |
304 | + | |
305 | +void WifiController::onScanResultsEvent(SupplicantScanResultsEvent *evt) { | |
306 | + char *reply; | |
307 | + | |
308 | + if (!(reply = (char *) malloc(4096))) { | |
309 | + LOGE("Out of memory"); | |
310 | + return; | |
311 | + } | |
312 | + | |
313 | + size_t len = 4096; | |
314 | + | |
315 | + if (mSupplicant->sendCommand("SCAN_RESULTS", reply, &len)) { | |
316 | + LOGW("onScanResultsEvent: Error getting scan results (%s)", | |
317 | + strerror(errno)); | |
318 | + free(reply); | |
319 | + return; | |
320 | + } | |
321 | + | |
322 | + pthread_mutex_lock(&mLatestScanResultsLock); | |
323 | + if (!mLatestScanResults->empty()) { | |
324 | + ScanResultCollection::iterator i; | |
325 | + | |
326 | + for (i = mLatestScanResults->begin(); | |
327 | + i !=mLatestScanResults->end(); ++i) { | |
328 | + delete *i; | |
329 | + } | |
330 | + mLatestScanResults->clear(); | |
331 | + } | |
332 | + | |
333 | + char *linep; | |
334 | + char *linep_next = NULL; | |
335 | + | |
336 | + if (!strtok_r(reply, "\n", &linep_next)) { | |
337 | + free(reply); | |
338 | + pthread_mutex_unlock(&mLatestScanResultsLock); | |
339 | + return; | |
340 | + } | |
341 | + | |
342 | + while((linep = strtok_r(NULL, "\n", &linep_next))) | |
343 | + mLatestScanResults->push_back(new ScanResult(linep)); | |
344 | + | |
345 | + char *tmp; | |
346 | + asprintf(&tmp, "Scan results ready (%d)", mLatestScanResults->size()); | |
347 | + NetworkManager::Instance()->getBroadcaster()-> | |
348 | + sendBroadcast(ErrorCode::UnsolicitedInformational, tmp, false); | |
349 | + free(tmp); | |
350 | + pthread_mutex_unlock(&mLatestScanResultsLock); | |
351 | + free(reply); | |
352 | +} | |
353 | + | |
354 | +void WifiController::onStateChangeEvent(SupplicantStateChangeEvent *evt) { | |
355 | + char tmp[32]; | |
356 | + char tmp2[32]; | |
357 | + | |
358 | + LOGD("onStateChangeEvent(%s -> %s)", | |
359 | + SupplicantState::toString(mSupplicantState, tmp, sizeof(tmp)), | |
360 | + SupplicantState::toString(evt->getState(), tmp2, sizeof(tmp2))); | |
361 | + | |
362 | + mSupplicantState = evt->getState(); | |
363 | +} | |
364 | + | |
365 | +void WifiController::onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt) { | |
366 | + LOGD("onConnectionTimeoutEvent(%s)", evt->getBssid()); | |
367 | +} | |
368 | + | |
369 | +void WifiController::onDisconnectedEvent(SupplicantDisconnectedEvent *evt) { | |
370 | + LOGD("onDisconnectedEvent()"); | |
371 | +} | |
372 | + | |
373 | +#if 0 | |
374 | +void WifiController::onTerminatingEvent(SupplicantEvent *evt) { | |
375 | + LOGD("onTerminatingEvent(%s)", evt->getEvent()); | |
376 | +} | |
377 | + | |
378 | +void WifiController::onPasswordChangedEvent(SupplicantEvent *evt) { | |
379 | + LOGD("onPasswordChangedEvent(%s)", evt->getEvent()); | |
380 | +} | |
381 | + | |
382 | +void WifiController::onEapNotificationEvent(SupplicantEvent *evt) { | |
383 | + LOGD("onEapNotificationEvent(%s)", evt->getEvent()); | |
384 | +} | |
385 | + | |
386 | +void WifiController::onEapStartedEvent(SupplicantEvent *evt) { | |
387 | + LOGD("onEapStartedEvent(%s)", evt->getEvent()); | |
388 | +} | |
389 | + | |
390 | +void WifiController::onEapMethodEvent(SupplicantEvent *evt) { | |
391 | + LOGD("onEapMethodEvent(%s)", evt->getEvent()); | |
392 | +} | |
393 | + | |
394 | +void WifiController::onEapSuccessEvent(SupplicantEvent *evt) { | |
395 | + LOGD("onEapSuccessEvent(%s)", evt->getEvent()); | |
396 | +} | |
397 | + | |
398 | +void WifiController::onEapFailureEvent(SupplicantEvent *evt) { | |
399 | + LOGD("onEapFailureEvent(%s)", evt->getEvent()); | |
400 | +} | |
401 | + | |
402 | +void WifiController::onLinkSpeedEvent(SupplicantEvent *evt) { | |
403 | + LOGD("onLinkSpeedEvent(%s)", evt->getEvent()); | |
404 | +} | |
405 | + | |
406 | +void WifiController::onDriverStateEvent(SupplicantEvent *evt) { | |
407 | + LOGD("onDriverStateEvent(%s)", evt->getEvent()); | |
408 | +} | |
409 | +#endif |
@@ -20,15 +20,21 @@ | ||
20 | 20 | #include <sys/types.h> |
21 | 21 | |
22 | 22 | #include "Controller.h" |
23 | +#include "ScanResult.h" | |
24 | +#include "WifiNetwork.h" | |
25 | +#include "ISupplicantEventHandler.h" | |
23 | 26 | |
24 | 27 | class NetInterface; |
25 | 28 | class Supplicant; |
26 | 29 | class WifiScanner; |
27 | - | |
28 | -#include "ScanResult.h" | |
29 | -#include "WifiNetwork.h" | |
30 | - | |
31 | -class WifiController : public Controller { | |
30 | +class SupplicantAssociatingEvent; | |
31 | +class SupplicantAssociatedEvent; | |
32 | +class SupplicantConnectedEvent; | |
33 | +class SupplicantScanResultsEvent; | |
34 | +class SupplicantStateChangeEvent; | |
35 | +class SupplicantDisconnectedEvent; | |
36 | + | |
37 | +class WifiController : public Controller, public ISupplicantEventHandler { | |
32 | 38 | public: |
33 | 39 | static const uint32_t SCAN_ENABLE_MASK = 0x01; |
34 | 40 | static const uint32_t SCAN_ACTIVE_MASK = 0x02; |
@@ -45,12 +51,18 @@ private: | ||
45 | 51 | char mModulePath[255]; |
46 | 52 | char mModuleName[64]; |
47 | 53 | char mModuleArgs[255]; |
54 | + | |
48 | 55 | uint32_t mCurrentScanMode; |
49 | 56 | WifiScanner *mScanner; |
57 | + int mSupplicantState; | |
58 | + | |
59 | + ScanResultCollection *mLatestScanResults; | |
60 | + pthread_mutex_t mLatestScanResultsLock; | |
61 | + | |
50 | 62 | bool mEnabled; |
51 | 63 | |
52 | 64 | public: |
53 | - WifiController(PropertyManager *propmngr, char *modpath, char *modname, char *modargs); | |
65 | + WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs); | |
54 | 66 | virtual ~WifiController() {} |
55 | 67 | |
56 | 68 | int start(); |
@@ -85,6 +97,27 @@ private: | ||
85 | 97 | int setScanMode(uint32_t mode); |
86 | 98 | int enable(); |
87 | 99 | int disable(); |
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 | + | |
88 | 121 | }; |
89 | 122 | |
90 | 123 | #endif |
@@ -76,7 +76,7 @@ WifiNetwork::WifiNetwork(WifiController *c, Supplicant *suppl, const char *data) | ||
76 | 76 | mDefaultKeyIndex = -1; |
77 | 77 | mPriority = -1; |
78 | 78 | mHiddenSsid = NULL; |
79 | - mAllowedKeyManagement = 0; | |
79 | + mAllowedKeyManagement = KeyManagementMask::UNKNOWN; | |
80 | 80 | mAllowedProtocols = 0; |
81 | 81 | mAllowedAuthAlgorithms = 0; |
82 | 82 | mAllowedPairwiseCiphers = 0; |
@@ -94,8 +94,6 @@ WifiNetwork::WifiNetwork(WifiController *c, Supplicant *suppl, const char *data) | ||
94 | 94 | asprintf(&tmp2, "wifi.net.%d", mNetid); |
95 | 95 | mIfaceCfg = new InterfaceConfig(tmp2); |
96 | 96 | free(tmp2); |
97 | - | |
98 | - registerProperties(); | |
99 | 97 | free(tmp); |
100 | 98 | } |
101 | 99 |
@@ -121,8 +119,6 @@ WifiNetwork::WifiNetwork(WifiController *c, Supplicant *suppl, int networkId) { | ||
121 | 119 | asprintf(&tmp2, "wifi.net.%d", mNetid); |
122 | 120 | mIfaceCfg = new InterfaceConfig(tmp2); |
123 | 121 | free(tmp2); |
124 | - | |
125 | - registerProperties(); | |
126 | 122 | } |
127 | 123 | |
128 | 124 | WifiNetwork *WifiNetwork::clone() { |
@@ -153,7 +149,6 @@ WifiNetwork *WifiNetwork::clone() { | ||
153 | 149 | } |
154 | 150 | |
155 | 151 | WifiNetwork::~WifiNetwork() { |
156 | - unregisterProperties(); | |
157 | 152 | if (mSsid) |
158 | 153 | free(mSsid); |
159 | 154 | if (mBssid) |
@@ -203,7 +198,26 @@ int WifiNetwork::refresh() { | ||
203 | 198 | |
204 | 199 | len = sizeof(buffer); |
205 | 200 | if (mSuppl->getNetworkVar(mNetid, "key_mgmt", buffer, len)) { |
206 | - // TODO | |
201 | + if (!strcmp(buffer, "NONE")) | |
202 | + setAllowedKeyManagement(KeyManagementMask::NONE); | |
203 | + else if (index(buffer, ' ')) { | |
204 | + char *next = buffer; | |
205 | + char *token; | |
206 | + uint32_t mask = 0; | |
207 | + | |
208 | + while((token = strsep(&next, " "))) { | |
209 | + if (!strcmp(token, "WPA-PSK")) | |
210 | + mask |= KeyManagementMask::WPA_PSK; | |
211 | + else if (!strcmp(token, "WPA-EAP")) | |
212 | + mask |= KeyManagementMask::WPA_EAP; | |
213 | + else if (!strcmp(token, "IEE8021X")) | |
214 | + mask |= KeyManagementMask::IEEE8021X; | |
215 | + else | |
216 | + LOGW("Unsupported key management scheme '%s'" , token); | |
217 | + } | |
218 | + setAllowedKeyManagement(mask); | |
219 | + } else | |
220 | + LOGE("Unsupported key management '%s'", buffer); | |
207 | 221 | } |
208 | 222 | |
209 | 223 | len = sizeof(buffer); |
@@ -273,7 +287,7 @@ int WifiNetwork::set(const char *name, const char *value) { | ||
273 | 287 | |
274 | 288 | while((v_token = strsep(&v_next, " "))) { |
275 | 289 | if (!strcasecmp(v_token, "NONE")) { |
276 | - mask = 0; | |
290 | + mask = KeyManagementMask::NONE; | |
277 | 291 | none = true; |
278 | 292 | } else if (!none) { |
279 | 293 | if (!strcasecmp(v_token, "WPA_PSK")) |
@@ -363,7 +377,29 @@ const char *WifiNetwork::get(const char *name, char *buffer, size_t maxsize) { | ||
363 | 377 | snprintf(buffer, maxsize, "%d", getDefaultKeyIndex()); |
364 | 378 | else if (!strcasecmp(fc, "pri")) |
365 | 379 | snprintf(buffer, maxsize, "%d", getPriority()); |
366 | - else if (!strcasecmp(fc, "hiddenssid")) { | |
380 | + else if (!strcasecmp(fc, "AllowedKeyManagement")) { | |
381 | + if (getAllowedKeyManagement() == KeyManagementMask::NONE) | |
382 | + strncpy(buffer, "NONE", maxsize); | |
383 | + else { | |
384 | + char tmp[80] = { '\0' }; | |
385 | + | |
386 | + if (getAllowedKeyManagement() & KeyManagementMask::WPA_PSK) | |
387 | + strcat(tmp, "WPA_PSK "); | |
388 | + if (getAllowedKeyManagement() & KeyManagementMask::WPA_EAP) | |
389 | + strcat(tmp, "WPA_EAP "); | |
390 | + if (getAllowedKeyManagement() & KeyManagementMask::IEEE8021X) | |
391 | + strcat(tmp, "IEEE8021X"); | |
392 | + if (tmp[0] == '\0') { | |
393 | + strncpy(buffer, "(internal error)", maxsize); | |
394 | + errno = ENOENT; | |
395 | + return NULL; | |
396 | + } | |
397 | + if (tmp[strlen(tmp)] == ' ') | |
398 | + tmp[strlen(tmp)] = '\0'; | |
399 | + | |
400 | + strncpy(buffer, tmp, maxsize); | |
401 | + } | |
402 | + } else if (!strcasecmp(fc, "hiddenssid")) { | |
367 | 403 | strncpy(buffer, |
368 | 404 | getHiddenSsid() ? getHiddenSsid() : "none", |
369 | 405 | maxsize); |
@@ -157,8 +157,6 @@ private: | ||
157 | 157 | |
158 | 158 | private: |
159 | 159 | WifiNetwork(); |
160 | - int registerProperties(); | |
161 | - int unregisterProperties(); | |
162 | 160 | |
163 | 161 | public: |
164 | 162 | WifiNetwork(WifiController *c, Supplicant *suppl, int networkId); |
@@ -167,6 +165,8 @@ public: | ||
167 | 165 | virtual ~WifiNetwork(); |
168 | 166 | |
169 | 167 | WifiNetwork *clone(); |
168 | + int registerProperties(); | |
169 | + int unregisterProperties(); | |
170 | 170 | |
171 | 171 | int getNetworkId() { return mNetid; } |
172 | 172 | const char *getSsid() { return mSsid; } |
@@ -187,7 +187,7 @@ public: | ||
187 | 187 | int set(const char *name, const char *value); |
188 | 188 | const char *get(const char *name, char *buffer, size_t maxsize); |
189 | 189 | |
190 | -// InterfaceConfig *getIfaceCfg() { return mIfaceCfg; } | |
190 | + InterfaceConfig *getIfaceCfg() { return mIfaceCfg; } | |
191 | 191 | |
192 | 192 | int setEnabled(bool enabled); |
193 | 193 | int setSsid(const char *ssid); |
@@ -40,10 +40,10 @@ int main() { | ||
40 | 40 | |
41 | 41 | nm->setBroadcaster((SocketListener *) cl); |
42 | 42 | |
43 | - nm->attachController(new LoopController(nm->getPropMngr())); | |
44 | - nm->attachController(new TiwlanWifiController(nm->getPropMngr(), "/system/lib/modules/wlan.ko", "wlan", "")); | |
45 | -// nm->attachController(new AndroidL2TPVpnController()); | |
46 | - nm->attachController(new OpenVpnController(nm->getPropMngr())); | |
43 | + nm->attachController(new LoopController(nm->getPropMngr(), nm)); | |
44 | + nm->attachController(new TiwlanWifiController(nm->getPropMngr(), nm, "/system/lib/modules/wlan.ko", "wlan", "")); | |
45 | +// nm->attachController(new AndroidL2TPVpnController(nm->getPropMngr(), nm)); | |
46 | + nm->attachController(new OpenVpnController(nm->getPropMngr(), nm)); | |
47 | 47 | |
48 | 48 | |
49 | 49 | if (NetworkManager::Instance()->run()) { |