eiwd

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

agent-manager.c (3035B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2017-2020  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 <ell/ell.h>
     28 #include <unistd.h>
     29 
     30 #include "client/agent.h"
     31 #include "client/dbus-proxy.h"
     32 #include "client/agent-manager.h"
     33 #include "client/command.h"
     34 
     35 #define IWD_AGENT_MANAGER_PATH		"/net/connman/iwd"
     36 
     37 static void check_errors_method_callback(struct l_dbus_message *message,
     38 								void *user_data)
     39 {
     40 	dbus_message_has_error(message);
     41 }
     42 
     43 static bool agent_manager_register_agent(const char *path)
     44 {
     45 	const struct proxy_interface *proxy;
     46 
     47 	if (!path)
     48 		return false;
     49 
     50 	proxy = proxy_interface_find(IWD_AGENT_MANAGER_INTERFACE,
     51 							IWD_AGENT_MANAGER_PATH);
     52 	if (!proxy)
     53 		return false;
     54 
     55 	proxy_interface_method_call(proxy, "RegisterAgent", "o",
     56 					check_errors_method_callback, path);
     57 
     58 	return true;
     59 }
     60 
     61 bool agent_manager_unregister_agent(void)
     62 {
     63 	const char *path;
     64 	const struct proxy_interface *proxy =
     65 		proxy_interface_find(IWD_AGENT_MANAGER_INTERFACE,
     66 							IWD_AGENT_MANAGER_PATH);
     67 
     68 	if (!proxy)
     69 		return false;
     70 
     71 	path = proxy_interface_get_data(proxy);
     72 	if (!path)
     73 		return false;
     74 
     75 	proxy_interface_method_call(proxy, "UnregisterAgent", "o",
     76 					check_errors_method_callback, path);
     77 
     78 	return true;
     79 }
     80 
     81 static void *agent_manager_create(void)
     82 {
     83 	char *path;
     84 
     85 	if (command_needs_no_agent())
     86 		return NULL;
     87 
     88 	path = l_strdup_printf("/agent/%i", getpid());
     89 
     90 	agent_init(path);
     91 
     92 	agent_manager_register_agent(path);
     93 
     94 	return path;
     95 }
     96 
     97 static void agent_manager_destroy(void *data)
     98 {
     99 	char *path = data;
    100 
    101 	if (!path)
    102 		return;
    103 
    104 	agent_exit(path);
    105 
    106 	l_free(path);
    107 }
    108 
    109 static const struct proxy_interface_type_ops agent_manager_ops = {
    110 	.create = agent_manager_create,
    111 	.destroy = agent_manager_destroy,
    112 };
    113 
    114 static struct proxy_interface_type agent_manager_interface_type = {
    115 	.interface = IWD_AGENT_MANAGER_INTERFACE,
    116 	.ops = &agent_manager_ops,
    117 };
    118 
    119 static int agent_manager_interface_init(void)
    120 {
    121 	proxy_interface_type_register(&agent_manager_interface_type);
    122 
    123 	return 0;
    124 }
    125 
    126 static void agent_manager_interface_exit(void)
    127 {
    128 	proxy_interface_type_unregister(&agent_manager_interface_type);
    129 }
    130 
    131 INTERFACE_TYPE(agent_manager_interface_type, agent_manager_interface_init,
    132 						agent_manager_interface_exit)