summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/wireless/plugin.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/plugins/wireless/plugin.c b/src/plugins/wireless/plugin.c
index 5708372..345fc3d 100644
--- a/src/plugins/wireless/plugin.c
+++ b/src/plugins/wireless/plugin.c
@@ -18,11 +18,22 @@ static DBusHandlerResult handle_message(DBusConnection *connection, DBusMessage
static DBusHandlerResult select_network(DBusConnection *connection, DBusMessage *message, plugin_t *plugin);
static DBusHandlerResult wpa_supplicant_request(DBusConnection *connection, DBusMessage *message, plugin_t *plugin, char *cmd);
+typedef struct {
+ struct wpa_ctrl *ctrl_conn;
+} w_plugin_t;
+
static int init(plugin_t *plugin, DBusConnection *connection) {
- struct wpa_ctrl *ctrl_conn = NULL;
const char *ctrl_iface_dir = "/var/run/wpa_supplicant";
- DIR *dir = opendir(ctrl_iface_dir);
+ w_plugin_t *w_plugin;
+ w_plugin = malloc(sizeof(w_plugin_t));
+ if (!w_plugin) {
+ fprintf(stderr, "unable to malloc w_plugin\n");
+ return -1;
+ }
+ w_plugin->ctrl_conn = NULL;
+
+ DIR *dir = opendir(ctrl_iface_dir);
if (dir) {
struct dirent *dent;
while ((dent = readdir(dir))) {
@@ -38,21 +49,22 @@ static int init(plugin_t *plugin, DBusConnection *connection) {
if (cfile == NULL)
return -1;
snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, dent->d_name);
- ctrl_conn = wpa_ctrl_open(cfile);
+ w_plugin->ctrl_conn = wpa_ctrl_open(cfile);
+ w_plugin->ctrl_conn = wpa_ctrl_open(cfile);
free(cfile);
break;
}
closedir(dir);
}
- if (ctrl_conn != NULL) {
- plugin->fd = wpa_ctrl_get_fd(ctrl_conn);
- wpa_ctrl_attach(ctrl_conn);
+ if (w_plugin->ctrl_conn != NULL) {
+ plugin->fd = wpa_ctrl_get_fd(w_plugin->ctrl_conn);
+ wpa_ctrl_attach(w_plugin->ctrl_conn);
} else {
/* do not fail, the plugin will try to re-init when needed */
plugin->fd = -1;
}
- plugin->priv = (void *) ctrl_conn;
+ plugin->priv = (void *) w_plugin;
return 0;
}
@@ -77,10 +89,10 @@ static void notify_event(DBusConnection *bus, char *event) {
}
static void handle_incoming(plugin_t *plugin, DBusConnection *connection) {
- struct wpa_ctrl *ctrl_conn = (struct wpa_ctrl *) plugin->priv;
+ w_plugin_t *w_plugin = (w_plugin_t *) plugin->priv;
char buf[2048];
size_t len = sizeof(buf);
- wpa_ctrl_recv(ctrl_conn, buf, &len);
+ wpa_ctrl_recv(w_plugin->ctrl_conn, buf, &len);
buf[len] = '\0';
printf("received event: %s\n", buf);
notify_event(connection, buf);
@@ -119,7 +131,7 @@ static DBusHandlerResult select_network(DBusConnection *connection, DBusMessage
}
static DBusHandlerResult wpa_supplicant_request(DBusConnection *connection, DBusMessage *message, plugin_t *plugin, char *cmd) {
- struct wpa_ctrl *ctrl_conn = (struct wpa_ctrl *) plugin->priv;
+ w_plugin_t *w_plugin = (w_plugin_t *) plugin->priv;
DBusMessage *reply;
char buf[2048];
size_t len;
@@ -128,15 +140,15 @@ static DBusHandlerResult wpa_supplicant_request(DBusConnection *connection, DBus
char *tmp_buf;
len = sizeof(buf) - 1;
- if (ctrl_conn) {
- ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, &len, NULL);
+ if (w_plugin->ctrl_conn) {
+ ret = wpa_ctrl_request(w_plugin->ctrl_conn, cmd, strlen(cmd), buf, &len, NULL);
}
if (ret == -1) {
fprintf(stderr, "connection to wpa_supplicant daemon lost, reconnecting\n");
init(plugin, connection);
- ctrl_conn = (struct wpa_ctrl *) plugin->priv;
- if (ctrl_conn) {
- ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, &len, NULL);
+ w_plugin = (w_plugin_t *) plugin->priv;
+ if (w_plugin->ctrl_conn) {
+ ret = wpa_ctrl_request(w_plugin->ctrl_conn, cmd, strlen(cmd), buf, &len, NULL);
}
}
if (ret != 0) {