DHCP Allows selecting the DHCP server's network interface

This changes the parameters of dhcpserver_start.

  Besides that, dhcpserver_start should only be called after user_init has
finished, else the call sdk_system_get_netif(SOFTAP_IF) will return NULL.
This commit is contained in:
Fernando Governatore 2017-08-03 22:34:59 -03:00
parent 9523e872f8
commit be7cabd94d
4 changed files with 19 additions and 12 deletions

View file

@ -77,8 +77,12 @@ inline static void sprintf_ipaddr(const ip_addr_t *addr, char *dest)
ip4_addr2(addr), ip4_addr3(addr), ip4_addr4(addr));
}
void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases)
void dhcpserver_start(struct netif *server_if, const ip_addr_t *first_client_addr, uint8_t max_leases)
{
if(!server_if){
printf("DHCP Server Error: server_if is NULL.\r\n");
return;
}
/* Stop any existing running dhcpserver */
if(dhcpserver_task_handle)
dhcpserver_stop();
@ -89,7 +93,7 @@ void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases)
// state->server_if is assigned once the task is running - see comment in dhcpserver_task()
ip_addr_copy(state->first_client_addr, *first_client_addr);
xTaskCreate(dhcpserver_task, "DHCPServer", 768, NULL, 8, &dhcpserver_task_handle);
xTaskCreate(dhcpserver_task, "DHCPServer", 768, server_if, 8, &dhcpserver_task_handle);
}
void dhcpserver_stop(void)
@ -104,7 +108,7 @@ void dhcpserver_stop(void)
static void dhcpserver_task(void *pxParameter)
{
/* netif_list isn't assigned until after user_init completes, which is why we do it inside the task */
state->server_if = netif_list; /* TODO: Make this configurable */
state->server_if = pxParameter;
state->nc = netconn_new (NETCONN_UDP);
if(!state->nc) {

View file

@ -25,8 +25,10 @@ extern "C" {
first_client_addr is the IP address of the first lease to be handed
to a client. Subsequent lease addresses are calculated by
incrementing the final octet of the IPv4 address, up to max_leases.
The server will wait for requests on server_if interface.
*/
void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases);
void dhcpserver_start(struct netif *server_if, const ip_addr_t *first_client_addr, uint8_t max_leases);
void dhcpserver_get_lease(const ip_addr_t *first_client_addr, uint8_t max_leases);