/* * uuid_str_to_bin() - convert string UUID or GUID to big endian binary data. * * @param uuid_str - pointer to UUID or GUID string [37B] or GUID shorcut * @param uuid_bin - pointer to allocated array for big endian output [16B] * @str_format - UUID string format: 0 - UUID; 1 - GUID */ int uuid_str_to_bin(char *uuid_str, unsigned char *uuid_bin, int str_format) { uint16_t tmp16; uint32_t tmp32; uint64_t tmp64; if (!uuid_str_valid(uuid_str)) { #ifdef CONFIG_PARTITION_TYPE_GUID if (!uuid_guid_get_bin(uuid_str, uuid_bin)) return 0; #endif return -EINVAL; } if (str_format == UUID_STR_FORMAT_STD) { tmp32 = cpu_to_be32(simple_strtoul(uuid_str, NULL, 16)); memcpy(uuid_bin, &tmp32, 4); tmp16 = cpu_to_be16(simple_strtoul(uuid_str + 9, NULL, 16)); memcpy(uuid_bin + 4, &tmp16, 2); tmp16 = cpu_to_be16(simple_strtoul(uuid_str + 14, NULL, 16)); memcpy(uuid_bin + 6, &tmp16, 2); } else { tmp32 = cpu_to_le32(simple_strtoul(uuid_str, NULL, 16)); memcpy(uuid_bin, &tmp32, 4); tmp16 = cpu_to_le16(simple_strtoul(uuid_str + 9, NULL, 16)); memcpy(uuid_bin + 4, &tmp16, 2); tmp16 = cpu_to_le16(simple_strtoul(uuid_str + 14, NULL, 16)); memcpy(uuid_bin + 6, &tmp16, 2); } tmp16 = cpu_to_be16(simple_strtoul(uuid_str + 19, NULL, 16)); memcpy(uuid_bin + 8, &tmp16, 2); tmp64 = cpu_to_be64(simple_strtoull(uuid_str + 24, NULL, 16)); memcpy(uuid_bin + 10, (char *)&tmp64 + 2, 6); return 0; }
static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP) { u8 *start = e; u8 *cnt; #if defined(CONFIG_BOOTP_PXE) char *uuid; u16 clientarch; #endif #if defined(CONFIG_BOOTP_VENDOREX) u8 *x; #endif #if defined(CONFIG_BOOTP_SEND_HOSTNAME) char *hostname; #endif *e++ = 99; /* RFC1048 Magic Cookie */ *e++ = 130; *e++ = 83; *e++ = 99; *e++ = 53; /* DHCP Message Type */ *e++ = 1; *e++ = message_type; *e++ = 57; /* Maximum DHCP Message Size */ *e++ = 2; *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8; *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; if (ServerID) { int tmp = ntohl(ServerID); *e++ = 54; /* ServerID */ *e++ = 4; *e++ = tmp >> 24; *e++ = tmp >> 16; *e++ = tmp >> 8; *e++ = tmp & 0xff; } if (RequestedIP) { int tmp = ntohl(RequestedIP); *e++ = 50; /* Requested IP */ *e++ = 4; *e++ = tmp >> 24; *e++ = tmp >> 16; *e++ = tmp >> 8; *e++ = tmp & 0xff; } #if defined(CONFIG_BOOTP_SEND_HOSTNAME) hostname = getenv("hostname"); if (hostname) { int hostnamelen = strlen(hostname); *e++ = 12; /* Hostname */ *e++ = hostnamelen; memcpy(e, hostname, hostnamelen); e += hostnamelen; } #endif #if defined(CONFIG_BOOTP_PXE) clientarch = CONFIG_BOOTP_PXE_CLIENTARCH; *e++ = 93; /* Client System Architecture */ *e++ = 2; *e++ = (clientarch >> 8) & 0xff; *e++ = clientarch & 0xff; *e++ = 94; /* Client Network Interface Identifier */ *e++ = 3; *e++ = 1; /* type field for UNDI */ *e++ = 0; /* major revision */ *e++ = 0; /* minor revision */ uuid = getenv("pxeuuid"); if (uuid) { if (uuid_str_valid(uuid)) { *e++ = 97; /* Client Machine Identifier */ *e++ = 17; *e++ = 0; /* type 0 - UUID */ uuid_str_to_bin(uuid, e, UUID_STR_FORMAT_STD); e += 16; } else { printf("Invalid pxeuuid: %s\n", uuid); } } #endif #ifdef CONFIG_BOOTP_VCI_STRING put_vci(e, CONFIG_BOOTP_VCI_STRING); #endif #if defined(CONFIG_BOOTP_VENDOREX) x = dhcp_vendorex_prep(e); if (x) return x - start; #endif *e++ = 55; /* Parameter Request List */ cnt = e++; /* Pointer to count of requested items */ *cnt = 0; #if defined(CONFIG_BOOTP_SUBNETMASK) *e++ = 1; /* Subnet Mask */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_TIMEOFFSET) *e++ = 2; *cnt += 1; #endif #if defined(CONFIG_BOOTP_GATEWAY) *e++ = 3; /* Router Option */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_DNS) *e++ = 6; /* DNS Server(s) */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_HOSTNAME) *e++ = 12; /* Hostname */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_BOOTFILESIZE) *e++ = 13; /* Boot File Size */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_BOOTPATH) *e++ = 17; /* Boot path */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_NISDOMAIN) *e++ = 40; /* NIS Domain name request */ *cnt += 1; #endif #if defined(CONFIG_BOOTP_NTPSERVER) *e++ = 42; *cnt += 1; #endif /* no options, so back up to avoid sending an empty request list */ if (*cnt == 0) e -= 2; *e++ = 255; /* End of the list */ /* Pad to minimal length */ #ifdef CONFIG_DHCP_MIN_EXT_LEN while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN) *e++ = 0; #endif return e - start; }