1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * Changes from Qualcomm Innovation Center are provided under the following license:
17  *
18  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted (subject to the limitations in the
22  * disclaimer below) provided that the following conditions are met:
23  *
24  *   * Redistributions of source code must retain the above copyright
25  *     notice, this list of conditions and the following disclaimer.
26  *
27  *   * Redistributions in binary form must reproduce the above
28  *     copyright notice, this list of conditions and the following
29  *     disclaimer in the documentation and/or other materials provided
30  *     with the distribution.
31  *
32  *   * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
33  *     contributors may be used to endorse or promote products derived
34  *     from this software without specific prior written permission.
35  *
36  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
37  * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
38  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
42  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
46  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
47  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
48  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49  */
50 
51 #ifndef __NAN_I_H__
52 #define __NAN_I_H__
53 
54 #include "common.h"
55 #include "cpp_bindings.h"
56 #include <hardware_legacy/wifi_hal.h>
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif /* __cplusplus */
62 
63 #ifndef PACKED
64 #define PACKED  __attribute__((packed))
65 #endif
66 #define BIT_NONE            0x00
67 #define BIT_0               0x01
68 #define BIT_1               0x02
69 #define BIT_2               0x04
70 #define BIT_3               0x08
71 #define BIT_4               0x10
72 #define BIT_5               0x20
73 #define BIT_6               0x40
74 #define BIT_7               0x80
75 #define BIT_8               0x0100
76 #define BIT_9               0x0200
77 #define BIT_10              0x0400
78 #define BIT_11              0x0800
79 #define BIT_12              0x1000
80 #define BIT_13              0x2000
81 #define BIT_14              0x4000
82 #define BIT_15              0x8000
83 #define BIT_16              0x010000
84 #define BIT_17              0x020000
85 #define BIT_18              0x040000
86 #define BIT_19              0x080000
87 #define BIT_20              0x100000
88 #define BIT_21              0x200000
89 #define BIT_22              0x400000
90 #define BIT_23              0x800000
91 #define BIT_24              0x01000000
92 #define BIT_25              0x02000000
93 #define BIT_26              0x04000000
94 #define BIT_27              0x08000000
95 #define BIT_28              0x10000000
96 #define BIT_29              0x20000000
97 #define BIT_30              0x40000000
98 #define BIT_31              0x80000000
99 
100 /** macro to convert FW MAC address from WMI word format to User Space MAC char array */
101 #define FW_MAC_ADDR_TO_CHAR_ARRAY(fw_mac_addr, mac_addr) do { \
102      (mac_addr)[0] =    ((fw_mac_addr).mac_addr31to0) & 0xff; \
103      (mac_addr)[1] =  (((fw_mac_addr).mac_addr31to0) >> 8) & 0xff; \
104      (mac_addr)[2] =  (((fw_mac_addr).mac_addr31to0) >> 16) & 0xff; \
105      (mac_addr)[3] =  (((fw_mac_addr).mac_addr31to0) >> 24) & 0xff; \
106      (mac_addr)[4] =    ((fw_mac_addr).mac_addr47to32) & 0xff; \
107      (mac_addr)[5] =  (((fw_mac_addr).mac_addr47to32) >> 8) & 0xff; \
108 } while (0)
109 
110 /** macro to convert User space MAC address from char array to FW WMI word format */
111 #define CHAR_ARRAY_TO_MAC_ADDR(mac_addr, fw_mac_addr)  do { \
112     (fw_mac_addr).mac_addr31to0  =                   \
113          ((mac_addr)[0] | ((mac_addr)[1] << 8)            \
114            | ((mac_addr)[2] << 16) | ((mac_addr)[3] << 24));          \
115     (fw_mac_addr).mac_addr47to32  =                  \
116          ((mac_addr)[4] | ((mac_addr)[5] << 8));          \
117 } while (0)
118 
119 /*---------------------------------------------------------------------------
120 * WLAN NAN CONSTANTS
121 *--------------------------------------------------------------------------*/
122 
123 typedef enum
124 {
125     NAN_MSG_ID_ERROR_RSP                    = 0,
126     NAN_MSG_ID_CONFIGURATION_REQ            = 1,
127     NAN_MSG_ID_CONFIGURATION_RSP            = 2,
128     NAN_MSG_ID_PUBLISH_SERVICE_REQ          = 3,
129     NAN_MSG_ID_PUBLISH_SERVICE_RSP          = 4,
130     NAN_MSG_ID_PUBLISH_SERVICE_CANCEL_REQ   = 5,
131     NAN_MSG_ID_PUBLISH_SERVICE_CANCEL_RSP   = 6,
132     NAN_MSG_ID_PUBLISH_REPLIED_IND          = 7,
133     NAN_MSG_ID_PUBLISH_TERMINATED_IND       = 8,
134     NAN_MSG_ID_SUBSCRIBE_SERVICE_REQ        = 9,
135     NAN_MSG_ID_SUBSCRIBE_SERVICE_RSP        = 10,
136     NAN_MSG_ID_SUBSCRIBE_SERVICE_CANCEL_REQ = 11,
137     NAN_MSG_ID_SUBSCRIBE_SERVICE_CANCEL_RSP = 12,
138     NAN_MSG_ID_MATCH_IND                    = 13,
139     NAN_MSG_ID_MATCH_EXPIRED_IND            = 14,
140     NAN_MSG_ID_SUBSCRIBE_TERMINATED_IND     = 15,
141     NAN_MSG_ID_DE_EVENT_IND                 = 16,
142     NAN_MSG_ID_TRANSMIT_FOLLOWUP_REQ        = 17,
143     NAN_MSG_ID_TRANSMIT_FOLLOWUP_RSP        = 18,
144     NAN_MSG_ID_FOLLOWUP_IND                 = 19,
145     NAN_MSG_ID_STATS_REQ                    = 20,
146     NAN_MSG_ID_STATS_RSP                    = 21,
147     NAN_MSG_ID_ENABLE_REQ                   = 22,
148     NAN_MSG_ID_ENABLE_RSP                   = 23,
149     NAN_MSG_ID_DISABLE_REQ                  = 24,
150     NAN_MSG_ID_DISABLE_RSP                  = 25,
151     NAN_MSG_ID_DISABLE_IND                  = 26,
152     NAN_MSG_ID_TCA_REQ                      = 27,
153     NAN_MSG_ID_TCA_RSP                      = 28,
154     NAN_MSG_ID_TCA_IND                      = 29,
155     NAN_MSG_ID_BEACON_SDF_REQ               = 30,
156     NAN_MSG_ID_BEACON_SDF_RSP               = 31,
157     NAN_MSG_ID_BEACON_SDF_IND               = 32,
158     NAN_MSG_ID_CAPABILITIES_REQ             = 33,
159     NAN_MSG_ID_CAPABILITIES_RSP             = 34,
160     NAN_MSG_ID_SELF_TRANSMIT_FOLLOWUP_IND   = 35,
161     NAN_MSG_ID_RANGING_REQUEST_RECEVD_IND   = 36,
162     NAN_MSG_ID_RANGING_RESULT_IND           = 37,
163     NAN_MSG_ID_TESTMODE_REQ                 = 1025,
164     NAN_MSG_ID_TESTMODE_RSP                 = 1026
165 } NanMsgId;
166 
167 /*
168   Various TLV Type ID sent as part of NAN Stats Response
169   or NAN TCA Indication
170 */
171 typedef enum
172 {
173     NAN_TLV_TYPE_FIRST = 0,
174 
175     /* Service Discovery Frame types */
176     NAN_TLV_TYPE_SDF_FIRST = NAN_TLV_TYPE_FIRST,
177     NAN_TLV_TYPE_SERVICE_NAME = NAN_TLV_TYPE_SDF_FIRST,
178     NAN_TLV_TYPE_SDF_MATCH_FILTER,
179     NAN_TLV_TYPE_TX_MATCH_FILTER,
180     NAN_TLV_TYPE_RX_MATCH_FILTER,
181     NAN_TLV_TYPE_SERVICE_SPECIFIC_INFO,
182     NAN_TLV_TYPE_EXT_SERVICE_SPECIFIC_INFO =5,
183     NAN_TLV_TYPE_VENDOR_SPECIFIC_ATTRIBUTE_TRANSMIT = 6,
184     NAN_TLV_TYPE_VENDOR_SPECIFIC_ATTRIBUTE_RECEIVE = 7,
185     NAN_TLV_TYPE_POST_NAN_CONNECTIVITY_CAPABILITIES_RECEIVE = 8,
186     NAN_TLV_TYPE_POST_NAN_DISCOVERY_ATTRIBUTE_RECEIVE = 9,
187     NAN_TLV_TYPE_BEACON_SDF_PAYLOAD_RECEIVE = 10,
188     NAN_TLV_TYPE_NAN_DATA_PATH_PARAMS = 11,
189     NAN_TLV_TYPE_NAN_DATA_SUPPORTED_BAND = 12,
190     NAN_TLV_TYPE_2G_COMMITTED_DW = 13,
191     NAN_TLV_TYPE_5G_COMMITTED_DW = 14,
192     NAN_TLV_TYPE_NAN_DATA_RESPONDER_MODE = 15,
193     NAN_TLV_TYPE_NAN_DATA_ENABLED_IN_MATCH = 16,
194     NAN_TLV_TYPE_NAN_SERVICE_ACCEPT_POLICY = 17,
195     NAN_TLV_TYPE_NAN_CSID = 18,
196     NAN_TLV_TYPE_NAN_SCID = 19,
197     NAN_TLV_TYPE_NAN_PMK = 20,
198     NAN_TLV_TYPE_SDEA_CTRL_PARAMS = 21,
199     NAN_TLV_TYPE_NAN_RANGING_CFG = 22,
200     NAN_TLV_TYPE_CONFIG_DISCOVERY_INDICATIONS = 23,
201     NAN_TLV_TYPE_NAN20_RANGING_REQUEST = 24,
202     NAN_TLV_TYPE_NAN20_RANGING_RESULT = 25,
203     NAN_TLV_TYPE_NAN20_RANGING_REQUEST_RECEIVED = 26,
204     NAN_TLV_TYPE_NAN_PASSPHRASE = 27,
205     NAN_TLV_TYPE_SDEA_SERVICE_SPECIFIC_INFO = 28,
206     NAN_TLV_TYPE_DEV_CAP_ATTR_CAPABILITY = 29,
207     NAN_TLV_TYPE_IP_TRANSPORT_PARAM = 30,
208     NAN_TLV_TYPE_SERVICE_ID = 31,
209     NAN_TLV_TYPE_SDF_LAST = 4095,
210 
211     /* Configuration types */
212     NAN_TLV_TYPE_CONFIG_FIRST = 4096,
213     NAN_TLV_TYPE_24G_SUPPORT = NAN_TLV_TYPE_CONFIG_FIRST,
214     NAN_TLV_TYPE_24G_BEACON,
215     NAN_TLV_TYPE_24G_SDF,
216     NAN_TLV_TYPE_24G_RSSI_CLOSE,
217     NAN_TLV_TYPE_24G_RSSI_MIDDLE = 4100,
218     NAN_TLV_TYPE_24G_RSSI_CLOSE_PROXIMITY,
219     NAN_TLV_TYPE_5G_SUPPORT,
220     NAN_TLV_TYPE_5G_BEACON,
221     NAN_TLV_TYPE_5G_SDF,
222     NAN_TLV_TYPE_5G_RSSI_CLOSE,
223     NAN_TLV_TYPE_5G_RSSI_MIDDLE,
224     NAN_TLV_TYPE_5G_RSSI_CLOSE_PROXIMITY,
225     NAN_TLV_TYPE_SID_BEACON,
226     NAN_TLV_TYPE_HOP_COUNT_LIMIT,
227     NAN_TLV_TYPE_MASTER_PREFERENCE = 4110,
228     NAN_TLV_TYPE_CLUSTER_ID_LOW,
229     NAN_TLV_TYPE_CLUSTER_ID_HIGH,
230     NAN_TLV_TYPE_RSSI_AVERAGING_WINDOW_SIZE,
231     NAN_TLV_TYPE_CLUSTER_OUI_NETWORK_ID,
232     NAN_TLV_TYPE_SOURCE_MAC_ADDRESS,
233     NAN_TLV_TYPE_CLUSTER_ATTRIBUTE_IN_SDF,
234     NAN_TLV_TYPE_SOCIAL_CHANNEL_SCAN_PARAMS,
235     NAN_TLV_TYPE_DEBUGGING_FLAGS,
236     NAN_TLV_TYPE_POST_NAN_CONNECTIVITY_CAPABILITIES_TRANSMIT,
237     NAN_TLV_TYPE_POST_NAN_DISCOVERY_ATTRIBUTE_TRANSMIT = 4120,
238     NAN_TLV_TYPE_FURTHER_AVAILABILITY_MAP,
239     NAN_TLV_TYPE_HOP_COUNT_FORCE,
240     NAN_TLV_TYPE_RANDOM_FACTOR_FORCE,
241     NAN_TLV_TYPE_RANDOM_UPDATE_TIME = 4124,
242     NAN_TLV_TYPE_EARLY_WAKEUP,
243     NAN_TLV_TYPE_PERIODIC_SCAN_INTERVAL,
244     NAN_TLV_TYPE_DW_INTERVAL = 4128,
245     NAN_TLV_TYPE_DB_INTERVAL,
246     NAN_TLV_TYPE_FURTHER_AVAILABILITY,
247     NAN_TLV_TYPE_24G_CHANNEL,
248     NAN_TLV_TYPE_5G_CHANNEL,
249     NAN_TLV_TYPE_DISC_MAC_ADDR_RANDOM_INTERVAL,
250     NAN_TLV_TYPE_RANGING_AUTO_RESPONSE_CFG = 4134,
251     NAN_TLV_TYPE_SUBSCRIBE_SID_BEACON = 4135,
252     NAN_TLV_TYPE_DW_EARLY_TERMINATION = 4136,
253     NAN_TLV_TYPE_TX_RX_CHAINS = 4137,
254     NAN_TLV_TYPE_ENABLE_DEVICE_RANGING = 4138,
255     NAN_TLV_TYPE_CONFIG_LAST = 8191,
256 
257     /* Attributes types */
258     NAN_TLV_TYPE_ATTRS_FIRST = 8192,
259     NAN_TLV_TYPE_AVAILABILITY_INTERVALS_MAP = NAN_TLV_TYPE_ATTRS_FIRST,
260     NAN_TLV_TYPE_WLAN_MESH_ID,
261     NAN_TLV_TYPE_MAC_ADDRESS,
262     NAN_TLV_TYPE_RECEIVED_RSSI_VALUE,
263     NAN_TLV_TYPE_CLUSTER_ATTRIBUTE,
264     NAN_TLV_TYPE_WLAN_INFRA_SSID,
265     NAN_TLV_TYPE_ATTRS_LAST = 12287,
266 
267     /* Events Type */
268     NAN_TLV_TYPE_EVENTS_FIRST = 12288,
269     NAN_TLV_TYPE_EVENT_SELF_STATION_MAC_ADDRESS = NAN_TLV_TYPE_EVENTS_FIRST,
270     NAN_TLV_TYPE_EVENT_STARTED_CLUSTER,
271     NAN_TLV_TYPE_EVENT_JOINED_CLUSTER,
272     NAN_TLV_TYPE_EVENT_CLUSTER_SCAN_RESULTS,
273     NAN_TLV_TYPE_FAW_MEM_AVAIL,
274     NAN_TLV_TYPE_EVENTS_LAST = 16383,
275 
276     /* TCA types */
277     NAN_TLV_TYPE_TCA_FIRST = 16384,
278     NAN_TLV_TYPE_CLUSTER_SIZE_REQ = NAN_TLV_TYPE_TCA_FIRST,
279     NAN_TLV_TYPE_CLUSTER_SIZE_RSP,
280     NAN_TLV_TYPE_TCA_LAST = 32767,
281 
282     /* Statistics types */
283     NAN_TLV_TYPE_STATS_FIRST = 32768,
284     NAN_TLV_TYPE_DE_PUBLISH_STATS = NAN_TLV_TYPE_STATS_FIRST,
285     NAN_TLV_TYPE_DE_SUBSCRIBE_STATS,
286     NAN_TLV_TYPE_DE_MAC_STATS,
287     NAN_TLV_TYPE_DE_TIMING_SYNC_STATS,
288     NAN_TLV_TYPE_DE_DW_STATS,
289     NAN_TLV_TYPE_DE_STATS,
290     NAN_TLV_TYPE_STATS_LAST = 36863,
291 
292     /* Testmode types */
293     NAN_TLV_TYPE_TESTMODE_FIRST = 36864,
294     NAN_TLV_TYPE_TESTMODE_GENERIC_CMD = NAN_TLV_TYPE_TESTMODE_FIRST,
295     NAN_TLV_TYPE_TESTMODE_LAST = 37000,
296 
297     NAN_TLV_TYPE_LAST = 65535
298 } NanTlvType;
299 
300 /* 8-byte control message header used by NAN*/
301 typedef struct PACKED
302 {
303    u16 msgVersion:4;
304    u16 msgId:12;
305    u16 msgLen;
306    u16 handle;
307    u16 transactionId;
308 } NanMsgHeader, *pNanMsgHeader;
309 
310 /* Enumeration for Version */
311 typedef enum
312 {
313    NAN_MSG_VERSION1 = 1,
314 }NanMsgVersion;
315 
316 typedef struct PACKED
317 {
318     u16 type;
319     u16 length;
320     u8* value;
321 } NanTlv, *pNanTlv;
322 
323 #define SIZEOF_TLV_HDR (sizeof(NanTlv::type) + sizeof(NanTlv::length))
324 /* NAN TLV Groups and Types */
325 typedef enum
326 {
327     NAN_TLV_GROUP_FIRST = 0,
328     NAN_TLV_GROUP_SDF = NAN_TLV_GROUP_FIRST,
329     NAN_TLV_GROUP_CONFIG,
330     NAN_TLV_GROUP_STATS,
331     NAN_TLV_GROUP_ATTRS,
332     NAN_TLV_NUM_GROUPS,
333     NAN_TLV_GROUP_LAST = NAN_TLV_NUM_GROUPS
334 } NanTlvGroup;
335 
336 /* NAN Miscellaneous Constants */
337 #define NAN_TTL_INFINITE            0
338 #define NAN_REPLY_COUNT_INFINITE    0
339 
340 /* NAN Confguration 5G Channel Access Bit */
341 #define NAN_5G_CHANNEL_ACCESS_UNSUPPORTED   0
342 #define NAN_5G_CHANNEL_ACCESS_SUPPORTED     1
343 
344 /* NAN Configuration Service IDs Enclosure Bit */
345 #define NAN_SIDS_NOT_ENCLOSED_IN_BEACONS    0
346 #define NAN_SIBS_ENCLOSED_IN_BEACONS        1
347 
348 /* NAN Configuration Priority */
349 #define NAN_CFG_PRIORITY_SERVICE_DISCOVERY  0
350 #define NAN_CFG_PRIORITY_DATA_CONNECTION    1
351 
352 /* NAN Configuration 5G Channel Usage */
353 #define NAN_5G_CHANNEL_USAGE_SYNC_AND_DISCOVERY 0
354 #define NAN_5G_CHANNEL_USAGE_DISCOVERY_ONLY     1
355 
356 /* NAN Configuration TX_Beacon Content */
357 #define NAN_TX_BEACON_CONTENT_OLD_AM_INFO       0
358 #define NAN_TX_BEACON_CONTENT_UPDATED_AM_INFO   1
359 
360 /* NAN Configuration Miscellaneous Constants */
361 #define NAN_MAC_INTERFACE_PERIODICITY_MIN   30
362 #define NAN_MAC_INTERFACE_PERIODICITY_MAX   255
363 
364 #define NAN_DW_RANDOM_TIME_MIN  120
365 #define NAN_DW_RANDOM_TIME_MAX  240
366 
367 #define NAN_INITIAL_SCAN_MIN_IDEAL_PERIOD   200
368 #define NAN_INITIAL_SCAN_MAX_IDEAL_PERIOD   300
369 
370 #define NAN_ONGOING_SCAN_MIN_PERIOD 10
371 #define NAN_ONGOING_SCAN_MAX_PERIOD 30
372 
373 #define NAN_HOP_COUNT_LIMIT 5
374 
375 #define NAN_WINDOW_DW   0
376 #define NAN_WINDOW_FAW  1
377 
378 #define NAN_TLV_HEADER_SIZE 4
379 
380 /* NAN Error Rsp */
381 typedef struct PACKED
382 {
383     NanMsgHeader fwHeader;
384     u16 status;
385     u16 value;
386 } NanErrorRspMsg, *pNanErrorRspMsg;
387 
388 //* NAN Publish Service Req */
389 typedef struct PACKED
390 {
391     u16 ttl;
392     u16 period;
393     u32 replyIndFlag:1;
394     u32 publishType:2;
395     u32 txType:1;
396     u32 rssiThresholdFlag:1;
397     u32 ota_flag:1;
398     u32 matchAlg:2;
399     u32 count:8;
400     u32 connmap:8;
401     u32 pubTerminatedIndDisableFlag:1;
402     u32 pubMatchExpiredIndDisableFlag:1;
403     u32 followupRxIndDisableFlag:1;
404     u32 reserved2:5;
405     /*
406      * Excludes TLVs
407      *
408      * Required: Service Name,
409      * Optional: Tx Match Filter, Rx Match Filter, Service Specific Info,
410      */
411 } NanPublishServiceReqParams, *pNanPublishServiceReqParams;
412 
413 typedef struct PACKED
414 {
415     NanMsgHeader fwHeader;
416     NanPublishServiceReqParams publishServiceReqParams;
417     u8 ptlv[];
418 } NanPublishServiceReqMsg, *pNanPublishServiceReqMsg;
419 
420 /* NAN Publish Service Rsp */
421 typedef struct PACKED
422 {
423     NanMsgHeader fwHeader;
424     /* status of the request */
425     u16 status;
426     u16 value;
427 } NanPublishServiceRspMsg, *pNanPublishServiceRspMsg;
428 
429 /* NAN Publish Service Cancel Req */
430 typedef struct PACKED
431 {
432     NanMsgHeader fwHeader;
433 } NanPublishServiceCancelReqMsg, *pNanPublishServiceCancelReqMsg;
434 
435 /* NAN Publish Service Cancel Rsp */
436 typedef struct PACKED
437 {
438     NanMsgHeader fwHeader;
439     /* status of the request */
440     u16 status;
441     u16 value;
442 } NanPublishServiceCancelRspMsg, *pNanPublishServiceCancelRspMsg;
443 
444 /* NAN Publish Terminated Ind */
445 typedef struct PACKED
446 {
447     NanMsgHeader fwHeader;
448     /* reason for the termination */
449     u16 reason;
450     u16 reserved;
451 } NanPublishTerminatedIndMsg, *pNanPublishTerminatedIndMsg;
452 
453 /* Params for NAN Publish Replied Ind */
454 typedef struct PACKED
455 {
456   u32  matchHandle;
457 } NanPublishRepliedIndParams;
458 
459 /* NAN Publish Replied Ind */
460 typedef struct PACKED
461 {
462     NanMsgHeader fwHeader;
463     NanPublishRepliedIndParams publishRepliedIndParams;
464     /*
465      * Excludes TLVs
466      *
467      * Required: MAC Address
468      * Optional: Received RSSI Value
469      *
470      */
471     u8 ptlv[];
472 } NanPublishRepliedIndMsg, *pNanPublishRepliedIndMsg;
473 
474 /* NAN Device Capability Attribute */
475 typedef struct PACKED
476 {
477     u32 dfs_master:1;
478     u32 ext_key_id:1;
479     u32 simu_ndp_data_recept:1;
480     u32 ndpe_attr_supp:1;
481     u32 reserved:28;
482 } NanDevCapAttrCap, *pNanDevCapAttrCap;
483 
484 /* NAN Subscribe Service Req */
485 typedef struct PACKED
486 {
487     u16 ttl;
488     u16 period;
489     u32 subscribeType:1;
490     u32 srfAttr:1;
491     u32 srfInclude:1;
492     u32 srfSend:1;
493     u32 ssiRequired:1;
494     u32 matchAlg:2;
495     u32 xbit:1;
496     u32 count:8;
497     u32 rssiThresholdFlag:1;
498     u32 ota_flag:1;
499     u32 subTerminatedIndDisableFlag:1;
500     u32 subMatchExpiredIndDisableFlag:1;
501     u32 followupRxIndDisableFlag:1;
502     u32 reserved:3;
503     u32 connmap:8;
504     /*
505      * Excludes TLVs
506      *
507      * Required: Service Name
508      * Optional: Rx Match Filter, Tx Match Filter, Service Specific Info,
509      */
510 } NanSubscribeServiceReqParams, *pNanSubscribeServiceReqParams;
511 
512 typedef struct PACKED
513 {
514     NanMsgHeader fwHeader;
515     NanSubscribeServiceReqParams subscribeServiceReqParams;
516     u8 ptlv[];
517 } NanSubscribeServiceReqMsg, *pNanSubscribeServiceReqMsg;
518 
519 /* NAN Subscribe Service Rsp */
520 typedef struct PACKED
521 {
522     NanMsgHeader fwHeader;
523     /* status of the request */
524     u16 status;
525     u16 value;
526 } NanSubscribeServiceRspMsg, *pNanSubscribeServiceRspMsg;
527 
528 /* NAN Subscribe Service Cancel Req */
529 typedef struct PACKED
530 {
531     NanMsgHeader fwHeader;
532 } NanSubscribeServiceCancelReqMsg, *pNanSubscribeServiceCancelReqMsg;
533 
534 /* NAN Subscribe Service Cancel Rsp */
535 typedef struct PACKED
536 {
537     NanMsgHeader fwHeader;
538     /* status of the request */
539     u16 status;
540     u16 value;
541 } NanSubscribeServiceCancelRspMsg, *pNanSubscribeServiceCancelRspMsg;
542 
543 /* NAN Subscribe Match Ind */
544 typedef struct PACKED
545 {
546     u32 matchHandle;
547     u32 matchOccuredFlag:1;
548     u32 outOfResourceFlag:1;
549     u32 reserved:30;
550 } NanMatchIndParams;
551 
552 typedef struct PACKED
553 {
554     NanMsgHeader fwHeader;
555     NanMatchIndParams matchIndParams;
556     u8 ptlv[];
557 } NanMatchIndMsg, *pNanMatchIndMsg;
558 
559 /* NAN Subscribe Unmatch Ind */
560 typedef struct PACKED
561 {
562     u32 matchHandle;
563 } NanmatchExpiredIndParams;
564 
565 typedef struct PACKED
566 {
567     NanMsgHeader fwHeader;
568     NanmatchExpiredIndParams matchExpiredIndParams;
569 } NanMatchExpiredIndMsg, *pNanMatchExpiredIndMsg;
570 
571 /* NAN Subscribe Terminated Ind */
572 typedef struct PACKED
573 {
574     NanMsgHeader fwHeader;
575     /* reason for the termination */
576     u16 reason;
577     u16 reserved;
578 } NanSubscribeTerminatedIndMsg, *pNanSubscribeTerminatedIndMsg;
579 
580 /* Event Ind */
581 typedef struct PACKED
582 {
583     u32 eventId:8;
584     u32 reserved:24;
585 } NanEventIndParams;
586 
587 typedef struct PACKED
588 {
589     NanMsgHeader fwHeader;
590     u8 ptlv[];
591 } NanEventIndMsg, *pNanEventIndMsg;
592 
593 /* NAN Transmit Followup Req */
594 typedef struct PACKED
595 {
596     u32 matchHandle;
597     u32 priority:4;
598     u32 window:1;
599     u32 followupTxRspDisableFlag:1;
600     u32 reserved:26;
601     /*
602      * Excludes TLVs
603      *
604      * Required: Service Specific Info or Extended Service Specific Info
605      */
606 } NanTransmitFollowupReqParams;
607 
608 typedef struct PACKED
609 {
610     NanMsgHeader fwHeader;
611     NanTransmitFollowupReqParams transmitFollowupReqParams;
612     u8 ptlv[];
613 } NanTransmitFollowupReqMsg, *pNanTransmitFollowupReqMsg;
614 
615 /* NAN Transmit Followup Rsp */
616 typedef struct PACKED
617 {
618     NanMsgHeader fwHeader;
619     /* status of the request */
620     u16 status;
621     u16 value;
622 } NanTransmitFollowupRspMsg, *pNanTransmitFollowupRspMsg;
623 
624 /* NAN Publish Followup Ind */
625 typedef struct PACKED
626 {
627     u32 matchHandle;
628     u32 window:1;
629     u32 reserved:31;
630     /*
631      * Excludes TLVs
632      *
633      * Required: Service Specific Info or Extended Service Specific Info
634      */
635 } NanFollowupIndParams;
636 
637 typedef struct PACKED
638 {
639     NanMsgHeader fwHeader;
640     NanFollowupIndParams followupIndParams;
641     u8 ptlv[];
642 } NanFollowupIndMsg, *pNanFollowupIndMsg;
643 
644 /* NAN Statistics Req */
645 typedef struct PACKED
646 {
647     u32 statsType:8;
648     u32 clear:1;
649     u32 reserved:23;
650 } NanStatsReqParams, *pNanStatsReqParams;
651 
652 typedef struct PACKED
653 {
654     NanMsgHeader fwHeader;
655     NanStatsReqParams statsReqParams;
656 } NanStatsReqMsg, *pNanStatsReqMsg;
657 
658 /* NAN Statistics Rsp */
659 typedef struct PACKED
660 {
661     /* status of the request */
662     u16 status;
663     u16 value;
664     u8 statsType;
665     u8 reserved;
666 } NanStatsRspParams, *pNanStatsRspParams;
667 
668 typedef struct PACKED
669 {
670     NanMsgHeader fwHeader;
671     NanStatsRspParams statsRspParams;
672     u8 ptlv[];
673 } NanStatsRspMsg, *pNanStatsRspMsg;
674 
675 typedef struct PACKED
676 {
677     u8 count:7;
678     u8 s:1;
679 } NanSidAttr, *pSidAttr;
680 
681 
682 /* NAN Configuration Req */
683 typedef struct PACKED
684 {
685     NanMsgHeader fwHeader;
686     /*
687      * TLVs:
688      *
689      * Required: None.
690      * Optional: SID, Random Time, Master Preference, WLAN Intra Attr,
691      *           P2P Operation Attr, WLAN IBSS Attr, WLAN Mesh Attr
692      */
693     u8 ptlv[];
694 } NanConfigurationReqMsg, *pNanConfigurationReqMsg;
695 
696 /*
697  * Because the Configuration Req message has TLVs in it use the macro below
698  * for the size argument to buffer allocation functions (vs. sizeof(msg)).
699  */
700 #define NAN_MAX_CONFIGURATION_REQ_SIZE                       \
701     (                                                        \
702         sizeof(NanMsgHeader)                             +   \
703         SIZEOF_TLV_HDR + sizeof(u8)  /* SID Beacon    */ +   \
704         SIZEOF_TLV_HDR + sizeof(u8)  /* Random Time   */ +   \
705         SIZEOF_TLV_HDR + sizeof(u8)  /* Master Pref   */     \
706     )
707 
708 /* NAN Configuration Rsp */
709 typedef struct PACKED
710 {
711     NanMsgHeader fwHeader;
712     /* status of the request */
713     u16 status;
714     u16 value;
715 } NanConfigurationRspMsg, *pNanConfigurationRspMsg;
716 
717 /*
718  * Because the Enable Req message has TLVs in it use the macro below for
719  * the size argument to buffer allocation functions (vs. sizeof(msg)).
720  */
721 #define NAN_MAX_ENABLE_REQ_SIZE                                 \
722     (                                                           \
723         sizeof(NanMsgHeader)                                +   \
724         SIZEOF_TLV_HDR + sizeof(u16) /* Cluster Low   */    +   \
725         SIZEOF_TLV_HDR + sizeof(u16) /* Cluster High  */    +   \
726         SIZEOF_TLV_HDR + sizeof(u8)  /* Master Pref   */        \
727     )
728 
729 /* Config Discovery Indication */
730  typedef struct PACKED
731  {
732     u32 disableDiscoveryMacAddressEvent:1;
733     u32 disableDiscoveryStartedClusterEvent:1;
734     u32 disableDiscoveryJoinedClusterEvent:1;
735     u32 reserved:29;
736  } NanConfigDiscoveryIndications;
737 
738 /* NAN Enable Req */
739 typedef struct PACKED
740 {
741     NanMsgHeader fwHeader;
742     /*
743      * TLVs:
744      *
745      * Required: Cluster Low, Cluster High, Master Preference,
746      * Optional: 5G Support, SID, 5G Sync Disc, RSSI Close, RSSI Medium,
747      *           Hop Count Limit, Random Time, Master Preference,
748      *           WLAN Intra Attr, P2P Operation Attr, WLAN IBSS Attr,
749      *           WLAN Mesh Attr
750      */
751     u8 ptlv[];
752 } NanEnableReqMsg, *pNanEnableReqMsg;
753 
754 /* NAN Enable Rsp */
755 typedef struct PACKED
756 {
757     NanMsgHeader fwHeader;
758     /* status of the request */
759     u16 status;
760     u16 value;
761 } NanEnableRspMsg, *pNanEnableRspMsg;
762 
763 /* NAN Disable Req */
764 typedef struct PACKED
765 {
766     NanMsgHeader fwHeader;
767 } NanDisableReqMsg, *pNanDisableReqMsg;
768 
769 /* NAN Disable Rsp */
770 typedef struct PACKED
771 {
772     NanMsgHeader fwHeader;
773     /* status of the request */
774     u16 status;
775     u16 reserved;
776 } NanDisableRspMsg, *pNanDisableRspMsg;
777 
778 /* NAN Disable Ind */
779 typedef struct PACKED
780 {
781     NanMsgHeader fwHeader;
782     /* reason for the termination */
783     u16 reason;
784     u16 reserved;
785 } NanDisableIndMsg, *pNanDisableIndMsg;
786 
787 typedef struct PACKED
788 {
789     NanMsgHeader fwHeader;
790     u8 ptlv[];
791 } NanTcaReqMsg, *pNanTcaReqMsg;
792 
793 /* NAN TCA Rsp */
794 typedef struct PACKED
795 {
796     NanMsgHeader   fwHeader;
797     /* status of the request */
798     u16 status;
799     u16 value;
800 } NanTcaRspMsg, *pNanTcaRspMsg;
801 
802 typedef struct PACKED
803 {
804     NanMsgHeader fwHeader;
805     /*
806      * TLVs:
807      *
808      * Optional: Cluster size.
809      */
810     u8 ptlv[];
811 } NanTcaIndMsg, *pNanTcaIndMsg;
812 
813 /*
814  * Because the TCA Ind message has TLVs in it use the macro below for the
815  * size argument to buffer allocation functions (vs. sizeof(msg)).
816  */
817 #define NAN_MAX_TCA_IND_SIZE                                 \
818     (                                                        \
819         sizeof(NanMsgHeader)                             +   \
820         sizeof(NanTcaIndParams)                          +   \
821         SIZEOF_TLV_HDR + sizeof(u16) /* Cluster Size */      \
822     )
823 
824 /* Function Declarations */
825 u8* addTlv(u16 type, u16 length, const u8* value, u8* pOutTlv);
826 u16 NANTLV_ReadTlv(u8 *pInTlv, pNanTlv pOutTlv, int inBufferSize);
827 u16 NANTLV_WriteTlv(pNanTlv pInTlv, u8 *pOutTlv);
828 
829 /* NAN Beacon Sdf Payload Req */
830 typedef struct PACKED
831 {
832     NanMsgHeader fwHeader;
833     /*
834      * TLVs:
835      *
836      * Optional: Vendor specific attribute
837      */
838     u8 ptlv[];
839 } NanBeaconSdfPayloadReqMsg, *pNanBeaconSdfPayloadReqMsg;
840 
841 /* NAN Beacon Sdf Payload Rsp */
842 typedef struct PACKED
843 {
844     NanMsgHeader   fwHeader;
845     /* status of the request */
846     u16 status;
847     u16 reserved;
848 } NanBeaconSdfPayloadRspMsg, *pNanBeaconSdfPayloadRspMsg;
849 
850 /* NAN Beacon Sdf Payload Ind */
851 typedef struct PACKED
852 {
853     NanMsgHeader fwHeader;
854     /*
855      * TLVs:
856      *
857      * Required: Mac address
858      * Optional: Vendor specific attribute, sdf payload
859      * receive
860      */
861     u8 ptlv[];
862 } NanBeaconSdfPayloadIndMsg, *pNanBeaconSdfPayloadIndMsg;
863 
864 typedef struct PACKED
865 {
866     u8 availIntDuration:2;
867     u8 mapId:4;
868     u8 reserved:2;
869 } NanApiEntryCtrl;
870 
871 /*
872  * Valid Operating Classes were derived from IEEE Std. 802.11-2012 Annex E
873  * Table E-4 Global Operating Classe and, filtered by channel, are: 81, 83,
874  * 84, 103, 114, 115, 116, 124, 125.
875  */
876 typedef struct PACKED
877 {
878     NanApiEntryCtrl entryCtrl;
879     u8 opClass;
880     u8 channel;
881     u8 availIntBitmap[4];
882 } NanFurtherAvailabilityChan, *pNanFurtherAvailabilityChan;
883 
884 typedef struct PACKED
885 {
886     u8 numChan;
887     u8 pFaChan[];
888 } NanFurtherAvailabilityMapAttrTlv, *pNanFurtherAvailabilityMapAttrTlv;
889 
890 /* Publish statistics. */
891 typedef struct PACKED
892 {
893     u32 validPublishServiceReqMsgs;
894     u32 validPublishServiceRspMsgs;
895     u32 validPublishServiceCancelReqMsgs;
896     u32 validPublishServiceCancelRspMsgs;
897     u32 validPublishRepliedIndMsgs;
898     u32 validPublishTerminatedIndMsgs;
899     u32 validActiveSubscribes;
900     u32 validMatches;
901     u32 validFollowups;
902     u32 invalidPublishServiceReqMsgs;
903     u32 invalidPublishServiceCancelReqMsgs;
904     u32 invalidActiveSubscribes;
905     u32 invalidMatches;
906     u32 invalidFollowups;
907     u32 publishCount;
908     u32 publishNewMatchCount;
909     u32 pubsubGlobalNewMatchCount;
910 } FwNanPublishStats, *pFwNanPublishStats;
911 
912 /* Subscribe statistics. */
913 typedef struct PACKED
914 {
915     u32 validSubscribeServiceReqMsgs;
916     u32 validSubscribeServiceRspMsgs;
917     u32 validSubscribeServiceCancelReqMsgs;
918     u32 validSubscribeServiceCancelRspMsgs;
919     u32 validSubscribeTerminatedIndMsgs;
920     u32 validSubscribeMatchIndMsgs;
921     u32 validSubscribeUnmatchIndMsgs;
922     u32 validSolicitedPublishes;
923     u32 validMatches;
924     u32 validFollowups;
925     u32 invalidSubscribeServiceReqMsgs;
926     u32 invalidSubscribeServiceCancelReqMsgs;
927     u32 invalidSubscribeFollowupReqMsgs;
928     u32 invalidSolicitedPublishes;
929     u32 invalidMatches;
930     u32 invalidFollowups;
931     u32 subscribeCount;
932     u32 bloomFilterIndex;
933     u32 subscribeNewMatchCount;
934     u32 pubsubGlobalNewMatchCount;
935 } FwNanSubscribeStats, *pFwNanSubscribeStats;
936 
937 /* NAN MAC Statistics. Used for MAC and DW statistics. */
938 typedef struct PACKED
939 {
940     /* RX stats */
941     u32 validFrames;
942     u32 validActionFrames;
943     u32 validBeaconFrames;
944     u32 ignoredActionFrames;
945     u32 ignoredBeaconFrames;
946     u32 invalidFrames;
947     u32 invalidActionFrames;
948     u32 invalidBeaconFrames;
949     u32 invalidMacHeaders;
950     u32 invalidPafHeaders;
951     u32 nonNanBeaconFrames;
952 
953     u32 earlyActionFrames;
954     u32 inDwActionFrames;
955     u32 lateActionFrames;
956 
957     /* TX stats */
958     u32 framesQueued;
959     u32 totalTRSpUpdates;
960     u32 completeByTRSp;
961     u32 completeByTp75DW;
962     u32 completeByTendDW;
963     u32 lateActionFramesTx;
964 
965     /* Misc stats - ignored for DW. */
966     u32 twIncreases;
967     u32 twDecreases;
968     u32 twChanges;
969     u32 twHighwater;
970     u32 bloomFilterIndex;
971 } FwNanMacStats, *pFwNanMacStats;
972 
973 /* NAN Sync and DW Statistics*/
974 typedef struct PACKED
975 {
976     u64 currTsf;
977     u64 myRank;
978     u64 currAmRank;
979     u64 lastAmRank;
980     u32 currAmBTT;
981     u32 lastAmBTT;
982     u8  currAmHopCount;
983     u8  currRole;
984     u16 currClusterId;
985     u32 reserved1;
986 
987     u64 timeSpentInCurrRole;
988     u64 totalTimeSpentAsMaster;
989     u64 totalTimeSpentAsNonMasterSync;
990     u64 totalTimeSpentAsNonMasterNonSync;
991     u32 transitionsToAnchorMaster;
992     u32 transitionsToMaster;
993     u32 transitionsToNonMasterSync;
994     u32 transitionsToNonMasterNonSync;
995     u32 amrUpdateCount;
996     u32 amrUpdateRankChangedCount;
997     u32 amrUpdateBTTChangedCount;
998     u32 amrUpdateHcChangedCount;
999     u32 amrUpdateNewDeviceCount;
1000     u32 amrExpireCount;
1001     u32 mergeCount;
1002     u32 beaconsAboveHcLimit;
1003     u32 beaconsBelowRssiThresh;
1004     u32 beaconsIgnoredNoSpace;
1005     u32 beaconsForOurCluster;
1006     u32 beaconsForOtherCluster;
1007     u32 beaconCancelRequests;
1008     u32 beaconCancelFailures;
1009     u32 beaconUpdateRequests;
1010     u32 beaconUpdateFailures;
1011     u32 syncBeaconTxAttempts;
1012     u32 syncBeaconTxFailures;
1013     u32 discBeaconTxAttempts;
1014     u32 discBeaconTxFailures;
1015     u32 amHopCountExpireCount;
1016     u32 ndpChannelFreq;
1017     u32 ndpChannelFreq2;
1018     u32 schedUpdateChannelFreq;
1019 } FwNanSyncStats, *pFwNanSyncStats;
1020 
1021 /* NAN Misc DE Statistics */
1022 typedef struct PACKED
1023 {
1024     u32 validErrorRspMsgs;
1025     u32 validTransmitFollowupReqMsgs;
1026     u32 validTransmitFollowupRspMsgs;
1027     u32 validFollowupIndMsgs;
1028     u32 validConfigurationReqMsgs;
1029     u32 validConfigurationRspMsgs;
1030     u32 validStatsReqMsgs;
1031     u32 validStatsRspMsgs;
1032     u32 validEnableReqMsgs;
1033     u32 validEnableRspMsgs;
1034     u32 validDisableReqMsgs;
1035     u32 validDisableRspMsgs;
1036     u32 validDisableIndMsgs;
1037     u32 validEventIndMsgs;
1038     u32 validTcaReqMsgs;
1039     u32 validTcaRspMsgs;
1040     u32 validTcaIndMsgs;
1041     u32 invalidTransmitFollowupReqMsgs;
1042     u32 invalidConfigurationReqMsgs;
1043     u32 invalidStatsReqMsgs;
1044     u32 invalidEnableReqMsgs;
1045     u32 invalidDisableReqMsgs;
1046     u32 invalidTcaReqMsgs;
1047 } FwNanDeStats, *pFwNanDeStats;
1048 
1049 /*
1050   Definition of various NanIndication(events)
1051 */
1052 typedef enum {
1053     NAN_INDICATION_PUBLISH_REPLIED         =0,
1054     NAN_INDICATION_PUBLISH_TERMINATED      =1,
1055     NAN_INDICATION_MATCH                   =2,
1056     NAN_INDICATION_MATCH_EXPIRED           =3,
1057     NAN_INDICATION_SUBSCRIBE_TERMINATED    =4,
1058     NAN_INDICATION_DE_EVENT                =5,
1059     NAN_INDICATION_FOLLOWUP                =6,
1060     NAN_INDICATION_DISABLED                =7,
1061     NAN_INDICATION_TCA                     =8,
1062     NAN_INDICATION_BEACON_SDF_PAYLOAD      =9,
1063     NAN_INDICATION_SELF_TRANSMIT_FOLLOWUP  =10,
1064     NAN_INDICATION_RANGING_REQUEST_RECEIVED =11,
1065     NAN_INDICATION_RANGING_RESULT           =12,
1066     NAN_INDICATION_UNKNOWN                 =0xFFFF
1067 } NanIndicationType;
1068 
1069 /* NAN Capabilities Req */
1070 typedef struct PACKED
1071 {
1072     NanMsgHeader fwHeader;
1073 } NanCapabilitiesReqMsg, *pNanCapabilitiesReqMsg;
1074 
1075 /* NAN Capabilities Rsp */
1076 typedef struct PACKED
1077 {
1078     NanMsgHeader fwHeader;
1079     /* status of the request */
1080     u32 status;
1081     u32 value;
1082     u32 max_concurrent_nan_clusters;
1083     u32 max_publishes;
1084     u32 max_subscribes;
1085     u32 max_service_name_len;
1086     u32 max_match_filter_len;
1087     u32 max_total_match_filter_len;
1088     u32 max_service_specific_info_len;
1089     u32 max_vsa_data_len;
1090     u32 max_mesh_data_len;
1091     u32 max_ndi_interfaces;
1092     u32 max_ndp_sessions;
1093     u32 max_app_info_len;
1094     u32 max_queued_transmit_followup_msgs;
1095     u32 ndp_supported_bands;
1096     u32 cipher_suites_supported;
1097     u32 max_scid_len;
1098     u32 is_ndp_security_supported:1;
1099     u32 max_sdea_service_specific_info_len:16;
1100     u32 reserved1:5;
1101     u32 reserved2:5;
1102     u32 ndpe_attr_supported:1;
1103     u32 reserved:4;
1104     u32 max_subscribe_address;
1105 } NanCapabilitiesRspMsg, *pNanCapabilitiesRspMsg;
1106 
1107 /* NAN Self Transmit Followup */
1108 typedef struct PACKED
1109 {
1110     NanMsgHeader fwHeader;
1111     u32 reason;
1112 } NanSelfTransmitFollowupIndMsg, *pNanSelfTransmitFollowupIndMsg;
1113 
1114 /* NAN Cipher Suite Shared Key */
1115 typedef struct PACKED
1116 {
1117     u32 csid_type;
1118 } NanCsidType;
1119 
1120 /* Service Discovery Extended Attribute params */
1121 typedef struct PACKED
1122 {
1123     u32 fsd_required:1;
1124     u32 fsd_with_gas:1;
1125     u32 data_path_required:1;
1126     u32 data_path_type:1;
1127     u32 multicast_type:1;
1128     u32 qos_required:1;
1129     u32 security_required:1;
1130     u32 ranging_required:1;
1131     u32 range_limit_present:1;
1132     u32 service_update_ind_present:1;
1133     u32 reserved1:6;
1134     u32 range_report:1;
1135     u32 reserved2:15;
1136 } NanFWSdeaCtrlParams;
1137 
1138 /* NAN Ranging Configuration params */
1139 typedef struct PACKED
1140 {
1141     u32  inner_threshold;
1142     u32  outer_threshold;
1143 } NanFWGeoFenceDescriptor;
1144 
1145 typedef struct PACKED
1146 {
1147     u32 range_resolution;
1148     u32 range_interval;
1149     u32 ranging_indication_event;
1150     NanFWGeoFenceDescriptor geo_fence_threshold;
1151 } NanFWRangeConfigParams;
1152 
1153 typedef struct PACKED
1154 {
1155     NanMsgHeader fwHeader;
1156     /*
1157       Excludes TLVs
1158       Optional: Nan Availability
1159     */
1160     u8 ptlv[];
1161 } NanTestModeReqMsg, *pNanTestModeReqMsg;
1162 
1163 /*
1164   NAN Status codes exchanged between firmware
1165   and WifiHal.
1166 */
1167 typedef enum {
1168     /* NAN Protocol Response Codes */
1169     NAN_I_STATUS_SUCCESS = 0,
1170     NAN_I_STATUS_TIMEOUT = 1,
1171     NAN_I_STATUS_DE_FAILURE = 2,
1172     NAN_I_STATUS_INVALID_MSG_VERSION = 3,
1173     NAN_I_STATUS_INVALID_MSG_LEN = 4,
1174     NAN_I_STATUS_INVALID_MSG_ID = 5,
1175     NAN_I_STATUS_INVALID_HANDLE = 6,
1176     NAN_I_STATUS_NO_SPACE_AVAILABLE = 7,
1177     NAN_I_STATUS_INVALID_PUBLISH_TYPE = 8,
1178     NAN_I_STATUS_INVALID_TX_TYPE = 9,
1179     NAN_I_STATUS_INVALID_MATCH_ALGORITHM = 10,
1180     NAN_I_STATUS_DISABLE_IN_PROGRESS = 11,
1181     NAN_I_STATUS_INVALID_TLV_LEN = 12,
1182     NAN_I_STATUS_INVALID_TLV_TYPE = 13,
1183     NAN_I_STATUS_MISSING_TLV_TYPE = 14,
1184     NAN_I_STATUS_INVALID_TOTAL_TLVS_LEN = 15,
1185     NAN_I_STATUS_INVALID_REQUESTER_INSTANCE_ID= 16,
1186     NAN_I_STATUS_INVALID_TLV_VALUE = 17,
1187     NAN_I_STATUS_INVALID_TX_PRIORITY = 18,
1188     NAN_I_STATUS_INVALID_CONNECTION_MAP = 19,
1189     NAN_I_STATUS_INVALID_THRESHOLD_CROSSING_ALERT_ID = 20,
1190     NAN_I_STATUS_INVALID_STATS_ID = 21,
1191     NAN_I_STATUS_NAN_NOT_ALLOWED = 22,
1192     NAN_I_STATUS_NO_OTA_ACK = 23,
1193     NAN_I_STATUS_TX_FAIL = 24,
1194     NAN_I_STATUS_NAN_ALREADY_ENABLED = 25,
1195     NAN_I_STATUS_FOLLOWUP_QUEUE_FULL = 26,
1196     /* 27-4095 Reserved */
1197     /* NAN Configuration Response codes */
1198     NAN_I_STATUS_INVALID_RSSI_CLOSE_VALUE = 4096,
1199     NAN_I_STATUS_INVALID_RSSI_MIDDLE_VALUE = 4097,
1200     NAN_I_STATUS_INVALID_HOP_COUNT_LIMIT = 4098,
1201     NAN_I_STATUS_INVALID_MASTER_PREFERENCE_VALUE = 4099,
1202     NAN_I_STATUS_INVALID_LOW_CLUSTER_ID_VALUE = 4100,
1203     NAN_I_STATUS_INVALID_HIGH_CLUSTER_ID_VALUE = 4101,
1204     NAN_I_STATUS_INVALID_BACKGROUND_SCAN_PERIOD = 4102,
1205     NAN_I_STATUS_INVALID_RSSI_PROXIMITY_VALUE = 4103,
1206     NAN_I_STATUS_INVALID_SCAN_CHANNEL = 4104,
1207     NAN_I_STATUS_INVALID_POST_NAN_CONNECTIVITY_CAPABILITIES_BITMAP = 4105,
1208     NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_NUMCHAN_VALUE = 4106,
1209     NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_DURATION_VALUE = 4107,
1210     NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_CLASS_VALUE = 4108,
1211     NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_CHANNEL_VALUE = 4109,
1212     NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_AVAILABILITY_INTERVAL_BITMAP_VALUE = 4110,
1213     NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_MAP_ID = 4111,
1214     NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_CONN_TYPE_VALUE = 4112,
1215     NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_DEVICE_ROLE_VALUE = 4113,
1216     NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_DURATION_VALUE = 4114,
1217     NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_BITMAP_VALUE = 4115,
1218     NAN_I_STATUS_MISSING_FUTHER_AVAILABILITY_MAP = 4116,
1219     NAN_I_STATUS_INVALID_BAND_CONFIG_FLAGS = 4117,
1220     NAN_I_STATUS_INVALID_RANDOM_FACTOR_UPDATE_TIME_VALUE = 4118,
1221     NAN_I_STATUS_INVALID_ONGOING_SCAN_PERIOD = 4119,
1222     NAN_I_STATUS_INVALID_DW_INTERVAL_VALUE = 4120,
1223     NAN_I_STATUS_INVALID_DB_INTERVAL_VALUE = 4121,
1224     /* 4122-8191 RESERVED */
1225     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_INVALID = 8192,
1226     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_TIMEOUT = 8193,
1227     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_USER_REQUEST = 8194,
1228     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_FAILURE = 8195,
1229     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_COUNT_REACHED = 8196,
1230     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_DE_SHUTDOWN = 8197,
1231     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_DISABLE_IN_PROGRESS = 8198,
1232     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_POST_DISC_ATTR_EXPIRED = 8199,
1233     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_POST_DISC_LEN_EXCEEDED = 8200,
1234     NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_FURTHER_AVAIL_MAP_EMPTY = 8201,
1235     /* 9000-9500 NDP Status type */
1236     NDP_I_UNSUPPORTED_CONCURRENCY = 9000,
1237     NDP_I_NAN_DATA_IFACE_CREATE_FAILED = 9001,
1238     NDP_I_NAN_DATA_IFACE_DELETE_FAILED = 9002,
1239     NDP_I_DATA_INITIATOR_REQUEST_FAILED = 9003,
1240     NDP_I_DATA_RESPONDER_REQUEST_FAILED = 9004,
1241     NDP_I_INVALID_SERVICE_INSTANCE_ID = 9005,
1242     NDP_I_INVALID_NDP_INSTANCE_ID = 9006,
1243     NDP_I_INVALID_RESPONSE_CODE = 9007,
1244     NDP_I_INVALID_APP_INFO_LEN = 9008,
1245     /* OTA failures and timeouts during negotiation */
1246     NDP_I_MGMT_FRAME_REQUEST_FAILED = 9009,
1247     NDP_I_MGMT_FRAME_RESPONSE_FAILED = 9010,
1248     NDP_I_MGMT_FRAME_CONFIRM_FAILED = 9011,
1249     NDP_I_END_FAILED = 9012,
1250     NDP_I_MGMT_FRAME_END_REQUEST_FAILED = 9013,
1251     NDP_I_MGMT_FRAME_SECURITY_INSTALL_FAILED = 9014,
1252 
1253     /* 9500 onwards vendor specific error codes */
1254     NDP_I_VENDOR_SPECIFIC_ERROR = 9500
1255 } NanInternalStatusType;
1256 
1257 /* This is the TLV used for range report */
1258 typedef struct PACKED
1259 {
1260     u32 publish_id;
1261     u32 event_type;
1262     u32 range_measurement;
1263 } NanFWRangeReportParams;
1264 
1265 typedef struct PACKED
1266 {
1267     NanMsgHeader fwHeader;
1268     /*TLV Required:
1269         MANDATORY
1270             1. MAC_ADDRESS
1271             2. NanFWRangeReportParams
1272         OPTIONAL:
1273             1. A_UINT32 event type
1274     */
1275     u8 ptlv[1];
1276 } NanFWRangeReportInd, *pNanFWRangeReportInd;
1277 
1278 /** 2 word representation of MAC addr */
1279 typedef struct {
1280     /** upper 4 bytes of  MAC address */
1281     u32 mac_addr31to0;
1282     /** lower 2 bytes of  MAC address */
1283     u32 mac_addr47to32;
1284 } fw_mac_addr;
1285 
1286 /* This is the TLV used to trigger ranging requests*/
1287 typedef struct PACKED
1288 {
1289     fw_mac_addr  range_mac_addr;
1290     u32 range_id; //Match handle in match_ind, publish_id in result ind
1291     u32 ranging_accept:1;
1292     u32 ranging_reject:1;
1293     u32 ranging_cancel:1;
1294     u32 reserved:29;
1295 } NanFWRangeReqMsg, *pNanFWRangeReqMsg;
1296 
1297 typedef struct PACKED
1298 {
1299     fw_mac_addr  range_mac_addr;
1300     u32 range_id;//This will publish_id in case of receiving publish.
1301 } NanFWRangeReqRecvdMsg, *pNanFWRangeReqRecvdMsg;
1302 
1303 typedef struct PACKED
1304 {
1305     NanMsgHeader fwHeader;
1306     /*TLV Required
1307        1. t_nan_range_req_recvd_msg
1308     */
1309     u8 ptlv[1];
1310 } NanFWRangeReqRecvdInd, *pNanFWRangeReqRecvdInd;
1311 
1312 /* Function for NAN error translation
1313    For NanResponse, NanPublishTerminatedInd, NanSubscribeTerminatedInd,
1314    NanDisabledInd, NanTransmitFollowupInd:
1315    function to translate firmware specific errors
1316    to generic freamework error along with the error string
1317 */
1318 void NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd,
1319                          u32 valueRcvd,
1320                          void *pRsp,
1321                          bool is_ndp_rsp);
1322 
1323 #ifdef __cplusplus
1324 }
1325 #endif /* __cplusplus */
1326 
1327 #endif /* __NAN_I_H__ */
1328 
1329