summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/NWK/include/nwkNeighbor.h
blob: f30822c0256b4c14856aaf5ff7baeb69763d3dfc (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/**************************************************************************//**
 \file nwkNeighbor.h

 \brief Neighbor table interface.

 \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:
    2009-04-14 Max Gekk - Created.
   Last change:
    $Id: nwkNeighbor.h 19021 2011-10-26 12:36:59Z mgekk $
 ******************************************************************************/
/**//**
 *  The neighbor table of a device shall contain information on every device
 * within transmission range. ZigBee Spec r17, 3.6.1.5, page 366.
 **/
#if !defined _NWK_NEIGHBOR_H
#define _NWK_NEIGHBOR_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <appFramework.h>
#include <appTimer.h>
#include <nwkCommon.h>

/******************************************************************************
                                 Types section
 ******************************************************************************/
/** The relationship between the neighbor and the current device */
typedef enum _Relationship_t
{
  RELATIONSHIP_PARENT                = 0x00, /**< neighbor is the parent */
  RELATIONSHIP_CHILD                 = 0x01, /**< neighbor is a child */
  RELATIONSHIP_SIBLING               = 0x02, /**< neighbor is a sibling */
  RELATIONSHIP_NONE_OF_ABOVE         = 0x03, /**< none of the above */
  RELATIONSHIP_PREVIOUS_CHILD        = 0x04, /**< previous child */
  RELATIONSHIP_UNAUTHENTICATED_CHILD = 0x05, /**< unauthenticated child */
  RELATIONSHIP_EMPTY
} Relationship_t;

/** The neighbor table item. */
typedef struct _NwkNeighbor_t
{
  Relationship_t relationship;
  /** The type of neighbor device. */
  DeviceType_t deviceType;
  /** IEEE 802.15.4-2006 7.3.1.2 Capability Information field. */
  MAC_CapabilityInf_t capability;
  /** The logical channel on which the network is operating. */
  Channel_t logicalChannel;
  /** The 16-bit network address of the neighboring device. */
  ShortAddr_t networkAddr;
  PanId_t panId;
  /** 64-bit IEEE address that is unique to every device. */
  ExtAddr_t extAddr;
  /** The 64-bit unique identifier of the network to which the device belongs.*/
  ExtPanId_t extPanId;
  /** The tree depth of the neighbor device. */
  NwkDepth_t depth;
  /** The value identifying a snapshot of the network settings with which this
   * node is operating with.*/
  NwkUpdateId_t updateId;
  /** Indicates if neighbor's receiver is enabled during idle periods. */
  bool rxOnWhenIdle       :1;
  /** An indication of whether the device is accepting joining requests. */
  bool permitJoining      :1;
  /** An indication of whether the device has been
   * ruled out as a potential parent. */
  bool potentialParent    :1;
  /** Network address of the neighbor is conflict with other address in network.
   **/
  bool isAddressConflict  :1;
  /** Upper layer knowns about this child (true) or not (false).*/
  bool isKnownChild       :1;
  unsigned reserved1      :3;
} NwkNeighbor_t;

/** Type of life time of neighbors in ticks. */
typedef uint16_t NwkLifeTime_t;
/** The bit map of passive acks, each bit is matched to a broadcast that
 * waits passive acknowledgements. */
typedef uint8_t NwkPassiveAckMap_t;

/** Mutable fields of a entry in the neighbor table. */
typedef struct _NwkMutablePartOfNeighbor_t
{
  /** The time of life of a neighbor entry. */
  NwkLifeTime_t lifeTime;
  /** The estimated link quality for RF transmissions from this device. */
  Lqi_t lqi;
  Rssi_t rssi;
  /** The cost of an outgoing link as measured by the neighbor. */
  unsigned outgoingCost  :3;
  /** The cost of an incoming link as measured by this device. */
  unsigned incomingCost  :3;
  /** Does the lqi field (and incomingCost) have a valid value. */
  unsigned isLqiUnInit   :1;
  unsigned reserved1     :1;
#if defined _NWK_PASSIVE_ACK_
  NwkPassiveAckMap_t passiveAckMap;
#endif /* _NWK_PASSIVE_ACK_ */
} NwkMutablePartOfNeighbor_t;

/** Type of size of the neighbor table. */
typedef uint8_t NwkSizeOfNeighborTable_t;

/** Type of the neighbor table. */
typedef struct _NwkNeighborTable_t
{
 /** The array of a neighbor entry. */
  NwkNeighbor_t *table;
  /** Pointer to memory area after last entry of the neighbor table. */
  NwkNeighbor_t *end;
  /** The array of a mutable neighbor entry. */
  NwkMutablePartOfNeighbor_t *mutableTable;
  /** Current size of the neighbor table. */
  NwkSizeOfNeighborTable_t size;
#if defined _ROUTER_ || defined _COORDINATOR_
  /** Timer for internal use. */
  HAL_AppTimer_t ageTimer;
#endif /* _ROUTER_ or _COORDINATOR_ */
} NwkNeighborTable_t;

/** For backward compatibility */
typedef NwkNeighbor_t Neib_t;
typedef NwkMutablePartOfNeighbor_t MutableNeib_t;
typedef NwkNeighborTable_t NeibTable_t;

/******************************************************************************
                               Prototypes section
 ******************************************************************************/
/**************************************************************************//**
  \brief Access function to the neighbor table.

  \return Pointer to the neighbor table.
 ******************************************************************************/
NwkNeighborTable_t* NWK_GetNeighborTable(void);

/**************************************************************************//**
  \brief Searching a neighbor entry by extended address.

  \param[in] extAddr - extended IEEE address of neighbor.
  \return NULL if no records found, or entry with extAddr otherwise
 ******************************************************************************/
NwkNeighbor_t* NWK_FindNeighborByExtAddr(const ExtAddr_t extAddr);

/**************************************************************************//**
  \brief Searching a neighbor entry by short address.

  \param[in] shortAddr - network address of neighbor.
  \return NULL if no records found, or entry with shortAddr otherwise
 ******************************************************************************/
NwkNeighbor_t* NWK_FindNeighborByShortAddr(const ShortAddr_t shortAddr);

/**************************************************************************//**
  \brief Remove a neighbor from the neighbor table with leave indication.

  \param[in] neighbor - pointer to a entry in the neighbor table.
  \param[in] cleanAddressMap - Remove records from address map if existed.
  \return None.
 ******************************************************************************/
void NWK_RemoveNeighbor(NwkNeighbor_t *const neighbor, bool cleanAddressMap);

/**************************************************************************//**
  \brief Link quality indication for given neighbor.

  \param[in] neighbor - pointer to a entry of neighbor in the neighbor table.
  \return LQI of received frames from a neighbor
 ******************************************************************************/
Lqi_t NWK_GetNeighborsLqi(NwkNeighbor_t const *const neighbor);

/**************************************************************************//**
  \brief RSSI for given neighbor.

  \param[in] neighbor - pointer to a entry of neighbor in the neighbor table.
  \return RSSI of received frames from a neighbor
 ******************************************************************************/
Rssi_t NWK_GetNeighborsRssi(NwkNeighbor_t const *const neighbor);

/**************************************************************************//**
  \brief Is given neighbor known child.

  \param[in] extAddr - extended address of child.
  \param[in] setKnownFlag - change the known flag to 'true' if this parameter
                              is equal 'true'.

  \return Current value of known flag.
 ******************************************************************************/
bool NWK_IsKnownChild(const ExtAddr_t extAddr, const bool setKnownFlag);

/**************************************************************************//**
  \brief Is given neighbor is child.

  \param[in] neighbor - pointer to a entry of neighbor in the neighbor table.

  \return True, given neighbor is child.; otherwise - false.
 ******************************************************************************/
INLINE bool NWK_IsChild(Neib_t const *const neighbor)
{
  return (RELATIONSHIP_CHILD == neighbor->relationship)
      || (RELATIONSHIP_UNAUTHENTICATED_CHILD == neighbor->relationship);
}

/**************************************************************************//**
  \brief Is given neighbor is unauthenticated child.

  \param[in] neighbor - pointer to a entry of neighbor in the neighbor table.

  \return True, given neighbor is unauthenticated child.; otherwise - false.
 ******************************************************************************/
INLINE bool NWK_IsUnauthenticatedChild(Neib_t const *const neighbor)
{
  return (RELATIONSHIP_UNAUTHENTICATED_CHILD == neighbor->relationship);
}

/**************************************************************************//**
  \brief Authenticate a child node.

  \param[in] extAddr - pointer to the extended address of child.
  \return None.
 ******************************************************************************/
bool NWK_AuthenticateNeighbor(const ExtAddr_t *const extAddr);

/*****************************************************************************
  \brief This function adds neighbor table record for a known neighbor.

  \param[in] nwkAddress - neighbor network address.
  \return None.
 *****************************************************************************/
void NWK_AddKnownNeighbor(const ShortAddr_t nwkAddress);

#endif /* _NWK_NEIGHBOR_H */
/** eof nwkNeighbor.h */