xref: /btstack/3rd-party/lwip/dhcp-server/dhserver.h (revision 97dc5e692c7d94a280158af58036a0efee5b0e56)
1*97dc5e69SMatthias Ringwald /*
2*97dc5e69SMatthias Ringwald  * The MIT License (MIT)
3*97dc5e69SMatthias Ringwald  *
4*97dc5e69SMatthias Ringwald  * Copyright (c) 2015 by Sergey Fetisov <[email protected]>
5*97dc5e69SMatthias Ringwald  *
6*97dc5e69SMatthias Ringwald  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*97dc5e69SMatthias Ringwald  * of this software and associated documentation files (the "Software"), to deal
8*97dc5e69SMatthias Ringwald  * in the Software without restriction, including without limitation the rights
9*97dc5e69SMatthias Ringwald  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10*97dc5e69SMatthias Ringwald  * copies of the Software, and to permit persons to whom the Software is
11*97dc5e69SMatthias Ringwald  * furnished to do so, subject to the following conditions:
12*97dc5e69SMatthias Ringwald  *
13*97dc5e69SMatthias Ringwald  * The above copyright notice and this permission notice shall be included in all
14*97dc5e69SMatthias Ringwald  * copies or substantial portions of the Software.
15*97dc5e69SMatthias Ringwald  *
16*97dc5e69SMatthias Ringwald  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*97dc5e69SMatthias Ringwald  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*97dc5e69SMatthias Ringwald  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*97dc5e69SMatthias Ringwald  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*97dc5e69SMatthias Ringwald  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*97dc5e69SMatthias Ringwald  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*97dc5e69SMatthias Ringwald  * SOFTWARE.
23*97dc5e69SMatthias Ringwald  */
24*97dc5e69SMatthias Ringwald 
25*97dc5e69SMatthias Ringwald /*
26*97dc5e69SMatthias Ringwald  * version: 1.0 demo (7.02.2015)
27*97dc5e69SMatthias Ringwald  * brief:   tiny dhcp ipv4 server using lwip (pcb)
28*97dc5e69SMatthias Ringwald  * ref:     https://lists.gnu.org/archive/html/lwip-users/2012-12/msg00016.html
29*97dc5e69SMatthias Ringwald  */
30*97dc5e69SMatthias Ringwald 
31*97dc5e69SMatthias Ringwald #ifndef DHSERVER_H
32*97dc5e69SMatthias Ringwald #define DHSERVER_H
33*97dc5e69SMatthias Ringwald 
34*97dc5e69SMatthias Ringwald // #include <stdint.h>
35*97dc5e69SMatthias Ringwald #include <stdbool.h>
36*97dc5e69SMatthias Ringwald // #include <stdio.h>
37*97dc5e69SMatthias Ringwald #include <string.h>
38*97dc5e69SMatthias Ringwald #include "lwip/err.h"
39*97dc5e69SMatthias Ringwald #include "lwip/udp.h"
40*97dc5e69SMatthias Ringwald #include "netif/etharp.h"
41*97dc5e69SMatthias Ringwald #include "lwip/ip_addr.h"
42*97dc5e69SMatthias Ringwald 
43*97dc5e69SMatthias Ringwald typedef struct dhcp_entry
44*97dc5e69SMatthias Ringwald {
45*97dc5e69SMatthias Ringwald 	uint8_t  mac[6];
46*97dc5e69SMatthias Ringwald 	uint8_t  addr[4];
47*97dc5e69SMatthias Ringwald 	uint8_t  subnet[4];
48*97dc5e69SMatthias Ringwald 	uint32_t lease;
49*97dc5e69SMatthias Ringwald } dhcp_entry_t;
50*97dc5e69SMatthias Ringwald 
51*97dc5e69SMatthias Ringwald typedef struct dhcp_config
52*97dc5e69SMatthias Ringwald {
53*97dc5e69SMatthias Ringwald 	uint8_t       addr[4];
54*97dc5e69SMatthias Ringwald 	uint16_t      port;
55*97dc5e69SMatthias Ringwald 	uint8_t       dns[4];
56*97dc5e69SMatthias Ringwald 	const char   *domain;
57*97dc5e69SMatthias Ringwald 	int           num_entry;
58*97dc5e69SMatthias Ringwald 	dhcp_entry_t *entries;
59*97dc5e69SMatthias Ringwald } dhcp_config_t;
60*97dc5e69SMatthias Ringwald 
61*97dc5e69SMatthias Ringwald err_t dhserv_init(dhcp_config_t *config);
62*97dc5e69SMatthias Ringwald void dhserv_free(void);
63*97dc5e69SMatthias Ringwald 
64*97dc5e69SMatthias Ringwald #endif /* DHSERVER_H */
65