Skip to content

Commit 1b499ff

Browse files
committed
airoc: enable wifi status
Add wifi status API to airoc wifi driver Signed-off-by: Mattia Pennasilico <[email protected]>
1 parent 277ebb6 commit 1b499ff

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

drivers/wifi/infineon/airoc_wifi.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ static int airoc_mgmt_connect(const struct device *dev, struct wifi_connect_req_
616616
} else {
617617
net_if_dormant_off(data->iface);
618618
data->is_sta_connected = true;
619+
data->ssid.length = MIN(params->ssid_length, WIFI_SSID_MAX_LEN);
620+
memcpy(data->ssid.value, params->ssid, data->ssid.length);
619621
#if defined(CONFIG_NET_DHCPV4)
620622
net_dhcpv4_restart(data->iface);
621623
#endif /* defined(CONFIG_NET_DHCPV4) */
@@ -750,6 +752,8 @@ static int airoc_mgmt_ap_enable(const struct device *dev, struct wifi_connect_re
750752
}
751753

752754
data->is_ap_up = true;
755+
data->ssid.length = MIN(ssid.length, WIFI_SSID_MAX_LEN);
756+
memcpy(data->ssid.value, ssid.value, data->ssid.length);
753757
airoc_if = airoc_ap_if;
754758
net_if_dormant_off(data->iface);
755759
error:
@@ -780,6 +784,71 @@ static int airoc_mgmt_wifi_stats(const struct device *dev, struct net_stats_wifi
780784
}
781785
#endif
782786

787+
static int airoc_mgmt_wifi_status(const struct device *dev, struct wifi_iface_status *status)
788+
{
789+
cy_rslt_t whd_ret;
790+
whd_mac_t bssid;
791+
uint32_t channel;
792+
int32_t rssi;
793+
whd_listen_interval_t li;
794+
struct airoc_wifi_data *data = dev->data;
795+
796+
status->state = WIFI_STATE_DISCONNECTED;
797+
status->ssid_len = 0;
798+
status->ssid[0] = '\0';
799+
status->bssid[0] = '\0';
800+
status->band = WIFI_FREQ_BAND_2_4_GHZ;
801+
status->channel = 0;
802+
status->iface_mode = data->second_interface_init ? WIFI_MODE_AP : WIFI_MODE_INFRA;
803+
status->link_mode = WIFI_LINK_MODE_UNKNOWN;
804+
status->wpa3_ent_type = WIFI_WPA3_ENTERPRISE_NA;
805+
status->security = WIFI_SECURITY_TYPE_UNKNOWN;
806+
status->mfp = WIFI_MFP_DISABLE;
807+
status->rssi = 0;
808+
status->dtim_period = 0;
809+
status->beacon_interval = 0;
810+
811+
if (data->is_ap_up == false && data->is_sta_connected == false) {
812+
return 0;
813+
}
814+
815+
status->state = WIFI_STATE_COMPLETED;
816+
status->ssid_len = MIN(data->ssid.length, WIFI_SSID_MAX_LEN);
817+
memcpy(status->ssid, data->ssid.value, status->ssid_len);
818+
819+
whd_interface_t *if_ptr = data->is_sta_connected ? &airoc_sta_if : &airoc_ap_if;
820+
821+
whd_ret = whd_wifi_get_bssid(*if_ptr, &bssid);
822+
if (whd_ret == WHD_SUCCESS) {
823+
memcpy(status->bssid, bssid.octet, sizeof(bssid.octet));
824+
}
825+
826+
whd_ret = whd_wifi_get_channel(*if_ptr, &channel);
827+
if (whd_ret == WHD_SUCCESS) {
828+
status->channel = channel;
829+
if (channel <= 14) {
830+
status->band = WIFI_FREQ_BAND_2_4_GHZ;
831+
} else {
832+
status->band = WIFI_FREQ_BAND_5_GHZ;
833+
}
834+
}
835+
836+
status->iface_mode = data->is_ap_up ? WIFI_MODE_AP : WIFI_MODE_INFRA;
837+
838+
whd_ret = whd_wifi_get_rssi(*if_ptr, &rssi);
839+
if (whd_ret == WHD_SUCCESS) {
840+
status->rssi = rssi;
841+
}
842+
843+
whd_ret = whd_wifi_get_listen_interval(*if_ptr, &li);
844+
if (whd_ret == WHD_SUCCESS) {
845+
status->beacon_interval = li.beacon;
846+
status->dtim_period = li.dtim;
847+
}
848+
849+
return 0;
850+
}
851+
783852
static int airoc_mgmt_ap_disable(const struct device *dev)
784853
{
785854
cy_rslt_t whd_ret;
@@ -867,6 +936,7 @@ static const struct wifi_mgmt_ops airoc_wifi_mgmt = {
867936
#if defined(CONFIG_NET_STATISTICS_WIFI)
868937
.get_stats = airoc_mgmt_wifi_stats,
869938
#endif
939+
.iface_status = airoc_mgmt_wifi_status,
870940
};
871941

872942
static const struct net_wifi_mgmt_offload airoc_api = {

0 commit comments

Comments
 (0)