MeterLogger
Data Structures | Macros | Typedefs | Functions | Variables
dhcpserver.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dhcps_state
 
struct  dhcps_msg
 
struct  dhcps_pool
 
struct  _list_node
 

Macros

#define USE_DNS
 
#define DHCPS_LEASE_TIMER   dhcps_lease_time
 
#define DHCPS_MAX_LEASE   0x64
 
#define BOOTP_BROADCAST   0x8000
 
#define DHCP_REQUEST   1
 
#define DHCP_REPLY   2
 
#define DHCP_HTYPE_ETHERNET   1
 
#define DHCP_HLEN_ETHERNET   6
 
#define DHCP_MSG_LEN   236
 
#define DHCPS_SERVER_PORT   67
 
#define DHCPS_CLIENT_PORT   68
 
#define DHCPDISCOVER   1
 
#define DHCPOFFER   2
 
#define DHCPREQUEST   3
 
#define DHCPDECLINE   4
 
#define DHCPACK   5
 
#define DHCPNAK   6
 
#define DHCPRELEASE   7
 
#define DHCP_OPTION_SUBNET_MASK   1
 
#define DHCP_OPTION_ROUTER   3
 
#define DHCP_OPTION_DNS_SERVER   6
 
#define DHCP_OPTION_REQ_IPADDR   50
 
#define DHCP_OPTION_LEASE_TIME   51
 
#define DHCP_OPTION_MSG_TYPE   53
 
#define DHCP_OPTION_SERVER_ID   54
 
#define DHCP_OPTION_INTERFACE_MTU   26
 
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY   31
 
#define DHCP_OPTION_BROADCAST_ADDRESS   28
 
#define DHCP_OPTION_REQ_LIST   55
 
#define DHCP_OPTION_END   255
 
#define DHCPS_DEBUG   0
 
#define MAX_STATION_NUM   8
 
#define DHCPS_STATE_OFFER   1
 
#define DHCPS_STATE_DECLINE   2
 
#define DHCPS_STATE_ACK   3
 
#define DHCPS_STATE_NAK   4
 
#define DHCPS_STATE_IDLE   5
 
#define DHCPS_STATE_RELEASE   6
 
#define dhcps_router_enabled(offer)   ((offer & OFFER_ROUTER) != 0)
 

Typedefs

typedef struct dhcps_state dhcps_state
 
typedef struct dhcps_msg dhcps_msg
 
typedef struct _list_node list_node
 

Functions

void dhcps_start (struct ip_info *info)
 
void dhcps_stop (void)
 
void dhcps_set_DNS (struct ip_addr *dns_ip) ICACHE_FLASH_ATTR
 
struct dhcps_pooldhcps_get_mapping (uint16_t no) ICACHE_FLASH_ATTR
 
void dhcps_set_mapping (struct ip_addr *addr, uint8 *mac, uint32 lease_time) ICACHE_FLASH_ATTR
 

Variables

uint32 dhcps_lease_time
 

Macro Definition Documentation

◆ BOOTP_BROADCAST

#define BOOTP_BROADCAST   0x8000

Definition at line 53 of file dhcpserver.h.

Referenced by create_msg().

◆ DHCP_HLEN_ETHERNET

#define DHCP_HLEN_ETHERNET   6

Definition at line 58 of file dhcpserver.h.

◆ DHCP_HTYPE_ETHERNET

#define DHCP_HTYPE_ETHERNET   1

Definition at line 57 of file dhcpserver.h.

Referenced by create_msg().

◆ DHCP_MSG_LEN

#define DHCP_MSG_LEN   236

Definition at line 59 of file dhcpserver.h.

◆ DHCP_OPTION_BROADCAST_ADDRESS

#define DHCP_OPTION_BROADCAST_ADDRESS   28

Definition at line 81 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_DNS_SERVER

#define DHCP_OPTION_DNS_SERVER   6

Definition at line 74 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_END

#define DHCP_OPTION_END   255

Definition at line 83 of file dhcpserver.h.

Referenced by add_end(), and parse_options().

◆ DHCP_OPTION_INTERFACE_MTU

#define DHCP_OPTION_INTERFACE_MTU   26

Definition at line 79 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_LEASE_TIME

#define DHCP_OPTION_LEASE_TIME   51

Definition at line 76 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_MSG_TYPE

#define DHCP_OPTION_MSG_TYPE   53

Definition at line 77 of file dhcpserver.h.

Referenced by add_msg_type(), and parse_options().

◆ DHCP_OPTION_PERFORM_ROUTER_DISCOVERY

#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY   31

Definition at line 80 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_REQ_IPADDR

#define DHCP_OPTION_REQ_IPADDR   50

Definition at line 75 of file dhcpserver.h.

Referenced by parse_options().

◆ DHCP_OPTION_REQ_LIST

#define DHCP_OPTION_REQ_LIST   55

Definition at line 82 of file dhcpserver.h.

◆ DHCP_OPTION_ROUTER

#define DHCP_OPTION_ROUTER   3

Definition at line 73 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_SERVER_ID

#define DHCP_OPTION_SERVER_ID   54

Definition at line 78 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_OPTION_SUBNET_MASK

#define DHCP_OPTION_SUBNET_MASK   1

Definition at line 72 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCP_REPLY

#define DHCP_REPLY   2

Definition at line 56 of file dhcpserver.h.

Referenced by create_msg().

◆ DHCP_REQUEST

#define DHCP_REQUEST   1

Definition at line 55 of file dhcpserver.h.

◆ DHCPACK

#define DHCPACK   5

Definition at line 68 of file dhcpserver.h.

Referenced by send_ack().

◆ DHCPDECLINE

#define DHCPDECLINE   4

Definition at line 67 of file dhcpserver.h.

Referenced by parse_options().

◆ DHCPDISCOVER

#define DHCPDISCOVER   1

Definition at line 64 of file dhcpserver.h.

Referenced by parse_options().

◆ DHCPNAK

#define DHCPNAK   6

Definition at line 69 of file dhcpserver.h.

Referenced by send_nak().

◆ DHCPOFFER

#define DHCPOFFER   2

Definition at line 65 of file dhcpserver.h.

Referenced by send_offer().

◆ DHCPRELEASE

#define DHCPRELEASE   7

Definition at line 70 of file dhcpserver.h.

Referenced by parse_options().

◆ DHCPREQUEST

#define DHCPREQUEST   3

Definition at line 66 of file dhcpserver.h.

Referenced by parse_options().

◆ DHCPS_CLIENT_PORT

#define DHCPS_CLIENT_PORT   68

Definition at line 62 of file dhcpserver.h.

Referenced by send_ack(), send_nak(), and send_offer().

◆ DHCPS_DEBUG

#define DHCPS_DEBUG   0

Definition at line 86 of file dhcpserver.h.

◆ DHCPS_LEASE_TIMER

#define DHCPS_LEASE_TIMER   dhcps_lease_time

Definition at line 51 of file dhcpserver.h.

Referenced by add_offer_options(), and parse_msg().

◆ DHCPS_MAX_LEASE

#define DHCPS_MAX_LEASE   0x64

Definition at line 52 of file dhcpserver.h.

Referenced by wifi_softap_init_dhcps_lease(), and wifi_softap_set_dhcps_lease().

◆ dhcps_router_enabled

#define dhcps_router_enabled (   offer)    ((offer & OFFER_ROUTER) != 0)

Definition at line 96 of file dhcpserver.h.

Referenced by add_offer_options().

◆ DHCPS_SERVER_PORT

#define DHCPS_SERVER_PORT   67

Definition at line 61 of file dhcpserver.h.

Referenced by dhcps_start().

◆ DHCPS_STATE_ACK

#define DHCPS_STATE_ACK   3

Definition at line 91 of file dhcpserver.h.

Referenced by handle_dhcp(), and parse_options().

◆ DHCPS_STATE_DECLINE

#define DHCPS_STATE_DECLINE   2

Definition at line 90 of file dhcpserver.h.

◆ DHCPS_STATE_IDLE

#define DHCPS_STATE_IDLE   5

Definition at line 93 of file dhcpserver.h.

Referenced by parse_options().

