diff --git a/cores/esp8266/LwipDhcpServer.cpp b/cores/esp8266/LwipDhcpServer.cpp index 07270bb6c2..3eea0ab3ce 100644 --- a/cores/esp8266/LwipDhcpServer.cpp +++ b/cores/esp8266/LwipDhcpServer.cpp @@ -536,6 +536,7 @@ void DhcpServer::send_offer(struct dhcps_msg* m) end = add_msg_type(&m->options[4], DHCPOFFER); end = add_offer_options(end); + end = insert_custom_offer_options(end, &m->options[0]); end = add_end(end); p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM); @@ -658,6 +659,7 @@ void DhcpServer::send_ack(struct dhcps_msg* m) end = add_msg_type(&m->options[4], DHCPACK); end = add_offer_options(end); + end = insert_custom_offer_options(end, &m->options[0]); end = add_end(end); p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM); @@ -1591,3 +1593,30 @@ uint32 DhcpServer::dhcps_client_update(u8* bssid, struct ipv4_addr* ip) return pdhcps_pool->ip.addr; } + +void DhcpServer::add_dhcps_custom_options(char *offerContent) +{ + isSetCustomOptions = true; + customOptionsContent = offerContent; +} + +void DhcpServer::remove_dhcps_custom_options() +{ + isSetCustomOptions = false; +} + +uint8_t* DhcpServer::insert_custom_offer_options(uint8_t* optptr, uint8_t* optionsStart) +{ + if(isSetCustomOptions){ + uint16 customOptionsSize = strlen(customOptionsContent); + if((optptr + customOptionsSize - optionsStart) >= 311){ + #if DHCPS_DEBUG + os_printf("ERROR: DHCP Custom Options Too Large. Ignoring Custom Options"); + #endif + return optptr; + } + memcpy(optptr, customOptionsContent, strlen(customOptionsContent)); + optptr += customOptionsSize; + } + return optptr; +} diff --git a/cores/esp8266/LwipDhcpServer.h b/cores/esp8266/LwipDhcpServer.h index d5eb6410ef..80a349501b 100644 --- a/cores/esp8266/LwipDhcpServer.h +++ b/cores/esp8266/LwipDhcpServer.h @@ -60,6 +60,11 @@ class DhcpServer bool reset_dhcps_lease_time(void); uint32 get_dhcps_lease_time(void); bool add_dhcps_lease(uint8* macaddr); + void add_dhcps_custom_options(char *offerContent); + void remove_dhcps_custom_options(void); + bool isSetCustomOptions; + char *customOptionsContent; + void dhcps_set_dns(int num, const ipv4_addr_t* dns); @@ -76,6 +81,7 @@ class DhcpServer void node_remove_from_list(list_node** phead, list_node* pdelete); uint8_t* add_msg_type(uint8_t* optptr, uint8_t type); uint8_t* add_offer_options(uint8_t* optptr); + uint8_t* insert_custom_offer_options(uint8_t* optptr, uint8_t* optionsStart); uint8_t* add_end(uint8_t* optptr); void create_msg(struct dhcps_msg* m); void send_offer(struct dhcps_msg* m);