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 interface_added(struct supplicant_interface *interface)
42 const char *ifname = supplicant_interface_get_ifname(interface);
44 DBG("ifname %s", ifname);
47 static void interface_removed(struct supplicant_interface *interface)
49 const char *ifname = supplicant_interface_get_ifname(interface);
51 DBG("ifname %s", ifname);
54 static void network_added(struct supplicant_network *network)
56 const char *name = supplicant_network_get_name(network);
60 DBG("%s", supplicant_network_get_identifier(network));
63 static void network_removed(struct supplicant_network *network)
65 const char *name = supplicant_network_get_name(network);
70 static const struct supplicant_callbacks callbacks = {
71 .interface_added = interface_added,
72 .interface_removed = interface_removed,
73 .network_added = network_added,
74 .network_removed = network_removed,
77 static GMainLoop *main_loop = NULL;
79 static void sig_term(int sig)
81 syslog(LOG_INFO, "Terminating");
83 g_main_loop_quit(main_loop);
86 static void disconnect_callback(DBusConnection *conn, void *user_data)
88 syslog(LOG_ERR, "D-Bus disconnect");
90 g_main_loop_quit(main_loop);
93 int main(int argc, char *argv[])
99 main_loop = g_main_loop_new(NULL, FALSE);
101 dbus_error_init(&err);
103 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
105 if (dbus_error_is_set(&err) == TRUE) {
106 fprintf(stderr, "%s\n", err.message);
107 dbus_error_free(&err);
109 fprintf(stderr, "Can't register with system bus\n");
113 openlog("supplicant", LOG_NDELAY | LOG_PERROR, LOG_USER);
115 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
117 memset(&sa, 0, sizeof(sa));
118 sa.sa_handler = sig_term;
119 sigaction(SIGINT, &sa, NULL);
120 sigaction(SIGTERM, &sa, NULL);
122 syslog(LOG_INFO, "Startup");
124 if (supplicant_register(&callbacks) < 0) {
125 syslog(LOG_ERR, "Failed to init supplicant");
129 g_main_loop_run(main_loop);
131 supplicant_unregister(&callbacks);
134 syslog(LOG_INFO, "Exit");
136 dbus_connection_unref(conn);
138 g_main_loop_unref(main_loop);