Tiny DHCP Server.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include "conf_tinyservices.h"
#include "tinyservices.h"
#include "wifi_private.h"
#include "lwip/dhcp.h"
#include "lwip/tcpip.h"
#include <string.h>
Macros | |
#define | LWIP_DHCP_MAX_CLIENT 8 |
Functions | |
static uint16_t | lwip_dhcp_find_option (struct pbuf *pbuf_in, uint8_t option, uint8_t *opt_val, uint8_t *opt_size) |
Find an option in a DHCP packet. More... | |
static ip_addr_t | lwip_dhcp_get_ip_address (uint8_t *mac) |
Find a IP address for MAC. More... | |
void | lwip_dhcp_register_mac (uint8_t *mac) |
static void | lwip_dhcp_server_fn (void *arg, struct udp_pcb *dhcp_pcb_recv, struct pbuf *pbuf_in, struct ip_addr *client_addr, uint16_t port) |
Receive DHCP discover, request and inform packets and respond to them by supplying one IP Address for the client and setting the DNS server address. More... | |
void | lwip_dhcp_unregister_mac (uint8_t *mac) |
static void | lwip_dhcpserver_start_threadsafe (void *arg) |
Start the Tiny DNS Server. More... | |
void | lwip_tiny_dhcpserver_start (void) |
Start the Tiny DHCP Server. More... | |
void | lwip_tiny_dhcpserver_stop (void) |
Stop a Tiny DHCP Server. More... | |
static void | lwip_tiny_dhcpserver_stop_threadsafe (void *arg) |
Stop a Tiny DHCP Server. More... | |
Variables | |
static struct udp_pcb * | dhcp_pcb = 0 |
static ip_addr_t | ip_addr_c_broadcast = { 0xff05a8c0 } |
static uint8_t | lwip_dhcp_known_mac [LWIP_DHCP_MAX_CLIENT][6] |
#define LWIP_DHCP_MAX_CLIENT 8 |
|
static |
Find an option in a DHCP packet.
pbuf_in | the pbuf containing the a DHCP packet. |
option | an unsigned char representing the option to search for. |
opt_val | a pointer to place the value of the option located. |
opt_size | a pointer to the size of the option located. |
References DHCP_OPTIONS_OFS, pbuf_copy_partial(), and pbuf_get_at().
Referenced by lwip_dhcp_server_fn().
|
static |
Find a IP address for MAC.
References lwip_dhcp_known_mac, and LWIP_DHCP_MAX_CLIENT.
Referenced by lwip_dhcp_server_fn().
void lwip_dhcp_register_mac | ( | uint8_t * | mac | ) |
References lwip_dhcp_known_mac, LWIP_DHCP_MAX_CLIENT, and lwip_dhcp_unregister_mac().
Referenced by lwip_dhcp_server_fn().
|
static |
Receive DHCP discover, request and inform packets and respond to them by supplying one IP Address for the client and setting the DNS server address.
arg | unused. |
dhcp_pcb | a pointer to the pcb that DHCP packets are received on. |
pbuf_in | a pointer to the pbuf containing the DHCP packet. |
client_addr | the IP Address (if any) that originated the DHCP traffic. |
port | unused. |
References AP_ADDR_IP, Assert, DHCP_ACK, DHCP_BOOTREPLY, DHCP_CHADDR_OFS, DHCP_CLIENT_PORT, DHCP_COOKIE_OFS, DHCP_DISCOVER, DHCP_FLAGS_OFS, DHCP_INFORM, DHCP_MAGIC_COOKIE, DHCP_NAK, DHCP_OFFER, DHCP_OP_OFS, DHCP_OPTION_DNS_SERVER, DHCP_OPTION_DOMAIN_NAME, DHCP_OPTION_END, DHCP_OPTION_LEASE_TIME, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_REQUESTED_IP, DHCP_OPTION_ROUTER, DHCP_OPTION_SERVER_ID, DHCP_OPTION_SUBNET_MASK, DHCP_OPTION_T1, DHCP_OPTION_T2, DHCP_OPTION_VENDOR_SPECIFIC_INFO, DHCP_OPTIONS_OFS, DHCP_REQUEST, DHCP_RESPONSE_DEFAULT_SIZE, DHCP_SECS_OFS, DHCP_SIADDR_OFS, DHCP_YIADDR_OFS, DOMAIN_NAME, DOMAIN_NAME_LEN, ERR_OK, flags, ip_addr_c_broadcast, lwip_dhcp_find_option(), lwip_dhcp_get_ip_address(), lwip_dhcp_register_mac(), NULL, pbuf_alloc(), pbuf_copy(), pbuf_free(), PBUF_POOL, pbuf_read8(), pbuf_realloc(), pbuf_take_partial(), PBUF_TRANSPORT, pbuf_write32be(), pbuf_write8(), pbuf_write_ip(), SANE_LEASE_TIME, SANE_REBINDING_TIME, SANE_RENEWAL_TIME, SN_MASK_IP, pbuf::tot_len, udp_sendto(), and UNUSED.
Referenced by lwip_dhcpserver_start_threadsafe().
void lwip_dhcp_unregister_mac | ( | uint8_t * | mac | ) |
References lwip_dhcp_known_mac, and LWIP_DHCP_MAX_CLIENT.
Referenced by lwip_dhcp_register_mac(), and wifi_cb().
Start the Tiny DNS Server.
Create a new UDP PCB, bind that PCB to the DHCP_SERVER_PORT and set up a receiver for that PCB.
This variant of the start function must only be called from within LWIP's main thread.
This function must be invoked via lwip_tiny_dhcpserver_start
References Assert, DHCP_SERVER_PORT, IP_ADDR_ANY, lwip_dhcp_known_mac, LWIP_DHCP_MAX_CLIENT, lwip_dhcp_server_fn(), udp_bind(), udp_new(), udp_recv(), and UNUSED.
Referenced by lwip_tiny_dhcpserver_start().
Start the Tiny DHCP Server.
Start Tiny DHCP server.
Create a new UDP PCB, bind that PCB to the DHCP_SERVER_PORT and set up a receiver for that PCB.
Thread-safe variant of this function. This function posts the LWIP-thread-only variant of this function (with dummy argument) to the LWIP thread's mailbox and returns.
NOTE: This function cannot wait. It may be called from within the LWIP main thread of execution.
References lwip_dhcpserver_start_threadsafe(), and tcpip_callback.
Referenced by net_interface_up_imp().
Stop a Tiny DHCP Server.
Stop Tiny DHCP server.
Disconnect and remove the UDP PCB.
Thread-safe variant of this function. This function posts the lwip-main-thread only function and a dummy argument to the main lwip thread.
NOTE: This function cannot wait. It may be called from within the LWIP main thread of execution.
References lwip_tiny_dhcpserver_stop_threadsafe(), and tcpip_callback.
Referenced by net_interface_down_imp().
Stop a Tiny DHCP Server.
Disconnect and remove the UDP PCB.
This function must only be called from within LWIP's main thread. It must be invoked via lwip_tiny_dhcp_server_stop.
References udp_disconnect(), udp_remove(), and UNUSED.
Referenced by lwip_tiny_dhcpserver_stop().
|
static |
|
static |
Referenced by lwip_dhcp_server_fn().
|
static |