3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-06 03:59:22 +01:00
iwd/src/main.c

176 lines
3.4 KiB
C
Raw Normal View History

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
#include <stdio.h>
2014-05-11 19:39:22 +02:00
#include <stdlib.h>
#include <getopt.h>
2014-05-11 19:39:22 +02:00
#include <ell/ell.h>
#include "src/netdev.h"
2014-07-29 21:25:01 +02:00
#include "src/wiphy.h"
#include "src/kdbus.h"
2014-10-07 04:50:27 +02:00
#include "src/dbus.h"
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;
}
}
static void usage(void)
{
printf("iwd - Wireless daemon\n"
"Usage:\n");
printf("\tiwd [options]\n");
printf("Options:\n"
"\t-S, --ssid <ssid> SSID of network\n"
2014-08-09 19:59:48 +02:00
"\t-K, --kdbus Setup Kernel D-Bus\n"
"\t-h, --help Show help options\n");
}
static const struct option main_options[] = {
{ "ssid", required_argument, NULL, 'S' },
2014-08-09 19:59:48 +02:00
{ "kdbus", no_argument, NULL, 'K' },
{ "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;
int exit_status;
2014-05-11 19:39:22 +02:00
for (;;) {
int opt;
opt = getopt_long(argc, argv, "S:vh", main_options, NULL);
if (opt < 0)
break;
switch (opt) {
case 'S':
wiphy_set_ssid(optarg);
break;
2014-08-09 19:59:48 +02:00
case 'K':
enable_kdbus = true;
break;
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();
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-08-09 19:59:48 +02:00
if (!kdbus_create_bus()) {
exit_status = EXIT_FAILURE;
goto done;
}
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-10-07 04:50:27 +02:00
if (!dbus_init()) {
exit_status = EXIT_FAILURE;
goto destroy;
}
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();
netdev_exit();
2014-10-07 04:50:27 +02:00
dbus_exit();
exit_status = EXIT_SUCCESS;
destroy:
2014-08-09 19:59:48 +02:00
if (enable_kdbus)
kdbus_destroy_bus();
done:
2014-05-11 19:39:22 +02:00
l_signal_remove(signal);
return exit_status;
2014-05-11 19:39:22 +02:00
}