5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #define CONNMAN_API_SUBJECT_TO_CHANGE
33 #include <connman/plugin.h>
34 #include <connman/provider.h>
35 #include <connman/log.h>
36 #include <connman/task.h>
40 static int oc_notify(DBusMessage *msg, struct connman_provider *provider)
42 DBusMessageIter iter, dict;
43 const char *reason, *key, *value;
44 const char *domain = NULL;
46 dbus_message_iter_init(msg, &iter);
48 dbus_message_iter_get_basic(&iter, &reason);
49 dbus_message_iter_next(&iter);
52 connman_error("No provider found");
53 return VPN_STATE_FAILURE;
56 if (strcmp(reason, "connect"))
57 return VPN_STATE_DISCONNECT;
59 domain = connman_provider_get_string(provider, "VPN.Domain");
61 dbus_message_iter_recurse(&iter, &dict);
63 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
64 DBusMessageIter entry;
66 dbus_message_iter_recurse(&dict, &entry);
67 dbus_message_iter_get_basic(&entry, &key);
68 dbus_message_iter_next(&entry);
69 dbus_message_iter_get_basic(&entry, &value);
71 if (strcmp(key, "CISCO_CSTP_OPTIONS"))
72 DBG("%s = %s", key, value);
74 if (!strcmp(key, "VPNGATEWAY"))
75 connman_provider_set_string(provider, "Gateway", value);
77 if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
78 connman_provider_set_string(provider, "Address", value);
80 if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
81 connman_provider_set_string(provider, "Netmask", value);
83 if (!strcmp(key, "INTERNAL_IP4_DNS"))
84 connman_provider_set_string(provider, "DNS", value);
86 if (!strcmp(key, "CISCO_PROXY_PAC"))
87 connman_provider_set_string(provider, "PAC", value);
89 if (domain == NULL && !strcmp(key, "CISCO_DEF_DOMAIN"))
92 if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
93 g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
94 connman_provider_append_route(provider, key, value);
96 dbus_message_iter_next(&dict);
99 connman_provider_set_string(provider, "Domain", domain);
101 return VPN_STATE_CONNECT;
104 static int oc_connect(struct connman_provider *provider,
105 struct connman_task *task, const char *if_name)
107 const char *vpnhost, *vpncookie, *cafile, *certsha1, *mtu;
110 vpnhost = connman_provider_get_string(provider, "Host");
112 connman_error("Host not set; cannot enable VPN");
116 vpncookie = connman_provider_get_string(provider, "OpenConnect.Cookie");
118 connman_error("OpenConnect.Cookie not set; cannot enable VPN");
122 certsha1 = connman_provider_get_string(provider,
123 "OpenConnect.ServerCert");
125 connman_task_add_argument(task, "--servercert",
128 cafile = connman_provider_get_string(provider, "OpenConnect.CACert");
129 mtu = connman_provider_get_string(provider, "VPN.MTU");
132 connman_task_add_argument(task, "--cafile",
135 connman_task_add_argument(task, "--mtu", (char *)mtu);
137 connman_task_add_argument(task, "--syslog", NULL);
138 connman_task_add_argument(task, "--cookie-on-stdin", NULL);
140 connman_task_add_argument(task, "--script",
141 SCRIPTDIR "/openconnect-script");
143 connman_task_add_argument(task, "--interface", if_name);
145 connman_task_add_argument(task, (char *)vpnhost, NULL);
147 err = connman_task_run(task, vpn_died, provider,
150 connman_error("openconnect failed to start");
154 if (write(fd, vpncookie, strlen(vpncookie)) !=
155 (ssize_t)strlen(vpncookie) ||
156 write(fd, "\n", 1) != 1) {
157 connman_error("openconnect failed to take cookie on stdin");
164 static int oc_error_code(int exit_code)
169 return CONNMAN_PROVIDER_ERROR_CONNECT_FAILED;
171 return CONNMAN_PROVIDER_ERROR_LOGIN_FAILED;
173 return CONNMAN_PROVIDER_ERROR_UNKNOWN;
177 static struct vpn_driver vpn_driver = {
179 .connect = oc_connect,
180 .error_code = oc_error_code,
183 static int openconnect_init(void)
185 return vpn_register("openconnect", &vpn_driver, OPENCONNECT);
188 static void openconnect_exit(void)
190 vpn_unregister("openconnect");
193 CONNMAN_PLUGIN_DEFINE(openconnect, "OpenConnect VPN plugin", VERSION,
194 CONNMAN_PLUGIN_PRIORITY_DEFAULT, openconnect_init, openconnect_exit)