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
@@ -25,7 +26,7 @@ LOG_MODULE_REGISTER(infineon_airoc_wifi, CONFIG_WIFI_LOG_LEVEL);
25
26
#endif
26
27
27
28
#ifndef AIROC_WIFI_PACKET_POOL_SIZE
28
- #define AIROC_WIFI_PACKET_POOL_SIZE (1600)
29
+ #define AIROC_WIFI_PACKET_POOL_SIZE (1600)
29
30
#endif
30
31
31
32
#define AIROC_WIFI_PACKET_POOL_COUNT \
@@ -49,8 +50,8 @@ int airoc_wifi_init_primary(const struct device *dev, whd_interface_t *interface
49
50
whd_netif_funcs_t * netif_funcs , whd_buffer_funcs_t * buffer_if );
50
51
51
52
/* 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 );
54
55
55
56
/* AIROC globals */
56
57
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_
236
237
* buffer = buf ;
237
238
238
239
/* Set buffer size */
239
- (void ) airoc_wifi_buffer_set_size (* buffer , size );
240
+ (void )airoc_wifi_buffer_set_size (* buffer , size );
240
241
241
242
return WHD_SUCCESS ;
242
243
}
@@ -302,7 +303,7 @@ static int airoc_mgmt_send(const struct device *dev, struct net_pkt *pkt)
302
303
}
303
304
304
305
/* 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 ,
306
307
pkt_len + sizeof (data_header_t ), 0 );
307
308
if ((ret != WHD_SUCCESS ) || (buf == NULL )) {
308
309
return - EIO ;
@@ -381,8 +382,7 @@ static enum ethernet_hw_caps airoc_get_capabilities(const struct device *dev)
381
382
return ETHERNET_HW_FILTERING ;
382
383
}
383
384
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 ,
386
386
const struct ethernet_config * config )
387
387
{
388
388
ARG_UNUSED (dev );
@@ -602,10 +602,8 @@ static void *airoc_wifi_ap_link_events_handler(whd_interface_t ifp,
602
602
const whd_event_header_t * event_header ,
603
603
const uint8_t * event_data , void * handler_user_data )
604
604
{
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 };
609
607
610
608
k_msgq_put (& airoc_wifi_msgq , & airoc_event , K_FOREVER );
611
609
@@ -658,8 +656,7 @@ static int airoc_mgmt_ap_enable(const struct device *dev, struct wifi_connect_re
658
656
channel = params -> channel ;
659
657
} else {
660
658
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 );
663
660
}
664
661
665
662
switch (params -> security ) {
@@ -760,6 +757,80 @@ static int airoc_mgmt_ap_disable(const struct device *dev)
760
757
return 0 ;
761
758
}
762
759
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
+
763
834
static int airoc_init (const struct device * dev )
764
835
{
765
836
int ret ;
@@ -785,8 +856,8 @@ static int airoc_init(const struct device *dev)
785
856
}
786
857
airoc_if = airoc_sta_if ;
787
858
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 );
790
861
if (whd_ret != CY_RSLT_SUCCESS ) {
791
862
LOG_ERR ("whd_management_set_event_handler failed ret = %d \r\n" , whd_ret );
792
863
return - EAGAIN ;
@@ -813,6 +884,7 @@ static const struct wifi_mgmt_ops airoc_wifi_mgmt = {
813
884
.disconnect = airoc_mgmt_disconnect ,
814
885
.ap_enable = airoc_mgmt_ap_enable ,
815
886
.ap_disable = airoc_mgmt_ap_disable ,
887
+ .iface_status = airoc_iface_status ,
816
888
#if defined(CONFIG_NET_STATISTICS_WIFI )
817
889
.get_stats = airoc_mgmt_wifi_stats ,
818
890
#endif
0 commit comments