[realtek-ambz2] Adapt WiFi library to ambz2_sdk
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
#include "WiFi.h"
|
||||
|
||||
void WiFiClass::printDiag(Print &dest) {
|
||||
const char *modes[] = {"NULL", "STA", "AP", "STA+AP"};
|
||||
const char *enc[] = {"Open", "WEP", "WPA PSK", "WPA2 PSK", "WPA/WPA2", "WPA", "WPA2"};
|
||||
|
||||
dest.print("Mode: ");
|
||||
dest.println(modes[getMode()]);
|
||||
dest.println(WiFiModeText[getMode()]);
|
||||
|
||||
dest.print("Status: ");
|
||||
dest.println(WiFiStatusText[status()]);
|
||||
|
||||
if (getMode() & WIFI_MODE_STA) {
|
||||
dest.println("-- Station --");
|
||||
@@ -21,7 +21,7 @@ void WiFiClass::printDiag(Print &dest) {
|
||||
dest.print("RSSI: ");
|
||||
dest.println(RSSI());
|
||||
dest.print("Encryption: ");
|
||||
dest.println(enc[getEncryption()]);
|
||||
dest.println(WiFiAuthModeText[getEncryption()]);
|
||||
dest.print("IP: ");
|
||||
dest.println(localIP());
|
||||
dest.print("MAC: ");
|
||||
|
||||
@@ -11,7 +11,7 @@ bool WiFiClass::mode(WiFiMode mode) {
|
||||
pWiFi = this;
|
||||
|
||||
WiFiMode currentMode = getMode();
|
||||
LT_DM(WIFI, "Mode changing %u -> %u", currentMode, mode);
|
||||
LT_DM(WIFI, "Mode changing %s -> %s", WiFiModeText[currentMode], WiFiModeText[mode]);
|
||||
if (mode == currentMode)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -162,3 +162,28 @@ typedef enum {
|
||||
WLMODE_DISABLE = 1,
|
||||
WLMODE_ENABLE = 2,
|
||||
} WiFiModeAction;
|
||||
|
||||
static const char *WiFiModeText[] = {"NULL", "STA", "AP", "AP+STA"};
|
||||
static const char *WiFiStatusText[] = {
|
||||
"Idle",
|
||||
"No SSID",
|
||||
"Scan Completed",
|
||||
"Connected",
|
||||
"Connect failed",
|
||||
"Connection lost",
|
||||
"Disconnected",
|
||||
};
|
||||
static const char *WiFiAuthModeText[] = {
|
||||
"Open",
|
||||
"WEP",
|
||||
"WPA PSK",
|
||||
"WPA2 PSK",
|
||||
"WPA/WPA2 PSK",
|
||||
"WPA2 EAP",
|
||||
"WPA3 PSK",
|
||||
"WPA2/WPA3 PSK",
|
||||
"WAPI PSK",
|
||||
"WPA",
|
||||
"WPA2",
|
||||
"Auto",
|
||||
};
|
||||
|
||||
@@ -72,11 +72,11 @@ uint8_t LwIPUDP::begin(IPAddress address, uint16_t port) {
|
||||
}
|
||||
|
||||
uint8_t LwIPUDP::begin(uint16_t p) {
|
||||
return begin(IPAddress(INADDR_ANY), p);
|
||||
return begin(IPAddress((uint32_t)INADDR_ANY), p);
|
||||
}
|
||||
|
||||
uint8_t LwIPUDP::beginMulticast(IPAddress a, uint16_t p) {
|
||||
if (begin(IPAddress(INADDR_ANY), p)) {
|
||||
if (begin(IPAddress((uint32_t)INADDR_ANY), p)) {
|
||||
if ((uint32_t)a != 0) {
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = (in_addr_t)a;
|
||||
@@ -111,14 +111,14 @@ void LwIPUDP::stop() {
|
||||
mreq.imr_multiaddr.s_addr = (in_addr_t)multicast_ip;
|
||||
mreq.imr_interface.s_addr = (in_addr_t)0;
|
||||
setsockopt(udp_server, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
|
||||
multicast_ip = IPAddress(INADDR_ANY);
|
||||
multicast_ip = IPAddress((uint32_t)INADDR_ANY);
|
||||
}
|
||||
close(udp_server);
|
||||
udp_server = -1;
|
||||
}
|
||||
|
||||
int LwIPUDP::beginMulticastPacket() {
|
||||
if (!server_port || multicast_ip == IPAddress(INADDR_ANY))
|
||||
if (!server_port || multicast_ip == IPAddress((uint32_t)INADDR_ANY))
|
||||
return 0;
|
||||
remote_ip = multicast_ip;
|
||||
remote_port = server_port;
|
||||
|
||||
@@ -13,6 +13,11 @@ extern "C" {
|
||||
#include <lwip/netif.h>
|
||||
}
|
||||
|
||||
#if LWIP_VERSION_SIMPLE < 20100 && defined(LWIP_NETIF_EXT_STATUS_CALLBACK)
|
||||
#warning "LWIP_NETIF_EXT_STATUS_CALLBACK not available before lwIP 2.1.0"
|
||||
#undef LWIP_NETIF_EXT_STATUS_CALLBACK
|
||||
#endif
|
||||
|
||||
#if LWIP_MDNS_RESPONDER
|
||||
|
||||
static std::vector<char *> services_name;
|
||||
|
||||
@@ -68,7 +68,6 @@ void wifi_unreg_event_handler(unsigned int event_cmds, rtw_event_handler_t handl
|
||||
|
||||
// function called by wext_wlan_indicate
|
||||
void wifi_indication(rtw_event_indicate_t event, char *buf, int buf_len, int flags) {
|
||||
LT_HEAP_I();
|
||||
if (event >= WIFI_EVENT_MAX)
|
||||
return;
|
||||
if (wifiEventQueueHandle && wifiEventTaskHandle) {
|
||||
|
||||
@@ -9,8 +9,7 @@ int32_t WiFiClass::channel() {
|
||||
}
|
||||
|
||||
bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
|
||||
__wrap_rtl_printf_disable();
|
||||
__wrap_DiagPrintf_disable();
|
||||
DIAG_PRINTF_DISABLE();
|
||||
startWifiTask();
|
||||
|
||||
if (!DATA->initialized) {
|
||||
@@ -102,7 +101,11 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
|
||||
LT_DM(WIFI, "Mode: %s DISABLE", WLAN1_NAME);
|
||||
netif_set_link_down(WLAN1_NETIF);
|
||||
netif_set_down(WLAN1_NETIF);
|
||||
#if !LT_RTL8720C
|
||||
rltk_stop_softap(WLAN1_NAME);
|
||||
#else
|
||||
rltk_suspend_softap(WLAN1_NAME);
|
||||
#endif
|
||||
rltk_wlan_init(WLAN1_IDX, RTW_MODE_NONE);
|
||||
wext_set_mode(WLAN1_NAME, IW_MODE_INFRA);
|
||||
}
|
||||
@@ -152,13 +155,11 @@ bool WiFiClass::modePriv(WiFiMode mode, WiFiModeAction sta, WiFiModeAction ap) {
|
||||
}
|
||||
|
||||
LT_HEAP_I();
|
||||
__wrap_rtl_printf_enable();
|
||||
__wrap_DiagPrintf_enable();
|
||||
DIAG_PRINTF_ENABLE();
|
||||
return true;
|
||||
|
||||
error:
|
||||
__wrap_rtl_printf_enable();
|
||||
__wrap_DiagPrintf_enable();
|
||||
DIAG_PRINTF_ENABLE();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,9 @@ extern void dns_server_init(struct netif *pnetif);
|
||||
extern void dns_server_deinit(void);
|
||||
|
||||
// wifi_util.c
|
||||
#if !LT_RTL8720C
|
||||
extern void rltk_stop_softap(const char *ifname);
|
||||
#endif
|
||||
extern void rltk_suspend_softap(const char *ifname);
|
||||
extern void rltk_suspend_softap_beacon(const char *ifname);
|
||||
|
||||
@@ -65,3 +67,33 @@ typedef struct {
|
||||
#define DATA ((WiFiData *)data)
|
||||
#define pDATA ((WiFiData *)pWiFi->data)
|
||||
#define cDATA ((WiFiData *)cls->data)
|
||||
|
||||
#if LT_RTL8710B // Realtek AmebaZ
|
||||
#define DIAG_PRINTF_ENABLE() \
|
||||
do { \
|
||||
__wrap_rtl_printf_enable(); \
|
||||
__wrap_DiagPrintf_enable(); \
|
||||
} while (0);
|
||||
#define DIAG_PRINTF_DISABLE() \
|
||||
do { \
|
||||
__wrap_rtl_printf_disable(); \
|
||||
__wrap_DiagPrintf_disable(); \
|
||||
} while (0);
|
||||
|
||||
#elif LT_RTL8720C // Realtek AmebaZ2
|
||||
#define DIAG_PRINTF_ENABLE() \
|
||||
do { \
|
||||
__wrap_rt_printf_enable(); \
|
||||
__wrap_rt_log_printf_enable(); \
|
||||
} while (0);
|
||||
#define DIAG_PRINTF_DISABLE() \
|
||||
do { \
|
||||
__wrap_rt_printf_disable(); \
|
||||
__wrap_rt_log_printf_disable(); \
|
||||
} while (0);
|
||||
|
||||
#else
|
||||
#define DIAG_PRINTF_ENABLE()
|
||||
#define DIAG_PRINTF_DISABLE()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -67,8 +67,7 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
WiFiNetworkInfo &info = DATA->sta;
|
||||
|
||||
LT_IM(WIFI, "Connecting to %s (bssid=%p)", info.ssid, bssid);
|
||||
__wrap_rtl_printf_disable();
|
||||
__wrap_DiagPrintf_disable();
|
||||
DIAG_PRINTF_DISABLE();
|
||||
|
||||
wext_set_ssid(WLAN0_NAME, (uint8_t *)"-", 1);
|
||||
|
||||
@@ -116,8 +115,7 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
wifi_indication(WIFI_EVENT_CONNECT, (char *)eventInfo, ARDUINO_EVENT_WIFI_STA_GOT_IP, -2);
|
||||
// free memory as wifi_indication creates a copy
|
||||
free(eventInfo);
|
||||
__wrap_rtl_printf_enable();
|
||||
__wrap_DiagPrintf_enable();
|
||||
DIAG_PRINTF_ENABLE();
|
||||
return true;
|
||||
}
|
||||
LT_EM(WIFI, "DHCP failed; dhcpRet=%d", dhcpRet);
|
||||
@@ -126,8 +124,7 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
}
|
||||
LT_EM(WIFI, "Connection failed; ret=%d", ret);
|
||||
error:
|
||||
__wrap_rtl_printf_enable();
|
||||
__wrap_DiagPrintf_enable();
|
||||
DIAG_PRINTF_ENABLE();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,3 +12,16 @@
|
||||
#ifndef INT_MAX
|
||||
#define INT_MAX 2147483647 // for RECV_BUFSIZE_DEFAULT
|
||||
#endif
|
||||
|
||||
// - 2022-05-23 set LWIP_NUM_NETIF_CLIENT_DATA to 1
|
||||
#define LWIP_NUM_NETIF_CLIENT_DATA 1
|
||||
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
|
||||
// - 2022-05-23 set MEMP_NUM_UDP_PCB to 7
|
||||
#undef MEMP_NUM_UDP_PCB
|
||||
#define MEMP_NUM_UDP_PCB 7
|
||||
|
||||
// LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define
|
||||
// LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)
|
||||
#define LWIP_COMPAT_MUTEX_ALLOWED 1
|
||||
|
||||
#define LWIP_TCPIP_TIMEOUT 1
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-02. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include_next "lwipopts.h"
|
||||
|
||||
// - 2022-05-23 set LWIP_NUM_NETIF_CLIENT_DATA to 1
|
||||
#define LWIP_NUM_NETIF_CLIENT_DATA 1
|
||||
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
|
||||
// - 2022-05-23 set MEMP_NUM_UDP_PCB to 7
|
||||
#undef MEMP_NUM_UDP_PCB
|
||||
#define MEMP_NUM_UDP_PCB 7
|
||||
|
||||
// LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define
|
||||
// LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)
|
||||
#define LWIP_COMPAT_MUTEX_ALLOWED 1
|
||||
|
||||
#define LWIP_TCPIP_TIMEOUT 1
|
||||
@@ -3,5 +3,6 @@
|
||||
#error "Don't include this file directly"
|
||||
|
||||
#define LT_ARD_HAS_SERIAL 1
|
||||
#define LT_ARD_HAS_WIFI 1
|
||||
|
||||
#define LT_ARD_MD5_MBEDTLS 1
|
||||
|
||||
9
cores/realtek-ambz2/base/config/platform_opts.h
Normal file
9
cores/realtek-ambz2/base/config/platform_opts.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-05-25. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include_next "platform_opts.h"
|
||||
|
||||
// this needs example_wlan_fast_connect.c
|
||||
#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
#undef CONFIG_FAST_DHCP
|
||||
Reference in New Issue
Block a user