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

  \brief Internal interface of APS command transmission.

  \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:
    2011-02-19 Max Gekk - Created.
   Last change:
    $Id: apsCommand.h 17813 2011-07-04 14:11:12Z dloskutnikov $
 ******************************************************************************/
#if !defined _APS_COMMAND_H
#define _APS_COMMAND_H

/******************************************************************************
                                Includes section
 ******************************************************************************/
#include <nwk.h>
#include <apsCommon.h>
#include <apsFrames.h>

/******************************************************************************
                               Definitions section
 ******************************************************************************/
/** Returns pointer to command payload */
#define APS_GET_COMMAND_PAYLOAD(req) \
  ((req)->service.allocateReq.confirm.nwkDataReq->nsdu)
/** Returns pointer to NWK_DataReq, associated with command */
#define APS_GET_ALLOCATED_COMMAND_BUFFER(req) \
  ((req)->service.allocateReq.confirm.nwkDataReq)
/** Returns command payload length */
#define APS_GET_COMMAND_PAYLOAD_LENGTH(req) \
  ((req)->service.allocateReq.nsduLength)

#ifdef _LINK_SECURITY_ 
/** APS command auxiliary header length */
#define APS_COMMAND_AUXILIARY_HEADER_LENGTH \
  (SSP_SECURITY_CONTROL_FIELD_LENGTH + SSP_FRAME_COUNTER_FIELD_LENGTH)
/** APS command security fields size */
#define APS_COMMAND_SECURITY_FIELDS_SIZE \
  (APS_COMMAND_AUXILIARY_HEADER_LENGTH + APS_MAX_DATA_FRAME_FOOTER_LENGTH)
#endif /* _LINK_SECURITY_ */


/******************************************************************************
                                 Types section
 ******************************************************************************/
/** Indicated command descriptor */
typedef struct _ApsCommandInd_t
{
  /** Pointer to first octet of unaligned source extended address. */
  const ExtAddr_t *srcExtAddr;
  /** Pointer to NLDE-DATA.indication parameters of the received command. */
  NWK_DataInd_t *nwkDataInd;
  /* Type of key with the received command was secured. */
  APS_Status_t securityStatus;
} ApsCommandInd_t;

/* Command identifier values are shown in Table 4.34 of ZigBee spec r19. */
typedef enum _ApsCommandId_t
{
  APS_CMD_MIN_ID              = 0x01,
  APS_CMD_SKKE_1_ID           = APS_CMD_MIN_ID,
  APS_CMD_SKKE_2_ID           = 0x02,
  APS_CMD_SKKE_3_ID           = 0x03,
  APS_CMD_SKKE_4_ID           = 0x04,
  APS_CMD_TRANSPORT_KEY_ID    = 0x05,
  APS_CMD_UPDATE_DEVICE_ID    = 0x06,
  APS_CMD_REMOVE_DEVICE_ID    = 0x07,
  APS_CMD_REQUEST_KEY_ID      = 0x08,
  APS_CMD_SWITCH_KEY_ID       = 0x09,
  APS_CMD_EA_INIT_CHLNG_ID    = 0x0a,
  APS_CMD_EA_RSP_CHLNG_ID     = 0x0b,
  APS_CMD_EA_INIT_MAC_DATA_ID = 0x0c,
  APS_CMD_EA_RSP_MAC_DATA_ID  = 0x0d,
  APS_CMD_TUNNEL_ID           = 0x0e,
  APS_CMD_MAX_ID              = APS_CMD_TUNNEL_ID
} ApsCommandId_t;

BEGIN_PACK
typedef struct PACK _ApduCommandBaseHeader_t
{
  ApduFrameControlField_t frameControl;
  uint8_t apsCounter;
} ApduCommandBaseHeader_t;

typedef struct PACK _ApduCommandHeader_t
{
  ApduFrameControlField_t frameControl;
  uint8_t apsCounter;
  uint8_t commandId;
} ApduCommandHeader_t;
END_PACK

/******************************************************************************
                               Prototypes section
 ******************************************************************************/
#if defined _SECURITY_
/**************************************************************************//**
  \brief Initialization of ApsCommandReq_t structure by default values.

   Following fields will be initialized:
    \li nwkSecurity and apsSecurity to true
    \li keyIdentifier to SSP_DATA_KEY_ID
    \li extendedNonce to false
    \li other fields to zero.

  \param[in] commandReq - pointer to request's parameters to APS command trasmission.
  \return None.
 ******************************************************************************/
APS_PRIVATE void apsSetCommandReqToDefault(ApsCommandReq_t *const commandReq);

/**************************************************************************//**
  \brief Module reset routine.

  \return None.
 ******************************************************************************/
APS_PRIVATE void apsCommandReset(void);

/**************************************************************************//**
  \brief Prepare command frame header.

  \param[out] header - pointer to memory to place header in.
  \param[in] commandId - command identifier.

  \return None.
 ******************************************************************************/
APS_PRIVATE
void apsCommandMakeHeader(ApduCommandHeader_t *header, ApsCommandId_t commandId);

/**************************************************************************//**
  \brief APS Command task handler.
 ******************************************************************************/
APS_PRIVATE void apsCommandReqTaskHandler(void);

/**************************************************************************//**
  \brief Request to allocate memory for APS command and send it.

  \param[in] commandReq - pointer to request's parameters to APS command trasmission.
  \return None.
 ******************************************************************************/
APS_PRIVATE void apsCommandReq(ApsCommandReq_t *const commandReq);

/**************************************************************************//**
  \brief Process an incoming command frame.

  \param[in] ind - pointer to NWK data indication structure.

  \return True, if memory buffer can be released; false - otherwise.
 ******************************************************************************/
APS_PRIVATE bool apsCommandInd(NWK_DataInd_t *ind);

/**************************************************************************//**
  \brief Handler of decrypted or unsecured incoming commands.

  \param[in] ind - pointer to data indication structure.
  \param[in] securityStatus - type of key with the transport key command
                              was secured.

  \return True, if memory buffer can be released; false - otherwise.
 ******************************************************************************/
bool apsUnsecuredNwkDataIndHandler(NWK_DataInd_t *const ind,
  const ExtAddr_t *srcExtAddr, const APS_Status_t securityStatus);

/**************************************************************************//**
  \brief Prepared command transmission routine.

  \param[in] req - command request pointer.

  \return None.
 ******************************************************************************/
APS_PRIVATE void apsCommandNwkDataReq(ApsCommandReq_t *const req);

#else
#define apsCommandReqTaskHandler NULL
#endif /* _SECURITY_ */
#endif /* _APS_COMMAND_H */
/** eof apsCommand.h */