Skip to content

Commit

Permalink
static rtl (#1492)
Browse files Browse the repository at this point in the history
* Update hal_wifi_rtl87x0c.c

* Update hal_wifi_rtl87x0c.c

* test

* fx

* test
  • Loading branch information
openshwprojects authored Jan 5, 2025
1 parent 9b84004 commit 6eb8162
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cmnds/cmd_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static int tok_flags = 0;
#define g_bAllowExpand (!(tok_flags&TOKENIZER_DONT_EXPAND))

int str_to_ip(const char *s, byte *ip) {
#if PLATFORM_W600 || PLATFORM_LN882H
#if PLATFORM_W600 || PLATFORM_LN882H || PLATFORM_RTL87X0C
//seems like sscanf in W600 does not support %hhu and uses it as %u, thus overwriting more memory, use temp array for it
// same for LN882h: %hhu isn't recognised, so we have to use %u for IP_STRING_FORMAT, which will lead to problems in sscanf, too
int tmp_ip[4];
Expand Down
24 changes: 23 additions & 1 deletion src/hal/rtl87x0c/hal_wifi_rtl87x0c.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static int g_bOpenAccessPointMode = 0;
static wifi_data_t wdata = { 0 };
extern uint8_t wmac[6];
extern bool g_powersave;
static int g_bStaticIP = 0;

const char* HAL_GetMyIPString()
{
Expand Down Expand Up @@ -228,19 +229,40 @@ void ConnectToWiFiTask(void* args)
printf("ERROR: Can't connect to AP\r\n");
goto exit;
}
LwIP_DHCP(0, DHCP_START);
if(g_bStaticIP == 0) {
LwIP_DHCP(0, DHCP_START);
}
if(wifi_is_up(RTW_STA_INTERFACE) && g_powersave) wifi_enable_powersave();
exit:
vTaskDelete(NULL);
}

void HAL_ConnectToWiFi(const char* oob_ssid, const char* connect_key, obkStaticIP_t* ip)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;
g_bOpenAccessPointMode = 0;
strcpy((char*)&wdata.ssid, oob_ssid);
strcpy((char*)&wdata.pwd, connect_key);
wifi_set_autoreconnect(0);



if (ip->localIPAddr[0] == 0) {
//dhcps_init(&xnetif[0]);
g_bStaticIP = 0;
}
else {
// dhcps_deinit();
g_bStaticIP = 1;

IP4_ADDR(ip_2_ip4(&ipaddr), ip->localIPAddr[0], ip->localIPAddr[1], ip->localIPAddr[2], ip->localIPAddr[3]);
IP4_ADDR(ip_2_ip4(&netmask), ip->netMask[0], ip->netMask[1], ip->netMask[2], ip->netMask[3]);
IP4_ADDR(ip_2_ip4(&gw), ip->gatewayIPAddr[0], ip->gatewayIPAddr[1], ip->gatewayIPAddr[2], ip->gatewayIPAddr[3]);
netif_set_addr(&xnetif[0], ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw));
}

netif_set_hostname(&xnetif[0], CFG_GetDeviceName());
wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, (rtw_event_handler_t)wifi_dis_hdl, NULL);
//wifi_reg_event_handler(WIFI_EVENT_CONNECT, (rtw_event_handler_t)wifi_con_hdl, NULL);
Expand Down
8 changes: 4 additions & 4 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,22 +1070,22 @@ int http_fn_cfg_ip(http_request_t* request) {

if (http_getArg(request->url, "IP", tmp, sizeof(tmp))) {
str_to_ip(tmp, g_cfg.staticIP.localIPAddr);
//hprintf255(request, "<br>IP=%s (%02x %02x %02x %02x)<br>",tmp,g_cfg.staticIP.localIPAddr[0],g_cfg.staticIP.localIPAddr[1],g_cfg.staticIP.localIPAddr[2],g_cfg.staticIP.localIPAddr[3]);
hprintf255(request, "<br>IP=%s (%02x %02x %02x %02x)<br>",tmp,g_cfg.staticIP.localIPAddr[0],g_cfg.staticIP.localIPAddr[1],g_cfg.staticIP.localIPAddr[2],g_cfg.staticIP.localIPAddr[3]);
g_changes++;
}
if (http_getArg(request->url, "mask", tmp, sizeof(tmp))) {
str_to_ip(tmp, g_cfg.staticIP.netMask);
//hprintf255(request, "<br>Mask=%s (%02x %02x %02x %02x)<br>",tmp, g_cfg.staticIP.netMask[0], g_cfg.staticIP.netMask[1], g_cfg.staticIP.netMask[2], g_cfg.staticIP.netMask[3]);
hprintf255(request, "<br>Mask=%s (%02x %02x %02x %02x)<br>",tmp, g_cfg.staticIP.netMask[0], g_cfg.staticIP.netMask[1], g_cfg.staticIP.netMask[2], g_cfg.staticIP.netMask[3]);
g_changes++;
}
if (http_getArg(request->url, "dns", tmp, sizeof(tmp))) {
str_to_ip(tmp, g_cfg.staticIP.dnsServerIpAddr);
//hprintf255(request, "<br>DNS=%s (%02x %02x %02x %02x)<br>",tmp, g_cfg.staticIP.dnsServerIpAddr[0], g_cfg.staticIP.dnsServerIpAddr[1], g_cfg.staticIP.dnsServerIpAddr[2], g_cfg.staticIP.dnsServerIpAddr[3]);
hprintf255(request, "<br>DNS=%s (%02x %02x %02x %02x)<br>",tmp, g_cfg.staticIP.dnsServerIpAddr[0], g_cfg.staticIP.dnsServerIpAddr[1], g_cfg.staticIP.dnsServerIpAddr[2], g_cfg.staticIP.dnsServerIpAddr[3]);
g_changes++;
}
if (http_getArg(request->url, "gate", tmp, sizeof(tmp))) {
str_to_ip(tmp, g_cfg.staticIP.gatewayIPAddr);
//hprintf255(request, "<br>GW=%s (%02x %02x %02x %02x)<br>",tmp, g_cfg.staticIP.gatewayIPAddr[0], g_cfg.staticIP.gatewayIPAddr[1], g_cfg.staticIP.gatewayIPAddr[2], g_cfg.staticIP.gatewayIPAddr[3]);
hprintf255(request, "<br>GW=%s (%02x %02x %02x %02x)<br>",tmp, g_cfg.staticIP.gatewayIPAddr[0], g_cfg.staticIP.gatewayIPAddr[1], g_cfg.staticIP.gatewayIPAddr[2], g_cfg.staticIP.gatewayIPAddr[3]);
g_changes++;
}
if (g_changes) {
Expand Down
2 changes: 1 addition & 1 deletion src/new_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ typedef enum
EXCELLENT,
} WIFI_RSSI_LEVEL;

#if PLATFORM_LN882H
#if PLATFORM_LN882H || PLATFORM_RTL87X0C
#define IP_STRING_FORMAT "%u.%u.%u.%u"
#else
#define IP_STRING_FORMAT "%hhu.%hhu.%hhu.%hhu"
Expand Down

0 comments on commit 6eb8162

Please sign in to comment.