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

  \brief Network leave header file.

  \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-06-27 V. Panov - Created.
    2009-05-26 M. Gekk  - Refactoring.
   Last change:
    $Id: nwkLeave.h 18970 2011-10-21 12:48:41Z mgekk $
******************************************************************************/
#if !defined _NWK_LEAVE_H
#define _NWK_LEAVE_H

/******************************************************************************
                                Includes section
 ******************************************************************************/
#include <nwkConfig.h>
#include <queue.h>
#include <appFramework.h>
#include <mac.h>
#include <nwkNeighbor.h>
#include <nwkFrame.h>
#include <nldeData.h>
#include <nlmeLeave.h>

/******************************************************************************
                               Definitions section
 ******************************************************************************/
/** Size of NWK leave command payload. */
#define NWK_LEAVE_CMD_PAYLOAD_SIZE 2U
/** Total size of self leave command - NWK header + payload */
#define NWK_LEAVE_ITSELF_CMD_SIZE 18U
/** Total size of child leave command - NWK header + payload */
#define NWK_LEAVE_CHILD_CMD_SIZE 26U
/** Parameters of leave command transmission. */
#define NWK_LEAVE_ITSELF_TX_PARAMETERS \
  {NWK_TX_DELAY_BROADCAST, nwkPrepareLeaveItselfTx,\
   nwkConfirmLeaveItselfTx, true}
#define NWK_LEAVE_CHILD_TX_PARAMETERS \
  {NWK_TX_DELAY_UNICAST_COMMAND, nwkPrepareLeaveChildTx,\
   nwkConfirmLeaveChildTx, true}

/******************************************************************************
                                  Types section
 ******************************************************************************/
/** Internal states of NLME-LEAVE component */
typedef enum _NwkLeaveState_t
{
  NWK_LEAVE_IDLE_STATE = 0xE6,
  NWK_LEAVE_FIRST_STATE = 0x11,
  NWK_LEAVE_BEGIN_STATE = NWK_LEAVE_FIRST_STATE,
  NWK_LEAVE_SELF_SEND_CMD_STATE = 0x12,
  NWK_LEAVE_SELF_WAIT_CONFIRM_STATE = 0x13,
  NWK_LEAVE_SELF_RESET_MAC_STATE = 0x14,
  NWK_LEAVE_CHILD_SEND_CMD_STATE = 0x15,
  NWK_LEAVE_CHILD_WAIT_CONFIRM_STATE = 0x16,
  NWK_LEAVE_CONFIRM_STATE = 0x17,
  NWK_LEAVE_LAST_STATE
} NwkLeaveState_t;

/** Leave Command Options Field */
typedef enum _NwkLeaveCommandOptionsField_t
{
  /** The Rejoin sub-field is a single-bit field. If the value of this
   * sub-field is 1, the device that is leaving from its current parent
   * will rejoin the network. If the value of this sub-field is 0, the device
   * will not rejoin the network. ZigBee spec r17, 3.4.4.3.1.1, page 325. */
  NWK_LEAVE_REJOIN          = 0x20,
  /** The request sub-field is a single-bit field. If the value of this
   * sub-field is 1, then the leave command frame is a request for another
   * device to leave the network. If the value of this sub-field is 0,
   * then the leave command frame is an indication that the sending device
   * plans to leave the network. ZigBee spec r17, 3.4.4.3.1.2, page 326. */
  NWK_LEAVE_REQUEST         = 0x40,
  /** The remove children sub-field is a single-bit field. If this sub-field
   * has a value of 1, then the children of the device that is leaving
   * the network will also be removed. If this sub-field has a value of 0,
   * then the children of the device leaving the network will not be removed.
   * ZigBee spec r17, 3.4.4.3.1.3, page 326. */
  NWK_LEAVE_REMOVE_CHILDREN = 0x80
} NwkLeaveCommandOptionsField_t;

/** Internal variables of NLME-LEAVE component. */
typedef struct _NwkLeave_t
{
  /** Finite-state machine */
  NwkLeaveState_t state;
  /** Queue of requests from upper layer */
  QueueDescriptor_t queue;
  /** Number of children which has been excluded from a network. */
  NwkSizeOfNeighborTable_t leaveChildCount;
  union
  {
    /** MLME-RESET request primitive's parameters. */
    MAC_ResetReq_t macReset;
    struct
    {
      /** The short address of the leaved child. */
      ShortAddr_t shortAddr;
      /** The extended address of the leaved child. */
      ExtAddr_t extAddr;
      /** The bits indicate the transmission options for the MAC frame. */
      MAC_TxOptions_t txOptions;
    } child;
  } param;
#if defined _ROUTER_ && defined _NWK_DISTRIBUTED_ADDRESSING_
  /** The leave indication component is busy or not. */
  bool leaveIndBusy;
  /** Leave request which is used by the leave indication component. */
  NWK_LeaveReq_t leaveReq;
#endif /* _ROUTER_ and _NWK_DISTRIBUTED_ADDRESSING_ */
} NwkLeave_t;

/******************************************************************************
                              Prototypes section
 ******************************************************************************/
/**************************************************************************//**
  \brief Main task handler of NLME-LEAVE component
 ******************************************************************************/
NWK_PRIVATE void nwkLeaveTaskHandler(void);

/**************************************************************************//**
  \brief Reset NLME-LEAVE component
 ******************************************************************************/
NWK_PRIVATE void nwkResetLeave(void);

/**************************************************************************//**
  \brief Action when a leave command is received.

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

/**************************************************************************//**
  \brief Prepare header and payload of the leave itself command.

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

/**************************************************************************//**
  \brief Confirmation of the leave itself command transmission.

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

#if defined _ROUTER_ || defined _COORDINATOR_
/**************************************************************************//**
  \brief Prepare header and payload of the leave child command.

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

/**************************************************************************//**
  \brief Confirmation of the leave child command transmission.

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

/******************************************************************************
  \brief nwkLeaveReq idle checking.

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

#else /* _ROUTER_ or _COORDINATOR_ */

#define nwkPrepareLeaveChildTx NULL
#define nwkConfirmLeaveChildTx NULL
#define nwkLeaveReqIsIdle      NULL

#endif /* _ROUTER_ or _COORDINATOR_ */
#endif /* _NWK_LEAVE_H */
/** eof nwkLeave.h */