@@ -172,6 +172,23 @@ static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
172
172
/* always add the DHCP options trailer to end and pad */
173
173
static void dhcp_option_trailer (struct dhcp * dhcp );
174
174
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
+
175
192
/**
176
193
* Back-off the DHCP client (because of a received NAK response).
177
194
*
@@ -321,6 +338,18 @@ dhcp_select(struct netif *netif)
321
338
}
322
339
#endif /* LWIP_NETIF_HOSTNAME */
323
340
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
+
324
353
dhcp_option_trailer (dhcp );
325
354
/* shrink the pbuf to the actual content length */
326
355
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)
918
947
}
919
948
}
920
949
#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
+
921
963
dhcp_option (dhcp , DHCP_OPTION_PARAMETER_REQUEST_LIST , 12 /*num options*/ );
922
964
dhcp_option_byte (dhcp , DHCP_OPTION_SUBNET_MASK );
923
965
dhcp_option_byte (dhcp , DHCP_OPTION_ROUTER );
@@ -1099,6 +1141,18 @@ dhcp_renew(struct netif *netif)
1099
1141
}
1100
1142
#endif /* LWIP_NETIF_HOSTNAME */
1101
1143
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
+
1102
1156
#if 0
1103
1157
dhcp_option (dhcp , DHCP_OPTION_REQUESTED_IP , 4 );
1104
1158
dhcp_option_long (dhcp , ntohl (dhcp -> offered_ip_addr .addr ));
@@ -1162,6 +1216,18 @@ dhcp_rebind(struct netif *netif)
1162
1216
}
1163
1217
#endif /* LWIP_NETIF_HOSTNAME */
1164
1218
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
+
1165
1231
#if 1
1166
1232
dhcp_option (dhcp , DHCP_OPTION_REQUESTED_IP , 4 );
1167
1233
dhcp_option_long (dhcp , ntohl (dhcp -> offered_ip_addr .addr ));
0 commit comments