summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/NWK/include/private/nwkNeighborTable.h
blob: 7c7c61799f2d0acb5321376c522eee71ad594f1a (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/**************************************************************************//**
  \file nwkNeighborTable.h

  \brief Interface of the neighbor table..

  \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-05-12 M. Gekk - Created.
   Last change:
    $Id: nwkNeighborTable.h 18296 2011-08-19 12:29:05Z mgekk $
 ******************************************************************************/
#if !defined _NWK_NEIGHBOR_TABLE_H
#define _NWK_NEIGHBOR_TABLE_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <mac.h>
#include <nwkNeighbor.h>
#include <nwkMem.h>

/******************************************************************************
                               Define(s) section
 ******************************************************************************/
#define IS_EMPTY(ntEntry) (RELATIONSHIP_EMPTY == ntEntry->relationship)
#define IS_AUTHENTICATED_CHILD(ntEntry) \
   (RELATIONSHIP_CHILD == ntEntry->relationship)
#define IS_UNAUTHENTICATED_CHILD(ntEntry) \
   (RELATIONSHIP_UNAUTHENTICATED_CHILD == ntEntry->relationship)
#define IS_END_DEVICE(ntEntry) \
   (DEVICE_TYPE_END_DEVICE == ntEntry->deviceType)
#define IS_CHILD(ntEntry) \
   (IS_AUTHENTICATED_CHILD(ntEntry) || IS_UNAUTHENTICATED_CHILD(ntEntry))
#define IS_PARENT(ntEntry) (RELATIONSHIP_PARENT == ntEntry->relationship)
#define IS_RX_ON_WHEN_IDLE(ntEntry) (ntEntry->rxOnWhenIdle)
#define FREE_NEIGHBOR(neighbor) neighbor->relationship = RELATIONSHIP_EMPTY
/** Getting mutable part of neighbor entry. */
#define MUTABLE_PART(neighbor) nwkMutablePart(nwkMemNeighborTable(), neighbor)
/** Minimum value of a cost metric. */
#define NWK_MIN_LINK_COST 1

/******************************************************************************
                 Inline static functions prototypes section
 ******************************************************************************/
/**************************************************************************//**
  \brief First entry of the neighbor table.
 ******************************************************************************/
INLINE NwkNeighbor_t* nwkNtBegin(void)
{
  return nwkMemNeighborTable()->table;
}

/**************************************************************************//**
  \brief Function returns a pointer to memory area after last entry of the
    neighbor table.
 ******************************************************************************/
INLINE NwkNeighbor_t* nwkNtEnd(void)
{
  return nwkMemNeighborTable()->end;
}

/**************************************************************************//**
  \brief Function return a total size of the neighbor table.
 ******************************************************************************/
INLINE NwkSizeOfNeighborTable_t nwkNtSize(void)
{
  return nwkMemNeighborTable()->size;
}

/**************************************************************************//**
  \brief Getting the mutable part of given neighbor entry.
 ******************************************************************************/
INLINE NwkMutablePartOfNeighbor_t* nwkMutablePart(
  NwkNeighborTable_t const *const neighborTable,
  NwkNeighbor_t const *const neighbor)
{
  return neighborTable->mutableTable + (neighbor - neighborTable->table);
}

/******************************************************************************
                              Prototypes section
 ******************************************************************************/
/**************************************************************************//**
  \brief Reset the neighbor table.

  \param[in] powerFailureControl - stack restoring after power failure control bitfield;
                                  affects on initialization procedure.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkResetNeighborTable(NWK_PowerFailureControl_t powerFailureControl);

/**************************************************************************//**
  \brief Clear all entries in the neighbor table.

  \param[in] removeParent - remove parent's entry.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkClearNeighborTable(const bool removeParent);

/**************************************************************************//**
  \brief Free a entry in the neighbor table.

  \param[in] neighbor - pointer to a neighbor.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkFreeNeighbor(NwkNeighbor_t *const neighbor);

/**************************************************************************//**
  \brief Update of time of a life of the neighbor.

  \param[in] neighbor - pointer to a neighbor.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkSetLifeTimeOfNeighbor(NwkNeighbor_t *const neighbor);

#if defined NWK_ROUTING_CAPACITY && defined _NWK_MESH_ROUTING_
/**************************************************************************//**
  \brief Checking of that the given device is destination node for the
    short address.

  \param[in] shortAddr - unicast or multicast short address.
  \param[in] group - if 'true' then shortAddress is a multicast address.
  \return 'true' if this node is destination else 'false'.
 ******************************************************************************/
NWK_PRIVATE bool nwkIsRouteDestination(const ShortAddr_t shortAddr,
  const bool group);
#endif /* NWK_ROUTING_CAPACITY and _NWK_MESH_ROUTING_ */

/**************************************************************************//**
  \brief Calculate an incoming cost by LQI.

  \param[in] lqi - link quality indicator.
  \return None.
 ******************************************************************************/
NWK_PRIVATE NwkPathCost_t nwkCostFromLqi(const Lqi_t lqi);

/**************************************************************************//**
  \brief Recalculation LQI and costs for the set neighbor.

  \param[in] neighbor - pointer to a neighbor
  \param[in] linkQuality - the link quality indicator of a received packet.
  \param[in] rssi - received signal strength indication.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkUpdateLqiAndCostOfNeighbor(NwkNeighbor_t *const neighbor,
  const Lqi_t linkQuality, const Rssi_t rssi);

/**************************************************************************//**
  \brief Recalculation LQI and costs for a neighbor with given short address.

  \param[in] addr - short address of a neighbor.
  \param[in] linkQuality - the link quality indicator of a received packet.
  \param[in] rssi - received signal strength indication.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkUpdateLqiAndLifeTime(const ShortAddr_t addr,
  const Lqi_t linkQuality, const Rssi_t rssi);

/**************************************************************************//**
  \brief Is there a free place in the neighbor table.

  \param endDeviceCount - current number of end device children.
  \param routerCount - current number of router children.

  \return 'true' if the neighbor table is full otherwise return 'false'.
 ******************************************************************************/
NWK_PRIVATE bool nwkIsNeighborTableFull(const NwkChildCount_t endDeviceCount,
  const NwkChildCount_t routerCount);

/**************************************************************************//**
  \brief Gets value for the end device capacity bit in the beacon payload.

  \param endDeviceCount - current number of end device children.

  \return 1U if a end device can rejoin to this device otherwise return 0U.
 ******************************************************************************/
NWK_PRIVATE uint8_t nwkGetEdCapacity(const NwkChildCount_t endDeviceCount);

/**************************************************************************//**
  \brief Gets value for the router capacity bit in the beacon payload.

  \param routerCount - current number of router children.

  \return 1U if a router can rejoin to this device otherwise return 0U.
 ******************************************************************************/
NWK_PRIVATE uint8_t nwkGetRouterCapacity(const NwkChildCount_t routerCount);

/**************************************************************************//**
  \brief Calculation of quantity of children and updating of capacity bits.
 ******************************************************************************/
NWK_PRIVATE void nwkUpdateCapacityBitsInBeacon(void);

/**************************************************************************//**
  \brief Updating capacity bits in beacon by end devices and routers count.

  \param[in] endDeviceCount - current number of end device children.
  \param[in] routerCount - current number of router children.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkUpdateCapacityBits(const NwkChildCount_t endDeviceCount,
  const NwkChildCount_t routerCount);

#if defined _RESOLVE_ADDR_CONFLICT_
/******************************************************************************
  \brief Find a neighbor with address conflict.

    This function reset the conflict flag.

  \return Pointer to neighbor's entry in the neighbor table.
******************************************************************************/
NWK_PRIVATE NwkNeighbor_t* nwkFindAddrConflictNeighbor(void);

#if defined _ROUTER_ || defined _COORDINATOR_
/******************************************************************************
  \brief Find a end device child with given short address.

  \param[in] shortAddr - short address of end device child.
  \return Pointer to neighbor's entry in the neighbor table.
******************************************************************************/
NWK_PRIVATE NwkNeighbor_t* nwkFindEndDeviceChild(const ShortAddr_t shortAddr);
#endif /* _ROUTER_ or _COORDINATOR_ */
#endif /* _RESOLVE_ADDR_CONFLICT_ */

#if defined _ROUTER_ || defined _COORDINATOR_
/**************************************************************************//**
  \brief Start the age timer of the neighbor table.
 ******************************************************************************/
NWK_PRIVATE void nwkStartAgeTimerOfNeighborTable(void);

/**************************************************************************//**
  \brief Stop the age timer of the neighbor table.
 ******************************************************************************/
NWK_PRIVATE void nwkStopAgeTimerOfNeighborTable(void);

/**************************************************************************//**
  \brief Search of the following child after given with a flag rxOnWhenIdle
    in 'false' and that can take indirect packet.

  \param[in] neighbor - the neighbor with which search should begin.
  \param[in] exceptShortAddr - the address of the child which should be passed.
  \return Pointer to sleeping child's entry in the neighbor table.
 ******************************************************************************/
NWK_PRIVATE NwkNeighbor_t* nwkNextSleepingChildForIndirectTx(
  NwkNeighbor_t* neighbor, const ShortAddr_t exceptShortAddr);

#else
#define nwkStartAgeTimerOfNeighborTable() (void)0
#define nwkStopAgeTimerOfNeighborTable() (void)0

#endif /* _ROUTER_ or _COORDINATOR_ */

#endif /* _NWK_NEIGHBOR_TABLE_H */
/** eof nwkNeighborTable.h */