@@ -174,6 +174,23 @@ static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
174
174
/* always add the DHCP options trailer to end and pad */
175
175
static void dhcp_option_trailer (struct dhcp * dhcp );
176
176
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
+
177
194
/**
178
195
* Back-off the DHCP client (because of a received NAK response).
179
196
*
@@ -323,6 +340,18 @@ dhcp_select(struct netif *netif)
323
340
}
324
341
#endif /* LWIP_NETIF_HOSTNAME */
325
342
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
+
326
355
dhcp_option_trailer (dhcp );
327
356
/* shrink the pbuf to the actual content length */
328
357
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)
920
949
}
921
950
}
922
951
#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
+
923
965
dhcp_option (dhcp , DHCP_OPTION_PARAMETER_REQUEST_LIST , 12 /*num options*/ );
924
966
dhcp_option_byte (dhcp , DHCP_OPTION_SUBNET_MASK );
925
967
dhcp_option_byte (dhcp , DHCP_OPTION_ROUTER );
@@ -1101,6 +1143,18 @@ dhcp_renew(struct netif *netif)
1101
1143
}
1102
1144
#endif /* LWIP_NETIF_HOSTNAME */
1103
1145
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
+
1104
1158
#if 0
1105
1159
dhcp_option (dhcp , DHCP_OPTION_REQUESTED_IP , 4 );
1106
1160
dhcp_option_long (dhcp , ntohl (dhcp -> offered_ip_addr .addr ));
@@ -1164,6 +1218,18 @@ dhcp_rebind(struct netif *netif)
1164
1218
}
1165
1219
#endif /* LWIP_NETIF_HOSTNAME */
1166
1220
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
+
1167
1233
#if 1
1168
1234
dhcp_option (dhcp , DHCP_OPTION_REQUESTED_IP , 4 );
1169
1235
dhcp_option_long (dhcp , ntohl (dhcp -> offered_ip_addr .addr ));
0 commit comments