Commit 463e159b authored by Maciej Lipinski's avatar Maciej Lipinski

[MAC/w1] fixed creation of MAC from onewire thermometer's ID when no SDB

parent 6f17361c
...@@ -310,9 +310,10 @@ found_exit: ...@@ -310,9 +310,10 @@ found_exit:
*/ */
int get_persistent_mac(uint8_t portnum, uint8_t *mac) int get_persistent_mac(uint8_t portnum, uint8_t *mac)
{ {
int ret; int ret = 0;
int i, class; int i, class;
uint64_t rom; uint64_t rom;
struct w1_dev *d;
if (IS_HOST_PROCESS) { if (IS_HOST_PROCESS) {
/* we don't have sdb working, so get the real eth address */ /* we don't have sdb working, so get the real eth address */
...@@ -321,10 +322,12 @@ int get_persistent_mac(uint8_t portnum, uint8_t *mac) ...@@ -321,10 +322,12 @@ int get_persistent_mac(uint8_t portnum, uint8_t *mac)
} }
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_MAC) < 0) if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_MAC) < 0)
return -1; ret =-1;
else
ret = sdbfs_fread(&wrc_sdb, 0, mac, 6); {
sdbfs_close(&wrc_sdb); ret = sdbfs_fread(&wrc_sdb, 0, mac, 6);
sdbfs_close(&wrc_sdb);
}
if (ret < 0) if (ret < 0)
pp_printf("%s: SDB error\n", __func__); pp_printf("%s: SDB error\n", __func__);
...@@ -335,19 +338,20 @@ int get_persistent_mac(uint8_t portnum, uint8_t *mac) ...@@ -335,19 +338,20 @@ int get_persistent_mac(uint8_t portnum, uint8_t *mac)
} }
if (ret < 0) { if (ret < 0) {
pp_printf("%s: Using W1 serial number\n", __func__); pp_printf("%s: Using W1 serial number\n", __func__);
w1_scan_bus(&wrpc_w1_bus);
for (i = 0; i < W1_MAX_DEVICES; i++) { for (i = 0; i < W1_MAX_DEVICES; i++) {
class = w1_class(wrpc_w1_bus.devs + i); d = wrpc_w1_bus.devs + i;
if (class != 0x28 && class != 0x42) if (d->rom) {
continue; mac[0] = 0x22;
rom = wrpc_w1_bus.devs[i].rom; mac[1] = 0x33;
mac[0] = 0x22; mac[2] = 0xff & (d->rom >> 32);
mac[1] = 0x33; mac[3] = 0xff & (d->rom >> 24);
mac[2] = rom >> 32; mac[4] = 0xff & (d->rom >> 16);
mac[3] = rom >> 24; mac[5] = 0xff & (d->rom >> 8);
mac[4] = rom >> 16; ret = 0;
mac[5] = rom >> 8; break;
ret = 0; }
} }
} }
if (ret < 0) { if (ret < 0) {
pp_printf("%s: failure\n", __func__); pp_printf("%s: failure\n", __func__);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment