Skip to content

Commit

Permalink
[nrf fromlist] wifi: ap: Add client side events
Browse files Browse the repository at this point in the history
These are helpful to track clients being added and deleted.
Applications can actions based on these events.

Upstream PR: zephyrproject-rtos/zephyr#67015

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
(cherry picked from commit 81038eb)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
krish2718 authored and de-nordic committed Jan 8, 2024
1 parent 5a892c0 commit 3b25348
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
38 changes: 38 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Expand Up @@ -184,6 +184,10 @@ enum net_event_wifi_cmd {
NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT,
/** AP mode disable result */
NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT,
/** STA connected to AP */
NET_EVENT_WIFI_CMD_AP_STA_CONNECTED,
/** STA disconnected from AP */
NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED,
};

#define NET_EVENT_WIFI_SCAN_RESULT \
Expand Down Expand Up @@ -219,6 +223,12 @@ enum net_event_wifi_cmd {
#define NET_EVENT_WIFI_AP_DISABLE_RESULT \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT)

#define NET_EVENT_WIFI_AP_STA_CONNECTED \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_CONNECTED)

#define NET_EVENT_WIFI_AP_STA_DISCONNECTED \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED)

/**
* @brief Wi-Fi structure to uniquely identify a band-channel pair
*/
Expand Down Expand Up @@ -568,6 +578,18 @@ struct wifi_raw_scan_result {
};
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */

/** AP mode - connected STA details */
struct wifi_ap_sta_info {
/** Link mode, see enum wifi_link_mode */
enum wifi_link_mode link_mode;
/** MAC address */
uint8_t mac[WIFI_MAC_ADDR_LEN];
/** MAC address length */
uint8_t mac_length;
/** is TWT capable ? */
bool twt_capable;
};

/* for use in max info size calculations */
union wifi_mgmt_events {
struct wifi_scan_result scan_result;
Expand All @@ -577,6 +599,7 @@ union wifi_mgmt_events {
struct wifi_raw_scan_result raw_scan_result;
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
struct wifi_twt_params twt_params;
struct wifi_ap_sta_info ap_sta_info;
};

/** Wi-Fi mode setup */
Expand Down Expand Up @@ -849,6 +872,21 @@ void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_s
*/
void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status);

/** Wi-Fi management AP mode STA connected event
*
* @param iface Network interface
* @param sta_info STA information
*/
void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface,
struct wifi_ap_sta_info *sta_info);

/** Wi-Fi management AP mode STA disconnected event
* @param iface Network interface
* @param sta_info STA information
*/
void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface,
struct wifi_ap_sta_info *sta_info);

/**
* @}
*/
Expand Down
16 changes: 16 additions & 0 deletions subsys/net/l2/wifi/wifi_mgmt.c
Expand Up @@ -731,3 +731,19 @@ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface,
iface, &cnx_status,
sizeof(enum wifi_ap_status));
}

void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface,
struct wifi_ap_sta_info *sta_info)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_CONNECTED,
iface, sta_info,
sizeof(struct wifi_ap_sta_info));
}

void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface,
struct wifi_ap_sta_info *sta_info)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_DISCONNECTED,
iface, sta_info,
sizeof(struct wifi_ap_sta_info));
}
32 changes: 31 additions & 1 deletion subsys/net/l2/wifi/wifi_shell.c
Expand Up @@ -35,7 +35,9 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
NET_EVENT_WIFI_TWT |\
NET_EVENT_WIFI_RAW_SCAN_RESULT |\
NET_EVENT_WIFI_AP_ENABLE_RESULT |\
NET_EVENT_WIFI_AP_DISABLE_RESULT)
NET_EVENT_WIFI_AP_DISABLE_RESULT |\
NET_EVENT_WIFI_AP_STA_CONNECTED |\
NET_EVENT_WIFI_AP_STA_DISCONNECTED)

#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY
#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON)
Expand Down Expand Up @@ -328,6 +330,28 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb)
}
}

static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb)
{
const struct wifi_ap_sta_info *sta_info =
(const struct wifi_ap_sta_info *)cb->info;
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];

print(context.sh, SHELL_NORMAL, "Station connected: %s\n",
net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN,
mac_string_buf, sizeof(mac_string_buf)));
}

static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb)
{
const struct wifi_ap_sta_info *sta_info =
(const struct wifi_ap_sta_info *)cb->info;
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];

print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n",
net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN,
mac_string_buf, sizeof(mac_string_buf)));
}

static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
Expand Down Expand Up @@ -358,6 +382,12 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
case NET_EVENT_WIFI_AP_DISABLE_RESULT:
handle_wifi_ap_disable_result(cb);
break;
case NET_EVENT_WIFI_AP_STA_CONNECTED:
handle_wifi_ap_sta_connected(cb);
break;
case NET_EVENT_WIFI_AP_STA_DISCONNECTED:
handle_wifi_ap_sta_disconnected(cb);
break;
default:
break;
}
Expand Down

0 comments on commit 3b25348

Please sign in to comment.