|
13 | 13 | #include <zephyr/net/conn_mgr/connectivity_wifi_mgmt.h> |
14 | 14 | #include <airoc_wifi.h> |
15 | 15 | #include <airoc_whd_hal_common.h> |
| 16 | +#include <whd_wlioctl.h> |
16 | 17 |
|
17 | 18 | LOG_MODULE_REGISTER(infineon_airoc_wifi, CONFIG_WIFI_LOG_LEVEL); |
18 | 19 |
|
@@ -811,6 +812,80 @@ static int airoc_mgmt_ap_disable(const struct device *dev) |
811 | 812 | return 0; |
812 | 813 | } |
813 | 814 |
|
| 815 | +static int airoc_iface_status(const struct device *dev, struct wifi_iface_status *status) |
| 816 | +{ |
| 817 | + struct airoc_wifi_data *data = dev->data; |
| 818 | + whd_result_t result; |
| 819 | + wl_bss_info_t bss_info; |
| 820 | + whd_security_t security_info = 0; |
| 821 | + uint32_t wpa_data_rate_value = 0; |
| 822 | + uint32_t join_status; |
| 823 | + |
| 824 | + if (airoc_if == NULL) { |
| 825 | + return -ENOTSUP; |
| 826 | + } |
| 827 | + |
| 828 | + status->iface_mode = |
| 829 | + (data->is_ap_up ? WIFI_MODE_AP |
| 830 | + : (data->is_sta_connected ? WIFI_MODE_INFRA : WIFI_MODE_UNKNOWN)); |
| 831 | + |
| 832 | + join_status = whd_wifi_is_ready_to_transceive(airoc_if); |
| 833 | + |
| 834 | + if (join_status == WHD_SUCCESS) { |
| 835 | + status->state = WIFI_STATE_COMPLETED; |
| 836 | + } else if (join_status == WHD_JOIN_IN_PROGRESS) { |
| 837 | + status->state = WIFI_STATE_ASSOCIATING; |
| 838 | + } else if (join_status == WHD_NOT_KEYED) { |
| 839 | + status->state = WIFI_STATE_AUTHENTICATING; |
| 840 | + } else { |
| 841 | + status->state = WIFI_STATE_DISCONNECTED; |
| 842 | + } |
| 843 | + |
| 844 | + result = whd_wifi_get_ap_info(airoc_if, &bss_info, &security_info); |
| 845 | + |
| 846 | + if (result == WHD_SUCCESS) { |
| 847 | + memcpy(&(status->bssid[0]), &(bss_info.BSSID), sizeof(whd_mac_t)); |
| 848 | + |
| 849 | + whd_wifi_get_channel(airoc_if, (int *)&status->channel); |
| 850 | + |
| 851 | + status->band = (status->channel <= CH_MAX_2G_CHANNEL) ? WIFI_FREQ_BAND_2_4_GHZ |
| 852 | + : WIFI_FREQ_BAND_5_GHZ; |
| 853 | + |
| 854 | + status->rssi = (int)bss_info.RSSI; |
| 855 | + |
| 856 | + status->ssid_len = bss_info.SSID_len; |
| 857 | + strncpy(status->ssid, bss_info.SSID, status->ssid_len); |
| 858 | + |
| 859 | + status->security = convert_whd_security_to_zephyr(security_info); |
| 860 | + |
| 861 | + status->beacon_interval = (unsigned short)bss_info.beacon_period; |
| 862 | + status->dtim_period = (unsigned char)bss_info.dtim_period; |
| 863 | + |
| 864 | + status->twt_capable = false; |
| 865 | + } |
| 866 | + |
| 867 | + whd_wifi_get_ioctl_value(airoc_if, WLC_GET_RATE, &wpa_data_rate_value); |
| 868 | + status->current_phy_tx_rate = wpa_data_rate_value; |
| 869 | + |
| 870 | + /* Unbelievably, this appears to be the only way to determine the phy mode with |
| 871 | + * the whd SDK that we're currently using. Note that the logic below is only valid on |
| 872 | + * devices that are limited to the 2.4Ghz band. Other versions of the SDK and chip |
| 873 | + * evidently allow one to obtain a phy_mode value directly from bss_info |
| 874 | + */ |
| 875 | + if (wpa_data_rate_value > 54) { |
| 876 | + status->link_mode = WIFI_4; |
| 877 | + } else if (wpa_data_rate_value == 6 || wpa_data_rate_value == 9 || |
| 878 | + wpa_data_rate_value == 12 || wpa_data_rate_value == 18 || |
| 879 | + wpa_data_rate_value == 24 || wpa_data_rate_value == 36 || |
| 880 | + wpa_data_rate_value == 48 || wpa_data_rate_value == 54) { |
| 881 | + status->link_mode = WIFI_3; |
| 882 | + } else { |
| 883 | + status->link_mode = WIFI_1; |
| 884 | + } |
| 885 | + |
| 886 | + return 0; |
| 887 | +} |
| 888 | + |
814 | 889 | static int airoc_init(const struct device *dev) |
815 | 890 | { |
816 | 891 | int ret; |
@@ -864,6 +939,7 @@ static const struct wifi_mgmt_ops airoc_wifi_mgmt = { |
864 | 939 | .disconnect = airoc_mgmt_disconnect, |
865 | 940 | .ap_enable = airoc_mgmt_ap_enable, |
866 | 941 | .ap_disable = airoc_mgmt_ap_disable, |
| 942 | + .iface_status = airoc_iface_status, |
867 | 943 | #if defined(CONFIG_NET_STATISTICS_WIFI) |
868 | 944 | .get_stats = airoc_mgmt_wifi_stats, |
869 | 945 | #endif |
|
0 commit comments