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

  \brief Interface of the route cache (route record 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:
    2010-03-15 M. Gekk - Created.
   Last change:
    $Id: nwkRouteCache.h 17448 2011-06-09 13:53:59Z ataradov $
 ******************************************************************************/
#if !defined _NWK_ROUTE_CACHE_H
#define _NWK_ROUTE_CACHE_H
/** See format of the route cache record in ZigBee spec r18, Table 3.45. */

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <nwkConfig.h>
#include <mac.h>
#include <nwkCommon.h>
#include <nwkRouteRecord.h>

/******************************************************************************
                                Types section
 ******************************************************************************/
/** Type of index in the route cache. */
typedef uint16_t NwkRouteCacheIndex_t;
/** Type of total size of the route cache. */
typedef NwkRouteCacheIndex_t NwkRouteCacheSize_t;
/** Type of the relay count field. Valid range 0-0xffff.
 * See Zigbee spec r18, Table 3.45. */
typedef uint16_t NwkRelayCount_t;

/** Format of a route cache record. ZigBee spec r18, page 350. */
typedef struct _NwkRouteCacheRecord_t
{
  /** The destination network address for this route record.*/
  ShortAddr_t dstAddr;
  /** The count of relay nodes from concentrator to the destination.
   * ZigBee spec r18, Table 3.45, page 350. */
  NwkRelayCount_t relayCount;
  /** The set of network addresses that represent the route in order from
   * the concentrator to the destination. ZigBee spec r18, Table 3.45. */
  ShortAddr_t path[NWK_MAX_SOURCE_ROUTE];
} NwkRouteCacheRecord_t;

/* Internal variables and state of the route cache. */
typedef struct _NwkRouteCache_t
{
  /* A set of cached route records. */
  NwkRouteCacheRecord_t *record;
  /* Total number of route records. */
  NwkRouteCacheSize_t size;
  /* The index of oldest route record. */
  NwkRouteCacheIndex_t current;
} NwkRouteCache_t;

/******************************************************************************
                               Prototypes section
 ******************************************************************************/
#if defined _NWK_ROUTE_CACHE_
/**************************************************************************//**
  \brief Find a record in the route cache by a destination address.

  \param[in] dstAddr - destination short address. Address must be valid.
  \return Pointer to a record of the route cache if it is found
          otherwise 'false'.
 ******************************************************************************/
NWK_PRIVATE
NwkRouteCacheRecord_t* nwkFindRouteRecord(const ShortAddr_t dstAddr);

/**************************************************************************//**
  \brief Add new record into the route cache.

  Preconditions:
    - Size of relay list must be less NWK_MAX_SOURCE_ROUTE.
    - Destination address must be valid (range 0x0000-0xFFF7).

  \param[in] dstAddr - destination short address of new route record.
  \param[in] routeRecordPayload - pointer to payload of a received route record
                                  command packet.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkAddRouteRecord(const ShortAddr_t dstAddr,
  const NwkRouteRecordPayload_t *const routeRecordPayload);

/**************************************************************************//**
  \brief Delete a record from the route cache.

  \param[in] dstAddr - destination short address for a route record.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkDeleteRouteRecord(const ShortAddr_t dstAddr);

/**************************************************************************//**
  \brief Reset the route cache.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkResetRouteCache(void);

#else /* _NWK_ROUTE_CACHE_ */

#define nwkResetRouteCache() (void)0

#endif /* _NWK_ROUTE_CACHE_ */
#endif /* _NWK_ROUTE_CACHE_H */
/** eof nwkRouteCache.h */