◆ DHCPS_STATE_NAK

#define DHCPS_STATE_NAK   4

Definition at line 92 of file dhcpserver.h.

Referenced by handle_dhcp(), and parse_options().

◆ DHCPS_STATE_OFFER

#define DHCPS_STATE_OFFER   1

Definition at line 89 of file dhcpserver.h.

Referenced by handle_dhcp(), and parse_options().

◆ DHCPS_STATE_RELEASE

#define DHCPS_STATE_RELEASE   6

Definition at line 94 of file dhcpserver.h.

Referenced by parse_msg(), and parse_options().

◆ MAX_STATION_NUM

#define MAX_STATION_NUM   8

Definition at line 87 of file dhcpserver.h.

Referenced by dhcps_coarse_tmr().

◆ USE_DNS

#define USE_DNS

Definition at line 4 of file dhcpserver.h.

Typedef Documentation

◆ dhcps_msg

typedef struct dhcps_msg dhcps_msg

◆ dhcps_state

typedef struct dhcps_state dhcps_state

◆ list_node

typedef struct _list_node list_node

Function Documentation

◆ dhcps_get_mapping()

struct dhcps_pool* dhcps_get_mapping ( uint16_t  no)

Definition at line 1160 of file dhcpserver.c.

References NULL, _list_node::pnext, and _list_node::pnode.

1161 {
1162 list_node *pback_node = NULL;
1163 
1164  for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext, no--) {
1165  if (no == 0) return pback_node->pnode;
1166  }
1167  return NULL;
1168 }
void * pnode
Definition: dhcpserver.h:46
#define NULL
Definition: def.h:47
struct _list_node * pnext
Definition: dhcpserver.h:47
static list_node * plist
Definition: dhcpserver.c:34

◆ dhcps_set_DNS()

void dhcps_set_DNS ( struct ip_addr dns_ip)

Definition at line 1155 of file dhcpserver.c.

References dns_ip.

Referenced by wifi_softap_ip_config().

1156 {
1157  dns_address = *dns_ip;
1158 }
static struct ip_addr dns_address
Definition: dhcpserver.c:30
static ip_addr_t dns_ip
Definition: wifi.c:65
Here is the caller graph for this function:

◆ dhcps_set_mapping()

void dhcps_set_mapping ( struct ip_addr addr,
uint8 mac,
uint32  lease_time 
)

Definition at line 1170 of file dhcpserver.c.

References ip_addr::addr, dhcps_pool::ip, dhcps_pool::lease_timer, dhcps_pool::mac, node_insert_to_list(), NULL, os_memcpy, os_zalloc, _list_node::pnext, and _list_node::pnode.

1171 {
1172 list_node *pback_node = NULL;
1173 list_node *pnode = NULL;
1174 struct dhcps_pool *pdhcps_pool = NULL;
1175 
1176  pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool));
1177  pdhcps_pool->ip.addr = addr->addr;
1178  os_memcpy(pdhcps_pool->mac, mac, sizeof(pdhcps_pool->mac));
1179  pdhcps_pool->lease_timer = lease_time;
1180  pnode = (list_node *)os_zalloc(sizeof(list_node ));
1181  pnode->pnode = pdhcps_pool;
1182  pnode->pnext = NULL;
1183  node_insert_to_list(&plist,pnode);
1184 }
void ICACHE_FLASH_ATTR node_insert_to_list(list_node **phead, list_node *pinsert)
Definition: dhcpserver.c:45
void * pnode
Definition: dhcpserver.h:46
#define NULL
Definition: def.h:47
uint8 mac[6]
Definition: dhcpserver.h:41
uint32 lease_timer
Definition: dhcpserver.h:42
#define os_zalloc(s)
Definition: mem.h:44
#define os_memcpy
Definition: osapi.h:36
struct _list_node * pnext
Definition: dhcpserver.h:47
struct ip_addr ip
Definition: dhcpserver.h:40
static list_node * plist
Definition: dhcpserver.c:34
u32_t addr
Definition: ip_addr.h:45
Here is the call graph for this function:

◆ dhcps_start()

void dhcps_start ( struct ip_info info)

