@@ -8,6 +8,7 @@ use std::io::ErrorKind;
8
8
use crate :: util:: Config ;
9
9
pub use crate :: util:: Platform ;
10
10
use num_derive:: FromPrimitive ;
11
+ use num_traits:: FromPrimitive ;
11
12
use smbioslib:: * ;
12
13
#[ cfg( feature = "uefi" ) ]
13
14
use spin:: Mutex ;
@@ -215,7 +216,7 @@ pub fn get_smbios() -> Option<SMBiosData> {
215
216
}
216
217
}
217
218
218
- fn get_product_name ( ) -> Option < String > {
219
+ pub fn get_product_name ( ) -> Option < String > {
219
220
// On FreeBSD we can short-circuit and avoid parsing SMBIOS
220
221
#[ cfg( target_os = "freebsd" ) ]
221
222
if let Ok ( product) = kenv_get ( "smbios.system.product" ) {
@@ -225,6 +226,7 @@ fn get_product_name() -> Option<String> {
225
226
let smbios = get_smbios ( ) ;
226
227
if smbios. is_none ( ) {
227
228
println ! ( "Failed to find SMBIOS" ) ;
229
+ return None ;
228
230
}
229
231
let mut smbios = smbios. into_iter ( ) . flatten ( ) ;
230
232
smbios. find_map ( |undefined_struct| {
@@ -237,6 +239,38 @@ fn get_product_name() -> Option<String> {
237
239
} )
238
240
}
239
241
242
+ pub fn get_baseboard_version ( ) -> Option < ConfigDigit0 > {
243
+ // TODO: On FreeBSD we can short-circuit and avoid parsing SMBIOS
244
+ // #[cfg(target_os = "freebsd")]
245
+ // if let Ok(product) = kenv_get("smbios.system.product") {
246
+ // return Some(product);
247
+ // }
248
+
249
+ let smbios = get_smbios ( ) ;
250
+ if smbios. is_none ( ) {
251
+ error ! ( "Failed to find SMBIOS" ) ;
252
+ return None ;
253
+ }
254
+ let mut smbios = smbios. into_iter ( ) . flatten ( ) ;
255
+ smbios. find_map ( |undefined_struct| {
256
+ if let DefinedStruct :: BaseBoardInformation ( data) = undefined_struct. defined_struct ( ) {
257
+ if let Some ( version) = dmidecode_string_val ( & data. version ( ) ) {
258
+ // Assumes it's ASCII, which is guaranteed by SMBIOS
259
+ let config_digit0 = & version[ 0 ..1 ] ;
260
+ let config_digit0 = u8:: from_str_radix ( config_digit0, 16 ) ;
261
+ if let Ok ( version_config) =
262
+ config_digit0. map ( <ConfigDigit0 as FromPrimitive >:: from_u8)
263
+ {
264
+ return version_config;
265
+ } else {
266
+ error ! ( " Invalid BaseBoard Version: {}'" , version) ;
267
+ }
268
+ }
269
+ }
270
+ None
271
+ } )
272
+ }
273
+
240
274
pub fn get_platform ( ) -> Option < Platform > {
241
275
#[ cfg( feature = "uefi" ) ]
242
276
let mut cached_platform = CACHED_PLATFORM . lock ( ) ;
0 commit comments