1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2025 Oxide Computer Company 14 */ 15 16 /* 17 * Basic tests for the SMBIOS Management Device and Component. Types 34 and 35. 18 */ 19 20 #include "smbios_test.h" 21 22 static const char *smbios_dev_desc = "Black Mage"; 23 static const char *smbios_comp_desc = "White Mage"; 24 25 boolean_t 26 smbios_test_mgmtdev_mktable(smbios_test_table_t *table) 27 { 28 smb_mgmtdev_t md; 29 30 bzero(&md, sizeof (md)); 31 md.smbmgd_hdr.smbh_type = SMB_TYPE_MGMTDEV; 32 md.smbmgd_hdr.smbh_len = sizeof (md); 33 md.smbmgd_desc = 1; 34 md.smbmgd_dtype = SMB_MGMTDEV_DT_LM79; 35 md.smbmgd_addr = 0x42; 36 md.smbmgd_atype = SMB_MGMTDEV_AT_SMBUS; 37 38 (void) smbios_test_table_append(table, &md, sizeof (md)); 39 smbios_test_table_append_string(table, smbios_dev_desc); 40 smbios_test_table_str_fini(table); 41 smbios_test_table_append_eot(table); 42 43 return (B_TRUE); 44 } 45 46 boolean_t 47 smbios_test_mgmtdev_verify(smbios_hdl_t *hdl) 48 { 49 smbios_struct_t sp; 50 smbios_mgmtdev_t md; 51 boolean_t ret = B_TRUE; 52 53 if (smbios_lookup_type(hdl, SMB_TYPE_MGMTDEV, &sp) == -1) { 54 warnx("failed to lookup SMBIOS management device: %s", 55 smbios_errmsg(smbios_errno(hdl))); 56 return (B_FALSE); 57 } 58 59 if (smbios_info_mgmtdev(hdl, sp.smbstr_id, &md) == -1) { 60 warnx("failed to get management device: %s", 61 smbios_errmsg(smbios_errno(hdl))); 62 return (B_FALSE); 63 } 64 65 if (strcmp(md.smbmd_desc, smbios_dev_desc) != 0) { 66 warnx("management device description mismatch: found %s, " 67 "expected %s", md.smbmd_desc, smbios_dev_desc); 68 ret = B_FALSE; 69 } 70 71 if (md.smbmd_dtype != SMB_MGMTDEV_DT_LM79) { 72 warnx("management device device type mismatch: found 0x%x, " 73 "expected 0x%x", md.smbmd_dtype, SMB_MGMTDEV_DT_LM79); 74 ret = B_FALSE; 75 } 76 77 if (md.smbmd_addr != 0x42) { 78 warnx("management device address mismatch: found 0x%x, " 79 "expected 0x42", md.smbmd_addr); 80 ret = B_FALSE; 81 } 82 83 if (md.smbmd_atype != SMB_MGMTDEV_AT_SMBUS) { 84 warnx("management device address type mismatch: found 0x%x, " 85 "expected 0x%x", md.smbmd_atype, SMB_MGMTDEV_AT_SMBUS); 86 ret = B_FALSE; 87 } 88 89 return (ret); 90 } 91 92 boolean_t 93 smbios_test_mgmtcomp_mktable(smbios_test_table_t *table) 94 { 95 smb_mgmtcomp_t mc; 96 97 bzero(&mc, sizeof (mc)); 98 mc.smbmgc_hdr.smbh_type = SMB_TYPE_MGMTDEVCP; 99 mc.smbmgc_hdr.smbh_len = sizeof (mc); 100 mc.smbmgc_desc = 1; 101 mc.smbmgc_mgmtdev = 0x1234; 102 mc.smbmgc_comp = 0x5678; 103 mc.smbmgc_thresh = 0x789a; 104 105 (void) smbios_test_table_append(table, &mc, sizeof (mc)); 106 smbios_test_table_append_string(table, smbios_comp_desc); 107 smbios_test_table_str_fini(table); 108 smbios_test_table_append_eot(table); 109 110 return (B_TRUE); 111 } 112 113 boolean_t 114 smbios_test_mgmtcomp_verify(smbios_hdl_t *hdl) 115 { 116 smbios_struct_t sp; 117 smbios_mgmtcomp_t mc; 118 boolean_t ret = B_TRUE; 119 120 if (smbios_lookup_type(hdl, SMB_TYPE_MGMTDEVCP, &sp) == -1) { 121 warnx("failed to lookup SMBIOS management component: %s", 122 smbios_errmsg(smbios_errno(hdl))); 123 return (B_FALSE); 124 } 125 126 if (smbios_info_mgmtcomp(hdl, sp.smbstr_id, &mc) == -1) { 127 warnx("failed to get management component: %s", 128 smbios_errmsg(smbios_errno(hdl))); 129 return (B_FALSE); 130 } 131 132 if (strcmp(mc.smbmc_desc, smbios_comp_desc) != 0) { 133 warnx("management component description mismatch: found %s, " 134 "expected %s", mc.smbmc_desc, smbios_comp_desc); 135 ret = B_FALSE; 136 } 137 138 if (mc.smbmc_mgmtdev != 0x1234) { 139 warnx("management component mgmt dev handle mismatch: found " 140 "0x%" _PRIxID ", expected 0x1234", mc.smbmc_mgmtdev); 141 ret = B_FALSE; 142 } 143 144 if (mc.smbmc_comp != 0x5678) { 145 warnx("management component component handle mismatch: found " 146 "0x%" _PRIxID ", expected 0x5678", mc.smbmc_comp); 147 ret = B_FALSE; 148 } 149 150 if (mc.smbmc_thresh != 0x789a) { 151 warnx("management component threshold handle mismatch: found " 152 "0x%" _PRIxID ", expected 0x789a", mc.smbmc_thresh); 153 ret = B_FALSE; 154 } 155 156 return (ret); 157 } 158