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