@@ -773,6 +773,13 @@ static int esp32_wifi_status(const struct device *dev, struct wifi_iface_status
773
773
status -> mfp = WIFI_MFP_DISABLE ;
774
774
775
775
if (esp_wifi_get_mode (& mode ) == ESP_OK ) {
776
+ #if defined(CONFIG_ESP32_WIFI_AP_STA_MODE )
777
+ if (mode == ESP32_WIFI_MODE_APSTA && data == & esp32_data ) {
778
+ mode = ESP32_WIFI_MODE_STA ;
779
+ } else if (mode == ESP32_WIFI_MODE_APSTA && data == & esp32_ap_sta_data ) {
780
+ mode = ESP32_WIFI_MODE_AP ;
781
+ }
782
+ #endif
776
783
if (mode == ESP32_WIFI_MODE_STA ) {
777
784
wifi_phy_mode_t phy_mode ;
778
785
esp_err_t err ;
@@ -842,21 +849,14 @@ static void esp32_wifi_init(struct net_if *iface)
842
849
#if defined(CONFIG_ESP32_WIFI_AP_STA_MODE )
843
850
struct wifi_nm_instance * nm = wifi_nm_get_instance ("esp32_wifi_nm" );
844
851
845
- if (!esp32_wifi_iface_ap ) {
846
- esp32_wifi_iface_ap = iface ;
847
- dev_data -> state = ESP32_AP_STOPPED ;
852
+ esp32_wifi_iface = iface ;
853
+ dev_data -> state = ESP32_STA_STOPPED ;
848
854
849
- esp_read_mac (dev_data -> mac_addr , ESP_MAC_WIFI_SOFTAP );
850
- wifi_nm_register_mgd_type_iface (nm , WIFI_TYPE_SAP , esp32_wifi_iface_ap );
851
- } else {
852
- esp32_wifi_iface = iface ;
853
- dev_data -> state = ESP32_STA_STOPPED ;
855
+ /* Start interface when we are actually connected with Wi-Fi network */
856
+ esp_read_mac (dev_data -> mac_addr , ESP_MAC_WIFI_STA );
857
+ esp_wifi_internal_reg_rxcb (ESP_IF_WIFI_STA , eth_esp32_rx );
858
+ wifi_nm_register_mgd_type_iface (nm , WIFI_TYPE_STA , esp32_wifi_iface );
854
859
855
- /* Start interface when we are actually connected with Wi-Fi network */
856
- esp_read_mac (dev_data -> mac_addr , ESP_MAC_WIFI_STA );
857
- esp_wifi_internal_reg_rxcb (ESP_IF_WIFI_STA , eth_esp32_rx );
858
- wifi_nm_register_mgd_type_iface (nm , WIFI_TYPE_STA , esp32_wifi_iface );
859
- }
860
860
#else
861
861
862
862
esp32_wifi_iface = iface ;
@@ -875,6 +875,31 @@ static void esp32_wifi_init(struct net_if *iface)
875
875
net_if_carrier_off (iface );
876
876
}
877
877
878
+ #if defined(CONFIG_ESP32_WIFI_AP_STA_MODE )
879
+ static void esp32_wifi_init_ap (struct net_if * iface )
880
+ {
881
+ const struct device * dev = net_if_get_device (iface );
882
+ struct esp32_wifi_runtime * dev_data = dev -> data ;
883
+ struct ethernet_context * eth_ctx = net_if_l2_data (iface );
884
+
885
+ eth_ctx -> eth_if_type = L2_ETH_IF_TYPE_WIFI ;
886
+
887
+ struct wifi_nm_instance * nm = wifi_nm_get_instance ("esp32_wifi_nm" );
888
+
889
+ esp32_wifi_iface_ap = iface ;
890
+ dev_data -> state = ESP32_AP_STOPPED ;
891
+
892
+ esp_read_mac (dev_data -> mac_addr , ESP_MAC_WIFI_SOFTAP );
893
+ wifi_nm_register_mgd_type_iface (nm , WIFI_TYPE_SAP , esp32_wifi_iface_ap );
894
+
895
+ /* Assign link local address. */
896
+ net_if_set_link_addr (iface , dev_data -> mac_addr , 6 , NET_LINK_ETHERNET );
897
+
898
+ ethernet_init (iface );
899
+ net_if_carrier_off (iface );
900
+ }
901
+ #endif
902
+
878
903
#if defined(CONFIG_NET_STATISTICS_WIFI )
879
904
static int esp32_wifi_stats (const struct device * dev , struct net_stats_wifi * stats )
880
905
{
@@ -905,6 +930,7 @@ static int esp32_wifi_dev_init(const struct device *dev)
905
930
906
931
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT ();
907
932
esp_err_t ret = esp_wifi_init (& config );
933
+ esp_wifi_set_mode (ESP32_WIFI_MODE_NULL );
908
934
909
935
if (ret == ESP_ERR_NO_MEM ) {
910
936
LOG_ERR ("Not enough memory to initialize Wi-Fi." );
@@ -939,6 +965,13 @@ static const struct net_wifi_mgmt_offload esp32_api = {
939
965
.wifi_iface .send = esp32_wifi_send ,
940
966
.wifi_mgmt_api = & esp32_wifi_mgmt ,
941
967
};
968
+ #if defined(CONFIG_ESP32_WIFI_AP_STA_MODE )
969
+ static const struct net_wifi_mgmt_offload esp32_api_ap = {
970
+ .wifi_iface .iface_api .init = esp32_wifi_init_ap ,
971
+ .wifi_iface .send = esp32_wifi_send ,
972
+ .wifi_mgmt_api = & esp32_wifi_mgmt ,
973
+ };
974
+ #endif
942
975
943
976
NET_DEVICE_DT_INST_DEFINE (0 ,
944
977
esp32_wifi_dev_init , NULL ,
@@ -950,7 +983,7 @@ NET_DEVICE_DT_INST_DEFINE(0,
950
983
NET_DEVICE_DT_INST_DEFINE (1 ,
951
984
NULL , NULL ,
952
985
& esp32_ap_sta_data , NULL , CONFIG_WIFI_INIT_PRIORITY ,
953
- & esp32_api , ETHERNET_L2 ,
986
+ & esp32_api_ap , ETHERNET_L2 ,
954
987
NET_L2_GET_CTX_TYPE (ETHERNET_L2 ), NET_ETH_MTU );
955
988
956
989
DEFINE_WIFI_NM_INSTANCE (esp32_wifi_nm , & esp32_wifi_mgmt );
0 commit comments