summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/Security/ServiceProvider/include/sspSfp.h
blob: ac53c27da2a1645efa96108249bba6b8c1859c63 (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
201
202
203
/**************************************************************************//**
  \file sspSfp.h

  \brief Security Frame Processor 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:
      2006 - VGribanovsky created.
      29/11/2007 - ALuzhetsky.
******************************************************************************/

#ifndef _SSPSFP_H
#define _SSPSFP_H

/******************************************************************************
                        Includes section.
******************************************************************************/
#include <types.h>
#include <macAddr.h>
#include <sspCommon.h>


/******************************************************************************
                        Definitions section.
******************************************************************************/
#define SSP_MAX_AUXILIARY_HEADER_LENGTH 14

/**************************************************************************//**
  \brief Possible key types.
******************************************************************************/
enum
{
  SSP_DATA_KEY_ID           = 0x00,
  SSP_NETWORK_KEY_ID        = 0x01,
  SSP_KEY_TRANSPORT_KEY_ID  = 0x02,
  SSP_KEY_LOAD_KEY_ID       = 0x03
};

/**************************************************************************//**
  \brief Possible levels of security.
******************************************************************************/
enum
{
  SSP_NONE_SECURITY_LEVEL        = 0x00,
  SSP_MIC_32_SECURITY_LEVEL      = 0x01,
  SSP_MIC_64_SECURITY_LEVEL      = 0x02,
  SSP_MIC_128_SECURITY_LEVEL     = 0x03,
  SSP_ENC_SECURITY_LEVEL         = 0x04,
  SSP_ENC_MIC_32_SECURITY_LEVEL  = 0x05,
  SSP_ENC_MIC_64_SECURITY_LEVEL  = 0x06,
  SSP_ENC_MIC_128_SECURITY_LEVEL = 0x07
};

/******************************************************************************
                        Types' definition section.
******************************************************************************/
/**************************************************************************//**
  \brief Confirm parameters of SSP_EncryptFrame.
******************************************************************************/
typedef struct
{
  //! Status of frame encoding.
  SSP_Status_t status;
} SSP_EncryptFrameConf_t;

typedef struct
{
  //! Status of frame encoding.
  SSP_Status_t status;

  //! Type of the used key.
  uint8_t keyIdentifier;
} SSP_DecryptFrameConf_t;

/**************************************************************************//**
  \brief Declaration of Encrypt Frame primitive's parameters structure.
******************************************************************************/
typedef struct
{
  //! Service field - for internal needs.
  SSP_Service_t service;
  //! The sequence number of active network key in nwkSecurityMaterialSet.
  uint8_t nwkActiveKeySeqNumber;
  //! The actual value of the key.
  const uint8_t *key/*[SECURITY_KEY_SIZE]*/;
  //! Identifies the type of the key which is used to protect the frame.
  uint8_t keyIdentifier;
  //! Outgoing frame counter used only for outgoing frames.
  uint32_t outFrameCounter;
  //! The security level for outgoing and incoming NWK and APS frames.
  uint8_t securityLevel;
  //! Detects whether the extended address is present in the nonce or not.
  bool extendedNoncePresent;
  //! Extended (64-bit) device address responsible for securing of the frame. Should always be presented.
  const ExtAddr_t *extAddr;
  //! Layer protocol data unit pointer. There is should be allocated memory for auxiliary header before pdu.
  uint8_t  *pdu/*[headerLength + payloadLength]*/;
  //! Length of the header.
  uint8_t  headerLength;
  //! Payload length.
  uint8_t  payloadLength;
  //! Security Service Provider SSP_EncryptFrame confirm parameters' structure.
  SSP_EncryptFrameConf_t confirm;
  //! Encrypt frame confirm callback function.
  void (*SSP_EncryptFrameConf)(SSP_EncryptFrameConf_t *conf);
} SSP_EncryptFrameReq_t;

/**************************************************************************//**
  \brief Declaration of Encrypt Frame primitive's parameters structure.
******************************************************************************/
typedef struct
{
  //! Service field - for internal needs.
  SSP_Service_t service;
  //! The actual value of the key.
  const uint8_t *key/*[SECURITY_KEY_SIZE]*/;
  //! The security level for outgoing and incoming NWK and APS frames.
  uint8_t securityLevel;
  //! Extended (64-bit) source device address.
  const ExtAddr_t *extAddr;
  //! Layer protocol data unit pointer.
  uint8_t *pdu;
  //! Length of the header.
  uint8_t headerLength;
  //! Payload length.
  uint8_t payloadLength;
  //! Enables a separate MIC check without payload decryption
  // Payload actually will be decrypted, but decryption results
  // will not overwrite original payload and they will be lost.
  bool onlyMicCheck;
  //! Encrypt frame confirm callback function.
  void (*SSP_DecryptFrameConf)(SSP_DecryptFrameConf_t *conf);
  //! Security Service Provider SSP_DecryptFrame confirm parameters' structure.
  SSP_DecryptFrameConf_t confirm;
} SSP_DecryptFrameReq_t;

/**************************************************************************//**
  \brief Declaration of Parse Auxiliary Header primitive's parameters structure.
******************************************************************************/
typedef struct
{
  //! Layer protocol data unit pointer - should be initialized by user.
  uint8_t  *pdu;
  //! Length of the header.
  uint8_t  headerLength;
  //! The sequence number of active network key in nwkSecurityMaterialSet.
  //! This parameter will be initialized during ParseAuxiliaryHeader function executing.
  uint8_t nwkActiveKeySeqNumber;
  //! Received frame counter.
  //! This parameter will be initialized during ParseAuxiliaryHeader function executing.
  u32Packed_t *receivedFrameCounter;
  //! Extended (64-bit) source device address.
  //! This parameter will be initialized during ParseAuxiliaryHeader function executing.
  u64Packed_t *sourceExtAddr;
  //! Identifies the type of the key which is used to protect the frame.
  uint8_t keyIdentifier;
  //! Extended nonce presented flag
  bool extendedNoncePresented;
} SSP_ParseAuxiliaryHeader_t;


/******************************************************************************
                        Functions' prototypes section.
******************************************************************************/
/**************************************************************************//**
  Performs frame encrypting based on incoming parameters.
  Parameters:
    param - encrypt frame procedure parameters (for detailed description look at
             SSP_EncryptFrameReq_t declaration).
  Return:
    none.
******************************************************************************/
void SSP_EncryptFrameReq(SSP_EncryptFrameReq_t *param);

/**************************************************************************//**
  Performs frame decrypting based on incoming parameters.
  Parameters:
    param - decrypt frame procedure parameters (for detailed description look at
             SSP_DecryptFrameReq_t declaration).
  Return:
    none.
******************************************************************************/
void SSP_DecryptFrameReq(SSP_DecryptFrameReq_t *param);

/**************************************************************************//**
  Extracts parameters from secured frame auxiliary header.
  Parameters:
    param - parse frame procedure parameters (for detailed description look at
             SSP_ParseAuxiliaryHeader_t declaration).
  Return:
    Auxiliary header length.
******************************************************************************/
uint8_t SSP_ParseAuxiliaryHeader(SSP_ParseAuxiliaryHeader_t *param);

#endif //_SSPSFP_H
// eof sspSfp.h