1mod low_level;
13
14use std::io;
15
16pub use uuid::Uuid;
17
18use low_level::{
19 EntryPoint, Structures, StructureKind, BiosInformation, SystemInformation
20};
21
22#[derive(Debug, PartialEq, Eq)]
23pub struct Bios {
24 entry_point: EntryPoint,
25 structures: Structures
26}
27
28#[derive(Debug, PartialEq, Eq, Hash)]
29pub struct BiosInfo<'a> {
30 pub vendor: &'a str,
31 pub version: &'a str,
32 pub release_date: &'a str,
33 pub major: u8,
34 pub minor: u8
35}
36
37#[derive(Debug, PartialEq, Eq, Hash)]
38pub struct SystemInfo<'a> {
39 pub manufacturer: &'a str,
40 pub product_name: &'a str,
41 pub version: &'a str,
42 pub serial_number: &'a str,
43 pub uuid: Uuid,
45 pub sku_number: &'a str,
46 pub family: &'a str
47}
48
49impl Bios {
50 pub fn read() -> io::Result<Self> {
51 let entry_point = EntryPoint::read()?;
52 Ok(Self {
53 structures: Structures::read(entry_point.table_max)?,
54 entry_point
55 })
56 }
57
58 pub fn bios_info(&self) -> Option<BiosInfo> {
59 let stru = self.structures.structures()
60 .find(|s| s.header.kind == StructureKind::BiosInformation)?;
61 let info = BiosInformation::from(&stru)?;
62
63 Some(BiosInfo {
64 vendor: stru.get_str(info.vendor)?,
65 version: stru.get_str(info.version)?,
66 release_date: stru.get_str(info.release_date)?,
67 major: info.major,
68 minor: info.minor
69 })
70 }
71
72 pub fn system_info(&self) -> Option<SystemInfo> {
73 let stru = self.structures.structures()
74 .find(|s| s.header.kind == StructureKind::SystemInformation)?;
75 let info = SystemInformation::from(&stru)?;
76
77 Some(SystemInfo {
78 manufacturer: stru.get_str(info.manufacturer)?,
79 product_name: stru.get_str(info.product_name)?,
80 version: stru.get_str(info.version)?,
81 serial_number: stru.get_str(info.serial_number)?,
82 uuid: info.uuid,
83 sku_number: stru.get_str(info.sku_number)?,
84 family: stru.get_str(info.family)?
85 })
86 }
87}