mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
recompile DHCP server function
modify DHCP data parameter type in calling DHCP interface.
This commit is contained in:
parent
aec816520c
commit
62c891735b
@ -92,6 +92,13 @@ static dhcps_lease_t dhcps_poll;
|
|||||||
static dhcps_offer_t dhcps_offer = 0xFF;
|
static dhcps_offer_t dhcps_offer = 0xFF;
|
||||||
static dhcps_time_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
|
static dhcps_time_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* FunctionName : dhcps_option_info
|
||||||
|
* Description : get the DHCP message option info
|
||||||
|
* Parameters : op_id -- DHCP message option id
|
||||||
|
* opt_len -- DHCP message option length
|
||||||
|
* Returns : DHCP message option addr
|
||||||
|
*******************************************************************************/
|
||||||
void *dhcps_option_info(u8_t op_id, u32_t opt_len)
|
void *dhcps_option_info(u8_t op_id, u32_t opt_len)
|
||||||
{
|
{
|
||||||
void* option_arg = NULL;
|
void* option_arg = NULL;
|
||||||
@ -117,7 +124,8 @@ void *dhcps_option_info(u8_t op_id, u32_t opt_len)
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* FunctionName : node_insert_to_list
|
* FunctionName : node_insert_to_list
|
||||||
* Description : insert the node to the list
|
* Description : insert the node to the list
|
||||||
* Parameters : arg -- Additional argument to pass to the callback function
|
* Parameters : phead -- the head node of the list
|
||||||
|
* pinsert -- the insert node of the list
|
||||||
* Returns : none
|
* Returns : none
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void node_insert_to_list(list_node **phead, list_node* pinsert)
|
void node_insert_to_list(list_node **phead, list_node* pinsert)
|
||||||
@ -157,7 +165,8 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* FunctionName : node_delete_from_list
|
* FunctionName : node_delete_from_list
|
||||||
* Description : remove the node from list
|
* Description : remove the node from list
|
||||||
* Parameters : arg -- Additional argument to pass to the callback function
|
* Parameters : phead -- the head node of the list
|
||||||
|
* pdelete -- the remove node of the list
|
||||||
* Returns : none
|
* Returns : none
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void node_remove_from_list(list_node **phead, list_node* pdelete)
|
void node_remove_from_list(list_node **phead, list_node* pdelete)
|
||||||
@ -182,16 +191,13 @@ void node_remove_from_list(list_node **phead, list_node* pdelete)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD>DHCP msg<EFBFBD><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* FunctionName : add_msg_type
|
||||||
*
|
* Description : add TYPE option of DHCP message
|
||||||
* @param optptr -- DHCP msg<EFBFBD><EFBFBD>Ϣλ<EFBFBD><EFBFBD>
|
* Parameters : optptr -- the addr of DHCP message option
|
||||||
* @param type -- Ҫ<EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>option
|
* Returns : the addr of DHCP message option
|
||||||
*
|
*******************************************************************************/
|
||||||
* @return uint8_t* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DHCP msgƫ<EFBFBD>Ƶ<EFBFBD>ַ
|
|
||||||
*/
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static u8_t* add_msg_type(u8_t *optptr, u8_t type)
|
static u8_t* add_msg_type(u8_t *optptr, u8_t type)
|
||||||
{
|
{
|
||||||
*optptr++ = DHCP_OPTION_MSG_TYPE;
|
*optptr++ = DHCP_OPTION_MSG_TYPE;
|
||||||
@ -199,15 +205,13 @@ static u8_t* add_msg_type(u8_t *optptr, u8_t type)
|
|||||||
*optptr++ = type;
|
*optptr++ = type;
|
||||||
return optptr;
|
return optptr;
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD>DHCP msg<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>offerӦ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* FunctionName : add_offer_options
|
||||||
*
|
* Description : add OFFER option of DHCP message
|
||||||
* @param optptr -- DHCP msg<EFBFBD><EFBFBD>Ϣλ<EFBFBD><EFBFBD>
|
* Parameters : optptr -- the addr of DHCP message option
|
||||||
*
|
* Returns : the addr of DHCP message option
|
||||||
* @return uint8_t* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DHCP msgƫ<EFBFBD>Ƶ<EFBFBD>ַ
|
*******************************************************************************/
|
||||||
*/
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static u8_t* add_offer_options(u8_t *optptr)
|
static u8_t* add_offer_options(u8_t *optptr)
|
||||||
{
|
{
|
||||||
ip4_addr_t ipadd;
|
ip4_addr_t ipadd;
|
||||||
@ -310,23 +314,25 @@ static u8_t* add_offer_options(u8_t *optptr)
|
|||||||
|
|
||||||
return optptr;
|
return optptr;
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD>DHCP msg<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* FunctionName : add_end
|
||||||
*
|
* Description : add end option of DHCP message
|
||||||
* @param optptr -- DHCP msg<EFBFBD><EFBFBD>Ϣλ<EFBFBD><EFBFBD>
|
* Parameters : optptr -- the addr of DHCP message option
|
||||||
*
|
* Returns : the addr of DHCP message option
|
||||||
* @return uint8_t* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DHCP msgƫ<EFBFBD>Ƶ<EFBFBD>ַ
|
*******************************************************************************/
|
||||||
*/
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static u8_t* add_end(u8_t *optptr)
|
static u8_t* add_end(u8_t *optptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
*optptr++ = DHCP_OPTION_END;
|
*optptr++ = DHCP_OPTION_END;
|
||||||
return optptr;
|
return optptr;
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
/******************************************************************************
|
||||||
|
* FunctionName : create_msg
|
||||||
|
* Description : create response message
|
||||||
|
* Parameters : m -- DHCP message info
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
static void create_msg(struct dhcps_msg *m)
|
static void create_msg(struct dhcps_msg *m)
|
||||||
{
|
{
|
||||||
ip4_addr_t client;
|
ip4_addr_t client;
|
||||||
@ -359,25 +365,17 @@ static void create_msg(struct dhcps_msg *m)
|
|||||||
|
|
||||||
memset((char *) m->options, 0, sizeof(m->options));
|
memset((char *) m->options, 0, sizeof(m->options));
|
||||||
|
|
||||||
// u32_t temp = 0x63538263;
|
u32_t magic_cookie_temp = magic_cookie;
|
||||||
// u8 *log_temp = (u8 *)&temp;
|
|
||||||
|
|
||||||
u32_t magic_cookie_temp = magic_cookie;
|
|
||||||
|
|
||||||
//extern bool system_get_string_from_flash(void *flash_str, void* ram_str,uint8 ram_str_len);
|
|
||||||
//system_get_string_from_flash((void *)(&magic_cookie), (void *)(&magic_cookie_temp),4);
|
|
||||||
//printf("ck_tmp3:%08X\n",magic_cookie_temp);
|
|
||||||
|
|
||||||
//memcpy((char *) m->options, &magic_cookie, sizeof(magic_cookie));
|
|
||||||
memcpy((char *) m->options, &magic_cookie_temp, sizeof(magic_cookie_temp));
|
memcpy((char *) m->options, &magic_cookie_temp, sizeof(magic_cookie_temp));
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>OFFER
|
* FunctionName : send_offer
|
||||||
*
|
* Description : DHCP message OFFER Response
|
||||||
* @param -- m ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>DHCP msg<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* Parameters : m -- DHCP message info
|
||||||
*/
|
* Returns : none
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
*******************************************************************************/
|
||||||
static void send_offer(struct dhcps_msg *m)
|
static void send_offer(struct dhcps_msg *m)
|
||||||
{
|
{
|
||||||
u8_t *end;
|
u8_t *end;
|
||||||
@ -440,13 +438,13 @@ static void send_offer(struct dhcps_msg *m)
|
|||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>NAK<EFBFBD><EFBFBD>Ϣ
|
* FunctionName : send_nak
|
||||||
*
|
* Description : DHCP message NACK Response
|
||||||
* @param m ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>DHCP msg<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* Parameters : m -- DHCP message info
|
||||||
*/
|
* Returns : none
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
*******************************************************************************/
|
||||||
static void send_nak(struct dhcps_msg *m)
|
static void send_nak(struct dhcps_msg *m)
|
||||||
{
|
{
|
||||||
u8_t *end;
|
u8_t *end;
|
||||||
@ -508,13 +506,13 @@ static void send_nak(struct dhcps_msg *m)
|
|||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ACK<EFBFBD><EFBFBD>DHCP<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>
|
* FunctionName : send_ack
|
||||||
*
|
* Description : DHCP message ACK Response
|
||||||
* @param m ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>DHCP msg<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* Parameters : m -- DHCP message info
|
||||||
*/
|
* Returns : none
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
*******************************************************************************/
|
||||||
static void send_ack(struct dhcps_msg *m)
|
static void send_ack(struct dhcps_msg *m)
|
||||||
{
|
{
|
||||||
u8_t *end;
|
u8_t *end;
|
||||||
@ -578,23 +576,21 @@ static void send_ack(struct dhcps_msg *m)
|
|||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DHCP<EFBFBD>ͻ<EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DHCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>ͬ<EFBFBD><EFBFBD>DHCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
* FunctionName : parse_options
|
||||||
*
|
* Description : parse DHCP message options
|
||||||
* @param optptr DHCP msg<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* Parameters : optptr -- DHCP message option info
|
||||||
* @param len <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD>?(byte)
|
* len -- DHCP message option length
|
||||||
*
|
* Returns : none
|
||||||
* @return uint8_t <EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DHCP Server״ֵ̬
|
*******************************************************************************/
|
||||||
*/
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
static u8_t parse_options(u8_t *optptr, s16_t len)
|
static u8_t parse_options(u8_t *optptr, s16_t len)
|
||||||
{
|
{
|
||||||
ip4_addr_t client;
|
ip4_addr_t client;
|
||||||
bool is_dhcp_parse_end = false;
|
bool is_dhcp_parse_end = false;
|
||||||
struct dhcps_state s;
|
struct dhcps_state s;
|
||||||
|
|
||||||
client.addr = *( (uint32_t *) &client_address);// Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD>DHCP<43>ͻ<EFBFBD><CDBB>˵<EFBFBD>IP
|
client.addr = *( (uint32_t *) &client_address);
|
||||||
|
|
||||||
u8_t *end = optptr + len;
|
u8_t *end = optptr + len;
|
||||||
u16_t type = 0;
|
u16_t type = 0;
|
||||||
@ -679,25 +675,21 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
|
|||||||
#endif
|
#endif
|
||||||
return s.state;
|
return s.state;
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
/******************************************************************************
|
||||||
|
* FunctionName : parse_msg
|
||||||
|
* Description : parse DHCP message from netif
|
||||||
|
* Parameters : m -- DHCP message info
|
||||||
|
* len -- DHCP message length
|
||||||
|
* Returns : DHCP message type
|
||||||
|
*******************************************************************************/
|
||||||
static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||||
{
|
{
|
||||||
|
if(memcmp((char *)m->options,&magic_cookie,sizeof(magic_cookie)) == 0){
|
||||||
//u32 magic_cookie_temp = magic_cookie;
|
|
||||||
//extern bool system_get_string_from_flash(void *flash_str, void* ram_str,uint8 ram_str_len);
|
|
||||||
//system_get_string_from_flash((void *)(&magic_cookie), (void *)(&magic_cookie_temp),4);
|
|
||||||
//printf("ck_tmp4:%08X\n",magic_cookie_temp);
|
|
||||||
|
|
||||||
if(memcmp((char *)m->options,
|
|
||||||
&magic_cookie,
|
|
||||||
sizeof(magic_cookie)) == 0){
|
|
||||||
#if DHCPS_DEBUG
|
#if DHCPS_DEBUG
|
||||||
DHCPS_LOG("dhcps: len = %d\n", len);
|
DHCPS_LOG("dhcps: len = %d\n", len);
|
||||||
#endif
|
#endif
|
||||||
|
ip4_addr_t addr_tmp;
|
||||||
ip4_addr_t addr_tmp;
|
|
||||||
// memcpy((char *)old_xid, (char *)m->xid, sizeof(m->xid));
|
|
||||||
|
|
||||||
struct dhcps_pool *pdhcps_pool = NULL;
|
struct dhcps_pool *pdhcps_pool = NULL;
|
||||||
list_node *pnode = NULL;
|
list_node *pnode = NULL;
|
||||||
@ -705,17 +697,13 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
|||||||
ip4_addr_t first_address;
|
ip4_addr_t first_address;
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
|
|
||||||
// POOL_START:
|
|
||||||
first_address.addr = dhcps_poll.start_ip.addr;
|
first_address.addr = dhcps_poll.start_ip.addr;
|
||||||
client_address.addr = client_address_plus.addr;
|
client_address.addr = client_address_plus.addr;
|
||||||
renew = false;
|
renew = false;
|
||||||
// addr_tmp.addr = htonl(client_address_plus.addr);
|
|
||||||
// addr_tmp.addr++;
|
|
||||||
// client_address_plus.addr = htonl(addr_tmp.addr);
|
|
||||||
for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) {
|
for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) {
|
||||||
pdhcps_pool = pback_node->pnode;
|
pdhcps_pool = pback_node->pnode;
|
||||||
if (memcmp(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac)) == 0){
|
if (memcmp(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac)) == 0){
|
||||||
// printf("the same device request ip\n");
|
|
||||||
if (memcmp(&pdhcps_pool->ip.addr, m->ciaddr, sizeof(pdhcps_pool->ip.addr)) == 0) {
|
if (memcmp(&pdhcps_pool->ip.addr, m->ciaddr, sizeof(pdhcps_pool->ip.addr)) == 0) {
|
||||||
renew = true;
|
renew = true;
|
||||||
}
|
}
|
||||||
@ -724,8 +712,6 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
|||||||
pnode = pback_node;
|
pnode = pback_node;
|
||||||
goto POOL_CHECK;
|
goto POOL_CHECK;
|
||||||
} else if (pdhcps_pool->ip.addr == client_address_plus.addr){
|
} else if (pdhcps_pool->ip.addr == client_address_plus.addr){
|
||||||
// client_address.addr = client_address_plus.addr;
|
|
||||||
// printf("the ip addr has been request\n");
|
|
||||||
addr_tmp.addr = htonl(client_address_plus.addr);
|
addr_tmp.addr = htonl(client_address_plus.addr);
|
||||||
addr_tmp.addr++;
|
addr_tmp.addr++;
|
||||||
client_address_plus.addr = htonl(addr_tmp.addr);
|
client_address_plus.addr = htonl(addr_tmp.addr);
|
||||||
@ -783,7 +769,6 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
|||||||
free(pdhcps_pool);
|
free(pdhcps_pool);
|
||||||
pdhcps_pool = NULL;
|
pdhcps_pool = NULL;
|
||||||
}
|
}
|
||||||
// client_address_plus.addr = dhcps_poll.start_ip.addr;
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,22 +788,25 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
|||||||
memset(&client_address,0x0,sizeof(client_address));
|
memset(&client_address,0x0,sizeof(client_address));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TO_DO , set (ap-> sta) ip_addr no use.
|
|
||||||
//if ( tcpip_dep_set_ip_info(STATION_IF, struct ip_info *if_ip) == false )
|
|
||||||
//return 0;
|
|
||||||
//if (wifi_softap_set_station_info(m->chaddr, &client_address) == false) {
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
#if DHCPS_DEBUG
|
#if DHCPS_DEBUG
|
||||||
DHCPS_LOG("dhcps: xid changed\n");
|
DHCPS_LOG("dhcps: xid changed\n");
|
||||||
DHCPS_LOG("dhcps: client_address.addr = %x\n", client_address.addr);
|
DHCPS_LOG("dhcps: client_address.addr = %x\n", client_address.addr);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* FunctionName : handle_dhcp
|
||||||
|
* Description : If an incoming DHCP message is in response to us, then trigger the state machine
|
||||||
|
* Parameters : arg -- arg user supplied argument (udp_pcb.recv_arg)
|
||||||
|
* pcb -- the udp_pcb which received data
|
||||||
|
* p -- the packet buffer that was received
|
||||||
|
* addr -- the remote IP address from which the packet was received
|
||||||
|
* port -- the remote port from which the packet was received
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
static void handle_dhcp(void *arg,
|
static void handle_dhcp(void *arg,
|
||||||
struct udp_pcb *pcb,
|
struct udp_pcb *pcb,
|
||||||
struct pbuf *p,
|
struct pbuf *p,
|
||||||
@ -882,9 +870,6 @@ static void handle_dhcp(void *arg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* DHCP <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
*/
|
|
||||||
#if DHCPS_DEBUG
|
#if DHCPS_DEBUG
|
||||||
DHCPS_LOG("dhcps: handle_dhcp-> parse_msg(p)\n");
|
DHCPS_LOG("dhcps: handle_dhcp-> parse_msg(p)\n");
|
||||||
#endif
|
#endif
|
||||||
@ -918,7 +903,13 @@ static void handle_dhcp(void *arg,
|
|||||||
free(pmsg_dhcps);
|
free(pmsg_dhcps);
|
||||||
pmsg_dhcps = NULL;
|
pmsg_dhcps = NULL;
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
/******************************************************************************
|
||||||
|
* FunctionName : dhcps_poll_set
|
||||||
|
* Description : set ip poll from start to end for station
|
||||||
|
* Parameters : ip -- The current ip addr
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
static void dhcps_poll_set(u32_t ip)
|
static void dhcps_poll_set(u32_t ip)
|
||||||
{
|
{
|
||||||
u32_t softap_ip = 0,local_ip = 0;
|
u32_t softap_ip = 0,local_ip = 0;
|
||||||
@ -956,11 +947,16 @@ static void dhcps_poll_set(u32_t ip)
|
|||||||
dhcps_poll.start_ip.addr = htonl(dhcps_poll.start_ip.addr);
|
dhcps_poll.start_ip.addr = htonl(dhcps_poll.start_ip.addr);
|
||||||
dhcps_poll.end_ip.addr= htonl(dhcps_poll.end_ip.addr);
|
dhcps_poll.end_ip.addr= htonl(dhcps_poll.end_ip.addr);
|
||||||
}
|
}
|
||||||
// printf("start_ip = 0x%x, end_ip = 0x%x\n",dhcps_poll.start_ip, dhcps_poll.end_ip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
* FunctionName : dhcps_start
|
||||||
|
* Description : start dhcp server function
|
||||||
|
* Parameters : netif -- The current netif addr
|
||||||
|
* : info -- The current ip info
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
void dhcps_start(struct netif *netif, struct ip_info *info)
|
void dhcps_start(struct netif *netif, struct ip_info *info)
|
||||||
{
|
{
|
||||||
struct netif * apnetif =netif;
|
struct netif * apnetif =netif;
|
||||||
@ -990,6 +986,12 @@ void dhcps_start(struct netif *netif, struct ip_info *info)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* FunctionName : dhcps_stop
|
||||||
|
* Description : stop dhcp server function
|
||||||
|
* Parameters : netif -- The current netif addr
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
void dhcps_stop(struct netif *netif )
|
void dhcps_stop(struct netif *netif )
|
||||||
{
|
{
|
||||||
struct netif * apnetif = netif;
|
struct netif * apnetif = netif;
|
||||||
@ -999,7 +1001,7 @@ void dhcps_stop(struct netif *netif )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
udp_disconnect(pcb_dhcps);
|
udp_disconnect(pcb_dhcps);
|
||||||
// dhcps_poll_flag = true;
|
|
||||||
if(apnetif->dhcps_pcb != NULL) {
|
if(apnetif->dhcps_pcb != NULL) {
|
||||||
udp_remove(apnetif->dhcps_pcb);
|
udp_remove(apnetif->dhcps_pcb);
|
||||||
apnetif->dhcps_pcb = NULL;
|
apnetif->dhcps_pcb = NULL;
|
||||||
@ -1019,6 +1021,12 @@ void dhcps_stop(struct netif *netif )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* FunctionName : kill_oldest_dhcps_pool
|
||||||
|
* Description : remove the oldest node from list
|
||||||
|
* Parameters : none
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
static void kill_oldest_dhcps_pool(void)
|
static void kill_oldest_dhcps_pool(void)
|
||||||
{
|
{
|
||||||
list_node *pre = NULL, *p = NULL;
|
list_node *pre = NULL, *p = NULL;
|
||||||
@ -1045,6 +1053,12 @@ static void kill_oldest_dhcps_pool(void)
|
|||||||
minp = NULL;
|
minp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* FunctionName : dhcps_coarse_tmr
|
||||||
|
* Description : the lease time count
|
||||||
|
* Parameters : none
|
||||||
|
* Returns : none
|
||||||
|
*******************************************************************************/
|
||||||
void dhcps_coarse_tmr(void)
|
void dhcps_coarse_tmr(void)
|
||||||
{
|
{
|
||||||
u8_t num_dhcps_pool = 0;
|
u8_t num_dhcps_pool = 0;
|
||||||
@ -1073,7 +1087,13 @@ void dhcps_coarse_tmr(void)
|
|||||||
kill_oldest_dhcps_pool();
|
kill_oldest_dhcps_pool();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search ip address based on mac address */
|
/******************************************************************************
|
||||||
|
* FunctionName : dhcp_search_ip_on_mac
|
||||||
|
* Description : Search ip address based on mac address
|
||||||
|
* Parameters : mac -- The MAC addr
|
||||||
|
* ip -- The IP info
|
||||||
|
* Returns : true or false
|
||||||
|
*******************************************************************************/
|
||||||
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip)
|
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip)
|
||||||
{
|
{
|
||||||
struct dhcps_pool *pdhcps_pool = NULL;
|
struct dhcps_pool *pdhcps_pool = NULL;
|
||||||
|
@ -110,12 +110,12 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
||||||
esp_err_t tcpip_adapter_dhcps_option(u8_t opt_op, u8_t opt_id, void* opt_val, u32_t opt_len);
|
esp_err_t tcpip_adapter_dhcps_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len);
|
||||||
esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if);
|
||||||
esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
||||||
esp_err_t tcpip_adapter_dhcpc_option(u8_t opt_op, u8_t opt_id, void* opt_val, u32_t opt_len);
|
esp_err_t tcpip_adapter_dhcpc_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len);
|
||||||
esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if);
|
||||||
esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcps_option(u8_t opt_op, u8_t opt_id, void* opt_val, u32_t opt_len)
|
esp_err_t tcpip_adapter_dhcps_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len)
|
||||||
{
|
{
|
||||||
void* opt_info = dhcps_option_info(opt_id, opt_len);
|
void* opt_info = dhcps_option_info(opt_id, opt_len);
|
||||||
if (opt_info == NULL || opt_val == NULL)
|
if (opt_info == NULL || opt_val == NULL)
|
||||||
@ -309,13 +309,13 @@ esp_err_t tcpip_adapter_dhcps_option(u8_t opt_op, u8_t opt_id, void* opt_val, u3
|
|||||||
|
|
||||||
switch (opt_id){
|
switch (opt_id){
|
||||||
case IP_ADDRESS_LEASE_TIME:
|
case IP_ADDRESS_LEASE_TIME:
|
||||||
*(u32_t*)opt_val = *(u32_t*)opt_info;
|
*(uint32_t*)opt_val = *(uint32_t*)opt_info;
|
||||||
break;
|
break;
|
||||||
case REQUESTED_IP_ADDRESS:
|
case REQUESTED_IP_ADDRESS:
|
||||||
memcpy(opt_val, opt_info, opt_len);
|
memcpy(opt_val, opt_info, opt_len);
|
||||||
break;
|
break;
|
||||||
case ROUTER_SOLICITATION_ADDRESS:
|
case ROUTER_SOLICITATION_ADDRESS:
|
||||||
*(u8_t *)opt_val = (*(u8_t *)opt_info) & OFFER_ROUTER;
|
*(uint8_t *)opt_val = (*(uint8_t *)opt_info) & OFFER_ROUTER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -326,14 +326,14 @@ esp_err_t tcpip_adapter_dhcps_option(u8_t opt_op, u8_t opt_id, void* opt_val, u3
|
|||||||
|
|
||||||
switch (opt_id){
|
switch (opt_id){
|
||||||
case IP_ADDRESS_LEASE_TIME:
|
case IP_ADDRESS_LEASE_TIME:
|
||||||
if (*(u32_t*)opt_val != 0)
|
if (*(uint32_t*)opt_val != 0)
|
||||||
*(u32_t*)opt_info = *(u32_t*)opt_val;
|
*(uint32_t*)opt_info = *(uint32_t*)opt_val;
|
||||||
else
|
else
|
||||||
*(u32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
|
*(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
|
||||||
break;
|
break;
|
||||||
case REQUESTED_IP_ADDRESS:{
|
case REQUESTED_IP_ADDRESS:{
|
||||||
struct ip_info info;
|
struct ip_info info;
|
||||||
u32_t softap_ip = 0;u32_t start_ip = 0;u32_t end_ip = 0;
|
uint32_t softap_ip = 0;uint32_t start_ip = 0;uint32_t end_ip = 0;
|
||||||
struct dhcps_lease *poll = opt_val;
|
struct dhcps_lease *poll = opt_val;
|
||||||
|
|
||||||
memset(&info, 0x00, sizeof(struct ip_info));
|
memset(&info, 0x00, sizeof(struct ip_info));
|
||||||
@ -360,7 +360,7 @@ esp_err_t tcpip_adapter_dhcps_option(u8_t opt_op, u8_t opt_id, void* opt_val, u3
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROUTER_SOLICITATION_ADDRESS:
|
case ROUTER_SOLICITATION_ADDRESS:
|
||||||
*(u8_t *)opt_info = (*(u8_t *)opt_val) & OFFER_ROUTER;
|
*(uint8_t *)opt_info = (*(uint8_t *)opt_val) & OFFER_ROUTER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -432,8 +432,9 @@ esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcpc_option(u8_t opt_op, u8_t opt_id, void* opt_val, u32_t opt_len)
|
esp_err_t tcpip_adapter_dhcpc_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len)
|
||||||
{
|
{
|
||||||
|
//TODO: when dhcp request timeout,change the retry count
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user