Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
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
#include "ieee-addr-id.h"
45
/*---------------------------------------------------------------------------*/
46
#include <ti/devices/DeviceFamily.h>
47
#include DeviceFamily_constructPath(inc/hw_memmap.h)
48
#include DeviceFamily_constructPath(inc/hw_fcfg1.h)
49
#include DeviceFamily_constructPath(inc/hw_ccfg.h)
50
/*---------------------------------------------------------------------------*/
51
#include <stdint.h>
52
#include <string.h>
53
/*---------------------------------------------------------------------------*/
54
#define IEEE_ADDR_HARDCODED IEEE_ADDR_CONF_HARDCODED
55
#define IEEE_ADDR_ADDRESS IEEE_ADDR_CONF_ADDRESS
56
/*---------------------------------------------------------------------------*/
57
#define IEEE_MAC_PRIMARY_ADDRESS (FCFG1_BASE + FCFG1_O_MAC_15_4_0)
58
#define IEEE_MAC_SECONDARY_ADDRESS (CCFG_BASE + CCFG_O_IEEE_MAC_0)
59
/*---------------------------------------------------------------------------*/
60
int
61
ieee_addr_cpy_to
(uint8_t *dst, uint8_t len)
62
{
63
if
(len > LINKADDR_SIZE) {
64
return
-1;
65
}
66
67
if
(IEEE_ADDR_HARDCODED) {
68
const
uint8_t ieee_addr_hc[LINKADDR_SIZE] = IEEE_ADDR_ADDRESS;
69
70
memcpy(dst, &ieee_addr_hc[LINKADDR_SIZE - len], len);
71
}
else
{
72
int
i;
73
74
volatile
const
uint8_t *
const
primary = (uint8_t *)IEEE_MAC_PRIMARY_ADDRESS;
75
volatile
const
uint8_t *
const
secondary = (uint8_t *)IEEE_MAC_SECONDARY_ADDRESS;
76
77
/* Reading from primary location... */
78
volatile
const
uint8_t *ieee_addr = primary;
79
80
/*
81
* ...unless we can find a byte != 0xFF in secondary.
82
*
83
* Intentionally checking all 8 bytes here instead of len, because we
84
* are checking validity of the entire address respective of the
85
* actual number of bytes the caller wants to copy over.
86
*/
87
for
(i = 0; i < len; i++) {
88
if
(secondary[i] != 0xFF) {
89
/* A byte in the secondary location is not 0xFF. Use the secondary */
90
ieee_addr = secondary;
91
break
;
92
}
93
}
94
95
/*
96
* We have chosen what address to read the address from. Do so,
97
* in inverted byte order.
98
*/
99
for
(i = 0; i < len; i++) {
100
dst[i] = ieee_addr[len - 1 - i];
101
}
102
}
103
104
#ifdef IEEE_ADDR_NODE_ID
105
dst[len - 1] = (IEEE_ADDR_NODE_ID >> 0) & 0xFF;
106
dst[len - 2] = (IEEE_ADDR_NODE_ID >> 8) & 0xFF;
107
#endif
108
109
return
0;
110
}
111
/*---------------------------------------------------------------------------*/
112
/** @} */
ieee_addr_cpy_to
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Definition
ieee-addr.c:47
linkaddr.h
Header file for the link-layer address representation.
ieee-addr.h
Header file for the CC13xx/CC26xx IEEE address driver.
arch
cpu
simplelink-cc13xx-cc26xx
rf
ieee-addr.c
Generated on
for Contiki-NG by
1.17.0