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

  \brief Interface of the routing 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-11-15 Max Gekk - Created.
   Last change:
    $Id: nwkRoutingTable.h 17448 2011-06-09 13:53:59Z ataradov $
 ******************************************************************************/
#if !defined _NWK_ROUTING_TABLE_H
#define _NWK_ROUTING_TABLE_H

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

/******************************************************************************
                                Types section
 ******************************************************************************/
/** Type of routing table size. */
typedef uint8_t NwkRoutingTableSize_t;
/** Type of routing entry index. */
typedef NwkRoutingTableSize_t NwkRoutingEntryIndex_t;
/** Type of routing rate. */
typedef uint8_t NwkRoutingRate_t;

/** Routing table entry. ZigBee spec r17, Table 3.51. */
typedef struct _NwkRoutingTableEntry_t
{
  /** The 16-bit network address or Group ID of this route. If the destination
   * device is a ZigBee router, ZigBee coordinator, or an end device, and
   * nwkAddrAlloc has a value of 0x02, this field shall contain the actual
   * 16-bit address of that device. If the destination device is an end device
   * and nwkAddrAlloc has a value of 0x00, this field shall contain the 16-bit
   * network address of the device's parent. */
  ShortAddr_t dstAddr;
  /** The 16-bit network address of the next hop on the way to the destination.
   **/
  ShortAddr_t nextHopAddr;
  /** A flag indicating that the entry is active. */
  bool active              : 1;
  /** A flag indicating that the destination indicated by this address does
   * not store source routes. */
  bool noRouteCache        : 1;
  /** A flag indicating that the destination is a concentrator
   * that issued a many-to-one route request. */
  bool manyToOne           : 1;
  /** A flag indicating that a route record command frame should be sent to
   * the destination prior to the next data packet. */
  bool routeRecordRequired : 1;
  /** A flag indicating that the destination address is a Group ID. */
  bool groupId             : 1;
  /** Counter of the many-to-one discovery periods
   * without any source route packets. */
  NwkBitField_t noSourceRoutePeriods  : 2;
  /** Indicate to upper layer about new concentrator. */
  bool newConcentrator     : 1;
  NwkRoutingRate_t rate;
  /** Cost of route path to destination node. */
  NwkPathCost_t cost;
} NwkRoutingTableEntry_t;

/** The routing table. */
typedef struct _NwkRoutingTable_t
{
  /** Pointer to first entry of the routing table. */
  NwkRoutingTableEntry_t *table;
  /** Current size of the routing table. */
  NwkRoutingTableSize_t size;
  /* Number of failure transmission after that a routing entry will be deleted.
   **/
  uint8_t failOrder;
} NwkRoutingTable_t;

/******************************************************************************
                              Prototypes section
 ******************************************************************************/
#if defined NWK_ROUTING_CAPACITY \
  && (defined _NWK_MESH_ROUTING_ || defined _NWK_MANY_TO_ONE_ROUTING_)
/**************************************************************************//**
  \brief Allocate a new entry in the routing table.

  \return pointer to an entry or NULL.
 ******************************************************************************/
NWK_PRIVATE NwkRoutingTableEntry_t* nwkAllocRoutingEntry(void);

/**************************************************************************//**
  \brief Free the entry of the routing table.

  \param[in] dstAddr - a short address of destination node.
  \param[in] isGroupId - 'true' if dstAddr is group id otherwise 'false'.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkFreeRoutingEntry(const ShortAddr_t dstAddr,
  const bool isGroupId);

/**************************************************************************//**
  \brief Find a routing table entry by destination address.

  \param[in] dstAddr - a short address of destination node.
  \param[in] isGroupId - 'true' if dstAddr is group id otherwise 'false'.

  \return pointer to a routing table entry with given dstAddr.
 ******************************************************************************/
NWK_PRIVATE
NwkRoutingTableEntry_t* nwkFindRoutingEntry(const ShortAddr_t dstAddr,
  const bool isGroupId);

/******************************************************************************
 \brief Update information of the routing table entry after a packet transmission.

 \param[in] entry - pointer to an entry in the routing table.
 \param status - NWK status of packet transmission.
 ******************************************************************************/
NWK_PRIVATE void nwkUpdateRoutingEntry(NwkRoutingTableEntry_t *const entry,
  const NWK_Status_t status);

/**************************************************************************//**
  \brief Reset the routing table.
 ******************************************************************************/
NWK_PRIVATE void nwkResetRoutingTable(void);

#if defined _NWK_MESH_ROUTING_
/**************************************************************************//**
  \brief Setting the next hop address of the routing table entry.

  \param[in] dstAddr - a short address of destination node.
  \param[in] nextHopAddr - short address of next hop node.
  \param[in] isGroupId - 'true' if dstAddr is group id otherwise 'false'.
  \param[in] cost - cost of path to destination node.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkUpdateNextHop(const ShortAddr_t dstAddr,
  const bool isGroupId, const ShortAddr_t nextHopAddr,
  const NwkPathCost_t cost);

#else
#define nwkUpdateNextHop(dstAddr, isGroupId, nextHopAddr, cost) (void)0
#endif /* _NWK_MESH_ROUTING_ */
#else /* NWK_ROUTING_CAPACITY and (_NWK_MESH_ROUTING_ or _NWK_MANY_TO_ONE_ROUTING_) */

#define nwkResetRoutingTable() (void)0
#define nwkUpdateNextHop(dstAddr, isGroupId, nextHopAddr, cost) (void)0
#define nwkFreeRoutingEntry(dstAddr, isGroupId) (void)0

#endif /* NWK_ROUTING_CAPACITY and (_NWK_MESH_ROUTING_ or _NWK_MANY_TO_ONE_ROUTING_) */
#endif /* _NWK_ROUTING_TABLE_H */
/** eof nwkRoutingTable.h */