summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/NWK/include/private/nwkRouteDiscoveryTable.h
blob: c25509a2b256996d6092dca4c3d094bdff54f4e1 (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
/**************************************************************************//**
  \file nwkRouteDiscoveryTable.h

  \brief Interface of the route discovery 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:
    2007-09-17 V. Panov - Created.
    2010-02-04 M. Gekk  - Redesign.
   Last change:
    $Id: nwkRouteDiscoveryTable.h 17448 2011-06-09 13:53:59Z ataradov $
 ******************************************************************************/
/**//**
 *  A ZigBee router or ZigBee coordinator maintains a route discovery table
 * containing the information that is required during route discovery.
 **/
#if !defined _NWK_ROUTE_DISCOVERY_TABLE_H
#define _NWK_ROUTE_DISCOVERY_TABLE_H

/******************************************************************************
                                 Includes section
 ******************************************************************************/
#include <nwkConfig.h>
#include <nwkSystem.h>
#include <appFramework.h>
#include <appTimer.h>
#include <nwkCommon.h>
#include <nlmeRouteDiscovery.h>
#include <nwkPacket.h>

/******************************************************************************
                                 Define(s) section
 ******************************************************************************/
#define NWK_RDISC_IS_MANY_TO_ONE(routeDiscoveryEntry) \
  (NWK_DSTADDRMODE_NOADDR == (routeDiscoveryEntry)->dstAddrMode)
#define NWK_RDISC_IS_MULTICAST(routeDiscoveryEntry) \
  (NWK_DSTADDRMODE_MULTICAST == (routeDiscoveryEntry)->dstAddrMode)
#define NWK_RDISC_IS_UNICAST(routeDiscoveryEntry) \
  (NWK_DSTADDRMODE_SHORT == (routeDiscoveryEntry)->dstAddrMode)

/******************************************************************************
                                  Types section
 ******************************************************************************/
/** Route discovery table entry. See ZigBee spec r18, Table 3.53, page 391. */
typedef struct _NwkRouteDiscoveryEntry_t
{
  /** Time-to-live of entry. If this field is equal to 0 then entry is inactive.
   **/
  uint8_t ttl;
  /* For this entry route request transmission is required or not. */
  bool routeRequestRequired : 1;
  /** A flag indicating that route request is required on originator. */
  bool initialRouteRequest  : 1;
  /* For this entry route reply transmission is required or not. */
  bool routeReplyRequired   : 1;
  bool highPriority         : 1;
  /** A flag indicating that the concentrator does not store source routes. */
  bool noRouteCache         : 1;
  /* - NWK_DSTADDRMODE_NOADDR - this value indicating that the source node
   *     is a concentrator that issued a many-to-one route request.
   * - NWK_DSTADDRMODE_MULTICAST - the destination address is a Group ID.
   * - NWK_DSTADDRMODE_SHORT - unicast route discovery.
   * */
  NwkBitField_t dstAddrMode : 2;
  bool reserved             : 1;
  /** The accumulated path cost from the source of
   * the route request to the current device. */
  NwkPathCost_t forwardCost;
  /** The accumulated path cost from the current device
   * to the destination device. */
  NwkPathCost_t residualCost;
  /** The 16-bit network address of the route request's initiator. */
  ShortAddr_t srcAddr;
  /** The 16-bit network address of the device that has sent the most recent
   * lowest cost route request command frame corresponding to this entry's
   * route request identifier and source address. This field is used to
   * determine the path that an eventual route reply command frame should
   * follow. */
  ShortAddr_t senderAddr;
  /** Destination short address or group id of route discovery request. */
  ShortAddr_t dstAddr;
  /** A sequence number for a route request command frame that is incremented
   * each time a device initiates a route request. */
  NwkRouteRequestId_t routeRequestId;
  /** Current hop distance from originator of route descovery. */
  NwkRadius_t radius;
  /** Sequence number of initial route request command. */
  uint8_t sequenceNumber;
  /** Initial route request parameters. */
  NWK_RouteDiscoveryReq_t *req;
  /** Pointer to output network packet. */
  NwkOutputPacket_t *outPkt;
} NwkRouteDiscoveryEntry_t;

/** State of processing of incoming requests to send route request
 * or reply commands. */
typedef enum _NwkRouteDiscoveryTableState_t
{
  NWK_RDISC_TABLE_IDLE_STATE = 0x00,
  /** Preparing and sending of route reqply or request command. */
  NWK_RDISC_TABLE_REQUEST_PROCESSING_STATE = 0x93,
  /** Wating a free packet from the network packet manager. */
  NWK_RDISC_TABLE_WAIT_PACKET_STATE = 0x1A
} NwkRouteDiscoveryTableState_t;

/**
 * Route discovery table - a table used by a ZigBee coordinator or ZigBee router
 * to store temporary information used during route discovery.
 **/
typedef struct _NwkRouteDiscoveryTable_t
{
  /** The countdown timer that is used for decrement of time-to-live fields.*/
  HAL_AppTimer_t timer;
  /** Pointer to the route discovery table. */
  NwkRouteDiscoveryEntry_t *table;
  /** Pointer to memory area after last entry of the route discovery table. */
  NwkRouteDiscoveryEntry_t *end;
  /** Current state of the route discovery table. */
  NwkRouteDiscoveryTableState_t state;
  /** Boolean flag indicating that the countdown timer is started. */
  bool isTimerStarted;
} NwkRouteDiscoveryTable_t;

/******************************************************************************
                               Prototypes section
 ******************************************************************************/
#if defined NWK_ROUTING_CAPACITY \
  && (defined _NWK_MESH_ROUTING_ || defined _NWK_MANY_TO_ONE_ROUTING_)
/**************************************************************************//**
  \brief Allocate place for new discovery request in the route discovery table.

  \param[in] highPriority - if new entry is important
    then this parameter is 'true' otherwise 'false'.
  \return Pointer to an allocated route discovery entry or NULL.
 ******************************************************************************/
NWK_PRIVATE
NwkRouteDiscoveryEntry_t* nwkAllocRouteDiscoveryEntry(const bool highPriority);

/**************************************************************************//**
  \brief Find an active route discovery entry by route request id and source address.

  \param[in] srcAddr - network address of route discovery originator.
  \param[in] requestId - identifier of initial route request.
  \return Pointer to a route discovery entry or NULL if entry is not found.
 ******************************************************************************/
NWK_PRIVATE NwkRouteDiscoveryEntry_t* nwkFindRouteDiscoveryEntry(
  const ShortAddr_t srcAddr,
  const NwkRouteRequestId_t requestId);

/**************************************************************************//**
  \brief Main task handler of the NWK route discovery component.
 ******************************************************************************/
NWK_PRIVATE void nwkRouteDiscoveryTableTaskHandler(void);

/**************************************************************************//**
  \brief Indication about network packet realizing.
 ******************************************************************************/
NWK_PRIVATE void nwkRouteDiscoveryTableFreePacketInd(void);

/**************************************************************************//**
  \brief Reset internal state and entries of the route discovery table.
 ******************************************************************************/
NWK_PRIVATE void nwkResetRouteDiscoveryTable(void);

/**************************************************************************//**
  \brief Stop processing of route discovery entries.
 ******************************************************************************/
NWK_PRIVATE void nwkFlushRouteDiscoveryTable(void);

/**************************************************************************//**
  \brief Prepare and send the route request command.

  \param[in] entry - pointer to a route discovery entry that is required
    transmission of route request command.
  \param[in] isInitialRequest - 'true' if this node is originator
    of route discovery otherwise 'false'.
  \return None.
 ******************************************************************************/
NWK_PRIVATE
void nwkSendRouteDiscoveryRequest(NwkRouteDiscoveryEntry_t *const entry,
  const bool isInitialRequest);

/******************************************************************************
  \brief nwkRouteDiscoveryTable idle checking.

  \return true, if nwkRouteDiscoveryTable performs no activity, false - otherwise.
 ******************************************************************************/
NWK_PRIVATE bool nwkRouteDiscoveryTableIsIdle(void);

#if defined _NWK_MESH_ROUTING_
/**************************************************************************//**
  \brief Prepare and send the route reply command.

  \param[in] entry - pointer to a route discovery entry that is required
    transmission of route reply command.
  \return None.
 ******************************************************************************/
NWK_PRIVATE
void nwkSendRouteDiscoveryReply(NwkRouteDiscoveryEntry_t *const entry);
#endif /* _NWK_MESH_ROUTING_ */

/**************************************************************************//**
  \brief Reliably adding a path cost and a link cost.

  \param[in] pathCost - cost of path.
  \param[in] linkCost - cost of link.
  \return Summary path cost.
 ******************************************************************************/
NWK_PRIVATE NwkPathCost_t nwkSumPathCost(const NwkPathCost_t pathCost,
  const NwkLinkCost_t linkCost);

/**************************************************************************//**
  \brief Confirmation of the route request transmission.

  \param[in] outPkt - pointer to output packet.
  \param[in] status - network status of route request transmission.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkConfirmRouteRequestTx(NwkOutputPacket_t *const outPkt,
  const NWK_Status_t status);

#else /* NWK_ROUTING_CAPACITY and _NWK_MESH_ROUTING_ */

#define nwkRouteDiscoveryTableTaskHandler NULL
#define nwkConfirmRouteRequestTx NULL
#define nwkRouteDiscoveryTableIsIdle NULL
#define nwkResetRouteDiscoveryTable() (void)0
#define nwkRouteDiscoveryTableFreePacketInd() (void)0

#endif /* NWK_ROUTING_CAPACITY and (_NWK_MESH_ROUTING_ or _NWK_MANY_TO_ONE_ROUTING_) */
#endif /* _NWK_ROUTE_DISCOVERY_TABLE_H */
/* eof nwkRouteDiscoveryTable.h */