Skip to content

at86rf2xx: fix EUI64 computation#2963

Merged
haukepetersen merged 5 commits intoRIOT-OS:masterfrom
OlegHahm:fix_2962
May 19, 2015
Merged

at86rf2xx: fix EUI64 computation#2963
haukepetersen merged 5 commits intoRIOT-OS:masterfrom
OlegHahm:fix_2962

Conversation

@OlegHahm
Copy link
Copy Markdown
Member

fixes #2962

@OlegHahm OlegHahm added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: drivers Area: Device drivers NSTF labels May 10, 2015
@OlegHahm OlegHahm added this to the Release 2015.06 milestone May 10, 2015
@miri64
Copy link
Copy Markdown
Member

miri64 commented May 10, 2015

I'd prefer to keep it completely independent from hashes. I'm already annoyed by native when it changes the hardware address everytime I restart and I forget the -i flag. I don't like it to be the case for every board to have a different address depending on the modules I compile in.

@OlegHahm OlegHahm added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 10, 2015
@OlegHahm
Copy link
Copy Markdown
Member Author

Ok, I agree. Here's another approach, that's mostly taken from OpenWSN. It seems a little bit arbitrary, but at least we will have the same EUI-64 addresses on the IoT-LAB.

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 10, 2015

Why not the XOR method you had earlier?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer some sort of enforced byteorder here... Either le_uintX_t (to keep the spirit of IEEE 802.15.4) or network_uintX_t (to be compatible with everything else).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will adapt.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But IEEE 802.15.4 addresses are little-endian, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the EUI-64 I'm never sure 😕

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the EUI-64 in the driver be a data type with enforced endianess, too?

@OlegHahm
Copy link
Copy Markdown
Member Author

Why not the XOR method you had earlier?

I think it makes things easier if we have the same UIDs at least in OpenWSN and RIOT.

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

Then you maybe should adapt the xbee driver, too (if you want to make it dependent on the EUI-64)

@OlegHahm
Copy link
Copy Markdown
Member Author

Then you maybe should adapt the xbee driver, too (if you want to make it dependent on the EUI-64)

I cannot test this device and I don't understand the parts in brackets.

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

I don't understand the parts in brackets.

Currently the short address for this device is generated from CPU ID, too. However, if we take the scheme you proposed to take bytes of the EUI-64 for that, we should do that on the xbee device too (where the EUI-64 is preinitialized by the vendor).

@OlegHahm
Copy link
Copy Markdown
Member Author

Ah, okay. Yes, I'm much in favor of this.

@OlegHahm
Copy link
Copy Markdown
Member Author

Updated. Endianess not yet addressed, because a) I'm not sure what the right endianess and b) I think the driver should reflect this, too. Maybe another PR for that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized, that this is not really an OUI, right? Maybe for the platforms that OpenWSN supports, but we support way more boards than them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we support way more boards than them.

Actually, I think they support more boards with 802.15.4 support than RIOT. But this code is taken from the iot-lab implementation. We could make it iot-lab specific, but wanted to avoid this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think we should that the first three bytes to 000425, Atmels OUI here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think we should that the first three bytes to 000425, Atmels OUI here?

no, I think that is a bad idea… I'd prefer the XOR solution above this solution actually :/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I think that is a bad idea…

Why? It is an Atmel device.

I'd prefer the XOR solution above this solution actually :/

Why?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Atmel is handling its device identifiers => a collision is bound to happen. And I don't know how the legal situation is. Also: since it is still a pseudo EUI-64 this way the correct prefix would be 020425, since the universal/local-bit must be set.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see a way to make sure not collide with any vendor's ID?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I don't see the benefit in making some pseudo-Atmel (actually not) sanctioned EUI-64 over a completely "randomised" one out of the whole range of the CPU ID.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so, I leave the PR as is.

@OlegHahm
Copy link
Copy Markdown
Member Author

@cladmi, do you have some insights how to sensibly compute an EUI64 for the at86rf2xx?

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

And what is @haukepetersen's opinion on this?

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

@OlegHahm I would prefer a method that can be generally applied for ALL IEEE 802.15.4 devices (as long as they allow for that), not just the at86rf2xx ones.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

@OlegHahm
Copy link
Copy Markdown
Member Author

I would prefer a method that can be generally applied for ALL IEEE 802.15.4 devices (as long as they allow for that), not just the at86rf2xx ones.

Apparently, that's not possible if weird devices as the XBEE not even allow to set the EUI-64.

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

That's why I wrote "(as long as they allow for that)".

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

Exceptions gonna except... let's at least have a general case for non-exceptions is all I'm saying.

@OlegHahm
Copy link
Copy Markdown
Member Author

Do you have a proposal?

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

As I proposed yesterday and you seem to ignore since then 😒: using "sliding XOR"

#if CPUID_ID_LEN
     uint8_t cpuid[CPU_ID_LEN];

     cpuid_get(cpuid);
#if CPUID_ID_LEN < 8
     /* in case CPUID_ID_LEN < 8, lead with zeros */
     for (int i = 0; i < (8 - CPUID_ID_LEN); i++) {
         addr_long[i] = 0;
     }

     for (int i = 0; i < CPUID_ID_LEN; i++) {
         addr_long[i + (8 - CPUID_ID_LEN)] = cpuid[i];
     }

 #else
    memset(addr_long, 0, 8);

    for (int i = 0; i < (CPUID_ID_LEN - 8); i++) {
         for (int j = i; j < 8; j++) {
             addr_long[j] ^= cpuid[i + j];
         } 
    }
#endif
#endif
    addr_long[0] &= ~0x01;    /* Ensure that address is unicast */
    addr_long[0] |= 0x02;     /* Ensure that address is local */

