Skip to content

Commit 298f0a3

Browse files
committed
drivers: wifi: infineon: add .iface_status method
The .iface_status method of the wifi_mgmt_ops API needs to be added so that the "wifi status" command on the network shell will work. Signed-off-by: Dave Rensberger <[email protected]>
1 parent 86293eb commit 298f0a3

File tree

1 file changed

+87
-15
lines changed

1 file changed

+87
-15
lines changed

drivers/wifi/infineon/airoc_wifi.c

+87-15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/net/conn_mgr/connectivity_wifi_mgmt.h>
1414
#include <airoc_wifi.h>
1515
#include <airoc_whd_hal_common.h>
16+
#include <whd_wlioctl.h>
1617

1718
LOG_MODULE_REGISTER(infineon_airoc_wifi, CONFIG_WIFI_LOG_LEVEL);
1819

@@ -25,7 +26,7 @@ LOG_MODULE_REGISTER(infineon_airoc_wifi, CONFIG_WIFI_LOG_LEVEL);
2526
#endif
2627

2728
#ifndef AIROC_WIFI_PACKET_POOL_SIZE
28-
#define AIROC_WIFI_PACKET_POOL_SIZE (1600)
29+
#define AIROC_WIFI_PACKET_POOL_SIZE (1600)
2930
#endif
3031

3132
#define AIROC_WIFI_PACKET_POOL_COUNT \
@@ -49,8 +50,8 @@ int airoc_wifi_init_primary(const struct device *dev, whd_interface_t *interface
4950
whd_netif_funcs_t *netif_funcs, whd_buffer_funcs_t *buffer_if);
5051

5152
/* Allocate network pool */
52-
NET_BUF_POOL_FIXED_DEFINE(airoc_pool, AIROC_WIFI_PACKET_POOL_COUNT,
53-
AIROC_WIFI_PACKET_POOL_SIZE, 0, NULL);
53+
NET_BUF_POOL_FIXED_DEFINE(airoc_pool, AIROC_WIFI_PACKET_POOL_COUNT, AIROC_WIFI_PACKET_POOL_SIZE, 0,
54+
NULL);
5455

5556
/* AIROC globals */
5657
static uint16_t ap_event_handler_index = 0xFF;
@@ -236,7 +237,7 @@ static whd_result_t airoc_wifi_host_buffer_get(whd_buffer_t *buffer, whd_buffer_
236237
*buffer = buf;
237238

238239
/* Set buffer size */
239-
(void) airoc_wifi_buffer_set_size(*buffer, size);
240+
(void)airoc_wifi_buffer_set_size(*buffer, size);
240241

241242
return WHD_SUCCESS;
242243
}
@@ -302,7 +303,7 @@ static int airoc_mgmt_send(const struct device *dev, struct net_pkt *pkt)
302303
}
303304

