Skip to content

Commit 40a8960

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 40a8960

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

drivers/wifi/infineon/airoc_wifi.c

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

0 commit comments

Comments
 (0)