From fc24ffcdb823c47b240385bed0ec0c96e3f1f177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Thu, 6 Jul 2023 16:25:41 +0200 Subject: [PATCH] wifi: use mac address reporter Remove the handcrafted MAC address reporter in favour the Genode C API utility (cf. #4918). Issue #4927 Issue #4918 --- repos/dde_linux/lib/mk/wifi.inc | 4 +- repos/dde_linux/src/lib/wifi/wlan.cc | 72 +++++---------------- repos/pc/recipes/src/pc_wifi_drv/content.mk | 3 +- 3 files changed, 22 insertions(+), 57 deletions(-) diff --git a/repos/dde_linux/lib/mk/wifi.inc b/repos/dde_linux/lib/mk/wifi.inc index 91e2aeb5a9..f7e99badae 100644 --- a/repos/dde_linux/lib/mk/wifi.inc +++ b/repos/dde_linux/lib/mk/wifi.inc @@ -51,5 +51,7 @@ CC_C_OPT += -DCONFIG_RFKILL_INPUT # SRC_CC += genode_c_api/uplink.cc - vpath genode_c_api/uplink.cc $(subst /genode_c_api,,$(call select_from_repositories,src/lib/genode_c_api)) + +SRC_CC += genode_c_api/mac_address_reporter.cc +vpath genode_c_api/mac_address_reporter.cc $(dir $(call select_from_repositories,src/lib/genode_c_api)) diff --git a/repos/dde_linux/src/lib/wifi/wlan.cc b/repos/dde_linux/src/lib/wifi/wlan.cc index a74fab8be5..a93c430532 100644 --- a/repos/dde_linux/src/lib/wifi/wlan.cc +++ b/repos/dde_linux/src/lib/wifi/wlan.cc @@ -15,9 +15,10 @@ #include #include #include -#include #include #include +#include + /* DDE Linux includes */ #include @@ -277,60 +278,13 @@ extern "C" char const *wifi_ifname(void) } -struct Mac_address_reporter -{ - bool _enabled = false; - - Net::Mac_address _mac_address { }; - - Constructible _reporter { }; - - Env &_env; - - Signal_context_capability _sigh; - - Mac_address_reporter(Env &env, Signal_context_capability sigh) - : _env(env), _sigh(sigh) - { - Attached_rom_dataspace config { _env, "config" }; - - config.xml().with_optional_sub_node("report", [&] (Xml_node const &xml) { - _enabled = xml.attribute_value("mac_address", false); }); - } - - void mac_address(Net::Mac_address const &mac_address) - { - _mac_address = mac_address; - - Signal_transmitter(_sigh).submit(); - } - - void report() - { - if (!_enabled) - return; - - _reporter.construct(_env, "devices"); - _reporter->enabled(true); - - Reporter::Xml_generator report(*_reporter, [&] () { - report.node("nic", [&] () { - report.attribute("mac_address", String<32>(_mac_address)); - }); - }); - - /* report only once */ - _enabled = false; - } -}; - -Constructible mac_address_reporter; - - /* used from socket_call.cc */ void _wifi_report_mac_address(Net::Mac_address const &mac_address) { - mac_address_reporter->mac_address(mac_address); + struct genode_mac_address address; + + mac_address.copy(&address); + genode_mac_address_register("wlan0", address); } @@ -350,13 +304,21 @@ struct Wlan } genode_uplink_notify_peers(); - - mac_address_reporter->report(); } Wlan(Env &env) : _env { env } { - mac_address_reporter.construct(_env, _signal_handler); + genode_mac_address_reporter_init(env, Lx_kit::env().heap); + + { + /* + * Query the configuration once at start-up to enable + * the reporter. The actual reporting will be done + * once by 'genode_mac_address_register()'. + */ + Attached_rom_dataspace _config_rom { _env, "config" }; + genode_mac_address_reporter_config(_config_rom.xml()); + } genode_uplink_init(genode_env_ptr(_env), genode_allocator_ptr(Lx_kit::env().heap), diff --git a/repos/pc/recipes/src/pc_wifi_drv/content.mk b/repos/pc/recipes/src/pc_wifi_drv/content.mk index b48fc722c5..92c4b6b371 100644 --- a/repos/pc/recipes/src/pc_wifi_drv/content.mk +++ b/repos/pc/recipes/src/pc_wifi_drv/content.mk @@ -14,7 +14,8 @@ MIRROR_FROM_REP_DIR := src/lib/pc/lx_emul \ # Generic driver poritions from dde_linux and os # # -MIRROR_FROM_OS_DIR := src/lib/genode_c_api/uplink.cc +MIRROR_FROM_OS_DIR := src/lib/genode_c_api/uplink.cc \ + src/lib/genode_c_api/mac_address_reporter.cc DDE_LINUX_REP_DIR := $(GENODE_DIR)/repos/dde_linux