From da90bdb89995f9a3cdd83582616c852009ac5957 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 13 Apr 2010 19:34:21 +0200 Subject: [PATCH] from now on, master branch will hold www only. --- Makefile | 36 ---- common.h | 45 ----- dbus-handler.c | 202 ------------------- dbus-handler.h | 43 ---- dbus-helper.c | 308 ----------------------------- dbus-helper.h | 65 ------ dbus.c | 81 -------- dbus.h | 42 ---- gconf.c | 51 ----- gconf.h | 31 --- icd.c | 531 ------------------------------------------------- icd.h | 36 ---- log.h | 35 ---- networks.c | 408 -------------------------------------- networks.h | 50 ----- supp.c | 598 -------------------------------------------------------- supp.h | 49 ----- wlan.c | 339 -------------------------------- wlan.h | 52 ----- 19 files changed, 3002 deletions(-) delete mode 100644 Makefile delete mode 100644 common.h delete mode 100644 dbus-handler.c delete mode 100644 dbus-handler.h delete mode 100644 dbus-helper.c delete mode 100644 dbus-helper.h delete mode 100644 dbus.c delete mode 100644 dbus.h delete mode 100644 gconf.c delete mode 100644 gconf.h delete mode 100644 icd.c delete mode 100644 icd.h delete mode 100644 log.h delete mode 100644 networks.c delete mode 100644 networks.h delete mode 100644 supp.c delete mode 100644 supp.h delete mode 100644 wlan.c delete mode 100644 wlan.h diff --git a/Makefile b/Makefile deleted file mode 100644 index acd2cab..0000000 --- a/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -LIBTOOL=libtool - -CFLAGS += -Wall -O2 -DDEBUG -DOSSOLOG_STDERR -shared -LDFLAGS += -shared -module - -# Library flags -PKG_CFLAGS := $(shell pkg-config --cflags glib-2.0 gconf-2.0 dbus-1 dbus-glib-1 osso-ic) -PKG_LDFLAGS := $(shell pkg-config --libs glib-2.0 gconf-2.0 dbus-1 dbus-glib-1) -CFLAGS += $(PKG_CFLAGS) -LDFLAGS += $(PKG_LDFLAGS) - -LTFLAGS = -shared - -BINARY = libicd_network_wpa.so -OBJS = icd.o wlan.o networks.o gconf.o \ - dbus.o dbus-helper.o dbus-handler.o supp.o - -all: $(BINARY) - -$(BINARY): $(OBJS) - $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $^ - -%.o: %.c - $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $< -o $@ - -clean: - $(LIBTOOL) --mode=clean $(RM) libicd_network_wpa.so *.o - -install: $(BINARY) - $(LIBTOOL) --mode=install install -c --strip --mode=644 \ - $(BINARY) $(DESTDIR)/usr/lib/icd2/ - $(LIBTOOL) --mode=finish $(DESTDIR)/usr/lib/icd2/ - - -.PHONY: all clean install - diff --git a/common.h b/common.h deleted file mode 100644 index 3f3fca3..0000000 --- a/common.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - @file common.h - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#define WPA_IFACE "wlan0" - -#define WPA_NETWORK_TYPE "WLAN_WPA" - -#define WPA_GCONF_NETWORK_TYPE "/type" -#define WPA_GCONF_NETWORK_TYPE_VALUE WPA_NETWORK_TYPE - -#define WPA_GCONF_SSID "/wpa_ssid" - -#define WPA_GCONF_SETTING_PREFIX "wpa_" -#define WPA_GCONF_SETTING_PREFIX_LEN 4 - -#define SEARCH_CONTINUE 0 -#define SEARCH_FINISHED 1 -#define SEARCH_STOPPED 2 - -#endif diff --git a/dbus-handler.c b/dbus-handler.c deleted file mode 100644 index 02ce44e..0000000 --- a/dbus-handler.c +++ /dev/null @@ -1,202 +0,0 @@ -/** - @file dbus-helper.c - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - Copyright (C) 2009 Javier S. Pedro - - @author Janne Ylalehto - @author Johan Hedberg - - @author Javier S. Pedro - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -#include - -#include - -#include "dbus-helper.h" -#include "dbus-handler.h" -#include "wlan.h" -#include "supp.h" -#include "log.h" - -static DBusHandlerResult wlancond_scan_results_handler(DBusMessage *message) { - DBusMessageIter iter; - gint32 number_of_results, i; - - if (!wlan_is_scanning()) { - DLOG_DEBUG("Received scan results we didn't ask for"); - // TODO: Somehow use them - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - dbus_message_iter_init(message, &iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) - goto param_err; - - dbus_message_iter_get_basic(&iter, &number_of_results); - - dbus_message_iter_next(&iter); - - for (i = 0; i < number_of_results; i++) { - DBusMessageIter array_iter; - gint32 ssid_len, bssid_len; - gchar * ssid, * bssid; - gint32 rssi; - guint32 channel, cap_bits; - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || - dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE) { - - goto param_err; - } - - dbus_message_iter_recurse(&iter, &array_iter); - dbus_message_iter_get_fixed_array(&array_iter, &ssid, &ssid_len); - dbus_message_iter_next(&iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || - dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE) { - - goto param_err; - } - - dbus_message_iter_recurse(&iter, &array_iter); - dbus_message_iter_get_fixed_array(&array_iter, &bssid, &bssid_len); - dbus_message_iter_next(&iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) - goto param_err; - dbus_message_iter_get_basic(&iter, &rssi); - dbus_message_iter_next(&iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) - goto param_err; - dbus_message_iter_get_basic(&iter, &channel); - dbus_message_iter_next(&iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) - goto param_err; - dbus_message_iter_get_basic(&iter, &cap_bits); - dbus_message_iter_next(&iter); - - DLOG_INFO("Scan result with %s.", ssid); - wlan_notify_ap(ssid, bssid, - rssi, channel, cap_bits); - } - - DLOG_DEBUG("Handled scan result, results=%ld.", - (long) number_of_results); - - wlan_notify_end_of_search(); - - return DBUS_HANDLER_RESULT_HANDLED; -param_err: - DLOG_WARN("Parameter error in scan request"); - - wlan_notify_end_of_search(); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult supp_state_change_handler(DBusMessage *message) { - gchar *old_state, *new_state; - - if (!dbus_message_get_args( - message, NULL, - DBUS_TYPE_STRING, &new_state, - DBUS_TYPE_STRING, &old_state, - DBUS_TYPE_INVALID)) - { - DLOG_WARN("Supplicant StateChange signal format error"); - return DBUS_HANDLER_RESULT_HANDLED; - } - - supp_handle_signal(old_state, new_state); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult wlancond_sig_handler(DBusConnection *connection, - DBusMessage *message, - void *user_data) { - if (dbus_message_is_signal(message, - WLANCOND_SIG_INTERFACE, - WLANCOND_SCAN_RESULTS_SIG)) - return wlancond_scan_results_handler(message); - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static DBusHandlerResult supp_sig_handler(DBusConnection *connection, - DBusMessage *message, - void *user_data) { - if (dbus_message_is_signal(message, - WPAS_DBUS_IFACE_INTERFACE, - WPAS_STATE_CHANGE_SIG)) - return supp_state_change_handler(message); - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -/** - Create bindings for D-BUS handlers. - @param connection DBUS connection. -*/ -void init_dbus_handlers(DBusConnection *connection) { - gboolean ret; - /*dbus_bool_t ret; - ret = dbus_connection_register_object_path(connection, - WLANCOND_REQ_PATH, - &wlancond_req_vtable, - NULL); - if (ret == FALSE) { - DLOG_ERR("dbus_connection_register_object_path failed"); - }*/ - - dbus_bus_add_match(connection, - "interface=" WLANCOND_SIG_INTERFACE - ",member=" WLANCOND_SCAN_RESULTS_SIG, NULL); - - ret = dbus_connection_add_filter(connection, - (DBusHandleMessageFunction)wlancond_sig_handler, NULL, NULL); - - if (!ret) { - DLOG_ERR("dbus_connection_add_filter failed"); - } - - dbus_bus_add_match(connection, - "interface=" WPAS_DBUS_IFACE_INTERFACE - ",member=" WPAS_STATE_CHANGE_SIG, NULL); - - ret = dbus_connection_add_filter(connection, - (DBusHandleMessageFunction)supp_sig_handler, NULL, NULL); - - if (!ret) { - DLOG_ERR("dbus_connection_add_filter failed"); - } -} - -/** - Destroy D-BUS handlers. - @param connection DBUS connection. -*/ -void destroy_dbus_handlers(DBusConnection *connection) { - //dbus_connection_unregister_object_path(connection, WLANCOND_REQ_PATH); -} diff --git a/dbus-handler.h b/dbus-handler.h deleted file mode 100644 index a274b6a..0000000 --- a/dbus-handler.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - @file dbus-helper.c - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - @author Janne Ylalehto - @author Johan Hedberg - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef _DBUS_HANDLER_H_ -#define _DBUS_HANDLER_H_ - -#ifndef DBUS_API_SUBJECT_TO_CHANGE -# define DBUS_API_SUBJECT_TO_CHANGE -# include -#endif - -/** Bind functions to corresponding D-Bus messages - * @param connection D-Bus connection - */ -void init_dbus_handlers(DBusConnection *connection); - -/** Free memory allocated to handlers - * @param connection D-Bus connection - */ -void destroy_dbus_handlers(DBusConnection *connection); - -#endif /* _DBUS_HANDLER_H_ */ diff --git a/dbus-helper.c b/dbus-helper.c deleted file mode 100644 index 4d3d025..0000000 --- a/dbus-helper.c +++ /dev/null @@ -1,308 +0,0 @@ -/** - @file dbus-helper.c - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - Copyright (C) 2003-2009, Jouni Malinen and contributors. - Copyright (C) 2009 Javier S. Pedro - - @author Janne Ylalehto - @author Johan Hedberg - @author Jouni Malinen and contributors - @author Javier S. Pedro - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ -#include -#include -#include - -#define DBUS_API_SUBJECT_TO_CHANGE -#include -#include "log.h" -#include "dbus-helper.h" - -DBusMessage *new_dbus_signal(const char *path, - const char *interface, - const char *name, - const char *destination) { - DBusMessage *signal; - - signal = dbus_message_new_signal(path, interface, name); - if (signal == NULL) { - die("Out of memory during dbus_message_new_error()"); - } - - if (destination) { - if (!dbus_message_set_destination(signal, destination)) { - die("Out of memory during dbus_message_set_destination()"); - } - } - - dbus_message_set_no_reply(signal, TRUE); - - return signal; -} - -DBusMessage *new_dbus_method_call(const char *service, - const char *path, - const char *interface, - const char *method) { - DBusMessage *message; - - message = dbus_message_new_method_call(service, path, interface, method); - if (message == NULL) { - die("Out of memory during dbus_message_new_method_call()"); - } - - return message; -} - -DBusMessage *new_dbus_method_return(DBusMessage *message) { - DBusMessage *reply; - - reply = dbus_message_new_method_return(message); - if (reply == NULL) { - die("Out of memory during dbus_message_new_method_return()"); - } - - return reply; -} - -DBusMessage *new_dbus_error(DBusMessage *message, const char *name) { - DBusMessage *error; - - error = dbus_message_new_error(message, name, NULL); - if (error == NULL) { - die("Out of memory during dbus_message_new_error()"); - } - - return error; -} - -int send_and_unref(DBusConnection *connection, DBusMessage *message) { - if (!dbus_connection_send(connection, message, NULL)) { - dbus_message_unref(message); - return -1; - } - - dbus_connection_flush(connection); - dbus_message_unref(message); - - return 0; -} - -int send_invalid_args(DBusConnection *connection, DBusMessage *message) { - DBusMessage *reply; - - reply = new_dbus_error(message, DBUS_ERROR_INVALID_ARGS); - - return send_and_unref(connection, reply); -} - -void append_dbus_args(DBusMessage *message, int first_arg_type, ...) { - dbus_bool_t ret; - va_list ap; - - va_start(ap, first_arg_type); - ret = dbus_message_append_args_valist(message, first_arg_type, ap); - va_end(ap); - - if (ret == FALSE) { - die("dbus_message_append_args failed"); - } -} - -/** - * Start a dict in a dbus message. Should be paired with a call to - * {@link wpa_dbus_dict_close_write}. - * - * @param iter A valid dbus message iterator - * @param iter_dict (out) A dict iterator to pass to further dict functions - * @return 0 on success, -1 on failure - * - */ -int dbus_dict_open_write(DBusMessageIter *iter, - DBusMessageIter *iter_dict) -{ - dbus_bool_t result; - - if (!iter || !iter_dict) - return FALSE; - - result = dbus_message_iter_open_container( - iter, - DBUS_TYPE_ARRAY, - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - DBUS_TYPE_STRING_AS_STRING - DBUS_TYPE_VARIANT_AS_STRING - DBUS_DICT_ENTRY_END_CHAR_AS_STRING, - iter_dict); - - return (result ? 0 : -1); -} - -/** - * End a dict element in a dbus message. Should be paired with - * a call to {@link wpa_dbus_dict_open_write}. - * - * @param iter valid dbus message iterator, same as passed to - * wpa_dbus_dict_open_write() - * @param iter_dict a dbus dict iterator returned from - * {@link wpa_dbus_dict_open_write} - * @return 0 on success, -1 on failure - * - */ -int dbus_dict_close_write(DBusMessageIter *iter, - DBusMessageIter *iter_dict) -{ - if (!iter || !iter_dict) - return FALSE; - - return dbus_message_iter_close_container(iter, iter_dict) ? 0 : -1; -} - -static const char * _get_type_as_string_from_type(const int type) -{ - switch(type) { - case DBUS_TYPE_BYTE: - return DBUS_TYPE_BYTE_AS_STRING; - case DBUS_TYPE_BOOLEAN: - return DBUS_TYPE_BOOLEAN_AS_STRING; - case DBUS_TYPE_INT16: - return DBUS_TYPE_INT16_AS_STRING; - case DBUS_TYPE_UINT16: - return DBUS_TYPE_UINT16_AS_STRING; - case DBUS_TYPE_INT32: - return DBUS_TYPE_INT32_AS_STRING; - case DBUS_TYPE_UINT32: - return DBUS_TYPE_UINT32_AS_STRING; - case DBUS_TYPE_INT64: - return DBUS_TYPE_INT64_AS_STRING; - case DBUS_TYPE_UINT64: - return DBUS_TYPE_UINT64_AS_STRING; - case DBUS_TYPE_DOUBLE: - return DBUS_TYPE_DOUBLE_AS_STRING; - case DBUS_TYPE_STRING: - return DBUS_TYPE_STRING_AS_STRING; - case DBUS_TYPE_OBJECT_PATH: - return DBUS_TYPE_OBJECT_PATH_AS_STRING; - case DBUS_TYPE_ARRAY: - return DBUS_TYPE_ARRAY_AS_STRING; - default: - return NULL; - } -} - -static int _dbus_add_dict_entry_start( - DBusMessageIter *iter_dict, DBusMessageIter *iter_dict_entry, - const char *key, const int value_type) -{ - if (!dbus_message_iter_open_container(iter_dict, - DBUS_TYPE_DICT_ENTRY, NULL, - iter_dict_entry)) - return FALSE; - - if (!dbus_message_iter_append_basic(iter_dict_entry, DBUS_TYPE_STRING, - &key)) - return FALSE; - - return TRUE; -} - - -static dbus_bool_t _dbus_add_dict_entry_end( - DBusMessageIter *iter_dict, DBusMessageIter *iter_dict_entry, - DBusMessageIter *iter_dict_val) -{ - if (!dbus_message_iter_close_container(iter_dict_entry, iter_dict_val)) - return FALSE; - if (!dbus_message_iter_close_container(iter_dict, iter_dict_entry)) - return FALSE; - - return TRUE; -} - -static dbus_bool_t _dbus_add_dict_entry_basic(DBusMessageIter *iter_dict, - const char *key, - const int value_type, - const void *value) -{ - DBusMessageIter iter_dict_entry, iter_dict_val; - const char *type_as_string = NULL; - - type_as_string = _get_type_as_string_from_type(value_type); - if (!type_as_string) - return FALSE; - - if (!_dbus_add_dict_entry_start(iter_dict, &iter_dict_entry, - key, value_type)) - return FALSE; - - if (!dbus_message_iter_open_container(&iter_dict_entry, - DBUS_TYPE_VARIANT, - type_as_string, &iter_dict_val)) - return FALSE; - - if (!dbus_message_iter_append_basic(&iter_dict_val, value_type, value)) - return FALSE; - - if (!_dbus_add_dict_entry_end(iter_dict, &iter_dict_entry, - &iter_dict_val)) - return FALSE; - - return TRUE; -} - -/** - * Add a string entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from - * {@link wpa_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The string value - * @return TRUE on success, FALSE on failure - * - */ -int dbus_dict_append_string(DBusMessageIter *iter_dict, - const char *key, const char *value) -{ - if (!key || !value) - return FALSE; - return _dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_STRING, - &value) ? 0 : -1; -} - -/** - * Add a 32-bit signed integer to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from - * {@link wpa_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 32-bit signed integer value - * @return TRUE on success, FALSE on failure - * - */ -int dbus_dict_append_int32(DBusMessageIter *iter_dict, - const char *key, - const dbus_int32_t value) -{ - if (!key) - return FALSE; - return _dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_INT32, - &value) ? 0 : -1; -} - diff --git a/dbus-helper.h b/dbus-helper.h deleted file mode 100644 index 094ce0c..0000000 --- a/dbus-helper.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - @file dbus-helper.h - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - @author Janne Ylälehto - @author Jouni Malinen and contributors - @author Javier S. Pedro - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -#ifndef _DBUS_HELPER_H_ -#define _DBUS_HELPER_H_ - -#ifndef DBUS_API_SUBJECT_TO_CHANGE -# define DBUS_API_SUBJECT_TO_CHANGE -# include -#endif - -void append_dbus_args(DBusMessage *message, int first_arg_type, ...); - -int send_and_unref(DBusConnection *connection, DBusMessage *message); - -int send_invalid_args(DBusConnection *connection, DBusMessage *message); - -DBusMessage *new_dbus_signal(const char *path, - const char *interface, - const char *name, - const char *destination); - -DBusMessage *new_dbus_method_call(const char *service, - const char *path, - const char *interface, - const char *method); - -DBusMessage *new_dbus_method_return(DBusMessage *message); - -DBusMessage *new_dbus_error(DBusMessage *message, const char *name); - -int dbus_dict_open_write(DBusMessageIter *iter, - DBusMessageIter *iter_dict); -int dbus_dict_close_write(DBusMessageIter *iter, - DBusMessageIter *iter_dict); - -int dbus_dict_append_string(DBusMessageIter *iter_dict, - const char *key, const char *value); - -int dbus_dict_append_int32(DBusMessageIter *iter_dict, - const char *key, - const dbus_int32_t value); - -#endif /* _DBUD_HELPER_H_ */ diff --git a/dbus.c b/dbus.c deleted file mode 100644 index cd14973..0000000 --- a/dbus.c +++ /dev/null @@ -1,81 +0,0 @@ -/** - @file dbus.c - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - @author Johan Hedberg - @author Janne Ylälehto - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -#include -#include -#include - -#define DBUS_API_SUBJECT_TO_CHANGE -#include -#include -#include - -#include "log.h" -#include "dbus.h" - -static DBusConnection *_dbus_connection = NULL; - -DBusConnection *get_dbus_connection(void) { - return _dbus_connection; -} - -int setup_dbus_connection(const char *service, - void (*handler_init)(DBusConnection *connection)) { - DBusError derror; - - g_assert(_dbus_connection == NULL); - - dbus_error_init(&derror); - _dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &derror); - if (_dbus_connection == NULL) { - DLOG_ERR("System DBus connection failed: %s", derror.message); - dbus_error_free(&derror); - return -1; - } - dbus_connection_setup_with_g_main(_dbus_connection, NULL); - - if (service) { - int ret = dbus_bus_request_name(_dbus_connection, service, 0, - &derror); - if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - DLOG_ERR("Could not aquire D-BUS name '%s' (ret: %d)", - service, ret); - if (dbus_error_is_set(&derror)) { - DLOG_DEBUG("%s", derror.message); - dbus_error_free(&derror); - } - return -1; - } - } - - if (handler_init) - handler_init(_dbus_connection); - - return 0; -} - -void close_dbus_connection(void) { - g_assert(_dbus_connection != NULL); - dbus_connection_unref(_dbus_connection); - _dbus_connection = NULL; -} diff --git a/dbus.h b/dbus.h deleted file mode 100644 index ba53f24..0000000 --- a/dbus.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - @file dbus.h - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - @author Johan Hedberg - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -#ifndef _DBUS_H_ -#define _DBUS_H_ - -#ifndef DBUS_API_SUBJECT_TO_CHANGE -# define DBUS_API_SUBJECT_TO_CHANGE -# include -#endif - -/** Connect to the system D-Bus - * @returns 0 on success, -1 on failure - */ -int setup_dbus_connection(const char *service, - void (*handler_init)(DBusConnection *connection)); - -/** Disconnect from the system D-Bus */ -void close_dbus_connection(void); - -DBusConnection *get_dbus_connection(void); - -#endif /* _DBUS_H_ */ diff --git a/gconf.c b/gconf.c deleted file mode 100644 index f08e567..0000000 --- a/gconf.c +++ /dev/null @@ -1,51 +0,0 @@ -/** - @file gconf.c - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include - -#include -#include - -#include "log.h" - -gchar * gconf_get_string(GConfClient *client, gchar * path) -{ - GError *error = NULL; - gchar *value = gconf_client_get_string(client, path, &error); - - if (error) { - DLOG_ERR("Could not get setting:%s, error:%s", path, - error->message); - - g_clear_error(&error); - value = NULL; - } else if (!value) { - DLOG_ERR("Could not get setting:%s", path); - } - - g_free(path); - - return value; -} diff --git a/gconf.h b/gconf.h deleted file mode 100644 index 4c52dee..0000000 --- a/gconf.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - @file gconf.h - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef _GCONF_H_ -#define _GCONF_H_ - -gchar * gconf_get_string(GConfClient *client, gchar * path); - -#endif diff --git a/icd.c b/icd.c deleted file mode 100644 index 4b07322..0000000 --- a/icd.c +++ /dev/null @@ -1,531 +0,0 @@ -/** - @file icd.c - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include - -#include -#include - -#include "common.h" -#include "dbus.h" -#include "dbus-handler.h" -#include "log.h" -#include "supp.h" -#include "networks.h" -#include "icd.h" - -/** time in seconds a found network is kept cached by icd2 */ -#define ICD_SEARCH_LIFETIME (5 * 60) -/** time in seconds after which a new network scan is to be triggered */ -#define ICD_SEARCH_INTERVAL (2 * 60) - -/** time (in milliseconds) to wait after a wpa_supplicant disconnected event - * before calling it a day and shutting down the interface */ -#define ICD_DISCONNECTED_TIMEOUT (60 * 1000) - -/** icd flags to use */ -#define ICD_WPA_FLAGS (ICD_NW_ATTR_AUTOCONNECT | ICD_NW_ATTR_IAPNAME) - - -/** equivalent to signal level 0 */ -#define RSSI_MIN (-85) -/** equivalent to signal level max */ -#define RSSI_MAX (-30) -/* guaranteed to be random, chosen by fair dice roll :) */ - - -static icd_nw_watch_pid_fn icd_watch_fn; -static gpointer icd_watch_token; -static icd_nw_close_fn icd_close_fn; -static icd_nw_status_change_fn icd_status_change_fn; -static icd_nw_renew_fn icd_renew_fn; - -static gchar * cur_network_id = NULL; - -/** @see ICD_DISCONNECTED_TIMEOUT */ -static guint connect_timeout = 0; - -static inline gint rssi_to_signal(gint rssi) -{ - gint signal = rssi - RSSI_MIN + ICD_NW_LEVEL_NONE; - signal *= ICD_NW_LEVEL_10; - signal /= (RSSI_MAX - RSSI_MIN); - - if (signal < ICD_NW_LEVEL_NONE) return ICD_NW_LEVEL_NONE; - else if (signal > ICD_NW_LEVEL_10) return ICD_NW_LEVEL_10; - else return signal; -} - -static gboolean disconnected_timeout_cb(gpointer data) -{ - // If connect_timeout is 0, we have been disabled. - if (!connect_timeout) return FALSE; - - // Disconnected for too long - DLOG_DEBUG("Disconnected for way too long"); - icd_close(ICD_NW_ERROR, ICD_DBUS_ERROR_NETWORK_ERROR); - connect_timeout = 0; - return FALSE; -} - -/** Supplicant callback while fully connected */ -static void icd_supp_cb(enum supp_status status, const char * error_str, - gpointer user_data) -{ - DLOG_DEBUG("%s: %d", __func__, status); - - switch (status) { - case SUPP_STATUS_ERROR: - DLOG_WARN_L("Unexpected supplicant error"); - - // Fall through - case SUPP_STATUS_KILLED: - // Close connection - icd_close(ICD_NW_ERROR, ICD_DBUS_ERROR_SYSTEM_ERROR); - - break; - case SUPP_STATUS_DISCONNECTED: - if (!connect_timeout) { - DLOG_DEBUG("Disconnected, starting timeout"); - connect_timeout = g_timeout_add( - ICD_DISCONNECTED_TIMEOUT, - disconnected_timeout_cb, - NULL - ); - } - break; - case SUPP_STATUS_CONNECTED: - if (connect_timeout) { - DLOG_DEBUG("Connected, removing timeout"); - g_source_remove(connect_timeout); - connect_timeout = 0; - } - break; - } - - // TODO Disable PSM while roaming (dis/asociating)? -} - -struct pre_down_data { - icd_nw_link_pre_down_cb_fn link_pre_down_cb; - gpointer link_pre_down_cb_token; -}; - -/** Supplicant callback in link_pre_down mode */ -static void icd_down_supp_cb(enum supp_status status, const char * error_str, - gpointer user_data) -{ - struct pre_down_data *data = (struct pre_down_data *) user_data; - DLOG_DEBUG("%s: %d", __func__, status); - - if (status == SUPP_STATUS_KILLED) { - // Everything was fine - supp_set_callback(NULL, NULL); - data->link_pre_down_cb(ICD_NW_SUCCESS, - data->link_pre_down_cb_token); - } -} - -static void -icd_pre_down (const gchar *network_type, - const guint network_attrs, - const gchar *network_id, - const gchar *interface_name, - icd_nw_link_pre_down_cb_fn link_pre_down_cb, - const gpointer link_pre_down_cb_token, - gpointer *private) -{ - DLOG_DEBUG(__func__); - - - struct pre_down_data *data = g_new(struct pre_down_data, 1); - data->link_pre_down_cb = link_pre_down_cb; - data->link_pre_down_cb_token = link_pre_down_cb_token; - - if (supp_is_active()) { - supp_set_callback(icd_down_supp_cb, data); - - // Kill the supplicant, - supp_disable(); - // but wait for the "child exit" event. - } else { - // Supplicant is already dead, no need to wait. - supp_set_callback(NULL, NULL); - supp_disable(); // Clears status info - - link_pre_down_cb(ICD_NW_SUCCESS, link_pre_down_cb_token); - } -} - -struct post_up_data { - icd_nw_link_post_up_cb_fn link_post_up_cb; - gpointer link_post_up_cb_token; -}; - -/** Supplicant callback in link_post_up status */ -static void icd_up_supp_cb(enum supp_status status, const char * error_str, - gpointer user_data) -{ - struct post_up_data *data = (struct post_up_data *) user_data; - DLOG_DEBUG("%s: %d", __func__, status); - - switch (status) { - case SUPP_STATUS_CONNECTED: - data->link_post_up_cb(ICD_NW_SUCCESS_NEXT_LAYER, - NULL, - data->link_post_up_cb_token, NULL); - - supp_set_callback(icd_supp_cb, NULL); - g_free(data); - break; - case SUPP_STATUS_DISCONNECTED: - error_str = ICD_DBUS_ERROR_WLAN_AUTH_FAILED; - - // Fall through - case SUPP_STATUS_ERROR: - - // An error happened - // kill the supplicant before everything crashes. - supp_set_callback(NULL, NULL); - supp_disable(); - - // Fall through - case SUPP_STATUS_KILLED: - data->link_post_up_cb(ICD_NW_ERROR, - error_str, - data->link_post_up_cb_token, NULL); - - g_free(data); - break; - - } -} - -static void icd_post_up(const gchar *network_type, - const guint network_attrs, - const gchar *network_id, - const gchar *interface_name, - icd_nw_link_post_up_cb_fn link_post_up_cb, - const gpointer link_post_up_cb_token, - gpointer *private) -{ - DLOG_DEBUG(__func__); - - struct post_up_data *data = g_new(struct post_up_data, 1); - data->link_post_up_cb = link_post_up_cb; - data->link_post_up_cb_token = link_post_up_cb_token; - - supp_set_callback(icd_up_supp_cb, data); - - if (supp_enable() != 0) - { - icd_up_supp_cb(-1, ICD_DBUS_ERROR_SYSTEM_ERROR, data); - } - - supp_set_interface(interface_name); - supp_set_network_id(network_id); -} - -static void icd_link_down(const gchar *network_type, - const guint network_attrs, - const gchar *network_id, - const gchar *interface_name, - icd_nw_link_down_cb_fn link_down_cb, - const gpointer link_down_cb_token, - gpointer *private) -{ - DLOG_DEBUG(__func__); - - networks_disconnect(network_id); - - g_free(cur_network_id); - cur_network_id = NULL; - - // TODO: Maybe wait for wlancond->disconnect callback? - - link_down_cb(ICD_NW_SUCCESS, link_down_cb_token); -} - -struct link_up_data { - icd_nw_link_up_cb_fn link_up_cb; - gpointer link_up_cb_token; -}; - -static void icd_link_up_done(int status, const char *error, gpointer user_data) -{ - DLOG_DEBUG("%s: %d", __func__, status); - - struct link_up_data *data = (struct link_up_data *) user_data; - - if (status) { - g_free(cur_network_id); - cur_network_id = NULL; - data->link_up_cb(ICD_NW_ERROR, - error, - WPA_IFACE, data->link_up_cb_token, - NULL); - - } else { - data->link_up_cb(ICD_NW_SUCCESS_NEXT_LAYER, - NULL, - WPA_IFACE, data->link_up_cb_token, - NULL); - } - - g_free(data); -} - -static void icd_link_up(const gchar *network_type, - const guint network_attrs, - const gchar *network_id, - icd_nw_link_up_cb_fn link_up_cb, - const gpointer link_up_cb_token, - gpointer *private) -{ - DLOG_DEBUG("%s: %s", __func__, network_id); - - struct link_up_data *data = g_new(struct link_up_data, 1); - data->link_up_cb = link_up_cb; - data->link_up_cb_token = link_up_cb_token; - - if (cur_network_id) { - DLOG_WARN_L("Double link up"); - - data->link_up_cb(ICD_NW_TOO_MANY_CONNECTIONS, - NULL, - WPA_IFACE, data->link_up_cb_token, - NULL); - - return; - } - cur_network_id = g_strdup(network_id); - - networks_connect(network_id, icd_link_up_done, data); -} - -struct stats_data { - icd_nw_link_stats_cb_fn cb; - gpointer token; -}; - -static void icd_link_stats_done - (int status, const char * strdata, int rssi, gpointer user_data) -{ - DLOG_DEBUG("%s: %d", __func__, status); - - struct stats_data * data = (struct stats_data *) user_data; - - gint signal = rssi_to_signal(rssi); - - DLOG_DEBUG("status: rssi=%d, signal=%d", rssi, signal); - - data->cb(data->token, - WPA_NETWORK_TYPE, - ICD_WPA_FLAGS, - cur_network_id, - /*time_active*/ 0, - /*signal*/ signal, - /*station_id*/ NULL, - /*dB*/ rssi, - /*tx*/0, - /*rx*/0); - - // IPv[46] module will fill time_active, rx & tx values. - // TODO station_id - - g_free(data); -} - -static void icd_link_stats(const gchar *network_type, - const guint network_attrs, - const gchar *network_id, - gpointer *private, - icd_nw_link_stats_cb_fn cb, - const gpointer link_stats_cb_token) -{ - DLOG_DEBUG("%s", __func__); - - struct stats_data *data = g_new(struct stats_data, 1); - data->cb = cb; - data->token = link_stats_cb_token; - - networks_status(icd_link_stats_done, data); -} - -struct search_data { - icd_nw_search_cb_fn search_cb; - gpointer search_cb_token; -}; - -static void icd_send_search_result(int status, const char * id, - const char * ssid, const char * ap, int rssi, gpointer user_data) -{ - DLOG_DEBUG("%s: %d", __func__, status); - - struct search_data * data = (struct search_data *) user_data; - gint signal; - - switch (status) { - case SEARCH_CONTINUE: - signal = rssi_to_signal(rssi); - - data->search_cb(ICD_NW_SEARCH_CONTINUE, - (gchar *) ssid, - WPA_NETWORK_TYPE, - ICD_WPA_FLAGS, - (gchar *) id, - signal, - /*ap*/"ap", - signal, - data->search_cb_token); - break; - case SEARCH_FINISHED: - data->search_cb(ICD_NW_SEARCH_COMPLETE, - NULL, - WPA_NETWORK_TYPE, - 0, - NULL, - ICD_NW_LEVEL_NONE, - NULL, - 0, - data->search_cb_token); - // Fall through - case SEARCH_STOPPED: - g_free(user_data); - break; - } -} - -static void icd_start_search(const gchar *network_type, - guint search_scope, - icd_nw_search_cb_fn search_cb, - const gpointer search_cb_token, - gpointer *private) -{ - DLOG_DEBUG(__func__); - - struct search_data *data = g_new(struct search_data, 1); - data->search_cb = search_cb; - data->search_cb_token = search_cb_token; - - networks_search_start(icd_send_search_result, data); -} - -static void icd_stop_search(gpointer *private) -{ - DLOG_DEBUG(__func__); - - // Never seen this called. - - networks_search_stop(); -} - -static void icd_child_exit(const pid_t pid, - const gint exit_value, - gpointer *private) -{ - DLOG_DEBUG(__func__); - - /*// Supplicant crashed/exited! - if (killed_supp_cb) { - // We have killed it, notify auth layer is now down. - - g_free(killed_supp_cb); - killed_supp_cb = 0; - } else { - DLOG_WARN("Supplicant exited, but we didn't expect it"); - icd_close(ICD_NW_ERROR, ICD_DBUS_ERROR_SYSTEM_ERROR); - }*/ - supp_handle_killed(); -} - -static void icd_network_destruct(gpointer *private) -{ - DLOG_DEBUG(__func__); - - // Fortunately, icd kills the supplicant for us. - - close_dbus_connection(); - networks_free(); -} - -gboolean icd_nw_init ( - struct icd_nw_api *network_api, - icd_nw_watch_pid_fn watch_fn, - gpointer watch_fn_token, - icd_nw_close_fn close_fn, - icd_nw_status_change_fn status_change_fn, - icd_nw_renew_fn renew_fn ) -{ - network_api->version = ICD_NW_MODULE_VERSION; - network_api->private = NULL; - - network_api->link_pre_down = icd_pre_down; - network_api->link_post_up = icd_post_up; - - network_api->link_down = icd_link_down; - network_api->link_up = icd_link_up; - network_api->link_stats = icd_link_stats; - - network_api->search_lifetime = ICD_SEARCH_LIFETIME; - network_api->search_interval = ICD_SEARCH_INTERVAL; - - network_api->start_search = icd_start_search; - network_api->stop_search = icd_stop_search; - - network_api->child_exit = icd_child_exit; - - network_api->network_destruct = icd_network_destruct; - - icd_watch_fn = watch_fn; - icd_watch_token = watch_fn_token; - icd_close_fn = close_fn; - icd_status_change_fn = status_change_fn; - icd_renew_fn = renew_fn; - - if (networks_initialize() != 0) { - DLOG_ERR_L("Network list failed!"); - return FALSE; - } - - if (setup_dbus_connection(NULL, init_dbus_handlers) != 0) { - DLOG_ERR_L("D-BUS connection setup failed!"); - return FALSE; - } - - return TRUE; -} - -void icd_watch_pid(const pid_t pid) -{ - icd_watch_fn(pid, icd_watch_token); -} - -void icd_close(enum icd_nw_status status, - const gchar *err_str) -{ - icd_close_fn(status, err_str, WPA_NETWORK_TYPE, ICD_WPA_FLAGS, cur_network_id); -} - diff --git a/icd.h b/icd.h deleted file mode 100644 index 467fbb7..0000000 --- a/icd.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - @file icd.h - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef _ICD_H_ -#define _ICD_H_ - -#include - -void icd_watch_pid(const pid_t pid); - -void icd_close(enum icd_nw_status status, - const gchar *err_str); - -#endif diff --git a/log.h b/log.h deleted file mode 100644 index 9c45895..0000000 --- a/log.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - @file log.h - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - @author Johan Hedberg - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -#ifndef _LOG_H_ -#define _LOG_H_ - -#include -#include - -/** Print error message and exit */ -#define die(...) do { \ - DLOG_ERR(__VA_ARGS__); \ - exit(EXIT_FAILURE); \ -} while (0) - -#endif /* _LOG_H_ */ diff --git a/networks.c b/networks.c deleted file mode 100644 index 7f52ae1..0000000 --- a/networks.c +++ /dev/null @@ -1,408 +0,0 @@ -/** - @file networks.c - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include -#include - -#include -#include - -#include -#include - -#include "common.h" -#include "log.h" -#include "wlan.h" -#include "networks.h" -#include "gconf.h" - -#define FAILED_SCAN_RETRY_WAIT 3 * 1000 -#define FAILED_SCAN_RETRY_TRIES 10 - -#define GCONF_NETWORK_TYPE "/type" - -static GSList *net_list = NULL; - -int networks_initialize() -{ - DLOG_DEBUG(__func__); - GConfClient *client = gconf_client_get_default(); - GError *error = NULL; - - net_list = NULL; - - if (!client) { - DLOG_ERR("Cannot get gconf client"); - return -1; - } - - net_list = gconf_client_all_dirs(client, ICD_GCONF_PATH, &error); - if (error) { - DLOG_ERR("Could not get setting:%s, error:%s", ICD_GCONF_PATH, - error->message); - g_clear_error(&error); - g_object_unref(client); - return -1; - } - - // Now, filter networks - GSList *prev = NULL; - GSList *cur = net_list; - while (cur) { - gchar* path = g_strconcat(cur->data, WPA_GCONF_NETWORK_TYPE, NULL); - gchar* type = gconf_client_get_string(client, path, &error); - - g_free(path); - - if (error) { - DLOG_ERR("Could not get setting:%s, error:%s", path, - error->message); - g_clear_error(&error); - - goto initialize_error; - } else if (!type) { - DLOG_ERR("Could not get setting:%s", path); - - goto initialize_error; - } - - if (strcmp(type, WPA_GCONF_NETWORK_TYPE_VALUE) != 0) { - // Remove this network from the list - DLOG_DEBUG("Ignoring %s from IAP (type is %s)", - (gchar*)cur->data, type); - g_free(cur->data); - if (prev) { - GSList *del = cur; - cur = g_slist_next(cur); - g_slist_free1(del); - prev->next = cur; - } else { - net_list = g_slist_next(cur); - g_slist_free1(cur); - cur = net_list; - } - } else { - DLOG_DEBUG("Added network %s from IAP", (gchar*)cur->data); - - prev = cur; - cur = g_slist_next(cur); - } - - g_free(type); - } - - return 0; - -initialize_error: - g_object_unref(client); - networks_free(); - - return -1; -} - -static void free_list_item(gpointer data, gpointer user_data) -{ - g_free(data); -} - -void networks_free() -{ - DLOG_DEBUG(__func__); - if (!net_list) return; - - g_slist_foreach(net_list, free_list_item, NULL); - - g_slist_free(net_list); - net_list = NULL; -} - - -/* Scanning networks */ - -static GSList *scan_cur_net = NULL; -static gchar *scan_cur_ssid = NULL; -static int scan_tries = 0; -static guint scan_retry_timer = 0; -static networks_search_found scan_found_cb = NULL; -static gpointer scan_found_cb_data = NULL; - -static void networks_search_iteration(); - -static void networks_search_finished() -{ - DLOG_DEBUG(__func__); - - scan_found_cb(SEARCH_FINISHED, NULL, - NULL, NULL, 0, scan_found_cb_data); - scan_cur_net = NULL; - - scan_found_cb = NULL; - scan_found_cb_data = NULL; - // Usually a new network_search will not happen on the FINISED cb, - // but if you do, you'll have to take care of the pseudorace here. - - networks_search_stop(); -} - -static void networks_search_scan_ap_found(int status, - const char * ssid, const char * ap, int dB) -{ - DLOG_DEBUG(__func__); - - if (!scan_cur_net) return; - if (scan_retry_timer) return; // Interface was already scanning - - if (status == SEARCH_FINISHED) { - DLOG_DEBUG("Searching for %s done, iterating", scan_cur_ssid); - // Go to next network - scan_cur_net = g_slist_next(scan_cur_net); - if (scan_cur_net) { - g_free(scan_cur_ssid); - scan_cur_ssid = NULL; - scan_tries = 0; - networks_search_iteration(); - } else { - // No more networks to search - networks_search_finished(); - } - } else if (status == SEARCH_CONTINUE) { - DLOG_DEBUG("Found ssid %s", ssid); - if (strcmp(ssid, scan_cur_ssid) == 0) - { - // This is our man - gchar *full_name = g_strdup(scan_cur_net->data); - - gchar *base_name = g_strdup(basename(full_name)); - - DLOG_INFO("%s (%s) was found", - base_name, ssid); - - scan_found_cb(SEARCH_CONTINUE, base_name, - ssid, ap, dB, scan_found_cb_data); - - g_free(base_name); - g_free(full_name); - } - } -} - -static gboolean networks_search_retry(gpointer data) -{ - DLOG_DEBUG(__func__); - - scan_retry_timer = 0; - if (scan_cur_net) networks_search_iteration(); - // Always disable this timeout, - // _search_iteration() will put a newer one if needed - return FALSE; -} - -static void networks_search_iteration() -{ - DLOG_DEBUG(__func__); - - GConfClient *client = gconf_client_get_default(); - GError *error = NULL; - - if (!client) { - DLOG_ERR("Cannot get gconf client"); - goto get_gconf_error; - } - - DLOG_DEBUG("Test if %s is active", (gchar*)scan_cur_net->data); - - gchar *path = g_strconcat(scan_cur_net->data, WPA_GCONF_SSID, NULL); - scan_cur_ssid = gconf_client_get_string(client, path, &error); - - g_object_unref(client); - - if (error) { - DLOG_ERR("Could not get setting:%s, error:%s", path, - error->message); - g_clear_error(&error); - - goto get_ssid_error; - } - else if (!scan_cur_ssid) { - DLOG_ERR("Could not get setting:%s", path); - - goto get_ssid_error; - } - - scan_retry_timer = 0; - - int result = wlan_scan(scan_cur_ssid, networks_search_scan_ap_found); - - if (result != 0) { - // Something went wront scanning this network, set timeout and - // try again - scan_tries++; - if (scan_tries >= FAILED_SCAN_RETRY_TRIES) { - // Give up - goto scan_error; - } else { - scan_retry_timer = g_timeout_add(FAILED_SCAN_RETRY_WAIT, - networks_search_retry, - NULL); - } - } - - return; -get_ssid_error: - g_free(path); - -get_gconf_error: -scan_error: - networks_search_finished(); -} - -void networks_search_start(networks_search_found found_cb, gpointer user_data) -{ - DLOG_DEBUG(__func__); - - if (scan_cur_net) - return; // Already active - - scan_cur_net = net_list; - scan_tries = 0; - scan_found_cb = found_cb; - scan_found_cb_data = user_data; - - if (scan_cur_net) - networks_search_iteration(); - else // No networks to scan? - networks_search_finished(); -} - -void networks_search_stop() -{ - DLOG_DEBUG(__func__); - - if (scan_found_cb) - scan_found_cb(SEARCH_STOPPED, - NULL, NULL, NULL, 0, scan_found_cb_data); - scan_cur_net = NULL; - - scan_found_cb = NULL; - scan_found_cb_data = NULL; - - g_free(scan_cur_ssid); - scan_cur_ssid = NULL; - - DLOG_DEBUG("Search stopped"); -} - -/* Connecting to networks */ - -static networks_connect_result connect_result_cb = NULL; -static gpointer connect_result_cb_data = NULL; - -static void networks_connected(int status, const char *error) -{ - DLOG_DEBUG("%s: %d", __func__, status); - - if (!connect_result_cb) return; - - if (status) { - connect_result_cb(status, ICD_DBUS_ERROR_NETWORK_ERROR, - connect_result_cb_data); - } else { - connect_result_cb(0, NULL, - connect_result_cb_data); - } - - connect_result_cb = NULL; -} - -void networks_connect(const char * id, - networks_connect_result result_cb, gpointer user_data) -{ - DLOG_DEBUG("%s: %s", __func__, id); - GConfClient *client = gconf_client_get_default(); - - connect_result_cb = result_cb; - connect_result_cb_data = user_data; - - gchar *net = g_strconcat(ICD_GCONF_PATH, "/", id, NULL); - gchar *path, *value; - - // Get ICD network type - path = g_strconcat(net, WPA_GCONF_NETWORK_TYPE, NULL); - value = gconf_get_string(client, path); - - if (!value || strcmp(value, WPA_GCONF_NETWORK_TYPE_VALUE) != 0) { - result_cb(-1, ICD_DBUS_ERROR_INVALID_IAP, user_data); - goto connect_error; - } - - g_free(value); - - path = g_strconcat(net, WPA_GCONF_SSID, NULL); - value = gconf_get_string(client, path); - - if (!value) { - result_cb(-1, ICD_DBUS_ERROR_INVALID_IAP, user_data); - goto connect_error; - } - - wlan_connect(value, networks_connected); - -connect_error: - if (value) g_free(value); -} - -void networks_disconnect(const char * id) -{ - wlan_disconnect(); -} - -/* -- STATUS -- */ - -static networks_status_result status_result_cb = NULL; -static gpointer status_result_cb_data = NULL; - -static void networks_status_reply(int status, - const char * essid, int essid_len, - const char * bssid, int bssid_len, - int qual, int channel, unsigned long security, unsigned long capability, - const char * data) -{ - if (!status_result_cb) return; - - if (status == 0) { - status_result_cb(status, essid, qual, status_result_cb_data); - } else { - status_result_cb(status, data, 0, status_result_cb_data); - } -} - -void networks_status(networks_status_result result_cb, gpointer user_data) -{ - status_result_cb = result_cb; - status_result_cb_data = user_data; - - wlan_get_status(networks_status_reply); -} - diff --git a/networks.h b/networks.h deleted file mode 100644 index c06c41e..0000000 --- a/networks.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - @file networks.h - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef _NETWORKS_H_ -#define _NETWORKS_H_ - -int networks_initialize(); -void networks_free(); - -// NULL, NULL, 0 if search ended -typedef void (*networks_search_found) - (int status, const char * id, - const char * ssid, const char * ap, int dB, gpointer user_data); - -void networks_search_start(networks_search_found found_cb, gpointer user_data); -void networks_search_stop(); - -typedef void (*networks_connect_result) - (int status, const char * error, gpointer user_data); -void networks_connect(const char * id, - networks_connect_result result_cb, gpointer user_data); -void networks_disconnect(const char * id); - -typedef void (*networks_status_result) - (int status, const char * data, int rssi, gpointer user_data); -void networks_status(networks_status_result result_cb, gpointer user_data); - -#endif diff --git a/supp.c b/supp.c deleted file mode 100644 index 3877e46..0000000 --- a/supp.c +++ /dev/null @@ -1,598 +0,0 @@ -/** - @file supp.c - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include -#include - -#include -#include -#include - -#include -#include - -#include "log.h" -#include "common.h" -#include "icd.h" -#include "dbus.h" -#include "dbus-helper.h" -#include "supp.h" - -/* Errors */ -#define WPAS_ERROR_INVALID_NETWORK \ - WPAS_DBUS_IFACE_INTERFACE ".InvalidNetwork" -#define WPAS_ERROR_INVALID_BSSID \ - WPAS_DBUS_IFACE_INTERFACE ".InvalidBSSID" - -#define WPAS_ERROR_INVALID_OPTS \ - WPAS_DBUS_INTERFACE ".InvalidOptions" -#define WPAS_ERROR_INVALID_IFACE \ - WPAS_DBUS_INTERFACE ".InvalidInterface" - -#define WPAS_ERROR_ADD_ERROR \ - WPAS_DBUS_INTERFACE ".AddError" -#define WPAS_ERROR_EXISTS_ERROR \ - WPAS_DBUS_INTERFACE ".ExistsError" -#define WPAS_ERROR_REMOVE_ERROR \ - WPAS_DBUS_INTERFACE ".RemoveError" - -#define WPAS_ERROR_SCAN_ERROR \ - WPAS_DBUS_IFACE_INTERFACE ".ScanError" -#define WPAS_ERROR_ADD_NETWORK_ERROR \ - WPAS_DBUS_IFACE_INTERFACE ".AddNetworkError" -#define WPAS_ERROR_INTERNAL_ERROR \ - WPAS_DBUS_IFACE_INTERFACE ".InternalError" -#define WPAS_ERROR_REMOVE_NETWORK_ERROR \ - WPAS_DBUS_IFACE_INTERFACE ".RemoveNetworkError" - -#define WPAS_DBUS_BSSID_FORMAT "%02x%02x%02x%02x%02x%02x" - -static pid_t supp_pid = 0; -static int supp_activation_tries = 0; - -static gchar* supp_iface = NULL; -static gchar* supp_iface_path = NULL; - -static gchar* supp_network_id = NULL; -static gchar* supp_config_path = NULL; - -static gboolean supp_configured = FALSE; // Unused right now - -/* Callback for supplicant events */ -static supp_cb_fn supp_cb = NULL; -static gpointer supp_cb_data = NULL; - -static void supp_configure(); - -void supp_set_callback(supp_cb_fn cb, gpointer user_data) -{ - supp_cb = cb; - supp_cb_data = user_data; -} - -static inline void supp_callback(int result, const char * message) -{ - if (supp_cb) supp_cb(result, message, supp_cb_data); -} - -static gboolean supp_set_interface_retry(gpointer data) -{ - DLOG_DEBUG(__func__); - - if (supp_pid && supp_iface) supp_set_interface(supp_iface); - return FALSE; -} - -static void add_iface_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("%s", __func__); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - DLOG_WARN_L("Error in %s:%s", __func__, error.name); - - if (strcmp(DBUS_ERROR_SERVICE_UNKNOWN, error.name) == 0) - { - // Supplicant not (yet) active? Try later - DLOG_DEBUG("Still waiting for supplicant"); - supp_activation_tries++; - if (supp_activation_tries >= 3) { - supp_callback(-1, error.name); - } else { - g_timeout_add(1000, - supp_set_interface_retry, - NULL); - } - } else { - supp_callback(-1, error.name); - } - - dbus_error_free(&error); - } else if (reply) { - // Move on to next step - gchar* path; - if (!dbus_message_get_args( - reply, NULL, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID)) - { - supp_callback(-1, error.name); - goto iface_reply_error; - } - - supp_iface_path = g_strdup(path); - DLOG_DEBUG("Got interface path: %s", supp_iface_path); - if (supp_network_id && !supp_config_path) { - supp_set_network_id(supp_network_id); - } else if (supp_config_path && !supp_configured) { - supp_configure(); - } - } - -iface_reply_error: - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -void supp_unset_interface() -{ - // TODO - // mostly uneeded, since we're killing the supplicant instead - g_free(supp_iface_path); - supp_iface_path = NULL; - g_free(supp_iface); - supp_iface = NULL; -} - -void supp_set_interface(const char * iface) -{ - DBusMessage *msg; - DBusPendingCall *pending; - - DLOG_DEBUG("%s: %s", __func__, iface); - - if (supp_iface_path) { - supp_unset_interface(); - } - - if (iface != supp_iface) { - if (supp_iface) { - g_free(supp_iface); - } - - supp_iface = g_strdup(iface); - } - - msg = new_dbus_method_call( - WPAS_DBUS_SERVICE, - WPAS_DBUS_PATH, - WPAS_DBUS_INTERFACE, - "addInterface"); - - append_dbus_args( - msg, - DBUS_TYPE_STRING, &iface, - DBUS_TYPE_INVALID); - - if (!dbus_connection_send_with_reply(get_dbus_connection(), - msg, &pending, -1)) - die("Out of memory"); - - if (!dbus_pending_call_set_notify(pending, - add_iface_reply_cb, NULL, NULL)) - die("Out of memory"); - - dbus_message_unref(msg); -} - -static void add_network_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("%s", __func__); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - DLOG_WARN_L("Error in %s:%s", __func__, error.name); - - supp_callback(-1, error.name); - dbus_error_free(&error); - } else if (reply) { - // Move on to next step - gchar* path; - if (!dbus_message_get_args( - reply, NULL, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID)) - { - supp_callback(-1, error.name); - goto net_reply_error; - } - - supp_config_path = g_strdup(path); - DLOG_DEBUG("Got network path: %s", supp_iface_path); - if (supp_iface_path && !supp_configured) { - supp_configure(); - } - } - -net_reply_error: - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -void supp_unset_network_id() -{ - g_free(supp_config_path); - supp_config_path = NULL; - g_free(supp_network_id); - supp_network_id = NULL; - // TODO -} - -void supp_set_network_id(const char * network_id) -{ - DBusMessage *msg; - DBusPendingCall *pending; - - DLOG_DEBUG("%s: %s", __func__, network_id); - - if (supp_config_path) { - supp_unset_network_id(); - } - - if (network_id != supp_network_id) { - if (supp_network_id) { - g_free(supp_network_id); - } - - supp_network_id = g_strdup(network_id); - } - - if (!supp_iface_path) { - DLOG_DEBUG("Deferring network creation"); - return; - } - - msg = new_dbus_method_call( - WPAS_DBUS_SERVICE, - supp_iface_path, - WPAS_DBUS_IFACE_INTERFACE, - "addNetwork"); - - if (!dbus_connection_send_with_reply(get_dbus_connection(), - msg, &pending, -1)) - die("Out of memory"); - - if (!dbus_pending_call_set_notify(pending, - add_network_reply_cb, NULL, NULL)) - die("Out of memory"); - - dbus_message_unref(msg); -} - -static gchar * wpas_params[3] = { "/sbin/wpa_supplicant", "-u", NULL }; - -int supp_enable() -{ - DLOG_DEBUG("%s", __func__); - - supp_activation_tries = 0; - - GError* error; - GPid pid; - if (!g_spawn_async(NULL, wpas_params, NULL, - G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, &pid, &error)) { - DLOG_ERR("Couldn't spawn supplicant: %s", error->message); - return -1; - } - - supp_pid = pid; - - DLOG_INFO("Spawned %s , pid %d", wpas_params[0], pid); - - icd_watch_pid(supp_pid); - - return 0; -} - -void supp_disable(void) -{ - if (supp_pid) { - DLOG_INFO("Killing supplicant (pid %d)", supp_pid); - kill(supp_pid, SIGTERM); - } - - // Consider everything as deconfigured - g_free(supp_iface); - supp_iface = NULL; - g_free(supp_iface_path); - supp_iface_path = NULL; - g_free(supp_network_id); - supp_network_id = NULL; - g_free(supp_config_path); - supp_config_path = NULL; - - supp_configured = FALSE; -} - -int supp_is_active(void) -{ - return supp_pid ? TRUE : FALSE; -} - -void supp_handle_signal(gchar* old_state, gchar* new_state) -{ - DLOG_DEBUG("Supplicant StateChange %s -> %s", old_state, new_state); - - if (strcmp(new_state, "COMPLETED") == 0) - { - supp_callback(SUPP_STATUS_CONNECTED, new_state); - } else if (strcmp(new_state, "DISCONNECTED") == 0) { - supp_callback(SUPP_STATUS_DISCONNECTED, new_state); - } -} - -void supp_handle_killed(void) -{ - DLOG_DEBUG("%s", __func__); - - g_spawn_close_pid(supp_pid); - supp_pid = 0; - - supp_disable(); - - supp_callback(SUPP_STATUS_KILLED, NULL); -} - -static void free_settings_item(gpointer data, gpointer user_data) -{ - gconf_entry_free(data); -} - -static void enable_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("%s", __func__); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - DLOG_WARN_L("Error in %s:%s", __func__, error.name); - - supp_callback(SUPP_STATUS_ERROR, error.name); - dbus_error_free(&error); - } - - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -static void supp_enable_network() -{ - DBusMessage* message; //The full mesage we are going to send. - DBusPendingCall *pending; - - message = dbus_message_new_method_call( - WPAS_DBUS_SERVICE, - supp_config_path, - WPAS_DBUS_IFACE_NETWORK, - WPAS_ENABLE_NETWORK_METHOD - ); - if (!message) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - return; - } - - // Send message - if (!dbus_connection_send_with_reply(get_dbus_connection(), - message, &pending, -1)) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - goto send_error; - } - - if (!dbus_pending_call_set_notify(pending, - enable_reply_cb, NULL, NULL)) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - } - - // Fall through -send_error: - dbus_message_unref(message); -} - -static void configure_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("%s", __func__); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - DLOG_WARN_L("Error in %s:%s", __func__, error.name); - - supp_callback(-1, error.name); - dbus_error_free(&error); - } else if (reply) { - supp_enable_network(); - } - - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -static void supp_configure() -{ - // This is going to be long - DLOG_DEBUG("%s: %s", __func__, supp_network_id); - GConfClient *client = gconf_client_get_default(); - GError *error = NULL; - - DBusMessage* message; //The full mesage we are going to send. - DBusMessageIter iter, iter_dict; - DBusPendingCall *pending; - - if (!client) { - DLOG_ERR("Cannot get gconf client"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - return; - } - - gchar * settings_path = g_strconcat(ICD_GCONF_PATH, - "/", supp_network_id, NULL); - - GSList * settings = gconf_client_all_entries(client, - settings_path, &error); - if (error) { - DLOG_ERR("Could not get setting:%s, error:%s", settings_path, - error->message); - g_free(settings_path); - g_clear_error(&error); - g_object_unref(client); - supp_callback(-1, error->message); - return; - } - - message = dbus_message_new_method_call( - WPAS_DBUS_SERVICE, - supp_config_path, - WPAS_DBUS_IFACE_NETWORK, - WPAS_SET_NETWORK_METHOD - ); - if (!message) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - goto msg_init_error; - } - - dbus_message_iter_init_append(message, &iter); - if (dbus_dict_open_write(&iter, &iter_dict) != 0) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - goto dict_init_error; - } - - DLOG_DEBUG("Preparing to send %d settings", g_slist_length(settings)); - - GSList* i; - for (i = settings; i; i = g_slist_next(i)) { - GConfEntry* entry = i->data; - gchar * key = g_path_get_basename(gconf_entry_get_key(entry)); - GConfValue* value = gconf_entry_get_value(entry); - - if (g_ascii_strncasecmp(key, - WPA_GCONF_SETTING_PREFIX, - WPA_GCONF_SETTING_PREFIX_LEN)) { - g_free(key); - continue; - } - - // Skip prefix - key += WPA_GCONF_SETTING_PREFIX_LEN; - - switch (value->type) { - case GCONF_VALUE_STRING: - DLOG_DEBUG("Setting string %s = %s", - key, gconf_value_get_string(value)); - dbus_dict_append_string(&iter_dict, - key, gconf_value_get_string(value)); - break; - - case GCONF_VALUE_INT: - DLOG_DEBUG("Setting int32 %s = %d", - key, gconf_value_get_int(value)); - dbus_dict_append_int32(&iter_dict, - key, gconf_value_get_int(value)); - break; - default: - DLOG_DEBUG("Unknown setting type for %s", - key); - break; - } - - key -= WPA_GCONF_SETTING_PREFIX_LEN; - g_free(key); - } - - if (dbus_dict_close_write(&iter, &iter_dict) != 0) { - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - goto dict_close_error; - } - - // Send message - if (!dbus_connection_send_with_reply(get_dbus_connection(), - message, &pending, -1)) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - goto send_error; - } - - if (!dbus_pending_call_set_notify(pending, - configure_reply_cb, NULL, NULL)) { - DLOG_CRIT_L("Out of memory"); - supp_callback(-1, ICD_DBUS_ERROR_SYSTEM_ERROR); - goto send_error; - } - - // Fall through -send_error: -dict_close_error: -dict_init_error: - dbus_message_unref(message); -msg_init_error: - g_free(settings_path); - - g_slist_foreach(settings, free_settings_item, NULL); - g_slist_free(settings); - - g_object_unref(client); -} - diff --git a/supp.h b/supp.h deleted file mode 100644 index 0314d57..0000000 --- a/supp.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _SUPP_H_ -#define _SUPP_H_ - -int supp_enable(); -void supp_disable(); - -#define WPAS_DBUS_OBJECT_PATH_MAX 150 - -#define WPAS_DBUS_SERVICE "fi.epitest.hostap.WPASupplicant" -#define WPAS_DBUS_PATH "/fi/epitest/hostap/WPASupplicant" -#define WPAS_DBUS_INTERFACE "fi.epitest.hostap.WPASupplicant" - -#define WPAS_STATE_CHANGE_SIG "StateChange" - -#define WPAS_DBUS_PATH_INTERFACES WPAS_DBUS_PATH "/Interfaces" -#define WPAS_DBUS_IFACE_INTERFACE WPAS_DBUS_INTERFACE ".Interface" - -#define WPAS_DBUS_NETWORKS_PART "Networks" -#define WPAS_DBUS_IFACE_NETWORK WPAS_DBUS_INTERFACE ".Network" - -#define WPAS_DBUS_BSSIDS_PART "BSSIDs" -#define WPAS_DBUS_IFACE_BSSID WPAS_DBUS_INTERFACE ".BSSID" - -#define WPAS_SET_NETWORK_METHOD "set" -#define WPAS_ENABLE_NETWORK_METHOD "enable" - -enum supp_status { - SUPP_STATUS_KILLED = -2, - SUPP_STATUS_ERROR = -1, - SUPP_STATUS_DISCONNECTED = 0, - SUPP_STATUS_CONNECTED -}; - -typedef void (*supp_cb_fn)(enum supp_status status, const char * data, - gpointer user_data); - -void supp_set_callback(supp_cb_fn cb, gpointer user_data); -void supp_set_interface(const char * iface); -void supp_set_network_id(const char * network_id); - -void supp_unset_interface(void); -void supp_unset_network_id(void); - -int supp_is_active(void); - -void supp_handle_signal(gchar* old_state, gchar* new_state); -void supp_handle_killed(void); - -#endif diff --git a/wlan.c b/wlan.c deleted file mode 100644 index 659e922..0000000 --- a/wlan.c +++ /dev/null @@ -1,339 +0,0 @@ -/** - @file wlan.c - - Copyright (C) 2004 Nokia Corporation. All rights reserved. - - Copyright (C) 2009 Javier S. Pedro - - @author Janne Ylalehto - @author Johan Hedberg - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include - -#include -#include - -#include -#include -#include - -#include "common.h" -#include "dbus.h" -#include "dbus-helper.h" -#include "wlan.h" -#include "log.h" - -/* -- SCANNING -- */ - -static wlan_found_ap found_ap_cb = NULL; - -int wlan_scan(const char * ssid, wlan_found_ap new_found_ap_cb) -{ - DBusMessage *msg, *reply; - DBusError error; - - DLOG_DEBUG("%s: %s (active)", __func__, ssid); - - dbus_error_init(&error); - - found_ap_cb = new_found_ap_cb; - - msg = new_dbus_method_call( - WLANCOND_SERVICE, - WLANCOND_REQ_PATH, - WLANCOND_REQ_INTERFACE, - WLANCOND_SCAN_REQ); - - gint32 power_level = WLANCOND_TX_POWER100; - guint32 flags = 0; - - append_dbus_args( - msg, - DBUS_TYPE_INT32, &power_level, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &ssid, strlen(ssid) + 1, - DBUS_TYPE_UINT32, &flags, - - DBUS_TYPE_INVALID); - - reply = dbus_connection_send_with_reply_and_block(get_dbus_connection(), - msg, -1, &error); - - dbus_message_unref(msg); - - if (reply) { - DLOG_DEBUG("Scan reply OK"); - dbus_message_unref(reply); - - return 0; - } else if (dbus_error_is_set(&error)) { - DLOG_INFO("Scan pending call result:%s", error.name); - dbus_error_free(&error); - found_ap_cb = NULL; - return -1; - } else { - DLOG_WARN("Scan without reply"); - found_ap_cb = NULL; - return -1; - } -} - -gboolean wlan_is_scanning() -{ - return found_ap_cb ? TRUE : FALSE; -} - -void wlan_notify_ap(const char *ssid, const char *bssid, - int rssi, unsigned int channel, unsigned int cap_bits) -{ - if (found_ap_cb) - found_ap_cb(SEARCH_CONTINUE, ssid, bssid, rssi / 2 - 110); -} - -void wlan_notify_end_of_search() -{ - wlan_found_ap prev_found_ap_cb = found_ap_cb; - found_ap_cb = NULL; - - // A new search may be started right after calling this callback - - if (prev_found_ap_cb) - prev_found_ap_cb(SEARCH_FINISHED, NULL, NULL, 0); -} - -/* - CONNECTING - */ - -static wlan_connected connected_cb; - -static void connect_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("Connect reply callback"); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - - DLOG_DEBUG("Connect pending call result:%s", error.name); - - connected_cb(-1, error.name); - dbus_error_free(&error); - } else if (reply) { - connected_cb(0, NULL); - } - - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -void wlan_connect(const char * ssid, wlan_connected _connected_cb) -{ - DBusMessage *msg; - DBusPendingCall *pending; - - DLOG_DEBUG("%s: %s", __func__, ssid); - - connected_cb = _connected_cb; - - msg = new_dbus_method_call( - WLANCOND_SERVICE, - WLANCOND_REQ_PATH, - WLANCOND_REQ_INTERFACE, - WLANCOND_SETTINGS_AND_CONNECT_REQ); - - guint32 dummy = 0; - guint32 *dummyP = &dummy; - - gint32 power_level, mode, encryption, default_key; - guint32 adhoc_channel, flags; - - power_level = WLANCOND_TX_POWER100; - mode = WLANCOND_INFRA; - encryption = 0; - default_key = 0; - adhoc_channel = 0; - flags = WLANCOND_USE_SUPPLICANT; - - append_dbus_args( - msg, - DBUS_TYPE_INT32, &power_level, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &ssid, strlen(ssid), - DBUS_TYPE_INT32, &mode, - DBUS_TYPE_INT32, &encryption, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &dummyP, 0, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &dummyP, 0, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &dummyP, 0, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &dummyP, 0, - DBUS_TYPE_INT32, &default_key, - DBUS_TYPE_UINT32, &adhoc_channel, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_INVALID); - - if (!dbus_connection_send_with_reply(get_dbus_connection(), - msg, &pending, -1)) - die("Out of memory"); - - if (!dbus_pending_call_set_notify(pending, connect_reply_cb, NULL, NULL)) - die("Out of memory"); - - dbus_message_unref(msg); -} - -static void disconnect_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("Disconnect reply callback"); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - - DLOG_DEBUG("Disconnect pending call result:%s", error.name); - - dbus_error_free(&error); - } - - // No need to notify, wpa_supplicant will signal that for us - - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -void wlan_disconnect() -{ - DBusMessage *msg; - DBusPendingCall *pending; - - DLOG_DEBUG("%s", __func__); - - msg = new_dbus_method_call( - WLANCOND_SERVICE, - WLANCOND_REQ_PATH, - WLANCOND_REQ_INTERFACE, - WLANCOND_DISCONNECT_REQ); - - if (!dbus_connection_send_with_reply(get_dbus_connection(), - msg, &pending, -1)) - die("Out of memory"); - - if (!dbus_pending_call_set_notify(pending, disconnect_reply_cb, NULL, NULL)) - die("Out of memory"); - - dbus_message_unref(msg); -} - -/* -- STATUS -- */ - -static wlan_status_reply status_cb; - -static void status_reply_cb(DBusPendingCall *pending, void *user_data) -{ - DBusMessage *reply; - DBusError error; - - DLOG_DEBUG("%s", __func__); - - dbus_error_init(&error); - - reply = dbus_pending_call_steal_reply(pending); - - if (dbus_set_error_from_message(&error, reply)) { - - DLOG_DEBUG("%s error: %s", __func__, error.name); - goto dbus_error; - } else if (reply) { - char *essid, *bssid, *ifname; - int essid_len, bssid_len; - unsigned long sens, channel, capability, security; - - if (!dbus_message_get_args( - reply, &error, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &essid, &essid_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &bssid, &bssid_len, - DBUS_TYPE_UINT32, &sens, - DBUS_TYPE_UINT32, &channel, - DBUS_TYPE_UINT32, &capability, - DBUS_TYPE_UINT32, &security, - DBUS_TYPE_STRING, &ifname, - DBUS_TYPE_INVALID)) - { - DLOG_DEBUG("%s parse reply error: %s", __func__, - error.name); - goto dbus_error; - } - - status_cb(0, essid, essid_len, bssid, bssid_len, - sens, channel, capability, security, - ifname); - } - - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); - - return; -dbus_error: - status_cb(-1, NULL, 0, NULL, 0, - 0, 0, 0, 0, - error.name); - dbus_error_free(&error); - - if (reply) - dbus_message_unref(reply); - dbus_pending_call_unref(pending); -} - -void wlan_get_status(wlan_status_reply reply_cb) -{ - DBusMessage *msg; - DBusPendingCall *pending; - - DLOG_DEBUG("%s", __func__); - - status_cb = reply_cb; - - msg = new_dbus_method_call( - WLANCOND_SERVICE, - WLANCOND_REQ_PATH, - WLANCOND_REQ_INTERFACE, - WLANCOND_STATUS_REQ); - - if (!dbus_connection_send_with_reply(get_dbus_connection(), - msg, &pending, -1)) - die("Out of memory"); - - if (!dbus_pending_call_set_notify(pending, status_reply_cb, NULL, NULL)) - die("Out of memory"); - - dbus_message_unref(msg); -} - diff --git a/wlan.h b/wlan.h deleted file mode 100644 index b3a29f3..0000000 --- a/wlan.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - @file wlan.h - - Copyright (C) 2009 Javier S. Pedro - - @author Javier S. Pedro - - This file is part of libicd-network-wpa. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef _WLAN_H_ -#define _WLAN_H_ - -typedef void (*wlan_found_ap)(int status, - const char * ssid, const char * ap, int dB); -int wlan_scan(const char * ssid, wlan_found_ap found_ap_cb); - -gboolean wlan_is_scanning(); -void wlan_notify_ap(const char *ssid, const char *bssid, - int rssi, unsigned int channel, unsigned int cap_bits); -void wlan_notify_end_of_search(); - - -typedef void (*wlan_connected)(int status, const char *error); -void wlan_connect(const char *ssid, wlan_connected connected_cb); - -void wlan_disconnect(); - -typedef void (*wlan_status_reply)(int status, - const char * essid, int essid_len, - const char * bssid, int bssid_len, - int qual, int channel, unsigned long security, unsigned long capability, - const char * data); -void wlan_get_status(wlan_status_reply reply_cb); - - -#endif -- 1.7.9.5