2014-05-11 19:39:22 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2014-08-09 06:53:13 +02:00
|
|
|
#include <stdio.h>
|
2014-05-11 19:39:22 +02:00
|
|
|
#include <stdlib.h>
|
2014-08-09 06:53:13 +02:00
|
|
|
#include <getopt.h>
|
2014-05-11 19:39:22 +02:00
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
#include "linux/nl80211.h"
|
|
|
|
|
2014-06-21 20:51:26 +02:00
|
|
|
#include "src/netdev.h"
|
2014-07-29 21:25:01 +02:00
|
|
|
#include "src/wiphy.h"
|
2014-05-21 06:44:13 +02:00
|
|
|
#include "src/kdbus.h"
|
2014-10-07 04:50:27 +02:00
|
|
|
#include "src/dbus.h"
|
2015-03-02 15:19:08 +01:00
|
|
|
#include "src/agent.h"
|
2015-06-22 22:08:12 +02:00
|
|
|
#include "src/network.h"
|
2015-09-29 02:51:40 +02:00
|
|
|
#include "src/eapol.h"
|
|
|
|
#include "src/scan.h"
|
|
|
|
#include "src/wsc.h"
|
2015-03-02 15:19:08 +01:00
|
|
|
|
|
|
|
static struct l_timeout *timeout = NULL;
|
|
|
|
|
|
|
|
static void main_loop_quit(struct l_timeout *timeout, void *user_data)
|
|
|
|
{
|
|
|
|
l_main_quit();
|
|
|
|
}
|
2014-05-21 06:44:13 +02:00
|
|
|
|
2014-05-11 19:39:22 +02:00
|
|
|
static void signal_handler(struct l_signal *signal, uint32_t signo,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
switch (signo) {
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
l_info("Terminate");
|
2015-03-02 15:19:08 +01:00
|
|
|
|
|
|
|
agent_exit();
|
|
|
|
|
|
|
|
timeout = l_timeout_create(1, main_loop_quit, NULL, NULL);
|
2014-05-11 19:39:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-09 06:53:13 +02:00
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
printf("iwd - Wireless daemon\n"
|
|
|
|
"Usage:\n");
|
|
|
|
printf("\tiwd [options]\n");
|
|
|
|
printf("Options:\n"
|
2014-11-08 04:43:18 +01:00
|
|
|
"\t-B, --dbus-debug Enable DBus debugging\n"
|
2014-08-09 19:59:48 +02:00
|
|
|
"\t-K, --kdbus Setup Kernel D-Bus\n"
|
2014-08-09 06:53:13 +02:00
|
|
|
"\t-h, --help Show help options\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct option main_options[] = {
|
2014-11-08 04:43:18 +01:00
|
|
|
{ "kdbus", no_argument, NULL, 'K' },
|
|
|
|
{ "dbus-debug", no_argument, NULL, 'B' },
|
|
|
|
{ "version", no_argument, NULL, 'v' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2014-08-09 06:53:13 +02:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
static void do_debug(const char *str, void *user_data)
|
|
|
|
{
|
|
|
|
const char *prefix = user_data;
|
|
|
|
|
|
|
|
l_info("%s%s", prefix, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nl80211_appeared(void *user_data)
|
|
|
|
{
|
|
|
|
struct l_genl_family *nl80211 = user_data;
|
|
|
|
|
|
|
|
l_debug("Found nl80211 interface");
|
|
|
|
|
|
|
|
if (!wiphy_init(nl80211))
|
|
|
|
l_error("Unable to init wiphy functionality");
|
|
|
|
|
|
|
|
if (!scan_init(nl80211))
|
|
|
|
l_error("Unable to init scan functionality");
|
|
|
|
|
|
|
|
if (!wsc_init(nl80211))
|
|
|
|
l_error("Unable to init WSC functionality");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nl80211_vanished(void *user_data)
|
|
|
|
{
|
|
|
|
l_debug("Lost nl80211 interface");
|
|
|
|
|
|
|
|
wsc_exit();
|
|
|
|
scan_exit();
|
|
|
|
wiphy_exit();
|
|
|
|
}
|
|
|
|
|
2014-05-11 19:39:22 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2014-08-09 19:59:48 +02:00
|
|
|
bool enable_kdbus = false;
|
2014-11-08 04:43:18 +01:00
|
|
|
bool enable_dbus_debug = false;
|
2014-05-11 19:39:22 +02:00
|
|
|
struct l_signal *signal;
|
|
|
|
sigset_t mask;
|
2014-05-21 06:44:13 +02:00
|
|
|
int exit_status;
|
2015-09-29 02:51:40 +02:00
|
|
|
struct l_genl *genl;
|
|
|
|
struct l_genl_family *nl80211;
|
2014-05-11 19:39:22 +02:00
|
|
|
|
2014-08-09 06:53:13 +02:00
|
|
|
for (;;) {
|
|
|
|
int opt;
|
|
|
|
|
2015-04-17 17:17:49 +02:00
|
|
|
opt = getopt_long(argc, argv, "KBvh", main_options, NULL);
|
2014-08-09 06:53:13 +02:00
|
|
|
if (opt < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (opt) {
|
2014-08-09 19:59:48 +02:00
|
|
|
case 'K':
|
|
|
|
enable_kdbus = true;
|
|
|
|
break;
|
2014-11-08 04:43:18 +01:00
|
|
|
case 'B':
|
|
|
|
enable_dbus_debug = true;
|
|
|
|
break;
|
2014-08-09 06:53:13 +02:00
|
|
|
case 'v':
|
|
|
|
printf("%s\n", VERSION);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
default:
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc - optind > 0) {
|
|
|
|
fprintf(stderr, "Invalid command line parameters\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-05-11 19:39:22 +02:00
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGINT);
|
|
|
|
sigaddset(&mask, SIGTERM);
|
|
|
|
|
|
|
|
signal = l_signal_create(&mask, signal_handler, NULL, NULL);
|
|
|
|
|
|
|
|
l_log_set_stderr();
|
2014-05-21 06:44:13 +02:00
|
|
|
l_debug_enable("*");
|
2014-05-11 19:39:22 +02:00
|
|
|
|
|
|
|
l_info("Wireless daemon version %s", VERSION);
|
|
|
|
|
2014-08-09 19:59:48 +02:00
|
|
|
if (enable_kdbus) {
|
|
|
|
char *bus_name;
|
|
|
|
bool result;
|
2014-05-21 06:44:13 +02:00
|
|
|
|
2014-08-09 19:59:48 +02:00
|
|
|
if (!kdbus_create_bus()) {
|
|
|
|
exit_status = EXIT_FAILURE;
|
|
|
|
goto done;
|
|
|
|
}
|
2014-05-21 06:44:13 +02:00
|
|
|
|
2014-08-09 19:59:48 +02:00
|
|
|
bus_name = kdbus_lookup_bus();
|
|
|
|
if (!bus_name) {
|
|
|
|
exit_status = EXIT_FAILURE;
|
2015-09-29 02:51:40 +02:00
|
|
|
goto fail_dbus;
|
2014-08-09 19:59:48 +02:00
|
|
|
}
|
2014-05-11 19:39:22 +02:00
|
|
|
|
2014-08-09 19:59:48 +02:00
|
|
|
l_debug("Bus location: %s", bus_name);
|
|
|
|
|
|
|
|
result = kdbus_open_bus(bus_name, "net.connman.iwd", "iwd");
|
|
|
|
|
|
|
|
l_free(bus_name);
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
exit_status = EXIT_FAILURE;
|
2015-09-29 02:51:40 +02:00
|
|
|
goto fail_dbus;
|
2014-08-09 19:59:48 +02:00
|
|
|
}
|
2014-05-21 08:07:49 +02:00
|
|
|
}
|
|
|
|
|
2014-11-08 04:43:18 +01:00
|
|
|
if (!dbus_init(enable_dbus_debug)) {
|
2014-10-07 04:50:27 +02:00
|
|
|
exit_status = EXIT_FAILURE;
|
2015-09-29 02:51:40 +02:00
|
|
|
goto fail_dbus;
|
2014-10-07 04:50:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
genl = l_genl_new_default();
|
|
|
|
if (!genl) {
|
|
|
|
l_error("Failed to open generic netlink socket");
|
|
|
|
exit_status = EXIT_FAILURE;
|
|
|
|
goto fail_genl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getenv("IWD_GENL_DEBUG"))
|
|
|
|
l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
|
|
|
|
|
2015-10-02 19:58:38 +02:00
|
|
|
if (!netdev_init()) {
|
|
|
|
exit_status = EXIT_FAILURE;
|
|
|
|
goto fail_netdev;
|
|
|
|
}
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
l_debug("Opening nl80211 interface");
|
|
|
|
|
|
|
|
nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
|
|
|
|
if (!nl80211) {
|
|
|
|
l_error("Failed to open nl80211 interface");
|
2014-06-21 13:41:40 +02:00
|
|
|
exit_status = EXIT_FAILURE;
|
2015-09-29 02:51:40 +02:00
|
|
|
goto fail_nl80211;
|
2014-06-21 13:41:40 +02:00
|
|
|
}
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
l_genl_family_set_watches(nl80211, nl80211_appeared, nl80211_vanished,
|
|
|
|
nl80211, NULL);
|
|
|
|
|
|
|
|
eapol_init();
|
2015-06-22 22:08:12 +02:00
|
|
|
network_init();
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
exit_status = EXIT_SUCCESS;
|
2014-05-11 19:39:22 +02:00
|
|
|
l_main_run();
|
|
|
|
|
2015-06-22 22:08:12 +02:00
|
|
|
network_exit();
|
2015-09-29 02:51:40 +02:00
|
|
|
eapol_exit();
|
|
|
|
|
|
|
|
l_genl_family_unref(nl80211);
|
|
|
|
|
|
|
|
fail_nl80211:
|
2015-10-02 19:58:38 +02:00
|
|
|
netdev_exit();
|
|
|
|
|
|
|
|
fail_netdev:
|
2015-09-29 02:51:40 +02:00
|
|
|
l_genl_unref(genl);
|
|
|
|
|
|
|
|
fail_genl:
|
|
|
|
dbus_exit();
|
2014-05-21 06:44:13 +02:00
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
fail_dbus:
|
2014-08-09 19:59:48 +02:00
|
|
|
if (enable_kdbus)
|
|
|
|
kdbus_destroy_bus();
|
2014-05-21 06:44:13 +02:00
|
|
|
|
|
|
|
done:
|
2014-05-11 19:39:22 +02:00
|
|
|
l_signal_remove(signal);
|
2015-03-02 15:19:08 +01:00
|
|
|
l_timeout_remove(timeout);
|
2014-05-11 19:39:22 +02:00
|
|
|
|
2014-05-21 06:44:13 +02:00
|
|
|
return exit_status;
|
2014-05-11 19:39:22 +02:00
|
|
|
}
|