eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

daemon.c (3426B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2021  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <errno.h>
     28 #include <ell/ell.h>
     29 #include <unistd.h>
     30 
     31 #include "client/dbus-proxy.h"
     32 #include "client/display.h"
     33 #include "client/command.h"
     34 #include "client/daemon.h"
     35 
     36 static bool netconfig_enabled;
     37 
     38 #define IWD_DAEMON_PATH "/net/connman/iwd"
     39 
     40 int daemon_netconfig_enabled()
     41 {
     42 	const struct proxy_interface *proxy =
     43 		proxy_interface_find(IWD_DAEMON_INTERFACE, IWD_DAEMON_PATH);
     44 
     45 	if (!proxy)
     46 		return -ENOENT;
     47 
     48 	return netconfig_enabled;
     49 }
     50 
     51 static void get_info_callback(struct l_dbus_message *message, void *user_data)
     52 {
     53 	struct l_dbus_message_iter iter;
     54 	struct l_dbus_message_iter variant;
     55 	const char *key;
     56 
     57 	if (dbus_message_has_error(message))
     58 		return;
     59 
     60 	if (!l_dbus_message_get_arguments(message, "a{sv}", &iter))
     61 		goto parse_failed;
     62 
     63 	while (l_dbus_message_iter_next_entry(&iter, &key, &variant)) {
     64 		if (strcmp(key, "NetworkConfigurationEnabled"))
     65 			continue;
     66 
     67 		if (!l_dbus_message_iter_get_variant(&variant, "b",
     68 							&netconfig_enabled))
     69 			goto parse_failed;
     70 
     71 		break;
     72 	}
     73 
     74 	if (!command_is_interactive_mode())
     75 		return;
     76 
     77 	if (!l_dbus_message_get_arguments(message, "a{sv}", &iter))
     78 		goto parse_failed;
     79 
     80 	display("NetworkConfigurationEnabled: %s\n",
     81 				netconfig_enabled ? "enabled" : "disabled");
     82 
     83 	while (l_dbus_message_iter_next_entry(&iter, &key, &variant)) {
     84 		if (!strcmp(key, "Version") ||
     85 					!strcmp(key, "StateDirectory")) {
     86 			const char *sval;
     87 
     88 			if (!l_dbus_message_iter_get_variant(&variant, "s",
     89 								&sval))
     90 				continue;
     91 
     92 			display("%s: %s\n", key, sval);
     93 		}
     94 	}
     95 
     96 	return;
     97 
     98 parse_failed:
     99 	l_error("Failed to parse GetInfo message");
    100 	return;
    101 }
    102 
    103 static bool daemon_get_info(void)
    104 {
    105 	const struct proxy_interface *proxy =
    106 		proxy_interface_find(IWD_DAEMON_INTERFACE, IWD_DAEMON_PATH);
    107 
    108 	if (!proxy)
    109 		return false;
    110 
    111 	proxy_interface_method_call(proxy, "GetInfo", "", get_info_callback);
    112 
    113 	return true;
    114 }
    115 
    116 static void *daemon_create(void)
    117 {
    118 	daemon_get_info();
    119 	return NULL;
    120 }
    121 
    122 static void daemon_destroy(void *data)
    123 {
    124 }
    125 
    126 static const struct proxy_interface_type_ops daemon_ops = {
    127 	.create = daemon_create,
    128 	.destroy = daemon_destroy,
    129 };
    130 
    131 static struct proxy_interface_type daemon_interface_type = {
    132 	.interface = IWD_DAEMON_INTERFACE,
    133 	.ops = &daemon_ops,
    134 };
    135 
    136 static int daemon_interface_init(void)
    137 {
    138 	proxy_interface_type_register(&daemon_interface_type);
    139 
    140 	return 0;
    141 }
    142 
    143 static void daemon_interface_exit(void)
    144 {
    145 	proxy_interface_type_unregister(&daemon_interface_type);
    146 }
    147 
    148 INTERFACE_TYPE(daemon_interface_type, daemon_interface_init,
    149 						daemon_interface_exit)