Skip to content

Commit 35f0d76

Browse files
committed
fixup! Allow decoding of SMBIOS Type 11 serialnumbers
1 parent 3928328 commit 35f0d76

File tree

3 files changed

+24
-44
lines changed

3 files changed

+24
-44
lines changed

framework_lib/src/commandline/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ use crate::esrt;
5050
#[cfg(feature = "rusb")]
5151
use crate::inputmodule::check_inputmodule_version;
5252
use crate::power;
53+
use crate::serialnum::Cfg0;
5354
use crate::smbios;
54-
use crate::smbios::ConfigDigit0;
5555
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
5656
#[cfg(feature = "hidapi")]
5757
use crate::touchpad::print_touchpad_fw_ver;
@@ -1430,8 +1430,7 @@ fn smbios_info() {
14301430
// Assumes it's ASCII, which is guaranteed by SMBIOS
14311431
let config_digit0 = &version[0..1];
14321432
let config_digit0 = u8::from_str_radix(config_digit0, 16);
1433-
if let Ok(version_config) =
1434-
config_digit0.map(<ConfigDigit0 as FromPrimitive>::from_u8)
1433+
if let Ok(version_config) = config_digit0.map(<Cfg0 as FromPrimitive>::from_u8)
14351434
{
14361435
println!(" Version: {:?} ({})", version_config, version);
14371436
} else {
@@ -1469,8 +1468,7 @@ fn smbios_info() {
14691468
// Assumes it's ASCII, which is guaranteed by SMBIOS
14701469
let config_digit0 = &version[0..1];
14711470
let config_digit0 = u8::from_str_radix(config_digit0, 16);
1472-
if let Ok(version_config) =
1473-
config_digit0.map(<ConfigDigit0 as FromPrimitive>::from_u8)
1471+
if let Ok(version_config) = config_digit0.map(<Cfg0 as FromPrimitive>::from_u8)
14741472
{
14751473
println!(" Version: {:?} ({})", version_config, version);
14761474
} else {

framework_lib/src/serialnum.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use alloc::string::{String, ToString};
22
use core::str::FromStr;
3+
use num_derive::FromPrimitive;
4+
use num_traits::FromPrimitive;
35

46
#[derive(Debug)]
57
pub struct FrameworkSerial {
@@ -20,7 +22,8 @@ pub struct FrameworkSerial {
2022
pub part: String,
2123
}
2224

23-
#[derive(Debug)]
25+
#[repr(u8)]
26+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy)]
2427
pub enum Cfg0 {
2528
SKU = 0x00,
2629
Poc1 = 0x01,
@@ -32,7 +35,12 @@ pub enum Cfg0 {
3235
Dvt1 = 0x07,
3336
Dvt2 = 0x08,
3437
Pvt = 0x09,
35-
Mp = 0x0A,
38+
MassProduction = 0x0A,
39+
MassProductionB = 0x0B,
40+
MassProductionC = 0x0C,
41+
MassProductionD = 0x0D,
42+
MassProductionE = 0x0E,
43+
MassProductionF = 0x0F,
3644
}
3745

3846
#[derive(Debug)]
@@ -57,19 +65,14 @@ impl FromStr for FrameworkSerial {
5765

5866
let caps = re.captures(s).ok_or("Invalid Serial".to_string())?;
5967

60-
let cfg0 = match caps.get(3).unwrap().as_str().chars().next().unwrap() {
61-
'0' => Cfg0::SKU,
62-
'1' => Cfg0::Poc1,
63-
'2' => Cfg0::Proto1,
64-
'3' => Cfg0::Proto2,
65-
'4' => Cfg0::Evt1,
66-
'5' => Cfg0::Evt2,
67-
'6' => Cfg0::Reserved,
68-
'7' => Cfg0::Dvt1,
69-
'8' => Cfg0::Dvt2,
70-
'9' => Cfg0::Pvt,
71-
'A' => Cfg0::Mp,
72-
_ => return Err("Invalid CFG0".to_string()),
68+
let cfg0 = caps.get(3).unwrap().as_str().chars().next();
69+
let cfg0 = cfg0.and_then(|x| str::parse::<u8>(&x.to_string()).ok());
70+
let cfg0 = cfg0.and_then(<Cfg0 as FromPrimitive>::from_u8);
71+
let cfg0 = if let Some(cfg0) = cfg0 {
72+
cfg0
73+
} else {
74+
error!("Invalid CFG0 '{:?}'", cfg0);
75+
return Err(format!("Invalid CFG0 '{:?}'", cfg0));
7376
};
7477
let cfg1 = caps.get(4).unwrap().as_str().chars().next().unwrap();
7578
let year = str::parse::<u16>(caps.get(5).unwrap().as_str()).unwrap();

framework_lib/src/smbios.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::prelude::v1::*;
66
#[cfg(all(not(feature = "uefi"), not(target_os = "freebsd")))]
77
use std::io::ErrorKind;
88

9+
use crate::serialnum::Cfg0;
910
use crate::serialnum::FrameworkSerial;
1011
use crate::util::Config;
1112
pub use crate::util::{Platform, PlatformFamily};
12-
use num_derive::FromPrimitive;
1313
use num_traits::FromPrimitive;
1414
use smbioslib::*;
1515
#[cfg(feature = "uefi")]
@@ -26,25 +26,6 @@ static CACHED_PLATFORM: Mutex<Option<Option<Platform>>> = Mutex::new(None);
2626
// TODO: Should cache SMBIOS and values gotten from it
2727
// SMBIOS is fixed after boot. Oh, so maybe not cache when we're running in UEFI
2828

29-
#[repr(u8)]
30-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy)]
31-
pub enum ConfigDigit0 {
32-
Poc1 = 0x01,
33-
Proto1 = 0x02,
34-
Proto2 = 0x03,
35-
Evt1 = 0x04,
36-
Evt2 = 0x05,
37-
Dvt1 = 0x07,
38-
Dvt2 = 0x08,
39-
Pvt = 0x09,
40-
MassProduction = 0x0A,
41-
MassProductionB = 0x0B,
42-
MassProductionC = 0x0C,
43-
MassProductionD = 0x0D,
44-
MassProductionE = 0x0E,
45-
MassProductionF = 0x0F,
46-
}
47-
4829
/// Check whether the manufacturer in the SMBIOS says Framework
4930
pub fn is_framework() -> bool {
5031
if matches!(
@@ -241,7 +222,7 @@ pub fn get_product_name() -> Option<String> {
241222
})
242223
}
243224

244-
pub fn get_baseboard_version() -> Option<ConfigDigit0> {
225+
pub fn get_baseboard_version() -> Option<Cfg0> {
245226
// TODO: On FreeBSD we can short-circuit and avoid parsing SMBIOS
246227
// #[cfg(target_os = "freebsd")]
247228
// if let Ok(product) = kenv_get("smbios.system.product") {
@@ -260,9 +241,7 @@ pub fn get_baseboard_version() -> Option<ConfigDigit0> {
260241
// Assumes it's ASCII, which is guaranteed by SMBIOS
261242
let config_digit0 = &version[0..1];
262243
let config_digit0 = u8::from_str_radix(config_digit0, 16);
263-
if let Ok(version_config) =
264-
config_digit0.map(<ConfigDigit0 as FromPrimitive>::from_u8)
265-
{
244+
if let Ok(version_config) = config_digit0.map(<Cfg0 as FromPrimitive>::from_u8) {
266245
return version_config;
267246
} else {
268247
error!(" Invalid BaseBoard Version: {}'", version);

0 commit comments

Comments
 (0)