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 2021 Oxide Computer Company 14 */ 15 16 /* 17 * Tests for SMBIOS type 46 - SMB_TYPE_STRPROP. 18 */ 19 20 #include "smbios_test.h" 21 22 static const char *smbios_strprop_path = "/not/really/uefi"; 23 static uint16_t smbios_strprop_hdl = 0xcafe; 24 25 boolean_t 26 smbios_test_strprop_mktable_basic(smbios_test_table_t *table) 27 { 28 smb_strprop_t str; 29 30 str.smbstrp_hdr.smbh_type = SMB_TYPE_STRPROP; 31 str.smbstrp_hdr.smbh_len = sizeof (str); 32 str.smbstrp_prop_id = htole16(SMB_STRP_UEFI_DEVPATH); 33 str.smbstrp_prop_val = 1; 34 str.smbstrp_phdl = htole16(smbios_strprop_hdl); 35 36 (void) smbios_test_table_append(table, &str, sizeof (str)); 37 smbios_test_table_append_string(table, smbios_strprop_path); 38 smbios_test_table_str_fini(table); 39 smbios_test_table_append_eot(table); 40 41 return (B_TRUE); 42 } 43 44 boolean_t 45 smbios_test_strprop_mktable_badstr(smbios_test_table_t *table) 46 { 47 smb_strprop_t str; 48 49 str.smbstrp_hdr.smbh_type = SMB_TYPE_STRPROP; 50 str.smbstrp_hdr.smbh_len = sizeof (str); 51 str.smbstrp_prop_id = htole16(SMB_STRP_UEFI_DEVPATH); 52 str.smbstrp_prop_val = 0x23; 53 str.smbstrp_phdl = htole16(smbios_strprop_hdl); 54 55 (void) smbios_test_table_append(table, &str, sizeof (str)); 56 smbios_test_table_append_string(table, smbios_strprop_path); 57 smbios_test_table_str_fini(table); 58 smbios_test_table_append_eot(table); 59 60 return (B_TRUE); 61 } 62 63 boolean_t 64 smbios_test_strprop_mktable_invlen1(smbios_test_table_t *table) 65 { 66 smb_header_t hdr; 67 68 hdr.smbh_type = SMB_TYPE_STRPROP; 69 hdr.smbh_len = sizeof (hdr); 70 71 (void) smbios_test_table_append(table, &hdr, sizeof (hdr)); 72 smbios_test_table_append_eot(table); 73 74 return (B_TRUE); 75 } 76 77 boolean_t 78 smbios_test_strprop_mktable_invlen2(smbios_test_table_t *table) 79 { 80 smb_strprop_t str; 81 const uint8_t endstring = 0; 82 83 str.smbstrp_hdr.smbh_type = SMB_TYPE_STRPROP; 84 str.smbstrp_hdr.smbh_len = sizeof (str) + 1; 85 str.smbstrp_prop_id = htole16(0); 86 str.smbstrp_prop_val = 0; 87 str.smbstrp_phdl = htole16(0); 88 89 /* 90 * Append the end string again as to get us to our additional byte of 91 * actual table length. 92 */ 93 (void) smbios_test_table_append(table, &str, sizeof (str)); 94 (void) smbios_test_table_append_raw(table, &endstring, 95 sizeof (endstring)); 96 (void) smbios_test_table_append_string(table, smbios_strprop_path); 97 (void) smbios_test_table_append_raw(table, &endstring, 98 sizeof (endstring)); 99 smbios_test_table_append_eot(table); 100 101 return (B_TRUE); 102 } 103 104 static boolean_t 105 smbios_test_strprop_verify_badtable(smbios_hdl_t *hdl, int smberr) 106 { 107 smbios_struct_t sp; 108 smbios_strprop_t prop; 109 110 if (smbios_lookup_type(hdl, SMB_TYPE_STRPROP, &sp) == -1) { 111 warnx("failed to lookup SMBIOS strprop: %s", 112 smbios_errmsg(smbios_errno(hdl))); 113 return (B_FALSE); 114 } 115 116 if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != -1) { 117 warnx("accidentally parsed invalid strprop information as " 118 "valid"); 119 return (B_FALSE); 120 } 121 122 if (smbios_errno(hdl) != smberr) { 123 warnx("encountered wrong error for strprop, expected: " 124 "0x%x, found: 0x%x", smberr, smbios_errno(hdl)); 125 return (B_FALSE); 126 } 127 128 return (B_TRUE); 129 } 130 131 boolean_t 132 smbios_test_strprop_verify_invlen1(smbios_hdl_t *hdl) 133 { 134 return (smbios_test_strprop_verify_badtable(hdl, ESMB_SHORT)); 135 } 136 137 boolean_t 138 smbios_test_strprop_verify_invlen2(smbios_hdl_t *hdl) 139 { 140 return (smbios_test_strprop_verify_badtable(hdl, ESMB_CORRUPT)); 141 } 142 143 boolean_t 144 smbios_test_strprop_verify_badtype(smbios_hdl_t *hdl) 145 { 146 smbios_struct_t sp; 147 smbios_strprop_t prop; 148 149 /* 150 * Here we've explicitly created a table with a memory device that we're 151 * going to try and look up as well, not that. 152 */ 153 if (smbios_lookup_type(hdl, SMB_TYPE_MEMDEVICE, &sp) == -1) { 154 warnx("failed to lookup SMBIOS memory device: %s", 155 smbios_errmsg(smbios_errno(hdl))); 156 return (B_FALSE); 157 } 158 159 if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != -1) { 160 warnx("accidentally parsed invalid strprop information as " 161 "valid"); 162 return (B_FALSE); 163 } 164 165 if (smbios_errno(hdl) != ESMB_TYPE) { 166 warnx("encountered wrong error for strprop, expected: " 167 "0x%x, found: 0x%x", ESMB_TYPE, smbios_errno(hdl)); 168 return (B_FALSE); 169 } 170 171 return (B_TRUE); 172 173 } 174 175 boolean_t 176 smbios_test_strprop_verify_basic(smbios_hdl_t *hdl) 177 { 178 smbios_struct_t sp; 179 smbios_strprop_t prop; 180 boolean_t ret = B_TRUE; 181 182 if (smbios_lookup_type(hdl, SMB_TYPE_STRPROP, &sp) == -1) { 183 warnx("failed to lookup SMBIOS strprop: %s", 184 smbios_errmsg(smbios_errno(hdl))); 185 return (B_FALSE); 186 } 187 188 if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != 0) { 189 warnx("failed to get SMBIOS strprop: %s", 190 smbios_errmsg(smbios_errno(hdl))); 191 return (B_FALSE); 192 } 193 194 if (prop.smbsp_prop_id != SMB_STRP_UEFI_DEVPATH) { 195 warnx("property id incorrect, expected 0x%x, found 0x %x", 196 SMB_STRP_UEFI_DEVPATH, prop.smbsp_prop_id); 197 ret = B_FALSE; 198 } 199 200 if (strcmp(smbios_strprop_id_desc(prop.smbsp_prop_id), 201 "UEFI device path") != 0) { 202 warnx("property id string incorrect, found %s", 203 smbios_strprop_id_desc(prop.smbsp_prop_id)); 204 ret = B_FALSE; 205 } 206 207 if (strcmp(prop.smbsp_prop_val, smbios_strprop_path) != 0) { 208 warnx("property value incorrect, found %s", 209 prop.smbsp_prop_val); 210 ret = B_FALSE; 211 } 212 213 return (ret); 214 } 215 216 boolean_t 217 smbios_test_strprop_verify_badstr(smbios_hdl_t *hdl) 218 { 219 smbios_struct_t sp; 220 smbios_strprop_t prop; 221 boolean_t ret = B_TRUE; 222 223 if (smbios_lookup_type(hdl, SMB_TYPE_STRPROP, &sp) == -1) { 224 warnx("failed to lookup SMBIOS strprop: %s", 225 smbios_errmsg(smbios_errno(hdl))); 226 return (B_FALSE); 227 } 228 229 if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != 0) { 230 warnx("failed to get SMBIOS strprop: %s", 231 smbios_errmsg(smbios_errno(hdl))); 232 return (B_FALSE); 233 } 234 235 if (prop.smbsp_prop_id != SMB_STRP_UEFI_DEVPATH) { 236 warnx("property id incorrect, expected 0x%x, found 0x %x", 237 SMB_STRP_UEFI_DEVPATH, prop.smbsp_prop_id); 238 ret = B_FALSE; 239 } 240 241 if (strcmp(smbios_strprop_id_desc(prop.smbsp_prop_id), 242 "UEFI device path") != 0) { 243 warnx("property id string incorrect, found %s", 244 smbios_strprop_id_desc(prop.smbsp_prop_id)); 245 ret = B_FALSE; 246 } 247 248 if (strcmp(prop.smbsp_prop_val, "") != 0) { 249 warnx("property value incorrect, found %s", 250 prop.smbsp_prop_val); 251 ret = B_FALSE; 252 } 253 254 return (ret); 255 } 256