[edit: Set the EUI-64 unicast/group and local/universal bits accordingly]

@OlegHahm
Copy link
Copy Markdown
Member Author

I'm not ignoring it, but you haven't answered why you prefer this solution. I don't see how this is more generic. The CPUID is vendor specific anyway.

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 11, 2015

Oh… sorry somehow your question slipped through my radar. I prefer it, since it uses the entire CPUID compared to just parts of it.

@haukepetersen
Copy link
Copy Markdown
Contributor

Looks good to me, just one remark: If we take addr_long.uint16[0].u16 as short address for the atxx driver, the short addresses seem not to be unique, right? looking at these two generated addresses:

node1: 36:32:48:33:46:d5:9f:26
node2: 36:32:48:33:46:d8:9e:16

doesn't it make more sense to use addr_long.uint16[3].u16 as default short address for now?

Edit: never mind, byte ordering is not my strength...

@haukepetersen
Copy link
Copy Markdown
Contributor

Looks good to me know, ACK when squashed and Travis is happy.

@OlegHahm
Copy link
Copy Markdown
Member Author

Too bad, just found a duplicate long address with this scheme on IoT-LAB. :(

@OlegHahm
Copy link
Copy Markdown
Member Author

Without the last commit but puting

    /* make sure we mark the address as non-multicast and not globally unique */
    cpuid[0] &= ~(0x01);
    cpuid[0] |= 0x02;

in the right place the duplicate is gone...

Tested with 150 nodes on IoT-Lab. Don't have time to check for duplicates on all nodes.

@haukepetersen
Copy link
Copy Markdown
Contributor

What do you mean with right place? Isn't it in the right place in the current code?

@OlegHahm
Copy link
Copy Markdown
Member Author

Yes, but not in the version before the last commit.

@haukepetersen
Copy link
Copy Markdown
Contributor

Ah, I understand :-) Do you want to squash?

@OlegHahm
Copy link
Copy Markdown
Member Author

This code definitely result in duplicate EUI64 addresses on IoT-LAB. I have a somewhat weird patch that doesn't reveal duplicates on the 160 nodes I tested, but I'm not sure, what's the better approach.

@haukepetersen
Copy link
Copy Markdown
Contributor

Hm, are the CPUIDs on IoT-Lab nodes definitely unique?

@OlegHahm
Copy link
Copy Markdown
Member Author

You should probably ask ST, but I think, yes, they are. It's impossible to guarantee any uniqueness here if we don't know the exact nature of the CPUID. What I propose for the IoT-Lab case: we leave the calculation in this driver as it is with the current state of this PR and add something to the netif auto_init that set different addresses if required (indicated by, e.g., the board or the user).

@haukepetersen
Copy link
Copy Markdown
Contributor

sounds good. What I do not quite understand is the duplicate EUIs in the IoT-Lab, as XORed results from unique CPUIDs should acutally lead to unique EUIs. But anyhow, lets merge and improve afterwards.

ACK

OlegHahm added 3 commits May 18, 2015 15:30
The EUI64 for the at86rfxx is computed from the full CPUID by using
sliding xor.
Dependency two CPUID and hard coded default short address are
superfluous now.
@OlegHahm
Copy link
Copy Markdown
Member Author

Rebased without merge conflicts.

@OlegHahm
Copy link
Copy Markdown
Member Author

What I do not quite understand is the duplicate EUIs in the IoT-Lab, as XORed results from unique CPUIDs should acutally lead to unique EUIs.

We're basically mapping a (probably unique) 12 bit value to a an 8 bit value. Collisions may occur with every mapping scheme.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented May 18, 2015

@OlegHahm: I can run my UID scripts to provide you all the CPUIDs of the working IoT-Lab nodes. I hope to give it by tomorrow evening, ping me on IRC if I don't.

@OlegHahm OlegHahm removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 18, 2015
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented May 18, 2015

https://gist.github.com/cladmi/06c5969be4f1e6e3254b

Almost every nodes. However half of grenoble,m3 nodes are missing because an experiment is currently run. The UID is printed in the uid8[0]->uid8[11] order and it also includes Paris that should be deployed "soon".

@jnohlgard
Copy link
Copy Markdown
Member

@OlegHahm @cladmi I checked the list that @cladmi posted using , there are no duplicates among the full CPUIDs
cat IoT-Lab\ CPUID | awk -F: '{ print $2; }' | sed -e 's/[", ]//g' -e '/^[ ]*$/d'| sort | uniq

@haukepetersen
Copy link
Copy Markdown
Contributor

When looking at these numbers, I get the feeling that i does make sense, to make the EUI creation platform dependent (-> then we can use known characteristics of the CPUIDs). So I am thinking, that it could make sense, to extend the cpuid module by a second function, maybe something like

void cpuid_get_unique_token(uint8_t res, sizte_t len);

In the implementation of that function we can than focus on known relevant bytes (e.g. bytes 3,9,10 for the iot-lab).

@OlegHahm
Copy link
Copy Markdown
Member Author

I think I like the idea. But should we merge this for now and make follow-up PR? Some duplicate EUI64s are less bad than identical EUI64s for all. 😉

@haukepetersen
Copy link
Copy Markdown
Contributor

Agreed. re-ACK and go.

haukepetersen added a commit that referenced this pull request May 19, 2015
at86rf2xx: fix EUI64 computation
@haukepetersen haukepetersen merged commit 354e5db into RIOT-OS:master May 19, 2015
@OlegHahm OlegHahm deleted the fix_2962 branch May 19, 2015 19:42
@miri64 miri64 added the Area: network Area: Networking label Sep 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Area: network Area: Networking Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

at8r6rf231/iot-lab_M3: long address is not unique

5 participants