blob: 4c144a46a2adaac4f384d9dd57720d231f838dad [file] [log] [blame]
San Mehat94447ca2009-05-13 11:54:16 -07001/*
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 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehat94447ca2009-05-13 11:54:16 -070017#include <errno.h>
San Mehat5d6d4172009-05-14 15:00:06 -070018#include <netinet/in.h>
19#include <arpa/inet.h>
San Mehat94447ca2009-05-13 11:54:16 -070020
21#define LOG_TAG "OpenVpnController"
22#include <cutils/log.h>
23#include <cutils/properties.h>
24
San Mehat5d6d4172009-05-14 15:00:06 -070025#include <sysutils/ServiceManager.h>
26
San Mehat94447ca2009-05-13 11:54:16 -070027#include "OpenVpnController.h"
San Mehat3c5a6f02009-05-22 15:36:13 -070028#include "PropertyManager.h"
San Mehat94447ca2009-05-13 11:54:16 -070029
30#define DAEMON_PROP_NAME "vpn.openvpn.status"
San Mehat5d6d4172009-05-14 15:00:06 -070031#define DAEMON_CONFIG_FILE "/data/misc/openvpn/openvpn.conf"
San Mehat94447ca2009-05-13 11:54:16 -070032
San Mehat3c5a6f02009-05-22 15:36:13 -070033OpenVpnController::OpenVpnController(PropertyManager *propmngr) :
34 VpnController(propmngr) {
San Mehat5d6d4172009-05-14 15:00:06 -070035 mServiceManager = new ServiceManager();
36}
37
38OpenVpnController::~OpenVpnController() {
39 delete mServiceManager;
San Mehat94447ca2009-05-13 11:54:16 -070040}
41
42int OpenVpnController::start() {
43 return 0;
44}
45
46int OpenVpnController::stop() {
47 return 0;
48}
49
50int OpenVpnController::enable() {
San Mehat2fd9c582009-05-20 10:15:23 -070051 char svc[PROPERTY_VALUE_MAX];
52 char tmp[64];
San Mehat3c5a6f02009-05-22 15:36:13 -070053
54 if (!mPropMngr->get("vpn.gateway", tmp, sizeof(tmp))) {
San Mehat2fd9c582009-05-20 10:15:23 -070055 LOGE("Error reading property 'vpn.gateway' (%s)", strerror(errno));
San Mehat94447ca2009-05-13 11:54:16 -070056 return -1;
57 }
San Mehat2fd9c582009-05-20 10:15:23 -070058 snprintf(svc, sizeof(svc), "openvpn:--remote %s 1194", tmp);
San Mehat94447ca2009-05-13 11:54:16 -070059
San Mehat2fd9c582009-05-20 10:15:23 -070060 if (mServiceManager->start(svc))
San Mehat5d6d4172009-05-14 15:00:06 -070061 return -1;
62
San Mehat94447ca2009-05-13 11:54:16 -070063 return 0;
64}
65
66int OpenVpnController::disable() {
San Mehat5d6d4172009-05-14 15:00:06 -070067 if (mServiceManager->stop("openvpn"))
68 return -1;
69 return 0;
70}