1 /* 2 * Copyright (C) 2022 Beken Corporation 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __DHCP_PRIV_H__ 16 #define __DHCP_PRIV_H__ 17 18 #include "lwip/sockets.h" 19 20 #if 0 21 #define dhcp_e(...) \ 22 LWIP_LOGI("dhcp: %s\r\n", ##__VA_ARGS__) 23 #define dhcp_w(...) \ 24 LWIP_LOGI("dhcp: %s\r\n", ##__VA_ARGS__) 25 26 #define dhcp_d(...) \ 27 LWIP_LOGI("dhcp: %s\r\n", ##__VA_ARGS__) 28 #else 29 #define dhcp_d(...) //LWIP_LOGI 30 #define dhcp_e(...) //LWIP_LOGI 31 #define dhcp_w(...) //LWIP_LOGI 32 #endif 33 34 #define SERVER_BUFFER_SIZE 1024 35 #define MAC_IP_CACHE_SIZE 8 36 37 #if CONFIG_MALLOC_STATIS 38 #define DHCP_SERVER_TASK_STACK_SIZE 2048 39 #else 40 #define DHCP_SERVER_TASK_STACK_SIZE 1536 41 #endif 42 43 struct client_mac_cache { 44 uint8_t client_mac[6]; /* mac address of the connected device */ 45 uint32_t client_ip; /* ip address of the connected device */ 46 }; 47 48 struct dhcp_server_data { 49 int sock; 50 int dnssock; 51 int ctrlsock; 52 int count_clients; /* to keep count of cached devices */ 53 char *msg; 54 struct sockaddr_in saddr; /* dhcp server address */ 55 struct sockaddr_in dnsaddr; /* dns server address */ 56 struct sockaddr_in uaddr; /* unicast address */ 57 struct sockaddr_in baddr; /* broadcast address */ 58 struct sockaddr_in ctrladdr; 59 struct client_mac_cache ip_mac_mapping[MAC_IP_CACHE_SIZE]; 60 uint32_t netmask; /* network order */ 61 uint32_t my_ip; /* network order */ 62 uint32_t client_ip; /* last address that was requested, network 63 * order */ 64 uint32_t current_ip; /* keep track of assigned IP addresses */ 65 uint32_t router_ip; /* router IP addresses */ 66 void *prv; 67 }; 68 69 void dhcp_enable_nack_dns_server(void); 70 int dhcp_server_init(void *intrfc_handle); 71 void dhcp_server(void* data); 72 int dhcp_send_halt(void); 73 int dhcp_free_allocations(void); 74 75 #endif 76