Skip to content

Commit 8ba6b9c

Browse files
committed
Merge branch 'feature/add_vendor_class_id_option_in_dhcp' into 'master'
feat(lwip): add vendor class id option in lwip See merge request sdk/ESP8266_NONOS_SDK!125
2 parents 742f7f6 + e5971e1 commit 8ba6b9c

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ phy:
1818

1919
gitlab:
2020
driver : c37b846e
21-
lwip : 23a2c547
21+
lwip : 10977b97
2222
mbedtls : c37b846e

lib/liblwip.a

2.65 KB
Binary file not shown.

third_party/include/lwip/dhcp.h

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ void dhcp_inform(struct netif *netif);
123123
/** Handle a possible change in the network configuration */
124124
void dhcp_network_changed(struct netif *netif);
125125

126+
err_t dhcp_set_vendor_class_identifier(uint8_t len, char *str);
127+
126128
/** if enabled, check whether the offered IP address is not in use, using ARP */
127129
#if DHCP_DOES_ARP_CHECK
128130
void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr);

third_party/lwip/core/dhcp.c

+66
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
174174
/* always add the DHCP options trailer to end and pad */
175175
static void dhcp_option_trailer(struct dhcp *dhcp);
176176

177+
static int vendor_class_len = 0;
178+
static char * vendor_class_buf = NULL;
179+
err_t dhcp_set_vendor_class_identifier(uint8_t len, char *str) {
180+
if (len == 0)
181+
return ERR_ARG;
182+
183+
if (str == NULL)
184+
return ERR_ARG;
185+
186+
vendor_class_buf = (char *)mem_zalloc(len + 1);
187+
if (vendor_class_buf == NULL) {
188+
return ERR_MEM;
189+
}
190+
vendor_class_len = len;
191+
memcpy(vendor_class_buf, str, len);
192+
}
193+
177194
/**
178195
* Back-off the DHCP client (because of a received NAK response).
179196
*
@@ -323,6 +340,18 @@ dhcp_select(struct netif *netif)
323340
}
324341
#endif /* LWIP_NETIF_HOSTNAME */
325342

343+
if (vendor_class_buf != NULL) {
344+
const char *p = (const char*)vendor_class_buf;
345+
u8_t namelen = (u8_t)os_strlen(p);
346+
if (vendor_class_len > 0) {
347+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
348+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
349+
while (*p) {
350+
dhcp_option_byte(dhcp, *p++);
351+
}
352+
}
353+
}
354+
326355
dhcp_option_trailer(dhcp);
327356
/* shrink the pbuf to the actual content length */
328357
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
@@ -920,6 +949,19 @@ dhcp_discover(struct netif *netif)
920949
}
921950
}
922951
#endif /* LWIP_NETIF_HOSTNAME */
952+
953+
if (vendor_class_buf != NULL) {
954+
const char *p = (const char*)vendor_class_buf;
955+
u8_t namelen = (u8_t)os_strlen(p);
956+
if (vendor_class_len > 0) {
957+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
958+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
959+
while (*p) {
960+
dhcp_option_byte(dhcp, *p++);
961+
}
962+
}
963+
}
964+
923965
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/);
924966
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
925967
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
@@ -1101,6 +1143,18 @@ dhcp_renew(struct netif *netif)
11011143
}
11021144
#endif /* LWIP_NETIF_HOSTNAME */
11031145

1146+
if (vendor_class_buf != NULL) {
1147+
const char *p = (const char*)vendor_class_buf;
1148+
u8_t namelen = (u8_t)os_strlen(p);
1149+
if (vendor_class_len > 0) {
1150+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
1151+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
1152+
while (*p) {
1153+
dhcp_option_byte(dhcp, *p++);
1154+
}
1155+
}
1156+
}
1157+
11041158
#if 0
11051159
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
11061160
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));
@@ -1164,6 +1218,18 @@ dhcp_rebind(struct netif *netif)
11641218
}
11651219
#endif /* LWIP_NETIF_HOSTNAME */
11661220

1221+
if (vendor_class_buf != NULL) {
1222+
const char *p = (const char*)vendor_class_buf;
1223+
u8_t namelen = (u8_t)os_strlen(p);
1224+
if (vendor_class_len > 0) {
1225+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
1226+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
1227+
while (*p) {
1228+
dhcp_option_byte(dhcp, *p++);
1229+
}
1230+
}
1231+
}
1232+
11671233
#if 1
11681234
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
11691235
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));

0 commit comments

Comments
 (0)