1 /*
2  * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
3 
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above
10  *       copyright notice, this list of conditions and the following
11  *       disclaimer in the documentation and/or other materials provided
12  *       with the distribution.
13  *     * Neither the name of The Linux Foundation nor the names of its
14  *       contributors may be used to endorse or promote products derived
15  *       from this software without specific prior written permission.
16 
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __NAN_CERT_H__
31 #define __NAN_CERT_H__
32 
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif /* __cplusplus */
38 
39 #ifndef PACKED
40 #define PACKED  __attribute__((packed))
41 #endif
42 #define NAN_CERT_VERSION                        5
43 #define NAN_MAX_DEBUG_MESSAGE_DATA_LEN          100
44 #define NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL       16
45 
46 typedef struct {
47     /* NAN master rank being advertised by DE */
48     u64 master_rank;
49     /* NAN master preference being advertised by DE */
50     u8 master_pref;
51     /* random value being advertised by DE */
52     u8 random_factor;
53     /* hop_count from anchor master */
54     u8 hop_count;
55     u32 beacon_transmit_time;
56     /* NDP channel Frequency */
57     u32 ndp_channel_freq;
58 } NanStaParameter;
59 
60 /* NAN Data Path Supported Band */
61 typedef enum {
62     NAN_DATA_PATH_SUPPORTED_BAND_2G = 1,
63     NAN_DATA_PATH_SUPPORTED_BAND_5G = 2,
64     NAN_DATA_PATH_SUPPORT_DUAL_BAND = 3
65 } NdpSupportedBand;
66 
67 /* NAN Responder mode policy */
68 typedef enum {
69     NAN_DATA_RESPONDER_MODE_AUTO    = 0,
70     NAN_DATA_RESPONDER_MODE_ACCEPT  = 1,
71     NAN_DATA_RESPONDER_MODE_REJECT  = 2,
72     NAN_DATA_RESPONDER_MODE_COUNTER = 3,
73     NAN_DATA_RESPONDER_MODE_COUNTER_NO_CHANNEL_CHANGE = 4
74 } NanDataResponderMode;
75 
76 /* NAN Data Path M4 response type */
77 typedef enum {
78     NAN_DATA_PATH_M4_RESPONSE_ACCEPT = 1,
79     NAN_DATA_PATH_M4_RESPONSE_REJECT = 2,
80     NAN_DATA_PATH_M4_RESPONSE_BADMIC = 3
81 } NdpM4ResponseType;
82 
83 /* NAN NMF Security Clear type */
84 typedef enum {
85     NAN_NMF_CLEAR_DISABLE = 0,
86     NAN_NMF_CLEAR_ENABLE = 1
87 } NanNmfClearConfig;
88 
89 /* NAN Schedule type */
90 typedef enum {
91     NAN_SCHED_VALID = 0,
92     NAN_SCHED_INVALID_BAD_FA = 1,
93     NAN_SCHED_INVALID_BAD_NDC = 2,
94     NAN_SCHED_INVALID_BAD_IMMU = 3
95 } NanSchedType;
96 
97 /* NAN device type */
98 typedef enum {
99     NAN_DEVICE_TYPE_TEST_BED = 1,
100     NAN_DEVICE_TYPE_DUT = 2
101 } NanDeviceType;
102 
103 /* NAN NDPE absent or present */
104 typedef enum {
105     NAN_NDPE_ATTR_PRESENT = 0,
106     NAN_NDPE_ATTR_ABSENT = 1
107 } NanNdpeAttrType;
108 
109 /* NAN NDP absent or present */
110 typedef enum {
111     NAN_NDP_ATTR_ABSENT = 0,
112     NAN_NDP_ATTR_PRESENT = 1
113 } NanNdpAttrType;
114 
115 /* NAN IPV6 implicit or explicit */
116 typedef enum {
117    NAN_IPV6_EXPLICIT = 0,
118    NAN_IPV6_IMPLICIT = 1
119 } NanIPv6Type;
120 
121 /* NAN IPV6 address, port number and protocol type */
122 #define NAN_MSG_IPV6_INTF_ADDR_LEN    16
123 
124 typedef struct PACKED
125 {
126     /* Presence of ipv6_intf_addr */
127     u32 ipv6_addr_present;
128     /* Presence of transport Port */
129     u32 trans_port_present;
130     /* Presence of  transport Protocol */
131     u32 trans_proto_present;
132     /* ipv6 Interface address */
133     u8  ipv6_intf_addr[NAN_MSG_IPV6_INTF_ADDR_LEN];
134     /* Transport Port */
135     u32 transport_port;
136     /* Transport Protocol */
137     u32 transport_protocol;
138 } NdpIpTransParams, *pNdpIpTransParams;
139 
140  /*
141   * Definitions of debug subcommand type for the
142   * generic debug command.
143   */
144 typedef enum {
145     NAN_TEST_MODE_CMD_NAN_AVAILABILITY = 1,
146     NAN_TEST_MODE_CMD_NDP_INCLUDE_IMMUTABLE = 2,
147     NAN_TEST_MODE_CMD_NDP_AVOID_CHANNEL = 3,
148     NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS = 4,
149     NAN_TEST_MODE_CMD_AUTO_RESPONDER_MODE = 5,
150     NAN_TEST_MODE_CMD_M4_RESPONSE_TYPE = 6,
151     NAN_TEST_MODE_CMD_NAN_SCHED_TYPE = 7,
152     NAN_TEST_MODE_CMD_NAN_NMF_CLEAR_CONFIG = 8,
153     NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_ULW_NOTIFY = 9,
154     NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NEGOTIATE = 10,
155     NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NOTIFY = 11,
156     NAN_TEST_MODE_CMD_NAN_AVAILABILITY_MAP_ORDER = 12,
157     NAN_TEST_MODE_CMD_CONFIG_QOS = 13,
158     NAN_TEST_MODE_CMD_DEVICE_TYPE = 14,
159     NAN_TEST_MODE_CMD_DISABLE_NDPE = 15,
160     NAN_TEST_MODE_CMD_ENABLE_NDP = 16,
161     NAN_TEST_MODE_CMD_DISABLE_IPV6_LINK_LOCAL = 17,
162     NAN_TEST_MODE_CMD_TRANSPORT_IP_PARAM = 18,
163 } NanDebugModeCmd;
164 
165 /*
166  * This debug command carries any one command type
167  * followed by corresponding command data content
168  * as indicated below.
169  *
170  * command: NAN_TEST_MODE_CMD_NAN_AVAILABILITY
171  * content: NAN Avaiability attribute blob
172  *
173  * command: NAN_TEST_MODE_CMD_NDP_INCLUDE_IMMUTABLE
174  * content: u32 value (0 - Ignore 1 - Include immuatable,
175  *                     2 - Don't include immutable)
176  *
177  * command: NAN_TEST_MODE_CMD_NDP_AVOID_CHANNEL
178  * content: u32 channel_frequency; (0 - Ignore)
179  *
180  * command: NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS
181  * content: u32 supported_bands; (0 . Ignore, 1 . 2g,
182  *                                2 . 5g, 3 . 2g & 5g)
183  *
184  * command: NAN_TEST_MODE_CMD_AUTO_RESPONDER_MODE
185  * content: u32 auto_resp_mode; (0 . Auto, 1 . Accept,
186  *                               2 . Reject, 3 . Counter)
187  *
188  * command: NAN_TEST_MODE_CMD_M4_RESPONSE_TYPE
189  * content: u32 m4_response_type; (0.Ignore, 1.Accept,
190  *                                 2.Reject, 3.BadMic)
191  *
192  * command: NAN_TEST_MODE_CMD_NAN_SCHED_TYPE
193  * content: u32 invalid_nan_schedule; (0. Valid sched,
194  *                                     1.Invalid Sched bad FA,
195  *                                     2.Invalid schedbad NDC,
196  *                                     3.Invalid sched bad Immutable)
197  *
198  * command: NAN_TEST_MODE_CMD_NAN_NMF_CLEAR_CONFIG
199  * content: u32 nmf_security_config_val;(0:NAN_NMF_CLEAR_DISABLE,
200  *                                       1:NAN_NMF_CLEAR_ENABLE)
201  *
202  * command: NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_ULW_NOTIFY
203  * content: u32 channel_availability;(0/1)
204  *
205  * command: NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NEGOTIATE
206  * content: responder_nmi_mac (Responder NMI Mac Address)
207  *
208  * command: NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NOTIFY
209  * content: NONE
210  *
211  * command: NAN_TEST_MODE_CMD_NAN_AVAILABILITY_MAP_ORDER
212  * content: u32 map_order_val; (0/1)
213  *
214  */
215 typedef struct PACKED {
216     /*
217      * To indicate the debug command type.
218      */
219     u32 cmd;
220     /*
221      * To hold the data for the above command
222      * type.
223      */
224     u8 debug_cmd_data[NAN_MAX_DEBUG_MESSAGE_DATA_LEN];
225 } NanDebugParams;
226 
227 /*
228    Function to get the sta_parameter expected by Sigma
229    as per CAPI spec.
230 */
231 wifi_error nan_get_sta_parameter(transaction_id id,
232                                  wifi_interface_handle iface,
233                                  NanStaParameter* msg);
234 
235 wifi_error nan_debug_command_config(transaction_id id,
236                                    wifi_interface_handle iface,
237                                    NanDebugParams msg,
238                                    int debug_msg_length);
239 #ifdef __cplusplus
240 }
241 #endif /* __cplusplus */
242 #endif /* __NAN_CERT_H__ */
243 
244