Skip to content

Commit 064d431

Browse files
committed
16449 Want smbios additional information (Type 40) decoding
Reviewed by: Toomas Soome <[email protected]> Reviewed by: Bill Sommerfeld <[email protected]> Approved by: Gordon Ross <[email protected]>
1 parent aba38c6 commit 064d431

File tree

11 files changed

+794
-16
lines changed

11 files changed

+794
-16
lines changed

usr/src/cmd/smbios/smbios.c

+70-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
2424
* Copyright (c) 2017, Joyent, Inc.
25-
* Copyright 2023 Oxide Computer Company
25+
* Copyright 2024 Oxide Computer Company
2626
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2727
* Use is subject to license terms.
2828
*/
@@ -1589,6 +1589,71 @@ print_powersup(smbios_hdl_t *shp, id_t id, FILE *fp)
15891589
}
15901590
}
15911591

1592+
static void
1593+
print_addinfo(smbios_hdl_t *shp, id_t id, FILE *fp)
1594+
{
1595+
uint_t nents, i;
1596+
1597+
if (smbios_info_addinfo_nents(shp, id, &nents) != 0) {
1598+
smbios_warn(shp, "failed to read additional information");
1599+
return;
1600+
}
1601+
1602+
oprintf(fp, " Number of Additional Information Entries: %u\n", nents);
1603+
for (i = 0; i < nents; i++) {
1604+
smbios_addinfo_ent_t *ent;
1605+
1606+
oprintf(fp, " Additional Information Entry %u\n", i);
1607+
if (smbios_info_addinfo_ent(shp, id, i, &ent) != 0) {
1608+
smbios_warn(shp, "failed to read additional "
1609+
"information entry %u", i);
1610+
continue;
1611+
}
1612+
1613+
oprintf(fp, " Referenced handle: %lu\n", ent->smbai_ref);
1614+
oprintf(fp, " Handle offset: %u\n", ent->smbai_ref_off);
1615+
if (ent->smbai_str != NULL) {
1616+
str_print(fp, " Information String", ent->smbai_str);
1617+
}
1618+
1619+
/*
1620+
* As of SMBIOS 3.7, there are no extra data entries strictly
1621+
* defined in the spec, but there may be something. If we find
1622+
* something that's a standard integer size, then we'll
1623+
* interpret it and print it as a hex value. In theory this is
1624+
* supposed to refer back to some field, but hard to say how
1625+
* this'll actually be used. The first time we encountered it
1626+
* was just an additional string entry.
1627+
*/
1628+
if (ent->smbai_dlen > 0) {
1629+
oprintf(fp, " Data Length: %u\n", ent->smbai_dlen);
1630+
switch (ent->smbai_dlen) {
1631+
case 1:
1632+
oprintf(fp, " Data: 0x%x\n",
1633+
*(uint8_t *)ent->smbai_data);
1634+
break;
1635+
case 2:
1636+
oprintf(fp, " Data: 0x%x\n",
1637+
*(uint16_t *)ent->smbai_data);
1638+
break;
1639+
case 4:
1640+
oprintf(fp, " Data: 0x%x\n",
1641+
*(uint32_t *)ent->smbai_data);
1642+
break;
1643+
case 8:
1644+
oprintf(fp, " Data: 0x%x\n",
1645+
*(uint64_t *)ent->smbai_data);
1646+
break;
1647+
default:
1648+
break;
1649+
}
1650+
}
1651+
1652+
smbios_info_addinfo_ent_free(shp, ent);
1653+
}
1654+
}
1655+
1656+
15921657
static void
15931658
print_processor_info_riscv(smbios_hdl_t *shp, id_t id, FILE *fp)
15941659
{
@@ -2048,6 +2113,10 @@ print_struct(smbios_hdl_t *shp, const smbios_struct_t *sp, void *fp)
20482113
oprintf(fp, "\n");
20492114
print_powersup(shp, sp->smbstr_id, fp);
20502115
break;
2116+
case SMB_TYPE_ADDINFO:
2117+
oprintf(fp, "\n");
2118+
print_addinfo(shp, sp->smbstr_id, fp);
2119+
break;
20512120
case SMB_TYPE_OBDEVEXT:
20522121
oprintf(fp, "\n");
20532122
print_obdevs_ext(shp, sp->smbstr_id, fp);

usr/src/common/smbios/smb_error.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
/*
2424
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2525
* Use is subject to license terms.
26+
*
27+
* Copyright 2024 Oxide Computer Company
2628
*/
2729

2830
#include <sys/smbios_impl.h>
@@ -45,10 +47,11 @@ static const char *const _smb_errlist[] = {
4547
"SMBIOS header checksum mismatch", /* ESMB_CKSUM */
4648
"Invalid argument specified in library call", /* ESMB_INVAL */
4749
"Structure is not of the expected type", /* ESMB_TYPE */
48-
"Unknown SMBIOS error" /* ESMB_UNKNOWN */
50+
"Unknown SMBIOS error", /* ESMB_UNKNOWN */
51+
"Invalid requested value" /* ESMB_REQVAL */
4952
};
5053

51-
static const int _smb_nerr = sizeof (_smb_errlist) / sizeof (_smb_errlist[0]);
54+
static const size_t _smb_nerr = ARRAY_SIZE(_smb_errlist);
5255

5356
const char *
5457
smbios_errmsg(int error)
@@ -60,7 +63,7 @@ smbios_errmsg(int error)
6063
else
6164
str = smb_strerror(error);
6265

63-
return (str ? str : "Unknown error");
66+
return (str != NULL ? str : "Unknown error");
6467
}
6568

