From e468cf53ee85991c4381b32cfb0aa17b53289d09 Mon Sep 17 00:00:00 2001 From: joba-1 Date: Tue, 15 Nov 2022 18:53:38 +0100 Subject: [PATCH 1/2] add command RgxPort to setup port forwarding --- .../xdrv_58_range_extender.ino | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino b/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino index 7352861dd..4ac0a2012 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino @@ -94,6 +94,8 @@ const char kDrvRgxCommands[] PROGMEM = "Rgx|" // Prefix #ifdef USE_WIFI_RANGE_EXTENDER_NAPT "|" "NAPT" + "|" + "Port" #endif // USE_WIFI_RANGE_EXTENDER_NAPT #ifdef ESP32 "|" @@ -110,6 +112,7 @@ void (*const DrvRgxCommand[])(void) PROGMEM = { &CmndRgxPassword, #ifdef USE_WIFI_RANGE_EXTENDER_NAPT &CmndRgxNAPT, + &CmndRgxPort, #endif // USE_WIFI_RANGE_EXTENDER_NAPT #ifdef ESP32 &CmndRgxClients, @@ -124,7 +127,6 @@ void (*const DrvRgxCommand[])(void) PROGMEM = { #endif // ESP8266 #endif // USE_WIFI_RANGE_EXTENDER_NAPT -#include #include #ifdef ESP8266 #include @@ -271,7 +273,52 @@ void CmndRgxNAPT(void) } } ResponseCmndStateText(Settings->sbflag1.range_extender_napt); -}; +} + +void CmndRgxPort(void) +{ + char *tok, *state, *parm_mac; + uint16_t gw, dst; + uint8_t proto = 0; + + Response_P(PSTR("ERROR")); + + if (ArgC()!=4) return; + if ((tok = strtok_r(XdrvMailbox.data, ", ", &state)) == 0) return; + if (strcasecmp("TCP", tok) == 0) proto = IP_PROTO_TCP; + if (strcasecmp("UDP", tok) == 0) proto = IP_PROTO_UDP; + if (!proto) return; + if ((tok = strtok_r(0, ", ", &state)) == 0) return; + if ((gw = strtoul(tok, nullptr, 0)) == 0) return; + if ((parm_mac = strtok_r(0, ", ", &state)) == 0) return; + if ((tok = strtok_r(0, ", ", &state)) == 0) return; + if ((dst = strtoul(tok, nullptr, 0)) == 0) return; + +#ifdef ESP32 + wifi_sta_list_t wifi_sta_list = {0}; + tcpip_adapter_sta_list_t adapter_sta_list = {0}; + + esp_wifi_ap_get_sta_list(&wifi_sta_list); + tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list); + + for (int i=0; i %_I:%u"), + (proto == IP_PROTO_TCP) ? "TCP" : "UDP", (uint32_t)WiFi.localIP(), gw, adapter_sta_list.sta[i].ip.addr, dst); + return; + } + break; + } + } +#endif // ESP32 +} #endif // USE_WIFI_RANGE_EXTENDER_NAPT void ResponseRgxConfig(void) From 8af22a1904e60380df5a2a80857b2a8e3e51dc97 Mon Sep 17 00:00:00 2001 From: joba-1 Date: Tue, 15 Nov 2022 20:12:07 +0100 Subject: [PATCH 2/2] remove unneeded return --- tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino b/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino index 4ac0a2012..27b257177 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_58_range_extender.ino @@ -312,7 +312,6 @@ void CmndRgxPort(void) { Response_P(PSTR("OK %s %_I:%u -> %_I:%u"), (proto == IP_PROTO_TCP) ? "TCP" : "UDP", (uint32_t)WiFi.localIP(), gw, adapter_sta_list.sta[i].ip.addr, dst); - return; } break; }