5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "supplicant.h"
36 #define DBG(fmt, arg...) do { \
37 syslog(LOG_DEBUG, "%s() " fmt, __FUNCTION__ , ## arg); \
40 static void create_callback(int result, struct supplicant_interface *interface,
43 DBG("* result %d ifname %s", result,
44 supplicant_interface_get_ifname(interface));
50 static void system_ready(void)
54 supplicant_interface_create("wlan0", "nl80211,wext",
55 create_callback, NULL);
58 static void system_killed(void)
63 static void interface_added(struct supplicant_interface *interface)
65 const char *ifname = supplicant_interface_get_ifname(interface);
66 const char *driver = supplicant_interface_get_driver(interface);
68 DBG("* ifname %s driver %s", ifname, driver);
70 if (supplicant_interface_scan(interface) < 0)
74 static void interface_removed(struct supplicant_interface *interface)
76 const char *ifname = supplicant_interface_get_ifname(interface);
78 DBG("* ifname %s", ifname);
81 static void scan_started(struct supplicant_interface *interface)
83 const char *ifname = supplicant_interface_get_ifname(interface);
85 DBG("* ifname %s", ifname);
88 static void scan_finished(struct supplicant_interface *interface)
90 const char *ifname = supplicant_interface_get_ifname(interface);
92 DBG("* ifname %s", ifname);
95 static void network_added(struct supplicant_network *network)
97 const char *name = supplicant_network_get_name(network);
99 DBG("* name %s", name);
101 DBG("* %s", supplicant_network_get_identifier(network));
104 static void network_removed(struct supplicant_network *network)
106 const char *name = supplicant_network_get_name(network);
108 DBG("* name %s", name);
111 static const struct supplicant_callbacks callbacks = {
112 .system_ready = system_ready,
113 .system_killed = system_killed,
114 .interface_added = interface_added,
115 .interface_removed = interface_removed,
116 .scan_started = scan_started,
117 .scan_finished = scan_finished,
118 .network_added = network_added,
119 .network_removed = network_removed,
122 static GMainLoop *main_loop = NULL;
124 static void sig_term(int sig)
126 syslog(LOG_INFO, "Terminating");
128 g_main_loop_quit(main_loop);
131 static void disconnect_callback(DBusConnection *conn, void *user_data)
133 syslog(LOG_ERR, "D-Bus disconnect");
135 g_main_loop_quit(main_loop);
138 int main(int argc, char *argv[])
140 DBusConnection *conn;
144 main_loop = g_main_loop_new(NULL, FALSE);
146 dbus_error_init(&err);
148 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
150 if (dbus_error_is_set(&err) == TRUE) {
151 fprintf(stderr, "%s\n", err.message);
152 dbus_error_free(&err);
154 fprintf(stderr, "Can't register with system bus\n");
158 openlog("supplicant", LOG_NDELAY | LOG_PERROR, LOG_USER);
160 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
162 memset(&sa, 0, sizeof(sa));
163 sa.sa_handler = sig_term;
164 sigaction(SIGINT, &sa, NULL);
165 sigaction(SIGTERM, &sa, NULL);
167 syslog(LOG_INFO, "Startup");
169 if (supplicant_register(&callbacks) < 0) {
170 syslog(LOG_ERR, "Failed to init supplicant");
174 g_main_loop_run(main_loop);
176 supplicant_unregister(&callbacks);
179 syslog(LOG_INFO, "Exit");
181 dbus_connection_unref(conn);
183 g_main_loop_unref(main_loop);