Contiki-NG
ieee-addr.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, 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 /**
33  * \addtogroup cc26xx-ieee-addr
34  * @{
35  *
36  * \file
37  * Driver for the CC13xx/CC26xx IEEE addresses
38  */
39 /*---------------------------------------------------------------------------*/
40 #include "contiki.h"
41 #include "net/linkaddr.h"
42 #include "ieee-addr.h"
43 
44 #include <stdint.h>
45 #include <string.h>
46 /*---------------------------------------------------------------------------*/
47 void
48 ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
49 {
51  uint8_t ieee_addr_hc[8] = IEEE_ADDR_CONF_ADDRESS;
52 
53  memcpy(dst, &ieee_addr_hc[8 - len], len);
54  } else {
55  int i;
56 
57  /* Reading from primary location... */
58  uint8_t *location = (uint8_t *)IEEE_ADDR_LOCATION_PRIMARY;
59 
60  /*
61  * ...unless we can find a byte != 0xFF in secondary
62  *
63  * Intentionally checking all 8 bytes here instead of len, because we
64  * are checking validity of the entire IEEE address irrespective of the
65  * actual number of bytes the caller wants to copy over.
66  */
67  for(i = 0; i < 8; i++) {
68  if(((uint8_t *)IEEE_ADDR_LOCATION_SECONDARY)[i] != 0xFF) {
69  /* A byte in the secondary location is not 0xFF. Use the secondary */
70  location = (uint8_t *)IEEE_ADDR_LOCATION_SECONDARY;
71  break;
72  }
73  }
74 
75  /*
76  * We have chosen what address to read the IEEE address from. Do so,
77  * inverting byte order
78  */
79  for(i = 0; i < len; i++) {
80  dst[i] = location[len - 1 - i];
81  }
82  }
83 
84 #if IEEE_ADDR_NODE_ID
85  dst[len - 1] = IEEE_ADDR_NODE_ID & 0xFF;
86  dst[len - 2] = IEEE_ADDR_NODE_ID >> 8;
87 #endif
88 }
89 /*---------------------------------------------------------------------------*/
90 /** @} */
Header file for the link-layer address representation
#define IEEE_ADDR_LOCATION_SECONDARY
Secondary IEEE address location.
Definition: ieee-addr.h:71
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
Header file with register and macro declarations for the cc26xx IEEE address driver.
#define IEEE_ADDR_LOCATION_PRIMARY
Primary IEEE address location.
Definition: ieee-addr.h:66
#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