@@ -51,14 +51,37 @@ pub struct System<'buffer> {
5151 pub product : & ' buffer str ,
5252 pub version : & ' buffer str ,
5353 pub serial : & ' buffer str ,
54- pub uuid : Option < [ u8 ; 16 ] > ,
54+ pub uuid : Option < uuid :: Uuid > ,
5555 pub wakeup : Option < WakeupType > ,
5656 pub sku : Option < & ' buffer str > ,
5757 pub family : Option < & ' buffer str > ,
5858}
5959
6060impl < ' buffer > System < ' buffer > {
6161 pub ( crate ) fn try_from ( structure : RawStructure < ' buffer > ) -> Result < System < ' buffer > , MalformedStructureError > {
62+ /// Internal helpers for decoding complex representations
63+ mod wrapper {
64+ /// Wrapper around the 16-byte UUID field to implement SMBIOS-version-aware decoding.
65+ #[ repr( transparent) ]
66+ pub struct UuidRepr ( [ u8 ; 16 ] ) ;
67+
68+ impl UuidRepr {
69+ /// Decodes the raw UUID according to the SMBIOS specification.
70+ ///
71+ /// - For SMBIOS versions >= 2.6, the first 3 fields are encoded in little-endian format according
72+ /// to the SMBIOS specification.
73+ /// - For older versions, the UUID is returned as-is to be consistent with `dmidecode` utility.
74+ #[ inline( always) ]
75+ pub fn decode_by_smbios_version ( self , version : crate :: SmbiosVersion ) -> uuid:: Uuid {
76+ if version < ( 2 , 6 ) . into ( ) {
77+ uuid:: Uuid :: from_bytes ( self . 0 )
78+ } else {
79+ uuid:: Uuid :: from_bytes_le ( self . 0 )
80+ }
81+ }
82+ }
83+ }
84+
6285 #[ repr( C ) ]
6386 #[ repr( packed) ]
6487 struct SystemPacked_2_0 {
@@ -72,7 +95,7 @@ impl<'buffer> System<'buffer> {
7295 #[ repr( packed) ]
7396 struct SystemPacked_2_1 {
7497 v2_0 : SystemPacked_2_0 ,
75- uuid : [ u8 ; 16 ] ,
98+ uuid : wrapper :: UuidRepr ,
7699 wakeup : u8 ,
77100 }
78101
@@ -107,7 +130,7 @@ impl<'buffer> System<'buffer> {
107130 product : structure. find_string ( packed. v2_0 . product ) ?,
108131 version : structure. find_string ( packed. v2_0 . version ) ?,
109132 serial : structure. find_string ( packed. v2_0 . serial ) ?,
110- uuid : Some ( packed. uuid ) ,
133+ uuid : Some ( packed. uuid . decode_by_smbios_version ( structure . version ) ) ,
111134 wakeup : Some ( packed. wakeup . into ( ) ) ,
112135 sku : None ,
113136 family : None ,
@@ -121,7 +144,7 @@ impl<'buffer> System<'buffer> {
121144 product : structure. find_string ( packed. v2_1 . v2_0 . product ) ?,
122145 version : structure. find_string ( packed. v2_1 . v2_0 . version ) ?,
123146 serial : structure. find_string ( packed. v2_1 . v2_0 . serial ) ?,
124- uuid : Some ( packed. v2_1 . uuid ) ,
147+ uuid : Some ( packed. v2_1 . uuid . decode_by_smbios_version ( structure . version ) ) ,
125148 wakeup : Some ( packed. v2_1 . wakeup . into ( ) ) ,
126149 sku : Some ( structure. find_string ( packed. sku ) ?) ,
127150 family : Some ( structure. find_string ( packed. family ) ?) ,
0 commit comments