Add methods for setting 802.11 network name and passphrase
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 3 Jan 2008 08:28:21 +0000 (09:28 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 3 Jan 2008 08:28:21 +0000 (09:28 +0100)
plugins/80211.c
plugins/supplicant.c
plugins/supplicant.h

index d4c63dc..5a74de5 100644 (file)
@@ -59,6 +59,9 @@ struct station_data {
 struct iface_data {
        char ifname[IFNAMSIZ];
        GSList *stations;
+
+       gchar *network;
+       gchar *passphrase;
 };
 
 static struct station_data *create_station(struct iface_data *iface,
@@ -208,6 +211,9 @@ static void iface_remove(struct connman_iface *iface)
 
        connman_iface_set_data(iface, NULL);
 
+       g_free(data->network);
+       g_free(data->passphrase);
+
        free(data);
 }
 
@@ -259,15 +265,41 @@ static int iface_scan(struct connman_iface *iface)
 static int iface_connect(struct connman_iface *iface,
                                        struct connman_network *network)
 {
-       printf("[802.11] connect interface index %d\n", iface->index);
+       struct iface_data *data = connman_iface_get_data(iface);
+
+       printf("[802.11] connect %s\n", data->ifname);
 
        __supplicant_start(iface);
 
-       __supplicant_connect(iface);
+       __supplicant_connect(iface, data->network, data->passphrase);
 
        return 0;
 }
 
+static void iface_set_network(struct connman_iface *iface,
+                                               const char *network)
+{
+       struct iface_data *data = connman_iface_get_data(iface);
+
+       printf("[802.11] set network %s\n", data->ifname);
+
+       g_free(data->network);
+
+       data->network = g_strdup(network);
+}
+
+static void iface_set_passphrase(struct connman_iface *iface,
+                                               const char *passphrase)
+{
+       struct iface_data *data = connman_iface_get_data(iface);
+
+       printf("[802.11] set passphrase %s\n", data->ifname);
+
+       g_free(data->passphrase);
+
+       data->passphrase = g_strdup(passphrase);
+}
+
 static void iface_carrier(struct connman_iface *iface, int carrier)
 {
        printf("[802.11] carrier %s\n", carrier ? "on" : "off");
@@ -480,6 +512,8 @@ static struct connman_iface_driver iface_driver = {
        .activate       = iface_activate,
        .scan           = iface_scan,
        .connect        = iface_connect,
+       .set_network    = iface_set_network,
+       .set_passphrase = iface_set_passphrase,
        .rtnl_carrier   = iface_carrier,
        .rtnl_wireless  = iface_wireless,
 };
index ec0b7e7..1eb729b 100644 (file)
@@ -260,9 +260,11 @@ int __supplicant_stop(struct connman_iface *iface)
        return 0;
 }
 
-int __supplicant_connect(struct connman_iface *iface)
+int __supplicant_connect(struct connman_iface *iface,
+                               const char *network, const char *passphrase)
 {
        struct supplicant_task *task;
+       char cmd[128];
 
        task = find_task(iface->index);
        if (task == NULL)
@@ -272,5 +274,21 @@ int __supplicant_connect(struct connman_iface *iface)
 
        exec_cmd(task, "DISABLE_NETWORK 0");
 
+       sprintf(cmd, "SET_NETWORK 0 ssid \"%s\"", network);
+       exec_cmd(task, cmd);
+
+       if (passphrase && strlen(passphrase) > 0) {
+               exec_cmd(task, "SET_NETWORK 0 proto RSN WPA");
+               exec_cmd(task, "SET_NETWORK 0 key_mgmt WPA-PSK");
+
+               sprintf(cmd, "SET_NETWORK 0 psk \"%s\"", passphrase);
+               exec_cmd(task, cmd);
+       } else {
+               exec_cmd(task, "SET_NETWORK 0 proto RSN WPA");
+               exec_cmd(task, "SET_NETWORK 0 key_mgmt NONE");
+       }
+
+       exec_cmd(task, "ENABLE_NETWORK 0");
+
        return 0;
 }
index ed753a8..9e5ebc6 100644 (file)
@@ -24,4 +24,5 @@
 int __supplicant_start(struct connman_iface *iface);
 int __supplicant_stop(struct connman_iface *iface);
 
-int __supplicant_connect(struct connman_iface *iface);
+int __supplicant_connect(struct connman_iface *iface,
+                               const char *network, const char *passphrase);