Skip to content

Commit ec98505

Browse files
committed
Add firmare lang infos type
1 parent 76c87dd commit ec98505

File tree

3 files changed

+83
-34
lines changed

3 files changed

+83
-34
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ sudo dmitui
4949
- [x] System (type 1)
5050
- [x] Baseboard (type 2)
5151
- [x] Chassis (type 3) (Partially)
52+
- [x] Firmware Language Information (type 13)
5253

5354
## ⚖️ License
5455

src/dmi.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod firmware;
44
mod system;
55

66
use std::{
7-
fmt::Display,
87
fs::File,
98
io::{BufRead, BufReader, Read},
109
path::Path,
@@ -58,6 +57,7 @@ impl From<[u8; 4]> for Header {
5857
1 => StructureType::System,
5958
2 => StructureType::Baseboard,
6059
3 => StructureType::Chassis,
60+
13 => StructureType::FirmwareLanguage,
6161
127 => StructureType::End,
6262
_ => StructureType::Other,
6363
};
@@ -77,6 +77,7 @@ pub enum StructureType {
7777
System = 1,
7878
Baseboard = 2,
7979
Chassis = 3,
80+
FirmwareLanguage = 13,
8081
End = 127,
8182
Other = 255,
8283
}
@@ -159,6 +160,13 @@ impl DMI {
159160
StructureType::Chassis => {
160161
chassis = Some(Chassis::from((data, text)));
161162
}
163+
StructureType::FirmwareLanguage => {
164+
let language_infos = firmware::LanguageInfos::from((data, text));
165+
166+
if let Some(firmware) = &mut firmware {
167+
firmware.language_infos = Some(language_infos);
168+
}
169+
}
162170
_ => {}
163171
}
164172
}
@@ -289,35 +297,3 @@ impl DMI {
289297
}
290298
}
291299
}
292-
293-
#[non_exhaustive]
294-
#[derive(Debug, PartialEq)]
295-
pub enum SmbiosType {
296-
Firmware,
297-
System,
298-
Baseboard,
299-
Chassis,
300-
Processor,
301-
Memory,
302-
Cache,
303-
Connector,
304-
Slot,
305-
}
306-
307-
#[derive(Debug)]
308-
pub struct Release {
309-
pub major: u8,
310-
pub minor: u8,
311-
}
312-
313-
impl Release {
314-
fn new(major: u8, minor: u8) -> Self {
315-
Self { major, minor }
316-
}
317-
}
318-
319-
impl Display for Release {
320-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
321-
write!(f, "{}.{}", self.major, self.minor)
322-
}
323-
}

src/dmi/firmware.rs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1+
use std::fmt::Display;
2+
13
use ratatui::{
24
Frame,
35
layout::{Constraint, Direction, Layout, Margin, Rect},
46
style::{Style, Stylize},
57
widgets::{Block, Cell, Padding, Row, Table},
68
};
79

8-
use crate::dmi::Release;
10+
#[derive(Debug)]
11+
pub struct Release {
12+
pub major: u8,
13+
pub minor: u8,
14+
}
15+
16+
impl Release {
17+
fn new(major: u8, minor: u8) -> Self {
18+
Self { major, minor }
19+
}
20+
}
21+
22+
impl Display for Release {
23+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
write!(f, "{}.{}", self.major, self.minor)
25+
}
26+
}
27+
28+
#[derive(Debug)]
29+
pub struct LanguageInfos {
30+
installed_languages: u8,
31+
abbreviated_format_is_used: bool,
32+
current_language: String,
33+
}
34+
35+
impl From<(Vec<u8>, Vec<String>)> for LanguageInfos {
36+
fn from((data, text): (Vec<u8>, Vec<String>)) -> Self {
37+
Self {
38+
installed_languages: data[0],
39+
abbreviated_format_is_used: data[1] << 1 != 0,
40+
current_language: text[data[17].saturating_sub(1) as usize].clone(),
41+
}
42+
}
43+
}
944

1045
#[derive(Debug)]
1146
pub struct Firmware {
@@ -18,6 +53,7 @@ pub struct Firmware {
1853
pub firmware_characteristics_exentions: FirmwareCharacteristicsExtension,
1954
pub platform_firmware_release: Release,
2055
pub embedded_controller_firmware_release: Release,
56+
pub language_infos: Option<LanguageInfos>,
2157
}
2258

2359
impl From<(Vec<u8>, Vec<String>, u8)> for Firmware {
@@ -55,6 +91,7 @@ impl From<(Vec<u8>, Vec<String>, u8)> for Firmware {
5591
]),
5692
platform_firmware_release: Release::new(data[16], data[17]),
5793
embedded_controller_firmware_release: Release::new(data[18], data[19]),
94+
language_infos: None,
5895
}
5996
}
6097
}
@@ -99,6 +136,41 @@ impl Firmware {
99136
Cell::from("Firmware ROM size").bold(),
100137
Cell::from(self.firmware_rom_size.clone()),
101138
]),
139+
Row::new(vec![
140+
Cell::from("Installable Languages").bold(),
141+
Cell::from(
142+
self.language_infos
143+
.as_ref()
144+
.unwrap()
145+
.installed_languages
146+
.to_string(),
147+
),
148+
]),
149+
Row::new(vec![
150+
Cell::from("Language Description Format").bold(),
151+
Cell::from(
152+
if self
153+
.language_infos
154+
.as_ref()
155+
.unwrap()
156+
.abbreviated_format_is_used
157+
{
158+
"Abbreviated".to_string()
159+
} else {
160+
"Long format".to_string()
161+
},
162+
),
163+
]),
164+
Row::new(vec![
165+
Cell::from("Current Language").bold(),
166+
Cell::from(
167+
self.language_infos
168+
.as_ref()
169+
.unwrap()
170+
.current_language
171+
.clone(),
172+
),
173+
]),
102174
];
103175
let widths = [Constraint::Length(40), Constraint::Fill(1)];
104176
let table = Table::new(rows, widths).block(Block::new().padding(Padding::uniform(2)));

0 commit comments

Comments
 (0)