netdev: parse rates in netdev_get_station
PATCH v4 1/5 netdev: parse rates in netdev_get_station
--- src/netdev.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/netdev.h | 16 ++++++++++ 2 files changed, 104 insertions(+)
v4:
* Added rate types for Legacy, HT, VHT, HE which we need to make any sense of the MCS index.
src/netdev.c +88 -0
@@ -368,11 +368,74 @@ int netdev_set_powered(struct netdev *netdev, bool powered,return 0 ; } +static bool netdev_parse_bitrate (struct l_genl_attr *attr, +enum netdev_rate_type *type_out, +uint32_t *rate_out, +uint8_t *mcs_out) +{ +uint16_t type, len; +const void *data; +uint32_t rate =0 ; +uint8_t mcs =0 ; +enum netdev_rate_type rate_type =NETDEV_RATE_TYPE_LEGACY ; + +while (l_genl_attr_next (attr, &type, &len, &data)) { +switch (type) { +case NL80211_RATE_INFO_BITRATE32 : +if (len !=4 ) +return false; + + rate = *(const uint32_t *) data; + +break ; + +case NL80211_RATE_INFO_MCS : +if (len !=1 ) +return false; + + mcs = *(const uint8_t *) data; + rate_type =NETDEV_RATE_TYPE_HT ; + +break ; + +case NL80211_RATE_INFO_VHT_MCS : +if (len !=1 ) +return false; + + mcs = *(const uint8_t *) data; + rate_type =NETDEV_RATE_TYPE_VHT ; + +break ; + +case NL80211_RATE_INFO_HE_MCS : +if (len !=1 ) +return false; + + mcs = *(const uint8_t *) data; + rate_type =NETDEV_RATE_TYPE_HT ; + +break ; + } + } + +if (!rate) +return false; + + *type_out = rate_type; + *rate_out = rate; + +if (rate_type !=NETDEV_RATE_TYPE_LEGACY ) + *mcs_out = mcs; + +return true; +} +static bool netdev_parse_sta_info (struct l_genl_attr *attr,struct netdev_station_info *info) {uint16_t type, len;const void *data; +struct l_genl_attr nested;while (l_genl_attr_next (attr, &type, &len, &data)) {switch (type) {
@@ -383,6 +446,31 @@ static bool netdev_parse_sta_info(struct l_genl_attr *attr, info->cur_rssi = *(const int8_t *) data; info->have_cur_rssi = true; +break ; +case NL80211_STA_INFO_RX_BITRATE : +if (!l_genl_attr_recurse (attr, &nested)) +return false; + +if (!netdev_parse_bitrate (&nested, &info->rx_rate_type, + &info->rx_bitrate, + &info->rx_mcs)) +return false; + + info->have_rx_bitrate = true; + +break ; + +case NL80211_STA_INFO_TX_BITRATE : +if (!l_genl_attr_recurse (attr, &nested)) +return false; + +if (!netdev_parse_bitrate (&nested, &info->tx_rate_type, + &info->tx_bitrate, + &info->tx_mcs)) +return false; + + info->have_tx_bitrate = true; +break ; } }
src/netdev.h +16 -0
@@ -114,11 +114,27 @@ typedef void (*netdev_station_watch_func_t)(struct netdev *netdev, const uint8_t *mac, bool added, void *user_data); +enum netdev_rate_type { +NETDEV_RATE_TYPE_LEGACY , +NETDEV_RATE_TYPE_HT , +NETDEV_RATE_TYPE_VHT , +NETDEV_RATE_TYPE_HE , +}; +struct netdev_station_info {uint8_t addr[6 ];int8_t cur_rssi; +enum netdev_rate_type rx_rate_type; +uint32_t rx_bitrate; +uint8_t rx_mcs; +enum netdev_rate_type tx_rate_type; +uint32_t tx_bitrate; +uint8_t tx_mcs; +bool have_cur_rssi :1 ; +bool have_rx_bitrate :1 ; +bool have_tx_bitrate :1 ; }; typedef void (*netdev_get_station_cb_t)(const struct netdev_station_info *info,
Signature · 1 line
2.26.2
PATCH v4 2/5 netdev: parse expected throughput in netdev_get_station
--- src/netdev.c | 9 +++++++++ src/netdev.h | 3 +++ 2 files changed, 12 insertions(+)
src/netdev.c +9 -0
@@ -471,6 +471,15 @@ static bool netdev_parse_sta_info(struct l_genl_attr *attr, info->have_tx_bitrate = true; +break ; + +case NL80211_STA_INFO_EXPECTED_THROUGHPUT : +if (len !=4 ) +return false; + + info->expected_throughput = *(const uint32_t *)data; + info->have_expected_throughput = true; +break ; } }
src/netdev.h +3 -0
@@ -132,9 +132,12 @@ struct netdev_station_info {uint32_t tx_bitrate;uint8_t tx_mcs; +uint32_t expected_throughput; + bool have_cur_rssi : 1; bool have_rx_bitrate : 1; bool have_tx_bitrate : 1; + bool have_expected_throughput : 1; }; typedef void (*netdev_get_station_cb_t)(const struct netdev_station_info *info,
Signature · 1 line
2.26.2
PATCH v4 3/5 station: create StationDiagnostic interface
In reply to James PrestwoodThis interface sits aside the regular station interface but provides low level connection details for diagnostic and testing purposes.
--- src/station.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+)
v4:
* Using the rate type we can now include whether the connection is Legacy, 802.11n/ac/ax.
src/station.c +142 -0
@@ -77,6 +77,7 @@ struct station {struct l_dbus_message *hidden_pending;struct l_dbus_message *disconnect_pending;struct l_dbus_message *scan_pending; +struct l_dbus_message *get_station_pending;struct signal_agent *signal_agent;uint32_t dbus_scan_id;uint32_t quick_scan_id;
@@ -3333,6 +3334,9 @@ static struct station *station_create(struct netdev *netdev)l_dbus_object_add_interface (dbus,netdev_get_path (netdev),IWD_STATION_INTERFACE , station); +l_dbus_object_add_interface (dbus,netdev_get_path (netdev), +IWD_STATION_DIAGNOSTIC_INTERFACE , + station);if (netconfig_enabled) station->netconfig =netconfig_new (netdev_get_ifindex (netdev));
@@ -3455,6 +3459,137 @@ static void station_destroy_interface(void *user_data)station_free (station); } +static void station_get_diagnostic_cb (const struct netdev_station_info *info, +void *user_data) +{ +struct station *station = user_data; +struct l_dbus_message *reply; +struct l_dbus_message_builder *builder; +int16_t rssi; + + +if (!info) { + reply =dbus_error_aborted (station->get_station_pending); + goto done; + } + + reply =l_dbus_message_new_method_return (station->get_station_pending); + + rssi = (int16_t )info->cur_rssi; + + builder =l_dbus_message_builder_new (reply); + +l_dbus_message_builder_enter_array (builder,"{sv}" ); + +dbus_append_dict_basic (builder,"ConnectedBss" ,'s' , +util_address_to_string (info->addr)); + +if (info->have_cur_rssi) +dbus_append_dict_basic (builder,"RSSI" ,'n' , &rssi); + +switch (info->rx_rate_type) { +case NETDEV_RATE_TYPE_LEGACY : +dbus_append_dict_basic (builder,"RxRateType" ,'s' ,"Legacy" ); +break ; +case NETDEV_RATE_TYPE_HT : +dbus_append_dict_basic (builder,"RxRateType" ,'s' ,"802.11n" ); +dbus_append_dict_basic (builder,"RxMCS" ,'y' , &info->rx_mcs); +break ; +case NETDEV_RATE_TYPE_VHT : +dbus_append_dict_basic (builder,"RxRateType" ,'s' ,"802.11ac" ); +dbus_append_dict_basic (builder,"RxMCS" ,'y' , &info->rx_mcs); +break ; +case NETDEV_RATE_TYPE_HE : +dbus_append_dict_basic (builder,"RxRateType" ,'s' ,"802.11ax" ); +dbus_append_dict_basic (builder,"RxMCS" ,'y' , &info->rx_mcs); +break ; + } + +switch (info->tx_rate_type) { +case NETDEV_RATE_TYPE_LEGACY : +dbus_append_dict_basic (builder,"TxRateType" ,'s' ,"Legacy" ); +break ; +case NETDEV_RATE_TYPE_HT : +dbus_append_dict_basic (builder,"TxRateType" ,'s' ,"802.11n" ); +dbus_append_dict_basic (builder,"TxMCS" ,'y' , &info->tx_mcs); +break ; +case NETDEV_RATE_TYPE_VHT : +dbus_append_dict_basic (builder,"TxRateType" ,'s' ,"802.11ac" ); +dbus_append_dict_basic (builder,"TxMCS" ,'y' , &info->tx_mcs); +break ; +case NETDEV_RATE_TYPE_HE : +dbus_append_dict_basic (builder,"TxRateType" ,'s' ,"802.11ax" ); +dbus_append_dict_basic (builder,"TxMCS" ,'y' , &info->tx_mcs); +break ; + } + +if (info->have_tx_bitrate) +dbus_append_dict_basic (builder,"TxBitrate" ,'u' , + &info->tx_bitrate); + +if (info->have_rx_bitrate) +dbus_append_dict_basic (builder,"RxBitrate" ,'u' , + &info->rx_bitrate); + +if (info->have_expected_throughput) +dbus_append_dict_basic (builder,"ExpectedThroughput" ,'u' , + &info->expected_throughput); + +l_dbus_message_builder_leave_array (builder); +l_dbus_message_builder_finalize (builder); +l_dbus_message_builder_destroy (builder); + +done: +dbus_pending_reply (&station->get_station_pending, reply); +} + +static void station_get_diagnostic_destroy (void *user_data) +{ +struct station *station = user_data; +struct l_dbus_message *reply; + +if (station->get_station_pending) { + reply =dbus_error_aborted (station->get_station_pending); +dbus_pending_reply (&station->get_station_pending, reply); + } +} + +static struct l_dbus_message *station_get_diagnostics (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +struct station *station = user_data; +int ret; + +/* +* At this time all values depend on a connected state. +*/ +if (station->state !=STATION_STATE_CONNECTED ) +return dbus_error_not_connected (message); + + ret =netdev_get_current_station (station->netdev, + station_get_diagnostic_cb, station, + station_get_diagnostic_destroy); +if (ret <0 ) +return dbus_error_from_errno (ret, message); + + station->get_station_pending =l_dbus_message_ref (message); + +return NULL ; +} + +static void station_setup_diagnostic_interface ( +struct l_dbus_interface *interface) +{ +l_dbus_interface_method (interface,"GetDiagnostics" ,0 , + station_get_diagnostics,"a{sv}" ,"" , +"diagnostics" ); +} + +static void station_destroy_diagnostic_interface (void *user_data) +{ +} +static void station_netdev_watch (struct netdev *netdev,enum netdev_watch_event event,void *userdata) {
@@ -3483,6 +3618,11 @@ static int station_init(void)l_dbus_register_interface (dbus_get_bus (),IWD_STATION_INTERFACE , station_setup_interface, station_destroy_interface, false); +l_dbus_register_interface (dbus_get_bus (), +IWD_STATION_DIAGNOSTIC_INTERFACE , + station_setup_diagnostic_interface, + station_destroy_diagnostic_interface, + false); if (!l_settings_get_uint(iwd_get_config(), "General", "ManagementFrameProtection",
@@ -3521,6 +3661,8 @@ static int station_init(void)static void station_exit (void ) { +l_dbus_unregister_interface (dbus_get_bus (), +IWD_STATION_DIAGNOSTIC_INTERFACE );l_dbus_unregister_interface (dbus_get_bus (),IWD_STATION_INTERFACE );netdev_watch_remove (netdev_watch);l_queue_destroy (station_list,NULL );
Signature · 1 line
2.26.2
PATCH v4 4/5 test: update get-diagnostics with RateTypes
In reply to James Prestwood--- test/get-diagnostics | 2 ++ 1 file changed, 2 insertions(+)
test/get-diagnostics +2 -0
@@ -8,8 +8,10 @@ import dbus unit_map = { "ConnectedBss" : None, "RSSI" : "dBm", + "RxRateType" : None, "RxBitrate" : lambda k : str(100 * int(k)) + ' Kbps', "RxMCS" : lambda i : str(int(i)), + "TxRateType" : None, "TxBitrate" : lambda k : str(100 * int(k)) + ' Kbps', "TxMCS" : lambda i : str(int(i)), "ExpectedThroughput" : "Kbps"
Signature · 1 line
2.26.2
PATCH v4 5/5 doc: add RateType's on diagnostic interface
In reply to James Prestwood--- doc/diagnostics.txt | 9 +++++++++ 1 file changed, 9 insertions(+)
doc/diagnostics.txt +9 -0
@@ -23,10 +23,19 @@ Methods dict GetDiagnostics() RSSI [optional] - The RSSI of the currently connected BSS. + RxRateType - The phy technology being use (Legacy, 802.11n, + 802.11ac or 802.11ax). The MCS values (not + present in Legacy case) have a different + meaning depending on RateType, e.g. 802.11n + will use HT MCS values, 802.11ac use VHT etc. + RxRate [optional] - Receive rate in 100kbit/s RxMCS [optional] - Receiving MCS index + TxRateType - Same meaning as RxRateType, just for + transmission. + TxRate [optional] - Transmission rate in 100kbit/s TxMCS [optional] - Transmitting MCS index
Signature · 1 line
2.26.2