Contiki-NG
ieee-addr.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538-ieee-addr
33  * @{
34  *
35  * \file
36  * Driver for the cc2538 IEEE addresses
37  */
38 #include "contiki.h"
39 #include "net/linkaddr.h"
40 #include "ieee-addr.h"
41 
42 #include <stdint.h>
43 #include <string.h>
44 /*---------------------------------------------------------------------------*/
45 void
46 ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
47 {
49  uint8_t ieee_addr_hc[8] = IEEE_ADDR_CONF_ADDRESS;
50 
51  memcpy(dst, &ieee_addr_hc[8 - len], len);
52  } else {
53  /*
54  * By default, we assume that the IEEE address is stored on flash using
55  * little-endian byte order.
56  *
57  * However, some SoCs ship with a different byte order, whereby the first
58  * four bytes are flipped with the four last ones.
59  *
60  * Using this address as an example: 00 12 4B 00 01 02 03 04
61  * We expect it stored as: 04 03 02 01 00 4B 12 00
62  * But it is also possible to encounter: 00 4B 12 00 04 03 02 01
63  *
64  * Thus: read locations [3, 2, 1] and if we encounter the TI OUI, flip the
65  * order of the two 4-byte sequences. Each of the 4-byte sequences is still
66  * little-endian.
67  */
68  int i;
69  uint8_t oui_ti[3] = IEEE_ADDR_OUI_TI;
70  if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0]
71  && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1]
72  && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) {
73  for(i = 0; i < len; i++) {
74  dst[len - i - 1] = ((uint8_t *)IEEE_ADDR_LOCATION)[i < 4 ? i + 4 : i - 4];
75  }
76  } else {
77  for(i = 0; i < len; i++) {
78  dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i];
79  }
80  }
81  }
82 
83 #if IEEE_ADDR_NODE_ID
84  dst[len - 1] = IEEE_ADDR_NODE_ID & 0xFF;
85  dst[len - 2] = IEEE_ADDR_NODE_ID >> 8;
86 #endif
87 }
88 
89 /** @} */
#define IEEE_ADDR_OUI_TI
TI OUI.
Definition: ieee-addr.h:55
Header file for the link-layer address representation
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Copy the node&#39;s IEEE address to a destination memory area.
Definition: ieee-addr.c:46
#define IEEE_ADDR_CONF_ADDRESS
The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED is defined as 1...
Definition: cc2538-conf.h:289
#define IEEE_ADDR_CONF_HARDCODED
Location of the IEEE address 0 => Read from InfoPage, 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS.
Definition: cc2538-conf.h:281
#define IEEE_ADDR_LOCATION
Select which address location to use.
Definition: ieee-addr.h:82
Header file with register and macro declarations for the cc2538 IEEE address driver.