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 /* 23*9c94f155SCheng Sean Ye * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2484ab085aSmws * Use is subject to license terms. 2584ab085aSmws */ 2684ab085aSmws 2784ab085aSmws /* 2884ab085aSmws * SMBIOS Information Routines 2984ab085aSmws * 3084ab085aSmws * The routines in this file are used to convert from the SMBIOS data format to 3184ab085aSmws * a more reasonable and stable set of structures offered as part of our ABI. 3284ab085aSmws * These functions take the general form: 3384ab085aSmws * 3484ab085aSmws * stp = smb_lookup_type(shp, foo); 3584ab085aSmws * smb_foo_t foo; 3684ab085aSmws * 3784ab085aSmws * smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo)); 3884ab085aSmws * bzero(caller's struct); 3984ab085aSmws * 4084ab085aSmws * copy/convert foo members into caller's struct 4184ab085aSmws * 4284ab085aSmws * We copy the internal structure on to an automatic variable so as to avoid 4384ab085aSmws * checks everywhere for structures that the BIOS has improperly truncated, and 4484ab085aSmws * also to automatically handle the case of a structure that has been extended. 4584ab085aSmws * When necessary, this code can use smb_gteq() to determine whether the SMBIOS 4684ab085aSmws * data is of a particular revision that is supposed to contain a new field. 4784ab085aSmws */ 4884ab085aSmws 4984ab085aSmws #include <sys/smbios_impl.h> 5084ab085aSmws 51*9c94f155SCheng Sean Ye #ifdef _KERNEL 52*9c94f155SCheng Sean Ye #include <sys/sunddi.h> 53*9c94f155SCheng Sean Ye #else 54c7c09f80SEric Schrock #include <fcntl.h> 55c7c09f80SEric Schrock #include <unistd.h> 56*9c94f155SCheng Sean Ye #include <string.h> 57c7c09f80SEric Schrock #endif 58c7c09f80SEric Schrock 5984ab085aSmws /* 6084ab085aSmws * A large number of SMBIOS structures contain a set of common strings used to 6184ab085aSmws * describe a h/w component's serial number, manufacturer, etc. These fields 6284ab085aSmws * helpfully have different names and offsets and sometimes aren't consistent. 6384ab085aSmws * To simplify life for our clients, we factor these common things out into 6484ab085aSmws * smbios_info_t, which can be retrieved for any structure. The following 6584ab085aSmws * table describes the mapping from a given structure to the smbios_info_t. 6684ab085aSmws */ 6784ab085aSmws static const struct smb_infospec { 6884ab085aSmws uint8_t is_type; /* structure type */ 6984ab085aSmws uint8_t is_manu; /* manufacturer offset */ 7084ab085aSmws uint8_t is_product; /* product name offset */ 7184ab085aSmws uint8_t is_version; /* version offset */ 7284ab085aSmws uint8_t is_serial; /* serial number offset */ 7384ab085aSmws uint8_t is_asset; /* asset tag offset */ 7484ab085aSmws uint8_t is_location; /* location string offset */ 7584ab085aSmws uint8_t is_part; /* part number offset */ 7684ab085aSmws } _smb_infospecs[] = { 7784ab085aSmws { SMB_TYPE_SYSTEM, 7884ab085aSmws offsetof(smb_system_t, smbsi_manufacturer), 7984ab085aSmws offsetof(smb_system_t, smbsi_product), 8084ab085aSmws offsetof(smb_system_t, smbsi_version), 8184ab085aSmws offsetof(smb_system_t, smbsi_serial), 8284ab085aSmws 0, 8384ab085aSmws 0, 8484ab085aSmws 0 }, 8584ab085aSmws { SMB_TYPE_BASEBOARD, 8684ab085aSmws offsetof(smb_bboard_t, smbbb_manufacturer), 8784ab085aSmws offsetof(smb_bboard_t, smbbb_product), 8884ab085aSmws offsetof(smb_bboard_t, smbbb_version), 8984ab085aSmws offsetof(smb_bboard_t, smbbb_serial), 9084ab085aSmws offsetof(smb_bboard_t, smbbb_asset), 9184ab085aSmws offsetof(smb_bboard_t, smbbb_location), 9284ab085aSmws 0 }, 9384ab085aSmws { SMB_TYPE_CHASSIS, 9484ab085aSmws offsetof(smb_chassis_t, smbch_manufacturer), 9584ab085aSmws 0, 9684ab085aSmws offsetof(smb_chassis_t, smbch_version), 9784ab085aSmws offsetof(smb_chassis_t, smbch_serial), 9884ab085aSmws offsetof(smb_chassis_t, smbch_asset), 9984ab085aSmws 0, 10084ab085aSmws 0 }, 10184ab085aSmws { SMB_TYPE_PROCESSOR, 10284ab085aSmws offsetof(smb_processor_t, smbpr_manufacturer), 10384ab085aSmws 0, 10484ab085aSmws offsetof(smb_processor_t, smbpr_version), 10584ab085aSmws offsetof(smb_processor_t, smbpr_serial), 10684ab085aSmws offsetof(smb_processor_t, smbpr_asset), 10784ab085aSmws offsetof(smb_processor_t, smbpr_socket), 10884ab085aSmws offsetof(smb_processor_t, smbpr_part) }, 10984ab085aSmws { SMB_TYPE_CACHE, 11084ab085aSmws 0, 11184ab085aSmws 0, 11284ab085aSmws 0, 11384ab085aSmws 0, 11484ab085aSmws 0, 11584ab085aSmws offsetof(smb_cache_t, smbca_socket), 11684ab085aSmws 0 }, 11784ab085aSmws { SMB_TYPE_PORT, 11884ab085aSmws 0, 11984ab085aSmws 0, 12084ab085aSmws 0, 12184ab085aSmws 0, 12284ab085aSmws 0, 12384ab085aSmws offsetof(smb_port_t, smbpo_iref), 12484ab085aSmws 0 }, 12584ab085aSmws { SMB_TYPE_SLOT, 12684ab085aSmws 0, 12784ab085aSmws 0, 12884ab085aSmws 0, 12984ab085aSmws 0, 13084ab085aSmws 0, 13184ab085aSmws offsetof(smb_slot_t, smbsl_name), 13284ab085aSmws 0 }, 13384ab085aSmws { SMB_TYPE_MEMDEVICE, 13484ab085aSmws offsetof(smb_memdevice_t, smbmdev_manufacturer), 13584ab085aSmws 0, 13684ab085aSmws 0, 13784ab085aSmws offsetof(smb_memdevice_t, smbmdev_serial), 13884ab085aSmws offsetof(smb_memdevice_t, smbmdev_asset), 13984ab085aSmws offsetof(smb_memdevice_t, smbmdev_dloc), 14084ab085aSmws offsetof(smb_memdevice_t, smbmdev_part) }, 14184ab085aSmws { SMB_TYPE_POWERSUP, 14284ab085aSmws offsetof(smb_powersup_t, smbpsup_manufacturer), 14384ab085aSmws offsetof(smb_powersup_t, smbpsup_devname), 14484ab085aSmws offsetof(smb_powersup_t, smbpsup_rev), 14584ab085aSmws offsetof(smb_powersup_t, smbpsup_serial), 14684ab085aSmws offsetof(smb_powersup_t, smbpsup_asset), 14784ab085aSmws offsetof(smb_powersup_t, smbpsup_loc), 14884ab085aSmws offsetof(smb_powersup_t, smbpsup_part) }, 14984ab085aSmws { SMB_TYPE_EOT } 15084ab085aSmws }; 15184ab085aSmws 15284ab085aSmws static const char * 15384ab085aSmws smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n) 15484ab085aSmws { 15584ab085aSmws const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr; 15684ab085aSmws 15784ab085aSmws if (off != 0 && sp + off < stp->smbst_end) { 15884ab085aSmws (*n)++; /* indicate success for caller */ 15984ab085aSmws return (smb_strptr(stp, sp[off])); 16084ab085aSmws } 16184ab085aSmws 16284ab085aSmws return (smb_strptr(stp, 0)); 16384ab085aSmws } 16484ab085aSmws 16584ab085aSmws static void 16684ab085aSmws smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen) 16784ab085aSmws { 16884ab085aSmws if (dstlen > hp->smbh_len) { 16984ab085aSmws bcopy(hp, dst, hp->smbh_len); 17084ab085aSmws bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len); 17184ab085aSmws } else 17284ab085aSmws bcopy(hp, dst, dstlen); 17384ab085aSmws } 17484ab085aSmws 17584ab085aSmws void 17684ab085aSmws smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep) 17784ab085aSmws { 17884ab085aSmws bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t)); 17984ab085aSmws } 18084ab085aSmws 181c7c09f80SEric Schrock #ifndef _KERNEL 182c7c09f80SEric Schrock static char smbios_product_override[256]; 183c7c09f80SEric Schrock static boolean_t smbios_product_checked; 184c7c09f80SEric Schrock #endif 185c7c09f80SEric Schrock 18684ab085aSmws int 18784ab085aSmws smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip) 18884ab085aSmws { 18984ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 19084ab085aSmws const struct smb_infospec *isp; 19184ab085aSmws int n = 0; 19284ab085aSmws 19384ab085aSmws if (stp == NULL) 19484ab085aSmws return (-1); /* errno is set for us */ 19584ab085aSmws 19684ab085aSmws for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) { 19784ab085aSmws if (isp->is_type == stp->smbst_hdr->smbh_type) 19884ab085aSmws break; 19984ab085aSmws } 20084ab085aSmws 20184ab085aSmws ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n); 20284ab085aSmws ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n); 20384ab085aSmws ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n); 20484ab085aSmws ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n); 20584ab085aSmws ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n); 20684ab085aSmws ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n); 20784ab085aSmws ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n); 20884ab085aSmws 20984ab085aSmws /* 210c7c09f80SEric Schrock * This private file allows developers to experiment with reporting 211c7c09f80SEric Schrock * different platform strings from SMBIOS. It is not a supported 212c7c09f80SEric Schrock * mechanism in the long term, and does not work in the kernel. 213c7c09f80SEric Schrock */ 214c7c09f80SEric Schrock #ifndef _KERNEL 215c7c09f80SEric Schrock if (isp->is_type == SMB_TYPE_SYSTEM) { 216c7c09f80SEric Schrock if (!smbios_product_checked) { 217c7c09f80SEric Schrock int fd = open("/etc/smbios_product", O_RDONLY); 218c7c09f80SEric Schrock if (fd >= 0) { 219c7c09f80SEric Schrock (void) read(fd, smbios_product_override, 220c7c09f80SEric Schrock sizeof (smbios_product_override) - 1); 221c7c09f80SEric Schrock (void) close(fd); 222c7c09f80SEric Schrock } 223c7c09f80SEric Schrock smbios_product_checked = B_TRUE; 224c7c09f80SEric Schrock } 225c7c09f80SEric Schrock 226c7c09f80SEric Schrock if (smbios_product_override[0] != '\0') 227c7c09f80SEric Schrock ip->smbi_product = smbios_product_override; 228c7c09f80SEric Schrock } 229c7c09f80SEric Schrock #endif 230c7c09f80SEric Schrock 231c7c09f80SEric Schrock /* 23284ab085aSmws * If we have a port with an empty internal reference designator string 23384ab085aSmws * try using the external reference designator string instead. 23484ab085aSmws */ 23584ab085aSmws if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') { 23684ab085aSmws ip->smbi_location = smb_info_strptr(stp, 23784ab085aSmws offsetof(smb_port_t, smbpo_eref), &n); 23884ab085aSmws } 23984ab085aSmws 24084ab085aSmws return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO)); 24184ab085aSmws } 24284ab085aSmws 24384ab085aSmws id_t 24484ab085aSmws smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp) 24584ab085aSmws { 24684ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS); 24784ab085aSmws const smb_bios_t *bip; 24884ab085aSmws 24984ab085aSmws if (stp == NULL) 25084ab085aSmws return (-1); /* errno is set for us */ 25184ab085aSmws 25284ab085aSmws if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t)) 25384ab085aSmws return (smb_set_errno(shp, ESMB_CORRUPT)); 25484ab085aSmws 25584ab085aSmws bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr; 25684ab085aSmws bzero(bp, sizeof (smbios_bios_t)); 25784ab085aSmws 25884ab085aSmws bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor); 25984ab085aSmws bp->smbb_version = smb_strptr(stp, bip->smbbi_version); 26084ab085aSmws bp->smbb_segment = bip->smbbi_segment; 26184ab085aSmws bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate); 26284ab085aSmws bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1); 26384ab085aSmws bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment); 26484ab085aSmws bp->smbb_cflags = bip->smbbi_cflags; 26584ab085aSmws 26684ab085aSmws /* 26784ab085aSmws * If one or more extension bytes are present, reset smbb_xcflags to 26884ab085aSmws * point to them. Otherwise leave this member set to NULL. 26984ab085aSmws */ 27084ab085aSmws if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) { 27184ab085aSmws bp->smbb_xcflags = bip->smbbi_xcflags; 27284ab085aSmws bp->smbb_nxcflags = stp->smbst_hdr->smbh_len - 27384ab085aSmws sizeof (smb_bios_t) + 1; 27484ab085aSmws 27584ab085aSmws if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN && 27684ab085aSmws smb_gteq(shp, SMB_VERSION_24)) { 27784ab085aSmws bp->smbb_biosv.smbv_major = 27884ab085aSmws bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ]; 27984ab085aSmws bp->smbb_biosv.smbv_minor = 28084ab085aSmws bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN]; 28184ab085aSmws bp->smbb_ecfwv.smbv_major = 28284ab085aSmws bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ]; 28384ab085aSmws bp->smbb_ecfwv.smbv_minor = 28484ab085aSmws bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN]; 28584ab085aSmws } 28684ab085aSmws } 28784ab085aSmws 28884ab085aSmws return (stp->smbst_hdr->smbh_hdl); 28984ab085aSmws } 29084ab085aSmws 29184ab085aSmws id_t 29284ab085aSmws smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip) 29384ab085aSmws { 29484ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM); 29584ab085aSmws smb_system_t si; 29684ab085aSmws 29784ab085aSmws if (stp == NULL) 29884ab085aSmws return (-1); /* errno is set for us */ 29984ab085aSmws 30084ab085aSmws smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si)); 30184ab085aSmws bzero(sip, sizeof (smbios_system_t)); 30284ab085aSmws 30384ab085aSmws sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid; 30484ab085aSmws sip->smbs_uuidlen = sizeof (si.smbsi_uuid); 30584ab085aSmws sip->smbs_wakeup = si.smbsi_wakeup; 30684ab085aSmws sip->smbs_sku = smb_strptr(stp, si.smbsi_sku); 30784ab085aSmws sip->smbs_family = smb_strptr(stp, si.smbsi_family); 30884ab085aSmws 30984ab085aSmws return (stp->smbst_hdr->smbh_hdl); 31084ab085aSmws } 31184ab085aSmws 31284ab085aSmws int 31384ab085aSmws smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp) 31484ab085aSmws { 31584ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 31684ab085aSmws smb_bboard_t bb; 31784ab085aSmws 31884ab085aSmws if (stp == NULL) 31984ab085aSmws return (-1); /* errno is set for us */ 32084ab085aSmws 32184ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD) 32284ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 32384ab085aSmws 32484ab085aSmws smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb)); 32584ab085aSmws bzero(bbp, sizeof (smbios_bboard_t)); 32684ab085aSmws 32784ab085aSmws /* 32884ab085aSmws * At present, we do not provide support for the contained object 32984ab085aSmws * handles portion of the Base Board structure, as none of the 2.3+ 33084ab085aSmws * BIOSes commonly in use appear to implement it at present. 33184ab085aSmws */ 33284ab085aSmws bbp->smbb_chassis = bb.smbbb_chassis; 33384ab085aSmws bbp->smbb_flags = bb.smbbb_flags; 33484ab085aSmws bbp->smbb_type = bb.smbbb_type; 33584ab085aSmws 33684ab085aSmws return (0); 33784ab085aSmws } 33884ab085aSmws 33984ab085aSmws int 34084ab085aSmws smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp) 34184ab085aSmws { 34284ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 34384ab085aSmws smb_chassis_t ch; 34484ab085aSmws 34584ab085aSmws if (stp == NULL) 34684ab085aSmws return (-1); /* errno is set for us */ 34784ab085aSmws 34884ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS) 34984ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 35084ab085aSmws 35184ab085aSmws smb_info_bcopy(stp->smbst_hdr, &ch, sizeof (ch)); 35284ab085aSmws bzero(chp, sizeof (smbios_chassis_t)); 35384ab085aSmws 35484ab085aSmws /* 35584ab085aSmws * At present, we do not provide support for the contained object 35684ab085aSmws * handles portion of the Chassis structure, as none of the 2.3+ 35784ab085aSmws * BIOSes commonly in use appear to implement it at present. 35884ab085aSmws */ 35984ab085aSmws chp->smbc_oemdata = ch.smbch_oemdata; 36084ab085aSmws chp->smbc_lock = (ch.smbch_type & SMB_CHT_LOCK) != 0; 36184ab085aSmws chp->smbc_type = ch.smbch_type & ~SMB_CHT_LOCK; 36284ab085aSmws chp->smbc_bustate = ch.smbch_bustate; 36384ab085aSmws chp->smbc_psstate = ch.smbch_psstate; 36484ab085aSmws chp->smbc_thstate = ch.smbch_thstate; 36584ab085aSmws chp->smbc_security = ch.smbch_security; 36684ab085aSmws chp->smbc_uheight = ch.smbch_uheight; 36784ab085aSmws chp->smbc_cords = ch.smbch_cords; 36884ab085aSmws chp->smbc_elems = ch.smbch_cn; 36984ab085aSmws 37084ab085aSmws return (0); 37184ab085aSmws } 37284ab085aSmws 37384ab085aSmws int 37484ab085aSmws smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp) 37584ab085aSmws { 37684ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 37784ab085aSmws smb_processor_t p; 37884ab085aSmws 37984ab085aSmws if (stp == NULL) 38084ab085aSmws return (-1); /* errno is set for us */ 38184ab085aSmws 38284ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR) 38384ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 38484ab085aSmws 38584ab085aSmws smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p)); 38684ab085aSmws bzero(pp, sizeof (smbios_processor_t)); 38784ab085aSmws 38884ab085aSmws pp->smbp_cpuid = p.smbpr_cpuid; 38984ab085aSmws pp->smbp_type = p.smbpr_type; 39084ab085aSmws pp->smbp_family = p.smbpr_family; 39184ab085aSmws pp->smbp_voltage = p.smbpr_voltage; 39284ab085aSmws pp->smbp_maxspeed = p.smbpr_maxspeed; 39384ab085aSmws pp->smbp_curspeed = p.smbpr_curspeed; 39484ab085aSmws pp->smbp_status = p.smbpr_status; 39584ab085aSmws pp->smbp_upgrade = p.smbpr_upgrade; 39684ab085aSmws pp->smbp_l1cache = p.smbpr_l1cache; 39784ab085aSmws pp->smbp_l2cache = p.smbpr_l2cache; 39884ab085aSmws pp->smbp_l3cache = p.smbpr_l3cache; 39984ab085aSmws 40084ab085aSmws return (0); 40184ab085aSmws } 40284ab085aSmws 40384ab085aSmws int 40484ab085aSmws smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap) 40584ab085aSmws { 40684ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 40784ab085aSmws smb_cache_t c; 40884ab085aSmws 40984ab085aSmws if (stp == NULL) 41084ab085aSmws return (-1); /* errno is set for us */ 41184ab085aSmws 41284ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE) 41384ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 41484ab085aSmws 41584ab085aSmws smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c)); 41684ab085aSmws bzero(cap, sizeof (smbios_cache_t)); 41784ab085aSmws 41884ab085aSmws cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize); 41984ab085aSmws cap->smba_size = SMB_CACHE_SIZE(c.smbca_size); 42084ab085aSmws cap->smba_stype = c.smbca_stype; 42184ab085aSmws cap->smba_ctype = c.smbca_ctype; 42284ab085aSmws cap->smba_speed = c.smbca_speed; 42384ab085aSmws cap->smba_etype = c.smbca_etype; 42484ab085aSmws cap->smba_ltype = c.smbca_ltype; 42584ab085aSmws cap->smba_assoc = c.smbca_assoc; 42684ab085aSmws cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config); 42784ab085aSmws cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config); 42884ab085aSmws cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config); 42984ab085aSmws 43084ab085aSmws if (SMB_CACHE_CFG_ENABLED(c.smbca_config)) 43184ab085aSmws cap->smba_flags |= SMB_CAF_ENABLED; 43284ab085aSmws 43384ab085aSmws if (SMB_CACHE_CFG_SOCKETED(c.smbca_config)) 43484ab085aSmws cap->smba_flags |= SMB_CAF_SOCKETED; 43584ab085aSmws 43684ab085aSmws return (0); 43784ab085aSmws } 43884ab085aSmws 43984ab085aSmws int 44084ab085aSmws smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop) 44184ab085aSmws { 44284ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 44384ab085aSmws smb_port_t p; 44484ab085aSmws 44584ab085aSmws if (stp == NULL) 44684ab085aSmws return (-1); /* errno is set for us */ 44784ab085aSmws 44884ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT) 44984ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 45084ab085aSmws 45184ab085aSmws smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p)); 45284ab085aSmws bzero(pop, sizeof (smbios_port_t)); 45384ab085aSmws 45484ab085aSmws pop->smbo_iref = smb_strptr(stp, p.smbpo_iref); 45584ab085aSmws pop->smbo_eref = smb_strptr(stp, p.smbpo_eref); 45684ab085aSmws 45784ab085aSmws pop->smbo_itype = p.smbpo_itype; 45884ab085aSmws pop->smbo_etype = p.smbpo_etype; 45984ab085aSmws pop->smbo_ptype = p.smbpo_ptype; 46084ab085aSmws 46184ab085aSmws return (0); 46284ab085aSmws } 46384ab085aSmws 46484ab085aSmws int 46584ab085aSmws smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) 46684ab085aSmws { 46784ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 46884ab085aSmws smb_slot_t s; 46984ab085aSmws 47084ab085aSmws if (stp == NULL) 47184ab085aSmws return (-1); /* errno is set for us */ 47284ab085aSmws 47384ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT) 47484ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 47584ab085aSmws 47684ab085aSmws smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 47784ab085aSmws bzero(sp, sizeof (smbios_slot_t)); 47884ab085aSmws 47984ab085aSmws sp->smbl_name = smb_strptr(stp, s.smbsl_name); 48084ab085aSmws sp->smbl_type = s.smbsl_type; 48184ab085aSmws sp->smbl_width = s.smbsl_width; 48284ab085aSmws sp->smbl_usage = s.smbsl_usage; 48384ab085aSmws sp->smbl_length = s.smbsl_length; 48484ab085aSmws sp->smbl_id = s.smbsl_id; 48584ab085aSmws sp->smbl_ch1 = s.smbsl_ch1; 48684ab085aSmws sp->smbl_ch2 = s.smbsl_ch2; 48784ab085aSmws 48884ab085aSmws return (0); 48984ab085aSmws } 49084ab085aSmws 49184ab085aSmws int 49284ab085aSmws smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp) 49384ab085aSmws { 49484ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 49584ab085aSmws const smb_obdev_t *op; 49684ab085aSmws int i, m, n; 49784ab085aSmws 49884ab085aSmws if (stp == NULL) 49984ab085aSmws return (-1); /* errno is set for us */ 50084ab085aSmws 50184ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS) 50284ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 50384ab085aSmws 50484ab085aSmws op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t)); 50584ab085aSmws m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op); 50684ab085aSmws n = MIN(m, obc); 50784ab085aSmws 50884ab085aSmws for (i = 0; i < n; i++, op++, obp++) { 50984ab085aSmws obp->smbd_name = smb_strptr(stp, op->smbob_name); 51084ab085aSmws obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED; 51184ab085aSmws obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0; 51284ab085aSmws } 51384ab085aSmws 51484ab085aSmws return (m); 51584ab085aSmws } 51684ab085aSmws 51784ab085aSmws /* 51884ab085aSmws * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the 51984ab085aSmws * first byte to indicate the size of a string table at the end of the record. 52084ab085aSmws * Therefore, smbios_info_strtab() can be used to retrieve the table size and 52184ab085aSmws * strings for any of these underlying record types. 52284ab085aSmws */ 52384ab085aSmws int 52484ab085aSmws smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[]) 52584ab085aSmws { 52684ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 52784ab085aSmws smb_strtab_t s; 52884ab085aSmws int i, n; 52984ab085aSmws 53084ab085aSmws if (stp == NULL) 53184ab085aSmws return (-1); /* errno is set for us */ 53284ab085aSmws 53384ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR && 53484ab085aSmws stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR && 53584ab085aSmws stp->smbst_hdr->smbh_type != SMB_TYPE_LANG) 53684ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 53784ab085aSmws 53884ab085aSmws smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 53984ab085aSmws n = MIN(s.smbtb_count, argc); 54084ab085aSmws 54184ab085aSmws for (i = 0; i < n; i++) 54284ab085aSmws argv[i] = smb_strptr(stp, i + 1); 54384ab085aSmws 54484ab085aSmws return (s.smbtb_count); 54584ab085aSmws } 54684ab085aSmws 54784ab085aSmws id_t 54884ab085aSmws smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp) 54984ab085aSmws { 55084ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG); 55184ab085aSmws smb_lang_t l; 55284ab085aSmws 55384ab085aSmws if (stp == NULL) 55484ab085aSmws return (-1); /* errno is set for us */ 55584ab085aSmws 55684ab085aSmws smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l)); 55784ab085aSmws bzero(lp, sizeof (smbios_lang_t)); 55884ab085aSmws 55984ab085aSmws lp->smbla_cur = smb_strptr(stp, l.smblang_cur); 56084ab085aSmws lp->smbla_fmt = l.smblang_flags & 1; 56184ab085aSmws lp->smbla_num = l.smblang_num; 56284ab085aSmws 56384ab085aSmws return (stp->smbst_hdr->smbh_hdl); 56484ab085aSmws } 56584ab085aSmws 56684ab085aSmws id_t 56784ab085aSmws smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp) 56884ab085aSmws { 56984ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG); 57084ab085aSmws const smb_sel_t *sel; 57184ab085aSmws size_t len; 57284ab085aSmws 57384ab085aSmws if (stp == NULL) 57484ab085aSmws return (-1); /* errno is set for us */ 57584ab085aSmws 57684ab085aSmws if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t)) 57784ab085aSmws return (smb_set_errno(shp, ESMB_CORRUPT)); 57884ab085aSmws 57984ab085aSmws sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr; 58084ab085aSmws len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t); 58184ab085aSmws bzero(evp, sizeof (smbios_evlog_t)); 58284ab085aSmws 58384ab085aSmws if (len < sel->smbsel_typec * sel->smbsel_typesz) 58484ab085aSmws return (smb_set_errno(shp, ESMB_CORRUPT)); 58584ab085aSmws 58684ab085aSmws evp->smbev_size = sel->smbsel_len; 58784ab085aSmws evp->smbev_hdr = sel->smbsel_hdroff; 58884ab085aSmws evp->smbev_data = sel->smbsel_dataoff; 58984ab085aSmws evp->smbev_method = sel->smbsel_method; 59084ab085aSmws evp->smbev_flags = sel->smbsel_status; 59184ab085aSmws evp->smbev_format = sel->smbsel_format; 59284ab085aSmws evp->smbev_token = sel->smbsel_token; 59384ab085aSmws evp->smbev_addr.eva_addr = sel->smbsel_addr; 59484ab085aSmws 59584ab085aSmws if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) { 59684ab085aSmws evp->smbev_typec = sel->smbsel_typec; 59784ab085aSmws evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev; 59884ab085aSmws } 59984ab085aSmws 60084ab085aSmws return (stp->smbst_hdr->smbh_hdl); 60184ab085aSmws } 60284ab085aSmws 60384ab085aSmws int 60484ab085aSmws smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map) 60584ab085aSmws { 60684ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 60784ab085aSmws smb_memarray_t m; 60884ab085aSmws 60984ab085aSmws if (stp == NULL) 61084ab085aSmws return (-1); /* errno is set for us */ 61184ab085aSmws 61284ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY) 61384ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 61484ab085aSmws 61584ab085aSmws smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 61684ab085aSmws bzero(map, sizeof (smbios_memarray_t)); 61784ab085aSmws 61884ab085aSmws map->smbma_location = m.smbmarr_loc; 61984ab085aSmws map->smbma_use = m.smbmarr_use; 62084ab085aSmws map->smbma_ecc = m.smbmarr_ecc; 62184ab085aSmws map->smbma_ndevs = m.smbmarr_ndevs; 62284ab085aSmws map->smbma_err = m.smbmarr_err; 62384ab085aSmws 62484ab085aSmws if (m.smbmarr_cap != 0x80000000) 62584ab085aSmws map->smbma_size = (uint64_t)m.smbmarr_cap * 1024; 62684ab085aSmws else 62784ab085aSmws map->smbma_size = 0; /* unknown */ 62884ab085aSmws 62984ab085aSmws return (0); 63084ab085aSmws } 63184ab085aSmws 63284ab085aSmws int 63384ab085aSmws smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map) 63484ab085aSmws { 63584ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 63684ab085aSmws smb_memarrmap_t m; 63784ab085aSmws 63884ab085aSmws if (stp == NULL) 63984ab085aSmws return (-1); /* errno is set for us */ 64084ab085aSmws 64184ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP) 64284ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 64384ab085aSmws 64484ab085aSmws smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 64584ab085aSmws bzero(map, sizeof (smbios_memarrmap_t)); 64684ab085aSmws 64784ab085aSmws map->smbmam_array = m.smbamap_array; 64884ab085aSmws map->smbmam_width = m.smbamap_width; 64984ab085aSmws map->smbmam_addr = (uint64_t)m.smbamap_start * 1024; 65084ab085aSmws map->smbmam_size = (uint64_t) 65184ab085aSmws (m.smbamap_end - m.smbamap_start + 1) * 1024; 65284ab085aSmws 65384ab085aSmws return (0); 65484ab085aSmws } 65584ab085aSmws 65684ab085aSmws int 65784ab085aSmws smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp) 65884ab085aSmws { 65984ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 66084ab085aSmws smb_memdevice_t m; 66184ab085aSmws 66284ab085aSmws if (stp == NULL) 66384ab085aSmws return (-1); /* errno is set for us */ 66484ab085aSmws 66584ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE) 66684ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 66784ab085aSmws 66884ab085aSmws smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 66984ab085aSmws bzero(mdp, sizeof (smbios_memdevice_t)); 67084ab085aSmws 67184ab085aSmws mdp->smbmd_array = m.smbmdev_array; 67284ab085aSmws mdp->smbmd_error = m.smbmdev_error; 67384ab085aSmws mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth; 67484ab085aSmws mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth; 67584ab085aSmws 67684ab085aSmws if (mdp->smbmd_size != 0xFFFF) { 67784ab085aSmws mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES); 67884ab085aSmws if (m.smbmdev_size & SMB_MDS_KBYTES) 67984ab085aSmws mdp->smbmd_size *= 1024; 68084ab085aSmws else 68184ab085aSmws mdp->smbmd_size *= 1024 * 1024; 68284ab085aSmws } else 68384ab085aSmws mdp->smbmd_size = -1ULL; /* size unknown */ 68484ab085aSmws 68584ab085aSmws mdp->smbmd_form = m.smbmdev_form; 68684ab085aSmws mdp->smbmd_set = m.smbmdev_set; 68784ab085aSmws mdp->smbmd_type = m.smbmdev_type; 68884ab085aSmws mdp->smbmd_flags = m.smbmdev_flags; 68984ab085aSmws mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc); 69084ab085aSmws mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc); 69184ab085aSmws 69284ab085aSmws if (m.smbmdev_speed != 0) 69384ab085aSmws mdp->smbmd_speed = 1000 / m.smbmdev_speed; /* MHz -> nsec */ 69484ab085aSmws 69584ab085aSmws return (0); 69684ab085aSmws } 69784ab085aSmws 69884ab085aSmws int 69984ab085aSmws smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp) 70084ab085aSmws { 70184ab085aSmws const smb_struct_t *stp = smb_lookup_id(shp, id); 70284ab085aSmws smb_memdevmap_t m; 70384ab085aSmws 70484ab085aSmws if (stp == NULL) 70584ab085aSmws return (-1); /* errno is set for us */ 70684ab085aSmws 70784ab085aSmws if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP) 70884ab085aSmws return (smb_set_errno(shp, ESMB_TYPE)); 70984ab085aSmws 71084ab085aSmws smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m)); 71184ab085aSmws bzero(mdp, sizeof (smbios_memdevmap_t)); 71284ab085aSmws 71384ab085aSmws mdp->smbmdm_device = m.smbdmap_device; 71484ab085aSmws mdp->smbmdm_arrmap = m.smbdmap_array; 71584ab085aSmws mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024; 71684ab085aSmws mdp->smbmdm_size = (uint64_t) 71784ab085aSmws (m.smbdmap_end - m.smbdmap_start + 1) * 1024; 71884ab085aSmws mdp->smbmdm_rpos = m.smbdmap_rpos; 71984ab085aSmws mdp->smbmdm_ipos = m.smbdmap_ipos; 72084ab085aSmws mdp->smbmdm_idepth = m.smbdmap_idepth; 72184ab085aSmws 72284ab085aSmws return (0); 72384ab085aSmws } 72484ab085aSmws 72584ab085aSmws id_t 72684ab085aSmws smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp) 72784ab085aSmws { 72884ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY); 72984ab085aSmws smb_hwsec_t hs; 73084ab085aSmws 73184ab085aSmws if (stp == NULL) 73284ab085aSmws return (-1); /* errno is set for us */ 73384ab085aSmws 73484ab085aSmws smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs)); 73584ab085aSmws bzero(hsp, sizeof (smbios_hwsec_t)); 73684ab085aSmws 73784ab085aSmws hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings); 73884ab085aSmws hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings); 73984ab085aSmws hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings); 74084ab085aSmws hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings); 74184ab085aSmws 74284ab085aSmws return (stp->smbst_hdr->smbh_hdl); 74384ab085aSmws } 74484ab085aSmws 74584ab085aSmws id_t 74684ab085aSmws smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp) 74784ab085aSmws { 74884ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT); 74984ab085aSmws const smb_boot_t *b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr; 75084ab085aSmws 75184ab085aSmws if (stp == NULL) 75284ab085aSmws return (-1); /* errno is set for us */ 75384ab085aSmws 75484ab085aSmws bzero(bp, sizeof (smbios_boot_t)); 75584ab085aSmws 75684ab085aSmws bp->smbt_status = b->smbbo_status[0]; 75784ab085aSmws bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t); 75884ab085aSmws bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL; 75984ab085aSmws 76084ab085aSmws return (stp->smbst_hdr->smbh_hdl); 76184ab085aSmws } 76284ab085aSmws 76384ab085aSmws id_t 76484ab085aSmws smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip) 76584ab085aSmws { 76684ab085aSmws const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV); 76784ab085aSmws smb_ipmi_t i; 76884ab085aSmws 76984ab085aSmws if (stp == NULL) 77084ab085aSmws return (-1); /* errno is set for us */ 77184ab085aSmws 77284ab085aSmws smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i)); 77384ab085aSmws bzero(ip, sizeof (smbios_ipmi_t)); 77484ab085aSmws 77584ab085aSmws ip->smbip_type = i.smbipm_type; 77684ab085aSmws ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec); 77784ab085aSmws ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec); 77884ab085aSmws ip->smbip_i2c = i.smbipm_i2c; 77984ab085aSmws ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO; 78084ab085aSmws ip->smbip_intr = i.smbipm_intr; 78184ab085aSmws 78284ab085aSmws if (i.smbipm_bus != (uint8_t)-1) 78384ab085aSmws ip->smbip_bus = i.smbipm_bus; 78484ab085aSmws else 78584ab085aSmws ip->smbip_bus = -1u; 78684ab085aSmws 78784ab085aSmws if (SMB_IPM_INFO_LSB(i.smbipm_info)) 78884ab085aSmws ip->smbip_addr |= 1; /* turn on least-significant bit of addr */ 78984ab085aSmws 79084ab085aSmws if (i.smbipm_addr & SMB_IPM_ADDR_IO) { 79184ab085aSmws switch (SMB_IPM_INFO_REGS(i.smbipm_info)) { 79284ab085aSmws case SMB_IPM_REGS_1B: 79384ab085aSmws ip->smbip_regspacing = 1; 79484ab085aSmws break; 79584ab085aSmws case SMB_IPM_REGS_4B: 79684ab085aSmws ip->smbip_regspacing = 4; 79784ab085aSmws break; 79884ab085aSmws case SMB_IPM_REGS_16B: 79984ab085aSmws ip->smbip_regspacing = 16; 80084ab085aSmws break; 80184ab085aSmws default: 80284ab085aSmws ip->smbip_regspacing = 1; 80384ab085aSmws } 80484ab085aSmws ip->smbip_flags |= SMB_IPMI_F_IOADDR; 80584ab085aSmws } 80684ab085aSmws 80784ab085aSmws if (SMB_IPM_INFO_ISPEC(i.smbipm_info)) 80884ab085aSmws ip->smbip_flags |= SMB_IPMI_F_INTRSPEC; 80984ab085aSmws 81084ab085aSmws if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI) 81184ab085aSmws ip->smbip_flags |= SMB_IPMI_F_INTRHIGH; 81284ab085aSmws 81384ab085aSmws if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE) 81484ab085aSmws ip->smbip_flags |= SMB_IPMI_F_INTREDGE; 81584ab085aSmws 81684ab085aSmws return (stp->smbst_hdr->smbh_hdl); 81784ab085aSmws } 818*9c94f155SCheng Sean Ye 819*9c94f155SCheng Sean Ye static boolean_t 820*9c94f155SCheng Sean Ye smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr) 821*9c94f155SCheng Sean Ye { 822*9c94f155SCheng Sean Ye const smb_struct_t *stp = shp->sh_structs; 823*9c94f155SCheng Sean Ye smb_strtab_t s; 824*9c94f155SCheng Sean Ye int i, j; 825*9c94f155SCheng Sean Ye 826*9c94f155SCheng Sean Ye for (i = 0; i < shp->sh_nstructs; i++, stp++) { 827*9c94f155SCheng Sean Ye if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR) 828*9c94f155SCheng Sean Ye continue; 829*9c94f155SCheng Sean Ye 830*9c94f155SCheng Sean Ye smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); 831*9c94f155SCheng Sean Ye for (j = 0; j < s.smbtb_count; j++) 832*9c94f155SCheng Sean Ye if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0) 833*9c94f155SCheng Sean Ye return (B_TRUE); 834*9c94f155SCheng Sean Ye } 835*9c94f155SCheng Sean Ye 836*9c94f155SCheng Sean Ye return (B_FALSE); 837*9c94f155SCheng Sean Ye } 838*9c94f155SCheng Sean Ye 839*9c94f155SCheng Sean Ye static const char * 840*9c94f155SCheng Sean Ye smb_serial_valid(const char *serial) 841*9c94f155SCheng Sean Ye { 842*9c94f155SCheng Sean Ye char buf[MAXNAMELEN]; 843*9c94f155SCheng Sean Ye int i = 0; 844*9c94f155SCheng Sean Ye 845*9c94f155SCheng Sean Ye if (serial == NULL) 846*9c94f155SCheng Sean Ye return (NULL); 847*9c94f155SCheng Sean Ye 848*9c94f155SCheng Sean Ye (void) strlcpy(buf, serial, sizeof (buf)); 849*9c94f155SCheng Sean Ye 850*9c94f155SCheng Sean Ye while (buf[i] != '\0' && buf[i] == ' ') 851*9c94f155SCheng Sean Ye i++; 852*9c94f155SCheng Sean Ye 853*9c94f155SCheng Sean Ye if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL || 854*9c94f155SCheng Sean Ye strstr(buf, SMB_DEFAULT2) != NULL) 855*9c94f155SCheng Sean Ye return (NULL); 856*9c94f155SCheng Sean Ye 857*9c94f155SCheng Sean Ye return (serial); 858*9c94f155SCheng Sean Ye } 859*9c94f155SCheng Sean Ye 860*9c94f155SCheng Sean Ye /* 861*9c94f155SCheng Sean Ye * Get chassis SN or product SN 862*9c94f155SCheng Sean Ye */ 863*9c94f155SCheng Sean Ye static int 864*9c94f155SCheng Sean Ye smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp) 865*9c94f155SCheng Sean Ye { 866*9c94f155SCheng Sean Ye const smb_struct_t *stp; 867*9c94f155SCheng Sean Ye smbios_info_t s1, s3; 868*9c94f155SCheng Sean Ye 869*9c94f155SCheng Sean Ye if (psnp == NULL || csnp == NULL) 870*9c94f155SCheng Sean Ye return (smb_set_errno(shp, ESMB_INVAL)); 871*9c94f155SCheng Sean Ye 872*9c94f155SCheng Sean Ye *psnp = *csnp = NULL; 873*9c94f155SCheng Sean Ye 874*9c94f155SCheng Sean Ye /* 875*9c94f155SCheng Sean Ye * If SMBIOS meets Sun's PRMS requirements, retrieve product SN 876*9c94f155SCheng Sean Ye * from type 1 structure, and chassis SN from type 3 structure. 877*9c94f155SCheng Sean Ye * Otherwise return SN in type 1 structure as chassis SN. 878*9c94f155SCheng Sean Ye */ 879*9c94f155SCheng Sean Ye 880*9c94f155SCheng Sean Ye /* Get type 1 SN */ 881*9c94f155SCheng Sean Ye if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL || 882*9c94f155SCheng Sean Ye smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR) 883*9c94f155SCheng Sean Ye s1.smbi_serial = NULL; 884*9c94f155SCheng Sean Ye 885*9c94f155SCheng Sean Ye /* Get type 3 SN */ 886*9c94f155SCheng Sean Ye if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL || 887*9c94f155SCheng Sean Ye smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR) 888*9c94f155SCheng Sean Ye s3.smbi_serial = NULL; 889*9c94f155SCheng Sean Ye 890*9c94f155SCheng Sean Ye if (smbios_has_oemstr(shp, SMB_PRMS1)) { 891*9c94f155SCheng Sean Ye *psnp = smb_serial_valid(s1.smbi_serial); 892*9c94f155SCheng Sean Ye *csnp = smb_serial_valid(s3.smbi_serial); 893*9c94f155SCheng Sean Ye } else { 894*9c94f155SCheng Sean Ye *csnp = smb_serial_valid(s1.smbi_serial); 895*9c94f155SCheng Sean Ye } 896*9c94f155SCheng Sean Ye 897*9c94f155SCheng Sean Ye return (0); 898*9c94f155SCheng Sean Ye } 899*9c94f155SCheng Sean Ye 900*9c94f155SCheng Sean Ye const char * 901*9c94f155SCheng Sean Ye smbios_psn(smbios_hdl_t *shp) 902*9c94f155SCheng Sean Ye { 903*9c94f155SCheng Sean Ye const char *psn, *csn; 904*9c94f155SCheng Sean Ye 905*9c94f155SCheng Sean Ye return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn); 906*9c94f155SCheng Sean Ye } 907*9c94f155SCheng Sean Ye 908*9c94f155SCheng Sean Ye const char * 909*9c94f155SCheng Sean Ye smbios_csn(smbios_hdl_t *shp) 910*9c94f155SCheng Sean Ye { 911*9c94f155SCheng Sean Ye const char *psn, *csn; 912*9c94f155SCheng Sean Ye 913*9c94f155SCheng Sean Ye return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn); 914*9c94f155SCheng Sean Ye } 915