6669
int

usr/src/common/smbios/smb_info.c

+114-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
2424
* Copyright 2019 Joyent, Inc.
25-
* Copyright 2023 Oxide Computer Company
25+
* Copyright 2024 Oxide Computer Company
2626
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2727
* Use is subject to license terms.
2828
*/
@@ -2151,3 +2151,116 @@ smbios_info_fwinfo_comps_free(smbios_hdl_t *shp, uint_t ncomps,
21512151

21522152
smb_free(comps, sz);
21532153
}
2154+
2155+
int
2156+
smbios_info_addinfo_nents(smbios_hdl_t *shp, id_t id, uint_t *nentsp)
2157+
{
2158+
const smb_struct_t *stp = smb_lookup_id(shp, id);
2159+
smb_addinfo_t add;
2160+
2161+
if (stp == NULL) {
2162+
return (-1); /* errno is set for us */
2163+
}
2164+
2165+
if (stp->smbst_hdr->smbh_type != SMB_TYPE_ADDINFO) {
2166+
return (smb_set_errno(shp, ESMB_TYPE));
2167+
}
2168+
2169+
if (stp->smbst_hdr->smbh_len < sizeof (add)) {
2170+
return (smb_set_errno(shp, ESMB_SHORT));
2171+
}
2172+
2173+
smb_info_bcopy(stp->smbst_hdr, &add, sizeof (add));
2174+
*nentsp = add.smbai_nents;
2175+
2176+
return (0);
2177+
}
2178+
2179+
void
2180+
smbios_info_addinfo_ent_free(smbios_hdl_t *hdl, smbios_addinfo_ent_t *ent)
2181+
{
2182+
if (ent->smbai_dlen > 0) {
2183+
ASSERT3P(ent->smbai_data, !=, NULL);
2184+
smb_free(ent->smbai_data, ent->smbai_dlen);
2185+
}
2186+
2187+
smb_free(ent, sizeof (smbios_addinfo_ent_t));
2188+
}
2189+
2190+
int
2191+
smbios_info_addinfo_ent(smbios_hdl_t *shp, id_t id, uint_t entno,
2192+
smbios_addinfo_ent_t **entp)
2193+
{
2194+
const smb_struct_t *stp = smb_lookup_id(shp, id);
2195+
size_t off;
2196+
smb_addinfo_t add;
2197+
smb_addinfo_ent_t ent;
2198+
smbios_addinfo_ent_t *entry;
2199+
uint_t i;
2200+
2201+
if (stp == NULL) {
2202+
return (-1); /* errno is set for us */
2203+
}
2204+
2205+
if (stp->smbst_hdr->smbh_type != SMB_TYPE_ADDINFO) {
2206+
return (smb_set_errno(shp, ESMB_TYPE));
2207+
}
2208+
2209+
if (stp->smbst_hdr->smbh_len < sizeof (add)) {
2210+
return (smb_set_errno(shp, ESMB_SHORT));
2211+
}
2212+
2213+
smb_info_bcopy(stp->smbst_hdr, &add, sizeof (add));
2214+
if (entno >= add.smbai_nents) {
2215+
return (smb_set_errno(shp, ESMB_REQVAL));
2216+
}
2217+
2218+
off = sizeof (add);
2219+
for (i = 0; i <= entno; i++) {
2220+
if (off + sizeof (ent) > stp->smbst_hdr->smbh_len) {
2221+
return (smb_set_errno(shp, ESMB_SHORT));
2222+
}
2223+
2224+
smb_info_bcopy_offset(stp->smbst_hdr, &ent, sizeof (ent), off);
2225+
if (ent.smbaie_len < sizeof (ent)) {
2226+
return (smb_set_errno(shp, ESMB_SHORT));
2227+
}
2228+
2229+
if (ent.smbaie_len + off > stp->smbst_hdr->smbh_len) {
2230+
return (smb_set_errno(shp, ESMB_CORRUPT));
2231+
}
2232+
2233+
if (i != entno) {
2234+
off += ent.smbaie_len;
2235+
}
2236+
}
2237+
2238+
entry = smb_alloc(sizeof (smbios_addinfo_ent_t));
2239+
if (entry == NULL) {
2240+
return (smb_set_errno(shp, ESMB_NOMEM));
2241+
}
2242+
2243+
entry->smbai_ref = ent.smbaie_rhdl;
2244+
entry->smbai_ref_off = ent.smbaie_off;
2245+
if (ent.smbaie_str != 0) {
2246+
entry->smbai_str = smb_strptr(stp, ent.smbaie_str);
2247+
} else {
2248+
entry->smbai_str = NULL;
2249+
}
2250+
entry->smbai_dlen = ent.smbaie_len - sizeof (ent);
2251+
if (entry->smbai_dlen > 0) {
2252+
entry->smbai_data = smb_alloc(entry->smbai_dlen);
2253+
if (entry->smbai_data == NULL) {
2254+
smb_free(entry, sizeof (smbios_addinfo_ent_t));
2255+
return (smb_set_errno(shp, ESMB_NOMEM));
2256+
}
2257+
smb_info_bcopy_offset(stp->smbst_hdr, entry->smbai_data,
2258+
entry->smbai_dlen, off + offsetof(smb_addinfo_ent_t,
2259+
smbaie_val));
2260+
} else {
2261+
entry->smbai_data = NULL;
2262+
}
2263+
2264+
*entp = entry;
2265+
return (0);
2266+
}

