From 94447ca34b2abf9b0d9d9cb52a18bf8ba0f01b61 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Wed, 13 May 2009 11:54:16 -0700 Subject: nexus: Introduce skelaton OpenVpnController class + remove some debug messages Signed-off-by: San Mehat --- nexus/Android.mk | 1 + nexus/OpenVpnController.cpp | 104 +++++++++++++++++++++++++++++++++++++++++ nexus/OpenVpnController.h | 40 ++++++++++++++++ nexus/TiwlanWifiController.cpp | 1 - nexus/VpnController.cpp | 3 -- nexus/VpnController.h | 2 - nexus/main.cpp | 9 ++-- 7 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 nexus/OpenVpnController.cpp create mode 100644 nexus/OpenVpnController.h (limited to 'nexus') diff --git a/nexus/Android.mk b/nexus/Android.mk index 42176cf..df170b8 100644 --- a/nexus/Android.mk +++ b/nexus/Android.mk @@ -21,6 +21,7 @@ LOCAL_SRC_FILES:= \ ScanResult.cpp \ WifiScanner.cpp \ WifiNetwork.cpp \ + OpenVpnController.cpp \ LOCAL_MODULE:= nexus diff --git a/nexus/OpenVpnController.cpp b/nexus/OpenVpnController.cpp new file mode 100644 index 0000000..eff653a --- /dev/null +++ b/nexus/OpenVpnController.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#define LOG_TAG "OpenVpnController" +#include +#include + +#include "OpenVpnController.h" + +#define DAEMON_PROP_NAME "vpn.openvpn.status" + +OpenVpnController::OpenVpnController() : + VpnController() { +} + +int OpenVpnController::start() { + return 0; +} + +int OpenVpnController::stop() { + return 0; +} + +int OpenVpnController::enable() { + + // Validate configuration file + + // Validate key file + + if (startServiceDaemon()) + return -1; + + errno = -ENOSYS; + return -1; +} + +int OpenVpnController::startServiceDaemon() { + char status[PROPERTY_VALUE_MAX]; + int count = 100; + + property_set("ctl.start", "openvpn"); + sched_yield(); + + while (count-- > 0) { + if (property_get(DAEMON_PROP_NAME, status, NULL)) { + if (strcmp(status, "ok") == 0) + return 0; + else if (strcmp(DAEMON_PROP_NAME, "failed") == 0) + return -1; + } + usleep(200000); + } + property_set(DAEMON_PROP_NAME, "timeout"); + return -1; +} + +int OpenVpnController::stopServiceDaemon() { + char status[PROPERTY_VALUE_MAX] = {'\0'}; + int count = 50; + + if (property_get(DAEMON_PROP_NAME, status, NULL) && + !strcmp(status, "stopped")) { + LOGD("Service already stopped"); + return 0; + } + + property_set("ctl.stop", "openvpn"); + sched_yield(); + + while (count-- > 0) { + if (property_get(DAEMON_PROP_NAME, status, NULL)) { + if (!strcmp(status, "stopped")) + break; + } + usleep(100000); + } + + if (!count) { + LOGD("Timed out waiting for openvpn to stop"); + errno = ETIMEDOUT; + return -1; + } + + return 0; +} + +int OpenVpnController::disable() { + errno = -ENOSYS; + return -1; +} diff --git a/nexus/OpenVpnController.h b/nexus/OpenVpnController.h new file mode 100644 index 0000000..1ecc3fb --- /dev/null +++ b/nexus/OpenVpnController.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _OPEN_VPN_CONTROLLER_H +#define _OPEN_VPN_CONTROLLER_H + +#include "VpnController.h" + +class OpenVpnController : public VpnController { + +public: + OpenVpnController(); + virtual ~OpenVpnController() {} + + int start(); + int stop(); + int enable(); + int disable(); + +protected: + +private: + int startServiceDaemon(); + int stopServiceDaemon(); +}; + +#endif diff --git a/nexus/TiwlanWifiController.cpp b/nexus/TiwlanWifiController.cpp index 2dc1eb3..27c972b 100644 --- a/nexus/TiwlanWifiController.cpp +++ b/nexus/TiwlanWifiController.cpp @@ -48,7 +48,6 @@ int TiwlanWifiController::loadFirmware() { char driver_status[PROPERTY_VALUE_MAX]; int count = 100; - LOGD("loadFirmware()"); property_set("ctl.start", "wlan_loader"); sched_yield(); diff --git a/nexus/VpnController.cpp b/nexus/VpnController.cpp index 2d3db85..17bfe41 100644 --- a/nexus/VpnController.cpp +++ b/nexus/VpnController.cpp @@ -31,9 +31,6 @@ int VpnController::stop() { } int VpnController::enable() { - - // Load modules - // Start daemons errno = -ENOSYS; return -1; } diff --git a/nexus/VpnController.h b/nexus/VpnController.h index f792ce3..049fe6e 100644 --- a/nexus/VpnController.h +++ b/nexus/VpnController.h @@ -31,8 +31,6 @@ public: virtual int disable(); protected: - -private: }; #endif diff --git a/nexus/main.cpp b/nexus/main.cpp index 9945034..0aec3e5 100644 --- a/nexus/main.cpp +++ b/nexus/main.cpp @@ -23,7 +23,7 @@ #include "CommandListener.h" #include "LoopController.h" -#include "VpnController.h" +#include "OpenVpnController.h" #include "TiwlanWifiController.h" int main() { @@ -41,7 +41,8 @@ int main() { nm->attachController(new LoopController()); nm->attachController(new TiwlanWifiController("/system/lib/modules/wlan.ko", "wlan", "")); - nm->attachController(new VpnController()); +// nm->attachController(new AndroidL2TPVpnController()); + nm->attachController(new OpenVpnController()); if (NetworkManager::Instance()->run()) { @@ -50,11 +51,11 @@ int main() { } if (cl->startListener()) { - LOGE("Unable to start CommandListener (%s)", strerror(errno)); + LOGE("Unable to start CommandListener (%s)", strerror(errno)); exit (1); } - // XXX: we'll use the main thread for the NetworkManager eventuall + // XXX: we'll use the main thread for the NetworkManager eventually while(1) { sleep(1000); -- cgit v1.1