Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
ble-addr.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016, Michael Spoerk
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-ble-addr
32
* @{
33
*
34
* \file
35
* Implementation of the CC13xx/CC26xx IEEE addresses driver.
36
* \author
37
* Michael Spoerk <mi.spoerk@gmail.com>
38
* Edvard Pettersen <e.pettersen@ti.com>
39
*/
40
/*---------------------------------------------------------------------------*/
41
#include "contiki.h"
42
#include "
dev/ble-hal.h
"
43
#include "
net/linkaddr.h
"
44
45
#include "
rf/ble-addr.h
"
46
/*---------------------------------------------------------------------------*/
47
#include <ti/devices/DeviceFamily.h>
48
#include DeviceFamily_constructPath(inc/hw_memmap.h)
49
#include DeviceFamily_constructPath(inc/hw_fcfg1.h)
50
#include DeviceFamily_constructPath(inc/hw_ccfg.h)
51
/*---------------------------------------------------------------------------*/
52
#include <string.h>
53
/*---------------------------------------------------------------------------*/
54
#define BLE_MAC_PRIMARY_ADDRESS (FCFG1_BASE + FCFG1_O_MAC_BLE_0)
55
#define BLE_MAC_SECONDARY_ADDRESS (CCFG_BASE + CCFG_O_IEEE_BLE_0)
56
/*---------------------------------------------------------------------------*/
57
uint8_t *
58
ble_addr_ptr
(
void
)
59
{
60
volatile
const
uint8_t *
const
primary = (uint8_t *)BLE_MAC_PRIMARY_ADDRESS;
61
volatile
const
uint8_t *
const
secondary = (uint8_t *)BLE_MAC_SECONDARY_ADDRESS;
62
63
/*
64
* Reading from primary location...
65
* ...unless we can find a byte != 0xFF in secondary
66
*
67
* Intentionally checking all bytes here instead of len, because we
68
* are checking validity of the entire address irrespective of the
69
* actual number of bytes the caller wants to copy over.
70
*/
71
size_t
i;
72
for
(i = 0; i < BLE_ADDR_SIZE; i++) {
73
if
(secondary[i] != 0xFF) {
74
/* A byte in secondary is not 0xFF. Use secondary address. */
75
return
(uint8_t *)secondary;
76
}
77
}
78
79
/* All bytes in secondary is 0xFF. Use primary address. */
80
return
(uint8_t *)primary;
81
}
82
/*---------------------------------------------------------------------------*/
83
int
84
ble_addr_be_cpy
(uint8_t *dst)
85
{
86
if
(!dst) {
87
return
-1;
88
}
89
90
volatile
const
uint8_t *
const
ble_addr =
ble_addr_ptr
();
91
92
/*
93
* We have chosen what address to read the BLE address from. Do so,
94
* inverting byte order
95
*/
96
size_t
i;
97
for
(i = 0; i < BLE_ADDR_SIZE; i++) {
98
dst[i] = ble_addr[BLE_ADDR_SIZE - 1 - i];
99
}
100
101
return
0;
102
}
103
/*---------------------------------------------------------------------------*/
104
int
105
ble_addr_le_cpy
(uint8_t *dst)
106
{
107
if
(!dst) {
108
return
-1;
109
}
110
111
volatile
const
uint8_t *
const
ble_addr =
ble_addr_ptr
();
112
113
size_t
i;
114
for
(i = 0; i < BLE_ADDR_SIZE; i++) {
115
dst[i] = ble_addr[i];
116
}
117
118
return
0;
119
}
120
/*---------------------------------------------------------------------------*/
121
int
122
ble_addr_to_eui64
(uint8_t *dst, uint8_t *src)
123
{
124
if
(!dst || !src) {
125
return
-1;
126
}
127
128
memcpy(dst, src, 3);
129
dst[3] = 0xFF;
130
dst[4] = 0xFE;
131
memcpy(&dst[5], &src[3], 3);
132
133
return
0;
134
}
135
/*---------------------------------------------------------------------------*/
136
int
137
ble_addr_to_eui64_cpy
(uint8_t *dst)
138
{
139
if
(!dst) {
140
return
-1;
141
}
142
143
int
res;
144
uint8_t ble_addr[BLE_ADDR_SIZE];
145
146
res =
ble_addr_le_cpy
(ble_addr);
147
if
(res) {
148
return
-1;
149
}
150
151
return
ble_addr_to_eui64
(dst, ble_addr);
152
}
153
/*---------------------------------------------------------------------------*/
154
/** @} */
ble-hal.h
hardware abstraction for a BLE controller
ble_addr_to_eui64
int ble_addr_to_eui64(uint8_t *dst, uint8_t *src)
Copy the node's BLE address to a destination memory area and converts it into a EUI64 address in the ...
Definition
ble-addr.c:58
ble_addr_le_cpy
int ble_addr_le_cpy(uint8_t *dst)
Copy the node's factory BLE address to a destination memory area in little-endian (le) order.
Definition
ble-addr.c:105
ble_addr_to_eui64_cpy
int ble_addr_to_eui64_cpy(uint8_t *dst)
Copy the node's EUI64 address that is based on its factory BLE address to a destination memory area.
Definition
ble-addr.c:137
ble_addr_ptr
uint8_t * ble_addr_ptr(void)
Retrieve the pointer to where the BLE address is stored.
Definition
ble-addr.c:58
ble_addr_be_cpy
int ble_addr_be_cpy(uint8_t *dst)
Copy the node's factory BLE address to a destination memory area in big-endian (be) order.
Definition
ble-addr.c:84
linkaddr.h
Header file for the link-layer address representation.
ble-addr.h
Header file for the CC13xx/CC26xx BLE address driver.
arch
cpu
simplelink-cc13xx-cc26xx
rf
ble-addr.c
Generated on
for Contiki-NG by
1.17.0