Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
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
#include "ieee-addr-id.h"
44
45
#include <stdint.h>
46
#include <string.h>
47
/*---------------------------------------------------------------------------*/
48
void
49
ieee_addr_cpy_to
(uint8_t *dst, uint8_t len)
50
{
51
if
(
IEEE_ADDR_CONF_HARDCODED
) {
52
uint8_t ieee_addr_hc[8] =
IEEE_ADDR_CONF_ADDRESS
;
53
54
memcpy(dst, &ieee_addr_hc[8 - len], len);
55
}
else
{
56
int
i;
57
58
/* Reading from primary location... */
59
uint8_t *location = (uint8_t *)
IEEE_ADDR_LOCATION_PRIMARY
;
60
61
/*
62
* ...unless we can find a byte != 0xFF in secondary
63
*
64
* Intentionally checking all 8 bytes here instead of len, because we
65
* are checking validity of the entire IEEE address irrespective of the
66
* actual number of bytes the caller wants to copy over.
67
*/
68
for
(i = 0; i < 8; i++) {
69
if
(((uint8_t *)
IEEE_ADDR_LOCATION_SECONDARY
)[i] != 0xFF) {
70
/* A byte in the secondary location is not 0xFF. Use the secondary */
71
location = (uint8_t *)
IEEE_ADDR_LOCATION_SECONDARY
;
72
break
;
73
}
74
}
75
76
/*
77
* We have chosen what address to read the IEEE address from. Do so,
78
* inverting byte order
79
*/
80
for
(i = 0; i < len; i++) {
81
dst[i] = location[len - 1 - i];
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
/** @} */
ieee-addr.h
Header file with register and macro declarations for the cc26xx IEEE address driver.
IEEE_ADDR_LOCATION_SECONDARY
#define IEEE_ADDR_LOCATION_SECONDARY
Secondary IEEE address location.
Definition
ieee-addr.h:71
IEEE_ADDR_LOCATION_PRIMARY
#define IEEE_ADDR_LOCATION_PRIMARY
Primary IEEE address location.
Definition
ieee-addr.h:66
ieee_addr_cpy_to
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Definition
ieee-addr.c:47
IEEE_ADDR_CONF_ADDRESS
#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:288
IEEE_ADDR_CONF_HARDCODED
#define IEEE_ADDR_CONF_HARDCODED
Location of the IEEE address 0 => Read from InfoPage, 1 => Use a hardcoded address,...
Definition
cc2538-conf.h:280
linkaddr.h
Header file for the link-layer address representation.
arch
cpu
cc26x0-cc13x0
ieee-addr.c
Generated on
for Contiki-NG by
1.17.0