summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/NWK/include/private/nwkJoinReq.h
blob: d9875567b140ead4f870fae29939a244122e9e39 (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 nwkJoinReq.h

  \brief Join request 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-14 S. Vladykin - Created.
    2008-12-10 M. Gekk     - Optimization of NWK memory.
    2009-02-09 M. Gekk     - Refactoring.
   Last change:
    $Id: nwkJoinReq.h 17448 2011-06-09 13:53:59Z ataradov $
******************************************************************************/
#if !defined _NWK_JOINREQ_H
#define _NWK_JOINREQ_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <nwkConfig.h>
#include <queue.h>
#include <mac.h>
#include <nlmeJoin.h>
#include <nldeData.h>
#include <nlmeNetworkDiscovery.h>
#include <nwkNeighbor.h>
#include <nwkFrame.h>
#include <appTimer.h>
#include <nwkAddress.h>

/******************************************************************************
                               Define(s) section
 ******************************************************************************/
#define NWK_JOIN_REQ_TX_PARAMETERS \
  {NWK_TX_DELAY_UNICAST_COMMAND, nwkPrepareJoinReqTx, nwkConfirmJoinReqTx, true}

/******************************************************************************
                                 Types section
 ******************************************************************************/
/** Internal states of the join request component. */
typedef enum _NwkJoinReqState_t
{
   JOIN_REQ_IDLE_STATE = 0xDA,
   JOIN_REQ_FIRST_STATE = 0x21,
   JOIN_REQ_GET_ELEM_FROM_QUEUE = JOIN_REQ_FIRST_STATE,
   JOIN_REQ_CONFIRM_STATE = 0x22,
   JOIN_REQ_ASSOCIATION_WAIT_STATE = 0x23,
   JOIN_REQ_SET_BEACON_PAYLOAD_STATE = 0x24,
   JOIN_REQ_SET_BEACON_PAYLOAD_LEN_STATE = 0x25,
   JOIN_REQ_SET_RX_ON_WHEN_IDLE_STATE = 0x26,
   JOIN_REQ_RX_ENABLE_STATE = 0x27,
   JOIN_REQ_PKT_PREPARE_AND_SEND_STATE = 0x28,
   JOIN_REQ_SET_PANID_STATE = 0x29,
   JOIN_REQ_SET_CHANNEL_STATE = 0x2A,
   JOIN_REQ_GET_RESPONSE_WAIT_TIME_STATE = 0x2B,
   JOIN_REQ_WAIT_REJOIN_RESPONSE_DECRYPT = 0x2C,
   JOIN_REQ_REJOIN_RESPONSE_WAITING_STATE = 0x2D,
   JOIN_REQ_SET_SHORT_ADDRESS_STATE = 0x2E,
   JOIN_REQ_SET_COORD_SHORT_ADDR_STATE = 0x2F,
   JOIN_REQ_SET_COORD_EXT_ADDR_STATE = 0x30,
   JOIN_REQ_SET_SHORT_ADDRESS_ONLY_STATE = 0x31,
   JOIN_REQ_NETWORK_DISCOVERY_STATE = 0x32,
   JOIN_REQ_SET_FIRST_SHORT_ADDRESS_STATE = 0x33,
   JOIN_REQ_SET_TRANSACTION_TIME_STATE = 0x34,
   JOIN_REQ_LAST_STATE
} NwkJoinReqState_t;

/** Format of rejoin command payload. ZigBee spec r17, 3.4.6.3, page 329. */
/** The NWK frame payload contains a command identifier field and a capability
 * information field. The command frame identifier shall contain the value
 * indicating a rejoin request command frame. */
BEGIN_PACK
typedef struct PACK
{
  NwkCommandIdField_t commandId;
  /** This one-octet field has the format of the capability information field
   * in the association request command. ZigBee spec r17, 3.4.6.3.1, page 329. */
  MAC_CapabilityInf_t capability;
} NwkRejoinReqCmd_t;
END_PACK

/** Internal parameters of the join request component. */
typedef struct _NwkJoinReq_t
{
  NwkJoinReqState_t state;
  QueueDescriptor_t queue;
  NWK_JoinReq_t *joinReq;
  NwkNeighbor_t *currentCandidateRouter;
  uint8_t attempNum;
  HAL_AppTimer_t timer;
  MAC_PollReq_t pollReq;
  union
  {
    MAC_AssociateReq_t macAssoc;
    MAC_SetReq_t macSet;
    MAC_GetReq_t macGet;
    MAC_RxEnableReq_t macRxEnable;
    NWK_NetworkDiscoveryReq_t netDisc;
  } req;
} NwkJoinReq_t;

/******************************************************************************
                             Prototypes section
 ******************************************************************************/
#if defined _ROUTER_ || defined _ENDDEVICE_
/**************************************************************************//**
  \brief Action when command received.

  \param[in] payload - a payload of network join request command.
  \param[in] header - pointer to raw NWK header.
  \param[in] parse - parsed header fields.

  \return 'true' if continue processing of command packet otherwise 'false'.
 ******************************************************************************/
NWK_PRIVATE bool nwkRejoinResponseFrameInd(const uint8_t *const payload,
  const NwkFrameHeader_t *const header, const NwkParseHeader_t *const parse);

/**************************************************************************//**
  \brief Reset the join request component
 ******************************************************************************/
NWK_PRIVATE void nwkResetJoinReq(void);

/**************************************************************************//**
  \brief Task handler of NWK join request component.
 ******************************************************************************/
NWK_PRIVATE void nwkJoinReqTaskHandler(void);

/**************************************************************************//**
  \brief Prepare header and payload of the join request command.

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

/**************************************************************************//**
  \brief Confirmation of join request command transmission.

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

/******************************************************************************
  \brief nwkJoinReq idle checking.

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

#else /* _ROUTER_ or _ENDDEVICE_ */

#define nwkRejoinResponseFrameInd NULL
#define nwkResetJoinReq() (void)0
#define nwkJoinReqTaskHandler NULL
#define nwkPrepareJoinReqTx NULL
#define nwkConfirmJoinReqTx NULL
#define nwkJoinReqIsIdle NULL

#endif /* _ROUTER_ or _ENDDEVICE_ */
#endif /* _NWK_JOINREQ_H */
/** eof nwkJoinReq.h */