blob: 411a0c768da362946aa8b703cfb886f3cffee2e6 [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 */
16#include <errno.h>
San Mehat5d6d4172009-05-14 15:00:06 -070017#include <netinet/in.h>
18#include <arpa/inet.h>
San Mehat94447ca2009-05-13 11:54:16 -070019
20#define LOG_TAG "OpenVpnController"
21#include <cutils/log.h>
22#include <cutils/properties.h>
23
San Mehat5d6d4172009-05-14 15:00:06 -070024#include <sysutils/ServiceManager.h>
25
San Mehat94447ca2009-05-13 11:54:16 -070026#include "OpenVpnController.h"
27
28#define DAEMON_PROP_NAME "vpn.openvpn.status"
San Mehat2fd9c582009-05-20 10:15:23 -070029
San Mehat5d6d4172009-05-14 15:00:06 -070030#define DAEMON_CONFIG_FILE "/data/misc/openvpn/openvpn.conf"
San Mehat94447ca2009-05-13 11:54:16 -070031
32OpenVpnController::OpenVpnController() :
33 VpnController() {
San Mehat5d6d4172009-05-14 15:00:06 -070034 mServiceManager = new ServiceManager();
35}
36
37OpenVpnController::~OpenVpnController() {
38 delete mServiceManager;
San Mehat94447ca2009-05-13 11:54:16 -070039}
40
41int OpenVpnController::start() {
42 return 0;
43}
44
45int OpenVpnController::stop() {
46 return 0;
47}
48
49int OpenVpnController::enable() {
San Mehat2fd9c582009-05-20 10:15:23 -070050 char svc[PROPERTY_VALUE_MAX];
51 char tmp[64];
52
53 if (!getProperty("vpn.gateway", tmp, sizeof(tmp))) {
54 LOGE("Error reading property 'vpn.gateway' (%s)", strerror(errno));
San Mehat94447ca2009-05-13 11:54:16 -070055 return -1;
56 }
San Mehat2fd9c582009-05-20 10:15:23 -070057 snprintf(svc, sizeof(svc), "openvpn:--remote %s 1194", tmp);
San Mehat94447ca2009-05-13 11:54:16 -070058
San Mehat2fd9c582009-05-20 10:15:23 -070059 if (mServiceManager->start(svc))
San Mehat5d6d4172009-05-14 15:00:06 -070060 return -1;
61
San Mehat94447ca2009-05-13 11:54:16 -070062 return 0;
63}
64
65int OpenVpnController::disable() {
San Mehat5d6d4172009-05-14 15:00:06 -070066
67 if (mServiceManager->stop("openvpn"))
68 return -1;
69 return 0;
70}