304305
/* Allocate Network Buffer from pool with Packet Length + Data Header */
305-
ret = airoc_wifi_host_buffer_get((whd_buffer_t *) &buf, WHD_NETWORK_TX,
306+
ret = airoc_wifi_host_buffer_get((whd_buffer_t *)&buf, WHD_NETWORK_TX,
306307
pkt_len + sizeof(data_header_t), 0);
307308
if ((ret != WHD_SUCCESS) || (buf == NULL)) {
308309
return -EIO;
@@ -381,8 +382,7 @@ static enum ethernet_hw_caps airoc_get_capabilities(const struct device *dev)
381382
return ETHERNET_HW_FILTERING;
382383
}
383384

384-
static int airoc_set_config(const struct device *dev,
385-
enum ethernet_config_type type,
385+
static int airoc_set_config(const struct device *dev, enum ethernet_config_type type,
386386
const struct ethernet_config *config)
387387
{
388388
ARG_UNUSED(dev);
@@ -602,10 +602,8 @@ static void *airoc_wifi_ap_link_events_handler(whd_interface_t ifp,
602602
const whd_event_header_t *event_header,
603603
const uint8_t *event_data, void *handler_user_data)
604604
{
605-
struct airoc_wifi_event_t airoc_event = {
606-
.is_ap_event = 1,
607-
.event_type = event_header->event_type
608-
};
605+
struct airoc_wifi_event_t airoc_event = {.is_ap_event = 1,
606+
.event_type = event_header->event_type};
609607

610608
k_msgq_put(&airoc_wifi_msgq, &airoc_event, K_FOREVER);
611609

@@ -658,8 +656,7 @@ static int airoc_mgmt_ap_enable(const struct device *dev, struct wifi_connect_re
658656
channel = params->channel;
659657
} else {
660658
channel = 1;
661-
LOG_WRN("Discard of setting unsupported channel: %u (will set 1)",
662-
params->channel);
659+
LOG_WRN("Discard of setting unsupported channel: %u (will set 1)", params->channel);
663660
}
664661

665662
switch (params->security) {
@@ -760,6 +757,80 @@ static int airoc_mgmt_ap_disable(const struct device *dev)
760757
return 0;
761758
}
762759

760+
static int airoc_iface_status(const struct device *dev, struct wifi_iface_status *status)
761+
{
762+
struct airoc_wifi_data *data = dev->data;
763+
whd_result_t result;
764+
wl_bss_info_t bss_info;
765+
whd_security_t security_info = 0;
766+
uint32_t wpa_data_rate_value = 0;
767+
uint32_t join_status;
768+
769+
if (airoc_if == NULL) {
770+
return -ENOTSUP;
771+
}
772+
773+
status->iface_mode =
774+
(data->is_ap_up ? WIFI_MODE_AP
775+
: (data->is_sta_connected ? WIFI_MODE_INFRA : WIFI_MODE_UNKNOWN));
776+
777+
join_status = whd_wifi_is_ready_to_transceive(airoc_if);
778+
779+
if (join_status == WHD_SUCCESS) {
780+
status->state = WIFI_STATE_COMPLETED;
781+
} else if (join_status == WHD_JOIN_IN_PROGRESS) {
782+
status->state = WIFI_STATE_ASSOCIATING;
783+
} else if (join_status == WHD_NOT_KEYED) {
784+
status->state = WIFI_STATE_AUTHENTICATING;
785+
} else {
786+
status->state = WIFI_STATE_DISCONNECTED;
787+
}
788+
789+
result = whd_wifi_get_ap_info(airoc_if, &bss_info, &security_info);
790+
791+
if (result == WHD_SUCCESS) {
792+
memcpy(&(status->bssid[0]), &(bss_info.BSSID), sizeof(whd_mac_t));
793+
794+
whd_wifi_get_channel(airoc_if, (int *)&status->channel);
795+
796+
status->band = (status->channel <= CH_MAX_2G_CHANNEL) ? WIFI_FREQ_BAND_2_4_GHZ
797+
: WIFI_FREQ_BAND_5_GHZ;
798+
799+
status->rssi = (int)bss_info.RSSI;
800+
801+
status->ssid_len = bss_info.SSID_len;
802+
strncpy(status->ssid, bss_info.SSID, bss_info.SSID_len);
803+
804+
status->security = convert_whd_security_to_zephyr(security_info);
805+
806+
status->beacon_interval = (unsigned short)bss_info.beacon_period;
807+
status->dtim_period = (unsigned char)bss_info.dtim_period;
808+
809+
status->twt_capable = false;
810+
}
811+
812+
whd_wifi_get_ioctl_value(airoc_if, WLC_GET_RATE, &wpa_data_rate_value);
813+
status->current_phy_tx_rate = wpa_data_rate_value;
814+
815+
/* Unbelievably, this appears to be the only way to determine the phy mode with
816+
* the whd SDK that we're currently using. Note that the logic below is only valid on
817+
* devices that are limited to the 2.4Ghz band. Other versions of the SDK and chip
818+
* evidently allow one to obtain a phy_mode value directly from bss_info
819+
*/
820+
if (wpa_data_rate_value > 54) {
821+
status->link_mode = WIFI_4;
822+
} else if (wpa_data_rate_value == 6 || wpa_data_rate_value == 9 ||
823+
wpa_data_rate_value == 12 || wpa_data_rate_value == 18 ||
824+
wpa_data_rate_value == 24 || wpa_data_rate_value == 36 ||
825+
wpa_data_rate_value == 48 || wpa_data_rate_value == 54) {
826+
status->link_mode = WIFI_3;
827+
} else {
828+
status->link_mode = WIFI_1;
829+
}
830+
831+
return 0;
832+
}
833+
763834
static int airoc_init(const struct device *dev)
764835
{
765836
int ret;
@@ -785,8 +856,8 @@ static int airoc_init(const struct device *dev)
785856
}
786857
airoc_if = airoc_sta_if;
787858

788-
whd_ret = whd_management_set_event_handler(airoc_sta_if, sta_link_events,
789-
link_events_handler, NULL, &sta_event_handler_index);
859+
whd_ret = whd_management_set_event_handler(
860+
airoc_sta_if, sta_link_events, link_events_handler, NULL, &sta_event_handler_index);
790861
if (whd_ret != CY_RSLT_SUCCESS) {
791862
LOG_ERR("whd_management_set_event_handler failed ret = %d \r\n", whd_ret);
792863
return -EAGAIN;
@@ -813,6 +884,7 @@ static const struct wifi_mgmt_ops airoc_wifi_mgmt = {
813884
.disconnect = airoc_mgmt_disconnect,
814885
.ap_enable = airoc_mgmt_ap_enable,
815886
.ap_disable = airoc_mgmt_ap_disable,
887+
.iface_status = airoc_iface_status,
816888
#if defined(CONFIG_NET_STATISTICS_WIFI)
817889
.get_stats = airoc_mgmt_wifi_stats,
818890
#endif

0 commit comments

Comments
 (0)