summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/MAC_PHY/include/macAddr.h
blob: c9ff0ccb67444b788fe4d7b74b8ebc5d99bc1185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**************************************************************************//**
  \file macAddr.h

  \brief MAC addressing types and constants.

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
    History:
      18/06/07 ALuzhetsky - Created.
******************************************************************************/

#ifndef _MACADDR_H
#define _MACADDR_H

/******************************************************************************
                        Includes section.
******************************************************************************/
#include <types.h>

/******************************************************************************
                        Define(s) section.
******************************************************************************/
#define MAC_BROADCAST_PANID       0xFFFFU ///< Broadcast PANID.
#define MAC_BROADCAST_SHORT_ADDR  0xFFFFU ///< Broadcast short address, no association.
#define MAC_NO_SHORT_ADDR         0xFFFEU ///< After association no short address.
#define MAC_NO_EXT_ADDR           0x00ULL

/******************************************************************************
                        Types section.
******************************************************************************/
typedef uint16_t PanId_t;     ///< PAN identifier type declaration.
typedef uint16_t ShortAddr_t; ///< Short address type declaration.
typedef uint64_t ExtAddr_t;   ///< Extended address type declaration.

/// Union of possible MAC address types.
typedef union
{
  ShortAddr_t sh;
  ExtAddr_t   ext;
} MAC_Addr_t;

//! MAC address mode types (IEEE 802.15.4-2006 Table 80).
 typedef enum
{
  MAC_NO_ADDR_MODE    = 0x00,
  MAC_RSRV_ADDR_MODE  = 0x01,
  MAC_SHORT_ADDR_MODE = 0x02,
  MAC_EXT_ADDR_MODE   = 0x03
} MAC_AddrMode_t;

/******************************************************************************
                        Definitions section.
******************************************************************************/
#if defined UINT64_MEMCMP
  #define IS_EQ_EXT_ADDR(A, B) (0 == memcmp(&(A), &(B), sizeof(uint64_t)))
  #define IS_CORRECT_EXT_ADDR(A)  isCorrectExtAddr((const uint8_t *)&A)
  #define COPY_EXT_ADDR(DST, SRC) __builtin_memcpy(&(DST), &(SRC), sizeof(uint64_t))
#else
  #define IS_EQ_EXT_ADDR(A, B) ((A) == (B))
  #define IS_CORRECT_EXT_ADDR(A)  (MAC_NO_EXT_ADDR != (A))
  #define COPY_EXT_ADDR(DST, SRC) (DST) = (SRC)
#endif

/******************************************************************************
                Inline static functions prototypes section
******************************************************************************/
INLINE bool isCorrectExtAddr(const uint8_t *extAddr)
{
  uint8_t i = 0U;

  do
    if (extAddr[i]) return true;
  while (++i < sizeof(uint64_t));
  return false;
}

#endif //_MACADDR_H

// eof macAddr.h