mirror of https://github.com/ipxe/ipxe.git
[uuid] Abstract UUID mangling code out to a separate uuid_mangle() function
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/13/head
parent
a9b63ecda5
commit
d938e50136
|
@ -9,6 +9,7 @@
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <byteswap.h>
|
||||||
|
|
||||||
/** A universally unique ID */
|
/** A universally unique ID */
|
||||||
union uuid {
|
union uuid {
|
||||||
|
@ -28,6 +29,24 @@ union uuid {
|
||||||
uint8_t raw[16];
|
uint8_t raw[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change UUID endianness
|
||||||
|
*
|
||||||
|
* @v uuid UUID
|
||||||
|
*
|
||||||
|
* RFC4122 defines UUIDs as being encoded in network byte order, but
|
||||||
|
* leaves some wriggle room for "explicit application or presentation
|
||||||
|
* protocol specification to the contrary". PXE, EFI and SMBIOS
|
||||||
|
* (versions 2.6 and above) treat the first three fields as being
|
||||||
|
* little-endian.
|
||||||
|
*/
|
||||||
|
static inline void uuid_mangle ( union uuid *uuid ) {
|
||||||
|
|
||||||
|
__bswap_32s ( &uuid->canonical.a );
|
||||||
|
__bswap_16s ( &uuid->canonical.b );
|
||||||
|
__bswap_16s ( &uuid->canonical.c );
|
||||||
|
}
|
||||||
|
|
||||||
extern char * uuid_ntoa ( const union uuid *uuid );
|
extern char * uuid_ntoa ( const union uuid *uuid );
|
||||||
|
|
||||||
#endif /* _IPXE_UUID_H */
|
#endif /* _IPXE_UUID_H */
|
||||||
|
|
|
@ -22,7 +22,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <byteswap.h>
|
|
||||||
#include <ipxe/settings.h>
|
#include <ipxe/settings.h>
|
||||||
#include <ipxe/init.h>
|
#include <ipxe/init.h>
|
||||||
#include <ipxe/uuid.h>
|
#include <ipxe/uuid.h>
|
||||||
|
@ -148,9 +147,7 @@ static int smbios_fetch ( struct settings *settings __unused,
|
||||||
( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
|
( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
|
||||||
DBG ( "SMBIOS detected mangled UUID\n" );
|
DBG ( "SMBIOS detected mangled UUID\n" );
|
||||||
memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) );
|
memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) );
|
||||||
__bswap_32s ( &uuid.canonical.a );
|
uuid_mangle ( &uuid );
|
||||||
__bswap_16s ( &uuid.canonical.b );
|
|
||||||
__bswap_16s ( &uuid.canonical.c );
|
|
||||||
raw = &uuid;
|
raw = &uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1049,9 +1049,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
|
||||||
client_uuid.type = DHCP_CLIENT_UUID_TYPE;
|
client_uuid.type = DHCP_CLIENT_UUID_TYPE;
|
||||||
if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
|
if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
|
||||||
&client_uuid.uuid ) ) >= 0 ) {
|
&client_uuid.uuid ) ) >= 0 ) {
|
||||||
__bswap_32s ( &client_uuid.uuid.canonical.a );
|
uuid_mangle ( &client_uuid.uuid );
|
||||||
__bswap_16s ( &client_uuid.uuid.canonical.b );
|
|
||||||
__bswap_16s ( &client_uuid.uuid.canonical.c );
|
|
||||||
if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
|
if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
|
||||||
&client_uuid,
|
&client_uuid,
|
||||||
sizeof ( client_uuid ) ) ) != 0 ) {
|
sizeof ( client_uuid ) ) ) != 0 ) {
|
||||||
|
|
Loading…
Reference in New Issue