From 6754ca34ccabc27a2f736754748a06dc0b2c6dd4 Mon Sep 17 00:00:00 2001 From: Karim BEN YOUSSEF Date: Sun, 20 Feb 2022 15:20:03 +0100 Subject: [PATCH] Added Vendor Class Identifier in DHCP offers and requests. The Vendor Class Identifier is a constant string that identifies the kind of hardware that asks the DHCP server for a IP address. The ID is passed via the option 60 of the DHCP messages. The ID is set to "WIZnetSE" constant. From a DHCP server point of view, this ID is useful for giving specific configuration for Wiznet modules : IP address from different address pool, different gateway, longer lease, etc. Reference documentation : https://datatracker.ietf.org/doc/html/rfc2132#section-9.13 --- ioLibrary/Internet/DHCP/dhcp.c | 16 ++++++++++++++++ ioLibrary/Internet/DHCP/dhcp.h | 2 ++ 2 files changed, 18 insertions(+) mode change 100644 => 100755 ioLibrary/Internet/DHCP/dhcp.h diff --git a/ioLibrary/Internet/DHCP/dhcp.c b/ioLibrary/Internet/DHCP/dhcp.c index f26e2e4..efb7724 100644 --- a/ioLibrary/Internet/DHCP/dhcp.c +++ b/ioLibrary/Internet/DHCP/dhcp.c @@ -224,6 +224,8 @@ uint32_t DHCP_XID; // Any number RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing +uint8_t VENDOR_ID[] = DHCP_VENDOR_ID; + uint8_t HOST_NAME[] = DCHP_HOST_NAME; uint8_t DHCP_CHADDR[6] = {0, }; // DHCP Client MAC address. @@ -387,6 +389,13 @@ void send_DHCP_DISCOVER(void) pDHCPMSG->OPT[k++] = 0x01; pDHCPMSG->OPT[k++] = DHCP_DISCOVER; + // Class identifier + pDHCPMSG->OPT[k++] = dhcpClassIdentifier; + pDHCPMSG->OPT[k++] = 0; // fill zero length of class identifier + for(i = 0 ; VENDOR_ID[i] != 0; i++) + pDHCPMSG->OPT[k++] = VENDOR_ID[i]; + pDHCPMSG->OPT[k - (i+1)] = i; + // Client identifier pDHCPMSG->OPT[k++] = dhcpClientIdentifier; pDHCPMSG->OPT[k++] = 0x07; @@ -476,6 +485,13 @@ void send_DHCP_REQUEST(void) pDHCPMSG->OPT[k++] = 0x01; pDHCPMSG->OPT[k++] = DHCP_REQUEST; + // Class identifier + pDHCPMSG->OPT[k++] = dhcpClassIdentifier; + pDHCPMSG->OPT[k++] = 0; // fill zero length of class identifier + for(i = 0 ; VENDOR_ID[i] != 0; i++) + pDHCPMSG->OPT[k++] = VENDOR_ID[i]; + pDHCPMSG->OPT[k - (i+1)] = i; + pDHCPMSG->OPT[k++] = dhcpClientIdentifier; pDHCPMSG->OPT[k++] = 0x07; pDHCPMSG->OPT[k++] = 0x01; diff --git a/ioLibrary/Internet/DHCP/dhcp.h b/ioLibrary/Internet/DHCP/dhcp.h old mode 100644 new mode 100755 index b3df630..1749918 --- a/ioLibrary/Internet/DHCP/dhcp.h +++ b/ioLibrary/Internet/DHCP/dhcp.h @@ -67,6 +67,8 @@ #define MAGIC_COOKIE 0x63825363 ///< Any number. You can be modifyed it any number +#define DHCP_VENDOR_ID "WIZnetSE\0" ///< Vendor ID used for DHCP requests, using Class-Id (option 60) + #define DCHP_HOST_NAME "WIZnet\0"