From 4ebdf4e2ca700149a15029164b5c8d0936ac0ddd Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Tue, 12 Jul 2016 04:13:54 +0200 Subject: [PATCH] wiphy: Add Adapter objects above Device Change the path for net.connman.iwd.Device objects to /phyX/Y and register net.connman.iwd.Adapter at /phyX grouping devices of the same wiphy. Turns out no changes to the test/* scripts are needed. --- src/dbus.h | 1 + src/device.c | 5 +++-- src/wiphy.c | 38 ++++++++++++++++++++++++++++++++++++++ src/wiphy.h | 2 ++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/dbus.h b/src/dbus.h index 4297ecf3..77a9f91f 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -25,6 +25,7 @@ #define IWD_SERVICE "net.connman.iwd" #define IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager" +#define IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter" #define IWD_DEVICE_INTERFACE "net.connman.iwd.Device" #define IWD_NETWORK_INTERFACE "net.connman.iwd.Network" #define IWD_AGENT_INTERFACE "net.connman.iwd.Agent" diff --git a/src/device.c b/src/device.c index 6be06234..cd5e69f7 100644 --- a/src/device.c +++ b/src/device.c @@ -442,9 +442,10 @@ struct network *device_get_connected_network(struct device *device) const char *device_get_path(struct device *device) { - static char path[12]; + static char path[26]; - snprintf(path, sizeof(path), "/%u", device->index); + snprintf(path, sizeof(path), "%s/%u", wiphy_get_path(device->wiphy), + device->index); return path; } diff --git a/src/wiphy.c b/src/wiphy.c index 24a2a04c..721e855e 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -38,6 +38,7 @@ #include "src/crypto.h" #include "src/scan.h" #include "src/netdev.h" +#include "src/dbus.h" #include "src/wiphy.h" static struct l_genl_family *nl80211 = NULL; @@ -90,6 +91,14 @@ struct wiphy *wiphy_find(int wiphy_id) return l_queue_find(wiphy_list, wiphy_match, L_UINT_TO_PTR(wiphy_id)); } +const char *wiphy_get_path(struct wiphy *wiphy) +{ + static char path[15]; + + snprintf(path, sizeof(path), "/phy%u", wiphy->id); + return path; +} + static void wiphy_print_basic_info(struct wiphy *wiphy) { uint32_t bands; @@ -324,6 +333,16 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data) wiphy_parse_attributes(wiphy, &attr); } +static void wiphy_register(struct wiphy *wiphy) +{ + struct l_dbus *dbus = dbus_get_bus(); + + if (!l_dbus_object_add_interface(dbus, wiphy_get_path(wiphy), + IWD_WIPHY_INTERFACE, wiphy)) + l_info("Unable to add the %s interface to %s", + IWD_WIPHY_INTERFACE, wiphy_get_path(wiphy)); +} + static void wiphy_dump_done(void *user) { const struct l_queue_entry *wiphy_entry; @@ -332,6 +351,8 @@ static void wiphy_dump_done(void *user) wiphy_entry = wiphy_entry->next) { struct wiphy *wiphy = wiphy_entry->data; + wiphy_register(wiphy); + wiphy_print_basic_info(wiphy); } } @@ -377,6 +398,8 @@ static void wiphy_new_wiphy_event(struct l_genl_msg *msg) wiphy_parse_attributes(wiphy, &attr); wiphy_print_basic_info(wiphy); + wiphy_register(wiphy); + netdev_new_wiphy_hint(wiphy->id); } @@ -408,6 +431,8 @@ static void wiphy_del_wiphy_event(struct l_genl_msg *msg) if (!wiphy) return; + l_dbus_unregister_object(dbus_get_bus(), wiphy_get_path(wiphy)); + wiphy_free(wiphy); } @@ -497,6 +522,10 @@ static void protocol_features_callback(struct l_genl_msg *msg, void *user_data) l_debug("Found split wiphy dump support"); } +static void setup_wiphy_interface(struct l_dbus_interface *interface) +{ +} + bool wiphy_init(struct l_genl_family *in) { struct l_genl_msg *msg; @@ -537,6 +566,13 @@ bool wiphy_init(struct l_genl_family *in) NULL, wiphy_dump_done)) l_error("Getting all wiphy devices failed"); + if (!l_dbus_register_interface(dbus_get_bus(), + IWD_WIPHY_INTERFACE, + setup_wiphy_interface, + NULL, true)) + l_error("Unable to register the %s interface", + IWD_WIPHY_INTERFACE); + return true; } @@ -547,5 +583,7 @@ bool wiphy_exit(void) nl80211 = NULL; + l_dbus_unregister_interface(dbus_get_bus(), IWD_WIPHY_INTERFACE); + return true; } diff --git a/src/wiphy.h b/src/wiphy.h index aeefb334..f7cbc0ac 100644 --- a/src/wiphy.h +++ b/src/wiphy.h @@ -30,5 +30,7 @@ enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, struct wiphy *wiphy_find(int wiphy_id); +const char *wiphy_get_path(struct wiphy *wiphy); + bool wiphy_init(struct l_genl_family *in); bool wiphy_exit(void);