1 /*
2  * Copyright 2022, Cypress Semiconductor Corporation (an Infineon company)
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /** @file
19  *  Defines common constants used with WHD within src folder
20  *
21  */
22 
23 #ifndef INCLUDED_WHD_TYPES_INT_H_
24 #define INCLUDED_WHD_TYPES_INT_H_
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <inttypes.h>
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 /******************************************************
36 *                      Macros
37 ******************************************************/
38 /**
39  * The size of an Ethernet header
40  */
41 #define WHD_ETHERNET_SIZE         (14)
42 
43 /**
44  * Ethernet Ethertypes
45  */
46 #define WHD_ETHERTYPE_IPv4    0x0800
47 #define WHD_ETHERTYPE_IPv6    0x86DD
48 #define WHD_ETHERTYPE_ARP     0x0806
49 #define WHD_ETHERTYPE_RARP    0x8035
50 #define WHD_ETHERTYPE_EAPOL   0x888E
51 #define WHD_ETHERTYPE_DOT1AS  0x88F7
52 #define WHD_ETHERTYPE_8021Q   0x8100
53 
54 /* bss_info_cap_t flags */
55 #define WL_BSS_FLAGS_FROM_BEACON        0x01    /* bss_info derived from beacon */
56 #define WL_BSS_FLAGS_FROM_CACHE         0x02    /* bss_info collected from cache */
57 #define WL_BSS_FLAGS_RSSI_ONCHANNEL     0x04    /* rssi info received on channel (vs offchannel) */
58 #define WL_BSS_FLAGS_HS20               0x08    /* hotspot 2.0 capable */
59 #define WL_BSS_FLAGS_RSSI_INVALID       0x10    /* BSS contains invalid RSSI */
60 #define WL_BSS_FLAGS_RSSI_INACCURATE    0x20    /* BSS contains inaccurate RSSI */
61 #define WL_BSS_FLAGS_SNR_INVALID        0x40    /* BSS contains invalid SNR */
62 #define WL_BSS_FLAGS_NF_INVALID         0x80    /* BSS contains invalid noise floor */
63 
64 #define HT_CAPABILITIES_IE_LENGTH       (26)
65 #define DOT11_OUI_LEN                   (3)/** Length in bytes of 802.11 OUI*/
66 #define DOT11_MGMT_HDR_LEN              (24) /* dot11 management header len */
67 
68 #define WHD_ETHER_ADDR_STR_LEN          (18)
69 #define WHD_ETHER_ADDR_LEN              (6)
70 
71 #define CHECK_IOCTL_BUFFER(buff)  if (buff == \
72                                       NULL){ WPRINT_WHD_ERROR( ("Buffer alloc failed in function %s at line %d \n", \
73                                                                 __func__, __LINE__) ); \
74                                              return WHD_BUFFER_ALLOC_FAIL; }
75 #define CHECK_PACKET_NULL(buff, err)  if (buff == \
76                                           NULL){ WPRINT_WHD_ERROR( ("No register function pointer in %s at line %d \n", \
77                                                                     __func__, __LINE__) ); \
78                                                  return err;}
79 #define CHECK_PACKET_WITH_NULL_RETURN(buff)  if (buff == \
80                                                  NULL){ WPRINT_WHD_ERROR( ( \
81                                                                               "No register function pointer in %s at line %d \n", \
82                                                                               __func__, __LINE__) ); \
83                                                         return;}
84 
85 #define CHECK_RETURN(expr)  { \
86         whd_result_t check_res = (expr); \
87         if (check_res != WHD_SUCCESS) \
88         { \
89             WPRINT_WHD_ERROR( ("Function %s failed at line %d checkres = %u \n", \
90                                __func__, __LINE__, \
91                                (unsigned int)check_res) ); \
92             return check_res; \
93         } \
94 }
95 
96 #define CHECK_RETURN_UNSUPPORTED_OK(expr)  { whd_result_t check_res = (expr);  \
97                                              if (check_res != WHD_SUCCESS) \
98                                              { \
99                                                  return check_res; \
100                                              } \
101 }
102 #define CHECK_RETURN_UNSUPPORTED_CONTINUE(expr)  { whd_result_t check_res = (expr);                                 \
103                                                    if (check_res != WHD_SUCCESS && check_res != WHD_WLAN_UNSUPPORTED) \
104                                                    { \
105                                                        return check_res; \
106                                                    } \
107 }
108 #define RETURN_WITH_ASSERT(expr)  { whd_result_t check_res = (expr); \
109                                     whd_assert("Command failed\n", check_res == WHD_SUCCESS); \
110                                     return check_res; }
111 
112 #define CHECK_RETURN_IGNORE(expr)  { whd_result_t check_res = (expr);  \
113                                      if (check_res != WHD_SUCCESS) \
114                                      { \
115                                      } \
116 }
117 
118 #define CHECK_IFP_NULL(ifp)  if (ifp == \
119                                  NULL){ WPRINT_WHD_ERROR( ( \
120                                                               "Interface is not up/NULL and failed in function %s at line %d \n", \
121                                                               __func__, __LINE__) ); \
122                                         return WHD_UNKNOWN_INTERFACE; }
123 
124 #define CHECK_DRIVER_NULL(driver)  if (driver == \
125                                        NULL){ WPRINT_WHD_ERROR( ( \
126                                                                     "WHD driver is not up/NULL and failed in function %s at line %d \n", \
127                                                                     __func__, __LINE__) ); \
128                                               return WHD_DOES_NOT_EXIST; }
129 
130 #define MIN_OF(x, y) ( (x) < (y) ? (x) : (y) )
131 #define MAX_OF(x, y)  ( (x) > (y) ? (x) : (y) )
132 
133 #ifndef ROUND_UP
134 #define ROUND_UP(x, y)    ( (x) % (y) ? (x) + (y) - ( (x) % (y) ) : (x) )
135 #endif
136 
137 #ifndef DIV_ROUND_UP
138 #define DIV_ROUND_UP(m, n)    ( ( (m) + (n) - 1 ) / (n) )
139 #endif
140 
141 #define WHD_WRITE_16(pointer, value)      (*( (uint16_t *)pointer ) = value)
142 #define WHD_WRITE_32(pointer, value)      (*( (uint32_t *)pointer ) = value)
143 #define WHD_READ_16(pointer)              *( (uint16_t *)pointer )
144 #define WHD_READ_32(pointer)              *( (uint32_t *)pointer )
145 
146 /**
147  *  Macro for checking for NULL MAC addresses
148  */
149 #define NULL_MAC(a)  ( ( ( ( (unsigned char *)a )[0] ) == 0 ) && \
150                        ( ( ( (unsigned char *)a )[1] ) == 0 ) && \
151                        ( ( ( (unsigned char *)a )[2] ) == 0 ) && \
152                        ( ( ( (unsigned char *)a )[3] ) == 0 ) && \
153                        ( ( ( (unsigned char *)a )[4] ) == 0 ) && \
154                        ( ( ( (unsigned char *)a )[5] ) == 0 ) )
155 
156 /**
157  *	Macro for checking for Broadcast address
158  */
159 #define BROADCAST_ID(a)  ( ( ( ( (unsigned char *)a )[0] ) == 255 ) && \
160                            ( ( ( (unsigned char *)a )[1] ) == 255 ) && \
161                            ( ( ( (unsigned char *)a )[2] ) == 255 ) && \
162                            ( ( ( (unsigned char *)a )[3] ) == 255 ) && \
163                            ( ( ( (unsigned char *)a )[4] ) == 255 ) && \
164                            ( ( ( (unsigned char *)a )[5] ) == 255 ) )
165 
166 /* Suppress unused variable warning occurring due to an assert which is disabled in release mode */
167 #define REFERENCE_DEBUG_ONLY_VARIABLE(x) ( (void)(x) )
168 
169 /* Suppress unused parameter warning */
170 #define UNUSED_PARAMETER(x) ( (void)(x) )
171 
172 /* Suppress unused variable warning */
173 #define UNUSED_VARIABLE(x) ( (void)(x) )
174 
175 #if defined (__IAR_SYSTEMS_ICC__)
176 #define DISABLE_COMPILER_WARNING(x) _Pragma(#x)
177 #define ENABLE_COMPILER_WARNING(x) _Pragma(#x)
178 #else
179 #define DISABLE_COMPILER_WARNING(x)
180 #define ENABLE_COMPILER_WARNING(x)
181 #endif
182 
183 /******************************************************
184 *                 Type Definitions
185 ******************************************************/
186 
187 /******************************************************
188 *                    Constants
189 ******************************************************/
190 
191 /******************************************************
192 *             Structures and Enumerations
193 ******************************************************/
194 #pragma pack(1)
195 typedef struct
196 {
197     whd_buffer_queue_ptr_t queue_next;
198     char bus_header[MAX_BUS_HEADER_SIZE];
199 } whd_buffer_header_t;
200 #pragma pack()
201 
202 /* 802.11 Information Element Identification Numbers (as per section 8.4.2.1 of 802.11-2012) */
203 typedef enum
204 {
205     DOT11_IE_ID_SSID                                 = 0,
206     DOT11_IE_ID_SUPPORTED_RATES                      = 1,
207     DOT11_IE_ID_FH_PARAMETER_SET                     = 2,
208     DOT11_IE_ID_DSSS_PARAMETER_SET                   = 3,
209     DOT11_IE_ID_CF_PARAMETER_SET                     = 4,
210     DOT11_IE_ID_TIM                                  = 5,
211     DOT11_IE_ID_IBSS_PARAMETER_SET                   = 6,
212     DOT11_IE_ID_COUNTRY                              = 7,
213     DOT11_IE_ID_HOPPING_PATTERN_PARAMETERS           = 8,
214     DOT11_IE_ID_HOPPING_PATTERN_TABLE                = 9,
215     DOT11_IE_ID_REQUEST                              = 10,
216     DOT11_IE_ID_BSS_LOAD                             = 11,
217     DOT11_IE_ID_EDCA_PARAMETER_SET                   = 12,
218     DOT11_IE_ID_TSPEC                                = 13,
219     DOT11_IE_ID_TCLAS                                = 14,
220     DOT11_IE_ID_SCHEDULE                             = 15,
221     DOT11_IE_ID_CHALLENGE_TEXT                       = 16,
222     /* 17-31 Reserved */
223     DOT11_IE_ID_POWER_CONSTRAINT                     = 32,
224     DOT11_IE_ID_POWER_CAPABILITY                     = 33,
225     DOT11_IE_ID_TPC_REQUEST                          = 34,
226     DOT11_IE_ID_TPC_REPORT                           = 35,
227     DOT11_IE_ID_SUPPORTED_CHANNELS                   = 36,
228     DOT11_IE_ID_CHANNEL_SWITCH_ANNOUNCEMENT          = 37,
229     DOT11_IE_ID_MEASUREMENT_REQUEST                  = 38,
230     DOT11_IE_ID_MEASUREMENT_REPORT                   = 39,
231     DOT11_IE_ID_QUIET                                = 40,
232     DOT11_IE_ID_IBSS_DFS                             = 41,
233     DOT11_IE_ID_ERP                                  = 42,
234     DOT11_IE_ID_TS_DELAY                             = 43,
235     DOT11_IE_ID_TCLAS_PROCESSING                     = 44,
236     DOT11_IE_ID_HT_CAPABILITIES                      = 45,
237     DOT11_IE_ID_QOS_CAPABILITY                       = 46,
238     /* 47 Reserved */
239     DOT11_IE_ID_RSN                                  = 48,
240     /* 49 Reserved */
241     DOT11_IE_ID_EXTENDED_SUPPORTED_RATES             = 50,
242     DOT11_IE_ID_AP_CHANNEL_REPORT                    = 51,
243     DOT11_IE_ID_NEIGHBOR_REPORT                      = 52,
244     DOT11_IE_ID_RCPI                                 = 53,
245     DOT11_IE_ID_MOBILITY_DOMAIN                      = 54,
246     DOT11_IE_ID_FAST_BSS_TRANSITION                  = 55,
247     DOT11_IE_ID_TIMEOUT_INTERVAL                     = 56,
248     DOT11_IE_ID_RIC_DATA                             = 57,
249     DOT11_IE_ID_DSE_REGISTERED_LOCATION              = 58,
250     DOT11_IE_ID_SUPPORTED_OPERATING_CLASSES          = 59,
251     DOT11_IE_ID_EXTENDED_CHANNEL_SWITCH_ANNOUNCEMENT = 60,
252     DOT11_IE_ID_HT_OPERATION                         = 61,
253     DOT11_IE_ID_SECONDARY_CHANNEL_OFFSET             = 62,
254     DOT11_IE_ID_BSS_AVERAGE_ACCESS_DELAY             = 63,
255     DOT11_IE_ID_ANTENNA                              = 64,
256     DOT11_IE_ID_RSNI                                 = 65,
257     DOT11_IE_ID_MEASUREMENT_PILOT_TRANSMISSION       = 66,
258     DOT11_IE_ID_BSS_AVAILABLE_ADMISSION_CAPACITY     = 67,
259     DOT11_IE_ID_BSS_AC_ACCESS_DELAY                  = 68,
260     DOT11_IE_ID_TIME_ADVERTISEMENT                   = 69,
261     DOT11_IE_ID_RM_ENABLED_CAPABILITIES              = 70,
262     DOT11_IE_ID_MULTIPLE_BSSID                       = 71,
263     DOT11_IE_ID_20_40_BSS_COEXISTENCE                = 72,
264     DOT11_IE_ID_20_40_BSS_INTOLERANT_CHANNEL_REPORT  = 73,
265     DOT11_IE_ID_OVERLAPPING_BSS_SCAN_PARAMETERS      = 74,
266     DOT11_IE_ID_RIC_DESCRIPTOR                       = 75,
267     DOT11_IE_ID_MANAGEMENT_MIC                       = 76,
268     DOT11_IE_ID_EVENT_REQUEST                        = 78,
269     DOT11_IE_ID_EVENT_REPORT                         = 79,
270     DOT11_IE_ID_DIAGNOSTIC_REQUEST                   = 80,
271     DOT11_IE_ID_DIAGNOSTIC_REPORT                    = 81,
272     DOT11_IE_ID_LOCATION_PARAMETERS                  = 82,
273     DOT11_IE_ID_NONTRANSMITTED_BSSID_CAPABILITY      = 83,
274     DOT11_IE_ID_SSID_LIST                            = 84,
275     DOT11_IE_ID_MULTIPLE_BSSID_INDEX                 = 85,
276     DOT11_IE_ID_FMS_DESCRIPTOR                       = 86,
277     DOT11_IE_ID_FMS_REQUEST                          = 87,
278     DOT11_IE_ID_FMS_RESPONSE                         = 88,
279     DOT11_IE_ID_QOS_TRAFFIC_CAPABILITY               = 89,
280     DOT11_IE_ID_BSS_MAX_IDLE_PERIOD                  = 90,
281     DOT11_IE_ID_TFS_REQUEST                          = 91,
282     DOT11_IE_ID_TFS_RESPONSE                         = 92,
283     DOT11_IE_ID_WNM_SLEEP_MODE                       = 93,
284     DOT11_IE_ID_TIM_BROADCAST_REQUEST                = 94,
285     DOT11_IE_ID_TIM_BROADCAST_RESPONSE               = 95,
286     DOT11_IE_ID_COLLOCATED_INTERFERENCE_REPORT       = 96,
287     DOT11_IE_ID_CHANNEL_USAGE                        = 97,
288     DOT11_IE_ID_TIME_ZONE                            = 98,
289     DOT11_IE_ID_DMS_REQUEST                          = 99,
290     DOT11_IE_ID_DMS_RESPONSE                         = 100,
291     DOT11_IE_ID_LINK_IDENTIFIER                      = 101,
292     DOT11_IE_ID_WAKEUP_SCHEDULE                      = 102,
293     /* 103 Reserved */
294     DOT11_IE_ID_CHANNEL_SWITCH_TIMING                = 104,
295     DOT11_IE_ID_PTI_CONTROL                          = 105,
296     DOT11_IE_ID_TPU_BUFFER_STATUS                    = 106,
297     DOT11_IE_ID_INTERWORKING                         = 107,
298     DOT11_IE_ID_ADVERTISMENT_PROTOCOL                = 108,
299     DOT11_IE_ID_EXPEDITED_BANDWIDTH_REQUEST          = 109,
300     DOT11_IE_ID_QOS_MAP_SET                          = 110,
301     DOT11_IE_ID_ROAMING_CONSORTIUM                   = 111,
302     DOT11_IE_ID_EMERGENCY_ALERT_IDENTIFIER           = 112,
303     DOT11_IE_ID_MESH_CONFIGURATION                   = 113,
304     DOT11_IE_ID_MESH_ID                              = 114,
305     DOT11_IE_ID_MESH_LINK_METRIC_REPORT              = 115,
306     DOT11_IE_ID_CONGESTION_NOTIFICATION              = 116,
307     DOT11_IE_ID_MESH_PEERING_MANAGEMENT              = 117,
308     DOT11_IE_ID_MESH_CHANNEL_SWITCH_PARAMETERS       = 118,
309     DOT11_IE_ID_MESH_AWAKE_WINDOW                    = 119,
310     DOT11_IE_ID_BEACON_TIMING                        = 120,
311     DOT11_IE_ID_MCCAOP_SETUP_REQUEST                 = 121,
312     DOT11_IE_ID_MCCAOP_SETUP_REPLY                   = 122,
313     DOT11_IE_ID_MCCAOP_ADVERTISMENT                  = 123,
314     DOT11_IE_ID_MCCAOP_TEARDOWN                      = 124,
315     DOT11_IE_ID_GANN                                 = 125,
316     DOT11_IE_ID_RANN                                 = 126,
317     DOT11_IE_ID_EXTENDED_CAPABILITIES                = 127,
318     /* 128-129 Reserved */
319     DOT11_IE_ID_PREQ                                 = 130,
320     DOT11_IE_ID_PREP                                 = 131,
321     DOT11_IE_ID_PERR                                 = 132,
322     /* 133-136 Reserved */
323     DOT11_IE_ID_PXU                                  = 137,
324     DOT11_IE_ID_PXUC                                 = 138,
325     DOT11_IE_ID_AUTHENTICATED_MESH_PEERING_EXCHANGE  = 139,
326     DOT11_IE_ID_MIC                                  = 140,
327     DOT11_IE_ID_DESTINATION_URI                      = 141,
328     DOT11_IE_ID_U_APSD_COEXISTENCE                   = 142,
329     /* 143-173 Reserved */
330     DOT11_IE_ID_MCCAOP_ADVERTISMENT_OVERVIEW         = 174,
331     /* 175-220 Reserved */
332     DOT11_IE_ID_VENDOR_SPECIFIC                      = 221,
333     /* 222-223 Reserved */
334     DOT11_IE_ID_RSNX                                 = 244,
335     /* 225-255 Reserved */
336 } dot11_ie_id_t;
337 
338 /* 802.11 Status Code */
339 typedef enum
340 {
341     DOT11_SC_SUCCESS                                 = 0,
342     DOT11_SC_FAILURE                                 = 1,
343     DOT11_SC_TDLS_WAKEUP_SCH_ALT                     = 2,
344     DOT11_SC_TDLS_WAKEUP_SCH_REJ                     = 3,
345     /* 4 Reserved */
346     DOT11_SC_TDLS_SEC_DISABLED                       = 5,
347     DOT11_SC_LIFETIME_REJ                            = 6,
348     DOT11_SC_NOT_SAME_BSS                            = 7,
349     /* 8-9 Reserved */
350     DOT11_SC_CAP_MISMATCH                            = 10,
351     DOT11_SC_REASSOC_FAIL                            = 11,
352     DOT11_SC_ASSOC_FAIL                              = 12,
353     DOT11_SC_AUTH_MISMATCH                           = 13,
354     DOT11_SC_AUTH_SEQ                                = 14,
355     DOT11_SC_AUTH_CHALLENGE_FAIL                     = 15,
356     DOT11_SC_AUTH_TIMEOUT                            = 16,
357     /* 17-255 Reserved */
358 } dot11_sc_t;
359 
360 uint32_t whd_wifi_get_iovar_value(whd_interface_t ifp, const char *iovar, uint32_t *value);
361 uint32_t whd_wifi_set_iovar_buffers(whd_interface_t ifp, const char *iovar, const void **in_buffers,
362                                     const uint16_t *lengths, const uint8_t num_buffers);
363 uint32_t whd_wifi_set_iovar_value(whd_interface_t ifp, const char *iovar, uint32_t value);
364 
365 /** Sends an IOVAR command
366  *
367  *  @param  ifp                 : Pointer to handle instance of whd interface
368  *  @param  iovar               : IOVAR name
369  *
370  *  @return WHD_SUCCESS or Error code
371  */
372 extern uint32_t whd_wifi_set_iovar_void(whd_interface_t ifp, const char *iovar);
373 
374 /** Sends an IOVAR command
375  *
376  *  @param  ifp                 : Pointer to handle instance of whd interface
377  *  @param  iovar               : IOVAR name
378  *  @param  buffer              : Handle for a packet buffer containing the data value to be sent.
379  *  @param  buffer_length       : Length of out_buffer
380  *
381  *  @return WHD_SUCCESS or Error code
382  */
383 extern uint32_t whd_wifi_set_iovar_buffer(whd_interface_t ifp, const char *iovar, void *buffer, uint16_t buffer_length);
384 
385 /** Sends an IOVAR command
386  *
387  *  @param  ifp                 : Pointer to handle instance of whd interface
388  *  @param  iovar               : IOVAR name
389  *  @param  in_buffers          : Handle for a packet buffers containing the data value to be sent.
390  *  @param  in_buffer_lengths   : Length of in_buffers
391  *  @param  num_buffers         : Number of handle buffers
392  *
393  *  @return WHD_SUCCESS or Error code
394  */
395 extern uint32_t whd_wifi_set_iovar_buffers(whd_interface_t ifp, const char *iovar, const void **in_buffers,
396                                            const uint16_t *in_buffer_lengths, const uint8_t num_buffers);
397 
398 /** Sends an IOVAR command
399  *
400  *  @param  ifp                 : Pointer to handle instance of whd interface
401  *  @param  iovar               : IOVAR name
402  *  @param  out_buffer          : Pointer to receive the handle for the packet buffer containing the response data value received
403  *  @param  out_length          : Length of out_buffer
404  *
405  *  @return WHD_SUCCESS or Error code
406  */
407 extern uint32_t whd_wifi_get_iovar_buffer(whd_interface_t ifp, const char *iovar_name, uint8_t *out_buffer,
408                                           uint16_t out_length);
409 
410 /** Sends an IOVAR command
411  *
412  *  @param  ifp                 : Pointer to handle instance of whd interface
413  *  @param  iovar               : IOVAR name
414  *  @param  buffer              : Handle for a packet buffer containing the data value to be sent.
415  *  @param  buffer_length       : Length of out_buffer
416  *
417  *  @return WHD_SUCCESS or Error code
418  */
419 extern uint32_t whd_wifi_set_iovar_buffer(whd_interface_t ifp, const char *iovar, void *buffer, uint16_t buffer_length);
420 
421 /** Sends an IOVAR command
422  *
423  *  @param  ifp                 : Pointer to handle instance of whd interface
424  *  @param  iovar               : IOVAR name
425  *  @param  in_buffers          : Handle for a packet buffers containing the data value to be sent.
426  *  @param  in_buffer_lengths   : Length of in_buffers
427  *  @param  num_buffers         : Number of handle buffers
428  *
429  *  @return WHD_SUCCESS or Error code
430  */
431 extern uint32_t whd_wifi_set_iovar_buffers(whd_interface_t ifp, const char *iovar, const void **in_buffers,
432                                            const uint16_t *in_buffer_lengths, const uint8_t num_buffers);
433 
434 extern uint32_t whd_wifi_set_mac_address(whd_interface_t ifp, whd_mac_t mac);
435 
436 #ifdef __cplusplus
437 }     /* extern "C" */
438 #endif
439 #endif /* ifndef INCLUDED_WHD_TYPES_INT_H_ */
440