Contiki-NG
ieee-addr.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, 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 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/**
31 * \addtogroup cc13xx-cc26xx-rf-ieee-addr
32 * @{
33 *
34 * \file
35 * Implementation of the CC13xx/CC26xx IEEE addresses driver.
36 * \author
37 * Edvard Pettersen <e.pettersen@ti.com>
38 */
39/*---------------------------------------------------------------------------*/
40#include "contiki.h"
41#include "net/linkaddr.h"
42
43#include "rf/ieee-addr.h"
44/*---------------------------------------------------------------------------*/
45#include <ti/devices/DeviceFamily.h>
46#include DeviceFamily_constructPath(inc/hw_memmap.h)
47#include DeviceFamily_constructPath(inc/hw_fcfg1.h)
48#include DeviceFamily_constructPath(inc/hw_ccfg.h)
49/*---------------------------------------------------------------------------*/
50#include <stdint.h>
51#include <string.h>
52/*---------------------------------------------------------------------------*/
53#define IEEE_ADDR_HARDCODED IEEE_ADDR_CONF_HARDCODED
54#define IEEE_ADDR_ADDRESS IEEE_ADDR_CONF_ADDRESS
55/*---------------------------------------------------------------------------*/
56#define IEEE_MAC_PRIMARY_ADDRESS (FCFG1_BASE + FCFG1_O_MAC_15_4_0)
57#define IEEE_MAC_SECONDARY_ADDRESS (CCFG_BASE + CCFG_O_IEEE_MAC_0)
58/*---------------------------------------------------------------------------*/
59int
60ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
61{
62 if(len > LINKADDR_SIZE) {
63 return -1;
64 }
65
66 if(IEEE_ADDR_HARDCODED) {
67 const uint8_t ieee_addr_hc[LINKADDR_SIZE] = IEEE_ADDR_ADDRESS;
68
69 memcpy(dst, &ieee_addr_hc[LINKADDR_SIZE - len], len);
70 } else {
71 int i;
72
73 volatile const uint8_t *const primary = (uint8_t *)IEEE_MAC_PRIMARY_ADDRESS;
74 volatile const uint8_t *const secondary = (uint8_t *)IEEE_MAC_SECONDARY_ADDRESS;
75
76 /* Reading from primary location... */
77 volatile const uint8_t *ieee_addr = primary;
78
79 /*
80 * ...unless we can find a byte != 0xFF in secondary.
81 *
82 * Intentionally checking all 8 bytes here instead of len, because we
83 * are checking validity of the entire address respective of the
84 * actual number of bytes the caller wants to copy over.
85 */
86 for(i = 0; i < len; i++) {
87 if(secondary[i] != 0xFF) {
88 /* A byte in the secondary location is not 0xFF. Use the secondary */
89 ieee_addr = secondary;
90 break;
91 }
92 }
93
94 /*
95 * We have chosen what address to read the address from. Do so,
96 * in inverted byte order.
97 */
98 for(i = 0; i < len; i++) {
99 dst[i] = ieee_addr[len - 1 - i];
100 }
101 }
102
103#ifdef IEEE_ADDR_NODE_ID
104 dst[len - 1] = (IEEE_ADDR_NODE_ID >> 0) & 0xFF;
105 dst[len - 2] = (IEEE_ADDR_NODE_ID >> 8) & 0xFF;
106#endif
107
108 return 0;
109}
110/*---------------------------------------------------------------------------*/
111/** @} */
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Copy the node's IEEE address to a destination memory area.
Definition: ieee-addr.c:46
Header file for the link-layer address representation.