commit
b520735d20
6 changed files with 14 additions and 16 deletions
|
@ -50,7 +50,7 @@ static void telnetTask(void *pvParameters)
|
|||
{
|
||||
ip_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(sdk_system_get_netif(SOFTAP_IF), &first_client_ip, 4);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
|
||||
struct netconn *nc = netconn_new(NETCONN_TCP);
|
||||
if (!nc)
|
||||
|
|
|
@ -193,7 +193,7 @@ void user_init(void)
|
|||
|
||||
ip_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(sdk_system_get_netif(SOFTAP_IF), &first_client_ip, 4);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
printf("DHCP started\n");
|
||||
|
||||
//Create a queue to store events on netconns
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
* Based on RFC2131 http://www.ietf.org/rfc/rfc2131.txt
|
||||
* ... although not fully RFC compliant yet.
|
||||
*
|
||||
* Probably allocates more memory than it should, it should be possible to reuse netbufs in most cases.
|
||||
* TODO
|
||||
* * Allow binding on a single interface only (for mixed AP/client mode), lwip seems to make it hard to
|
||||
* listen for or send broadcasts on a specific interface only.
|
||||
*
|
||||
* * Probably allocates more memory than it should, it should be possible to reuse netbufs in most cases.
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||
|
@ -88,12 +92,8 @@ inline static void sprintf_ipaddr(const ip4_addr_t *addr, char *dest)
|
|||
ip4_addr2(addr), ip4_addr3(addr), ip4_addr4(addr));
|
||||
}
|
||||
|
||||
void dhcpserver_start(struct netif *server_if, const ip_addr_t *first_client_addr, uint8_t max_leases)
|
||||
void dhcpserver_start(const ip4_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();
|
||||
|
@ -109,7 +109,7 @@ void dhcpserver_start(struct netif *server_if, const ip_addr_t *first_client_add
|
|||
ip4_addr_set_zero(&state->router);
|
||||
ip4_addr_set_zero(&state->dns);
|
||||
|
||||
xTaskCreate(dhcpserver_task, "DHCPServer", 768, server_if, 8, &dhcpserver_task_handle);
|
||||
xTaskCreate(dhcpserver_task, "DHCP Server", 448, NULL, 2, &dhcpserver_task_handle);
|
||||
}
|
||||
|
||||
void dhcpserver_stop(void)
|
||||
|
@ -134,7 +134,7 @@ void dhcpserver_set_dns(const ip4_addr_t *dns)
|
|||
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 = pxParameter;
|
||||
state->server_if = netif_list; /* TODO: Make this configurable */
|
||||
|
||||
state->nc = netconn_new (NETCONN_UDP);
|
||||
if(!state->nc) {
|
||||
|
@ -143,7 +143,7 @@ static void dhcpserver_task(void *pxParameter)
|
|||
}
|
||||
|
||||
netconn_bind(state->nc, IP4_ADDR_ANY, LWIP_IANA_PORT_DHCP_SERVER);
|
||||
netconn_bind_if(state->nc, netif_get_index(state->server_if));
|
||||
netconn_bind_if (state->nc, netif_get_index(state->server_if));
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
|
|
@ -25,10 +25,8 @@ 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(struct netif *server_if, const ip_addr_t *first_client_addr, uint8_t max_leases);
|
||||
void dhcpserver_start(const ip4_addr_t *first_client_addr, uint8_t max_leases);
|
||||
|
||||
void dhcpserver_get_lease(const ip4_addr_t *first_client_addr, uint8_t max_leases);
|
||||
|
||||
|
|
|
@ -1995,7 +1995,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
|
|||
if (wifi_ap_dns < 0 || wifi_ap_dns > 1)
|
||||
wifi_ap_dns = 1;
|
||||
|
||||
dhcpserver_start(sdk_system_get_netif(SOFTAP_IF), &first_client_ip, wifi_ap_dhcp_leases);
|
||||
dhcpserver_start(&first_client_ip, wifi_ap_dhcp_leases);
|
||||
dhcpserver_set_router(&ap_ip.ip);
|
||||
if (wifi_ap_dns) {
|
||||
dhcpserver_set_dns(&ap_ip.ip);
|
||||
|
|
|
@ -43,7 +43,7 @@ static void server_task(void *pvParameters)
|
|||
|
||||
ip_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(sdk_system_get_netif(SOFTAP_IF), &first_client_ip, 4);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
|
||||
char buf[BUF_SIZE];
|
||||
struct netconn *nc = netconn_new(NETCONN_TCP);
|
||||
|
|
Loading…
Reference in a new issue