Skip to content

Commit 5d9bfe3

Browse files
committed
Add capability to have light static DHCP lease
1 parent 7c2e071 commit 5d9bfe3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Diff for: tools/sdk/include/user_interface.h

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please);
385385
uint32 wifi_softap_get_dhcps_lease_time(void);
386386
bool wifi_softap_set_dhcps_lease_time(uint32 minute);
387387
bool wifi_softap_reset_dhcps_lease_time(void);
388+
bool wifi_softap_add_dhcps_lease(uint8 *macaddr);
388389

389390
enum dhcp_status wifi_softap_dhcps_status(void);
390391
bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg);

Diff for: tools/sdk/lwip/src/app/dhcpserver.c

+48
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,54 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele
104104
}
105105
}
106106
}
107+
108+
/******************************************************************************
109+
* FunctionName : wifi_softap_add_dhcps_lease
110+
* Description : add static lease on the list, this will be the next available @
111+
* Parameters : mac address
112+
* Returns : true if ok and false if this mac already exist or if all ip are already reserved
113+
*******************************************************************************/
114+
bool ICACHE_FLASH_ATTR wifi_softap_add_dhcps_lease(uint8 *macaddr)
115+
{
116+
117+
struct dhcps_pool *pdhcps_pool = NULL;
118+
list_node *pback_node = NULL;
119+
120+
uint32 start_ip = dhcps_lease.start_ip.addr;
121+
uint32 end_ip = dhcps_lease.end_ip.addr;
122+
123+
for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) {
124+
pdhcps_pool = pback_node->pnode;
125+
if (os_memcmp(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)) == 0){
126+
#if DHCPS_DEBUG
127+
os_printf("this mac already exist");
128+
#endif
129+
return false;
130+
}
131+
else start_ip = htonl((ntohl(start_ip) + 1));
132+
}
133+
134+
if (start_ip>end_ip) {
135+
#if DHCPS_DEBUG
136+
os_printf("no more ip available");
137+
#endif
138+
return false;
139+
}
140+
141+
pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool));
142+
pdhcps_pool->ip.addr = start_ip;
143+
os_memcpy(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac));
144+
pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER;
145+
pdhcps_pool->type = DHCPS_TYPE_STATIC;
146+
pdhcps_pool->state = DHCPS_STATE_ONLINE;
147+
pback_node = (list_node *)os_zalloc(sizeof(list_node ));
148+
pback_node->pnode = pdhcps_pool;
149+
pback_node->pnext = NULL;
150+
node_insert_to_list(&plist,pback_node);
151+
152+
return true;
153+
}
154+
107155
///////////////////////////////////////////////////////////////////////////////////
108156
/*
109157
* ��DHCP msg��Ϣ�ṹ����������

0 commit comments

Comments
 (0)