Contiki-NG
Loading...
Searching...
No Matches
ieee-addr.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013, 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 * \addtogroup cc2538-ieee-addr
33 * @{
34 *
35 * \file
36 * Driver for the cc2538 IEEE addresses
37 */
38#include "contiki.h"
39#include "net/linkaddr.h"
40#include "ieee-addr.h"
41#include "ieee-addr-id.h"
42
43#include <stdint.h>
44#include <string.h>
45/*---------------------------------------------------------------------------*/
46void
47ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
48{
50 uint8_t ieee_addr_hc[8] = IEEE_ADDR_CONF_ADDRESS;
51
52 memcpy(dst, &ieee_addr_hc[8 - len], len);
53 } else {
54 /*
55 * By default, we assume that the IEEE address is stored on flash using
56 * little-endian byte order.
57 *
58 * However, some SoCs ship with a different byte order, whereby the first
59 * four bytes are flipped with the four last ones.
60 *
61 * Using this address as an example: 00 12 4B 00 01 02 03 04
62 * We expect it stored as: 04 03 02 01 00 4B 12 00
63 * But it is also possible to encounter: 00 4B 12 00 04 03 02 01
64 *
65 * Thus: read locations [3, 2, 1] and if we encounter the TI OUI, flip the
66 * order of the two 4-byte sequences. Each of the 4-byte sequences is still
67 * little-endian.
68 */
69 int i;
70 uint8_t oui_ti[3] = IEEE_ADDR_OUI_TI;
71 if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0]
72 && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1]
73 && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) {
74 for(i = 0; i < len; i++) {
75 dst[len - i - 1] = ((uint8_t *)IEEE_ADDR_LOCATION)[i < 4 ? i + 4 : i - 4];
76 }
77 } else {
78 for(i = 0; i < len; i++) {
79 dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i];
80 }
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 with register and macro declarations for the cc2538 IEEE address driver.
#define IEEE_ADDR_OUI_TI
TI OUI.
Definition ieee-addr.h:55
#define IEEE_ADDR_LOCATION
Select which address location to use.
Definition ieee-addr.h:82
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Definition ieee-addr.c:47
#define IEEE_ADDR_CONF_ADDRESS
The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED is defined as 1.
#define IEEE_ADDR_CONF_HARDCODED
Location of the IEEE address 0 => Read from InfoPage, 1 => Use a hardcoded address,...
Header file for the link-layer address representation.