XCORE SDK
XCORE Software Development Kit
sl_wfx_constants.h
1 /**************************************************************************/
17 #ifndef SL_WFX_CONSTANTS_H
18 #define SL_WFX_CONSTANTS_H
19 
20 #include "sl_wfx_configuration_defaults.h"
21 #include "sl_status.h"
22 #include "sl_wfx_api.h"
23 #include <stdint.h>
24 
25 /******************************************************
26 * Macros
27 ******************************************************/
28 
29 #define SL_WFX_UNUSED_VARIABLE(x) (void)(x)
30 #define SL_WFX_UNUSED_PARAMETER(x) (void)(x)
31 
32 #ifndef SL_WFX_ARRAY_COUNT
33 #define SL_WFX_ARRAY_COUNT(x) (sizeof (x) / sizeof *(x))
34 #endif /* ifndef SL_WFX_ARRAY_COUNT */
35 
36 #ifndef SL_WFX_ROUND_UP
37 #define SL_WFX_ROUND_UP(x, y) ((x) % (y) ? (x) + (y) - ((x) % (y)) : (x))
38 #endif /* ifndef SL_WFX_ROUND_UP */
39 
40 #ifndef SL_WFX_ROUND_UP_EVEN
41 #define SL_WFX_ROUND_UP_EVEN(x) ((x) + ((x) & 1))
42 #endif /* ifndef SL_WFX_ROUND_UP_EVEN */
43 
44 #define SL_WAIT_FOREVER 0xFFFFFFFF
45 
46 #define SL_WFX_ERROR_CHECK(__status__) \
47  do { \
48  if (((sl_status_t)__status__) != SL_STATUS_OK) { \
49  goto error_handler; \
50  } \
51  } while (0)
52 
53 // little endian has Least Significant Byte First
54 #define sl_wfx_pack_32bit_little_endian(_ptr_, _val_) do { \
55  *((uint8_t *)(_ptr_) ) = ((_val_) & 0x000000FF); \
56  *((uint8_t *)(_ptr_) + 1) = ((_val_) & 0x0000FF00) >> 8; \
57  *((uint8_t *)(_ptr_) + 2) = ((_val_) & 0x00FF0000) >> 16; \
58  *((uint8_t *)(_ptr_) + 3) = ((_val_) & 0xFF000000) >> 24; \
59 } while (0)
60 
61 #define sl_wfx_unpack_32bit_little_endian(_ptr_) \
62  (((uint32_t)(*((uint8_t *)(_ptr_) ))) \
63  | ((uint32_t)(*((uint8_t *)(_ptr_) + 1))) << 8 \
64  | ((uint32_t)(*((uint8_t *)(_ptr_) + 2))) << 16 \
65  | ((uint32_t)(*((uint8_t *)(_ptr_) + 3))) << 24)
66 
67 #define sl_wfx_pack_24bit_little_endian(_ptr_, _val_) do { \
68  *((uint8_t *)(_ptr_) ) = ((_val_) & 0x000000FF); \
69  *((uint8_t *)(_ptr_) + 1) = ((_val_) & 0x0000FF00) >> 8; \
70  *((uint8_t *)(_ptr_) + 2) = ((_val_) & 0x00FF0000) >> 16; \
71 } while (0)
72 
73 #define sl_wfx_unpack_24bit_little_endian(_ptr_) \
74  (((uint32_t)(*((uint8_t *)(_ptr_) ))) \
75  | ((uint32_t)(*((uint8_t *)(_ptr_) + 1))) << 8 \
76  | ((uint32_t)(*((uint8_t *)(_ptr_) + 2))) << 16)
77 
78 #define sl_wfx_pack_16bit_little_endian(_ptr_, _val_) do { \
79  *((uint8_t *)(_ptr_) ) = ((_val_) & 0x000000FF); \
80  *((uint8_t *)(_ptr_) + 1) = ((_val_) & 0x0000FF00) >> 8; \
81 } while (0)
82 
83 #define sl_wfx_unpack_16bit_little_endian(_ptr_) \
84  (((uint32_t)(*((uint8_t *)(_ptr_) ))) \
85  | ((uint32_t)(*((uint8_t *)(_ptr_) + 1))) << 8)
86 
87 // big endian has Most Significant Byte First
88 #define sl_wfx_pack_32bit_big_endian(_ptr_, _val_) do { \
89  *((uint8_t *)(_ptr_) ) = ((_val_) & 0xFF000000) >> 24; \
90  *((uint8_t *)(_ptr_) + 1) = ((_val_) & 0x00FF0000) >> 16; \
91  *((uint8_t *)(_ptr_) + 2) = ((_val_) & 0x0000FF00) >> 8; \
92  *((uint8_t *)(_ptr_) + 3) = ((_val_) & 0x000000FF); \
93 } while (0)
94 
95 #define sl_wfx_unpack_32bit_big_endian(_ptr_) \
96  (((uint32_t)(*((uint8_t *)(_ptr_) ))) << 24 \
97  | ((uint32_t)(*((uint8_t *)(_ptr_) + 1))) << 16 \
98  | ((uint32_t)(*((uint8_t *)(_ptr_) + 2))) << 8 \
99  | ((uint32_t)(*((uint8_t *)(_ptr_) + 3))))
100 
101 #define sl_wfx_pack_24bit_big_endian(_ptr_, _val_) do { \
102  *((uint8_t *)(_ptr_) ) = ((_val_) & 0x00FF0000) >> 16; \
103  *((uint8_t *)(_ptr_) + 1) = ((_val_) & 0x0000FF00) >> 8; \
104  *((uint8_t *)(_ptr_) + 2) = ((_val_) & 0x000000FF); \
105 } while (0)
106 
107 #define sl_wfx_unpack_24bit_big_endian(_ptr_) \
108  (((uint32_t)(*((uint8_t *)(_ptr_) ))) << 16 \
109  | ((uint32_t)(*((uint8_t *)(_ptr_) + 1))) << 8 \
110  | ((uint32_t)(*((uint8_t *)(_ptr_) + 2))))
111 
112 #define sl_wfx_pack_16bit_big_endian(_ptr_, _val_) do { \
113  *((uint8_t *)(_ptr_) ) = ((_val_) & 0x0000FF00) >> 8; \
114  *((uint8_t *)(_ptr_) + 1) = ((_val_) & 0x000000FF); \
115 } while (0)
116 
117 #define sl_wfx_unpack_16bit_big_endian(_ptr_) \
118  (((uint16_t)(*((uint8_t *)(_ptr_) ))) << 8 \
119  | ((uint16_t)(*((uint8_t *)(_ptr_) + 1))))
120 
121 #define sl_wfx_unpack_8bit(_ptr_) \
122  ((uint8_t)(*((uint8_t *)(_ptr_))))
123 
124 #define sl_wfx_swap_16(x) ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
125 #define sl_wfx_swap_32(x) ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
126 
127 static inline uint16_t bswap_16(uint16_t bsx)
128 {
129  return sl_wfx_swap_16(bsx);
130 }
131 
132 static inline uint32_t bswap_32(uint32_t bsx)
133 {
134  return sl_wfx_swap_32(bsx);
135 }
136 
137 static inline uint16_t uint16_identity(uint16_t x)
138 {
139  return x;
140 }
141 
142 static inline uint32_t uint32_identity(uint32_t x)
143 {
144  return x;
145 }
146 
147 #ifdef SL_WFX_BIG_ENDIAN
148 #define sl_wfx_htobe16(x) uint16_identity(x)
149 #define sl_wfx_htole16(x) bswap_16(x)
150 #define sl_wfx_htobe32(x) uint32_identity(x)
151 #define sl_wfx_htole32(x) bswap_32(x)
152 #else
153 #define sl_wfx_htobe16(x) bswap_16(x)
154 #define sl_wfx_htole16(x) uint16_identity(x)
155 #define sl_wfx_htobe32(x) bswap_32(x)
156 #define sl_wfx_htole32(x) uint32_identity(x)
157 #endif
158 
159 /******************************************************
160 * Constants
161 ******************************************************/
162 
163 #define SL_WAIT_FOREVER 0xFFFFFFFF
164 
165 #define SL_WFX_ROUND_UP_VALUE SL_WFX_SDIO_BLOCK_SIZE
166 
167 #ifndef SL_WFX_DEBUG_MASK
168 #define SL_WFX_DEBUG_MASK 0x0000
169 #endif
170 
171 #define SL_WFX_DEBUG_ERROR 0x0001
172 #define SL_WFX_DEBUG_INIT 0x0002
173 #define SL_WFX_DEBUG_SLEEP 0x0004
174 #define SL_WFX_DEBUG_SLK 0x0008
175 #define SL_WFX_DEBUG_RX 0x0010
176 #define SL_WFX_DEBUG_RX_RAW 0x0020
177 #define SL_WFX_DEBUG_RX_REG 0x0040
178 #define SL_WFX_DEBUG_TX 0x0080
179 #define SL_WFX_DEBUG_TX_RAW 0x0100
180 #define SL_WFX_DEBUG_TX_REG 0x0200
181 #define SL_WFX_DEBUG_FW_LOAD 0x0400
182 
183 #define SL_WFX_PDS_KEY_A 'a'
184 #define SL_WFX_PDS_KEY_B 'b'
185 #define SL_WFX_PDS_KEY_C 'c'
186 #define SL_WFX_PDS_KEY_D 'd'
187 #define SL_WFX_PDS_KEY_E 'e'
188 #define SL_WFX_PDS_KEY_F 'f'
189 #define SL_WFX_PDS_ANTENNA_SEL_KEY 'j'
190 
191 #define SL_WFX_PTE_INFO 0x0900C0C0
192 #define SL_WFX_MSG_ID_GENERAL_API_MASK 0x20
193 #define SL_WFX_MSG_INFO_INTERFACE_OFFSET 1
194 #define SL_WFX_MSG_INFO_INTERFACE_MASK 0x06
195 #define SL_WFX_OPN_SIZE 14
196 
197 #ifdef SL_WFX_USE_SECURE_LINK
198 #define SL_WFX_MSG_INFO_SECURE_LINK_OFFSET 6
199 #define SL_WFX_MSG_INFO_SECURE_LINK_MASK 0xC0
200 /* Secure link constants*/
201 #define SL_WFX_SECURE_LINK_MAC_KEY_LENGTH 32
202 
203 #define SL_WFX_SECURE_LINK_SESSION_KEY_LENGTH (16)
204 
205 #define SL_WFX_SECURE_LINK_ENCRYPTION_BITMAP_SIZE (32)
206 #define SL_WFX_SECURE_LINK_ENCRYPTION_NOT_REQUIRED (0)
207 #define SL_WFX_SECURE_LINK_ENCRYPTION_REQUIRED (1)
208 
209 #define SL_WFX_SECURE_LINK_HEADER_SIZE (4)
210 #define SL_WFX_SECURE_LINK_CCM_TAG_SIZE (16)
211 #define SL_WFX_SECURE_LINK_NONCE_SIZE_BYTES (12)
212 #define SL_WFX_SECURE_LINK_NONCE_COUNTER_MAX (0x3FFFFFFFUL) // Top two bits are used to indicate which counter
213 #define SL_WFX_SECURE_LINK_OVERHEAD (SL_WFX_SECURE_LINK_HEADER_SIZE + SL_WFX_SECURE_LINK_CCM_TAG_SIZE)
214 
215 #define SL_WFX_SECURE_LINK_SESSION_KEY_BIT_COUNT (SL_WFX_SECURE_LINK_SESSION_KEY_LENGTH * 8)
216 
217 // Maximum nonce value is 2 ^ 30, watermark is chosen as 2 ^ 29
218 #define SL_WFX_SECURE_LINK_NONCE_MAX_VALUE 1 << 30
219 #define SL_WFX_SECURE_LINK_NONCE_WATERMARK 1 << 29
220 #endif //SL_WFX_USE_SECURE_LINK
221 
222 #define SL_WFX_ERROR_LOGS { \
223  { SL_WFX_ERROR_FIRMWARE_ROLLBACK, "Rollback error", 0 }, \
224  { SL_WFX_ERROR_DEPRECATED_0, "Not used anymore", 0 }, \
225  { SL_WFX_ERROR_DEPRECATED_1, "Not used anymore", 0 }, \
226  { SL_WFX_ERROR_INVALID_SESSION_KEY, "Session key is invalid", 0 }, \
227  { SL_WFX_ERROR_OOR_VOLTAGE, "Out-of-range power supply voltage", 4 }, \
228  { SL_WFX_ERROR_PDS_VERSION, "Wrong PDS version", 0 }, \
229  { SL_WFX_ERROR_OOR_TEMPERATURE, "Out-of-range temperature", 0 }, \
230  { SL_WFX_ERROR_REQ_DURING_KEY_EXCHANGE, "Requests from Host are forbidden until the end of key exchange", 0 }, \
231  { SL_WFX_ERROR_DEPRECATED_2, "Not used anymore", 0 }, \
232  { SL_WFX_ERROR_DEPRECATED_3, "Not used anymore", 0 }, \
233  { SL_WFX_ERROR_SECURELINK_DECRYPTION, "Error occured during message decryption", 0 }, \
234  { SL_WFX_ERROR_SECURELINK_WRONG_ENCRYPTION_STATE, "Encryption state of the received message doesn't match", 4 }, \
235  { SL_WFX_SPI_OR_SDIO_FREQ_TOO_LOW, "Bus clock is too slow (<1kHz)", 0 }, \
236  { SL_WFX_ERROR_DEPRECATED_4, "Not used anymore", 0 }, \
237  { SL_WFX_ERROR_DEPRECATED_5, "Not used anymore", 0 }, \
238  { SL_WFX_HIF_BUS_ERROR, "HIF HW has reported an error", 4 }, \
239  { SL_WFX_PDS_TESTFEATURE_MODE_ERROR, "Unknown TestFeatureMode", 0 } \
240 }
241 
242 /**************************************************************************/
247 /**************************************************************************/
251 typedef enum {
252  SL_WFX_CONFIG_REG_ID = 0x0000,
253  SL_WFX_CONTROL_REG_ID = 0x0001,
254  SL_WFX_IN_OUT_QUEUE_REG_ID = 0x0002,
255  SL_WFX_AHB_DPORT_REG_ID = 0x0003,
256  SL_WFX_SRAM_BASE_ADDR_REG_ID = 0x0004,
257  SL_WFX_SRAM_DPORT_REG_ID = 0x0005,
258  SL_WFX_TSET_GEN_R_W_REG_ID = 0x0006,
259  SL_WFX_FRAME_OUT_REG_ID = 0x0007,
261 
262 /**************************************************************************/
266 typedef enum {
267  SL_WFX_STARTED = (1 << 0),
268  SL_WFX_STA_INTERFACE_CONNECTED = (1 << 1),
269  SL_WFX_AP_INTERFACE_UP = (1 << 2),
270  SL_WFX_SLEEPING = (1 << 3),
271  SL_WFX_POWER_SAVE_ACTIVE = (1 << 4),
273 
274 /**************************************************************************/
280 typedef enum {
284 
285 /**************************************************************************/
289 typedef enum {
296 
297 /**************************************************************************/
303 typedef enum {
309 
310 /**************************************************************************/
314 typedef enum {
315  SL_WFX_TX_FRAME_BUFFER,
316  SL_WFX_RX_FRAME_BUFFER,
317  SL_WFX_CONTROL_BUFFER,
319 
320 /**************************************************************************/
324 typedef enum {
325  SL_WFX_BUS_WRITE = (1 << 0),
326  SL_WFX_BUS_READ = (1 << 1),
327  SL_WFX_BUS_WRITE_AND_READ = SL_WFX_BUS_WRITE | SL_WFX_BUS_READ,
329 
330 #ifdef SL_WFX_USE_SECURE_LINK
331 /**************************************************************************/
335 typedef enum {
336  SL_WFX_LINK_MODE_RESERVED = 0,
337  SL_WFX_LINK_MODE_UNTRUSTED = 1,
338  SL_WFX_LINK_MODE_TRUSTED_EVAL = 2,
339  SL_WFX_LINK_MODE_ACTIVE = 3,
340 } sl_wfx_secure_link_mode_t;
341 
342 /**************************************************************************/
346 typedef enum {
347  SL_WFX_SECURELINK_DEFAULT = 0,
348  SL_WFX_SECURELINK_RENEGOTIATION_NEEDED = 1,
349  SL_WFX_SECURELINK_RENEGOTIATION_PENDING = 2,
350 } sl_wfx_securelink_renegotiation_state_t;
351 #endif //SL_WFX_USE_SECURE_LINK
352 
355 /******************************************************
356 * Structures
357 ******************************************************/
358 
359 /**************************************************************************/
363 typedef struct {
364  uint8_t octet[6];
366 
367 /**************************************************************************/
371 typedef struct {
372  uint8_t password[SL_WFX_PASSWORD_SIZE];
374 
375 /**************************************************************************/
379 typedef struct {
380  uint32_t hp_packet_count;
381  uint32_t rx_packet_count;
382  uint32_t tx_packet_count;
384 
385 /**************************************************************************/
389 typedef struct {
390  uint32_t val;
391  const char *str;
392  uint8_t param_length;
394 
395 /**************************************************************************/
400 typedef struct {
401  uint8_t event_payload_buffer[512];
402  uint8_t firmware_build;
403  uint8_t firmware_minor;
404  uint8_t firmware_major;
405  uint16_t data_frame_id;
406  uint16_t used_buffers;
407  uint8_t wfx_opn[SL_WFX_OPN_SIZE];
411 #ifdef SL_WFX_USE_SECURE_LINK
412  uint8_t secure_link_mac_key[SL_WFX_SECURE_LINK_MAC_KEY_LENGTH];
413  sl_wfx_nonce_t secure_link_nonce;
414  uint8_t encryption_bitmap[SL_WFX_SECURE_LINK_ENCRYPTION_BITMAP_SIZE];
415  uint8_t secure_link_session_key[SL_WFX_SECURE_LINK_SESSION_KEY_LENGTH];
416  uint8_t secure_link_renegotiation_state;
417  sl_wfx_securelink_exchange_pub_keys_ind_t secure_link_exchange_ind;
418 #endif //SL_WFX_USE_SECURE_LINK
420 
421 #endif // SL_WFX_CONSTANTS_H
sl_wfx_antenna_config_t
Enum listing the different antenna configurations.
Definition: sl_wfx_constants.h:289
sl_wfx_state_t
Enum listing the different state of the WFx chip.
Definition: sl_wfx_constants.h:266
sl_wfx_interface_t
Enum listing available interfaces in WFx Wi-Fi solution.
Definition: sl_wfx_constants.h:280
sl_wfx_buffer_type_t
Enumerates the different types of buffer.
Definition: sl_wfx_constants.h:314
sl_wfx_register_address_t
Enum listing the registers of the WFx solution.
Definition: sl_wfx_constants.h:251
sl_wfx_received_message_type_t
Enum listing different message types received from WFx. The information is found in the control regis...
Definition: sl_wfx_constants.h:303
sl_wfx_host_bus_transfer_type_t
Enumerates the different types of bus transfers.
Definition: sl_wfx_constants.h:324
@ SL_WFX_ANTENNA_TX1_RX2
RF output 1 is used for TX, RF 2 for RX.
Definition: sl_wfx_constants.h:292
@ SL_WFX_ANTENNA_TX2_RX1
RF output 2 is used for TX, RF 1 for RX.
Definition: sl_wfx_constants.h:293
@ SL_WFX_ANTENNA_DIVERSITY
WF200 uses an antenna diversity algorithm.
Definition: sl_wfx_constants.h:294
@ SL_WFX_ANTENNA_1_ONLY
RF output 1 is used.
Definition: sl_wfx_constants.h:290
@ SL_WFX_ANTENNA_2_ONLY
RF output 2 is used.
Definition: sl_wfx_constants.h:291
@ SL_WFX_SOFTAP_INTERFACE
Interface 1, linked to the softap.
Definition: sl_wfx_constants.h:282
@ SL_WFX_STA_INTERFACE
Interface 0, linked to the station.
Definition: sl_wfx_constants.h:281
@ SL_WFX_INDICATION_MESSAGE
Frame type indicating an indication message is available.
Definition: sl_wfx_constants.h:305
@ SL_WFX_CONFIRMATION_MESSAGE
Frame type indicating a confirmation message is available.
Definition: sl_wfx_constants.h:304
@ SL_WFX_ETHERNET_DATA_MESSAGE
Frame type indicating message encapsulating a data frame is available.
Definition: sl_wfx_constants.h:307
@ SL_WFX_MANAGEMENT_MESSAGE
Reserved from Low MAC interface.
Definition: sl_wfx_constants.h:306
#define SL_WFX_PASSWORD_SIZE
Definition: sl_wfx_cmd_api.h:213
Structure used to maintain the Wi-Fi solution context on the host side.
Definition: sl_wfx_constants.h:400
uint16_t used_buffers
Number of buffers currently in use by the WFx chip.
Definition: sl_wfx_constants.h:406
uint16_t data_frame_id
Frame ID incremented by sl_wfx_send_ethernet_frame.
Definition: sl_wfx_constants.h:405
sl_wfx_state_t state
State of the WFx Wi-Fi chip.
Definition: sl_wfx_constants.h:410
sl_wfx_mac_address_t mac_addr_0
Mac address used by WFx interface 0, station.
Definition: sl_wfx_constants.h:408
sl_wfx_mac_address_t mac_addr_1
Mac address used by WFx interface 1, softap.
Definition: sl_wfx_constants.h:409
uint8_t firmware_major
Firmware major version.
Definition: sl_wfx_constants.h:404
uint8_t firmware_minor
Firmware minor version.
Definition: sl_wfx_constants.h:403
uint8_t firmware_build
Firmware build version.
Definition: sl_wfx_constants.h:402
Definition: sl_wfx_constants.h:389
Structure to handle MAC address format.
Definition: sl_wfx_constants.h:363
Structure to maintain secure link counters.
Definition: sl_wfx_constants.h:379
uint32_t rx_packet_count
Received packet counter.
Definition: sl_wfx_constants.h:381
uint32_t hp_packet_count
High priority packet counter.
Definition: sl_wfx_constants.h:380
uint32_t tx_packet_count
Sent packet counter.
Definition: sl_wfx_constants.h:382
Structure to handle password format.
Definition: sl_wfx_constants.h:371