Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c94662d

Browse files
committed
Merge branch 'feature/autoip_bind_trigger_callback' into 'master'
lAutoIP trigger callback so that application can know IP changes See merge request sdk/ESP8266_RTOS_SDK!972
2 parents ca5e899 + 8227962 commit c94662d

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

components/lwip/lwip/src/core/ipv4/autoip.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "lwip/autoip.h"
6868
#include "lwip/etharp.h"
6969
#include "lwip/prot/autoip.h"
70+
#include "lwip/dhcp.h"
7071

7172
#include <string.h>
7273

@@ -241,6 +242,13 @@ autoip_bind(struct netif *netif)
241242
netif_set_addr(netif, &autoip->llipaddr, &sn_mask, &gw_addr);
242243
/* interface is used by routing now that an address is set */
243244

245+
#if ESP_LWIP
246+
struct dhcp *dhcp = netif_dhcp_data(netif);
247+
if (dhcp->cb != NULL) {
248+
dhcp->cb(netif);
249+
}
250+
#endif
251+
244252
return ERR_OK;
245253
}
246254

components/lwip/lwip/src/core/ipv4/dhcp.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,4 +1954,23 @@ dhcp_supplied_address(const struct netif *netif)
19541954
return 0;
19551955
}
19561956

1957+
#if ESP_LWIP
1958+
/** Set callback for dhcp, reserved parameter for future use.
1959+
*
1960+
* @param netif the netif from which to remove the struct dhcp
1961+
* @param cb callback for dhcp
1962+
*/
1963+
void dhcp_set_cb(struct netif *netif, void (*cb)(struct netif*))
1964+
{
1965+
struct dhcp *dhcp;
1966+
dhcp = netif_dhcp_data(netif);
1967+
1968+
LWIP_ASSERT("netif != NULL", netif != NULL);
1969+
1970+
if (dhcp != NULL) {
1971+
dhcp->cb = cb;
1972+
}
1973+
}
1974+
#endif
1975+
19571976
#endif /* LWIP_IPV4 && LWIP_DHCP */

components/lwip/lwip/src/include/lwip/dhcp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ struct dhcp
103103
ip4_addr_t offered_si_addr;
104104
char boot_file_name[DHCP_BOOT_FILE_LEN];
105105
#endif /* LWIP_DHCP_BOOTPFILE */
106+
107+
#if ESP_LWIP
108+
void (*cb)(struct netif*); /* callback for dhcp, add a parameter to show dhcp status if needed */
109+
#endif
106110
};
107111

108112

@@ -134,6 +138,10 @@ extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, const ip4_addr_t* ntp_ser
134138

135139
#define netif_dhcp_data(netif) ((struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP))
136140

141+
#ifdef ESP_LWIP
142+
void dhcp_set_cb(struct netif *netif, void (*cb)(struct netif*));
143+
#endif
144+
137145
#ifdef __cplusplus
138146
}
139147
#endif

components/tcpip_adapter/tcpip_adapter_lwip.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,17 @@ static void tcpip_adapter_dhcps_cb(u8_t client_ip[4])
9898

9999
static err_t _dhcp_start(struct tcpip_api_call_data *p)
100100
{
101+
err_t ret;
101102
struct tcpip_adapter_api_call_data *call = (struct tcpip_adapter_api_call_data *)p;
102103

103-
return dhcp_start(call->netif);
104+
ret = dhcp_start(call->netif);
105+
106+
#if ESP_LWIP
107+
if (ret == ERR_OK)
108+
dhcp_set_cb(call->netif, tcpip_adapter_dhcpc_cb);
109+
#endif
110+
111+
return ret;
104112
}
105113

106114
static err_t _dhcp_stop(struct tcpip_api_call_data *p)

0 commit comments

Comments
 (0)