drivers: wifi: nxp: add split entity network for soft AP

Fix wifi connect and wifi ap start mix wifi network issue.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
This commit is contained in:
Fengming Ye 2024-09-06 15:50:07 +09:00 committed by Benjamin Cabé
commit b9d7ce7c1c

View file

@ -55,6 +55,9 @@ static struct k_event s_nxp_wifi_SyncEvent;
static struct nxp_wifi_dev nxp_wifi0; /* static instance */
static struct wlan_network nxp_wlan_network;
#ifdef CONFIG_NXP_WIFI_SOFTAP_SUPPORT
static struct wlan_network nxp_wlan_uap_network;
#endif
#ifndef CONFIG_WIFI_NM_HOSTAPD_AP
static char uap_ssid[IEEEtypes_SSID_SIZE + 1];
@ -278,18 +281,18 @@ int nxp_wifi_wlan_event_callback(enum wlan_event_reason reason, void *data)
LOG_DBG("Associated with Soft AP");
break;
case WLAN_REASON_UAP_CLIENT_CONN:
wlan_get_current_uap_network(&nxp_wlan_network);
wlan_get_current_uap_network(&nxp_wlan_uap_network);
#ifdef CONFIG_NXP_WIFI_11AX
if (nxp_wlan_network.dot11ax) {
if (nxp_wlan_uap_network.dot11ax) {
ap_sta_info.link_mode = WIFI_6;
} else
#endif
#ifdef CONFIG_NXP_WIFI_11AC
if (nxp_wlan_network.dot11ac) {
if (nxp_wlan_uap_network.dot11ac) {
ap_sta_info.link_mode = WIFI_5;
} else
#endif
if (nxp_wlan_network.dot11n) {
if (nxp_wlan_uap_network.dot11n) {
ap_sta_info.link_mode = WIFI_4;
} else {
ap_sta_info.link_mode = WIFI_3;
@ -443,7 +446,7 @@ static int nxp_wifi_start_ap(const struct device *dev, struct wifi_connect_req_p
int status = NXP_WIFI_RET_SUCCESS;
int ret;
struct interface *if_handle = (struct interface *)&g_uap;
struct ipv4_config *ap_addr4 = &nxp_wlan_network.ip.ipv4;
struct ipv4_config *ap_addr4 = &nxp_wlan_uap_network.ip.ipv4;
if (if_handle->state.interface != WLAN_BSS_TYPE_UAP) {
LOG_ERR("Wi-Fi not in uAP mode");
@ -461,48 +464,48 @@ static int nxp_wifi_start_ap(const struct device *dev, struct wifi_connect_req_p
}
if (status == NXP_WIFI_RET_SUCCESS) {
wlan_remove_network(nxp_wlan_network.name);
wlan_remove_network(nxp_wlan_uap_network.name);
wlan_initialize_uap_network(&nxp_wlan_network);
wlan_initialize_uap_network(&nxp_wlan_uap_network);
memcpy(nxp_wlan_network.name, NXP_WIFI_UAP_NETWORK_NAME,
memcpy(nxp_wlan_uap_network.name, NXP_WIFI_UAP_NETWORK_NAME,
strlen(NXP_WIFI_UAP_NETWORK_NAME));
memcpy(nxp_wlan_network.ssid, params->ssid, params->ssid_length);
memcpy(nxp_wlan_uap_network.ssid, params->ssid, params->ssid_length);
if (params->channel == WIFI_CHANNEL_ANY) {
nxp_wlan_network.channel = 0;
nxp_wlan_uap_network.channel = 0;
} else {
nxp_wlan_network.channel = params->channel;
nxp_wlan_uap_network.channel = params->channel;
}
if (params->mfp == WIFI_MFP_REQUIRED) {
nxp_wlan_network.security.mfpc = true;
nxp_wlan_network.security.mfpr = true;
nxp_wlan_uap_network.security.mfpc = true;
nxp_wlan_uap_network.security.mfpr = true;
} else if (params->mfp == WIFI_MFP_OPTIONAL) {
nxp_wlan_network.security.mfpc = true;
nxp_wlan_network.security.mfpr = false;
nxp_wlan_uap_network.security.mfpc = true;
nxp_wlan_uap_network.security.mfpr = false;
}
if (params->security == WIFI_SECURITY_TYPE_NONE) {
nxp_wlan_network.security.type = WLAN_SECURITY_NONE;
nxp_wlan_uap_network.security.type = WLAN_SECURITY_NONE;
} else if (params->security == WIFI_SECURITY_TYPE_PSK) {
nxp_wlan_network.security.type = WLAN_SECURITY_WPA2;
nxp_wlan_network.security.psk_len = params->psk_length;
strncpy(nxp_wlan_network.security.psk, params->psk, params->psk_length);
nxp_wlan_uap_network.security.type = WLAN_SECURITY_WPA2;
nxp_wlan_uap_network.security.psk_len = params->psk_length;
strncpy(nxp_wlan_uap_network.security.psk, params->psk, params->psk_length);
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT
else if (params->security == WIFI_SECURITY_TYPE_PSK_SHA256) {
nxp_wlan_network.security.type = WLAN_SECURITY_WPA2;
nxp_wlan_network.security.key_mgmt |= WLAN_KEY_MGMT_PSK_SHA256;
nxp_wlan_network.security.psk_len = params->psk_length;
strncpy(nxp_wlan_network.security.psk, params->psk, params->psk_length);
nxp_wlan_uap_network.security.type = WLAN_SECURITY_WPA2;
nxp_wlan_uap_network.security.key_mgmt |= WLAN_KEY_MGMT_PSK_SHA256;
nxp_wlan_uap_network.security.psk_len = params->psk_length;
strncpy(nxp_wlan_uap_network.security.psk, params->psk, params->psk_length);
}
#endif
else if (params->security == WIFI_SECURITY_TYPE_SAE) {
nxp_wlan_network.security.type = WLAN_SECURITY_WPA3_SAE;
nxp_wlan_network.security.password_len = params->psk_length;
strncpy(nxp_wlan_network.security.password, params->psk,
nxp_wlan_uap_network.security.type = WLAN_SECURITY_WPA3_SAE;
nxp_wlan_uap_network.security.password_len = params->psk_length;
strncpy(nxp_wlan_uap_network.security.password, params->psk,
params->psk_length);
} else {
status = NXP_WIFI_RET_BAD_PARAM;
@ -529,14 +532,14 @@ static int nxp_wifi_start_ap(const struct device *dev, struct wifi_connect_req_p
return -ENOENT;
}
ret = wlan_add_network(&nxp_wlan_network);
ret = wlan_add_network(&nxp_wlan_uap_network);
if (ret != WM_SUCCESS) {
status = NXP_WIFI_RET_FAIL;
}
ret = wlan_start_network(nxp_wlan_network.name);
ret = wlan_start_network(nxp_wlan_uap_network.name);
if (ret != WM_SUCCESS) {
wlan_remove_network(nxp_wlan_network.name);
wlan_remove_network(nxp_wlan_uap_network.name);
status = NXP_WIFI_RET_FAIL;
}
@ -988,20 +991,20 @@ static int nxp_wifi_uap_status(const struct device *dev, struct wifi_iface_statu
if (connection_state == WLAN_UAP_STARTED) {
if (!wlan_get_current_uap_network(&nxp_wlan_network)) {
strncpy(status->ssid, nxp_wlan_network.ssid, WIFI_SSID_MAX_LEN);
if (!wlan_get_current_uap_network(&nxp_wlan_uap_network)) {
strncpy(status->ssid, nxp_wlan_uap_network.ssid, WIFI_SSID_MAX_LEN);
status->ssid[WIFI_SSID_MAX_LEN - 1] = 0;
status->ssid_len = strlen(status->ssid);
memcpy(status->bssid, nxp_wlan_network.bssid, WIFI_MAC_ADDR_LEN);
memcpy(status->bssid, nxp_wlan_uap_network.bssid, WIFI_MAC_ADDR_LEN);
status->rssi = nxp_wlan_network.rssi;
status->rssi = nxp_wlan_uap_network.rssi;
status->channel = nxp_wlan_network.channel;
status->channel = nxp_wlan_uap_network.channel;
status->beacon_interval = nxp_wlan_network.beacon_period;
status->beacon_interval = nxp_wlan_uap_network.beacon_period;
status->dtim_period = nxp_wlan_network.dtim_period;
status->dtim_period = nxp_wlan_uap_network.dtim_period;
if (if_handle->state.interface == WLAN_BSS_TYPE_STA) {
status->iface_mode = WIFI_MODE_INFRA;
@ -1010,26 +1013,30 @@ static int nxp_wifi_uap_status(const struct device *dev, struct wifi_iface_statu
}
#ifdef CONFIG_NXP_WIFI_11AX
if (nxp_wlan_network.dot11ax) {
if (nxp_wlan_uap_network.dot11ax) {
status->link_mode = WIFI_6;
}
#endif
#ifdef CONFIG_NXP_WIFI_11AC
else if (nxp_wlan_network.dot11ac) {
else if (nxp_wlan_uap_network.dot11ac) {
status->link_mode = WIFI_5;
}
#endif
else if (nxp_wlan_network.dot11n) {
else if (nxp_wlan_uap_network.dot11n) {
status->link_mode = WIFI_4;
} else {
status->link_mode = WIFI_3;
}
status->band = nxp_wlan_network.channel > 14 ? WIFI_FREQ_BAND_5_GHZ
: WIFI_FREQ_BAND_2_4_GHZ;
status->security = nxp_wifi_security_type(nxp_wlan_network.security.type);
status->mfp = nxp_wlan_network.security.mfpr ? WIFI_MFP_REQUIRED :
(nxp_wlan_network.security.mfpc ? WIFI_MFP_OPTIONAL : 0);
status->band = nxp_wlan_uap_network.channel > 14 ? WIFI_FREQ_BAND_5_GHZ
: WIFI_FREQ_BAND_2_4_GHZ;
status->security =
nxp_wifi_security_type(nxp_wlan_uap_network.security.type);
status->mfp =
nxp_wlan_uap_network.security.mfpr
? WIFI_MFP_REQUIRED
: (nxp_wlan_uap_network.security.mfpc ? WIFI_MFP_OPTIONAL
: 0);
}
}