Skip to content

Commit beff44c

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 <davidr@beechwoods.com>
1 parent 86293eb commit beff44c

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

drivers/wifi/infineon/airoc_wifi.c

Lines changed: 80 additions & 0 deletions
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

@@ -760,6 +761,84 @@ static int airoc_mgmt_ap_disable(const struct device *dev)
760761
return 0;
761762
}
762763

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

0 commit comments

Comments
 (0)