Wifi web based configuration.

This commit is contained in:
ourairquality 2016-09-02 23:02:57 +10:00 committed by Our Air Quality
parent 5c885c7722
commit 26a5eba0ad
19 changed files with 2109 additions and 5 deletions

View file

@ -44,6 +44,7 @@ typedef struct {
ip_addr_t first_client_addr;
struct netif *server_if;
dhcp_lease_t *leases; /* length max_leases */
bool dns; /* Enable sending a DNS server option */
} server_state_t;
/* Only one DHCP server task can run at once, so we have global state
@ -77,7 +78,7 @@ 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(const ip_addr_t *first_client_addr, uint8_t max_leases, bool dns)
{
/* Stop any existing running dhcpserver */
if(dhcpserver_task_handle)
@ -88,8 +89,9 @@ void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases)
state->leases = calloc(max_leases, sizeof(dhcp_lease_t));
// 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);
state->dns = dns;
xTaskCreate(dhcpserver_task, "DHCPServer", 768, NULL, 8, &dhcpserver_task_handle);
xTaskCreate(dhcpserver_task, "DHCP Server", 336, NULL, 2, &dhcpserver_task_handle);
}
void dhcpserver_stop(void)
@ -206,6 +208,8 @@ static void handle_dhcp_discover(struct dhcp_msg *dhcpmsg)
opt = add_dhcp_option_byte(opt, DHCP_OPTION_MESSAGE_TYPE, DHCP_OFFER);
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_SERVER_ID, &state->server_if->ip_addr, 4);
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_SUBNET_MASK, &state->server_if->netmask, 4);
if (state->dns)
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_DNS_SERVER, &state->server_if->ip_addr, 4);
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_END, NULL, 0);
struct netbuf *netbuf = netbuf_new();
@ -279,6 +283,8 @@ static void handle_dhcp_request(struct dhcp_msg *dhcpmsg)
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_LEASE_TIME, &expiry, 4);
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_SERVER_ID, &state->server_if->ip_addr, 4);
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_SUBNET_MASK, &state->server_if->netmask, 4);
if (state->dns)
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_DNS_SERVER, &state->server_if->ip_addr, 4);
opt = add_dhcp_option_bytes(opt, DHCP_OPTION_END, NULL, 0);
struct netbuf *netbuf = netbuf_new();

View file

@ -26,7 +26,7 @@ extern "C" {
to a client. Subsequent lease addresses are calculated by
incrementing the final octet of the IPv4 address, up to max_leases.
*/
void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases);
void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases, bool dns);
void dhcpserver_get_lease(const ip_addr_t *first_client_addr, uint8_t max_leases);