| 1 |
|
| 2 |
|
| 3 |
#include <boot/coreboot_tables.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <ctype.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include <drivers/vpd/vpd.h> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
static void decode_mac(struct mac_address *mac, |
| 16 |
const char *mac_addr_str, |
| 17 |
const char *key_name) |
| 18 |
{ |
| 19 |
int i; |
| 20 |
|
| 21 |
for (i = 0; i < sizeof(mac->mac_addr); i++) { |
| 22 |
int j; |
| 23 |
uint8_t n = 0; |
| 24 |
|
| 25 |
for (j = 0; j < 2; j++) { |
| 26 |
char c = mac_addr_str[i * 2 + j]; |
| 27 |
|
| 28 |
if (isxdigit(c)) { |
| 29 |
if (isdigit(c)) |
| 30 |
c -= '0'; |
| 31 |
else |
| 32 |
c = tolower(c) - 'a' + 10; |
| 33 |
} else { |
| 34 |
printk(BIOS_ERR, "%s: non hexadecimal symbol " |
| 35 |
"%#2.2x in the VPD field %s:%s\n", |
| 36 |
__func__, (uint8_t)c, key_name, |
| 37 |
mac_addr_str); |
| 38 |
c = 0; |
| 39 |
} |
| 40 |
n <<= 4; |
| 41 |
n |= c; |
| 42 |
} |
| 43 |
mac->mac_addr[i] = n; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
void lb_table_add_macs_from_vpd(struct lb_header *header) |
| 48 |
{ |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
const char *mac_addr_key_bases[] = {"ethernet_mac0", "wifi_mac0"}; |
| 54 |
char mac_addr_key[20]; |
| 55 |
char mac_addr_str[13]; |
| 56 |
int i, count; |
| 57 |
struct lb_macs *macs = NULL; |
| 58 |
|
| 59 |
|
| 60 |
mac_addr_key[sizeof(mac_addr_key) - 1] = '\0'; |
| 61 |
|
| 62 |
count = 0; |
| 63 |
for (i = 0; i < ARRAY_SIZE(mac_addr_key_bases); i++) { |
| 64 |
int index_of_index; |
| 65 |
|
| 66 |
strncpy(mac_addr_key, mac_addr_key_bases[i], |
| 67 |
sizeof(mac_addr_key) - 1); |
| 68 |
index_of_index = strlen(mac_addr_key) - 1; |
| 69 |
|
| 70 |
do { |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if (!vpd_gets(mac_addr_key, mac_addr_str, |
| 76 |
sizeof(mac_addr_str), VPD_RO_THEN_RW)) |
| 77 |
break; |
| 78 |
|
| 79 |
if (!macs) { |
| 80 |
macs = (struct lb_macs *)lb_new_record(header); |
| 81 |
macs->tag = LB_TAG_MAC_ADDRS; |
| 82 |
} |
| 83 |
|
| 84 |
decode_mac(macs->mac_addrs + count, |
| 85 |
mac_addr_str, |
| 86 |
mac_addr_key); |
| 87 |
|
| 88 |
count++; |
| 89 |
mac_addr_key[index_of_index]++; |
| 90 |
} while (count < 10); |
| 91 |
} |
| 92 |
if (!count) |
| 93 |
return; |
| 94 |
|
| 95 |
macs->count = count; |
| 96 |
macs->size = sizeof(*macs) + count * sizeof(struct mac_address); |
| 97 |
} |