@@ -209,6 +209,12 @@ static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif);
209
209
/* always add the DHCP options trailer to end and pad */
210
210
static void dhcp_option_trailer (struct dhcp * dhcp );
211
211
212
+ #if ESP_DHCP_OPTION
213
+ /* set dhcp option61 */
214
+ static void dhcp_option_clientid (struct dhcp * dhcp , struct netif * netif );
215
+ /* set dhcp option60 */
216
+ static void dhcp_option_vendor (struct dhcp * dhcp , struct netif * netif );
217
+ #endif
212
218
/** Ensure DHCP PCB is allocated and bound */
213
219
static err_t
214
220
dhcp_inc_pcb_refcount (void )
@@ -362,6 +368,10 @@ dhcp_select(struct netif *netif)
362
368
/* create and initialize the DHCP message header */
363
369
result = dhcp_create_msg (netif , dhcp , DHCP_REQUEST );
364
370
if (result == ERR_OK ) {
371
+ #if ESP_DHCP_OPTION
372
+ dhcp_option_clientid (dhcp , netif );
373
+ dhcp_option_vendor (dhcp , netif );
374
+ #endif
365
375
dhcp_option (dhcp , DHCP_OPTION_MAX_MSG_SIZE , DHCP_OPTION_MAX_MSG_SIZE_LEN );
366
376
dhcp_option_short (dhcp , DHCP_MAX_MSG_LEN (netif ));
367
377
@@ -980,13 +990,22 @@ dhcp_discover(struct netif *netif)
980
990
if (result == ERR_OK ) {
981
991
LWIP_DEBUGF (DHCP_DEBUG | LWIP_DBG_TRACE , ("dhcp_discover: making request\n" ));
982
992
993
+ #if ESP_DHCP_OPTION
994
+ dhcp_option_clientid (dhcp , netif );
995
+ dhcp_option_vendor (dhcp , netif );
996
+ #endif
983
997
dhcp_option (dhcp , DHCP_OPTION_MAX_MSG_SIZE , DHCP_OPTION_MAX_MSG_SIZE_LEN );
984
998
dhcp_option_short (dhcp , DHCP_MAX_MSG_LEN (netif ));
985
999
986
1000
dhcp_option (dhcp , DHCP_OPTION_PARAMETER_REQUEST_LIST , LWIP_ARRAYSIZE (dhcp_discover_request_options ));
987
1001
for (i = 0 ; i < LWIP_ARRAYSIZE (dhcp_discover_request_options ); i ++ ) {
988
1002
dhcp_option_byte (dhcp , dhcp_discover_request_options [i ]);
989
1003
}
1004
+
1005
+ #if LWIP_NETIF_HOSTNAME
1006
+ dhcp_option_hostname (dhcp , netif );
1007
+ #endif /* LWIP_NETIF_HOSTNAME */
1008
+
990
1009
dhcp_option_trailer (dhcp );
991
1010
992
1011
LWIP_DEBUGF (DHCP_DEBUG | LWIP_DBG_TRACE , ("dhcp_discover: realloc()ing\n" ));
@@ -1153,6 +1172,10 @@ dhcp_renew(struct netif *netif)
1153
1172
/* create and initialize the DHCP message header */
1154
1173
result = dhcp_create_msg (netif , dhcp , DHCP_REQUEST );
1155
1174
if (result == ERR_OK ) {
1175
+ #if ESP_DHCP_OPTION
1176
+ dhcp_option_clientid (dhcp , netif );
1177
+ dhcp_option_vendor (dhcp , netif );
1178
+ #endif
1156
1179
dhcp_option (dhcp , DHCP_OPTION_MAX_MSG_SIZE , DHCP_OPTION_MAX_MSG_SIZE_LEN );
1157
1180
dhcp_option_short (dhcp , DHCP_MAX_MSG_LEN (netif ));
1158
1181
@@ -1205,6 +1228,10 @@ dhcp_rebind(struct netif *netif)
1205
1228
/* create and initialize the DHCP message header */
1206
1229
result = dhcp_create_msg (netif , dhcp , DHCP_REQUEST );
1207
1230
if (result == ERR_OK ) {
1231
+ #if ESP_DHCP_OPTION
1232
+ dhcp_option_clientid (dhcp , netif );
1233
+ dhcp_option_vendor (dhcp , netif );
1234
+ #endif
1208
1235
dhcp_option (dhcp , DHCP_OPTION_MAX_MSG_SIZE , DHCP_OPTION_MAX_MSG_SIZE_LEN );
1209
1236
dhcp_option_short (dhcp , DHCP_MAX_MSG_LEN (netif ));
1210
1237
@@ -1255,6 +1282,10 @@ dhcp_reboot(struct netif *netif)
1255
1282
/* create and initialize the DHCP message header */
1256
1283
result = dhcp_create_msg (netif , dhcp , DHCP_REQUEST );
1257
1284
if (result == ERR_OK ) {
1285
+ #if ESP_DHCP_OPTION
1286
+ dhcp_option_clientid (dhcp , netif );
1287
+ dhcp_option_vendor (dhcp , netif );
1288
+ #endif
1258
1289
dhcp_option (dhcp , DHCP_OPTION_MAX_MSG_SIZE , DHCP_OPTION_MAX_MSG_SIZE_LEN );
1259
1290
dhcp_option_short (dhcp , DHCP_MAX_MSG_LEN_MIN_REQUIRED );
1260
1291
@@ -1266,6 +1297,10 @@ dhcp_reboot(struct netif *netif)
1266
1297
dhcp_option_byte (dhcp , dhcp_discover_request_options [i ]);
1267
1298
}
1268
1299
1300
+ #if LWIP_NETIF_HOSTNAME
1301
+ dhcp_option_hostname (dhcp , netif );
1302
+ #endif /* LWIP_NETIF_HOSTNAME */
1303
+
1269
1304
dhcp_option_trailer (dhcp );
1270
1305
1271
1306
pbuf_realloc (dhcp -> p_out , sizeof (struct dhcp_msg ) - DHCP_OPTIONS_LEN + dhcp -> options_out_len );
@@ -1463,6 +1498,76 @@ dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif)
1463
1498
}
1464
1499
#endif /* LWIP_NETIF_HOSTNAME */
1465
1500
1501
+ #if ESP_DHCP_OPTION
1502
+ static void dhcp_option_clientid (struct dhcp * dhcp , struct netif * netif )
1503
+ {
1504
+ if (netif ) {
1505
+ u8_t id_len = NETIF_MAX_HWADDR_LEN + 1 ;
1506
+ dhcp_option (dhcp , DHCP_OPTION_CLIENT_ID , id_len );
1507
+ dhcp_option_byte (dhcp , DHCP_HTYPE_ETH );
1508
+ for (u8_t i = 0 ; i < NETIF_MAX_HWADDR_LEN ; i ++ ) {
1509
+ dhcp_option_byte (dhcp , netif -> hwaddr [i ]);
1510
+ }
1511
+ }
1512
+ }
1513
+
1514
+ static u8_t vendor_class_len = 0 ;
1515
+ static char * vendor_class_buf = NULL ;
1516
+ err_t dhcp_set_vendor_class_identifier (u8_t len , char * str )
1517
+ {
1518
+ if (len == 0 || str == NULL ) {
1519
+ return ERR_ARG ;
1520
+ }
1521
+
1522
+ if (vendor_class_buf ) {
1523
+ mem_free (vendor_class_buf );
1524
+ vendor_class_buf = NULL ;
1525
+ }
1526
+
1527
+ vendor_class_buf = (char * )mem_malloc (len + 1 );
1528
+
1529
+ if (vendor_class_buf == NULL ) {
1530
+ return ERR_MEM ;
1531
+ }
1532
+
1533
+ vendor_class_len = len ;
1534
+ memcpy (vendor_class_buf , str , len );
1535
+ return ERR_OK ;
1536
+ }
1537
+
1538
+ static void dhcp_option_vendor (struct dhcp * dhcp , struct netif * netif )
1539
+ {
1540
+ const char * p = NULL ;
1541
+ u8_t len = 0 ;
1542
+ /* Shrink len to available bytes (need 2 bytes for OPTION_HOSTNAME
1543
+ and 1 byte for trailer) */
1544
+ size_t available = DHCP_OPTIONS_LEN - dhcp -> options_out_len - 3 ;
1545
+ if (vendor_class_buf && vendor_class_len ) {
1546
+ p = vendor_class_buf ;
1547
+ LWIP_ASSERT ("DHCP: vendor_class_len is too long!" , vendor_class_len <= available );
1548
+ len = vendor_class_len ;
1549
+ } else { //use hostname as vendor
1550
+ #if LWIP_NETIF_HOSTNAME
1551
+ if (netif -> hostname != NULL ) {
1552
+ size_t namelen = strlen (netif -> hostname );
1553
+ if ((namelen > 0 ) && (namelen < 0xFF )) {
1554
+ p = netif -> hostname ;
1555
+ LWIP_ASSERT ("DHCP: hostname is too long!" , namelen <= available );
1556
+ len = (u8_t ) namelen ;
1557
+ }
1558
+ }
1559
+ #endif
1560
+ }
1561
+
1562
+ if (p ) {
1563
+ dhcp_option (dhcp , DHCP_OPTION_US , (u8_t )len );
1564
+ while (len -- ) {
1565
+ dhcp_option_byte (dhcp , * p ++ );
1566
+ }
1567
+ }
1568
+ }
1569
+ #endif
1570
+
1466
1571
/**
1467
1572
* Extract the DHCP message and the DHCP options.
1468
1573
*
0 commit comments