Skip to content

Commit 63eda93

Browse files
drivers: wifi: siwx917: Add AP station disconnect functionality
This commit adds support the following wifi commands: - wifi ap disconnect: Disconnect a specific station from the AP. - wifi ap stations: List connected devices. Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
1 parent c08ae5b commit 63eda93

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

drivers/wifi/siwx917/siwx917_wifi.c

+62-2
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,61 @@ static int siwx917_ap_disable(const struct device *dev)
490490
return ret;
491491
}
492492

493+
static int siwx917_ap_sta_disconnect(const struct device *dev, const uint8_t *mac_addr)
494+
{
495+
struct siwx917_dev *sidev = dev->data;
496+
sl_mac_address_t mac = { };
497+
int ret;
498+
499+
__ASSERT(mac_addr, "mac_addr cannot be NULL");
500+
501+
memcpy(mac.octet, mac_addr, ARRAY_SIZE(mac.octet));
502+
503+
ret = sl_wifi_disconnect_ap_client(sidev->interface, &mac, SL_WIFI_DEAUTH);
504+
if (ret) {
505+
LOG_ERR("Failed to disconnect: 0x%x", ret);
506+
return -EIO;
507+
}
508+
509+
return ret;
510+
}
511+
512+
static sl_status_t siwx917_on_connect(sl_wifi_event_t event, void *data,
513+
uint32_t data_length, void *arg)
514+
{
515+
ARG_UNUSED(event);
516+
struct siwx917_dev *sidev = arg;
517+
struct wifi_ap_sta_info sta_info = { };
518+
519+
__ASSERT(data, "data cannot be NULL");
520+
__ASSERT(arg, "arg cannot be NULL");
521+
522+
strncpy(sta_info.mac, (uint8_t *)data, data_length);
523+
sta_info.mac_length = data_length;
524+
sta_info.link_mode = WIFI_LINK_MODE_UNKNOWN;
525+
526+
wifi_mgmt_raise_ap_sta_connected_event(sidev->iface, &sta_info);
527+
528+
return SL_STATUS_OK;
529+
}
530+
531+
static sl_status_t siwx917_on_disconnect(sl_wifi_event_t event, void *data,
532+
uint32_t data_length, void *arg)
533+
{
534+
ARG_UNUSED(event);
535+
struct siwx917_dev *sidev = arg;
536+
struct wifi_ap_sta_info sta_info = { };
537+
538+
__ASSERT(data, "data cannot be NULL");
539+
__ASSERT(arg, "arg cannot be NULL");
540+
541+
memcpy(sta_info.mac, (uint8_t *)data, data_length);
542+
sta_info.mac_length = data_length;
543+
wifi_mgmt_raise_ap_sta_disconnected_event(sidev->iface, &sta_info);
544+
545+
return SL_STATUS_OK;
546+
}
547+
493548
static void siwx917_iface_init(struct net_if *iface)
494549
{
495550
struct siwx917_dev *sidev = iface->if_dev->dev->data;
@@ -500,6 +555,9 @@ static void siwx917_iface_init(struct net_if *iface)
500555

501556
sl_wifi_set_scan_callback(siwx917_on_scan, sidev);
502557
sl_wifi_set_join_callback(siwx917_on_join, sidev);
558+
sl_wifi_set_callback(SL_WIFI_CLIENT_CONNECTED_EVENTS, siwx917_on_connect, sidev);
559+
sl_wifi_set_callback(SL_WIFI_CLIENT_DISCONNECTED_EVENTS, siwx917_on_disconnect,
560+
sidev);
503561

504562
sidev->interface = sl_wifi_get_default_interface();
505563
status = sl_wifi_get_mac_address(FIELD_GET(SIWX917_INTERFACE_MASK, sidev->interface),
@@ -508,6 +566,7 @@ static void siwx917_iface_init(struct net_if *iface)
508566
LOG_ERR("sl_wifi_get_mac_address(): %#04x", status);
509567
return;
510568
}
569+
511570
net_if_set_link_addr(iface, sidev->macaddr.octet, sizeof(sidev->macaddr.octet),
512571
NET_LINK_ETHERNET);
513572
siwx917_sock_init(iface);
@@ -525,8 +584,9 @@ static const struct wifi_mgmt_ops siwx917_mgmt = {
525584
.scan = siwx917_scan,
526585
.connect = siwx917_connect,
527586
.disconnect = siwx917_disconnect,
528-
.ap_enable = siwx917_ap_enable,
529-
.ap_disable = siwx917_ap_disable,
587+
.ap_enable = siwx917_ap_enable,
588+
.ap_disable = siwx917_ap_disable,
589+
.ap_sta_disconnect = siwx917_ap_sta_disconnect,
530590
.iface_status = siwx917_status,
531591
};
532592

0 commit comments

Comments
 (0)