netdev: move GETLINK into its own function, track command ID
PATCH v2 1/3 netdev: move GETLINK into its own function, track command ID
Move this logic into its own function and track the command ID so it can be canceled in case of netdev going down.
--- src/netdev.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-)
src/netdev.c +31 -18
@@ -131,6 +131,7 @@ struct netdev {uint32_t qos_map_cmd_id;uint32_t mac_change_cmd_id;uint32_t get_oci_cmd_id; +uint32_t get_link_cmd_id;enum netdev_result result;uint16_t last_code;/* reason or status, depending on result */ struct l_timeout *neighbor_report_timeout;
@@ -940,6 +941,11 @@ static void netdev_free(void *data)if (netdev->fw_roam_bss)scan_bss_free (netdev->fw_roam_bss); +if (netdev->get_link_cmd_id) { +l_netlink_cancel (rtnl, netdev->get_link_cmd_id); + netdev->get_link_cmd_id =0 ; + } +scan_wdev_remove (netdev->wdev_id);watchlist_destroy (&netdev->station_watches);
@@ -6116,9 +6122,9 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,static void netdev_getlink_cb (int error,uint16_t type,const void *data,uint32_t len,void *user_data) { +struct netdev *netdev = user_data;const struct ifinfomsg *ifi = data;unsigned int bytes; -struct netdev *netdev;l_netlink_command_func_t cb;bool powered;
@@ -6133,8 +6139,7 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,return ; } - netdev =netdev_find (ifi->ifi_index); -if (!netdev) +if (L_WARN_ON ((uint32_t )ifi->ifi_index != netdev->index))return ; bytes = len -NLMSG_ALIGN (sizeof (struct ifinfomsg ));
@@ -6212,6 +6217,27 @@ error:return NULL ; } +static void netdev_get_link (struct netdev *netdev) +{ +struct ifinfomsg *rtmmsg; +size_t bufsize; + +/* Query interface flags */ + bufsize =NLMSG_ALIGN (sizeof (struct ifinfomsg )); + rtmmsg =l_malloc (bufsize); +memset (rtmmsg,0 , bufsize); + + rtmmsg->ifi_family =AF_UNSPEC ; + rtmmsg->ifi_index = netdev->index; + + netdev->get_link_cmd_id =l_netlink_send (rtnl,RTM_GETLINK ,0 , rtmmsg, + bufsize, netdev_getlink_cb, + netdev,NULL ); +L_WARN_ON (netdev->get_link_cmd_id ==0 ); + +l_free (rtmmsg); +} +struct netdev *netdev_create_from_genl (struct l_genl_msg *msg,const uint8_t *set_mac) {
@@ -6223,8 +6249,6 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,uint32_t wiphy_id;struct netdev *netdev;struct wiphy *wiphy =NULL ; -struct ifinfomsg *rtmmsg; -size_t bufsize;struct l_io *pae_io =NULL ; if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
@@ -6283,21 +6307,10 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,l_debug ("Created interface %s[%d %" PRIx64"]" , netdev->name, netdev->index, netdev->wdev_id); -/* Query interface flags */ - bufsize =NLMSG_ALIGN (sizeof (struct ifinfomsg )); - rtmmsg =l_malloc (bufsize); -memset (rtmmsg,0 , bufsize); - - rtmmsg->ifi_family =AF_UNSPEC ; - rtmmsg->ifi_index = ifindex; - -l_netlink_send (rtnl,RTM_GETLINK ,0 , rtmmsg, bufsize, - netdev_getlink_cb,NULL ,NULL ); - -l_free (rtmmsg); -netdev_setup_interface (netdev); +netdev_get_link (netdev); +return netdev; }
Signature · 1 line
2.25.1
PATCH v2 2/3 netdev: disable power save if required
Disable power save if the wiphy indicates its needed. Do this before issuing GET_LINK so the netdev doesn't signal its up until power save is disabled.
--- src/netdev.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
src/netdev.c +41 -0
@@ -132,6 +132,7 @@ struct netdev {uint32_t mac_change_cmd_id;uint32_t get_oci_cmd_id;uint32_t get_link_cmd_id; +uint32_t power_save_cmd_id;enum netdev_result result;uint16_t last_code;/* reason or status, depending on result */ struct l_timeout *neighbor_report_timeout;
@@ -6238,6 +6239,40 @@ static void netdev_get_link(struct netdev *netdev)l_free (rtmmsg); } +static void netdev_disable_ps_cb (struct l_genl_msg *msg,void *user_data) +{ +struct netdev *netdev = user_data; +int err =l_genl_msg_get_error (msg); + +/* Can't do anything about it but inform the user */ +if (err <0 ) +l_error ("Failed to disable power save for ifindex %u (%s: %d)" , + netdev->index,strerror (-err), err); +else +l_debug ("Disabled power save for ifindex %u" , netdev->index); + +netdev_get_link (netdev); +} + +static bool netdev_disable_power_save (struct netdev *netdev) +{ +struct l_genl_msg *msg =l_genl_msg_new (NL80211_CMD_SET_POWER_SAVE ); +uint32_t disabled =NL80211_PS_DISABLED ; + +l_genl_msg_append_attr (msg,NL80211_ATTR_IFINDEX ,4 , &netdev->index); +l_genl_msg_append_attr (msg,NL80211_ATTR_PS_STATE ,4 , &disabled); + + netdev->power_save_cmd_id =l_genl_family_send (nl80211, msg, + netdev_disable_ps_cb, + netdev,NULL ); +if (!netdev->power_save_cmd_id) { +l_error ("Failed to send SET_POWER_SAVE (-EIO)" ); +return false; + } + +return true; +} +struct netdev *netdev_create_from_genl (struct l_genl_msg *msg,const uint8_t *set_mac) {
@@ -6309,6 +6344,12 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,netdev_setup_interface (netdev); +if (wiphy_power_save_disabled (wiphy)) { +/* Wait to issue GET_LINK until PS is disabled */ +if (netdev_disable_power_save (netdev)) +return netdev; + } +netdev_get_link (netdev);return netdev;
Signature · 1 line
2.25.1
PATCH v2 3/3 wiphy: remove l_info's for control port/power save
In reply to James PrestwoodThese should not have been put into a getter for wiphy and now the driver quirks are printed out in wiphy_print_basic_info.
--- src/wiphy.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
src/wiphy.c +2 -8
@@ -708,11 +708,8 @@ bool wiphy_control_port_enabled(struct wiphy *wiphy)const struct l_settings *settings =iwd_get_config ();bool enabled; -if (wiphy->driver_flags &FORCE_PAE ) { -l_info ("Not using Control Port due to driver quirks: %s" , -wiphy_get_driver (wiphy)); +if (wiphy->driver_flags &FORCE_PAE )return false; - }if (!wiphy_has_ext_feature (wiphy,NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211 ))
@@ -727,11 +724,8 @@ bool wiphy_control_port_enabled(struct wiphy *wiphy)bool wiphy_power_save_disabled (struct wiphy *wiphy) { -if (wiphy->driver_flags &POWER_SAVE_DISABLE ) { -l_info ("Disabling power save due to driver quirks: %s" , -wiphy_get_driver (wiphy)); +if (wiphy->driver_flags &POWER_SAVE_DISABLE )return true; - }return false; }
Signature · 1 line
2.25.1