From 5d9bfe38cb3408f92570096d144e6452da5904ef Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 6 Jan 2019 19:45:57 +0100 Subject: [PATCH 1/7] Add capability to have light static DHCP lease --- tools/sdk/include/user_interface.h | 1 + tools/sdk/lwip/src/app/dhcpserver.c | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 71159bf202..586d8627a5 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -385,6 +385,7 @@ bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); uint32 wifi_softap_get_dhcps_lease_time(void); bool wifi_softap_set_dhcps_lease_time(uint32 minute); bool wifi_softap_reset_dhcps_lease_time(void); +bool wifi_softap_add_dhcps_lease(uint8 *macaddr); enum dhcp_status wifi_softap_dhcps_status(void); bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); diff --git a/tools/sdk/lwip/src/app/dhcpserver.c b/tools/sdk/lwip/src/app/dhcpserver.c index 07e893d6e8..efa691fbf2 100644 --- a/tools/sdk/lwip/src/app/dhcpserver.c +++ b/tools/sdk/lwip/src/app/dhcpserver.c @@ -104,6 +104,54 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele } } } + +/****************************************************************************** + * FunctionName : wifi_softap_add_dhcps_lease + * Description : add static lease on the list, this will be the next available @ + * Parameters : mac address + * Returns : true if ok and false if this mac already exist or if all ip are already reserved +*******************************************************************************/ +bool ICACHE_FLASH_ATTR wifi_softap_add_dhcps_lease(uint8 *macaddr) +{ + + struct dhcps_pool *pdhcps_pool = NULL; + list_node *pback_node = NULL; + + uint32 start_ip = dhcps_lease.start_ip.addr; + uint32 end_ip = dhcps_lease.end_ip.addr; + + for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) { + pdhcps_pool = pback_node->pnode; + if (os_memcmp(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)) == 0){ +#if DHCPS_DEBUG + os_printf("this mac already exist"); +#endif + return false; + } + else start_ip = htonl((ntohl(start_ip) + 1)); + } + + if (start_ip>end_ip) { +#if DHCPS_DEBUG + os_printf("no more ip available"); +#endif + return false; + } + + pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool)); + pdhcps_pool->ip.addr = start_ip; + os_memcpy(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)); + pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER; + pdhcps_pool->type = DHCPS_TYPE_STATIC; + pdhcps_pool->state = DHCPS_STATE_ONLINE; + pback_node = (list_node *)os_zalloc(sizeof(list_node )); + pback_node->pnode = pdhcps_pool; + pback_node->pnext = NULL; + node_insert_to_list(&plist,pback_node); + + return true; +} + /////////////////////////////////////////////////////////////////////////////////// /* * ��DHCP msg��Ϣ�ṹ���������� From c32b463c2580a083ea43df9ba4cbb8dbe78339e6 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 6 Jan 2019 19:45:57 +0100 Subject: [PATCH 2/7] Add capability to have light static DHCP lease --- tools/sdk/include/user_interface.h | 1 + tools/sdk/lwip/src/app/dhcpserver.c | 48 +++++++++++++++++++++++++++++ tools/sdk/lwip2/builder | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 71159bf202..586d8627a5 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -385,6 +385,7 @@ bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); uint32 wifi_softap_get_dhcps_lease_time(void); bool wifi_softap_set_dhcps_lease_time(uint32 minute); bool wifi_softap_reset_dhcps_lease_time(void); +bool wifi_softap_add_dhcps_lease(uint8 *macaddr); enum dhcp_status wifi_softap_dhcps_status(void); bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); diff --git a/tools/sdk/lwip/src/app/dhcpserver.c b/tools/sdk/lwip/src/app/dhcpserver.c index 07e893d6e8..efa691fbf2 100644 --- a/tools/sdk/lwip/src/app/dhcpserver.c +++ b/tools/sdk/lwip/src/app/dhcpserver.c @@ -104,6 +104,54 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele } } } + +/****************************************************************************** + * FunctionName : wifi_softap_add_dhcps_lease + * Description : add static lease on the list, this will be the next available @ + * Parameters : mac address + * Returns : true if ok and false if this mac already exist or if all ip are already reserved +*******************************************************************************/ +bool ICACHE_FLASH_ATTR wifi_softap_add_dhcps_lease(uint8 *macaddr) +{ + + struct dhcps_pool *pdhcps_pool = NULL; + list_node *pback_node = NULL; + + uint32 start_ip = dhcps_lease.start_ip.addr; + uint32 end_ip = dhcps_lease.end_ip.addr; + + for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) { + pdhcps_pool = pback_node->pnode; + if (os_memcmp(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)) == 0){ +#if DHCPS_DEBUG + os_printf("this mac already exist"); +#endif + return false; + } + else start_ip = htonl((ntohl(start_ip) + 1)); + } + + if (start_ip>end_ip) { +#if DHCPS_DEBUG + os_printf("no more ip available"); +#endif + return false; + } + + pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool)); + pdhcps_pool->ip.addr = start_ip; + os_memcpy(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)); + pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER; + pdhcps_pool->type = DHCPS_TYPE_STATIC; + pdhcps_pool->state = DHCPS_STATE_ONLINE; + pback_node = (list_node *)os_zalloc(sizeof(list_node )); + pback_node->pnode = pdhcps_pool; + pback_node->pnext = NULL; + node_insert_to_list(&plist,pback_node); + + return true; +} + /////////////////////////////////////////////////////////////////////////////////// /* * ��DHCP msg��Ϣ�ṹ���������� diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 4670dfc00f..485aed7535 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 4670dfc00f0ce2caf194aca2f497d89d7b758ac7 +Subproject commit 485aed753582d1c07d2ef4878f461a61ba6105fd From 3309b7ba6321c3eef98e2374abd7d1f56c9e8a6a Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 12 Jan 2019 13:10:56 +0100 Subject: [PATCH 3/7] Add capability to have light static DHCP lease --- .gitmodules | 3 +++ tools/sdk/lwip2/builder | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 6ccf7f096b..1dca0efc3f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "libraries/SoftwareSerial"] path = libraries/SoftwareSerial url = https://github.com/plerup/espsoftwareserial.git +[submodule "tools/sdk/lwip2/builder"] + path = tools/sdk/lwip2/builder + url = https://github.com/SmartBlug/esp82xx-nonos-linklayer diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 485aed7535..56e0410010 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 485aed753582d1c07d2ef4878f461a61ba6105fd +Subproject commit 56e04100107366601e6fbf2bea55c32b390a98c3 From f83eae803e6413b8f442ebed0bea141943ac2f78 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 14 Jan 2019 06:44:56 +0100 Subject: [PATCH 4/7] Add capability to have light static DHCP lease --- .gitmodules | 5 +-- tools/sdk/include/user_interface.h | 3 +- tools/sdk/lwip/src/app/dhcpserver.c | 47 ----------------------------- 3 files changed, 3 insertions(+), 52 deletions(-) diff --git a/.gitmodules b/.gitmodules index 1dca0efc3f..1c0fd177ce 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,4 @@ url = https://github.com/earlephilhower/bearssl-esp8266 [submodule "libraries/SoftwareSerial"] path = libraries/SoftwareSerial - url = https://github.com/plerup/espsoftwareserial.git -[submodule "tools/sdk/lwip2/builder"] - path = tools/sdk/lwip2/builder - url = https://github.com/SmartBlug/esp82xx-nonos-linklayer + url = https://github.com/plerup/espsoftwareserial.git \ No newline at end of file diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 586d8627a5..bb36d57e38 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -385,7 +385,8 @@ bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); uint32 wifi_softap_get_dhcps_lease_time(void); bool wifi_softap_set_dhcps_lease_time(uint32 minute); bool wifi_softap_reset_dhcps_lease_time(void); -bool wifi_softap_add_dhcps_lease(uint8 *macaddr); + +bool wifi_softap_add_dhcps_lease(uint8 *macaddr); // add static lease on the list, this will be the next available @ enum dhcp_status wifi_softap_dhcps_status(void); bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); diff --git a/tools/sdk/lwip/src/app/dhcpserver.c b/tools/sdk/lwip/src/app/dhcpserver.c index efa691fbf2..7463922144 100644 --- a/tools/sdk/lwip/src/app/dhcpserver.c +++ b/tools/sdk/lwip/src/app/dhcpserver.c @@ -105,53 +105,6 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele } } -/****************************************************************************** - * FunctionName : wifi_softap_add_dhcps_lease - * Description : add static lease on the list, this will be the next available @ - * Parameters : mac address - * Returns : true if ok and false if this mac already exist or if all ip are already reserved -*******************************************************************************/ -bool ICACHE_FLASH_ATTR wifi_softap_add_dhcps_lease(uint8 *macaddr) -{ - - struct dhcps_pool *pdhcps_pool = NULL; - list_node *pback_node = NULL; - - uint32 start_ip = dhcps_lease.start_ip.addr; - uint32 end_ip = dhcps_lease.end_ip.addr; - - for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) { - pdhcps_pool = pback_node->pnode; - if (os_memcmp(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)) == 0){ -#if DHCPS_DEBUG - os_printf("this mac already exist"); -#endif - return false; - } - else start_ip = htonl((ntohl(start_ip) + 1)); - } - - if (start_ip>end_ip) { -#if DHCPS_DEBUG - os_printf("no more ip available"); -#endif - return false; - } - - pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool)); - pdhcps_pool->ip.addr = start_ip; - os_memcpy(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)); - pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER; - pdhcps_pool->type = DHCPS_TYPE_STATIC; - pdhcps_pool->state = DHCPS_STATE_ONLINE; - pback_node = (list_node *)os_zalloc(sizeof(list_node )); - pback_node->pnode = pdhcps_pool; - pback_node->pnext = NULL; - node_insert_to_list(&plist,pback_node); - - return true; -} - /////////////////////////////////////////////////////////////////////////////////// /* * ��DHCP msg��Ϣ�ṹ���������� From 639c993a7795cbd0ea42abd6a60a09fb4e47e21f Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 17 Jan 2019 07:02:46 +0100 Subject: [PATCH 5/7] added ESP8266WiFi StaticLease sample --- .gitmodules | 2 +- .../examples/StaticLease/StaticLease.ino | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino diff --git a/.gitmodules b/.gitmodules index 1c0fd177ce..6ccf7f096b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,4 @@ url = https://github.com/earlephilhower/bearssl-esp8266 [submodule "libraries/SoftwareSerial"] path = libraries/SoftwareSerial - url = https://github.com/plerup/espsoftwareserial.git \ No newline at end of file + url = https://github.com/plerup/espsoftwareserial.git diff --git a/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino new file mode 100644 index 0000000000..c79aa5eadf --- /dev/null +++ b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino @@ -0,0 +1,95 @@ +/* Create a WiFi access point and provide static lease */ + +#include +#include +#include + +/* Set these to your desired credentials. */ +const char *ssid = "ESPap"; +const char *password = "thereisnospoon"; + +ESP8266WebServer server(80); + +/* Set the IP Address you want for your AP */ +IPAddress apIP(192, 168, 0, 1); + +/* Go to http://192.168.0.1 in a web browser to see current lease */ +void handleRoot() { + String result; + char wifiClientMac[18]; + unsigned char number_client; + struct station_info *stat_info; + struct ip_addr *IPaddress; + + IPAddress address; + int i = 1; + + number_client = wifi_softap_get_station_num(); + stat_info = wifi_softap_get_station_info(); + + result = "

Total Connected Clients : "; + result += String(number_client); + result += "


"; + while (stat_info != NULL) { + IPaddress = &stat_info->ip; + address = IPaddress->addr; + + result += "Client "; + result += String(i); + result += " = "; + result += String(address.toString()); + result += " - "; + sprintf(wifiClientMac, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(stat_info->bssid)); + result += wifiClientMac; + result += "
"; + + stat_info = STAILQ_NEXT(stat_info, next); + i++; + } + result = result + ""; + + server.send(200, "text/html", result); +} + +void setup() { + /* List of mac address for static lease */ + uint8 mac_CAM[6] = { 0x00, 0x0C, 0x43, 0x01, 0x60, 0x15 }; + uint8 mac_PC[6] = { 0xb4, 0x52, 0x7e, 0x9a, 0x19, 0xa5 }; + + Serial.begin(115200); + Serial.println(); + Serial.println("Configuring access point..."); + + /* Disable the WiFi persistence to avoid any re-configuration that may erase static lease when starting softAP */ + WiFi.persistent(false); + + WiFi.mode(WIFI_AP); + /* Configure AP with IP = 192.168.0.1 / Gateway = 192.168.0.1 / Subnet = 255.255.255.0 + if you specify the ESP8266's IP-address with 192.168.0.1, the function softAPConfig() sets the DHCP-range as 192.168.0.100 - 192.168.0.200 + */ + WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); + /* Setup your static leases. + + As it depend from your first address, and need to be done BEFORE any request from client, + this need to be specified after WiFi.softAPConfig() and before WiFi.softAP(). + + first call to wifi_softap_add_dhcps_lease() will setup first IP address of the range + second call to wifi_softap_add_dhcps_lease() will setup second IP address of the range + ... + any client not listed will use next IP address available from the range (here 192.168.0.102 and more) + */ + wifi_softap_add_dhcps_lease(mac_CAM); // always 192.168.0.100 + wifi_softap_add_dhcps_lease(mac_PC); // always 192.168.0.101 + /* Start Access Point. You can remove the password parameter if you want the AP to be open. */ + WiFi.softAP(ssid, password); + Serial.print("AP IP address: "); + Serial.println(WiFi.softAPIP()); + /* Setup HTTP Server */ + server.on("/", handleRoot); + server.begin(); + Serial.println("HTTP server started"); +} + +void loop() { + server.handleClient(); +} From 0d4dfa8b2500597ae207bc7c59204fac08440ed6 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 17 Jan 2019 07:02:46 +0100 Subject: [PATCH 6/7] added ESP8266WiFi StaticLease sample --- .gitmodules | 2 +- .../examples/StaticLease/StaticLease.ino | 95 +++++++++++++++++++ tools/sdk/lwip2/include/lwip-git-hash.h | 2 +- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino diff --git a/.gitmodules b/.gitmodules index 1c0fd177ce..6ccf7f096b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,4 @@ url = https://github.com/earlephilhower/bearssl-esp8266 [submodule "libraries/SoftwareSerial"] path = libraries/SoftwareSerial - url = https://github.com/plerup/espsoftwareserial.git \ No newline at end of file + url = https://github.com/plerup/espsoftwareserial.git diff --git a/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino new file mode 100644 index 0000000000..c79aa5eadf --- /dev/null +++ b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino @@ -0,0 +1,95 @@ +/* Create a WiFi access point and provide static lease */ + +#include +#include +#include + +/* Set these to your desired credentials. */ +const char *ssid = "ESPap"; +const char *password = "thereisnospoon"; + +ESP8266WebServer server(80); + +/* Set the IP Address you want for your AP */ +IPAddress apIP(192, 168, 0, 1); + +/* Go to http://192.168.0.1 in a web browser to see current lease */ +void handleRoot() { + String result; + char wifiClientMac[18]; + unsigned char number_client; + struct station_info *stat_info; + struct ip_addr *IPaddress; + + IPAddress address; + int i = 1; + + number_client = wifi_softap_get_station_num(); + stat_info = wifi_softap_get_station_info(); + + result = "

Total Connected Clients : "; + result += String(number_client); + result += "


"; + while (stat_info != NULL) { + IPaddress = &stat_info->ip; + address = IPaddress->addr; + + result += "Client "; + result += String(i); + result += " = "; + result += String(address.toString()); + result += " - "; + sprintf(wifiClientMac, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(stat_info->bssid)); + result += wifiClientMac; + result += "
"; + + stat_info = STAILQ_NEXT(stat_info, next); + i++; + } + result = result + ""; + + server.send(200, "text/html", result); +} + +void setup() { + /* List of mac address for static lease */ + uint8 mac_CAM[6] = { 0x00, 0x0C, 0x43, 0x01, 0x60, 0x15 }; + uint8 mac_PC[6] = { 0xb4, 0x52, 0x7e, 0x9a, 0x19, 0xa5 }; + + Serial.begin(115200); + Serial.println(); + Serial.println("Configuring access point..."); + + /* Disable the WiFi persistence to avoid any re-configuration that may erase static lease when starting softAP */ + WiFi.persistent(false); + + WiFi.mode(WIFI_AP); + /* Configure AP with IP = 192.168.0.1 / Gateway = 192.168.0.1 / Subnet = 255.255.255.0 + if you specify the ESP8266's IP-address with 192.168.0.1, the function softAPConfig() sets the DHCP-range as 192.168.0.100 - 192.168.0.200 + */ + WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); + /* Setup your static leases. + + As it depend from your first address, and need to be done BEFORE any request from client, + this need to be specified after WiFi.softAPConfig() and before WiFi.softAP(). + + first call to wifi_softap_add_dhcps_lease() will setup first IP address of the range + second call to wifi_softap_add_dhcps_lease() will setup second IP address of the range + ... + any client not listed will use next IP address available from the range (here 192.168.0.102 and more) + */ + wifi_softap_add_dhcps_lease(mac_CAM); // always 192.168.0.100 + wifi_softap_add_dhcps_lease(mac_PC); // always 192.168.0.101 + /* Start Access Point. You can remove the password parameter if you want the AP to be open. */ + WiFi.softAP(ssid, password); + Serial.print("AP IP address: "); + Serial.println(WiFi.softAPIP()); + /* Setup HTTP Server */ + server.on("/", handleRoot); + server.begin(); + Serial.println("HTTP server started"); +} + +void loop() { + server.handleClient(); +} diff --git a/tools/sdk/lwip2/include/lwip-git-hash.h b/tools/sdk/lwip2/include/lwip-git-hash.h index 7c1841eb9a..efa52f4bea 100644 --- a/tools/sdk/lwip2/include/lwip-git-hash.h +++ b/tools/sdk/lwip2/include/lwip-git-hash.h @@ -1,5 +1,5 @@ // generated by makefiles/make-lwip2-hash #ifndef LWIP_HASH_H #define LWIP_HASH_H -#define LWIP_HASH_STR "STABLE-2_1_2_RELEASE/glue:1.0-9-g56e0410" +#define LWIP_HASH_STR "STABLE-2_1_2_RELEASE/glue:1.0-11-g87c709d" #endif // LWIP_HASH_H From 06356b6e75f56fe2b75d6e3ea5abfcc165597348 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 19 Jan 2019 08:30:56 +0100 Subject: [PATCH 7/7] Update StaticLease to IPv4 --- libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino index c79aa5eadf..51c0b97874 100644 --- a/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino +++ b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino @@ -19,7 +19,7 @@ void handleRoot() { char wifiClientMac[18]; unsigned char number_client; struct station_info *stat_info; - struct ip_addr *IPaddress; + struct ip4_addr *IPaddress; IPAddress address; int i = 1;