system/corennnnn
Revisão | 80c3b189d7e81a895524ad627841222b9c17da04 (tree) |
---|---|
Hora | 2009-05-14 04:52:53 |
Autor | San Mehat <san@goog...> |
Commiter | The Android Open Source Project |
am 94447ca: nexus: Introduce skelaton OpenVpnController class + remove s
Merge commit '94447ca34b2abf9b0d9d9cb52a18bf8ba0f01b61'
* commit '94447ca34b2abf9b0d9d9cb52a18bf8ba0f01b61':
@@ -21,6 +21,7 @@ LOCAL_SRC_FILES:= \ | ||
21 | 21 | ScanResult.cpp \ |
22 | 22 | WifiScanner.cpp \ |
23 | 23 | WifiNetwork.cpp \ |
24 | + OpenVpnController.cpp \ | |
24 | 25 | |
25 | 26 | LOCAL_MODULE:= nexus |
26 | 27 |
@@ -0,0 +1,104 @@ | ||
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 | +#include <errno.h> | |
17 | + | |
18 | +#define LOG_TAG "OpenVpnController" | |
19 | +#include <cutils/log.h> | |
20 | +#include <cutils/properties.h> | |
21 | + | |
22 | +#include "OpenVpnController.h" | |
23 | + | |
24 | +#define DAEMON_PROP_NAME "vpn.openvpn.status" | |
25 | + | |
26 | +OpenVpnController::OpenVpnController() : | |
27 | + VpnController() { | |
28 | +} | |
29 | + | |
30 | +int OpenVpnController::start() { | |
31 | + return 0; | |
32 | +} | |
33 | + | |
34 | +int OpenVpnController::stop() { | |
35 | + return 0; | |
36 | +} | |
37 | + | |
38 | +int OpenVpnController::enable() { | |
39 | + | |
40 | + // Validate configuration file | |
41 | + | |
42 | + // Validate key file | |
43 | + | |
44 | + if (startServiceDaemon()) | |
45 | + return -1; | |
46 | + | |
47 | + errno = -ENOSYS; | |
48 | + return -1; | |
49 | +} | |
50 | + | |
51 | +int OpenVpnController::startServiceDaemon() { | |
52 | + char status[PROPERTY_VALUE_MAX]; | |
53 | + int count = 100; | |
54 | + | |
55 | + property_set("ctl.start", "openvpn"); | |
56 | + sched_yield(); | |
57 | + | |
58 | + while (count-- > 0) { | |
59 | + if (property_get(DAEMON_PROP_NAME, status, NULL)) { | |
60 | + if (strcmp(status, "ok") == 0) | |
61 | + return 0; | |
62 | + else if (strcmp(DAEMON_PROP_NAME, "failed") == 0) | |
63 | + return -1; | |
64 | + } | |
65 | + usleep(200000); | |
66 | + } | |
67 | + property_set(DAEMON_PROP_NAME, "timeout"); | |
68 | + return -1; | |
69 | +} | |
70 | + | |
71 | +int OpenVpnController::stopServiceDaemon() { | |
72 | + char status[PROPERTY_VALUE_MAX] = {'\0'}; | |
73 | + int count = 50; | |
74 | + | |
75 | + if (property_get(DAEMON_PROP_NAME, status, NULL) && | |
76 | + !strcmp(status, "stopped")) { | |
77 | + LOGD("Service already stopped"); | |
78 | + return 0; | |
79 | + } | |
80 | + | |
81 | + property_set("ctl.stop", "openvpn"); | |
82 | + sched_yield(); | |
83 | + | |
84 | + while (count-- > 0) { | |
85 | + if (property_get(DAEMON_PROP_NAME, status, NULL)) { | |
86 | + if (!strcmp(status, "stopped")) | |
87 | + break; | |
88 | + } | |
89 | + usleep(100000); | |
90 | + } | |
91 | + | |
92 | + if (!count) { | |
93 | + LOGD("Timed out waiting for openvpn to stop"); | |
94 | + errno = ETIMEDOUT; | |
95 | + return -1; | |
96 | + } | |
97 | + | |
98 | + return 0; | |
99 | +} | |
100 | + | |
101 | +int OpenVpnController::disable() { | |
102 | + errno = -ENOSYS; | |
103 | + return -1; | |
104 | +} |
@@ -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 | +#ifndef _OPEN_VPN_CONTROLLER_H | |
18 | +#define _OPEN_VPN_CONTROLLER_H | |
19 | + | |
20 | +#include "VpnController.h" | |
21 | + | |
22 | +class OpenVpnController : public VpnController { | |
23 | + | |
24 | +public: | |
25 | + OpenVpnController(); | |
26 | + virtual ~OpenVpnController() {} | |
27 | + | |
28 | + int start(); | |
29 | + int stop(); | |
30 | + int enable(); | |
31 | + int disable(); | |
32 | + | |
33 | +protected: | |
34 | + | |
35 | +private: | |
36 | + int startServiceDaemon(); | |
37 | + int stopServiceDaemon(); | |
38 | +}; | |
39 | + | |
40 | +#endif |
@@ -48,7 +48,6 @@ int TiwlanWifiController::loadFirmware() { | ||
48 | 48 | char driver_status[PROPERTY_VALUE_MAX]; |
49 | 49 | int count = 100; |
50 | 50 | |
51 | - LOGD("loadFirmware()"); | |
52 | 51 | property_set("ctl.start", "wlan_loader"); |
53 | 52 | sched_yield(); |
54 | 53 |
@@ -31,9 +31,6 @@ int VpnController::stop() { | ||
31 | 31 | } |
32 | 32 | |
33 | 33 | int VpnController::enable() { |
34 | - | |
35 | - // Load modules | |
36 | - // Start daemons | |
37 | 34 | errno = -ENOSYS; |
38 | 35 | return -1; |
39 | 36 | } |
@@ -31,8 +31,6 @@ public: | ||
31 | 31 | virtual int disable(); |
32 | 32 | |
33 | 33 | protected: |
34 | - | |
35 | -private: | |
36 | 34 | }; |
37 | 35 | |
38 | 36 | #endif |
@@ -23,7 +23,7 @@ | ||
23 | 23 | #include "CommandListener.h" |
24 | 24 | |
25 | 25 | #include "LoopController.h" |
26 | -#include "VpnController.h" | |
26 | +#include "OpenVpnController.h" | |
27 | 27 | #include "TiwlanWifiController.h" |
28 | 28 | |
29 | 29 | int main() { |
@@ -41,7 +41,8 @@ int main() { | ||
41 | 41 | |
42 | 42 | nm->attachController(new LoopController()); |
43 | 43 | nm->attachController(new TiwlanWifiController("/system/lib/modules/wlan.ko", "wlan", "")); |
44 | - nm->attachController(new VpnController()); | |
44 | +// nm->attachController(new AndroidL2TPVpnController()); | |
45 | + nm->attachController(new OpenVpnController()); | |
45 | 46 | |
46 | 47 | |
47 | 48 | if (NetworkManager::Instance()->run()) { |
@@ -50,11 +51,11 @@ int main() { | ||
50 | 51 | } |
51 | 52 | |
52 | 53 | if (cl->startListener()) { |
53 | - LOGE("Unable to start CommandListener (%s)", strerror(errno)); | |
54 | + LOGE("Unable to start CommandListener (%s)", strerror(errno)); | |
54 | 55 | exit (1); |
55 | 56 | } |
56 | 57 | |
57 | - // XXX: we'll use the main thread for the NetworkManager eventuall | |
58 | + // XXX: we'll use the main thread for the NetworkManager eventually | |
58 | 59 | |
59 | 60 | while(1) { |
60 | 61 | sleep(1000); |