10000 Add capability to have light static DHCP lease by SmartBlug · Pull Request #5594 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Add capability to have light static DHCP lease #5594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add capability to have light static DHCP lease
  • Loading branch information
SmartBlug committed Jan 12, 2019
commit c32b463c2580a083ea43df9ba4cbb8dbe78339e6
1 change: 1 addition & 0 deletions tools/sdk/include/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please);
uint32 wifi_softap_get_dhcps_lease_time(void);
bool wifi_softap_set_dhcps_lease_time(uint32 minute);
bool wifi_softap_reset_dhcps_lease_time(void);
bool wifi_softap_add_dhcps_lease(uint8 *macaddr);

enum dhcp_status wifi_softap_dhcps_status(void);
bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg);
Expand Down
48 changes: 48 additions & 0 deletions tools/sdk/lwip/src/app/dhcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,54 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele
}
}
}

/******************************************************************************
* FunctionName : wifi_softap_add_dhcps_lease
* Description : add static lease on the list, this will be the next available @
* Parameters : mac address
* Returns : true if ok and false if this mac already exist or if all ip are already reserved
*******************************************************************************/
bool ICACHE_FLASH_ATTR wifi_softap_add_dhcps_lease(uint8 *macaddr)
{

struct dhcps_pool *pdhcps_pool = NULL;
list_node *pback_node = NULL;

uint32 start_ip = dhcps_lease.start_ip.addr;
uint32 end_ip = dhcps_lease.end_ip.addr;

for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) {
pdhcps_pool = pback_node->pnode;
if (os_memcmp(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac)) == 0){
#if DHCPS_DEBUG
os_printf("this mac already exist");
#endif
return false;
}
else start_ip = htonl((ntohl(start_ip) + 1));
}

if (start_ip>end_ip) {
#if DHCPS_DEBUG
os_printf("no more ip available");
#endif
return false;
}

pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool));
pdhcps_pool->ip.addr = start_ip;
os_memcpy(pdhcps_pool->mac, macaddr, sizeof(pdhcps_pool->mac));
pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER;
pdhcps_pool->type = DHCPS_TYPE_STATIC;
pdhcps_pool->state = DHCPS_STATE_ONLINE;
pback_node = (list_node *)os_zalloc(sizeof(list_node ));
pback_node->pnode = pdhcps_pool;
pback_node->pnext = NULL;
node_insert_to_list(&plist,pback_node);

return true;
}

///////////////////////////////////////////////////////////////////////////////////
/*
* ��DHCP msg��Ϣ�ṹ����������
Expand Down
0