1 /*
2  * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: wlan_hdd_nan_datapath.h
22  *
23  * WLAN Host Device Driver nan datapath API specification
24  */
25 #ifndef __WLAN_HDD_NAN_DATAPATH_H
26 #define __WLAN_HDD_NAN_DATAPATH_H
27 
28 struct hdd_context;
29 struct hdd_config;
30 struct hdd_adapter;
31 struct wireless_dev;
32 
33 /* NAN Social frequencies */
34 #define NAN_SOCIAL_FREQ_2_4GHZ 2437
35 #define NAN_SOCIAL_FREQ_5GHZ_LOWER_BAND 5220
36 #define NAN_SOCIAL_FREQ_5GHZ_UPPER_BAND 5745
37 
38 #define NDP_BROADCAST_STAID           (0)
39 
40 #ifdef WLAN_FEATURE_NAN
41 
42 #define WLAN_HDD_IS_NDI(adapter) ((adapter)->device_mode == QDF_NDI_MODE)
43 
44 #define WLAN_HDD_IS_NDI_CONNECTED(adapter) ( \
45 	eConnectionState_NdiConnected ==\
46 		(adapter)->session.station.conn_info.conn_state)
47 
48 void hdd_nan_datapath_target_config(struct hdd_context *hdd_ctx,
49 						struct wma_tgt_cfg *cfg);
50 
51 /**
52  * hdd_ndp_event_handler() - API to handle NDP create/delete events
53  * @link_info: Link info pointer in HDD adapter.
54  * @roam_info: Roam data
55  * @roam_status: roam status
56  * @roam_result: Result of roam
57  *
58  * The function performs operations based on NDP create/delete response.
59  *
60  * Return: void
61  */
62 void hdd_ndp_event_handler(struct wlan_hdd_link_info *link_info,
63 			   struct csr_roam_info *roam_info,
64 			   eRoamCmdStatus roam_status,
65 			   eCsrRoamResult roam_result);
66 
67 int wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
68 	struct wireless_dev *wdev, const void *data, int data_len);
69 int hdd_init_nan_data_mode(struct hdd_adapter *adapter);
70 void hdd_ndp_session_end_handler(struct hdd_adapter *adapter);
71 
72 /**
73  * hdd_cleanup_ndi() - Cleanup NDI state/resources
74  * @link_info: Link info pointer in HDD adapter
75  *
76  * Cleanup NDI state/resources allocated when NDPs are created on that NDI.
77  *
78  * Return: None
79  */
80 
81 void hdd_cleanup_ndi(struct wlan_hdd_link_info *link_info);
82 
83 /**
84  * hdd_ndi_start() - Start NDI adapter and create NDI vdev
85  * @iface_name: NDI interface name
86  * @transaction_id: Transaction id given by framework to start the NDI.
87  *                  Framework expects this in the immediate response when
88  *                  the NDI is created by it.
89  *
90  * Create NDI move interface and vdev.
91  *
92  * Return: 0 upon success
93  */
94 int hdd_ndi_start(const char *iface_name, uint16_t transaction_id);
95 
96 enum nan_datapath_state;
97 struct nan_datapath_inf_create_rsp;
98 
99 /**
100  * hdd_ndi_open() - Open NDI interface
101  * @iface_name: NDI interface name
102  * @is_add_virtual_iface: is this interface getting created through add virtual
103  * interface
104  *
105  * Return: 0 on success, error code on failure
106  */
107 int hdd_ndi_open(const char *iface_name, bool is_add_virtual_iface);
108 
109 /**
110  * hdd_ndi_delete() - Delete NDI interface
111  * @vdev_id: vdev id of the NDI interface
112  * @iface_name: NDI interface name
113  * @transaction_id: Transaction id
114  *
115  * Return: 0 on success, error code on failure
116  */
117 int hdd_ndi_delete(uint8_t vdev_id, const char *iface_name,
118 		   uint16_t transaction_id);
119 
120 /**
121  * hdd_ndi_close() - Close NDI interface
122  * @vdev_id: vdev id of the NDI interface
123  *
124  * Return: None
125  */
126 void hdd_ndi_close(uint8_t vdev_id);
127 
128 /**
129  * hdd_ndi_drv_ndi_create_rsp_handler() - ndi create response handler
130  * @vdev_id: vdev id of the NDI interface
131  * @ndi_rsp: NDI create response
132  *
133  * Return: None
134  */
135 void hdd_ndi_drv_ndi_create_rsp_handler(uint8_t vdev_id,
136 					struct nan_datapath_inf_create_rsp *ndi_rsp);
137 
138 /**
139  * hdd_ndi_drv_ndi_delete_rsp_handler() - ndi delete response handler
140  * @vdev_id: vdev id of the NDI interface
141  *
142  * Return: None
143  */
144 void hdd_ndi_drv_ndi_delete_rsp_handler(uint8_t vdev_id);
145 
146 /**
147  * hdd_ndp_new_peer_handler() - NDP new peer indication handler
148  * @vdev_id: vdev id
149  * @sta_id: STA ID
150  * @peer_mac_addr: MAC address of the peer
151  * @first_peer: Indicates if it is first peer
152  *
153  * Return: 0 on success, error code on failure
154  */
155 int hdd_ndp_new_peer_handler(uint8_t vdev_id, uint16_t sta_id,
156 			     struct qdf_mac_addr *peer_mac_addr,
157 			     bool first_peer);
158 
159 /**
160  * hdd_ndp_peer_departed_handler() - Handle NDP peer departed indication
161  * @vdev_id: vdev id
162  * @sta_id: STA ID
163  * @peer_mac_addr: MAC address of the peer
164  * @last_peer: Indicates if it is last peer
165  *
166  * Return: None
167  */
168 void hdd_ndp_peer_departed_handler(uint8_t vdev_id, uint16_t sta_id,
169 				   struct qdf_mac_addr *peer_mac_addr,
170 				   bool last_peer);
171 
172 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
173 /**
174  * hdd_ndi_set_mode() - set the adapter mode to NDI
175  * @iface_name: NDI interface name
176  *
177  * The adapter mode is STA while creating virtual interface.
178  * mode is set to NDI while creating NDI.
179  *
180  * Return: 0 upon success
181  */
182 int hdd_ndi_set_mode(const char *iface_name);
183 #else
hdd_ndi_set_mode(const char * iface_name)184 static inline int hdd_ndi_set_mode(const char *iface_name)
185 {
186 	return 0;
187 }
188 #endif /* LINUX_VERSION_CODE  */
189 
190 #else
191 #define WLAN_HDD_IS_NDI(adapter)	(false)
192 #define WLAN_HDD_IS_NDI_CONNECTED(adapter) (false)
193 
hdd_nan_datapath_target_config(struct hdd_context * hdd_ctx,struct wma_tgt_cfg * cfg)194 static inline void hdd_nan_datapath_target_config(struct hdd_context *hdd_ctx,
195 						struct wma_tgt_cfg *cfg)
196 {
197 }
198 
hdd_ndp_event_handler(struct wlan_hdd_link_info * link_info,struct csr_roam_info * roam_info,eRoamCmdStatus roam_status,eCsrRoamResult roam_result)199 static inline void hdd_ndp_event_handler(struct wlan_hdd_link_info *link_info,
200 					 struct csr_roam_info *roam_info,
201 					 eRoamCmdStatus roam_status,
202 					 eCsrRoamResult roam_result)
203 {
204 }
205 
wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)206 static inline int wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
207 		struct wireless_dev *wdev, const void *data, int data_len)
208 {
209 	return 0;
210 }
hdd_init_nan_data_mode(struct hdd_adapter * adapter)211 static inline int hdd_init_nan_data_mode(struct hdd_adapter *adapter)
212 {
213 	return 0;
214 }
hdd_ndp_session_end_handler(struct hdd_adapter * adapter)215 static inline void hdd_ndp_session_end_handler(struct hdd_adapter *adapter)
216 {
217 }
218 
hdd_cleanup_ndi(struct wlan_hdd_link_info * link_info)219 static inline void hdd_cleanup_ndi(struct wlan_hdd_link_info *link_info)
220 {
221 }
222 
hdd_ndi_start(const char * iface_name,uint16_t transaction_id)223 static inline int hdd_ndi_start(const char *iface_name, uint16_t transaction_id)
224 {
225 	return 0;
226 }
227 
hdd_ndi_set_mode(const char * iface_name)228 static inline int hdd_ndi_set_mode(const char *iface_name)
229 {
230 	return 0;
231 }
232 
233 enum nan_datapath_state;
234 struct nan_datapath_inf_create_rsp;
235 
236 static inline int
hdd_ndi_open(const char * iface_name,bool is_add_virtual_iface)237 hdd_ndi_open(const char *iface_name, bool is_add_virtual_iface)
238 {
239 	return 0;
240 }
241 
242 static inline int
hdd_ndi_delete(uint8_t vdev_id,const char * iface_name,uint16_t transaction_id)243 hdd_ndi_delete(uint8_t vdev_id, const char *iface_name, uint16_t transaction_id)
244 {
245 	return 0;
246 }
247 
hdd_ndi_close(uint8_t vdev_id)248 static inline void hdd_ndi_close(uint8_t vdev_id)
249 {
250 }
251 
252 static inline void
hdd_ndi_drv_ndi_create_rsp_handler(uint8_t vdev_id,struct nan_datapath_inf_create_rsp * ndi_rsp)253 hdd_ndi_drv_ndi_create_rsp_handler(uint8_t vdev_id,
254 				   struct nan_datapath_inf_create_rsp *ndi_rsp)
255 {
256 }
257 
hdd_ndi_drv_ndi_delete_rsp_handler(uint8_t vdev_id)258 static inline void hdd_ndi_drv_ndi_delete_rsp_handler(uint8_t vdev_id)
259 {
260 }
261 
hdd_ndp_new_peer_handler(uint8_t vdev_id,uint16_t sta_id,struct qdf_mac_addr * peer_mac_addr,bool first_peer)262 static inline int hdd_ndp_new_peer_handler(uint8_t vdev_id, uint16_t sta_id,
263 					   struct qdf_mac_addr *peer_mac_addr,
264 					   bool first_peer)
265 {
266 	return 0;
267 }
268 
hdd_ndp_peer_departed_handler(uint8_t vdev_id,uint16_t sta_id,struct qdf_mac_addr * peer_mac_addr,bool last_peer)269 static inline void hdd_ndp_peer_departed_handler(uint8_t vdev_id,
270 						 uint16_t sta_id,
271 						 struct qdf_mac_addr *peer_mac_addr,
272 						 bool last_peer)
273 {
274 }
275 #endif /* WLAN_FEATURE_NAN */
276 
277 #endif /* __WLAN_HDD_NAN_DATAPATH_H */
278