]>
Commit | Line | Data |
---|---|---|
46cc2926 | 1 | #!/bin/bash |
46cc2926 HH |
2 | # |
3 | # Copyright 2013 Red Hat, Inc. All rights reserved. | |
4 | # Copyright 2013 Harald Hoyer <harald@redhat.com> | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | # | |
19 | ||
20 | getbyte () { | |
350ec5d9 | 21 | local IFS= LC_CTYPE=C res c=0 |
46cc2926 HH |
22 | read -r -n 1 -d '' c |
23 | res=$? | |
24 | # the single quote in the argument of the printf | |
25 | # yields the numeric value of $c (ASCII since LC_CTYPE=C) | |
26 | [[ -n $c ]] && c=$(printf '%u' "'$c") || c=0 | |
27 | printf "$c" | |
28 | return $res | |
29 | } | |
30 | ||
31 | getword () { | |
350ec5d9 HH |
32 | local b1=0 b2=0 val=0 |
33 | b1=$(getbyte) | |
34 | b2=$(getbyte) | |
46cc2926 HH |
35 | (( val = b2 * 256 + b1 )) |
36 | echo $val | |
37 | return 0 | |
38 | } | |
39 | ||
40 | # Acpi(PNP0A08,0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)/MAC(90E2BA265ED4,0x0)/Vlan(172)/Fibre(0x4EA06104A0CC0050,0x0) | |
41 | uefi_device_path() | |
42 | { | |
350ec5d9 HH |
43 | data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data} |
44 | [ -f "$data" ] || return 1 | |
45 | ||
46cc2926 HH |
46 | local IFS= LC_CTYPE=C res tt len type hextype first |
47 | first=1 | |
350ec5d9 HH |
48 | { |
49 | getword >/dev/null | |
50 | getword >/dev/null | |
51 | while :; do | |
52 | type=$(getbyte) || return 1 | |
53 | subtype=$(getbyte) || return 1 | |
54 | len=$(getword) || return 1 | |
55 | hextype=$(printf "%02x%02x" "$type" "$subtype") | |
56 | if [[ $first == 1 ]]; then | |
57 | first=0 | |
58 | elif [[ $hextype != "7fff" ]]; then | |
59 | printf "/" | |
60 | fi | |
61 | case $hextype in | |
62 | 0101) | |
63 | # PCI | |
64 | tt=$(getword) | |
65 | printf "PCI(0x%x,0x%x)" $(($tt / 256)) $(($tt & 255)) | |
66 | ;; | |
67 | 0201) | |
68 | # ACPI | |
69 | printf "Acpi(0x%x,0x%x)" $(($(getword) + $(getword) * 65536)) $(($(getword) + $(getword) * 65536)) | |
70 | ;; | |
71 | 0303) | |
72 | # FIBRE | |
73 | getword &>/dev/null | |
74 | getword &>/dev/null | |
75 | printf "Fibre(0x%x%x%x%x%x%x%x%x,0x%x)" \ | |
76 | $(getbyte) $(getbyte) $(getbyte) $(getbyte) \ | |
77 | $(getbyte) $(getbyte) $(getbyte) $(getbyte) \ | |
78 | $(( $(getword) + $(getword) * 65536 + 4294967296 * ( $(getword) + $(getword) * 65536 ) )) | |
79 | ;; | |
80 | 030b) | |
81 | # MAC | |
82 | printf "MAC(%02x%02x%02x%02x%02x%02x," $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) | |
83 | for((i=0; i<26; i++)); do tt=$(getbyte) || return 1; done | |
84 | #read -r -d '' -n 26 tt || return 1 | |
85 | printf "0x%x)" $(getbyte) | |
86 | ;; | |
87 | 0314) | |
88 | # VLAN | |
89 | printf "VLAN(%d)" $(getword) | |
90 | ;; | |
91 | 7fff) | |
92 | # END | |
93 | printf "\n" | |
94 | return 0 | |
95 | ;; | |
96 | *) | |
97 | #printf "Unknown(Type:0x%02x SubType:0x%02x len=%d)\n" "$type" "$subtype" "$len" >&2 | |
98 | for((i=0; i<len-4; i++)); do tt=$(getbyte); done | |
99 | ;; | |
100 | esac | |
101 | done | |
102 | } < "$data" | |
46cc2926 HH |
103 | } |
104 | ||
350ec5d9 HH |
105 | # /home/harald/Downloads/FcoeBootDevice-80005007-4248-4e4b-8df4-93060220756f |
106 | ||
46cc2926 HH |
107 | get_fcoe_boot_mac() |
108 | { | |
109 | data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data} | |
350ec5d9 | 110 | [ -f "$data" ] || return 1 |
46cc2926 | 111 | local IFS= LC_CTYPE=C tt len type hextype |
350ec5d9 HH |
112 | { |
113 | getword >/dev/null | |
114 | getword >/dev/null | |
115 | while :; do | |
116 | type=$(getbyte) || return 1 | |
117 | subtype=$(getbyte) || return 1 | |
118 | len=$(getword) || return 1 | |
119 | hextype=$(printf "%02x%02x" "$type" "$subtype") | |
120 | case $hextype in | |
121 | 030b) | |
122 | # MAC | |
123 | printf "%02x:%02x:%02x:%02x:%02x:%02x" $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) | |
124 | for((i=0; i<27; i++)); do tt=$(getbyte) || return 1; done | |
125 | ;; | |
126 | 7fff) | |
127 | # END | |
128 | return 0 | |
129 | ;; | |
130 | *) | |
131 | #printf "Unknown(Type:0x%02x SubType:0x%02x len=%d)\n" "$type" "$subtype" "$len" >&2 | |
132 | for((i=0; i<len-4; i++)); do tt=$(getbyte); done | |
133 | ;; | |
134 | esac | |
135 | done | |
136 | } < "$data" | |
46cc2926 HH |
137 | } |
138 | ||
139 | get_fcoe_boot_vlan() | |
140 | { | |
141 | data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data} | |
350ec5d9 | 142 | [ -f "$data" ] || return 1 |
46cc2926 | 143 | local IFS= LC_CTYPE=C tt len type hextype |
350ec5d9 HH |
144 | { |
145 | getword >/dev/null | |
146 | getword >/dev/null | |
147 | while :; do | |
148 | type=$(getbyte) || return 1 | |
149 | subtype=$(getbyte) || return 1 | |
150 | len=$(getword) || return 1 | |
151 | hextype=$(printf "%02x%02x" "$type" "$subtype") | |
152 | case $hextype in | |
153 | 0314) | |
154 | # VLAN | |
155 | printf "%d" $(getword) | |
156 | ;; | |
157 | 7fff) | |
158 | # END | |
159 | return 0 | |
160 | ;; | |
161 | *) | |
162 | #printf "Unknown(Type:0x%02x SubType:0x%02x len=%d)\n" "$type" "$subtype" "$len" >&2 | |
163 | for((i=0; i<len; i++)); do tt=$(getbyte); done | |
164 | ;; | |
165 | esac | |
166 | done | |
167 | } < "$data" | |
46cc2926 | 168 | } |