usr/src/lib/libsmbios/common/mapfile-vers

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
2323
# Copyright (c) 2018, Joyent, Inc.
2424
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
25-
# Copyright 2021 Oxide Computer Company
25+
# Copyright 2024 Oxide Computer Company
2626
#
2727

2828
#
@@ -44,6 +44,9 @@ $mapfile_version 2
4444
SYMBOL_VERSION SUNWprivate_1.1 {
4545
global:
4646
_smb_debug { ASSERT = { TYPE = OBJECT; SIZE = 4; }; };
47+
smbios_info_addinfo_ent;
48+
smbios_info_addinfo_ent_free;
49+
smbios_info_addinfo_nents;
4750
smbios_battery_chem_desc;
4851
smbios_bboard_flag_desc;
4952
smbios_bboard_flag_name;

usr/src/test/util-tests/tests/smbios/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#
1313
# Copyright (c) 2018, Joyent, Inc.
14-
# Copyright 2022 Oxide Computer Company
14+
# Copyright 2024 Oxide Computer Company
1515
#
1616

1717
include $(SRC)/Makefile.master
@@ -20,6 +20,7 @@ ROOTOPTPKG = $(ROOT)/opt/util-tests
2020
TESTDIR = $(ROOTOPTPKG)/tests/
2121

2222
OBJS = smbios.o \
23+
smbios_test_addinfo.o \
2324
smbios_test_chassis.o \
2425
smbios_test_errors.o \
2526
smbios_test_extmemdevice.o \

usr/src/test/util-tests/tests/smbios/smbios.c

+52-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/*
1313
* Copyright (c) 2018, Joyent, Inc.
14-
* Copyright 2023 Oxide Computer Company
14+
* Copyright 2024 Oxide Computer Company
1515
*/
1616

1717
/*
@@ -584,7 +584,58 @@ static const smbios_test_t smbios_tests[] = {
584584
.st_canopen = B_TRUE,
585585
.st_verify = smbios_test_extmem_verify_invlen_cs,
586586
.st_desc = "SMBIOS Sun extended memory device invalid cs length"
587+
},
588+
{
589+
.st_entry = SMBIOS_ENTRY_POINT_30,
590+
.st_tvers = SMB_VERSION,
591+
.st_libvers = SMB_VERSION,
592+
.st_mktable = smbios_test_addinfo_mktable_noent,
593+
.st_canopen = B_TRUE,
594+
.st_verify = smbios_test_addinfo_verify_noent,
595+
.st_desc = "additional information - no entries"
596+
}, {
597+
.st_entry = SMBIOS_ENTRY_POINT_30,
598+
.st_tvers = SMB_VERSION,
599+
.st_libvers = SMB_VERSION,
600+
.st_mktable = smbios_test_addinfo_mktable_ents,
601+
.st_canopen = B_TRUE,
602+
.st_verify = smbios_test_addinfo_verify_ents,
603+
.st_desc = "additional information - multiple entries"
604+
}, {
605+
.st_entry = SMBIOS_ENTRY_POINT_30,
606+
.st_tvers = SMB_VERSION,
607+
.st_libvers = SMB_VERSION,
608+
.st_mktable = smbios_test_addinfo_mktable_invlen_base,
609+
.st_canopen = B_TRUE,
610+
.st_verify = smbios_test_addinfo_verify_invlen_base,
611+
.st_desc = "additional information - invalid length: base"
612+
}, {
613+
.st_entry = SMBIOS_ENTRY_POINT_30,
614+
.st_tvers = SMB_VERSION,
615+
.st_libvers = SMB_VERSION,
616+
.st_mktable = smbios_test_addinfo_mktable_invlen_ent,
617+
.st_canopen = B_TRUE,
618+
.st_verify = smbios_test_addinfo_verify_invlen_ent,
619+
.st_desc = "additional information - invalid length: base entry"
620+
}, {
621+
.st_entry = SMBIOS_ENTRY_POINT_30,
622+
.st_tvers = SMB_VERSION,
623+
.st_libvers = SMB_VERSION,
624+
.st_mktable = smbios_test_addinfo_mktable_invlen_multient,
625+
.st_canopen = B_TRUE,
626+
.st_verify = smbios_test_addinfo_verify_invlen_multient,
627+
.st_desc = "additional information - invalid length: multiple "
628+
"entries"
629+
}, {
630+
.st_entry = SMBIOS_ENTRY_POINT_30,
631+
.st_tvers = SMB_VERSION,
632+
.st_libvers = SMB_VERSION,
633+
.st_mktable = smbios_test_addinfo_mktable_invlen_entdata,
634+
.st_canopen = B_TRUE,
635+
.st_verify = smbios_test_addinfo_verify_invlen_entdata,
636+
.st_desc = "additional information - invalid length: entry data"
587637
}
638+
/* XXX Missing an addinfo ent call with the wrong type to verify */
588639
};
589640

