From 66edb5b263f9e77abde5f24c944f1cf6a5e37da8 Mon Sep 17 00:00:00 2001 From: LudovicW Date: Fri, 25 Apr 2014 09:32:37 +0200 Subject: [PATCH 1/4] Fix incorrect IEEE address byte re-ordering --- cpu/cc2538/ieee-addr.c | 18 +++++++++++++++--- cpu/cc2538/ieee-addr.h | 7 +++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cpu/cc2538/ieee-addr.c b/cpu/cc2538/ieee-addr.c index cb8c901bc..0e615f87e 100644 --- a/cpu/cc2538/ieee-addr.c +++ b/cpu/cc2538/ieee-addr.c @@ -49,10 +49,22 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len) memcpy(dst, &ieee_addr_hc[8 - len], len); } else { - /* Reading from Info Page, we need to invert byte order */ + /* Verify if we detect TI OUI in fourth position. TI store the MAC @ on + two parts (4 bytes LSB first and 4 bytes MSB) in this case, we need + to flip the 2 parts */ int i; - for(i = 0; i < len; i++) { - dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i]; + uint8_t oui_ti[3] = IEEE_ADDR_OUI_TI; + if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0] && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1] && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) { + for(i = 0; i < len / 2; i++) { + dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len / 2 - 1 - i]; + } + for(i = 0; i < len / 2; i++) { + dst[i + len / 2] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i]; + } + } else { + for(i = 0; i < len; i++) { + dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i]; + } } } diff --git a/cpu/cc2538/ieee-addr.h b/cpu/cc2538/ieee-addr.h index c7618c1e7..79e97d1fc 100644 --- a/cpu/cc2538/ieee-addr.h +++ b/cpu/cc2538/ieee-addr.h @@ -48,6 +48,13 @@ #include /*---------------------------------------------------------------------------*/ +/** + * \name TI OUI + * @{ + */ +#define IEEE_ADDR_OUI_TI { 0x00, 0x12, 0x4B } /**< TI OUI */ +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name IEEE address locations * @{ From 623d6084e75737b1fc4a54d34f98be9278326b98 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 6 Jun 2014 18:15:07 +0100 Subject: [PATCH 2/4] Make the CC2538 secondary IEEE address location configurable --- cpu/cc2538/ieee-addr.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cpu/cc2538/ieee-addr.h b/cpu/cc2538/ieee-addr.h index 79e97d1fc..faeacdb8f 100644 --- a/cpu/cc2538/ieee-addr.h +++ b/cpu/cc2538/ieee-addr.h @@ -57,10 +57,19 @@ /*---------------------------------------------------------------------------*/ /** * \name IEEE address locations + * + * The address of the secondary location can be configured by the platform + * or example + * * @{ */ -#define IEEE_ADDR_LOCATION_PRIMARY 0x00280028 /**< IEEE address location */ -#define IEEE_ADDR_LOCATION_SECONDARY 0x0027FFCC /**< IEEE address location */ +#define IEEE_ADDR_LOCATION_PRIMARY 0x00280028 /**< Primary IEEE address location */ + +#ifdef IEEE_ADDR_CONF_LOCATION_SECONDARY +#define IEEE_ADDR_LOCATION_SECONDARY IEEE_ADDR_CONF_LOCATION_SECONDARY +#else +#define IEEE_ADDR_LOCATION_SECONDARY 0x0027FFCC /**< Secondary IEEE address location */ +#endif /** @} */ /*---------------------------------------------------------------------------*/ /** From 5acc20fc47266fc316adaf0a27bbc2c4a676ebc9 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 6 Jun 2014 18:32:58 +0100 Subject: [PATCH 3/4] Improve code style --- cpu/cc2538/ieee-addr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpu/cc2538/ieee-addr.c b/cpu/cc2538/ieee-addr.c index 0e615f87e..e045d5d1d 100644 --- a/cpu/cc2538/ieee-addr.c +++ b/cpu/cc2538/ieee-addr.c @@ -54,7 +54,9 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len) to flip the 2 parts */ int i; uint8_t oui_ti[3] = IEEE_ADDR_OUI_TI; - if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0] && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1] && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) { + if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0] + && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1] + && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) { for(i = 0; i < len / 2; i++) { dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len / 2 - 1 - i]; } From 9d7c3b9866b672168c4798491c35a02c146fd240 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 6 Jun 2014 18:33:28 +0100 Subject: [PATCH 4/4] Improve documentation for the CC2538 IEEE address re-ordering --- cpu/cc2538/ieee-addr.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cpu/cc2538/ieee-addr.c b/cpu/cc2538/ieee-addr.c index e045d5d1d..f45e4210d 100644 --- a/cpu/cc2538/ieee-addr.c +++ b/cpu/cc2538/ieee-addr.c @@ -49,9 +49,21 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len) memcpy(dst, &ieee_addr_hc[8 - len], len); } else { - /* Verify if we detect TI OUI in fourth position. TI store the MAC @ on - two parts (4 bytes LSB first and 4 bytes MSB) in this case, we need - to flip the 2 parts */ + /* + * By default, we assume that the IEEE address is stored on flash using + * little-endian byte order. + * + * However, some SoCs ship with a different byte order, whereby the first + * four bytes are flipped with the four last ones. + * + * Using this address as an example: 00 12 4B 00 01 02 03 04 + * We expect it stored as: 04 03 02 01 00 4B 12 00 + * But it is also possible to encounter: 00 4B 12 00 04 03 02 01 + * + * Thus: read locations [3, 2, 1] and if we encounter the TI OUI, flip the + * order of the two 4-byte sequences. Each of the 4-byte sequences is still + * little-endian. + */ int i; uint8_t oui_ti[3] = IEEE_ADDR_OUI_TI; if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0]