gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/uefivars/boot/efiDppMessage.go (about) 1 // Copyright 2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 // 5 // SPDX-License-Identifier: BSD-3-Clause 6 // 7 8 package boot 9 10 import ( 11 "encoding/binary" 12 "fmt" 13 ) 14 15 type EfiDppMsgSubType EfiDevPathProtoSubType 16 17 const ( 18 DppMsgTypeATAPI EfiDppMsgSubType = iota + 1 19 DppMsgTypeSCSI //2 20 DppMsgTypeFibreCh //3 21 DppMsgTypeFirewire //4 22 DppMsgTypeUSB //5 23 DppMsgTypeIIO //6 24 _ //7 25 _ //8 26 DppMsgTypeInfiniband //9 27 DppMsgTypeVendor //10 //uart flow control, sas are subtypes 28 DppMsgTypeMAC //11 29 DppMsgTypeIP4 //12 30 DppMsgTypeIP6 //13 31 DppMsgTypeUART //14 32 DppMsgTypeUSBClass //15 33 DppMsgTypeUSBWWID //16 34 DppMsgTypeDevLU //17 35 DppMsgTypeSATA //18 36 DppMsgTypeISCSI //19 37 DppMsgTypeVLAN //20 38 _ //21 39 DppMsgTypeSASEx //22 40 DppMsgTypeNVME //23 41 DppMsgTypeURI //24 42 DppMsgTypeUFS //25 43 DppMsgTypeSD //26 44 DppMsgTypeBT //27 45 DppMsgTypeWiFi //28 46 DppMsgTypeeMMC //29 47 DppMsgTypeBLE //30 48 DppMsgTypeDNS //31 49 DppMsgTypeNVDIMM //32 50 DppMsgTypeRest //documented as 32, likely 33 51 ) 52 53 var efiDppMsgSubTypeStrings = map[EfiDppMsgSubType]string{ 54 DppMsgTypeATAPI: "ATAPI", 55 DppMsgTypeSCSI: "SCSI", 56 DppMsgTypeFibreCh: "Fibre Channel", 57 DppMsgTypeFirewire: "1394", 58 DppMsgTypeUSB: "USB", 59 DppMsgTypeIIO: "I2O", 60 DppMsgTypeInfiniband: "Infiniband", 61 DppMsgTypeVendor: "Vendor", 62 DppMsgTypeMAC: "MAC", 63 DppMsgTypeIP4: "IPv4", 64 DppMsgTypeIP6: "IPv6", 65 DppMsgTypeUART: "UART", 66 DppMsgTypeUSBClass: "USB Class", 67 DppMsgTypeUSBWWID: "USB WWID", 68 DppMsgTypeDevLU: "Device Logical Unit", 69 DppMsgTypeSATA: "SATA", 70 DppMsgTypeISCSI: "iSCSI", 71 DppMsgTypeVLAN: "VLAN", 72 DppMsgTypeSASEx: "SAS Ex", 73 DppMsgTypeNVME: "NVME", 74 DppMsgTypeURI: "URI", 75 DppMsgTypeUFS: "UFS", 76 DppMsgTypeSD: "SD", 77 DppMsgTypeBT: "Bluetooth", 78 DppMsgTypeWiFi: "WiFi", 79 DppMsgTypeeMMC: "eMMC", 80 DppMsgTypeBLE: "BLE", 81 DppMsgTypeDNS: "DNS", 82 DppMsgTypeNVDIMM: "NVDIMM", 83 DppMsgTypeRest: "REST", 84 } 85 86 func (e EfiDppMsgSubType) String() string { 87 if s, ok := efiDppMsgSubTypeStrings[e]; ok { 88 return s 89 } 90 return fmt.Sprintf("UNKNOWN-0x%x", uint8(e)) 91 } 92 93 // DppMsgATAPI is a struct describing an atapi dpp message. 94 // pg 293 95 type DppMsgATAPI struct { 96 Hdr EfiDevicePathProtocolHdr 97 Primary, Master bool 98 LUN uint16 99 } 100 101 var _ EfiDevicePathProtocol = (*DppMsgATAPI)(nil) 102 103 // ParseDppMsgATAPI parses input into a DppMsgATAPI. 104 func ParseDppMsgATAPI(h EfiDevicePathProtocolHdr, b []byte) (*DppMsgATAPI, error) { 105 if h.Length != 8 { 106 return nil, ErrParse 107 } 108 msg := &DppMsgATAPI{ 109 Hdr: h, 110 Primary: b[0] == 0, 111 Master: b[1] == 0, 112 LUN: binary.LittleEndian.Uint16(b[2:4]), 113 } 114 return msg, nil 115 } 116 117 func (e *DppMsgATAPI) Header() EfiDevicePathProtocolHdr { return e.Hdr } 118 119 // ProtoSubTypeStr returns the subtype as human readable. 120 func (e *DppMsgATAPI) ProtoSubTypeStr() string { 121 return EfiDppMsgSubType(e.Hdr.ProtoSubType).String() 122 } 123 124 func (e *DppMsgATAPI) String() string { 125 return fmt.Sprintf("ATAPI(pri=%t,master=%t,lun=%d)", e.Primary, e.Master, e.LUN) 126 } 127 128 // Resolver returns a nil EfiPathSegmentResolver and ErrUnimpl. See the comment 129 // associated with ErrUnimpl. 130 func (e *DppMsgATAPI) Resolver() (EfiPathSegmentResolver, error) { 131 return nil, ErrUnimpl 132 } 133 134 // DppMsgMAC contains a MAC address. 135 // pg 300 136 type DppMsgMAC struct { 137 Hdr EfiDevicePathProtocolHdr 138 Mac [32]byte //0-padded 139 IfType uint8 //RFC3232; seems ethernet is 6 140 } 141 142 // ParseDppMsgMAC parses input into a DppMsgMAC. 143 func ParseDppMsgMAC(h EfiDevicePathProtocolHdr, b []byte) (*DppMsgMAC, error) { 144 if h.Length != 37 { 145 return nil, ErrParse 146 } 147 mac := &DppMsgMAC{ 148 Hdr: h, 149 //Mac: b[:32], 150 IfType: b[32], 151 } 152 copy(mac.Mac[:], b[:32]) 153 return mac, nil 154 } 155 156 func (e *DppMsgMAC) Header() EfiDevicePathProtocolHdr { return e.Hdr } 157 158 // ProtoSubTypeStr returns the subtype as human readable. 159 func (e *DppMsgMAC) ProtoSubTypeStr() string { 160 return EfiDppMsgSubType(e.Hdr.ProtoSubType).String() 161 } 162 163 func (e *DppMsgMAC) String() string { 164 switch e.IfType { 165 case 1: 166 return fmt.Sprintf("MAC(%x)", e.Mac[:6]) 167 default: 168 return fmt.Sprintf("MAC(mac=%08x,iftype=0x%x)", e.Mac, e.IfType) 169 } 170 } 171 172 // Resolver returns a nil EfiPathSegmentResolver and ErrUnimpl. See the comment 173 // associated with ErrUnimpl. 174 func (e *DppMsgMAC) Resolver() (EfiPathSegmentResolver, error) { 175 return nil, ErrUnimpl 176 }