1 /***************************************************************************/ /**
2  * @file
3  * @brief
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 #pragma once
31 
32 #include "sl_si91x_constants.h"
33 #include "sl_wifi_host_interface.h"
34 #include <stdint.h>
35 
36 /* NUMBER_OF_BSD_SOCKETS must be < 32 (sizeof(unsigned) * 8) */
37 typedef struct sl_si91x_fd_set {
38 	unsigned int __fds_bits;
39 } sl_si91x_fd_set;
40 
41 /// Flag to indicate that the response status of the command is expected.
42 #define SI91X_PACKET_RESPONSE_STATUS (1 << 0)
43 
44 /// Flag to indicate that the response packet of the command is expected.
45 #define SI91X_PACKET_RESPONSE_PACKET (1 << 1)
46 
47 /// Flag to indicate that all the packet tx has to be suspended until the corresponding command response is received.
48 #define SI91X_PACKET_GLOBAL_QUEUE_BLOCK (1 << 3)
49 
50 /// Flag to indicate that host would receive the response from firmware in asynchronous manner.
51 #define SI91X_PACKET_WITH_ASYNC_RESPONSE (1 << 4)
52 
53 /// Si91x specific command type
54 typedef enum {
55   SI91X_COMMON_CMD  = 0, ///< SI91X Common Command
56   SI91X_WLAN_CMD    = 1, ///< SI91X Wireless LAN Command
57   SI91X_NETWORK_CMD = 2, ///< SI91X Network Command
58   SI91X_BT_CMD      = 3, ///< SI91X Bluetooth Command
59   SI91X_SOCKET_CMD  = 4, ///< SI91X Socket Command
60   SI91X_CMD_MAX,         ///< SI91X Maximum Command value
61 } sl_si91x_command_type_t;
62 
63 /** \addtogroup SL_SI91X_CONSTANTS
64  * @{
65  * */
66 /// Si91x band mode.
67 /// @note Only 2.4 GHz is currently supported.
68 typedef enum {
69   SL_SI91X_WIFI_BAND_2_4GHZ = 0, ///< 2.4 GHz Wi-Fi band
70   SL_SI91X_WIFI_BAND_5GHZ   = 1, ///< 5 GHz Wi-Fi band (not currently supported)
71   SL_SI91X_WIFI_DUAL_BAND   = 2  ///< Both 2.4 GHz and 5 GHZ WiFi band (not currently supported)
72 } sl_si91x_band_mode_t;
73 
74 /// Si91x region code.
75 /// @note Singapore region not currently supported.
76 typedef enum {
77   DEFAULT_REGION, ///< Factory default region
78   US,             ///< United States
79   EU,             ///< European Union
80   JP,             ///< Japan
81   WORLD_DOMAIN,   ///< Worldwide domain
82   KR,             ///< Korea
83   SG,             ///< Singapore (not currently supported)
84   CN,             ///< China
85   IGNORE_REGION   ///< Do not update region code during initialization
86 } sl_si91x_region_code_t;
87 
88 /// Si91x Timeout types
89 typedef enum {
90   SL_SI91X_AUTHENTICATION_ASSOCIATION_TIMEOUT =
91     0, ///< Used for setting association and authentication timeout request in milliseconds
92   SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT, ///< Used for setting dwell time per channel in milliseconds during active scan
93   SL_SI91X_KEEP_ALIVE_TIMEOUT,          ///< Used for setting WLAN keep alive time in seconds
94   SL_SI91X_CHANNEL_PASSIVE_SCAN_TIMEOUT ///< Used for setting dwell time per channel in milliseconds during passive scan
95 } sl_si91x_timeout_type_t;
96 
97 /// Si91x Wi-Fi VAP ID
98 typedef enum {
99   SL_SI91X_WIFI_CLIENT_VAP_ID, ///< Wi-Fi Client VAP ID
100   SL_SI91X_WIFI_AP_VAP_ID,     ///< Wi-Fi Access Point VAP ID
101 } sl_si91x_wifi_vap_id_t;
102 /** @} */
103 
104 /** \addtogroup SL_SI91X_TYPES
105  * @{
106  * */
107 // NWP RSI_COMMON_REQ_OPERMODE command request structure
108 // Note: refer sl_wifi_device.h for complete bit map details
109 /// Si91x boot configuration structure
110 typedef struct {
111   uint16_t oper_mode;                  ///< Operation mode, one of the values from @ref sl_si91x_operation_mode_t.
112   uint16_t coex_mode;                  ///< Coexistence mode, one of the values from @ref sl_si91x_coex_mode_t.
113   uint32_t feature_bit_map;            ///< Feature bit map, @ref SI91X_FEATURE_BITMAP
114   uint32_t tcp_ip_feature_bit_map;     ///< TCP/IP feature bit map, @ref SI91X_TCP_IP_FEATURE_BITMAP
115   uint32_t custom_feature_bit_map;     ///< Custom feature bit map, @ref SI91X_CUSTOM_FEATURE_BITMAP
116   uint32_t ext_custom_feature_bit_map; ///< Extended custom feature bit map, @ref SI91X_EXTENDED_CUSTOM_FEATURE_BITMAP
117   uint32_t bt_feature_bit_map;         ///< BT featured bit map, @ref SI91X_BT_FEATURE_BITMAP
118   uint32_t ext_tcp_ip_feature_bit_map; ///< Extended TCP/IP feature bit map, @ref SI91X_EXTENDED_TCP_IP_FEATURE_BITMAP
119   uint32_t ble_feature_bit_map;        ///< BLE feature bitmap, @ref SI91X_BLE_FEATURE_BITMAP
120   uint32_t ble_ext_feature_bit_map;    ///< BLE extended feature bitmap, @ref SI91X_EXTENDED_BLE_CUSTOM_FEATURE_BITMAP
121   uint32_t config_feature_bit_map;     ///< Config feature bitmap, @ref SI91X_CONFIG_FEATURE_BITMAP
122 } sl_si91x_boot_configuration_t;
123 
124 /// Timeout Configuration Structure
125 typedef struct {
126   uint16_t
127     active_chan_scan_timeout_value; ///< Time spent on each channel when performing active scan (milliseconds). Default value of 100 millisecs is used when SL_WIFI_DEFAULT_ACTIVE_CHANNEL_SCAN_TIME is passed.
128   uint16_t
129     auth_assoc_timeout_value; ///< Authentication and association timeout value. Default value of 300 millisecs is used when SL_WIFI_DEFAULT_AUTH_ASSOCIATION_TIMEOUT is passed.
130   uint16_t
131     keep_alive_timeout_value; ///< Keep Alive Timeout value. Default value of 30 seconds is used when SL_WIFI_DEFAULT_KEEP_ALIVE_TIMEOUT is passed.
132   uint16_t
133     passive_scan_timeout_value; ///< Time spent on each channel when performing passive scan (milliseconds). The minimum passive_scan_timeout_value is 5 millisecs, and maximum is 1000 milliseconds. Default value of 400 milliseconds is used when SL_WIFI_DEFAULT_PASSIVE_CHANNEL_SCAN_TIME is passed.
134 } sl_si91x_timeout_t;
135 
136 /// Si917 specific Wi-Fi module state statistics
137 #pragma pack(1)
138 typedef struct {
139   uint32_t
140     timestamp; ///< Timestamp. This is value of counter at the time of message. This counter is continuously incremented by one per 100ms time.
141   uint8_t
142     state_code; ///< State code. This field indicates state of the module. state code contain two parts (upper and lower nibbles). Upper nibble represent the state of rejoin process and StateCode represented by the lower nibble of state code.
143   uint8_t reason_code; ///< Reason code. This is used to get the reason code from firmware point of view.
144   uint8_t
145     channel; ///< Channel number. If value of channel is 0, it means channel information is not available. In State-I, channel of association or Invalid if it is startup. In State-II, channel of next association if module finds better AP in bgscan result. In State-III, Channel at the time of association.
146   uint8_t
147     rssi; ///< RSSI VALUE. If value of rssi is 100, it means RSSI information is not available. In State-I it is RSSI of AP at the time of trigger. In State-II it is RSSI of next association. In State-III it is RSSI at the time of final association.
148   uint8_t bssid
149     [6]; ///< BSSID of AP. If the value of AP BSSID is 00:00:00:00:00:00,it means MAC information is not available. In State-I it is MAC of AP at the time of scan trigger. In State-II it is MAC of next association. In State-III it is MAC at the time of association.
150 } sl_si91x_module_state_stats_response_t;
151 #pragma pack()
152 
153 /// Firmware version information
154 typedef struct {
155   uint8_t build_num;        ///< Build number of the firmware
156   uint8_t security_version; ///< Security version indicating if security is enabled or disabled
157   uint8_t minor;            ///< Minor version number of the firmware
158   uint8_t major;            ///< Major version number of the firmware
159 } sl_si91x_fw_version_info_t;
160 
161 /// Firmware version extended information
162 typedef struct {
163   uint8_t patch_num;                  ///< Patch number of the firmware
164   uint8_t customer_id : 4;            ///< Customer ID
165   uint8_t build_number_extension : 4; ///< Build number extension
166   uint8_t rom_id;                     ///< ROM ID of the firmware
167   uint8_t chip_id;                    ///< Chip ID of the device
168 } sl_si91x_fw_version_ext_info_t;
169 
170 /// Firmware header information
171 typedef struct {
172   uint16_t control_flags;                     ///< Control flags for the firmware image.
173   uint16_t sha_type;                          ///< SHA type used for the firmware image.
174   uint32_t magic_no;                          ///< Magic number identifying the firmware image.
175   uint32_t image_size;                        ///< Size of the firmware image in bytes.
176   sl_si91x_fw_version_info_t fw_version_info; ///< Firmware version information.
177   uint32_t flash_location;                    ///< Address location in flash memory where the firmware image is stored.
178   uint32_t crc;                               ///< Cyclic Redundancy Check (CRC) value of the firmware image.
179   uint32_t mic[4];                            ///< Message Integrity Code (MIC) of the firmware image.
180   uint32_t reserved;                          ///< Reserved fields for future use.
181   sl_si91x_fw_version_ext_info_t fw_version_ext_info; ///< Firmware version extended information.
182   uint32_t reserved1[4];                              ///< Reserved fields for future use.
183 } sl_si91x_firmware_header_t;
184 
185 /** @} */
186 
187 #if defined(__Keil)
188 #pragma anon_unions
189 #endif
190 
191 // driver TX/RX packet structure
192 /// Si91x packet structure
193 typedef struct {
194   union {
195     struct {
196       uint16_t length;  ///< Length of data
197       uint16_t command; ///< Si91x command type
198       uint8_t unused
199         [12]; ///< Contains command status and other additional information. Unused for TX and only used for rx packets.
200     };
201     uint8_t desc[16]; ///< Si91x packet header
202   };                  ///< Command header
203 
204   uint8_t data[]; ///< Data to be transmitted or received
205 } sl_si91x_packet_t;
206 
207 /// Si91x queue packet structure
208 typedef struct {
209   sl_wifi_buffer_t *host_packet;        ///< Si91x host buffer
210   uint8_t firmware_queue_id;            ///< Si91x firmware queue id
211   sl_si91x_command_type_t command_type; ///< Si91x command type
212   //  uint16_t packet_id;                   ///< Packet id, used internally to track packets
213   uint8_t flags;              ///< One of the values from Si91x packet response flags
214   uint16_t frame_status;      ///< Si91x command status
215   void *sdk_context;          ///< SDK context, unused internally to invoke user callbacks
216   uint32_t command_timeout;   ///< Si91x command timeout
217   uint32_t command_tickcount; ///< command_tickcount stores the tickcount when the command is given to the bus thread.
218 } sli_si91x_queue_packet_t;
219 
220 /// Si91x specific buffer queue structure
221 typedef struct {
222   sl_wifi_buffer_t *head; ///< Head
223   sl_wifi_buffer_t *tail; ///< Tail
224 } sl_si91x_buffer_queue_t;
225 
226 /// NWP buffer allocation command parameters
227 /// The summation of all three ratios should max 10 and the ratio should be in decimal value.
228 typedef struct {
229   uint8_t tx_ratio_in_buffer_pool;     ///< tx ratio
230   uint8_t rx_ratio_in_buffer_pool;     ///< rx ratio
231   uint8_t global_ratio_in_buffer_pool; ///< global ratio
232 } sl_si91x_dynamic_pool;
233 
234 /// Structure to represent a command queue
235 typedef struct {
236   sl_si91x_buffer_queue_t tx_queue;    ///< TX queue
237   sl_si91x_buffer_queue_t rx_queue;    ///< RX queue
238   sl_si91x_buffer_queue_t event_queue; ///< Event queue
239   void *mutex;                         ///< Pointer to mutex
240   uint32_t flag;                       ///< Flags
241   bool sequential;                     ///< Indicates if the commands are sequential
242   bool command_in_flight;              ///< Indicates if a command is currently being processed
243   uint16_t frame_type;                 ///< Type of the frame associated with the command
244   uint8_t firmware_queue_id;           ///< ID of the firmware queue for the command
245   uint32_t rx_counter;                 ///< Counter for received packets
246   uint32_t tx_counter;                 ///< Counter for transmitted packets
247   uint16_t packet_id;                  ///< ID of the packet associated with the command
248   uint8_t flags;                       ///< Flags associated with the command
249   uint32_t command_tickcount;          ///< Command tick count
250   uint32_t command_timeout;            ///< Command timeout
251   void *sdk_context;                   ///< Context data associated with the command
252 } sli_si91x_command_queue_t;
253