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

  \brief Interface of the route record functionality.

  \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-28 V. Panov - Created.
    2008-12-10 M. Gekk  - Memory optimization.
    2010-03-07 M. Gekk  - Redesign.
   Last change:
    $Id: nwkRouteRecord.h 18167 2011-08-08 11:26:31Z mgekk $
 ******************************************************************************/
/**//**
 *  The route record command allows the route taken by a unicast packet
 * through the network to be recorded in the command payload and delivered
 * to the destination device. ZigBee spec r18, 3.4.5, page 330.
 **/
#if !defined _NWK_ROUTE_RECORD_H
#define _NWK_ROUTE_RECORD_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <nwkConfig.h>
#include <queue.h>
#include <nwkCommon.h>
#include <nldeData.h>
#include <nwkFrame.h>

/******************************************************************************
                               Define(s) section
 ******************************************************************************/
#define NWK_ROUTE_RECORD_TX_PARAMETERS \
  {NWK_TX_DELAY_INITIAL_ROUTE_RECORD, nwkPrepareRouteRecordTx, \
   nwkConfirmRouteRecordTx, true}
#define NWK_ROUTE_RECORD_TRANSIT_TX_PARAMETERS \
  {NWK_TX_DELAY_UNICAST_COMMAND, nwkPrepareTransitRouteRecordTx, NULL, true}
#define NWK_IS_NOT_ROUTE_RECORD(outPkt) \
  ((NWK_ROUTE_RECORD_TX_ID != (outPkt)->txId) && \
   (NWK_ROUTE_RECORD_TRANSIT_TX_ID != (outPkt)->txId))  

/******************************************************************************
                                 Types section
 ******************************************************************************/
/** Route record command format. ZigBee spec r18, Figure 3.18, page 330. */
BEGIN_PACK
typedef struct PACK _NwkRouteRecordPayload_t
{
  /** The identifier of the route request command. */
  uint8_t commandId;
  /** This field contains the number of relays in the relay list field of
   * the route record command. ZigBee spec r18, 3.4.5.3.1, page 331. */
  uint8_t relayCount;
  /** The relay list field is a list of the 16-bit network addresses of the nodes
   * that have relayed the packet. ZigBee spec r18, 3.4.5.3.2, page 331. */
  ShortAddr_t relayList[NWK_MAX_SOURCE_ROUTE];
} NwkRouteRecordPayload_t;
END_PACK

/** Internal states of the route record component */
typedef enum _NwkRouteRecordState_t
{
  NWK_ROUTE_RECORD_IDLE_STATE = 0x2E,
  NWK_ROUTE_RECORD_FIRST_STATE = 0xF6,
  NWK_ROUTE_RECORD_BEGIN_STATE = NWK_ROUTE_RECORD_FIRST_STATE,
  NWK_ROUTE_RECORD_PREPARE_STATE = 0xF7,
  NWK_ROUTE_RECORD_SEND_STATE = 0xF8,
  NWK_ROUTE_RECORD_CONFIRM_STATE = 0xF9,
  NWK_ROUTE_RECORD_LAST_STATE
} NwkRouteRecordState_t;

/** Internal variables and state of the route record component. */
typedef struct _NwkRouteRecord_t
{
  QueueDescriptor_t queue; /**< Queue of requests from other NWK components. */
  NwkRouteRecordState_t state; /**< finite-state machine. */
} NwkRouteRecord_t;

/******************************************************************************
                               Prototypes section
 ******************************************************************************/
#if defined NWK_ROUTING_CAPACITY && defined _NWK_ROUTE_RECORD_
/**************************************************************************//**
  \brief Send the route record command before given output packet.

  \param[in] outPkt - pointer to output packet for which route record is sending.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkRouteRecordReq(NwkOutputPacket_t *const outPkt);

/**************************************************************************//**
  \brief Transmission of the route record command is done.

  \param[in] outPkt - pointer to output packet for which route record is sending.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkRouteRecordConf(NwkOutputPacket_t *const outPkt);

/**************************************************************************//**
  \brief Prepare header and payload of the route record command.

  \param outPkt - pointer to output packet.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkPrepareRouteRecordTx(NwkOutputPacket_t *const outPkt);

/**************************************************************************//**
  \brief Confirmation of the route record command transmission.

  \param outPkt - pointer to output packet.
  \param status - network status of route record transmission.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkConfirmRouteRecordTx(NwkOutputPacket_t *const outPkt,
  const NWK_Status_t status);

/**************************************************************************//**
  \brief Relay list of transit route record is changed.

  \param outPkt - pointer to output packet.
  \return None.
 ******************************************************************************/
NWK_PRIVATE
void nwkPrepareTransitRouteRecordTx(NwkOutputPacket_t *const outPkt);

/**************************************************************************//**
  \brief Reset the route record component.
 ******************************************************************************/
NWK_PRIVATE void nwkResetRouteRecord(void);

/**************************************************************************//**
  \brief Main task handler of the route record component.
 ******************************************************************************/
NWK_PRIVATE void nwkRouteRecordTaskHandler(void);

#else /* NWK_ROUTING_CAPACITY and _NWK_ROUTE_RECORD_ */

#define nwkPrepareRouteRecordTx NULL
#define nwkConfirmRouteRecordTx NULL
#define nwkPrepareTransitRouteRecordTx NULL
#define nwkResetRouteRecord() (void)0
#define nwkRouteRecordTaskHandler NULL

#endif /* NWK_ROUTING_CAPACITY and _NWK_ROUTE_RECORD_ */

#if defined NWK_ROUTING_CAPACITY && defined _NWK_ROUTE_CACHE_
/******************************************************************************
  \brief Action when a route record command is received.

  \param payload - pointer to raw command payload.
  \param header  - pointer to raw NWK header of command.
  \param parse   - parsed NWK header fields.
  \return 'true' if continue processing of command packet otherwise 'false'.
******************************************************************************/
NWK_PRIVATE bool nwkRouteRecordFrameInd(const uint8_t *const payload,
  const NwkFrameHeader_t *const header, const NwkParseHeader_t *const parse);

#else /* NWK_ROUTING_CAPACITY and _NWK_ROUTE_CACHE_*/
#define nwkRouteRecordFrameInd NULL
#endif /* NWK_ROUTING_CAPACITY and _NWK_ROUTE_CACHE_ */

#endif /* _NWK_ROUTE_RECORD_H */
/** eof nwkRouteRecord.h */