#include <connman/provider.h>
#include <connman/log.h>
#include <connman/task.h>
+#include <connman/ipconfig.h>
#include <connman/dbus.h>
#include "vpn.h"
const char *vpnc_opt;
const char *vpnc_default;
int type;
+ connman_bool_t cm_save;
} vpnc_options[] = {
- { "Host", "IPSec gateway", NULL, OPT_STRING },
- { "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING },
- { "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING },
- { "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING },
- { "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING },
- { "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING },
- { "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING },
- { "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING },
- { "VPNC.Domain", "Domain", NULL, OPT_STRING },
- { "VPNC.Vendor", "Vendor", NULL, OPT_STRING },
- { "VPNC.LocalPort", "Local Port", "0", OPT_STRING },
- { "VPNC.CiscoPort","Cisco UDP Encapsulation Port", "0", OPT_STRING },
- { "VPNC.AppVersion", "Application Version", NULL, OPT_STRING },
- { "VPNC.NATTMode", "NAT Traversal Mode", "cisco-udp", OPT_STRING },
- { "VPNC.DPDTimeout", "DPD idle timeout (our side)", NULL, OPT_STRING },
- { "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN },
- { "VPNC.NoEncryption", "Enable no encryption", NULL, OPT_BOOLEAN },
+ { "Host", "IPSec gateway", NULL, OPT_STRING, TRUE },
+ { "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING, TRUE },
+ { "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING, FALSE },
+ { "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING, FALSE },
+ { "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING, FALSE },
+ { "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING, TRUE },
+ { "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING, TRUE },
+ { "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING, TRUE },
+ { "VPNC.Domain", "Domain", NULL, OPT_STRING, TRUE },
+ { "VPNC.Vendor", "Vendor", NULL, OPT_STRING, TRUE },
+ { "VPNC.LocalPort", "Local Port", "0", OPT_STRING, TRUE, },
+ { "VPNC.CiscoPort","Cisco UDP Encapsulation Port", "0", OPT_STRING,
+ TRUE },
+ { "VPNC.AppVersion", "Application Version", NULL, OPT_STRING, TRUE },
+ { "VPNC.NATTMode", "NAT Traversal Mode", "cisco-udp", OPT_STRING,
+ TRUE },
+ { "VPNC.DPDTimeout", "DPD idle timeout (our side)", NULL, OPT_STRING,
+ TRUE },
+ { "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN, TRUE },
+ { "VPNC.NoEncryption", "Enable no encryption", NULL, OPT_BOOLEAN,
+ TRUE },
};
static int vc_notify(DBusMessage *msg, struct connman_provider *provider)
{
DBusMessageIter iter, dict;
+ char *address = NULL, *netmask = NULL, *gateway = NULL;
+ struct connman_ipaddress *ipaddress;
const char *reason, *key, *value;
dbus_message_iter_init(msg, &iter);
DBG("%s = %s", key, value);
if (!strcmp(key, "VPNGATEWAY"))
- connman_provider_set_string(provider, "Gateway", value);
+ gateway = g_strdup(value);
if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
- connman_provider_set_string(provider, "Address", value);
+ address = g_strdup(value);
if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
- connman_provider_set_string(provider, "Netmask", value);
+ netmask = g_strdup(value);
if (!strcmp(key, "INTERNAL_IP4_DNS"))
- connman_provider_set_string(provider, "DNS", value);
+ connman_provider_set_nameservers(provider, value);
if (!strcmp(key, "CISCO_DEF_DOMAIN"))
- connman_provider_set_string(provider, "Domain", value);
+ connman_provider_set_domain(provider, value);
if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
dbus_message_iter_next(&dict);
}
+
+ ipaddress = connman_ipaddress_alloc(AF_INET);
+ if (ipaddress == NULL) {
+ g_free(address);
+ g_free(netmask);
+ g_free(gateway);
+
+ return VPN_STATE_FAILURE;
+ }
+
+ connman_ipaddress_set_ipv4(ipaddress, address, netmask, gateway);
+ connman_provider_set_ipaddress(provider, ipaddress);
+
+ g_free(address);
+ g_free(netmask);
+ g_free(gateway);
+ connman_ipaddress_free(ipaddress);
+
return VPN_STATE_CONNECT;
}
return 0;
}
+static int vc_save(struct connman_provider *provider, GKeyFile *keyfile)
+{
+ const char *option;
+ int i;
+
+ for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
+ if (strncmp(vpnc_options[i].cm_opt, "VPNC.", 5) == 0) {
+
+ if (vpnc_options[i].cm_save == FALSE)
+ continue;
+
+ option = connman_provider_get_string(provider,
+ vpnc_options[i].cm_opt);
+ if (option == NULL)
+ continue;
+
+ g_key_file_set_string(keyfile,
+ connman_provider_get_save_group(provider),
+ vpnc_options[i].cm_opt, option);
+ }
+ }
+ return 0;
+}
+
static int vc_connect(struct connman_provider *provider,
struct connman_task *task, const char *if_name)
{
return err;
}
+static int vc_error_code(int exit_code)
+{
+ switch (exit_code) {
+ case 1:
+ return CONNMAN_PROVIDER_ERROR_CONNECT_FAILED;
+ case 2:
+ return CONNMAN_PROVIDER_ERROR_LOGIN_FAILED;
+ default:
+ return CONNMAN_PROVIDER_ERROR_UNKNOWN;
+ }
+}
+
static struct vpn_driver vpn_driver = {
.notify = vc_notify,
.connect = vc_connect,
+ .error_code = vc_error_code,
+ .save = vc_save,
};
static int vpnc_init(void)