Skip to content

Commit 26b2f65

Browse files
committed
Merge branch 'feature/add_vendor_class_id_option_in_dhcp' into 'release/v2.2.x'
feat(lwip): add vendor class id option in lwip See merge request sdk/ESP8266_NONOS_SDK!134
2 parents 57fa2e7 + 03f6f12 commit 26b2f65

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 : 68fc7b06
21-
lwip : d481a1f7
21+
lwip : b802c938
2222
mbedtls : e4dace14

lib/liblwip.a

2.61 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
@@ -172,6 +172,23 @@ static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
172172
/* always add the DHCP options trailer to end and pad */
173173
static void dhcp_option_trailer(struct dhcp *dhcp);
174174

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

341+
if (vendor_class_buf != NULL) {
342+
const char *p = (const char*)vendor_class_buf;
343+
u8_t namelen = (u8_t)os_strlen(p);
344+
if (vendor_class_len > 0) {
345+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
346+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
347+
while (*p) {
348+
dhcp_option_byte(dhcp, *p++);
349+
}
350+
}
351+
}
352+
324353
dhcp_option_trailer(dhcp);
325354
/* shrink the pbuf to the actual content length */
326355
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
@@ -918,6 +947,19 @@ dhcp_discover(struct netif *netif)
918947
}
919948
}
920949
#endif /* LWIP_NETIF_HOSTNAME */
950+
951+
if (vendor_class_buf != NULL) {
952+
const char *p = (const char*)vendor_class_buf;
953+
u8_t namelen = (u8_t)os_strlen(p);
954+
if (vendor_class_len > 0) {
955+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
956+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
957+
while (*p) {
958+
dhcp_option_byte(dhcp, *p++);
959+
}
960+
}
961+
}
962+
921963
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/);
922964
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
923965
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
@@ -1099,6 +1141,18 @@ dhcp_renew(struct netif *netif)
10991141
}
11001142
#endif /* LWIP_NETIF_HOSTNAME */
11011143

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

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

0 commit comments

Comments
 (0)