• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisão80c3b189d7e81a895524ad627841222b9c17da04 (tree)
Hora2009-05-14 04:52:53
AutorSan Mehat <san@goog...>
CommiterThe Android Open Source Project

Mensagem de Log

am 94447ca: nexus: Introduce skelaton OpenVpnController class + remove s

Merge commit '94447ca34b2abf9b0d9d9cb52a18bf8ba0f01b61'

* commit '94447ca34b2abf9b0d9d9cb52a18bf8ba0f01b61':

nexus: Introduce skelaton OpenVpnController class + remove some debug messages

Mudança Sumário

Diff

--- a/nexus/Android.mk
+++ b/nexus/Android.mk
@@ -21,6 +21,7 @@ LOCAL_SRC_FILES:= \
2121 ScanResult.cpp \
2222 WifiScanner.cpp \
2323 WifiNetwork.cpp \
24+ OpenVpnController.cpp \
2425
2526 LOCAL_MODULE:= nexus
2627
--- /dev/null
+++ b/nexus/OpenVpnController.cpp
@@ -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+}
--- /dev/null
+++ b/nexus/OpenVpnController.h
@@ -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
--- a/nexus/TiwlanWifiController.cpp
+++ b/nexus/TiwlanWifiController.cpp
@@ -48,7 +48,6 @@ int TiwlanWifiController::loadFirmware() {
4848 char driver_status[PROPERTY_VALUE_MAX];
4949 int count = 100;
5050
51- LOGD("loadFirmware()");
5251 property_set("ctl.start", "wlan_loader");
5352 sched_yield();
5453
--- a/nexus/VpnController.cpp
+++ b/nexus/VpnController.cpp
@@ -31,9 +31,6 @@ int VpnController::stop() {
3131 }
3232
3333 int VpnController::enable() {
34-
35- // Load modules
36- // Start daemons
3734 errno = -ENOSYS;
3835 return -1;
3936 }
--- a/nexus/VpnController.h
+++ b/nexus/VpnController.h
@@ -31,8 +31,6 @@ public:
3131 virtual int disable();
3232
3333 protected:
34-
35-private:
3634 };
3735
3836 #endif
--- a/nexus/main.cpp
+++ b/nexus/main.cpp
@@ -23,7 +23,7 @@
2323 #include "CommandListener.h"
2424
2525 #include "LoopController.h"
26-#include "VpnController.h"
26+#include "OpenVpnController.h"
2727 #include "TiwlanWifiController.h"
2828
2929 int main() {
@@ -41,7 +41,8 @@ int main() {
4141
4242 nm->attachController(new LoopController());
4343 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());
4546
4647
4748 if (NetworkManager::Instance()->run()) {
@@ -50,11 +51,11 @@ int main() {
5051 }
5152
5253 if (cl->startListener()) {
53- LOGE("Unable to start CommandListener (%s)", strerror(errno));
54+ LOGE("Unable to start CommandListener (%s)", strerror(errno));
5455 exit (1);
5556 }
5657
57- // XXX: we'll use the main thread for the NetworkManager eventuall
58+ // XXX: we'll use the main thread for the NetworkManager eventually
5859
5960 while(1) {
6061 sleep(1000);