1 /*
2  * Copyright (c) 2017-2019, 2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022, 2024 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: Defines off channel tx API & structures
22  */
23 
24 #ifndef _WLAN_P2P_OFF_CHAN_TX_H_
25 #define _WLAN_P2P_OFF_CHAN_TX_H_
26 
27 #include <qdf_types.h>
28 #include <qdf_mc_timer.h>
29 #include <qdf_list.h>
30 
31 #define P2P_EID_VENDOR                          0xdd
32 #define P2P_ACTION_VENDOR_SPECIFIC_CATEGORY     0x7F
33 #define P2P_PUBLIC_ACTION_FRAME                 0x4
34 #define P2P_MAC_MGMT_ACTION                     0xD
35 #define P2P_PUBLIC_ACTION_VENDOR_SPECIFIC       0x9
36 #define P2P_NOA_ATTR                            0xC
37 #define WNM_ACTION_FRAME                        0xA
38 #define RRM_ACTION_FRAME                        0x5
39 
40 #define P2P_MAX_NOA_ATTR_LEN                    31
41 #define P2P_IE_HEADER_LEN                       6
42 #define P2P_ACTION_OFFSET                       24
43 #define P2P_PUBLIC_ACTION_FRAME_TYPE_OFFSET     30
44 #define P2P_ACTION_FRAME_TYPE_OFFSET            29
45 #define PROBE_RSP_IE_OFFSET                     36
46 
47 #define P2P_TX_PKT_MIN_HEADROOM                (64)
48 
49 #define P2P_OUI                                 "\x50\x6f\x9a\x09"
50 #define P2P_OUI_SIZE                            4
51 
52 #define P2P_ACTION_FRAME_RSP_WAIT               500
53 #define P2P_ACTION_FRAME_ACK_WAIT               300
54 #define P2P_ACTION_FRAME_TX_TIMEOUT             2000
55 
56 #define DST_MAC_ADDR_OFFSET  4
57 #define SRC_MAC_ADDR_OFFSET  (DST_MAC_ADDR_OFFSET + QDF_MAC_ADDR_SIZE)
58 
59 #define P2P_NOA_STREAM_ARR_SIZE (P2P_MAX_NOA_ATTR_LEN + (2 * P2P_IE_HEADER_LEN))
60 
61 #define P2P_GET_TYPE_FRM_FC(__fc__)         (((__fc__) & 0x0F) >> 2)
62 #define P2P_GET_SUBTYPE_FRM_FC(__fc__)      (((__fc__) & 0xF0) >> 4)
63 
64 #define WLAN_WAIT_TIME_SET_RND 1000
65 
66 struct p2p_soc_priv_obj;
67 struct cancel_roc_context;
68 struct p2p_tx_conf_event;
69 struct p2p_rx_mgmt_event;
70 
71 /**
72  * enum p2p_frame_type - frame type
73  * @P2P_FRAME_MGMT:         mgmt frame
74  * @P2P_FRAME_NOT_SUPPORT:  not support frame type
75  */
76 enum p2p_frame_type {
77 	P2P_FRAME_MGMT = 0,
78 	P2P_FRAME_NOT_SUPPORT,
79 };
80 
81 /**
82  * enum p2p_frame_sub_type - frame sub type
83  * @P2P_MGMT_PROBE_REQ:       probe request frame
84  * @P2P_MGMT_PROBE_RSP:       probe response frame
85  * @P2P_MGMT_DISASSOC:        disassociation frame
86  * @P2P_MGMT_AUTH:            authentication frame
87  * @P2P_MGMT_DEAUTH:          deauthentication frame
88  * @P2P_MGMT_ACTION:          action frame
89  * @P2P_MGMT_NOT_SUPPORT:     not support sub frame type
90  */
91 enum p2p_frame_sub_type {
92 	P2P_MGMT_PROBE_REQ = 4,
93 	P2P_MGMT_PROBE_RSP,
94 	P2P_MGMT_DISASSOC = 10,
95 	P2P_MGMT_AUTH,
96 	P2P_MGMT_DEAUTH,
97 	P2P_MGMT_ACTION,
98 	P2P_MGMT_NOT_SUPPORT,
99 };
100 
101 /**
102  * enum p2p_public_action_type - public action frame type
103  * @P2P_PUBLIC_ACTION_NEG_REQ:       go negotiation request frame
104  * @P2P_PUBLIC_ACTION_NEG_RSP:       go negotiation response frame
105  * @P2P_PUBLIC_ACTION_NEG_CNF:       go negotiation confirm frame
106  * @P2P_PUBLIC_ACTION_INVIT_REQ:     p2p invitation request frame
107  * @P2P_PUBLIC_ACTION_INVIT_RSP:     p2p invitation response frame
108  * @P2P_PUBLIC_ACTION_DEV_DIS_REQ:   device discoverability request
109  * @P2P_PUBLIC_ACTION_DEV_DIS_RSP:   device discoverability response
110  * @P2P_PUBLIC_ACTION_PROV_DIS_REQ:  provision discovery request
111  * @P2P_PUBLIC_ACTION_PROV_DIS_RSP:  provision discovery response
112  * @P2P_PUBLIC_ACTION_GAS_INIT_REQ:  gas initial request,
113  * @P2P_PUBLIC_ACTION_GAS_INIT_RSP:  gas initial response
114  * @P2P_PUBLIC_ACTION_GAS_COMB_REQ:  gas comeback request
115  * @P2P_PUBLIC_ACTION_GAS_COMB_RSP:  gas comeback response
116  * @P2P_PUBLIC_ACTION_WNM_BTM_REQ:   bss transition management request
117  * @P2P_PUBLIC_ACTION_RRM_BEACON_REQ:rrm beacon request
118  * @P2P_PUBLIC_ACTION_RRM_NEIGHBOR_RSP:rrm neighbor response
119  * @P2P_PUBLIC_ACTION_NOT_SUPPORT:   not support p2p public action frame
120  */
121 enum p2p_public_action_type {
122 	P2P_PUBLIC_ACTION_NEG_REQ = 0,
123 	P2P_PUBLIC_ACTION_NEG_RSP,
124 	P2P_PUBLIC_ACTION_NEG_CNF,
125 	P2P_PUBLIC_ACTION_INVIT_REQ,
126 	P2P_PUBLIC_ACTION_INVIT_RSP,
127 	P2P_PUBLIC_ACTION_DEV_DIS_REQ,
128 	P2P_PUBLIC_ACTION_DEV_DIS_RSP,
129 	P2P_PUBLIC_ACTION_PROV_DIS_REQ,
130 	P2P_PUBLIC_ACTION_PROV_DIS_RSP,
131 	P2P_PUBLIC_ACTION_GAS_INIT_REQ = 10,
132 	P2P_PUBLIC_ACTION_GAS_INIT_RSP,
133 	P2P_PUBLIC_ACTION_GAS_COMB_REQ,
134 	P2P_PUBLIC_ACTION_GAS_COMB_RSP,
135 	P2P_PUBLIC_ACTION_WNM_BTM_REQ,
136 	P2P_PUBLIC_ACTION_RRM_BEACON_REQ,
137 	P2P_PUBLIC_ACTION_RRM_NEIGHBOR_RSP,
138 	P2P_PUBLIC_ACTION_NOT_SUPPORT,
139 };
140 
141 /**
142  * enum p2p_action_type - p2p action frame type
143  * @P2P_ACTION_PRESENCE_REQ:    presence request frame
144  * @P2P_ACTION_PRESENCE_RSP:    presence response frame
145  * @P2P_ACTION_NOT_SUPPORT:     not support action frame type
146  */
147 enum p2p_action_type {
148 	P2P_ACTION_PRESENCE_REQ = 1,
149 	P2P_ACTION_PRESENCE_RSP = 2,
150 	P2P_ACTION_NOT_SUPPORT,
151 };
152 
153 struct p2p_frame_info {
154 	enum p2p_frame_type type;
155 	enum p2p_frame_sub_type sub_type;
156 	enum p2p_public_action_type public_action_type;
157 	enum p2p_action_type action_type;
158 };
159 
160 /**
161  * struct tx_action_context - tx action frame context
162  * @node:           Node for next element in the list
163  * @p2p_soc_obj:    Pointer to SoC global p2p private object
164  * @vdev_id:        Vdev id on which this request has come
165  * @scan_id:        Scan id given by scan component for this roc req
166  * @roc_cookie:     Cookie for remain on channel request
167  * @id:             Identifier of this tx context
168  * @chan_freq:      Chan frequency for which this tx has been requested
169  * @buf:            tx buffer
170  * @buf_len:        Length of tx buffer
171  * @off_chan:       Is this off channel tx
172  * @no_cck:         Required cck or not
173  * @no_ack:         Required ack or not
174  * @rand_mac_tx:    Use random MAC address
175  * @duration:       Duration for the RoC
176  * @tx_timer:       RoC timer
177  * @frame_info:     Frame type information
178  * @nbuf:           Network buffer
179  */
180 struct tx_action_context {
181 	qdf_list_node_t node;
182 	struct p2p_soc_priv_obj *p2p_soc_obj;
183 	int vdev_id;
184 	int scan_id;
185 	uint64_t roc_cookie;
186 	int32_t id;
187 	qdf_freq_t chan_freq;
188 	uint8_t *buf;
189 	int buf_len;
190 	bool off_chan;
191 	bool no_cck;
192 	bool no_ack;
193 	bool rand_mac_tx;
194 	uint32_t duration;
195 	qdf_mc_timer_t tx_timer;
196 	struct p2p_frame_info frame_info;
197 	qdf_nbuf_t nbuf;
198 };
199 
200 /**
201  * p2p_get_frame_info() - get frame information from packet
202  * @data_buf:          data buffer address
203  * @length:            buffer length
204  * @frame_info:        frame information
205  *
206  * This function gets frame information from packet.
207  *
208  * Return: QDF_STATUS_SUCCESS - in case of success
209  */
210 QDF_STATUS p2p_get_frame_info(uint8_t *data_buf, uint32_t length,
211 			      struct p2p_frame_info *frame_info);
212 
213 /**
214  * p2p_is_action_frame_of_p2p_type() - Given action frame is p2p type or not
215  * @data_buf: data buffer address
216  * @length: buffer length
217  *
218  * Return: bool
219  */
220 bool p2p_is_action_frame_of_p2p_type(uint8_t *data_buf, uint32_t length);
221 
222 /**
223  * p2p_rand_mac_tx_done() - process random mac mgmt tx done
224  * @soc: soc
225  * @tx_ctx: tx context
226  *
227  * This function will remove the random mac addr filter reference.
228  *
229  * Return: void
230  */
231 void
232 p2p_rand_mac_tx_done(struct wlan_objmgr_psoc *soc,
233 		     struct tx_action_context *tx_ctx);
234 
235 /**
236  * p2p_clear_mac_filter() - send clear mac addr filter cmd
237  * @soc: soc
238  * @vdev_id: vdev id
239  * @mac: mac addr
240  * @freq: freq
241  *
242  * This function send clear random mac addr filter command to p2p component
243  * msg core
244  *
245  * Return: QDF_STATUS_SUCCESS - if sent successfully.
246  *         otherwise: failed.
247  */
248 QDF_STATUS
249 p2p_clear_mac_filter(struct wlan_objmgr_psoc *soc, uint32_t vdev_id,
250 		     uint8_t *mac, uint32_t freq);
251 
252 /**
253  * p2p_is_vdev_support_rand_mac() - check vdev type support random mac mgmt
254  *    tx or not
255  * @vdev: vdev object
256  *
257  * Return: true: support random mac mgmt tx
258  *         false: not support random mac mgmt tx.
259  */
260 bool
261 p2p_is_vdev_support_rand_mac(struct wlan_objmgr_vdev *vdev);
262 
263 /**
264  * p2p_dump_tx_queue() - dump tx queue
265  * @p2p_soc_obj: p2p soc private object
266  *
267  * This function dumps tx queue and output details about tx context in
268  * queue.
269  *
270  * Return: None
271  */
272 void p2p_dump_tx_queue(struct p2p_soc_priv_obj *p2p_soc_obj);
273 
274 /**
275  * p2p_ready_to_tx_frame() - dump tx queue
276  * @p2p_soc_obj: p2p soc private object
277  * @cookie: cookie is pointer to roc
278  *
279  * This function find out the tx context in wait for roc queue and tx
280  * this frame.
281  *
282  * Return: QDF_STATUS_SUCCESS - in case of success
283  */
284 QDF_STATUS p2p_ready_to_tx_frame(struct p2p_soc_priv_obj *p2p_soc_obj,
285 	uint64_t cookie);
286 
287 /**
288  * p2p_cleanup_tx_sync() - Cleanup tx queue
289  * @p2p_soc_obj: p2p psoc private object
290  * @vdev:        vdev object
291  *
292  * This function cleanup tx context in queue until cancellation done.
293  * To avoid deadlock, don't call from scheduler thread.
294  *
295  * Return: QDF_STATUS_SUCCESS - in case of success
296  */
297 QDF_STATUS p2p_cleanup_tx_sync(
298 	struct p2p_soc_priv_obj *p2p_soc_obj,
299 	struct wlan_objmgr_vdev *vdev);
300 
301 /**
302  * p2p_process_cleanup_tx_queue() - process the message to cleanup tx
303  * @param: pointer to cleanup parameters
304  *
305  * This function cleanup wait for roc queue and wait for ack queue.
306  *
307  * Return: QDF_STATUS_SUCCESS - in case of success
308  */
309 QDF_STATUS p2p_process_cleanup_tx_queue(
310 	struct p2p_cleanup_param *param);
311 
312 /**
313  * p2p_process_mgmt_tx() - Process mgmt frame tx request
314  * @tx_ctx: tx context
315  *
316  * This function handles mgmt frame tx request. It will call API from
317  * mgmt txrx component.
318  *
319  * Return: QDF_STATUS_SUCCESS - in case of success
320  */
321 QDF_STATUS p2p_process_mgmt_tx(struct tx_action_context *tx_ctx);
322 
323 /**
324  * p2p_process_mgmt_tx_cancel() - Process cancel mgmt frame tx request
325  * @cancel_tx: cancel tx context
326  *
327  * This function cancel mgmt frame tx request by cookie.
328  *
329  * Return: QDF_STATUS_SUCCESS - in case of success
330  */
331 QDF_STATUS p2p_process_mgmt_tx_cancel(
332 	struct cancel_roc_context *cancel_tx);
333 
334 /**
335  * p2p_process_mgmt_tx_ack_cnf() - Process tx ack event
336  * @tx_cnf_event: tx confirmation event information
337  *
338  * This function mgmt frame tx confirmation. It will deliver this
339  * event to up layer
340  *
341  * Return: QDF_STATUS_SUCCESS - in case of success
342  */
343 QDF_STATUS p2p_process_mgmt_tx_ack_cnf(
344 	struct p2p_tx_conf_event *tx_cnf_event);
345 
346 /**
347  * p2p_process_rx_mgmt() - Process rx mgmt frame event
348  * @rx_mgmt_event: rx mgmt frame event information
349  *
350  * This function mgmt frame rx mgmt frame event. It will deliver this
351  * event to up layer
352  *
353  * Return: QDF_STATUS_SUCCESS - in case of success
354  */
355 QDF_STATUS p2p_process_rx_mgmt(
356 	struct p2p_rx_mgmt_event *rx_mgmt_event);
357 
358 /**
359  * p2p_find_tx_ctx_by_nbuf() - find tx context by nbuf
360  * @p2p_soc_obj:        p2p soc object
361  * @nbuf:               pointer to nbuf
362  *
363  * This function finds out tx context by nbuf.
364  *
365  * Return: pointer to tx context
366  */
367 struct tx_action_context *p2p_find_tx_ctx_by_nbuf(
368 	struct p2p_soc_priv_obj *p2p_soc_obj, void *nbuf);
369 
370 #define P2P_80211_FRM_SA_OFFSET 10
371 
372 /**
373  * p2p_del_random_mac() - del mac filter from given vdev rand mac list
374  * @soc: soc object
375  * @vdev_id: vdev id
376  * @rnd_cookie: random mac mgmt tx cookie
377  *
378  * This function will del the mac addr filter from vdev random mac addr list.
379  * If there is no reference to mac addr, it will set a clear timer to flush it
380  * in target finally.
381  *
382  * Return: QDF_STATUS_SUCCESS - del successfully.
383  *             other : failed to del the mac address entry.
384  */
385 QDF_STATUS
386 p2p_del_random_mac(struct wlan_objmgr_psoc *soc, uint32_t vdev_id,
387 		   uint64_t rnd_cookie);
388 
389 /**
390  * p2p_random_mac_handle_tx_done() - del mac filter from given vdev rand mac
391  * list when mgmt tx done
392  * @soc: soc object
393  * @vdev_id: vdev id
394  * @rnd_cookie: random mac mgmt tx cookie
395  * @duration: timeout value to flush the addr in target.
396  *
397  * This function will del the mac addr filter from vdev random mac addr list
398  * and also remove the filter from firmware if duration is zero else start
399  * the timer for that duration.
400  *
401  * Return: QDF_STATUS_SUCCESS - del successfully.
402  *		other : failed to del the mac address entry.
403  */
404 QDF_STATUS
405 p2p_random_mac_handle_tx_done(struct wlan_objmgr_psoc *soc, uint32_t vdev_id,
406 			      uint64_t rnd_cookie, uint32_t duration);
407 
408 /**
409  * p2p_check_random_mac() - check random mac addr or not
410  * @soc: soc context
411  * @vdev_id: vdev id
412  * @random_mac_addr: mac addr to be checked
413  *
414  * This function check the input addr is random mac addr or not for vdev.
415  *
416  * Return: true if addr is random mac address else false.
417  */
418 bool p2p_check_random_mac(struct wlan_objmgr_psoc *soc, uint32_t vdev_id,
419 			  uint8_t *random_mac_addr);
420 
421 /**
422  * p2p_process_set_rand_mac() - process the set random mac command
423  * @set_filter_req: request data
424  *
425  * This function will process the set mac addr filter command.
426  *
427  * Return: QDF_STATUS_SUCCESS: if process successfully
428  *             other: failed.
429  */
430 QDF_STATUS p2p_process_set_rand_mac(
431 		struct p2p_set_mac_filter_req *set_filter_req);
432 
433 /**
434  * p2p_process_set_rand_mac_rsp() - process the set random mac response
435  * @resp: response date
436  *
437  * This function will process the set mac addr filter event.
438  *
439  * Return: QDF_STATUS_SUCCESS: if process successfully
440  *             other: failed.
441  */
442 QDF_STATUS p2p_process_set_rand_mac_rsp(struct p2p_mac_filter_rsp *resp);
443 
444 /**
445  * p2p_del_all_rand_mac_vdev() - del all random mac filter in vdev
446  * @vdev: vdev object
447  *
448  * This function will del all random mac filter in vdev
449  *
450  * Return: void
451  */
452 void p2p_del_all_rand_mac_vdev(struct wlan_objmgr_vdev *vdev);
453 
454 /**
455  * p2p_del_all_rand_mac_soc() - del all random mac filter in soc
456  * @soc: soc object
457  *
458  * This function will del all random mac filter in all vdev of soc
459  *
460  * Return: void
461  */
462 void p2p_del_all_rand_mac_soc(struct wlan_objmgr_psoc *soc);
463 
464 /**
465  * p2p_rand_mac_tx() - handle random mac mgmt tx
466  * @pdev: pdev object
467  * @tx_action: tx action context
468  *
469  * This function will check whether need to set random mac tx filter for a
470  * given mgmt tx request and do the mac addr filter process as needed.
471  *
472  * Return: void
473  */
474 void p2p_rand_mac_tx(struct wlan_objmgr_pdev *pdev,
475 		     struct tx_action_context *tx_action);
476 
477 /**
478  * p2p_init_random_mac_vdev() - Init random mac data for vdev
479  * @p2p_vdev_obj: p2p vdev private object
480  *
481  * This function will init the per vdev random mac data structure.
482  *
483  * Return: void
484  */
485 void p2p_init_random_mac_vdev(struct p2p_vdev_priv_obj *p2p_vdev_obj);
486 
487 /**
488  * p2p_deinit_random_mac_vdev() - Init random mac data for vdev
489  * @p2p_vdev_obj: p2p vdev private object
490  *
491  * This function will deinit the per vdev random mac data structure.
492  *
493  * Return: void
494  */
495 void p2p_deinit_random_mac_vdev(struct p2p_vdev_priv_obj *p2p_vdev_obj);
496 
497 /**
498  * p2p_get_p2pie_ptr() - get the pointer to p2p ie
499  * @ie:      source ie
500  * @ie_len:  source ie length
501  *
502  * This function finds out p2p ie by p2p oui and return the pointer.
503  *
504  * Return: pointer to p2p ie
505  */
506 const uint8_t *p2p_get_p2pie_ptr(const uint8_t *ie, uint16_t ie_len);
507 
508 #endif /* _WLAN_P2P_OFF_CHAN_TX_H_ */
509