xref: /titanic_51/usr/src/common/smbios/smb_info.c (revision 0cf7d4e904aa4bd4edbfa2041fc6dd92298f04cc)
184ab085aSmws /*
284ab085aSmws  * CDDL HEADER START
384ab085aSmws  *
484ab085aSmws  * The contents of this file are subject to the terms of the
5c7c09f80SEric Schrock  * Common Development and Distribution License (the "License").
6c7c09f80SEric Schrock  * You may not use this file except in compliance with the License.
784ab085aSmws  *
884ab085aSmws  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
984ab085aSmws  * or http://www.opensolaris.org/os/licensing.
1084ab085aSmws  * See the License for the specific language governing permissions
1184ab085aSmws  * and limitations under the License.
1284ab085aSmws  *
1384ab085aSmws  * When distributing Covered Code, include this CDDL HEADER in each
1484ab085aSmws  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1584ab085aSmws  * If applicable, add the following below this CDDL HEADER, with the
1684ab085aSmws  * fields enclosed by brackets "[]" replaced with your own identifying
1784ab085aSmws  * information: Portions Copyright [yyyy] [name of copyright owner]
1884ab085aSmws  *
1984ab085aSmws  * CDDL HEADER END
2084ab085aSmws  */
2184ab085aSmws 
2284ab085aSmws /*
234e901881SDale Ghent  * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
24*0cf7d4e9SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
2503f9f63dSTom Pothier  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2684ab085aSmws  * Use is subject to license terms.
2784ab085aSmws  */
2884ab085aSmws 
2984ab085aSmws /*
3084ab085aSmws  * SMBIOS Information Routines
3184ab085aSmws  *
3284ab085aSmws  * The routines in this file are used to convert from the SMBIOS data format to
3384ab085aSmws  * a more reasonable and stable set of structures offered as part of our ABI.
3484ab085aSmws  * These functions take the general form:
3584ab085aSmws  *
3684ab085aSmws  *	stp = smb_lookup_type(shp, foo);
3784ab085aSmws  *	smb_foo_t foo;
3884ab085aSmws  *
3984ab085aSmws  *	smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
4084ab085aSmws  *      bzero(caller's struct);
4184ab085aSmws  *
4284ab085aSmws  *	copy/convert foo members into caller's struct
4384ab085aSmws  *
4484ab085aSmws  * We copy the internal structure on to an automatic variable so as to avoid
4584ab085aSmws  * checks everywhere for structures that the BIOS has improperly truncated, and
4684ab085aSmws  * also to automatically handle the case of a structure that has been extended.
4784ab085aSmws  * When necessary, this code can use smb_gteq() to determine whether the SMBIOS
4884ab085aSmws  * data is of a particular revision that is supposed to contain a new field.
496734c4b0SRobert Mustacchi  *
506734c4b0SRobert Mustacchi  * Note, when trying to bzero the caller's struct you have to be careful about
516734c4b0SRobert Mustacchi  * versions. One can only bzero the initial version that existed in illumos. In
526734c4b0SRobert Mustacchi  * other words, if someone passes an older library handle that doesn't support a
536734c4b0SRobert Mustacchi  * version you cannot assume that their structures have those additional members
546734c4b0SRobert Mustacchi  * in them. Instead, a 'base' version is introduced for such types that have
556734c4b0SRobert Mustacchi  * differences and instead we only bzero out the base version and then handle
566734c4b0SRobert Mustacchi  * the additional members. In general, because all additional members will be
576734c4b0SRobert Mustacchi  * assigned, there's no reason to zero them out unless they are arrays that
586734c4b0SRobert Mustacchi  * won't be entirely filled in.
596734c4b0SRobert Mustacchi  *
606734c4b0SRobert Mustacchi  * Due to history, anything added after the update from version 2.4, in other
616734c4b0SRobert Mustacchi  * words additions from or after '5094 Update libsmbios with recent items'
626734c4b0SRobert Mustacchi  * (4e901881) is currently being used for this. While we don't allow software
636734c4b0SRobert Mustacchi  * compiling against this to get an older form, this was the first major update
646734c4b0SRobert Mustacchi  * and a good starting point for us to enforce this behavior which is useful for
656734c4b0SRobert Mustacchi  * moving forward to making this more public.
6684ab085aSmws  */
6784ab085aSmws 
6884ab085aSmws #include <sys/smbios_impl.h>
6938d76b18SRobert Mustacchi #include <sys/byteorder.h>
7084ab085aSmws 
719c94f155SCheng Sean Ye #ifdef _KERNEL
729c94f155SCheng Sean Ye #include <sys/sunddi.h>
739c94f155SCheng Sean Ye #else
74c7c09f80SEric Schrock #include <fcntl.h>
75c7c09f80SEric Schrock #include <unistd.h>
769c94f155SCheng Sean Ye #include <string.h>
77c7c09f80SEric Schrock #endif
78c7c09f80SEric Schrock 
7984ab085aSmws /*
8084ab085aSmws  * A large number of SMBIOS structures contain a set of common strings used to
8184ab085aSmws  * describe a h/w component's serial number, manufacturer, etc.  These fields
8284ab085aSmws  * helpfully have different names and offsets and sometimes aren't consistent.
8384ab085aSmws  * To simplify life for our clients, we factor these common things out into
8484ab085aSmws  * smbios_info_t, which can be retrieved for any structure.  The following
8584ab085aSmws  * table describes the mapping from a given structure to the smbios_info_t.
86074bb90dSTom Pothier  * Multiple SMBIOS stuctures' contained objects are also handled here.
8784ab085aSmws  */
8884ab085aSmws static const struct smb_infospec {
8984ab085aSmws 	uint8_t is_type;		/* structure type */
9084ab085aSmws 	uint8_t is_manu;		/* manufacturer offset */
9184ab085aSmws 	uint8_t is_product;		/* product name offset */
9284ab085aSmws 	uint8_t is_version;		/* version offset */
9384ab085aSmws 	uint8_t is_serial;		/* serial number offset */
9484ab085aSmws 	uint8_t is_asset;		/* asset tag offset */
9584ab085aSmws 	uint8_t is_location;		/* location string offset */
9684ab085aSmws 	uint8_t is_part;		/* part number offset */
97074bb90dSTom Pothier 	uint8_t is_contc;		/* contained count */
98074bb90dSTom Pothier 	uint8_t is_contsz;		/* contained size */
99074bb90dSTom Pothier 	uint8_t is_contv;		/* contained objects */
10084ab085aSmws } _smb_infospecs[] = {
10184ab085aSmws 	{ SMB_TYPE_SYSTEM,
10284ab085aSmws 		offsetof(smb_system_t, smbsi_manufacturer),
10384ab085aSmws 		offsetof(smb_system_t, smbsi_product),
10484ab085aSmws 		offsetof(smb_system_t, smbsi_version),
10584ab085aSmws 		offsetof(smb_system_t, smbsi_serial),
10684ab085aSmws 		0,
10784ab085aSmws 		0,
108074bb90dSTom Pothier 		0,
109074bb90dSTom Pothier 		0,
110074bb90dSTom Pothier 		0,
11184ab085aSmws 		0 },
11284ab085aSmws 	{ SMB_TYPE_BASEBOARD,
11384ab085aSmws 		offsetof(smb_bboard_t, smbbb_manufacturer),
11484ab085aSmws 		offsetof(smb_bboard_t, smbbb_product),
11584ab085aSmws 		offsetof(smb_bboard_t, smbbb_version),
11684ab085aSmws 		offsetof(smb_bboard_t, smbbb_serial),
11784ab085aSmws 		offsetof(smb_bboard_t, smbbb_asset),
11884ab085aSmws 		offsetof(smb_bboard_t, smbbb_location),
119074bb90dSTom Pothier 		0,
120074bb90dSTom Pothier 		offsetof(smb_bboard_t, smbbb_cn),
121074bb90dSTom Pothier 		SMB_CONT_WORD,
122074bb90dSTom Pothier 		offsetof(smb_bboard_t, smbbb_cv) },
12384ab085aSmws 	{ SMB_TYPE_CHASSIS,
12484ab085aSmws 		offsetof(smb_chassis_t, smbch_manufacturer),
12584ab085aSmws 		0,
12684ab085aSmws 		offsetof(smb_chassis_t, smbch_version),
12784ab085aSmws 		offsetof(smb_chassis_t, smbch_serial),
12884ab085aSmws 		offsetof(smb_chassis_t, smbch_asset),
12984ab085aSmws 		0,
130074bb90dSTom Pothier 		0,
131074bb90dSTom Pothier 		offsetof(smb_chassis_t, smbch_cn),
132074bb90dSTom Pothier 		SMB_CONT_BYTE,
133074bb90dSTom Pothier 		offsetof(smb_chassis_t, smbch_cv) },
13484ab085aSmws 	{ SMB_TYPE_PROCESSOR,
13584ab085aSmws 		offsetof(smb_processor_t, smbpr_manufacturer),
13684ab085aSmws 		0,
13784ab085aSmws 		offsetof(smb_processor_t, smbpr_version),
13884ab085aSmws 		offsetof(smb_processor_t, smbpr_serial),
13984ab085aSmws 		offsetof(smb_processor_t, smbpr_asset),
14084ab085aSmws 		offsetof(smb_processor_t, smbpr_socket),
141074bb90dSTom Pothier 		offsetof(smb_processor_t, smbpr_part),
142074bb90dSTom Pothier 		0,
143074bb90dSTom Pothier 		0,
144074bb90dSTom Pothier 		0 },
14584ab085aSmws 	{ SMB_TYPE_CACHE,
14684ab085aSmws 		0,
14784ab085aSmws 		0,
14884ab085aSmws 		0,
14984ab085aSmws 		0,
15084ab085aSmws 		0,
15184ab085aSmws 		offsetof(smb_cache_t, smbca_socket),
152074bb90dSTom Pothier 		0,
153074bb90dSTom Pothier 		0,
154074bb90dSTom Pothier 		0,
15584ab085aSmws 		0 },
15684ab085aSmws 	{ SMB_TYPE_PORT,
15784ab085aSmws 		0,
15884ab085aSmws 		0,
15984ab085aSmws 		0,
16084ab085aSmws 		0,
16184ab085aSmws 		0,
16284ab085aSmws 		offsetof(smb_port_t, smbpo_iref),
163074bb90dSTom Pothier 		0,
164074bb90dSTom Pothier 		0,
165074bb90dSTom Pothier 		0,
16684ab085aSmws 		0 },
16784ab085aSmws 	{ SMB_TYPE_SLOT,
16884ab085aSmws 		0,
16984ab085aSmws 		0,
17084ab085aSmws 		0,
17184ab085aSmws 		0,
17284ab085aSmws 		0,
17384ab085aSmws 		offsetof(smb_slot_t, smbsl_name),
174074bb90dSTom Pothier 		0,
175074bb90dSTom Pothier 		0,
176074bb90dSTom Pothier 		0,
17784ab085aSmws 		0 },
17884ab085aSmws 	{ SMB_TYPE_MEMDEVICE,
17984ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_manufacturer),
18084ab085aSmws 		0,
18184ab085aSmws 		0,
18284ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_serial),
18384ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_asset),
18484ab085aSmws 		offsetof(smb_memdevice_t, smbmdev_dloc),
185074bb90dSTom Pothier 		offsetof(smb_memdevice_t, smbmdev_part),
186074bb90dSTom Pothier 		0,
187074bb90dSTom Pothier 		0,
188074bb90dSTom Pothier 		0 },
18984ab085aSmws 	{ SMB_TYPE_POWERSUP,
19084ab085aSmws 		offsetof(smb_powersup_t, smbpsup_manufacturer),
19184ab085aSmws 		offsetof(smb_powersup_t, smbpsup_devname),
19284ab085aSmws 		offsetof(smb_powersup_t, smbpsup_rev),
19384ab085aSmws 		offsetof(smb_powersup_t, smbpsup_serial),
19484ab085aSmws 		offsetof(smb_powersup_t, smbpsup_asset),
19584ab085aSmws 		offsetof(smb_powersup_t, smbpsup_loc),
196074bb90dSTom Pothier 		offsetof(smb_powersup_t, smbpsup_part),
197074bb90dSTom Pothier 		0,
198074bb90dSTom Pothier 		0,
199074bb90dSTom Pothier 		0 },
20084ab085aSmws 	{ SMB_TYPE_EOT }
20184ab085aSmws };
20284ab085aSmws 
20384ab085aSmws static const char *
20484ab085aSmws smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n)
20584ab085aSmws {
20684ab085aSmws 	const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr;
20784ab085aSmws 
20884ab085aSmws 	if (off != 0 && sp + off < stp->smbst_end) {
20984ab085aSmws 		(*n)++; /* indicate success for caller */
21084ab085aSmws 		return (smb_strptr(stp, sp[off]));
21184ab085aSmws 	}
21284ab085aSmws 
21384ab085aSmws 	return (smb_strptr(stp, 0));
21484ab085aSmws }
21584ab085aSmws 
21684ab085aSmws static void
21784ab085aSmws smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen)
21884ab085aSmws {
21984ab085aSmws 	if (dstlen > hp->smbh_len) {
22084ab085aSmws 		bcopy(hp, dst, hp->smbh_len);
22184ab085aSmws 		bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len);
22284ab085aSmws 	} else
22384ab085aSmws 		bcopy(hp, dst, dstlen);
22484ab085aSmws }
22584ab085aSmws 
226c325726fSToomas Soome smbios_entry_point_t
22784ab085aSmws smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
22884ab085aSmws {
22984ab085aSmws 	bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
230c325726fSToomas Soome 	return (shp->sh_ent_type);
231c325726fSToomas Soome }
232c325726fSToomas Soome 
233c325726fSToomas Soome void
234c325726fSToomas Soome smbios_info_smbios_version(smbios_hdl_t *shp, smbios_version_t *v)
235c325726fSToomas Soome {
236c325726fSToomas Soome 	v->smbv_major = SMB_MAJOR(shp->sh_smbvers);
237c325726fSToomas Soome 	v->smbv_minor = SMB_MINOR(shp->sh_smbvers);
23884ab085aSmws }
23984ab085aSmws 
240c7c09f80SEric Schrock #ifndef _KERNEL
241c7c09f80SEric Schrock static char smbios_product_override[256];
242c7c09f80SEric Schrock static boolean_t smbios_product_checked;
243c7c09f80SEric Schrock #endif
244c7c09f80SEric Schrock 
24584ab085aSmws int
24684ab085aSmws smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip)
24784ab085aSmws {
24884ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
24984ab085aSmws 	const struct smb_infospec *isp;
25084ab085aSmws 	int n = 0;
25184ab085aSmws 
25284ab085aSmws 	if (stp == NULL)
25384ab085aSmws 		return (-1); /* errno is set for us */
25484ab085aSmws 
25584ab085aSmws 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
25684ab085aSmws 		if (isp->is_type == stp->smbst_hdr->smbh_type)
25784ab085aSmws 			break;
25884ab085aSmws 	}
25984ab085aSmws 
26084ab085aSmws 	ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n);
26184ab085aSmws 	ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n);
26284ab085aSmws 	ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n);
26384ab085aSmws 	ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n);
26484ab085aSmws 	ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n);
26584ab085aSmws 	ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n);
26684ab085aSmws 	ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n);
26784ab085aSmws 
26884ab085aSmws 	/*
269c7c09f80SEric Schrock 	 * This private file allows developers to experiment with reporting
270c7c09f80SEric Schrock 	 * different platform strings from SMBIOS.  It is not a supported
271c7c09f80SEric Schrock 	 * mechanism in the long term, and does not work in the kernel.
272c7c09f80SEric Schrock 	 */
273c7c09f80SEric Schrock #ifndef _KERNEL
274c7c09f80SEric Schrock 	if (isp->is_type == SMB_TYPE_SYSTEM) {
275c7c09f80SEric Schrock 		if (!smbios_product_checked) {
276c7c09f80SEric Schrock 			int fd = open("/etc/smbios_product", O_RDONLY);
277c7c09f80SEric Schrock 			if (fd >= 0) {
278c7c09f80SEric Schrock 				(void) read(fd, smbios_product_override,
279c7c09f80SEric Schrock 				    sizeof (smbios_product_override) - 1);
280c7c09f80SEric Schrock 				(void) close(fd);
281c7c09f80SEric Schrock 			}
282c7c09f80SEric Schrock 			smbios_product_checked = B_TRUE;
283c7c09f80SEric Schrock 		}
284c7c09f80SEric Schrock 
285c7c09f80SEric Schrock 		if (smbios_product_override[0] != '\0')
286c7c09f80SEric Schrock 			ip->smbi_product = smbios_product_override;
287c7c09f80SEric Schrock 	}
288c7c09f80SEric Schrock #endif
289c7c09f80SEric Schrock 
290c7c09f80SEric Schrock 	/*
29184ab085aSmws 	 * If we have a port with an empty internal reference designator string
29284ab085aSmws 	 * try using the external reference designator string instead.
29384ab085aSmws 	 */
29484ab085aSmws 	if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') {
29584ab085aSmws 		ip->smbi_location = smb_info_strptr(stp,
29684ab085aSmws 		    offsetof(smb_port_t, smbpo_eref), &n);
29784ab085aSmws 	}
29884ab085aSmws 
29984ab085aSmws 	return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO));
30084ab085aSmws }
30184ab085aSmws 
302074bb90dSTom Pothier /*
303074bb90dSTom Pothier  * Returns the actual number of contained objects.
304074bb90dSTom Pothier  *
305074bb90dSTom Pothier  * idc - number of contained objects
306074bb90dSTom Pothier  * idv - returned array of contained objects
307074bb90dSTom Pothier  */
308074bb90dSTom Pothier int
309074bb90dSTom Pothier smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv)
310074bb90dSTom Pothier {
311074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
312074bb90dSTom Pothier 	const struct smb_infospec *isp;
313074bb90dSTom Pothier 	id_t *cp;
314074bb90dSTom Pothier 	uint_t size;
315074bb90dSTom Pothier 	uint8_t cnt;
316074bb90dSTom Pothier 	int i, n;
317074bb90dSTom Pothier 
318074bb90dSTom Pothier 	if (stp == NULL) {
319074bb90dSTom Pothier 		return (-1); /* errno is set for us */
320074bb90dSTom Pothier 	}
321074bb90dSTom Pothier 
322074bb90dSTom Pothier 	for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
323074bb90dSTom Pothier 		if (isp->is_type == stp->smbst_hdr->smbh_type)
324074bb90dSTom Pothier 			break;
325074bb90dSTom Pothier 	}
326074bb90dSTom Pothier 	if (isp->is_type == SMB_TYPE_EOT)
327074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
328074bb90dSTom Pothier 
329074bb90dSTom Pothier 	size = isp->is_contsz;
330074bb90dSTom Pothier 	cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc);
331074bb90dSTom Pothier 	cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv);
332074bb90dSTom Pothier 
333074bb90dSTom Pothier 	n = MIN(cnt, idc);
334074bb90dSTom Pothier 	for (i = 0; i < n; i++) {
335074bb90dSTom Pothier 		if (size == SMB_CONT_WORD)
336074bb90dSTom Pothier 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 2));
337074bb90dSTom Pothier 		else if (size == SMB_CONT_BYTE)
338074bb90dSTom Pothier 			idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 3));
339074bb90dSTom Pothier 		else
340074bb90dSTom Pothier 			return (smb_set_errno(shp, ESMB_INVAL));
341074bb90dSTom Pothier 	}
342074bb90dSTom Pothier 
343074bb90dSTom Pothier 	return (cnt);
344074bb90dSTom Pothier }
345074bb90dSTom Pothier 
34684ab085aSmws id_t
34784ab085aSmws smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp)
34884ab085aSmws {
34984ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS);
35084ab085aSmws 	const smb_bios_t *bip;
35184ab085aSmws 
35284ab085aSmws 	if (stp == NULL)
35384ab085aSmws 		return (-1); /* errno is set for us */
35484ab085aSmws 
35584ab085aSmws 	if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t))
35684ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
35784ab085aSmws 
35884ab085aSmws 	bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr;
35938d76b18SRobert Mustacchi 	bzero(bp, sizeof (smb_base_bios_t));
36038d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31)) {
36138d76b18SRobert Mustacchi 		bp->smbb_extromsize = 0;
36238d76b18SRobert Mustacchi 	}
36384ab085aSmws 
36484ab085aSmws 	bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor);
36584ab085aSmws 	bp->smbb_version = smb_strptr(stp, bip->smbbi_version);
36684ab085aSmws 	bp->smbb_segment = bip->smbbi_segment;
36784ab085aSmws 	bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate);
36884ab085aSmws 	bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1);
36984ab085aSmws 	bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment);
37084ab085aSmws 	bp->smbb_cflags = bip->smbbi_cflags;
37184ab085aSmws 
37284ab085aSmws 	/*
37384ab085aSmws 	 * If one or more extension bytes are present, reset smbb_xcflags to
37484ab085aSmws 	 * point to them.  Otherwise leave this member set to NULL.
37584ab085aSmws 	 */
37684ab085aSmws 	if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) {
37784ab085aSmws 		bp->smbb_xcflags = bip->smbbi_xcflags;
37884ab085aSmws 		bp->smbb_nxcflags = stp->smbst_hdr->smbh_len -
37984ab085aSmws 		    sizeof (smb_bios_t) + 1;
38084ab085aSmws 
38184ab085aSmws 		if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
38284ab085aSmws 		    smb_gteq(shp, SMB_VERSION_24)) {
38384ab085aSmws 			bp->smbb_biosv.smbv_major =
38484ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ];
38584ab085aSmws 			bp->smbb_biosv.smbv_minor =
38684ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN];
38784ab085aSmws 			bp->smbb_ecfwv.smbv_major =
38884ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ];
38984ab085aSmws 			bp->smbb_ecfwv.smbv_minor =
39084ab085aSmws 			    bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN];
39184ab085aSmws 		}
39238d76b18SRobert Mustacchi 
39338d76b18SRobert Mustacchi 		if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 &&
39438d76b18SRobert Mustacchi 		    smb_gteq(shp, SMB_VERSION_31)) {
39538d76b18SRobert Mustacchi 			uint16_t val;
39638d76b18SRobert Mustacchi 			uint64_t rs;
39738d76b18SRobert Mustacchi 
39838d76b18SRobert Mustacchi 			/*
39938d76b18SRobert Mustacchi 			 * Because of the fact that the extended size is a
40038d76b18SRobert Mustacchi 			 * uint16_t and we'd need to define an explicit
40138d76b18SRobert Mustacchi 			 * endian-aware way to access it, we don't include it in
40238d76b18SRobert Mustacchi 			 * the number of extended flags below and thus subtract
40338d76b18SRobert Mustacchi 			 * its size.
40438d76b18SRobert Mustacchi 			 */
40538d76b18SRobert Mustacchi 			bp->smbb_nxcflags -= sizeof (uint16_t);
40638d76b18SRobert Mustacchi 			bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val,
40738d76b18SRobert Mustacchi 			    sizeof (val));
40838d76b18SRobert Mustacchi 			val = LE_16(val);
40938d76b18SRobert Mustacchi 
41038d76b18SRobert Mustacchi 			/*
41138d76b18SRobert Mustacchi 			 * The upper two bits of the extended rom size are used
41238d76b18SRobert Mustacchi 			 * to indicate whether the other 14 bits are in MB or
41338d76b18SRobert Mustacchi 			 * GB.
41438d76b18SRobert Mustacchi 			 */
41538d76b18SRobert Mustacchi 			rs = SMB_BIOS_EXTROM_VALUE_MASK(val);
41638d76b18SRobert Mustacchi 			switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) {
41738d76b18SRobert Mustacchi 			case 0:
41838d76b18SRobert Mustacchi 				rs *= 1024ULL * 1024ULL;
41938d76b18SRobert Mustacchi 				break;
42038d76b18SRobert Mustacchi 			case 1:
42138d76b18SRobert Mustacchi 				rs *= 1024ULL * 1024ULL * 1024ULL;
42238d76b18SRobert Mustacchi 				break;
42338d76b18SRobert Mustacchi 			default:
42438d76b18SRobert Mustacchi 				rs = 0;
42538d76b18SRobert Mustacchi 				break;
42638d76b18SRobert Mustacchi 			}
42738d76b18SRobert Mustacchi 
42838d76b18SRobert Mustacchi 			if (smb_libgteq(shp, SMB_VERSION_31)) {
42938d76b18SRobert Mustacchi 				bp->smbb_extromsize = rs;
43038d76b18SRobert Mustacchi 			}
43138d76b18SRobert Mustacchi 		}
43238d76b18SRobert Mustacchi 	}
43338d76b18SRobert Mustacchi 
43438d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) {
43538d76b18SRobert Mustacchi 		bp->smbb_extromsize = bp->smbb_romsize;
43684ab085aSmws 	}
43784ab085aSmws 
43884ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
43984ab085aSmws }
44084ab085aSmws 
44184ab085aSmws id_t
44284ab085aSmws smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip)
44384ab085aSmws {
44484ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM);
44584ab085aSmws 	smb_system_t si;
44684ab085aSmws 
44784ab085aSmws 	if (stp == NULL)
44884ab085aSmws 		return (-1); /* errno is set for us */
44984ab085aSmws 
45084ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si));
45184ab085aSmws 	bzero(sip, sizeof (smbios_system_t));
45284ab085aSmws 
45384ab085aSmws 	sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid;
45484ab085aSmws 	sip->smbs_uuidlen = sizeof (si.smbsi_uuid);
45584ab085aSmws 	sip->smbs_wakeup = si.smbsi_wakeup;
45684ab085aSmws 	sip->smbs_sku = smb_strptr(stp, si.smbsi_sku);
45784ab085aSmws 	sip->smbs_family = smb_strptr(stp, si.smbsi_family);
45884ab085aSmws 
45984ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
46084ab085aSmws }
46184ab085aSmws 
46284ab085aSmws int
46384ab085aSmws smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp)
46484ab085aSmws {
46584ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
46684ab085aSmws 	smb_bboard_t bb;
46784ab085aSmws 
46884ab085aSmws 	if (stp == NULL)
46984ab085aSmws 		return (-1); /* errno is set for us */
47084ab085aSmws 
47184ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD)
47284ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
47384ab085aSmws 
47484ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb));
47584ab085aSmws 	bzero(bbp, sizeof (smbios_bboard_t));
47684ab085aSmws 
47784ab085aSmws 	bbp->smbb_chassis = bb.smbbb_chassis;
47884ab085aSmws 	bbp->smbb_flags = bb.smbbb_flags;
47984ab085aSmws 	bbp->smbb_type = bb.smbbb_type;
480074bb90dSTom Pothier 	bbp->smbb_contn = bb.smbbb_cn;
48184ab085aSmws 
48284ab085aSmws 	return (0);
48384ab085aSmws }
48484ab085aSmws 
48584ab085aSmws int
48684ab085aSmws smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp)
48784ab085aSmws {
48884ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
4894e901881SDale Ghent 	/* Length is measurable by one byte, so it'll be no more than 255. */
4904e901881SDale Ghent 	uint8_t buf[256];
4914e901881SDale Ghent 	smb_chassis_t *ch = (smb_chassis_t *)&buf[0];
49284ab085aSmws 
49384ab085aSmws 	if (stp == NULL)
49484ab085aSmws 		return (-1); /* errno is set for us */
49584ab085aSmws 
49684ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS)
49784ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
49884ab085aSmws 
4994e901881SDale Ghent 	smb_info_bcopy(stp->smbst_hdr, ch, sizeof (buf));
5006734c4b0SRobert Mustacchi 	bzero(chp, sizeof (smb_base_chassis_t));
50138d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
5026734c4b0SRobert Mustacchi 		bzero(chp->smbc_sku, sizeof (chp->smbc_sku));
5036734c4b0SRobert Mustacchi 	}
50484ab085aSmws 
5054e901881SDale Ghent 	chp->smbc_oemdata = ch->smbch_oemdata;
5064e901881SDale Ghent 	chp->smbc_lock = (ch->smbch_type & SMB_CHT_LOCK) != 0;
5074e901881SDale Ghent 	chp->smbc_type = ch->smbch_type & ~SMB_CHT_LOCK;
5084e901881SDale Ghent 	chp->smbc_bustate = ch->smbch_bustate;
5094e901881SDale Ghent 	chp->smbc_psstate = ch->smbch_psstate;
5104e901881SDale Ghent 	chp->smbc_thstate = ch->smbch_thstate;
5114e901881SDale Ghent 	chp->smbc_security = ch->smbch_security;
5124e901881SDale Ghent 	chp->smbc_uheight = ch->smbch_uheight;
5134e901881SDale Ghent 	chp->smbc_cords = ch->smbch_cords;
5144e901881SDale Ghent 	chp->smbc_elems = ch->smbch_cn;
5154e901881SDale Ghent 	chp->smbc_elemlen = ch->smbch_cm;
5164e901881SDale Ghent 
51738d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
5184e901881SDale Ghent 		(void) strlcpy(chp->smbc_sku, SMB_CH_SKU(ch),
5194e901881SDale Ghent 		    sizeof (chp->smbc_sku));
5204e901881SDale Ghent 	}
52184ab085aSmws 
52284ab085aSmws 	return (0);
52384ab085aSmws }
52484ab085aSmws 
52584ab085aSmws int
52684ab085aSmws smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp)
52784ab085aSmws {
52884ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
52984ab085aSmws 	smb_processor_t p;
53084ab085aSmws 
53184ab085aSmws 	if (stp == NULL)
53284ab085aSmws 		return (-1); /* errno is set for us */
53384ab085aSmws 
53484ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR)
53584ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
53684ab085aSmws 
53784ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
5386734c4b0SRobert Mustacchi 	bzero(pp, sizeof (smb_base_processor_t));
53984ab085aSmws 
54084ab085aSmws 	pp->smbp_cpuid = p.smbpr_cpuid;
54184ab085aSmws 	pp->smbp_type = p.smbpr_type;
54284ab085aSmws 	pp->smbp_family = p.smbpr_family;
54384ab085aSmws 	pp->smbp_voltage = p.smbpr_voltage;
54484ab085aSmws 	pp->smbp_maxspeed = p.smbpr_maxspeed;
54584ab085aSmws 	pp->smbp_curspeed = p.smbpr_curspeed;
54684ab085aSmws 	pp->smbp_status = p.smbpr_status;
54784ab085aSmws 	pp->smbp_upgrade = p.smbpr_upgrade;
54884ab085aSmws 	pp->smbp_l1cache = p.smbpr_l1cache;
54984ab085aSmws 	pp->smbp_l2cache = p.smbpr_l2cache;
55084ab085aSmws 	pp->smbp_l3cache = p.smbpr_l3cache;
55184ab085aSmws 
55238d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_25)) {
5534e901881SDale Ghent 		pp->smbp_corecount = p.smbpr_corecount;
5544e901881SDale Ghent 		pp->smbp_coresenabled = p.smbpr_coresenabled;
5554e901881SDale Ghent 		pp->smbp_threadcount = p.smbpr_threadcount;
5564e901881SDale Ghent 		pp->smbp_cflags = p.smbpr_cflags;
5574e901881SDale Ghent 	}
5584e901881SDale Ghent 
55938d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_26)) {
5604e901881SDale Ghent 		pp->smbp_family2 = p.smbpr_family2;
56138d76b18SRobert Mustacchi 	}
5624e901881SDale Ghent 
56338d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_30)) {
5646734c4b0SRobert Mustacchi 		pp->smbp_corecount2 = p.smbpr_corecount2;
5656734c4b0SRobert Mustacchi 		pp->smbp_coresenabled2 = p.smbpr_coresenabled2;
5666734c4b0SRobert Mustacchi 		pp->smbp_threadcount2 = p.smbpr_threadcount2;
5676734c4b0SRobert Mustacchi 	}
5686734c4b0SRobert Mustacchi 
56984ab085aSmws 	return (0);
57084ab085aSmws }
57184ab085aSmws 
57284ab085aSmws int
57384ab085aSmws smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap)
57484ab085aSmws {
57584ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
57684ab085aSmws 	smb_cache_t c;
57784ab085aSmws 
57884ab085aSmws 	if (stp == NULL)
57984ab085aSmws 		return (-1); /* errno is set for us */
58084ab085aSmws 
58184ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE)
58284ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
58384ab085aSmws 
58484ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c));
58538d76b18SRobert Mustacchi 	bzero(cap, sizeof (smb_base_cache_t));
58684ab085aSmws 
58784ab085aSmws 	cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize);
58884ab085aSmws 	cap->smba_size = SMB_CACHE_SIZE(c.smbca_size);
58984ab085aSmws 	cap->smba_stype = c.smbca_stype;
59084ab085aSmws 	cap->smba_ctype = c.smbca_ctype;
59184ab085aSmws 	cap->smba_speed = c.smbca_speed;
59284ab085aSmws 	cap->smba_etype = c.smbca_etype;
59384ab085aSmws 	cap->smba_ltype = c.smbca_ltype;
59484ab085aSmws 	cap->smba_assoc = c.smbca_assoc;
59584ab085aSmws 	cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config);
59684ab085aSmws 	cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config);
59784ab085aSmws 	cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config);
59884ab085aSmws 
59984ab085aSmws 	if (SMB_CACHE_CFG_ENABLED(c.smbca_config))
60084ab085aSmws 		cap->smba_flags |= SMB_CAF_ENABLED;
60184ab085aSmws 
60284ab085aSmws 	if (SMB_CACHE_CFG_SOCKETED(c.smbca_config))
60384ab085aSmws 		cap->smba_flags |= SMB_CAF_SOCKETED;
60484ab085aSmws 
60538d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_31)) {
60638d76b18SRobert Mustacchi 		if (smb_gteq(shp, SMB_VERSION_31)) {
60738d76b18SRobert Mustacchi 			cap->smba_maxsize2 =
60838d76b18SRobert Mustacchi 			    SMB_CACHE_EXT_SIZE(c.smbca_maxsize2);
60938d76b18SRobert Mustacchi 			cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2);
61038d76b18SRobert Mustacchi 		} else {
61138d76b18SRobert Mustacchi 			cap->smba_maxsize2 = cap->smba_maxsize;
61238d76b18SRobert Mustacchi 			cap->smba_size2 = cap->smba_size;
61338d76b18SRobert Mustacchi 		}
61438d76b18SRobert Mustacchi 	}
61538d76b18SRobert Mustacchi 
61684ab085aSmws 	return (0);
61784ab085aSmws }
61884ab085aSmws 
61984ab085aSmws int
62084ab085aSmws smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop)
62184ab085aSmws {
62284ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
62384ab085aSmws 	smb_port_t p;
62484ab085aSmws 
62584ab085aSmws 	if (stp == NULL)
62684ab085aSmws 		return (-1); /* errno is set for us */
62784ab085aSmws 
62884ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT)
62984ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
63084ab085aSmws 
63184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
63284ab085aSmws 	bzero(pop, sizeof (smbios_port_t));
63384ab085aSmws 
63484ab085aSmws 	pop->smbo_iref = smb_strptr(stp, p.smbpo_iref);
63584ab085aSmws 	pop->smbo_eref = smb_strptr(stp, p.smbpo_eref);
63684ab085aSmws 
63784ab085aSmws 	pop->smbo_itype = p.smbpo_itype;
63884ab085aSmws 	pop->smbo_etype = p.smbpo_etype;
63984ab085aSmws 	pop->smbo_ptype = p.smbpo_ptype;
64084ab085aSmws 
64184ab085aSmws 	return (0);
64284ab085aSmws }
64384ab085aSmws 
64484ab085aSmws int
64584ab085aSmws smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp)
64684ab085aSmws {
64784ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
64884ab085aSmws 	smb_slot_t s;
64984ab085aSmws 
65084ab085aSmws 	if (stp == NULL)
65184ab085aSmws 		return (-1); /* errno is set for us */
65284ab085aSmws 
65384ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
65484ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
65584ab085aSmws 
65684ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
65784ab085aSmws 	bzero(sp, sizeof (smbios_slot_t));
65884ab085aSmws 
65984ab085aSmws 	sp->smbl_name = smb_strptr(stp, s.smbsl_name);
66084ab085aSmws 	sp->smbl_type = s.smbsl_type;
66184ab085aSmws 	sp->smbl_width = s.smbsl_width;
66284ab085aSmws 	sp->smbl_usage = s.smbsl_usage;
66384ab085aSmws 	sp->smbl_length = s.smbsl_length;
66484ab085aSmws 	sp->smbl_id = s.smbsl_id;
66584ab085aSmws 	sp->smbl_ch1 = s.smbsl_ch1;
66684ab085aSmws 	sp->smbl_ch2 = s.smbsl_ch2;
66703f9f63dSTom Pothier 	sp->smbl_sg = s.smbsl_sg;
66803f9f63dSTom Pothier 	sp->smbl_bus = s.smbsl_bus;
66903f9f63dSTom Pothier 	sp->smbl_df = s.smbsl_df;
67003f9f63dSTom Pothier 
67103f9f63dSTom Pothier 	return (0);
67203f9f63dSTom Pothier }
67303f9f63dSTom Pothier 
67403f9f63dSTom Pothier int
67503f9f63dSTom Pothier smbios_info_obdevs_ext(smbios_hdl_t *shp, id_t id, smbios_obdev_ext_t *oep)
67603f9f63dSTom Pothier {
67703f9f63dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
67803f9f63dSTom Pothier 	smb_obdev_ext_t obe;
67903f9f63dSTom Pothier 
68003f9f63dSTom Pothier 	if (stp == NULL)
68103f9f63dSTom Pothier 		return (-1); /* errno is set for us */
68203f9f63dSTom Pothier 
68303f9f63dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVEXT)
68403f9f63dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
68503f9f63dSTom Pothier 
68603f9f63dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &obe, sizeof (obe));
68703f9f63dSTom Pothier 	bzero(oep, sizeof (smbios_obdev_ext_t));
68803f9f63dSTom Pothier 
68903f9f63dSTom Pothier 	oep->smboe_name = smb_strptr(stp, obe.smbobe_name);
69003f9f63dSTom Pothier 	oep->smboe_dtype = obe.smbobe_dtype;
69103f9f63dSTom Pothier 	oep->smboe_dti = obe.smbobe_dti;
69203f9f63dSTom Pothier 	oep->smboe_sg = obe.smbobe_sg;
69303f9f63dSTom Pothier 	oep->smboe_bus = obe.smbobe_bus;
69403f9f63dSTom Pothier 	oep->smboe_df = obe.smbobe_df;
69584ab085aSmws 
69684ab085aSmws 	return (0);
69784ab085aSmws }
69884ab085aSmws 
69984ab085aSmws int
70084ab085aSmws smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp)
70184ab085aSmws {
70284ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
70384ab085aSmws 	const smb_obdev_t *op;
70484ab085aSmws 	int i, m, n;
70584ab085aSmws 
70684ab085aSmws 	if (stp == NULL)
70784ab085aSmws 		return (-1); /* errno is set for us */
70884ab085aSmws 
70984ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS)
71084ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
71184ab085aSmws 
71284ab085aSmws 	op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t));
71384ab085aSmws 	m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op);
71484ab085aSmws 	n = MIN(m, obc);
71584ab085aSmws 
71684ab085aSmws 	for (i = 0; i < n; i++, op++, obp++) {
71784ab085aSmws 		obp->smbd_name = smb_strptr(stp, op->smbob_name);
71884ab085aSmws 		obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED;
71984ab085aSmws 		obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0;
72084ab085aSmws 	}
72184ab085aSmws 
72284ab085aSmws 	return (m);
72384ab085aSmws }
72484ab085aSmws 
72584ab085aSmws /*
72684ab085aSmws  * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the
72784ab085aSmws  * first byte to indicate the size of a string table at the end of the record.
72884ab085aSmws  * Therefore, smbios_info_strtab() can be used to retrieve the table size and
72984ab085aSmws  * strings for any of these underlying record types.
73084ab085aSmws  */
73184ab085aSmws int
73284ab085aSmws smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[])
73384ab085aSmws {
73484ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
73584ab085aSmws 	smb_strtab_t s;
73684ab085aSmws 	int i, n;
73784ab085aSmws 
73884ab085aSmws 	if (stp == NULL)
73984ab085aSmws 		return (-1); /* errno is set for us */
74084ab085aSmws 
74184ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR &&
74284ab085aSmws 	    stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR &&
74384ab085aSmws 	    stp->smbst_hdr->smbh_type != SMB_TYPE_LANG)
74484ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
74584ab085aSmws 
74684ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
74784ab085aSmws 	n = MIN(s.smbtb_count, argc);
74884ab085aSmws 
74984ab085aSmws 	for (i = 0; i < n; i++)
75084ab085aSmws 		argv[i] = smb_strptr(stp, i + 1);
75184ab085aSmws 
75284ab085aSmws 	return (s.smbtb_count);
75384ab085aSmws }
75484ab085aSmws 
75584ab085aSmws id_t
75684ab085aSmws smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp)
75784ab085aSmws {
75884ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG);
75984ab085aSmws 	smb_lang_t l;
76084ab085aSmws 
76184ab085aSmws 	if (stp == NULL)
76284ab085aSmws 		return (-1); /* errno is set for us */
76384ab085aSmws 
76484ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l));
76584ab085aSmws 	bzero(lp, sizeof (smbios_lang_t));
76684ab085aSmws 
76784ab085aSmws 	lp->smbla_cur = smb_strptr(stp, l.smblang_cur);
76884ab085aSmws 	lp->smbla_fmt = l.smblang_flags & 1;
76984ab085aSmws 	lp->smbla_num = l.smblang_num;
77084ab085aSmws 
77184ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
77284ab085aSmws }
77384ab085aSmws 
77484ab085aSmws id_t
77584ab085aSmws smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp)
77684ab085aSmws {
77784ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG);
77884ab085aSmws 	const smb_sel_t *sel;
77984ab085aSmws 	size_t len;
78084ab085aSmws 
78184ab085aSmws 	if (stp == NULL)
78284ab085aSmws 		return (-1); /* errno is set for us */
78384ab085aSmws 
78484ab085aSmws 	if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t))
78584ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
78684ab085aSmws 
78784ab085aSmws 	sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr;
78884ab085aSmws 	len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t);
78984ab085aSmws 	bzero(evp, sizeof (smbios_evlog_t));
79084ab085aSmws 
79184ab085aSmws 	if (len < sel->smbsel_typec * sel->smbsel_typesz)
79284ab085aSmws 		return (smb_set_errno(shp, ESMB_CORRUPT));
79384ab085aSmws 
79484ab085aSmws 	evp->smbev_size = sel->smbsel_len;
79584ab085aSmws 	evp->smbev_hdr = sel->smbsel_hdroff;
79684ab085aSmws 	evp->smbev_data = sel->smbsel_dataoff;
79784ab085aSmws 	evp->smbev_method = sel->smbsel_method;
79884ab085aSmws 	evp->smbev_flags = sel->smbsel_status;
79984ab085aSmws 	evp->smbev_format = sel->smbsel_format;
80084ab085aSmws 	evp->smbev_token = sel->smbsel_token;
80184ab085aSmws 	evp->smbev_addr.eva_addr = sel->smbsel_addr;
80284ab085aSmws 
80384ab085aSmws 	if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) {
80484ab085aSmws 		evp->smbev_typec = sel->smbsel_typec;
80584ab085aSmws 		evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev;
80684ab085aSmws 	}
80784ab085aSmws 
80884ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
80984ab085aSmws }
81084ab085aSmws 
81184ab085aSmws int
81284ab085aSmws smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map)
81384ab085aSmws {
81484ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
81584ab085aSmws 	smb_memarray_t m;
81684ab085aSmws 
81784ab085aSmws 	if (stp == NULL)
81884ab085aSmws 		return (-1); /* errno is set for us */
81984ab085aSmws 
82084ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY)
82184ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
82284ab085aSmws 
82384ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
82484ab085aSmws 	bzero(map, sizeof (smbios_memarray_t));
82584ab085aSmws 
82684ab085aSmws 	map->smbma_location = m.smbmarr_loc;
82784ab085aSmws 	map->smbma_use = m.smbmarr_use;
82884ab085aSmws 	map->smbma_ecc = m.smbmarr_ecc;
82984ab085aSmws 	map->smbma_ndevs = m.smbmarr_ndevs;
83084ab085aSmws 	map->smbma_err = m.smbmarr_err;
83184ab085aSmws 
83284ab085aSmws 	if (m.smbmarr_cap != 0x80000000)
83384ab085aSmws 		map->smbma_size = (uint64_t)m.smbmarr_cap * 1024;
8344e901881SDale Ghent 	else if (m.smbmarr_extcap != 0)
8354e901881SDale Ghent 		map->smbma_size = m.smbmarr_extcap;
83684ab085aSmws 	else
83784ab085aSmws 		map->smbma_size = 0; /* unknown */
83884ab085aSmws 
83984ab085aSmws 	return (0);
84084ab085aSmws }
84184ab085aSmws 
84284ab085aSmws int
84384ab085aSmws smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map)
84484ab085aSmws {
84584ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
84684ab085aSmws 	smb_memarrmap_t m;
84784ab085aSmws 
84884ab085aSmws 	if (stp == NULL)
84984ab085aSmws 		return (-1); /* errno is set for us */
85084ab085aSmws 
85184ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP)
85284ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
85384ab085aSmws 
85484ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
85584ab085aSmws 	bzero(map, sizeof (smbios_memarrmap_t));
85684ab085aSmws 
85784ab085aSmws 	map->smbmam_array = m.smbamap_array;
85884ab085aSmws 	map->smbmam_width = m.smbamap_width;
8594e901881SDale Ghent 
8604e901881SDale Ghent 	if (m.smbamap_start != 0xFFFFFFFF && m.smbamap_end != 0xFFFFFFFF) {
86184ab085aSmws 		map->smbmam_addr = (uint64_t)m.smbamap_start * 1024;
86284ab085aSmws 		map->smbmam_size = (uint64_t)
86384ab085aSmws 		    (m.smbamap_end - m.smbamap_start + 1) * 1024;
8644e901881SDale Ghent 	} else if (m.smbamap_extstart != 0 && m.smbamap_extend != 0) {
8654e901881SDale Ghent 		map->smbmam_addr = m.smbamap_extstart;
8664e901881SDale Ghent 		map->smbmam_size = m.smbamap_extend - m.smbamap_extstart + 1;
8674e901881SDale Ghent 	}
86884ab085aSmws 
86984ab085aSmws 	return (0);
87084ab085aSmws }
87184ab085aSmws 
87284ab085aSmws int
87384ab085aSmws smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp)
87484ab085aSmws {
87584ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
87684ab085aSmws 	smb_memdevice_t m;
87784ab085aSmws 
87884ab085aSmws 	if (stp == NULL)
87984ab085aSmws 		return (-1); /* errno is set for us */
88084ab085aSmws 
88184ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE)
88284ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
88384ab085aSmws 
88484ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
8856734c4b0SRobert Mustacchi 	bzero(mdp, sizeof (smb_base_memdevice_t));
88684ab085aSmws 
88784ab085aSmws 	mdp->smbmd_array = m.smbmdev_array;
88884ab085aSmws 	mdp->smbmd_error = m.smbmdev_error;
88984ab085aSmws 	mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth;
89084ab085aSmws 	mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth;
89184ab085aSmws 
8924e901881SDale Ghent 	if (m.smbmdev_size == 0x7FFF) {
8934e901881SDale Ghent 		mdp->smbmd_size = (uint64_t)m.smbmdev_extsize;
8944e901881SDale Ghent 		mdp->smbmd_size *= 1024 * 1024; /* convert MB to bytes */
8954e901881SDale Ghent 	} else if (m.smbmdev_size != 0xFFFF) {
89684ab085aSmws 		mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES);
89784ab085aSmws 		if (m.smbmdev_size & SMB_MDS_KBYTES)
89884ab085aSmws 			mdp->smbmd_size *= 1024;
89984ab085aSmws 		else
90084ab085aSmws 			mdp->smbmd_size *= 1024 * 1024;
90184ab085aSmws 	} else
90284ab085aSmws 		mdp->smbmd_size = -1ULL; /* size unknown */
90384ab085aSmws 
90484ab085aSmws 	mdp->smbmd_form = m.smbmdev_form;
90584ab085aSmws 	mdp->smbmd_set = m.smbmdev_set;
90684ab085aSmws 	mdp->smbmd_type = m.smbmdev_type;
9074e901881SDale Ghent 	mdp->smbmd_speed = m.smbmdev_speed;
90884ab085aSmws 	mdp->smbmd_flags = m.smbmdev_flags;
90984ab085aSmws 	mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc);
91084ab085aSmws 	mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc);
91184ab085aSmws 
91238d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_26)) {
9134e901881SDale Ghent 		mdp->smbmd_rank = m.smbmdev_attrs & 0x0F;
91438d76b18SRobert Mustacchi 	}
9154e901881SDale Ghent 
91638d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27)) {
9174e901881SDale Ghent 		mdp->smbmd_clkspeed = m.smbmdev_clkspeed;
91838d76b18SRobert Mustacchi 	}
9194e901881SDale Ghent 
92038d76b18SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_28)) {
9214e901881SDale Ghent 		mdp->smbmd_minvolt = m.smbmdev_minvolt;
9224e901881SDale Ghent 		mdp->smbmd_maxvolt = m.smbmdev_maxvolt;
9234e901881SDale Ghent 		mdp->smbmd_confvolt = m.smbmdev_confvolt;
9244e901881SDale Ghent 	}
92584ab085aSmws 
92684ab085aSmws 	return (0);
92784ab085aSmws }
92884ab085aSmws 
92984ab085aSmws int
93084ab085aSmws smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp)
93184ab085aSmws {
93284ab085aSmws 	const smb_struct_t *stp = smb_lookup_id(shp, id);
93384ab085aSmws 	smb_memdevmap_t m;
93484ab085aSmws 
93584ab085aSmws 	if (stp == NULL)
93684ab085aSmws 		return (-1); /* errno is set for us */
93784ab085aSmws 
93884ab085aSmws 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP)
93984ab085aSmws 		return (smb_set_errno(shp, ESMB_TYPE));
94084ab085aSmws 
94184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
94284ab085aSmws 	bzero(mdp, sizeof (smbios_memdevmap_t));
94384ab085aSmws 
94484ab085aSmws 	mdp->smbmdm_device = m.smbdmap_device;
94584ab085aSmws 	mdp->smbmdm_arrmap = m.smbdmap_array;
94684ab085aSmws 	mdp->smbmdm_rpos = m.smbdmap_rpos;
94784ab085aSmws 	mdp->smbmdm_ipos = m.smbdmap_ipos;
94884ab085aSmws 	mdp->smbmdm_idepth = m.smbdmap_idepth;
94984ab085aSmws 
9504e901881SDale Ghent 	if (m.smbdmap_start != 0xFFFFFFFF && m.smbdmap_end != 0xFFFFFFFF) {
9514e901881SDale Ghent 		mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024;
9524e901881SDale Ghent 		mdp->smbmdm_size = (uint64_t)
9534e901881SDale Ghent 		    (m.smbdmap_end - m.smbdmap_start + 1) * 1024;
9544e901881SDale Ghent 	} else if (m.smbdmap_extstart != 0 && m.smbdmap_extend != 0) {
9554e901881SDale Ghent 		mdp->smbmdm_addr = m.smbdmap_extstart;
9564e901881SDale Ghent 		mdp->smbmdm_size = m.smbdmap_extend - m.smbdmap_extstart + 1;
9574e901881SDale Ghent 	}
9584e901881SDale Ghent 
95984ab085aSmws 	return (0);
96084ab085aSmws }
96184ab085aSmws 
96284ab085aSmws id_t
96384ab085aSmws smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp)
96484ab085aSmws {
96584ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY);
96684ab085aSmws 	smb_hwsec_t hs;
96784ab085aSmws 
96884ab085aSmws 	if (stp == NULL)
96984ab085aSmws 		return (-1); /* errno is set for us */
97084ab085aSmws 
97184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
97284ab085aSmws 	bzero(hsp, sizeof (smbios_hwsec_t));
97384ab085aSmws 
97484ab085aSmws 	hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
97584ab085aSmws 	hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
97684ab085aSmws 	hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
97784ab085aSmws 	hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
97884ab085aSmws 
97984ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
98084ab085aSmws }
98184ab085aSmws 
98284ab085aSmws id_t
98384ab085aSmws smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
98484ab085aSmws {
98584ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
986*0cf7d4e9SJohn Levon 	const smb_boot_t *b;
98784ab085aSmws 
98884ab085aSmws 	if (stp == NULL)
98984ab085aSmws 		return (-1); /* errno is set for us */
99084ab085aSmws 
99184ab085aSmws 	bzero(bp, sizeof (smbios_boot_t));
99284ab085aSmws 
993*0cf7d4e9SJohn Levon 	b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
994*0cf7d4e9SJohn Levon 
99584ab085aSmws 	bp->smbt_status = b->smbbo_status[0];
99684ab085aSmws 	bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
99784ab085aSmws 	bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
99884ab085aSmws 
99984ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
100084ab085aSmws }
100184ab085aSmws 
100284ab085aSmws id_t
100384ab085aSmws smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
100484ab085aSmws {
100584ab085aSmws 	const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
100684ab085aSmws 	smb_ipmi_t i;
100784ab085aSmws 
100884ab085aSmws 	if (stp == NULL)
100984ab085aSmws 		return (-1); /* errno is set for us */
101084ab085aSmws 
101184ab085aSmws 	smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
101284ab085aSmws 	bzero(ip, sizeof (smbios_ipmi_t));
101384ab085aSmws 
101484ab085aSmws 	ip->smbip_type = i.smbipm_type;
101584ab085aSmws 	ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec);
101684ab085aSmws 	ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec);
101784ab085aSmws 	ip->smbip_i2c = i.smbipm_i2c;
101884ab085aSmws 	ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO;
101984ab085aSmws 	ip->smbip_intr = i.smbipm_intr;
102084ab085aSmws 
102184ab085aSmws 	if (i.smbipm_bus != (uint8_t)-1)
102284ab085aSmws 		ip->smbip_bus = i.smbipm_bus;
102384ab085aSmws 	else
102484ab085aSmws 		ip->smbip_bus = -1u;
102584ab085aSmws 
102684ab085aSmws 	if (SMB_IPM_INFO_LSB(i.smbipm_info))
102784ab085aSmws 		ip->smbip_addr |= 1; /* turn on least-significant bit of addr */
102884ab085aSmws 
102984ab085aSmws 	if (i.smbipm_addr & SMB_IPM_ADDR_IO) {
103084ab085aSmws 		switch (SMB_IPM_INFO_REGS(i.smbipm_info)) {
103184ab085aSmws 		case SMB_IPM_REGS_1B:
103284ab085aSmws 			ip->smbip_regspacing = 1;
103384ab085aSmws 			break;
103484ab085aSmws 		case SMB_IPM_REGS_4B:
103584ab085aSmws 			ip->smbip_regspacing = 4;
103684ab085aSmws 			break;
103784ab085aSmws 		case SMB_IPM_REGS_16B:
103884ab085aSmws 			ip->smbip_regspacing = 16;
103984ab085aSmws 			break;
104084ab085aSmws 		default:
104184ab085aSmws 			ip->smbip_regspacing = 1;
104284ab085aSmws 		}
104384ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_IOADDR;
104484ab085aSmws 	}
104584ab085aSmws 
104684ab085aSmws 	if (SMB_IPM_INFO_ISPEC(i.smbipm_info))
104784ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTRSPEC;
104884ab085aSmws 
104984ab085aSmws 	if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI)
105084ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTRHIGH;
105184ab085aSmws 
105284ab085aSmws 	if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE)
105384ab085aSmws 		ip->smbip_flags |= SMB_IPMI_F_INTREDGE;
105484ab085aSmws 
105584ab085aSmws 	return (stp->smbst_hdr->smbh_hdl);
105684ab085aSmws }
10579c94f155SCheng Sean Ye 
10589c94f155SCheng Sean Ye static boolean_t
10599c94f155SCheng Sean Ye smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr)
10609c94f155SCheng Sean Ye {
10619c94f155SCheng Sean Ye 	const smb_struct_t *stp = shp->sh_structs;
10629c94f155SCheng Sean Ye 	smb_strtab_t s;
10639c94f155SCheng Sean Ye 	int i, j;
10649c94f155SCheng Sean Ye 
10659c94f155SCheng Sean Ye 	for (i = 0; i < shp->sh_nstructs; i++, stp++) {
10669c94f155SCheng Sean Ye 		if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR)
10679c94f155SCheng Sean Ye 			continue;
10689c94f155SCheng Sean Ye 
10699c94f155SCheng Sean Ye 		smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
10709c94f155SCheng Sean Ye 		for (j = 0; j < s.smbtb_count; j++)
10719c94f155SCheng Sean Ye 			if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0)
10729c94f155SCheng Sean Ye 				return (B_TRUE);
10739c94f155SCheng Sean Ye 	}
10749c94f155SCheng Sean Ye 
10759c94f155SCheng Sean Ye 	return (B_FALSE);
10769c94f155SCheng Sean Ye }
10779c94f155SCheng Sean Ye 
10789c94f155SCheng Sean Ye static const char *
10799c94f155SCheng Sean Ye smb_serial_valid(const char *serial)
10809c94f155SCheng Sean Ye {
10819c94f155SCheng Sean Ye 	char buf[MAXNAMELEN];
10829c94f155SCheng Sean Ye 	int i = 0;
10839c94f155SCheng Sean Ye 
10849c94f155SCheng Sean Ye 	if (serial == NULL)
10859c94f155SCheng Sean Ye 		return (NULL);
10869c94f155SCheng Sean Ye 
10879c94f155SCheng Sean Ye 	(void) strlcpy(buf, serial, sizeof (buf));
10889c94f155SCheng Sean Ye 
10899c94f155SCheng Sean Ye 	while (buf[i] != '\0' && buf[i] == ' ')
10909c94f155SCheng Sean Ye 		i++;
10919c94f155SCheng Sean Ye 
10929c94f155SCheng Sean Ye 	if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL ||
10939c94f155SCheng Sean Ye 	    strstr(buf, SMB_DEFAULT2) != NULL)
10949c94f155SCheng Sean Ye 		return (NULL);
10959c94f155SCheng Sean Ye 
10969c94f155SCheng Sean Ye 	return (serial);
10979c94f155SCheng Sean Ye }
10989c94f155SCheng Sean Ye 
10999c94f155SCheng Sean Ye /*
11009c94f155SCheng Sean Ye  * Get chassis SN or product SN
11019c94f155SCheng Sean Ye  */
11029c94f155SCheng Sean Ye static int
11039c94f155SCheng Sean Ye smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp)
11049c94f155SCheng Sean Ye {
11059c94f155SCheng Sean Ye 	const smb_struct_t *stp;
11069c94f155SCheng Sean Ye 	smbios_info_t s1, s3;
11079c94f155SCheng Sean Ye 
11089c94f155SCheng Sean Ye 	if (psnp == NULL || csnp == NULL)
11099c94f155SCheng Sean Ye 		return (smb_set_errno(shp, ESMB_INVAL));
11109c94f155SCheng Sean Ye 
11119c94f155SCheng Sean Ye 	*psnp = *csnp = NULL;
11129c94f155SCheng Sean Ye 
11139c94f155SCheng Sean Ye 	/*
11149c94f155SCheng Sean Ye 	 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN
11159c94f155SCheng Sean Ye 	 * from type 1 structure, and chassis SN from type 3 structure.
11169c94f155SCheng Sean Ye 	 * Otherwise return SN in type 1 structure as chassis SN.
11179c94f155SCheng Sean Ye 	 */
11189c94f155SCheng Sean Ye 
11199c94f155SCheng Sean Ye 	/* Get type 1 SN */
11209c94f155SCheng Sean Ye 	if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL ||
11219c94f155SCheng Sean Ye 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR)
11229c94f155SCheng Sean Ye 		s1.smbi_serial = NULL;
11239c94f155SCheng Sean Ye 
11249c94f155SCheng Sean Ye 	/* Get type 3 SN */
11259c94f155SCheng Sean Ye 	if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL ||
11269c94f155SCheng Sean Ye 	    smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR)
11279c94f155SCheng Sean Ye 		s3.smbi_serial = NULL;
11289c94f155SCheng Sean Ye 
11299c94f155SCheng Sean Ye 	if (smbios_has_oemstr(shp, SMB_PRMS1)) {
11309c94f155SCheng Sean Ye 		*psnp = smb_serial_valid(s1.smbi_serial);
11319c94f155SCheng Sean Ye 		*csnp = smb_serial_valid(s3.smbi_serial);
11329c94f155SCheng Sean Ye 	} else {
11339c94f155SCheng Sean Ye 		*csnp = smb_serial_valid(s1.smbi_serial);
11349c94f155SCheng Sean Ye 	}
11359c94f155SCheng Sean Ye 
11369c94f155SCheng Sean Ye 	return (0);
11379c94f155SCheng Sean Ye }
11389c94f155SCheng Sean Ye 
11399c94f155SCheng Sean Ye const char *
11409c94f155SCheng Sean Ye smbios_psn(smbios_hdl_t *shp)
11419c94f155SCheng Sean Ye {
11429c94f155SCheng Sean Ye 	const char *psn, *csn;
11439c94f155SCheng Sean Ye 
11449c94f155SCheng Sean Ye 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn);
11459c94f155SCheng Sean Ye }
11469c94f155SCheng Sean Ye 
11479c94f155SCheng Sean Ye const char *
11489c94f155SCheng Sean Ye smbios_csn(smbios_hdl_t *shp)
11499c94f155SCheng Sean Ye {
11509c94f155SCheng Sean Ye 	const char *psn, *csn;
11519c94f155SCheng Sean Ye 
11529c94f155SCheng Sean Ye 	return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn);
11539c94f155SCheng Sean Ye }
1154074bb90dSTom Pothier 
1155074bb90dSTom Pothier int
1156074bb90dSTom Pothier smbios_info_extprocessor(smbios_hdl_t *shp, id_t id,
1157074bb90dSTom Pothier     smbios_processor_ext_t *epp)
1158074bb90dSTom Pothier {
1159074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1160074bb90dSTom Pothier 	smb_processor_ext_t *exp;
1161074bb90dSTom Pothier 
1162074bb90dSTom Pothier 	if (stp == NULL)
1163074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1164074bb90dSTom Pothier 
1165074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR)
1166074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1167074bb90dSTom Pothier 
1168074bb90dSTom Pothier 	exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr;
1169074bb90dSTom Pothier 	bzero(epp, sizeof (smbios_processor_ext_t));
1170074bb90dSTom Pothier 
1171074bb90dSTom Pothier 	epp->smbpe_processor = exp->smbpre_processor;
1172074bb90dSTom Pothier 	epp->smbpe_fru = exp->smbpre_fru;
1173074bb90dSTom Pothier 	epp->smbpe_n = exp->smbpre_n;
1174074bb90dSTom Pothier 	epp->smbpe_apicid = exp->smbpre_apicid;
1175074bb90dSTom Pothier 
1176074bb90dSTom Pothier 	return (0);
1177074bb90dSTom Pothier }
1178074bb90dSTom Pothier 
1179074bb90dSTom Pothier int
118003f9f63dSTom Pothier smbios_info_extport(smbios_hdl_t *shp, id_t id, smbios_port_ext_t *eportp)
118103f9f63dSTom Pothier {
118203f9f63dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
118303f9f63dSTom Pothier 	smb_port_ext_t *ep;
118403f9f63dSTom Pothier 
118503f9f63dSTom Pothier 	if (stp == NULL)
118603f9f63dSTom Pothier 		return (-1); /* errno is set for us */
118703f9f63dSTom Pothier 
118803f9f63dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PORT)
118903f9f63dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
119003f9f63dSTom Pothier 
119103f9f63dSTom Pothier 	ep = (smb_port_ext_t *)(uintptr_t)stp->smbst_hdr;
119203f9f63dSTom Pothier 	bzero(eportp, sizeof (smbios_port_ext_t));
119303f9f63dSTom Pothier 
119403f9f63dSTom Pothier 	eportp->smbporte_chassis = ep->smbpoe_chassis;
119503f9f63dSTom Pothier 	eportp->smbporte_port = ep->smbpoe_port;
119603f9f63dSTom Pothier 	eportp->smbporte_dtype = ep->smbpoe_dtype;
119703f9f63dSTom Pothier 	eportp->smbporte_devhdl = ep->smbpoe_devhdl;
119803f9f63dSTom Pothier 	eportp->smbporte_phy = ep->smbpoe_phy;
119903f9f63dSTom Pothier 
120003f9f63dSTom Pothier 	return (0);
120103f9f63dSTom Pothier }
120203f9f63dSTom Pothier 
120303f9f63dSTom Pothier int
1204074bb90dSTom Pothier smbios_info_pciexrc(smbios_hdl_t *shp, id_t id,
1205074bb90dSTom Pothier     smbios_pciexrc_t *rcp)
1206074bb90dSTom Pothier {
1207074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1208074bb90dSTom Pothier 	smb_pciexrc_t rc;
1209074bb90dSTom Pothier 
1210074bb90dSTom Pothier 	if (stp == NULL)
1211074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1212074bb90dSTom Pothier 
1213074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC)
1214074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1215074bb90dSTom Pothier 
1216074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc));
1217074bb90dSTom Pothier 	bzero(rcp, sizeof (smbios_pciexrc_t));
1218074bb90dSTom Pothier 
1219074bb90dSTom Pothier 	rcp->smbpcie_bb = rc.smbpciexrc_bboard;
1220074bb90dSTom Pothier 	rcp->smbpcie_bdf = rc.smbpciexrc_bdf;
1221074bb90dSTom Pothier 
1222074bb90dSTom Pothier 	return (0);
1223074bb90dSTom Pothier }
1224074bb90dSTom Pothier 
1225074bb90dSTom Pothier int
1226074bb90dSTom Pothier smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap)
1227074bb90dSTom Pothier {
1228074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1229074bb90dSTom Pothier 	smb_memarray_ext_t exma;
1230074bb90dSTom Pothier 
1231074bb90dSTom Pothier 	if (stp == NULL)
1232074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1233074bb90dSTom Pothier 
1234074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY)
1235074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1236074bb90dSTom Pothier 
1237074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma));
1238074bb90dSTom Pothier 	bzero(emap, sizeof (smbios_memarray_ext_t));
1239074bb90dSTom Pothier 
1240074bb90dSTom Pothier 	emap->smbmae_ma = exma.smbmarre_ma;
1241074bb90dSTom Pothier 	emap->smbmae_comp = exma.smbmarre_component;
1242074bb90dSTom Pothier 	emap->smbmae_bdf = exma.smbmarre_bdf;
1243074bb90dSTom Pothier 
1244074bb90dSTom Pothier 	return (0);
1245074bb90dSTom Pothier }
1246074bb90dSTom Pothier 
1247074bb90dSTom Pothier int
1248074bb90dSTom Pothier smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id,
1249074bb90dSTom Pothier     smbios_memdevice_ext_t *emdp)
1250074bb90dSTom Pothier {
1251074bb90dSTom Pothier 	const smb_struct_t *stp = smb_lookup_id(shp, id);
1252074bb90dSTom Pothier 	smb_memdevice_ext_t exmd;
1253074bb90dSTom Pothier 
1254074bb90dSTom Pothier 	if (stp == NULL)
1255074bb90dSTom Pothier 		return (-1); /* errno is set for us */
1256074bb90dSTom Pothier 
1257074bb90dSTom Pothier 	if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE)
1258074bb90dSTom Pothier 		return (smb_set_errno(shp, ESMB_TYPE));
1259074bb90dSTom Pothier 
1260074bb90dSTom Pothier 	smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd));
1261074bb90dSTom Pothier 	bzero(emdp, sizeof (smbios_memdevice_ext_t));
1262074bb90dSTom Pothier 
1263074bb90dSTom Pothier 	emdp->smbmdeve_md = exmd.smbmdeve_mdev;
1264074bb90dSTom Pothier 	emdp->smbmdeve_drch = exmd.smbmdeve_dchan;
1265074bb90dSTom Pothier 	emdp->smbmdeve_ncs  = exmd.smbmdeve_ncs;
1266074bb90dSTom Pothier 	emdp->smbmdeve_cs = exmd.smbmdeve_cs;
1267074bb90dSTom Pothier 
1268074bb90dSTom Pothier 	return (0);
1269074bb90dSTom Pothier }
12702b9d2074SRobert Mustacchi 
12712b9d2074SRobert Mustacchi int
12722b9d2074SRobert Mustacchi smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup)
12732b9d2074SRobert Mustacchi {
12742b9d2074SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
12752b9d2074SRobert Mustacchi 	smb_powersup_t psu;
12762b9d2074SRobert Mustacchi 
12772b9d2074SRobert Mustacchi 	if (stp == NULL)
12782b9d2074SRobert Mustacchi 		return (-1); /* errno is set for us */
12792b9d2074SRobert Mustacchi 
12802b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP)
12812b9d2074SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
12822b9d2074SRobert Mustacchi 
12832b9d2074SRobert Mustacchi 	/* The minimum length required by the spec is 0x10. */
12842b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < 0x10)
12852b9d2074SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
12862b9d2074SRobert Mustacchi 
12872b9d2074SRobert Mustacchi 	bzero(psup, sizeof (*psup));
12882b9d2074SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu));
12892b9d2074SRobert Mustacchi 	psup->smbps_group = psu.smbpsup_group;
12902b9d2074SRobert Mustacchi 	psup->smbps_maxout = psu.smbpsup_max;
12912b9d2074SRobert Mustacchi 
12922b9d2074SRobert Mustacchi 	if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char))
12932b9d2074SRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_HOT;
12942b9d2074SRobert Mustacchi 	if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char))
12952b9d2074SRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_PRESENT;
12962b9d2074SRobert Mustacchi 	if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char))
12972b9d2074SRobert Mustacchi 		psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG;
12982b9d2074SRobert Mustacchi 
12992b9d2074SRobert Mustacchi 	psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char);
13002b9d2074SRobert Mustacchi 	psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char);
13012b9d2074SRobert Mustacchi 	psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char);
13022b9d2074SRobert Mustacchi 
13032b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x12) {
13042b9d2074SRobert Mustacchi 		psup->smbps_vprobe = psu.smbpsup_vprobe;
13052b9d2074SRobert Mustacchi 	} else {
13062b9d2074SRobert Mustacchi 		psup->smbps_vprobe = 0xffff;
13072b9d2074SRobert Mustacchi 	}
13082b9d2074SRobert Mustacchi 
13092b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x14) {
13102b9d2074SRobert Mustacchi 		psup->smbps_cooldev = psu.smbpsup_cooldev;
13112b9d2074SRobert Mustacchi 	} else {
13122b9d2074SRobert Mustacchi 		psup->smbps_cooldev = 0xffff;
13132b9d2074SRobert Mustacchi 	}
13142b9d2074SRobert Mustacchi 
13152b9d2074SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= 0x16) {
13162b9d2074SRobert Mustacchi 		psup->smbps_iprobe = psu.smbpsup_iprobe;
13172b9d2074SRobert Mustacchi 	} else {
13182b9d2074SRobert Mustacchi 		psup->smbps_iprobe = 0xffff;
13192b9d2074SRobert Mustacchi 	}
13202b9d2074SRobert Mustacchi 
13212b9d2074SRobert Mustacchi 	return (0);
13222b9d2074SRobert Mustacchi }
132345807aa8SRobert Mustacchi 
132445807aa8SRobert Mustacchi int
132545807aa8SRobert Mustacchi smbios_info_vprobe(smbios_hdl_t *shp, id_t id, smbios_vprobe_t *vprobe)
132645807aa8SRobert Mustacchi {
132745807aa8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
132845807aa8SRobert Mustacchi 	smb_vprobe_t vp;
132945807aa8SRobert Mustacchi 
133045807aa8SRobert Mustacchi 	if (stp == NULL)
133145807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
133245807aa8SRobert Mustacchi 
133345807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_VPROBE)
133445807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
133545807aa8SRobert Mustacchi 
133645807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_VPROBE_MINLEN)
133745807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
133845807aa8SRobert Mustacchi 
133945807aa8SRobert Mustacchi 	bzero(vprobe, sizeof (*vprobe));
134045807aa8SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &vp, sizeof (vp));
134145807aa8SRobert Mustacchi 	vprobe->smbvp_description = smb_strptr(stp, vp.smbvpr_descr);
134245807aa8SRobert Mustacchi 	vprobe->smbvp_location = SMB_VPROBE_LOCATION(vp.smbvpr_locstat);
134345807aa8SRobert Mustacchi 	vprobe->smbvp_status = SMB_VPROBE_STATUS(vp.smbvpr_locstat);
134445807aa8SRobert Mustacchi 	vprobe->smbvp_maxval = vp.smbvpr_maxval;
134545807aa8SRobert Mustacchi 	vprobe->smbvp_minval = vp.smbvpr_minval;
134645807aa8SRobert Mustacchi 	vprobe->smbvp_resolution = vp.smbvpr_resolution;
134745807aa8SRobert Mustacchi 	vprobe->smbvp_tolerance	= vp.smbvpr_tolerance;
134845807aa8SRobert Mustacchi 	vprobe->smbvp_accuracy = vp.smbvpr_accuracy;
134945807aa8SRobert Mustacchi 
135045807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_VPROBE_NOMINAL_MINLEN) {
135145807aa8SRobert Mustacchi 		vprobe->smbvp_nominal = vp.smbvpr_nominal;
135245807aa8SRobert Mustacchi 	} else {
135345807aa8SRobert Mustacchi 		vprobe->smbvp_nominal = SMB_PROBE_UNKNOWN_VALUE;
135445807aa8SRobert Mustacchi 	}
135545807aa8SRobert Mustacchi 
135645807aa8SRobert Mustacchi 	return (0);
135745807aa8SRobert Mustacchi }
135845807aa8SRobert Mustacchi 
135945807aa8SRobert Mustacchi int
136045807aa8SRobert Mustacchi smbios_info_cooldev(smbios_hdl_t *shp, id_t id, smbios_cooldev_t *cooldev)
136145807aa8SRobert Mustacchi {
136245807aa8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
136345807aa8SRobert Mustacchi 	smb_cooldev_t cd;
136445807aa8SRobert Mustacchi 
136545807aa8SRobert Mustacchi 	if (stp == NULL)
136645807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
136745807aa8SRobert Mustacchi 
136845807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_COOLDEV)
136945807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
137045807aa8SRobert Mustacchi 
137145807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_COOLDEV_MINLEN)
137245807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
137345807aa8SRobert Mustacchi 
137445807aa8SRobert Mustacchi 	bzero(cooldev, sizeof (*cooldev));
137545807aa8SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &cd, sizeof (cd));
137645807aa8SRobert Mustacchi 	cooldev->smbcd_tprobe = cd.smbcdev_tprobe;
137745807aa8SRobert Mustacchi 	cooldev->smbcd_type = SMB_COOLDEV_TYPE(cd.smbcdev_typstat);
137845807aa8SRobert Mustacchi 	cooldev->smbcd_status = SMB_COOLDEV_STATUS(cd.smbcdev_typstat);
137945807aa8SRobert Mustacchi 	cooldev->smbcd_group = cd.smbcdev_group;
138045807aa8SRobert Mustacchi 	cooldev->smbcd_oem = cd.smbcdev_oem;
138145807aa8SRobert Mustacchi 
138245807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_COOLDEV_NOMINAL_MINLEN) {
138345807aa8SRobert Mustacchi 		cooldev->smbcd_nominal = cd.smbcdev_nominal;
138445807aa8SRobert Mustacchi 	} else {
138545807aa8SRobert Mustacchi 		cooldev->smbcd_nominal = SMB_PROBE_UNKNOWN_VALUE;
138645807aa8SRobert Mustacchi 	}
138745807aa8SRobert Mustacchi 
138845807aa8SRobert Mustacchi 	/*
138945807aa8SRobert Mustacchi 	 * The description field was added in SMBIOS version 2.7. The
139045807aa8SRobert Mustacchi 	 * SMB_TYPE_COOLDEV support was only added after all of the 2.7+ fields
139145807aa8SRobert Mustacchi 	 * were added in the spec. So while a user may request an older version,
139245807aa8SRobert Mustacchi 	 * we don't have to worry about old structures and just simply skip it
139345807aa8SRobert Mustacchi 	 * if they're not asking for it.
139445807aa8SRobert Mustacchi 	 */
139545807aa8SRobert Mustacchi 	if (smb_libgteq(shp, SMB_VERSION_27) &&
139645807aa8SRobert Mustacchi 	    smb_gteq(shp, SMB_VERSION_27) &&
139745807aa8SRobert Mustacchi 	    stp->smbst_hdr->smbh_len >= SMB_COOLDEV_DESCR_MINLEN) {
139845807aa8SRobert Mustacchi 		cooldev->smbcd_descr = smb_strptr(stp, cd.smbcdev_descr);
139945807aa8SRobert Mustacchi 	} else {
140045807aa8SRobert Mustacchi 		cooldev->smbcd_descr = NULL;
140145807aa8SRobert Mustacchi 	}
140245807aa8SRobert Mustacchi 
140345807aa8SRobert Mustacchi 	return (0);
140445807aa8SRobert Mustacchi }
140545807aa8SRobert Mustacchi 
140645807aa8SRobert Mustacchi int
140745807aa8SRobert Mustacchi smbios_info_tprobe(smbios_hdl_t *shp, id_t id, smbios_tprobe_t *tprobe)
140845807aa8SRobert Mustacchi {
140945807aa8SRobert Mustacchi 	const smb_struct_t *stp = smb_lookup_id(shp, id);
141045807aa8SRobert Mustacchi 	smb_tprobe_t tp;
141145807aa8SRobert Mustacchi 
141245807aa8SRobert Mustacchi 	if (stp == NULL)
141345807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
141445807aa8SRobert Mustacchi 
141545807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_type != SMB_TYPE_TPROBE)
141645807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
141745807aa8SRobert Mustacchi 
141845807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len < SMB_TPROBE_MINLEN)
141945807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
142045807aa8SRobert Mustacchi 
142145807aa8SRobert Mustacchi 	bzero(tprobe, sizeof (*tprobe));
142245807aa8SRobert Mustacchi 	smb_info_bcopy(stp->smbst_hdr, &tp, sizeof (tp));
142345807aa8SRobert Mustacchi 	tprobe->smbtp_description = smb_strptr(stp, tp.smbtpr_descr);
142445807aa8SRobert Mustacchi 	tprobe->smbtp_location = SMB_TPROBE_LOCATION(tp.smbtpr_locstat);
142545807aa8SRobert Mustacchi 	tprobe->smbtp_status = SMB_TPROBE_STATUS(tp.smbtpr_locstat);
142645807aa8SRobert Mustacchi 	tprobe->smbtp_maxval = tp.smbtpr_maxval;
142745807aa8SRobert Mustacchi 	tprobe->smbtp_minval = tp.smbtpr_minval;
142845807aa8SRobert Mustacchi 	tprobe->smbtp_resolution = tp.smbtpr_resolution;
142945807aa8SRobert Mustacchi 	tprobe->smbtp_tolerance	= tp.smbtpr_tolerance;
143045807aa8SRobert Mustacchi 	tprobe->smbtp_accuracy = tp.smbtpr_accuracy;
143145807aa8SRobert Mustacchi 
143245807aa8SRobert Mustacchi 	if (stp->smbst_hdr->smbh_len >= SMB_TPROBE_NOMINAL_MINLEN) {
143345807aa8SRobert Mustacchi 		tprobe->smbtp_nominal = tp.smbtpr_nominal;
143445807aa8SRobert Mustacchi 	} else {
143545807aa8SRobert Mustacchi 		tprobe->smbtp_nominal = SMB_PROBE_UNKNOWN_VALUE;
143645807aa8SRobert Mustacchi 	}
143745807aa8SRobert Mustacchi 
143845807aa8SRobert Mustacchi 	return (0);
143945807aa8SRobert Mustacchi }
144045807aa8SRobert Mustacchi 
144145807aa8SRobert Mustacchi int
144245807aa8SRobert Mustacchi smbios_info_iprobe(smbios_hdl_t *shp, id_t id, smbios_iprobe_t *iprobe)
144345807aa8SRobert Mustacchi {
144445807aa8SRobert Mustacchi 	const smb_struct_t *sip = smb_lookup_id(shp, id);
144545807aa8SRobert Mustacchi 	smb_iprobe_t ip;
144645807aa8SRobert Mustacchi 
144745807aa8SRobert Mustacchi 	if (sip == NULL)
144845807aa8SRobert Mustacchi 		return (-1); /* errno is set for us */
144945807aa8SRobert Mustacchi 
145045807aa8SRobert Mustacchi 	if (sip->smbst_hdr->smbh_type != SMB_TYPE_IPROBE)
145145807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_TYPE));
145245807aa8SRobert Mustacchi 
145345807aa8SRobert Mustacchi 	if (sip->smbst_hdr->smbh_len < SMB_IPROBE_MINLEN)
145445807aa8SRobert Mustacchi 		return (smb_set_errno(shp, ESMB_SHORT));
145545807aa8SRobert Mustacchi 
145645807aa8SRobert Mustacchi 	bzero(iprobe, sizeof (*iprobe));
145745807aa8SRobert Mustacchi 	smb_info_bcopy(sip->smbst_hdr, &ip, sizeof (ip));
145845807aa8SRobert Mustacchi 	iprobe->smbip_description = smb_strptr(sip, ip.smbipr_descr);
145945807aa8SRobert Mustacchi 	iprobe->smbip_location = SMB_IPROBE_LOCATION(ip.smbipr_locstat);
146045807aa8SRobert Mustacchi 	iprobe->smbip_status = SMB_IPROBE_STATUS(ip.smbipr_locstat);
146145807aa8SRobert Mustacchi 	iprobe->smbip_maxval = ip.smbipr_maxval;
146245807aa8SRobert Mustacchi 	iprobe->smbip_minval = ip.smbipr_minval;
146345807aa8SRobert Mustacchi 	iprobe->smbip_resolution = ip.smbipr_resolution;
146445807aa8SRobert Mustacchi 	iprobe->smbip_tolerance	= ip.smbipr_tolerance;
146545807aa8SRobert Mustacchi 	iprobe->smbip_accuracy = ip.smbipr_accuracy;
146645807aa8SRobert Mustacchi 
146745807aa8SRobert Mustacchi 	if (sip->smbst_hdr->smbh_len >= SMB_IPROBE_NOMINAL_MINLEN) {
146845807aa8SRobert Mustacchi 		iprobe->smbip_nominal = ip.smbipr_nominal;
146945807aa8SRobert Mustacchi 	} else {
147045807aa8SRobert Mustacchi 		iprobe->smbip_nominal = SMB_PROBE_UNKNOWN_VALUE;
147145807aa8SRobert Mustacchi 	}
147245807aa8SRobert Mustacchi 
147345807aa8SRobert Mustacchi 	return (0);
147445807aa8SRobert Mustacchi }
1475