commit 4a969294f76e778d95b54d0eef1c30eedab420bf
parent fd0892baf02792ff8bd3fd0a59740b8258e75b04
Author: Andrew Zaborowski <andrew.zaborowski@intel.com>
Date: Thu, 11 Apr 2019 03:10:23 +0200
wiphy: Add wiphy_create/wiphy_destroy API
Add wiphy_create, wiphy_update_from_genl and wiphy_destroy that together
will let a new file command the wiphy creation, updates and deletion
with the same functionality the current config notification handler
implements in wiphy.c.
Diffstat:
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -781,6 +781,53 @@ static void wiphy_new_wiphy_event(struct l_genl_msg *msg)
wiphy_register(wiphy);
}
+struct wiphy *wiphy_create(uint32_t wiphy_id, const char *name)
+{
+ struct wiphy *wiphy;
+
+ if (!wiphy_is_managed(name))
+ return NULL;
+
+ wiphy = wiphy_new(wiphy_id);
+ l_strlcpy(wiphy->name, name, sizeof(wiphy->name));
+ l_queue_push_head(wiphy_list, wiphy);
+
+ wiphy_register(wiphy);
+ return wiphy;
+}
+
+void wiphy_update_from_genl(struct wiphy *wiphy, struct l_genl_msg *msg)
+{
+ struct l_genl_attr attr;
+ const char *name;
+
+ l_debug("");
+
+ if (!l_genl_attr_init(&attr, msg))
+ return;
+
+ if (!wiphy_parse_id_and_name(&attr, NULL, &name))
+ return;
+
+ /*
+ * WIPHY_NAME is a NLA_NUL_STRING, so the kernel
+ * enforces the data to be null terminated.
+ */
+ if (strncmp(wiphy->name, name, sizeof(wiphy->name))) {
+ struct l_dbus *dbus = dbus_get_bus();
+
+ l_strlcpy(wiphy->name, name, sizeof(wiphy->name));
+ l_dbus_property_changed(dbus, wiphy_get_path(wiphy),
+ IWD_WIPHY_INTERFACE, "Name");
+ }
+
+ if (!wiphy->supported_iftypes) {
+ /* Most likely a new wiphy, set all the parameters */
+ wiphy_parse_attributes(wiphy, &attr);
+ wiphy_print_basic_info(wiphy);
+ }
+}
+
static void wiphy_del_wiphy_event(struct l_genl_msg *msg)
{
struct wiphy *wiphy;
@@ -804,6 +851,19 @@ static void wiphy_del_wiphy_event(struct l_genl_msg *msg)
wiphy_free(wiphy);
}
+bool wiphy_destroy(struct wiphy *wiphy)
+{
+ l_debug("");
+
+ if (!l_queue_remove(wiphy_list, wiphy))
+ return false;
+
+ l_dbus_unregister_object(dbus_get_bus(), wiphy_get_path(wiphy));
+
+ wiphy_free(wiphy);
+ return true;
+}
+
static void wiphy_config_notify(struct l_genl_msg *msg, void *user_data)
{
uint8_t cmd;
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -46,6 +46,10 @@ bool wiphy_parse_id_and_name(struct l_genl_attr *attr, uint32_t *out_id,
struct wiphy *wiphy_find(int wiphy_id);
+struct wiphy *wiphy_create(uint32_t wiphy_id, const char *name);
+bool wiphy_destroy(struct wiphy *wiphy);
+void wiphy_update_from_genl(struct wiphy *wiphy, struct l_genl_msg *msg);
+
const char *wiphy_get_path(struct wiphy *wiphy);
uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
const struct scan_freq_set *wiphy_get_supported_freqs(