Definition at line 886 of file dhcpserver.c.

References ip_addr::addr, broadcast_dhcps, client_address_plus, DHCPS_SERVER_PORT, eagle_lwip_getif(), handle_dhcp(), ip_info::ip, IP4_ADDR, NULL, os_printf, pcb_dhcps, server_address, dhcps_lease::start_ip, and wifi_softap_init_dhcps_lease().

887 {
888  struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01);
889 
890  if(apnetif->dhcps_pcb != NULL) {
891  udp_remove(apnetif->dhcps_pcb);
892  }
893 
894  pcb_dhcps = udp_new();
895  if (pcb_dhcps == NULL || info ==NULL) {
896  os_printf("dhcps_start(): could not obtain pcb\n");
897  }
898 
899  apnetif->dhcps_pcb = pcb_dhcps;
900 
901  IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
902 
903  server_address = info->ip;
904  if (dns_address.addr == 0) {
906  }
907 
910 
911  udp_bind(pcb_dhcps, &info->ip, DHCPS_SERVER_PORT);
912  udp_recv(pcb_dhcps, handle_dhcp, NULL);
913 #if DHCPS_DEBUG
914  os_printf("dhcps:dhcps_start->udp_recv function Set a receive callback handle_dhcp for UDP_PCB pcb_dhcps\n");
915 #endif
916 
917 }
#define DHCPS_SERVER_PORT
Definition: dhcpserver.h:61
struct ip_addr ip
Definition: ip_addr.h:248
static void ICACHE_FLASH_ATTR wifi_softap_init_dhcps_lease(uint32 ip)
Definition: dhcpserver.c:843
static struct ip_addr broadcast_dhcps
Definition: dhcpserver.c:25
#define NULL
Definition: def.h:47
struct netif * eagle_lwip_getif(uint8 index)
#define os_printf
Definition: osapi.h:62
static void ICACHE_FLASH_ATTR handle_dhcp(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, uint16_t port)
Definition: dhcpserver.c:744
static struct ip_addr dns_address
Definition: dhcpserver.c:30
Definition: netif.h:139
struct ip_addr start_ip
static struct udp_pcb * pcb_dhcps
Definition: dhcpserver.c:24
u32_t addr
Definition: ip_addr.h:45
static struct ip_addr server_address
Definition: dhcpserver.c:26
static struct ip_addr client_address_plus
Definition: dhcpserver.c:28
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
Here is the call graph for this function:

◆ dhcps_stop()

void dhcps_stop ( void  )

Definition at line 919 of file dhcpserver.c.

References eagle_lwip_getif(), node_remove_from_list(), NULL, os_free, pcb_dhcps, plist, _list_node::pnext, and _list_node::pnode.

920 {
921  struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01);
922 
923  udp_disconnect(pcb_dhcps);
924 // dhcps_lease_flag = true;
925  if(apnetif->dhcps_pcb != NULL) {
926  udp_remove(apnetif->dhcps_pcb);
927  apnetif->dhcps_pcb = NULL;
928  }
929 
930  //udp_remove(pcb_dhcps);
931  list_node *pnode = NULL;
932  list_node *pback_node = NULL;
933  pnode = plist;
934  while (pnode != NULL) {
935  pback_node = pnode;
936  pnode = pback_node->pnext;
937  node_remove_from_list(&plist, pback_node);
938  os_free(pback_node->pnode);
939  pback_node->pnode = NULL;
940  os_free(pback_node);
941  pback_node = NULL;
942  }
943 }
void * pnode
Definition: dhcpserver.h:46
#define NULL
Definition: def.h:47
struct netif * eagle_lwip_getif(uint8 index)
struct _list_node * pnext
Definition: dhcpserver.h:47
Definition: netif.h:139
#define os_free(s)
Definition: mem.h:40
void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node *pdelete)
Definition: dhcpserver.c:86
static struct udp_pcb * pcb_dhcps
Definition: dhcpserver.c:24
static list_node * plist
Definition: dhcpserver.c:34
Here is the call graph for this function:

Variable Documentation

◆ dhcps_lease_time

uint32 dhcps_lease_time