@@ -8,6 +8,7 @@ use std::io::ErrorKind;
88use crate :: util:: Config ;
99pub use crate :: util:: Platform ;
1010use num_derive:: FromPrimitive ;
11+ use num_traits:: FromPrimitive ;
1112use smbioslib:: * ;
1213#[ cfg( feature = "uefi" ) ]
1314use spin:: Mutex ;
@@ -215,7 +216,7 @@ pub fn get_smbios() -> Option<SMBiosData> {
215216 }
216217}
217218
218- fn get_product_name ( ) -> Option < String > {
219+ pub fn get_product_name ( ) -> Option < String > {
219220 // On FreeBSD we can short-circuit and avoid parsing SMBIOS
220221 #[ cfg( target_os = "freebsd" ) ]
221222 if let Ok ( product) = kenv_get ( "smbios.system.product" ) {
@@ -225,6 +226,7 @@ fn get_product_name() -> Option<String> {
225226 let smbios = get_smbios ( ) ;
226227 if smbios. is_none ( ) {
227228 println ! ( "Failed to find SMBIOS" ) ;
229+ return None ;
228230 }
229231 let mut smbios = smbios. into_iter ( ) . flatten ( ) ;
230232 smbios. find_map ( |undefined_struct| {
@@ -237,6 +239,38 @@ fn get_product_name() -> Option<String> {
237239 } )
238240}
239241
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+
240274pub fn get_platform ( ) -> Option < Platform > {
241275 #[ cfg( feature = "uefi" ) ]
242276 let mut cached_platform = CACHED_PLATFORM . lock ( ) ;
0 commit comments