Contiki 3.x
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-conf.h"
39 #include "net/linkaddr.h"
40 #include "ieee-addr.h"
41 
42 #include <stdint.h>
43 /*---------------------------------------------------------------------------*/
44 void
45 ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
46 {
48  uint8_t ieee_addr_hc[8] = IEEE_ADDR_CONF_ADDRESS;
49 
50  memcpy(dst, &ieee_addr_hc[8 - len], len);
51  } else {
52  /*
53  * By default, we assume that the IEEE address is stored on flash using
54  * little-endian byte order.
55  *
56  * However, some SoCs ship with a different byte order, whereby the first
57  * four bytes are flipped with the four last ones.
58  *
59  * Using this address as an example: 00 12 4B 00 01 02 03 04
60  * We expect it stored as: 04 03 02 01 00 4B 12 00
61  * But it is also possible to encounter: 00 4B 12 00 04 03 02 01
62  *
63  * Thus: read locations [3, 2, 1] and if we encounter the TI OUI, flip the
64  * order of the two 4-byte sequences. Each of the 4-byte sequences is still
65  * little-endian.
66  */
67  int i;
68  uint8_t oui_ti[3] = IEEE_ADDR_OUI_TI;
69  if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0]
70  && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1]
71  && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) {
72  for(i = 0; i < len / 2; i++) {
73  dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len / 2 - 1 - i];
74  }
75  for(i = 0; i < len / 2; i++) {
76  dst[i + len / 2] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i];
77  }
78  } else {
79  for(i = 0; i < len; i++) {
80  dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i];
81  }
82  }
83  }
84 
85 #if IEEE_ADDR_NODE_ID
86  dst[len - 1] = IEEE_ADDR_NODE_ID & 0xFF;
87  dst[len - 2] = IEEE_ADDR_NODE_ID >> 8;
88 #endif
89 }
90 
91 /** @} */
#define IEEE_ADDR_CONF_HARDCODED
Location of the IEEE address 0 =&gt; Read from InfoPage, 1 =&gt; Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS.
Definition: contiki-conf.h:361
#define IEEE_ADDR_CONF_ADDRESS
The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED is defined as 1...
Definition: contiki-conf.h:369
Header file with register and macro declarations for the cc2538 IEEE address driver.
#define IEEE_ADDR_OUI_TI
TI OUI.
Definition: ieee-addr.h:55
#define IEEE_ADDR_LOCATION
Select which address location to use.
Definition: ieee-addr.h:82
Header file for the Rime address representation