590641
static boolean_t

usr/src/test/util-tests/tests/smbios/smbios_test.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*/
1111

1212
/*
13-
* Copyright 2019 Robert Mustacchi
14-
* Copyright 2023 Oxide Computer Company
13+
* Copyright 2024 Oxide Computer Company
1514
*/
1615

1716
#ifndef _SMBIOS_TEST_H
@@ -150,7 +149,6 @@ extern boolean_t smbios_test_chassis_verify_comps(smbios_hdl_t *);
150149
extern boolean_t smbios_test_chassis_verify_sku_nocomps(smbios_hdl_t *);
151150
extern boolean_t smbios_test_chassis_verify_sku(smbios_hdl_t *);
152151

153-
154152
extern boolean_t smbios_test_proc_mktable_25(smbios_test_table_t *);
155153
extern boolean_t smbios_test_proc_mktable_36(smbios_test_table_t *);
156154
extern boolean_t smbios_test_proc_verify_25(smbios_hdl_t *);
@@ -164,6 +162,21 @@ extern boolean_t smbios_test_extmem_verify_invlen_cs(smbios_hdl_t *);
164162
extern boolean_t smbios_test_extmem_verify_nocs(smbios_hdl_t *);
165163
extern boolean_t smbios_test_extmem_verify_cs(smbios_hdl_t *);
166164

165+
extern boolean_t smbios_test_addinfo_mktable_noent(smbios_test_table_t *);
166+
extern boolean_t smbios_test_addinfo_mktable_ents(smbios_test_table_t *);
167+
extern boolean_t smbios_test_addinfo_mktable_invlen_base(smbios_test_table_t *);
168+
extern boolean_t smbios_test_addinfo_mktable_invlen_ent(smbios_test_table_t *);
169+
extern boolean_t smbios_test_addinfo_mktable_invlen_multient(
170+
smbios_test_table_t *);
171+
extern boolean_t smbios_test_addinfo_mktable_invlen_entdata(
172+
smbios_test_table_t *);
173+
extern boolean_t smbios_test_addinfo_verify_noent(smbios_hdl_t *);
174+
extern boolean_t smbios_test_addinfo_verify_ents(smbios_hdl_t *);
175+
extern boolean_t smbios_test_addinfo_verify_invlen_base(smbios_hdl_t *);
176+
extern boolean_t smbios_test_addinfo_verify_invlen_ent(smbios_hdl_t *);
177+
extern boolean_t smbios_test_addinfo_verify_invlen_multient(smbios_hdl_t *);
178+
extern boolean_t smbios_test_addinfo_verify_invlen_entdata(smbios_hdl_t *);
179+
167180
#ifdef __cplusplus
168181
}
169182
#endif

0 commit comments

Comments
 (0)