[beken-72xx] Allow connecting to specific BSSID if provided (#209)
* Switch to bk_wlan_start_sta_adv for specific bssid control. * Allow split sta/adv_sta configs. * Add wifi_mode back for regular STA mode. * Fix apparent bug of setting null/empty wifi key. Reset STA_ADV_CFG.dhcp_mode in reconnect, as it seems to not survive for some reason. Do les _CFG setting in reconnect() * Move all _CFG setting to begin() * Fix dhcp_mode in STA_ADV_CFG. * Remove no longer necessary dhcp_mode re-set. * Formatting cleanups. * Formatting. * Update cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp * Apply suggestions from code review --------- Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
This commit is contained in:
@@ -5,8 +5,9 @@
|
||||
WiFiClass::WiFiClass() {
|
||||
data = (WiFiData *)calloc(1, sizeof(WiFiData));
|
||||
|
||||
DATA->scanSem = xSemaphoreCreateBinary();
|
||||
STA_CFG.dhcp_mode = DHCP_CLIENT;
|
||||
DATA->scanSem = xSemaphoreCreateBinary();
|
||||
STA_CFG.dhcp_mode = DHCP_CLIENT;
|
||||
STA_ADV_CFG.dhcp_mode = DHCP_CLIENT;
|
||||
}
|
||||
|
||||
WiFiClass::~WiFiClass() {
|
||||
|
||||
@@ -57,6 +57,7 @@ extern void wifiEventHandler(rw_evt_type event);
|
||||
|
||||
typedef struct {
|
||||
network_InitTypeDef_st configSta;
|
||||
network_InitTypeDef_adv_st configStaAdv;
|
||||
network_InitTypeDef_ap_st configAp;
|
||||
unsigned long scannedAt;
|
||||
SemaphoreHandle_t scanSem;
|
||||
@@ -73,6 +74,7 @@ typedef struct {
|
||||
#define cDATA ((WiFiData *)cls->data)
|
||||
|
||||
#define STA_CFG (DATA->configSta)
|
||||
#define STA_ADV_CFG (DATA->configStaAdv)
|
||||
#define AP_CFG (DATA->configAp)
|
||||
#define IP_STATUS (DATA->statusIp)
|
||||
#define LINK_STATUS (DATA->statusLink)
|
||||
|
||||
@@ -13,11 +13,26 @@ WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, cons
|
||||
|
||||
disconnect(false);
|
||||
|
||||
strcpy(STA_CFG.wifi_ssid, ssid);
|
||||
if (passphrase) {
|
||||
strcpy(STA_CFG.wifi_key, passphrase);
|
||||
if (bssid) {
|
||||
strcpy(STA_ADV_CFG.ap_info.ssid, ssid);
|
||||
if (passphrase) {
|
||||
strcpy(STA_ADV_CFG.key, passphrase);
|
||||
STA_ADV_CFG.key_len = strlen(passphrase);
|
||||
} else {
|
||||
STA_ADV_CFG.key[0] = '\0';
|
||||
STA_ADV_CFG.key_len = 0;
|
||||
}
|
||||
STA_ADV_CFG.ap_info.channel = channel;
|
||||
STA_ADV_CFG.wifi_retry_interval = 100;
|
||||
} else {
|
||||
STA_CFG.wifi_bssid[0] = '\0';
|
||||
strcpy(STA_CFG.wifi_ssid, ssid);
|
||||
if (passphrase) {
|
||||
strcpy(STA_CFG.wifi_key, passphrase);
|
||||
} else {
|
||||
STA_CFG.wifi_key[0] = '\0';
|
||||
}
|
||||
STA_CFG.wifi_retry_interval = 100;
|
||||
STA_CFG.wifi_mode = BK_STATION;
|
||||
}
|
||||
|
||||
if (reconnect(bssid))
|
||||
@@ -27,21 +42,31 @@ WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, cons
|
||||
}
|
||||
|
||||
bool WiFiClass::config(IPAddress localIP, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) {
|
||||
STA_CFG.dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT;
|
||||
STA_CFG.dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT;
|
||||
STA_ADV_CFG.dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT;
|
||||
if (localIP) {
|
||||
sprintf(STA_CFG.local_ip_addr, IP_FMT, localIP[0], localIP[1], localIP[2], localIP[3]);
|
||||
sprintf(STA_CFG.net_mask, IP_FMT, subnet[0], subnet[1], subnet[2], subnet[3]);
|
||||
sprintf(STA_CFG.gateway_ip_addr, IP_FMT, gateway[0], gateway[1], gateway[2], gateway[3]);
|
||||
sprintf(STA_ADV_CFG.local_ip_addr, IP_FMT, localIP[0], localIP[1], localIP[2], localIP[3]);
|
||||
sprintf(STA_ADV_CFG.net_mask, IP_FMT, subnet[0], subnet[1], subnet[2], subnet[3]);
|
||||
sprintf(STA_ADV_CFG.gateway_ip_addr, IP_FMT, gateway[0], gateway[1], gateway[2], gateway[3]);
|
||||
if (dns1) {
|
||||
sprintf(STA_CFG.dns_server_ip_addr, IP_FMT, dns1[0], dns1[1], dns1[2], dns1[3]);
|
||||
sprintf(STA_ADV_CFG.dns_server_ip_addr, IP_FMT, dns1[0], dns1[1], dns1[2], dns1[3]);
|
||||
} else {
|
||||
STA_CFG.dns_server_ip_addr[0] = '\0';
|
||||
STA_CFG.dns_server_ip_addr[0] = '\0';
|
||||
STA_ADV_CFG.dns_server_ip_addr[0] = '\0';
|
||||
}
|
||||
} else {
|
||||
STA_CFG.local_ip_addr[0] = '\0';
|
||||
STA_CFG.net_mask[0] = '\0';
|
||||
STA_CFG.gateway_ip_addr[0] = '\0';
|
||||
STA_CFG.dns_server_ip_addr[0] = '\0';
|
||||
STA_CFG.local_ip_addr[0] = '\0';
|
||||
STA_CFG.net_mask[0] = '\0';
|
||||
STA_CFG.gateway_ip_addr[0] = '\0';
|
||||
STA_CFG.dns_server_ip_addr[0] = '\0';
|
||||
STA_ADV_CFG.local_ip_addr[0] = '\0';
|
||||
STA_ADV_CFG.net_mask[0] = '\0';
|
||||
STA_ADV_CFG.gateway_ip_addr[0] = '\0';
|
||||
STA_ADV_CFG.dns_server_ip_addr[0] = '\0';
|
||||
}
|
||||
|
||||
// from wlan_ui.c:1370
|
||||
@@ -74,10 +99,8 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
|
||||
LT_DM(WIFI, "Data = %p", DATA->configSta);
|
||||
|
||||
STA_CFG.wifi_mode = BK_STATION;
|
||||
STA_CFG.wifi_retry_interval = 100;
|
||||
if (bssid)
|
||||
memcpy(STA_CFG.wifi_bssid, bssid, 6);
|
||||
memcpy(STA_ADV_CFG.ap_info.bssid, bssid, 6);
|
||||
else
|
||||
memset(STA_CFG.wifi_bssid, 0x00, 6);
|
||||
|
||||
@@ -91,7 +114,11 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
LT_DM(WIFI, "Starting WiFi...");
|
||||
|
||||
__wrap_bk_printf_disable();
|
||||
bk_wlan_start_sta(&STA_CFG);
|
||||
if (bssid) {
|
||||
bk_wlan_start_sta_adv(&STA_ADV_CFG);
|
||||
} else {
|
||||
bk_wlan_start_sta(&STA_CFG);
|
||||
}
|
||||
__wrap_bk_printf_enable();
|
||||
|
||||
LT_DM(WIFI, "Start OK");
|
||||
|
||||
Reference in New Issue
Block a user