_format_hw_dn(char *buf, size_t size, const_efidp dp) { efi_guid_t edd10_guid = EDD10_HARDWARE_VENDOR_PATH_GUID; off_t off = 0; switch (dp->subtype) { case EFIDP_HW_PCI: off += format(buf, size, off, "Pci(0x%"PRIx32",0x%"PRIx32")", dp->pci.device, dp->pci.function); break; case EFIDP_HW_PCCARD: off += format(buf, size, off, "PcCard(0x%"PRIx32")", dp->pccard.function); break; case EFIDP_HW_MMIO: off += format(buf, size, off, "MemoryMapped(%"PRIu32",0x%"PRIx64",0x%"PRIx64")", dp->mmio.memory_type, dp->mmio.starting_address, dp->mmio.ending_address); break; case EFIDP_HW_VENDOR: if (!efi_guid_cmp(&dp->hw_vendor.vendor_guid, &edd10_guid)) { off += format_helper(format_edd10_guid, buf, size, off, dp); } else { off += format_vendor(buf, size, off, "VenHw", dp); } break; case EFIDP_HW_CONTROLLER: off += format(buf, size, off, "Ctrl(0x%"PRIx32")", dp->controller.controller); break; case EFIDP_HW_BMC: off += format(buf, size, off, "BMC(%d,0x%"PRIx64")", dp->bmc.interface_type, dp->bmc.base_addr); break; default: off += format(buf, size, off, "HardwarePath(%d,", dp->subtype); off += format_hex(buf, size, off, (uint8_t *)dp+4, efidp_node_size(dp)-4); off += format(buf,size,off,")"); break; } return off; }
_format_message_dn(char *buf, size_t size, const_efidp dp) { ssize_t off = 0; ssize_t sz; switch (dp->subtype) { case EFIDP_MSG_ATAPI: off += format(buf, size, off, "Ata(%d,%d,%d)", dp->atapi.primary, dp->atapi.slave, dp->atapi.lun); break; case EFIDP_MSG_SCSI: off += format(buf, size, off, "SCSI(%d,%d)", dp->scsi.target, dp->scsi.lun); break; case EFIDP_MSG_FIBRECHANNEL: off += format(buf, size, off, "Fibre(%"PRIx64",%"PRIx64")", le64_to_cpu(dp->fc.wwn), le64_to_cpu(dp->fc.lun)); break; case EFIDP_MSG_FIBRECHANNELEX: off += format(buf, size, off, "Fibre(%"PRIx64",%"PRIx64")", be64_to_cpu(dp->fc.wwn), be64_to_cpu(dp->fc.lun)); break; case EFIDP_MSG_1394: off += format(buf, size, off, "I1394(0x%"PRIx64")", dp->firewire.guid); break; case EFIDP_MSG_USB: off += format(buf, size, off, "USB(%d,%d)", dp->usb.parent_port, dp->usb.interface); break; case EFIDP_MSG_I2O: off += format(buf, size, off, "I2O(%d)", dp->i2o.target); break; case EFIDP_MSG_INFINIBAND: if (dp->infiniband.resource_flags & EFIDP_INFINIBAND_RESOURCE_IOC_SERVICE) { off += format(buf, size, off, "Infiniband(%08x,%"PRIx64"%"PRIx64",%"PRIx64",%"PRIu64",%"PRIu64")", dp->infiniband.resource_flags, dp->infiniband.port_gid[1], dp->infiniband.port_gid[0], dp->infiniband.service_id, dp->infiniband.target_port_id, dp->infiniband.device_id); } else { off += format(buf, size, off, "Infiniband(%08x,%"PRIx64"%"PRIx64",", dp->infiniband.resource_flags, dp->infiniband.port_gid[1], dp->infiniband.port_gid[0]); off += format_guid(buf, size, off, (efi_guid_t *) &dp->infiniband.ioc_guid); off += format(buf, size, off, ",%"PRIu64",%"PRIu64")", dp->infiniband.target_port_id, dp->infiniband.device_id); } break; case EFIDP_MSG_MAC_ADDR: off += format(buf, size, off, "MAC("); off += format_hex(buf, size, off, dp->mac_addr.mac_addr, dp->mac_addr.if_type < 2 ? 6 : sizeof(dp->mac_addr.mac_addr)); off += format(buf, size, off, ",%d)", dp->mac_addr.if_type); break; case EFIDP_MSG_IPv4: { efidp_ipv4_addr const *a = &dp->ipv4_addr; off += format(buf, size, off, "IPv4(%hhu.%hhu.%hhu.%hhu:%hu<->%hhu.%hhu.%hhu.%hhu:%hu,%hx,%hhx)", a->local_ipv4_addr[0], a->local_ipv4_addr[1], a->local_ipv4_addr[2], a->local_ipv4_addr[3], a->local_port, a->remote_ipv4_addr[0], a->remote_ipv4_addr[1], a->remote_ipv4_addr[2], a->remote_ipv4_addr[3], a->remote_port, a->protocol, a->static_ip_addr); break; } case EFIDP_MSG_VENDOR: { struct { efi_guid_t guid; char label[40]; ssize_t (*formatter)(char *buf, size_t size, const_efidp dp); } subtypes[] = { { EFIDP_PC_ANSI_GUID, "VenPcAnsi" }, { EFIDP_VT_100_GUID, "VenVt100" }, { EFIDP_VT_100_PLUS_GUID, "VenVt100Plus" }, { EFIDP_VT_UTF8_GUID, "VenUtf8" }, { EFIDP_MSG_DEBUGPORT_GUID, "DebugPort" }, { EFIDP_MSG_UART_GUID, "", format_uart }, { EFIDP_MSG_SAS_GUID, "", format_sas }, { efi_guid_empty, "" } }; char *label = NULL; ssize_t (*formatter)(char *buf, size_t size, const_efidp dp) = NULL; for (int i = 0; !efi_guid_is_zero(&subtypes[i].guid); i++) { if (efi_guid_cmp(&subtypes[i].guid, &dp->msg_vendor.vendor_guid)) continue; label = subtypes[i].label; formatter = subtypes[i].formatter; break; } if (!label && !formatter) { off += format_vendor(buf, size, off, "VenMsg", dp); break; } else if (formatter) { off += format_helper(formatter, buf, size, off, dp); break; } off += format(buf, size, off, "%s(", label); if (efidp_node_size(dp) > (ssize_t)(sizeof (efidp_header) + sizeof (efi_guid_t))) { off += format_hex(buf, size, off, dp->msg_vendor.vendor_data, efidp_node_size(dp) - sizeof (efidp_header) - sizeof (efi_guid_t)); } break; } case EFIDP_MSG_IPv6: { efidp_ipv6_addr const *a = &dp->ipv6_addr; char *addr0 = NULL; char *addr1 = NULL; sz = format_ipv6_port(addr0, 0, 0, a->local_ipv6_addr, a->local_port); if (sz < 0) return sz; addr0 = alloca(sz+1); sz = format_ipv6_port(addr0, sz, 0, a->local_ipv6_addr, a->local_port); if (sz < 0) return sz; sz = format_ipv6_port(addr1, 0, 0, a->remote_ipv6_addr, a->remote_port); if (sz < 0) return sz; addr1 = alloca(sz+1); sz = format_ipv6_port(addr1, sz, 0, a->remote_ipv6_addr, a->remote_port); if (sz < 0) return sz; off += format(buf, size, off, "IPv6(%s<->%s,%hx,%hhx)", addr0, addr1, a->protocol, a->ip_addr_origin); break; } case EFIDP_MSG_UART: { int parity = dp->uart.parity; char parity_label[] = "DNEOMS"; int stop_bits = dp->uart.stop_bits; char *sb_label[] = {"D", "1", "1.5", "2"}; off += format(buf, size, off, "Uart(%"PRIu64",%d,", dp->uart.baud_rate ? dp->uart.baud_rate : 115200, dp->uart.data_bits ? dp->uart.data_bits : 8); off += format(buf, size, off, parity > 5 ? "%d," : "%c,", parity > 5 ? parity : parity_label[parity]); if (stop_bits > 3) off += format(buf, size, off, "%d)", stop_bits); else off += format(buf, size, off, "%s)", sb_label[stop_bits]); break; } case EFIDP_MSG_USB_CLASS: off += format_helper(format_usb_class, buf, size, off, dp); break; case EFIDP_MSG_USB_WWID: off += format(buf, size, off, "UsbWwid(%"PRIx16",%"PRIx16",%d,", dp->usb_wwid.vendor_id, dp->usb_wwid.product_id, dp->usb_wwid.interface); off += format_ucs2(buf, size, off, dp->usb_wwid.serial_number, (efidp_node_size(dp) - offsetof(efidp_usb_wwid, serial_number)) / 2 + 1); off += format(buf, size, off, ")"); break; case EFIDP_MSG_LUN: off += format(buf, size, off, "Unit(%d)", dp->lun.lun); break; case EFIDP_MSG_SATA: off += format(buf, size, off, "Sata(%d,%d,%d)", dp->sata.hba_port, dp->sata.port_multiplier_port, dp->sata.lun); break; case EFIDP_MSG_ISCSI: { size_t sz = efidp_node_size(dp) - offsetof(efidp_iscsi, target_name); if (sz > EFIDP_ISCSI_MAX_TARGET_NAME_LEN) sz = EFIDP_ISCSI_MAX_TARGET_NAME_LEN; char target_name[sz + 1]; memcpy(target_name, dp->iscsi.target_name, sz); target_name[sz] = '\0'; uint64_t lun; memcpy(&lun, dp->iscsi.lun, sizeof (lun)); off += format(buf, size, off, "iSCSI(%s,%d,0x%"PRIx64",%s,%s,%s,%s)", target_name, dp->iscsi.tpgt, be64_to_cpu(lun), (dp->iscsi.options >> EFIDP_ISCSI_HEADER_DIGEST_SHIFT) & EFIDP_ISCSI_HEADER_CRC32 ? "CRC32" : "None", (dp->iscsi.options >> EFIDP_ISCSI_DATA_DIGEST_SHIFT) & EFIDP_ISCSI_DATA_CRC32 ? "CRC32" : "None", (dp->iscsi.options >> EFIDP_ISCSI_AUTH_SHIFT) & EFIDP_ISCSI_AUTH_NONE ? "None" : \ (dp->iscsi.options >> EFIDP_ISCSI_CHAP_SHIFT) & EFIDP_ISCSI_CHAP_UNI ? "CHAP_UNI" : "CHAP_BI", dp->iscsi.protocol == 0 ? "TCP" : "Unknown"); break; } case EFIDP_MSG_VLAN: off += format(buf, size, off, "Vlan(%d)", dp->vlan.vlan_id); break; case EFIDP_MSG_SAS_EX: off += format_sas(buf, size, dp); break; case EFIDP_MSG_NVME: off += format(buf, size, off, "NVMe(0x%"PRIx32"," "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X)", dp->nvme.namespace_id, dp->nvme.ieee_eui_64[0], dp->nvme.ieee_eui_64[1], dp->nvme.ieee_eui_64[2], dp->nvme.ieee_eui_64[3], dp->nvme.ieee_eui_64[4], dp->nvme.ieee_eui_64[5], dp->nvme.ieee_eui_64[6], dp->nvme.ieee_eui_64[7]); break; case EFIDP_MSG_URI: { size_t sz = efidp_node_size(dp) - offsetof(efidp_uri, uri); char uri[sz + 1]; memcpy(uri, dp->uri.uri, sz); uri[sz] = '\0'; off += format(buf, size, off, "Uri(%s)", uri); break; } case EFIDP_MSG_UFS: off += format(buf, size, off, "UFS(%d,0x%02x)", dp->ufs.target_id, dp->ufs.lun); break; case EFIDP_MSG_SD: off += format(buf, size, off, "SD(%d)", dp->sd.slot_number); break; default: off += format(buf, size, off, "Msg(%d,", dp->subtype); off += format_hex(buf, size, off, (uint8_t *)dp+4, efidp_node_size(dp)-4); off += format(buf,size,off,")"); break; } return off; }
ssize_t _format_media_dn(char *buf, size_t size, const_efidp dp) { ssize_t off = 0; switch (dp->subtype) { case EFIDP_MEDIA_HD: off += format(buf, size, off, "HD(%d,", dp->hd.partition_number); switch (dp->hd.signature_type) { case EFIDP_HD_SIGNATURE_MBR: off += format(buf, size, off, "MBR,0x%"PRIu32",0x%"PRIx64",0x%"PRIx64")", *(char *)dp->hd.signature, dp->hd.start, dp->hd.size); break; case EFIDP_HD_SIGNATURE_GUID: off += format(buf, size, off, "GPT,"); off += format_guid(buf, size, off, (efi_guid_t *)dp->hd.signature); off += format(buf, size, off, ",0x%"PRIx64",0x%"PRIx64")", dp->hd.start, dp->hd.size); break; default: off += format(buf, size, off, "%d,", dp->hd.signature_type); off += format_hex(buf, size, off, dp->hd.signature, sizeof(dp->hd.signature)); off += format(buf, size, off, ",0x%"PRIx64",0x%"PRIx64")", dp->hd.start, dp->hd.size); break; } break; case EFIDP_MEDIA_CDROM: off += format(buf, size, off, "CDROM(%d,0x%"PRIx64",0x%"PRIx64")", dp->cdrom.boot_catalog_entry, dp->cdrom.partition_rba, dp->cdrom.sectors); break; case EFIDP_MEDIA_VENDOR: off += format_vendor(buf, size, off, "VenMedia", dp); break; case EFIDP_MEDIA_FILE: off += format(buf, size, off, "File("); off += format_ucs2(buf, size, off, dp->file.name, (efidp_node_size(dp) - offsetof(efidp_file, name)) / 2); off += format(buf, size, off, ")"); break; case EFIDP_MEDIA_PROTOCOL: off += format(buf, size, off, "Media("); off += format_guid(buf, size, off, &dp->protocol.protocol_guid); off += format(buf, size, off, ")"); break; case EFIDP_MEDIA_FIRMWARE_FILE: off += format(buf, size, off, "FvFile("); off += format_guid(buf, size, off, &dp->protocol.protocol_guid); off += format(buf, size, off, ")"); break; case EFIDP_MEDIA_FIRMWARE_VOLUME: off += format(buf, size, off, "FvVol("); off += format_guid(buf, size, off, &dp->protocol.protocol_guid); off += format(buf, size, off, ")"); break; case EFIDP_MEDIA_RELATIVE_OFFSET: off = format(buf, size, off, "Offset(0x%"PRIx64",0x%"PRIx64")", dp->relative_offset.first_byte, dp->relative_offset.last_byte); break; case EFIDP_MEDIA_RAMDISK: { struct { efi_guid_t guid; char label[40]; } subtypes[] = { { EFIDP_VIRTUAL_DISK_GUID, "VirtualDisk" }, { EFIDP_VIRTUAL_CD_GUID, "VirtualCD" }, { EFIDP_PERSISTENT_VIRTUAL_DISK_GUID, "PersistentVirtualDisk" }, { EFIDP_PERSISTENT_VIRTUAL_CD_GUID, "PersistentVirtualCD" }, { efi_guid_empty, "" } }; char *label = NULL; for (int i = 0; !efi_guid_is_zero(&subtypes[i].guid); i++) { if (efi_guid_cmp(&subtypes[i].guid, &dp->ramdisk.disk_type_guid)) continue; label = subtypes[i].label; break; } if (label) { off += format(buf, size, off, "%s(0x%"PRIx64",0x%"PRIx64",%d)", label, dp->ramdisk.start_addr, dp->ramdisk.end_addr, dp->ramdisk.instance_number); break; } off += format(buf, size, off, "Ramdisk(0x%"PRIx64",0x%"PRIx64",%d,", dp->ramdisk.start_addr, dp->ramdisk.end_addr, dp->ramdisk.instance_number); off += format_guid(buf, size, off, &dp->ramdisk.disk_type_guid); off += format(buf, size, off, ")"); break; } default: off += format(buf, size, off, "MediaPath(%d,", dp->subtype); off += format_hex(buf, size, off, (uint8_t *)dp+4, (efidp_node_size(dp)-4) / 2); off += format(buf,size,off,")"); break; } return off; }