struct iface_data {
char ifname[IFNAMSIZ];
GSList *stations;
+
+ gchar *network;
+ gchar *passphrase;
};
static struct station_data *create_station(struct iface_data *iface,
connman_iface_set_data(iface, NULL);
+ g_free(data->network);
+ g_free(data->passphrase);
+
free(data);
}
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");
.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,
};
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)
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;
}