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>
|
|
|
|
|
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"
|
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");
|
|
|
|
l_main_quit();
|
|
|
|
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-08-09 07:19:47 +02:00
|
|
|
"\t-S, --ssid <ssid> SSID of network\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-08-09 07:19:47 +02:00
|
|
|
{ "ssid", required_argument, NULL, 'S' },
|
2014-08-09 19:59:48 +02:00
|
|
|
{ "kdbus", no_argument, NULL, 'K' },
|
2014-08-09 06:53:13 +02:00
|
|
|
{ "version", no_argument, NULL, 'v' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
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-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;
|
2014-05-11 19:39:22 +02:00
|
|
|
|
2014-08-09 06:53:13 +02:00
|
|
|
for (;;) {
|
|
|
|
int opt;
|
|
|
|
|
2014-08-09 07:19:47 +02:00
|
|
|
opt = getopt_long(argc, argv, "S:vh", main_options, NULL);
|
2014-08-09 06:53:13 +02:00
|
|
|
if (opt < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (opt) {
|
2014-08-09 07:19:47 +02:00
|
|
|
case 'S':
|
|
|
|
wiphy_set_ssid(optarg);
|
|
|
|
break;
|
2014-08-09 19:59:48 +02:00
|
|
|
case 'K':
|
|
|
|
enable_kdbus = 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;
|
|
|
|
goto destroy;
|
|
|
|
}
|
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;
|
|
|
|
goto destroy;
|
|
|
|
}
|
2014-05-21 08:07:49 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 04:50:27 +02:00
|
|
|
if (!dbus_init()) {
|
|
|
|
exit_status = EXIT_FAILURE;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2014-06-21 13:41:40 +02:00
|
|
|
if (!netdev_init()) {
|
|
|
|
exit_status = EXIT_FAILURE;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
if (!wiphy_init()) {
|
|
|
|
netdev_exit();
|
|
|
|
exit_status = EXIT_FAILURE;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2014-05-11 19:39:22 +02:00
|
|
|
l_main_run();
|
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
wiphy_exit();
|
2014-06-21 13:41:40 +02:00
|
|
|
netdev_exit();
|
2014-10-07 04:50:27 +02:00
|
|
|
dbus_exit();
|
2014-06-21 13:41:40 +02:00
|
|
|
|
2014-05-21 06:44:13 +02:00
|
|
|
exit_status = EXIT_SUCCESS;
|
|
|
|
|
2014-05-21 08:07:49 +02:00
|
|
|
destroy:
|
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);
|
|
|
|
|
2014-05-21 06:44:13 +02:00
|
|
|
return exit_status;
|
2014-05-11 19:39:22 +02:00
|
|
|
}
|