xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 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: Public APIs for crypto service
22  */
23 #ifndef _WLAN_CRYPTO_GLOBAL_API_H_
24 #define _WLAN_CRYPTO_GLOBAL_API_H_
25 
26 #include "wlan_crypto_global_def.h"
27 #include <qdf_crypto.h>
28 /**
29  * wlan_crypto_set_vdev_param - called by ucfg to set crypto param
30  * @vdev: vdev
31  * @param: param to be set.
32  * @value: value
33  *
34  * This function gets called from ucfg to set param
35  *
36  * Return: QDF_STATUS_SUCCESS - in case of success
37  */
38 QDF_STATUS wlan_crypto_set_vdev_param(struct wlan_objmgr_vdev *vdev,
39 					wlan_crypto_param_type param,
40 					uint32_t value);
41 
42 /**
43  * wlan_crypto_set_peer_param - called by ucfg to set crypto param
44  *
45  * @peer: peer
46  * @param: param to be set.
47  * @value: value
48  *
49  * This function gets called from ucfg to set param
50  *
51  * Return: QDF_STATUS_SUCCESS - in case of success
52  */
53 QDF_STATUS wlan_crypto_set_peer_param(struct wlan_objmgr_peer *peer,
54 						wlan_crypto_param_type param,
55 						uint32_t value);
56 
57 /**
58  * wlan_crypto_get_param - called by ucfg to get crypto param
59  * @vdev: vdev
60  * @param: param to be get.
61  *
62  * This function gets called from ucfg to get param
63  *
64  * Return: value or -1 for failure
65  */
66 int32_t wlan_crypto_get_param(struct wlan_objmgr_vdev *vdev,
67 					wlan_crypto_param_type param);
68 /**
69  * wlan_crypto_get_peer_param - called by ucfg to get crypto peer param
70  * @peer: peer
71  * @param: param to be get.
72  *
73  * This function gets called from ucfg to get peer param
74  *
75  * Return: value or -1 for failure
76  */
77 int32_t wlan_crypto_get_peer_param(struct wlan_objmgr_peer *peer,
78 					wlan_crypto_param_type param);
79 
80 /**
81  * wlan_crypto_is_htallowed - called by ucfg to check if HT rates is allowed
82  * @vdev: Vdev
83  * @peer: Peer
84  *
85  * This function is called to check if HT rates is allowed
86  *
87  * Return: 0 for not allowed and +ve for allowed
88  */
89 uint8_t wlan_crypto_is_htallowed(struct wlan_objmgr_vdev *vdev,
90 				 struct wlan_objmgr_peer *peer);
91 /**
92  * wlan_crypto_setkey - called by ucfg to setkey
93  * @vdev: vdev
94  * @req_key: req_key with cipher type, key macaddress
95  *
96  * This function gets called from ucfg to sey key
97  *
98  * Return: QDF_STATUS_SUCCESS - in case of success
99  */
100 QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev,
101 					struct wlan_crypto_req_key *req_key);
102 
103 /**
104  * store_def_keyix_peer - called by wlan_crypto_setkey
105  *                   to store default key index for each peer in the vdev.
106  * @vdev: vdev
107  * @object: Peer object
108  * @arg: Argument passed by caller
109  *
110  * This function gets called from wlan_crypto_setkey
111  *
112  * Return: None
113  */
114 void store_def_keyix_peer(struct wlan_objmgr_vdev *vdev, void *object,
115 			  void *arg);
116 
117 /**
118  * wlan_crypto_getkey - called by ucfg to get key
119  * @vdev: vdev
120  * @req_key: key value will be copied in this req_key
121  * @mac_address: mac address of the peer for unicast key
122  *                   or broadcast address if group key is requested.
123  *
124  * This function gets called from ucfg to get key
125  *
126  * Return: QDF_STATUS_SUCCESS - in case of success
127  */
128 QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev,
129 					struct wlan_crypto_req_key *req_key,
130 					uint8_t *mac_addr);
131 
132 /**
133  * wlan_crypto_delkey - called by ucfg to delete key
134  * @vdev: vdev
135  * @mac_address: mac address of the peer for unicast key
136  *                   or broadcast address if group key is deleted.
137  * @key_idx: key index to be deleted
138  *
139  * This function gets called from ucfg to delete key
140  *
141  * Return: QDF_STATUS_SUCCESS - in case of success
142  */
143 QDF_STATUS wlan_crypto_delkey(struct wlan_objmgr_vdev *vdev,
144 					uint8_t *macaddr,
145 					uint8_t key_idx);
146 
147 /**
148  * wlan_crypto_default_key - called by ucfg to set default tx key
149  * @vdev: vdev
150  * @mac_address: mac address of the peer for unicast key
151  *                   or broadcast address if group key need to made default.
152  * @key_idx: key index to be made as default key
153  * @unicast: is key was unicast or group key.
154  *
155  * This function gets called from ucfg to set default key
156  *
157  * Return: QDF_STATUS_SUCCESS - in case of success
158  */
159 QDF_STATUS wlan_crypto_default_key(struct wlan_objmgr_vdev *vdev,
160 					uint8_t *macaddr,
161 					uint8_t key_idx,
162 					bool unicast);
163 
164 /**
165  * wlan_crypto_encap - called by mgmt for encap the frame based on cipher
166  * @vdev: vdev
167  * @wbuf: wbuf
168  * @macaddr: macaddr
169  * @encapdone: is encapdone already or not.
170  *
171  * This function gets called from mgmt txrx to encap frame.
172  *
173  * Return: QDF_STATUS_SUCCESS - in case of success
174  */
175 QDF_STATUS wlan_crypto_encap(struct wlan_objmgr_vdev *vdev,
176 					qdf_nbuf_t wbuf,
177 					uint8_t *macaddr,
178 					uint8_t encapdone);
179 
180 /**
181  * wlan_crypto_decap - called by mgmt for decap the frame based on cipher
182  * @vdev: vdev
183  * @wbuf: wbuf
184  * @macaddr: macaddr
185  * @tid: tid of the packet.
186  *
187  * This function gets called from mgmt txrx to decap frame.
188  *
189  * Return: QDF_STATUS_SUCCESS - in case of success
190  */
191 QDF_STATUS wlan_crypto_decap(struct wlan_objmgr_vdev *vdev,
192 					qdf_nbuf_t wbuf,
193 					uint8_t *macaddr,
194 					uint8_t tid);
195 
196 /**
197  * wlan_crypto_enmic - called by mgmt for adding mic in frame based on cipher
198  * @vdev: vdev
199  * @wbuf: wbuf
200  * @macaddr: macaddr
201  * @encapdone: is encapdone already or not.
202  *
203  * This function gets called from mgmt txrx to adding mic to the frame.
204  *
205  * Return: QDF_STATUS_SUCCESS - in case of success
206  */
207 QDF_STATUS wlan_crypto_enmic(struct wlan_objmgr_vdev *vdev,
208 					qdf_nbuf_t wbuf,
209 					uint8_t *macaddr,
210 					uint8_t encapdone);
211 
212 /**
213  * wlan_crypto_demic - called by mgmt for remove and check mic for
214  *                                    the frame based on cipher
215  * @vdev: vdev
216  * @wbuf: wbuf
217  * @macaddr: macaddr
218  * @tid: tid of the frame
219  * @keyid: keyid in the received frame
220  *
221  * This function gets called from mgmt txrx to decap frame.
222  *
223  * Return: QDF_STATUS_SUCCESS - in case of success
224  */
225 QDF_STATUS wlan_crypto_demic(struct wlan_objmgr_vdev *vdev,
226 			     qdf_nbuf_t wbuf,
227 			     uint8_t *macaddr,
228 			     uint8_t tid,
229 			     uint8_t keyid);
230 
231 /**
232  * wlan_crypto_vdev_is_pmf_enabled - called to check is pmf enabled in vdev
233  * @vdev: vdev
234  *
235  * This function gets called to check is pmf enabled or not in vdev.
236  *
237  * Return: true or false
238  */
239 bool wlan_crypto_vdev_is_pmf_enabled(struct wlan_objmgr_vdev *vdev);
240 
241 /**
242  * wlan_crypto_vdev_is_pmf_required - called to check is pmf required in vdev
243  * @vdev: vdev
244  *
245  * This function gets called to check is pmf required or not in vdev.
246  *
247  * Return: true or false
248  */
249 bool wlan_crypto_vdev_is_pmf_required(struct wlan_objmgr_vdev *vdev);
250 
251 /**
252  * wlan_crypto_is_pmf_enabled - called by mgmt txrx to check is pmf enabled
253  * @vdev: vdev
254  * @peer: peer
255  *
256  * This function gets called by mgmt txrx to check is pmf enabled or not.
257  *
258  * Return: true or false
259  */
260 bool wlan_crypto_is_pmf_enabled(struct wlan_objmgr_vdev *vdev,
261 					struct wlan_objmgr_peer *peer);
262 
263 /**
264  * wlan_crypto_is_key_valid - called by mgmt txrx to check if key is valid
265  * @vdev: vdev
266  * @peer: peer
267  * @keyidx : key index
268  *
269  * This function gets called by mgmt txrx to check if key is valid
270  *
271  * Return: true or false
272  */
273 bool wlan_crypto_is_key_valid(struct wlan_objmgr_vdev *vdev,
274 			      struct wlan_objmgr_peer *peer,
275 			      uint16_t keyidx);
276 
277 /**
278  * wlan_crypto_add_mmie - called by mgmt txrx to add mmie in frame
279  * @vdev: vdev
280  * @frm:  frame starting pointer
281  * @len: length of the frame
282  *
283  * This function gets called by mgmt txrx to add mmie in frame
284  *
285  * Return: end of frame or NULL in case failure
286  */
287 uint8_t *wlan_crypto_add_mmie(struct wlan_objmgr_vdev *vdev,
288 					uint8_t *frm,
289 					uint32_t len);
290 
291 /**
292  * wlan_crypto_is_mmie_valid - called by mgmt txrx to check mmie of the frame
293  * @vdev: vdev
294  * @frm:  frame starting pointer
295  * @efrm: end of frame pointer
296  *
297  * This function gets called by mgmt txrx to check mmie of the frame
298  *
299  * Return: true or false
300  */
301 bool wlan_crypto_is_mmie_valid(struct wlan_objmgr_vdev *vdev,
302 					uint8_t *frm,
303 					uint8_t *efrm);
304 
305 /**
306  * wlan_crypto_wpaie_check - called by mlme to check the wpaie
307  * @crypto_params: crypto params
308  * @frm: ie buffer
309  *
310  * This function gets called by mlme to check the contents of wpa is
311  * matching with given crypto params
312  *
313  * Return: QDF_STATUS_SUCCESS - in case of success
314  */
315 QDF_STATUS wlan_crypto_wpaie_check(struct wlan_crypto_params *crypto_params,
316 				   const uint8_t *frm);
317 
318 /**
319  * wlan_crypto_rsnie_check - called by mlme to check the rsnie
320  * @crypto_params: crypto params
321  * @frm: ie buffer
322  *
323  * This function gets called by mlme to check the contents of rsn is
324  * matching with given crypto params
325  *
326  * Return: QDF_STATUS_SUCCESS - in case of success
327  */
328 QDF_STATUS wlan_crypto_rsnie_check(struct wlan_crypto_params *crypto_params,
329 				   const uint8_t *frm);
330 /**
331  * wlan_crypto_build_wpaie - called by mlme to build wpaie
332  * @vdev: vdev
333  * @iebuf: ie buffer
334  *
335  * This function gets called by mlme to build wpaie from given vdev
336  *
337  * Return: end of buffer
338  */
339 uint8_t *wlan_crypto_build_wpaie(struct wlan_objmgr_vdev *vdev,
340 					uint8_t *iebuf);
341 
342 /**
343  * wlan_crypto_build_rsnie_with_pmksa() - called by mlme to build rsnie
344  * @vdev: vdev
345  * @iebuf: ie buffer
346  * @pmksa: pmksa struct
347  *
348  * This function gets called by mlme to build rsnie from given vdev
349  *
350  * Return: end of buffer
351  */
352 uint8_t *wlan_crypto_build_rsnie_with_pmksa(struct wlan_objmgr_vdev *vdev,
353 					    uint8_t *iebuf,
354 					    struct wlan_crypto_pmksa *pmksa);
355 
356 /**
357  * wlan_crypto_build_rsnie - called by mlme to build rsnie
358  * @vdev: vdev
359  * @iebuf: ie buffer
360  * @bssid: bssid mac address to add pmkid in rsnie
361  *
362  * This function gets called by mlme to build rsnie from given vdev
363  *
364  * Return: end of buffer
365  */
366 uint8_t *wlan_crypto_build_rsnie(struct wlan_objmgr_vdev *vdev,
367 					uint8_t *iebuf,
368 					struct qdf_mac_addr *bssid);
369 
370 /**
371  * wlan_crypto_wapiie_check - called by mlme to check the wapiie
372  * @crypto_params: crypto params
373  * @frm: ie buffer
374  *
375  * This function gets called by mlme to check the contents of wapi is
376  * matching with given crypto params
377  *
378  * Return: QDF_STATUS_SUCCESS - in case of success
379  */
380 QDF_STATUS wlan_crypto_wapiie_check(struct wlan_crypto_params *crypto_params,
381 				    const uint8_t *frm);
382 
383 /**
384  * wlan_crypto_build_wapiie - called by mlme to build wapi ie
385  * @vdev: vdev
386  * @iebuf: ie buffer
387  *
388  * This function gets called by mlme to build wapi ie from given vdev
389  *
390  * Return: end of buffer
391  */
392 uint8_t *wlan_crypto_build_wapiie(struct wlan_objmgr_vdev *vdev,
393 					uint8_t *iebuf);
394 /**
395  * wlan_crypto_rsn_info - check is given params matching with vdev params.
396  * @vdev: vdev
397  * @crypto params: crypto params
398  *
399  * This function gets called by mlme to check is given params matching with
400  * vdev params.
401  *
402  * Return: true success or false for failure.
403  */
404 bool wlan_crypto_rsn_info(struct wlan_objmgr_vdev *vdev,
405 				struct wlan_crypto_params *crypto_params);
406 /**
407  * wlan_crypto_pn_check - called by data patch for PN check
408  * @vdev: vdev
409  * @wbuf: wbuf
410  *
411  * This function gets called by data patch for PN check
412  *
413  * Return: QDF_STATUS
414  */
415 QDF_STATUS wlan_crypto_pn_check(struct wlan_objmgr_vdev *vdev,
416 					qdf_nbuf_t wbuf);
417 /**
418  * wlan_crypto_vdev_get_crypto_params - called by mlme to get crypto params
419  * @vdev:vdev
420  *
421  * This function gets called by mlme to get crypto params
422  *
423  * Return: wlan_crypto_params or NULL in case of failure
424  */
425 struct wlan_crypto_params *wlan_crypto_vdev_get_crypto_params(
426 						struct wlan_objmgr_vdev *vdev);
427 /**
428  * wlan_crypto_peer_get_crypto_params - called by mlme to get crypto params
429  * @peer:peer
430  *
431  * This function gets called by mlme to get crypto params
432  *
433  * Return: wlan_crypto_params or NULL in case of failure
434  */
435 struct wlan_crypto_params *wlan_crypto_peer_get_crypto_params(
436 						struct wlan_objmgr_peer *peer);
437 
438 /**
439  * wlan_crypto_set_peer_wep_keys - set wep keys into peer entries
440  * @vdev:vdev
441  * @peer:peer
442  *
443  * This function gets called by mlme, when auth frame is received.
444  * this helps in setting wep keys into peer data structure.
445  *
446  * Return: QDF_STATUS
447  */
448 QDF_STATUS wlan_crypto_set_peer_wep_keys(struct wlan_objmgr_vdev *vdev,
449 					struct wlan_objmgr_peer *peer);
450 
451 /**
452  * wlan_crypto_register_crypto_rx_ops - set crypto_rx_ops
453  * @crypto_rx_ops: crypto_rx_ops
454  *
455  * This function gets called by object manager to register crypto rx ops.
456  *
457  * Return: QDF_STATUS
458  */
459 QDF_STATUS wlan_crypto_register_crypto_rx_ops(
460 			struct wlan_lmac_if_crypto_rx_ops *crypto_rx_ops);
461 
462 /**
463  * wlan_crypto_get_crypto_rx_ops - get crypto_rx_ops from psoc
464  * @psoc: psoc
465  *
466  * This function gets called by umac to get the crypto_rx_ops
467  *
468  * Return: crypto_rx_ops
469  */
470 struct wlan_lmac_if_crypto_rx_ops *wlan_crypto_get_crypto_rx_ops(
471 			struct wlan_objmgr_psoc *psoc);
472 /**
473  * wlan_crypto_vdev_has_auth_mode - check authmode for vdev
474  * @vdev: vdev
475  * @authvalue: authvalue to be checked
476  *
477  * This function check is authvalue passed is set in vdev or not
478  *
479  * Return: true or false
480  */
481 bool wlan_crypto_vdev_has_auth_mode(struct wlan_objmgr_vdev *vdev,
482 					wlan_crypto_auth_mode authmode);
483 
484 /**
485  * wlan_crypto_peer_has_auth_mode - check authmode for peer
486  * @peer: peer
487  * @authvalue: authvalue to be checked
488  *
489  * This function check is authvalue passed is set in peer or not
490  *
491  * Return: true or false
492  */
493 bool wlan_crypto_peer_has_auth_mode(struct wlan_objmgr_peer *peer,
494 					wlan_crypto_auth_mode authvalue);
495 
496 /**
497  * wlan_crypto_vdev_has_ucastcipher - check ucastcipher for vdev
498  * @vdev: vdev
499  * @ucastcipher: ucastcipher to be checked
500  *
501  * This function check is ucastcipher passed is set in vdev or not
502  *
503  * Return: true or false
504  */
505 bool wlan_crypto_vdev_has_ucastcipher(struct wlan_objmgr_vdev *vdev,
506 					wlan_crypto_cipher_type ucastcipher);
507 
508 /**
509  * wlan_crypto_peer_has_ucastcipher - check ucastcipher for peer
510  * @peer: peer
511  * @ucastcipher: ucastcipher to be checked
512  *
513  * This function check is ucastcipher passed is set in peer or not
514  *
515  * Return: true or false
516  */
517 bool wlan_crypto_peer_has_ucastcipher(struct wlan_objmgr_peer *peer,
518 					wlan_crypto_cipher_type ucastcipher);
519 
520 
521 /**
522  * wlan_crypto_vdev_has_mcastcipher - check mcastcipher for vdev
523  * @vdev: vdev
524  * @mcastcipher: mcastcipher to be checked
525  *
526  * This function check is mcastcipher passed is set in vdev or not
527  *
528  * Return: true or false
529  */
530 bool wlan_crypto_vdev_has_mcastcipher(struct wlan_objmgr_vdev *vdev,
531 					wlan_crypto_cipher_type mcastcipher);
532 
533 /**
534  * wlan_crypto_peer_has_mcastcipher - check mcastcipher for peer
535  * @peer: peer
536  * @mcastcipher: mcastcipher to be checked
537  *
538  * This function check is mcastcipher passed is set in peer or not
539  *
540  * Return: true or false
541  */
542 bool wlan_crypto_peer_has_mcastcipher(struct wlan_objmgr_peer *peer,
543 					wlan_crypto_cipher_type mcastcipher);
544 
545 /**
546  * wlan_crypto_vdev_has_mgmtcipher - check mgmtcipher for vdev
547  * @vdev: vdev
548  * @mgmtcipher: mgmtcipher to be checked
549  *
550  * This function checks any one of mgmtciphers are supported by vdev or not.
551  *
552  * Return: true or false
553  */
554 bool wlan_crypto_vdev_has_mgmtcipher(struct wlan_objmgr_vdev *vdev,
555 				     uint32_t mgmtcipher);
556 
557 /**
558  * wlan_crypto_peer_has_mgmtcipher - check mgmtcipher for peer
559  * @peer: peer
560  * @mgmtcipher: mgmtcipher to be checked
561  *
562  * This function checks any one of mgmtciphers are supported by peer or not.
563  *
564  * Return: true or false
565  */
566 bool wlan_crypto_peer_has_mgmtcipher(struct wlan_objmgr_peer *peer,
567 				     uint32_t mgmtcipher);
568 
569 /**
570  * wlan_crypto_get_keytype - get keytype
571  * @key: key
572  *
573  * This function gets keytype from key
574  *
575  * Return: keytype
576  */
577 wlan_crypto_cipher_type wlan_crypto_get_key_type(
578 						struct wlan_crypto_key *key);
579 
580 /**
581  * wlan_crypto_vdev_getkey - get key from vdev
582  * @vdev: vdev
583  * @keyix: keyix
584  *
585  * This function gets key from vdev
586  *
587  * Return: key or NULL
588  */
589 struct wlan_crypto_key *wlan_crypto_vdev_getkey(struct wlan_objmgr_vdev *vdev,
590 						uint16_t keyix);
591 /**
592  * wlan_crypto_peer_getkey - get key from peer
593  * @peer: peer
594  * @keyix: keyix
595  *
596  * This function gets key from peer
597  *
598  * Return: key or NULL
599  */
600 struct wlan_crypto_key *wlan_crypto_peer_getkey(struct wlan_objmgr_peer *peer,
601 						uint16_t keyix);
602 /**
603  * wlan_crypto_get_peer_fils_aead - Get peer fils aead set flag
604  * @peer: Peer object
605  *
606  * This function returns the peer fils aead set flag value.
607  *
608  * Return: 1 for enabled, 0 for disabled
609  */
610 uint8_t wlan_crypto_get_peer_fils_aead(struct wlan_objmgr_peer *peer);
611 
612 /**
613  * wlan_crypto_set_peer_fils_aead - Set peer fils aead set flag
614  * @peer: Peer object
615  * @value: Value to set the flag
616  *
617  * This function set the peer fils aead set flag once FILS AUTH received.
618  *
619  * Return: None
620  */
621 void wlan_crypto_set_peer_fils_aead(
622 			struct wlan_objmgr_peer *peer, uint8_t value);
623 
624 /**
625  * wlan_crypto_get_key_header - get header length
626  * @key: key
627  *
628  * This function gets header length based on keytype
629  *
630  * Return: header length
631  */
632 uint8_t wlan_crypto_get_key_header(struct wlan_crypto_key *key);
633 
634 /**
635  * wlan_crypto_get_key_trailer - get cipher trailer length
636  * @key: key
637  *
638  * This function gets cipher trailer length based on keytype
639  *
640  * Return: cipher trailer length
641  */
642 uint8_t wlan_crypto_get_key_trailer(struct wlan_crypto_key *key);
643 
644 /**
645  * wlan_crypto_get_key_miclen - get cipher miclen length
646  * @key: key
647  *
648  * This function gets cipher miclen length based on keytype
649  *
650  * Return: cipher miclen length
651  */
652 uint8_t wlan_crypto_get_key_miclen(struct wlan_crypto_key *key);
653 
654 /**
655  * wlan_crypto_get_keyid - get keyid from frame
656  * @data: frame
657  * @hdrlen: 802.11 header length
658  *
659  * This function parse frame and returns keyid
660  *
661  * Return: keyid
662  */
663 uint16_t wlan_crypto_get_keyid(uint8_t *data, int hdrlen);
664 
665 /**
666  * wlan_crypto_restore_keys - restore crypto keys in hw keycache
667  * @vdev: vdev
668  *
669  * This function restores keys in hw keycache
670  *
671  * Return: void
672  */
673 void wlan_crypto_restore_keys(struct wlan_objmgr_vdev *vdev);
674 
675 /**
676  * wlan_crypto_check_rsn_match - called by ucfg to check for RSN match
677  * @psoc: psoc pointer
678  * @vdev_id: vdev id
679  * @ie_ptr: pointer to IEs
680  * @ie_len: IE length
681  * @peer_crypto_params: return peer crypto parameters
682  *
683  * This function gets called from ucfg to check RSN match.
684  *
685  * Return: true or false
686  */
687 bool wlan_crypto_check_rsn_match(struct wlan_objmgr_psoc *psoc,
688 				 uint8_t vedv_id, uint8_t *ie_ptr,
689 				 uint16_t ie_len, struct wlan_crypto_params *
690 				 peer_crypto_params);
691 
692 /**
693  * wlan_crypto_check_rsn_match - called by ucfg to check for WPA match
694  * @psoc: psoc pointer
695  * @vdev_id: vdev id
696  * @ie_ptr: pointer to IEs
697  * @ie_len: IE length
698  * @peer_crypto_params: return peer crypto parameters
699  *
700  * This function gets called from ucfg to check WPA match.
701  *
702  * Return: true or false
703  */
704 bool wlan_crypto_check_wpa_match(struct wlan_objmgr_psoc *psoc,
705 				 uint8_t vedv_id, uint8_t *ie_ptr,
706 				 uint16_t ie_len, struct wlan_crypto_params *
707 				 peer_crypto_params);
708 
709 /**
710  * wlan_crypto_parse_rsnxe_ie() - parse RSNXE IE
711  * @rsnxe_ie: RSNXE IE pointer
712  * @cap_len: pointer to hold len of ext capability
713  *
714  * Return: pointer to RSNXE capability or NULL
715  */
716 const uint8_t *
717 wlan_crypto_parse_rsnxe_ie(const uint8_t *rsnxe_ie, uint8_t *cap_len);
718 
719 /**
720  * wlan_get_crypto_params_from_wapi_ie - Function to get crypto params
721  * from wapi ie
722  * @crypto_params: return crypto parameters
723  * @ie_ptr: pointer to IEs
724  * @ie_len: IE length
725  *
726  * This function is used to get the crypto parameters from wapi ie
727  *
728  * Context: Any context.
729  * Return: QDF_STATUS
730  */
731 #ifdef FEATURE_WLAN_WAPI
732 QDF_STATUS
733 wlan_get_crypto_params_from_wapi_ie(struct wlan_crypto_params *crypto_params,
734 				    const uint8_t *ie_ptr, uint16_t ie_len);
735 
736 #else
737 static inline QDF_STATUS
738 wlan_get_crypto_params_from_wapi_ie(struct wlan_crypto_params *crypto_params,
739 				    const uint8_t *ie_ptr, uint16_t ie_len)
740 {
741 	return QDF_STATUS_E_NOSUPPORT;
742 }
743 #endif
744 
745 /**
746  * wlan_get_crypto_params_from_wpa_ie - Function to get crypto params
747  * from wpa ie
748  * @crypto_params: return crypto parameters
749  * @ie_ptr: pointer to IEs
750  * @ie_len: IE length
751  *
752  * This function is used to get the crypto parameters from wpa ie
753  *
754  * Context: Any context.
755  * Return: QDF_STATUS
756  */
757 QDF_STATUS
758 wlan_get_crypto_params_from_wpa_ie(struct wlan_crypto_params *crypto_params,
759 				   const uint8_t *ie_ptr, uint16_t ie_len);
760 
761 /**
762  * wlan_get_crypto_params_from_rsn_ie - Function to get crypto params
763  * from rsn ie
764  * @crypto_params: return crypto parameters
765  * @ie_ptr: pointer to IEs
766  * @ie_len: IE length
767  *
768  * This function is used to get the crypto parameters from rsn ie
769  *
770  * Context: Any context.
771  * Return: QDF_STATUS
772  */
773 QDF_STATUS
774 wlan_get_crypto_params_from_rsn_ie(struct wlan_crypto_params *crypto_params,
775 				   const uint8_t *ie_ptr, uint16_t ie_len);
776 
777 /**
778  * wlan_set_vdev_crypto_prarams_from_ie - Sets vdev crypto params from IE info
779  * @vdev: vdev pointer
780  * @ie_ptr: pointer to IE
781  * @ie_len: IE length
782  *
783  * This function gets called from ucfg to set crypto params from IE data.
784  *
785  * Return: QDF_STATUS_SUCCESS or error code
786  */
787 QDF_STATUS wlan_set_vdev_crypto_prarams_from_ie(struct wlan_objmgr_vdev *vdev,
788 						uint8_t *ie_ptr,
789 						uint16_t ie_len);
790 #ifdef WLAN_CRYPTO_GCM_OS_DERIVATIVE
791 static inline int wlan_crypto_aes_gmac(const uint8_t *key, size_t key_len,
792 				       uint8_t *iv, size_t iv_len,
793 				       const uint8_t *aad, size_t aad_len,
794 				       uint8_t *tag)
795 {
796 	return qdf_crypto_aes_gmac(key, key_len, iv, aad,
797 				   aad + AAD_LEN,
798 				   aad_len - AAD_LEN -
799 				   IEEE80211_MMIE_GMAC_MICLEN,
800 				   tag);
801 }
802 #endif
803 #ifdef WLAN_CRYPTO_OMAC1_OS_DERIVATIVE
804 static inline int omac1_aes_128(const uint8_t *key, const uint8_t *data,
805 				size_t data_len, uint8_t *mac)
806 {
807 	return qdf_crypto_aes_128_cmac(key, data, data_len, mac);
808 }
809 
810 static inline int omac1_aes_256(const uint8_t *key, const uint8_t *data,
811 				size_t data_len, uint8_t *mac)
812 {
813 	return 0;
814 }
815 #endif
816 
817 /**
818  * ucfg_crypto_set_key_req() - Set key request to UCFG
819  * @vdev: vdev object
820  * @req: key request information
821  * @key_type: indicates the type of key to be set, unicast or group key
822  *
823  * Return: None
824  */
825 QDF_STATUS ucfg_crypto_set_key_req(struct wlan_objmgr_vdev *vdev,
826 				   struct wlan_crypto_key *req,
827 				   enum wlan_crypto_key_type key_type);
828 
829 /**
830  * wlan_crypto_get_default_key_idx() - Get the default key index
831  * @vdev: vdev object
832  * @igtk: denotes if the request is for igtk key type or not
833  *
834  * Return: Index of the requested key
835  */
836 int8_t wlan_crypto_get_default_key_idx(struct wlan_objmgr_vdev *vdev,
837 				       bool igtk);
838 
839 /**
840  * wlan_crypto_get_cipher() - Get the cipher type for the vdev
841  * @vdev: vdev object
842  * @pairwise: denotes if the request is for pairwise cipher or not
843  * @key_index: Index of the key whose cipher type has to be returned
844  *
845  * Return: enum wlan_crypto_cipher_type
846  */
847 enum wlan_crypto_cipher_type
848 wlan_crypto_get_cipher(struct wlan_objmgr_vdev *vdev,
849 		       bool pairwise, uint8_t key_index);
850 
851 #ifdef CRYPTO_SET_KEY_CONVERGED
852 /**
853  * wlan_crypto_update_set_key_peer() - Update the peer for set key
854  * @vdev: vdev object
855  * @pairwise: denotes if the request is for pairwise cipher or not
856  * @key_index: Index of the key whose peer has to be set
857  * @peer_mac: MAC address of the peer
858  *
859  * Return: None
860  */
861 void wlan_crypto_update_set_key_peer(struct wlan_objmgr_vdev *vdev,
862 				     bool pairwise, uint8_t key_index,
863 				     struct qdf_mac_addr *peer_mac);
864 
865 /**
866  * wlan_crypto_validate_key_params() - validates key parameters
867  * @cipher: cipher type
868  * @key_index: the index of the key
869  * @key_len: key length
870  * @seq_len: sequence counter length
871  *
872  * Return: QDF_STATUS
873  */
874 QDF_STATUS wlan_crypto_validate_key_params(enum wlan_crypto_cipher_type cipher,
875 					   uint8_t key_index, uint8_t key_len,
876 					   uint8_t seq_len);
877 
878 /**
879  * wlan_crypto_save_key() - Allocate memory for storing key
880  * @vdev: vdev object
881  * @key_index: the index of the key that needs to be allocated
882  * @crypto_key: Pointer to crypto key
883  *
884  * Return: QDF_STATUS
885  */
886 QDF_STATUS wlan_crypto_save_key(struct wlan_objmgr_vdev *vdev,
887 				uint8_t key_index,
888 				struct wlan_crypto_key *crypto_key);
889 
890 /**
891  * wlan_crypto_get_key() - Get the stored key information
892  * @vdev: vdev object
893  * @key_index: the index of the key that needs to be retrieved
894  *
895  * Return: Key material
896  */
897 struct wlan_crypto_key *wlan_crypto_get_key(struct wlan_objmgr_vdev *vdev,
898 					    uint8_t key_index);
899 
900 /**
901  * wlan_crypto_set_key_req() - Set key request
902  * @vdev: vdev object
903  * @req: key request information
904  * @key_type: indicates the type of key to be set, unicast or group key
905  *
906  * Return: QDF status
907  */
908 QDF_STATUS wlan_crypto_set_key_req(struct wlan_objmgr_vdev *vdev,
909 				   struct wlan_crypto_key *req,
910 				   enum wlan_crypto_key_type key_type);
911 
912 /**
913  * wlan_crypto_free_vdev_key - Free keys for vdev
914  * @vdev: vdev object
915  *
916  * This function frees keys stored in vdev crypto object.
917  *
918  * Return: None
919  */
920 void wlan_crypto_free_vdev_key(struct wlan_objmgr_vdev *vdev);
921 
922 /**
923  * wlan_crypto_reset_vdev_params - Reset params for vdev
924  * @vdev: vdev object
925  *
926  * This function reset params stored in vdev crypto object.
927  *
928  * Return: None
929  */
930 void wlan_crypto_reset_vdev_params(struct wlan_objmgr_vdev *vdev);
931 #else
932 static inline void wlan_crypto_update_set_key_peer(
933 						struct wlan_objmgr_vdev *vdev,
934 						bool pairwise,
935 						uint8_t key_index,
936 						struct qdf_mac_addr *peer_mac)
937 {
938 }
939 
940 static inline QDF_STATUS
941 wlan_crypto_save_key(struct wlan_objmgr_vdev *vdev, uint8_t key_index,
942 		     struct wlan_crypto_key *crypto_key)
943 {
944 	return QDF_STATUS_SUCCESS;
945 }
946 
947 static inline struct wlan_crypto_key *
948 wlan_crypto_get_key(struct wlan_objmgr_vdev *vdev, uint8_t key_index)
949 {
950 	return NULL;
951 }
952 
953 static inline
954 QDF_STATUS wlan_crypto_set_key_req(struct wlan_objmgr_vdev *vdev,
955 				   struct wlan_crypto_key *req,
956 				   enum wlan_crypto_key_type key_type)
957 {
958 	return QDF_STATUS_SUCCESS;
959 }
960 
961 static inline void wlan_crypto_free_vdev_key(struct wlan_objmgr_vdev *vdev)
962 {
963 }
964 
965 static inline void wlan_crypto_reset_vdev_prarams(struct wlan_objmgr_vdev *vdev)
966 {
967 }
968 #endif /* CRYPTO_SET_KEY_CONVERGED */
969 
970 /**
971  * wlan_crypto_vdev_set_param() - Send vdev set param to firmware.
972  * @psoc: Pointer to PSOC object
973  * @vdev_id: vdev id
974  * @param_id: Param id
975  * @param_value: Param value
976  *
977  * Return: QDF_STATUS
978  */
979 QDF_STATUS
980 wlan_crypto_vdev_set_param(struct wlan_objmgr_psoc *psoc, uint32_t vdev_id,
981 			   uint32_t param_id, uint32_t param_value);
982 
983 /**
984  * wlan_crypto_get_peer_pmksa() - called to get pmksa based on pmksa parameter
985  * @vdev: vdev
986  * @pmksa: bssid
987  *
988  * This function is to get pmksa based on pmksa parameter
989  *
990  * Return: wlan_crypto_pmksa when match found else NULL.
991  */
992 struct wlan_crypto_pmksa *
993 wlan_crypto_get_peer_pmksa(struct wlan_objmgr_vdev *vdev,
994 			   struct wlan_crypto_pmksa *pmksa);
995 
996 /**
997  * wlan_crypto_get_pmksa - called to get pmksa of bssid passed.
998  * @vdev: vdev
999  * @bssid: bssid
1000  *
1001  * This function gets called from to get pmksa for the bssid.
1002  *
1003  * Return: wlan_crypto_pmksa when match found else NULL.
1004  */
1005 struct wlan_crypto_pmksa *
1006 wlan_crypto_get_pmksa(struct wlan_objmgr_vdev *vdev,
1007 		      struct qdf_mac_addr *bssid);
1008 
1009 /**
1010  * wlan_crypto_get_fils_pmksa  - Get the PMKSA for FILS
1011  * SSID, if the SSID and cache id matches
1012  * @vdev:     Pointer with VDEV object
1013  * @cache_id: Cache id
1014  * @ssid:     Pointer to ssid
1015  * @ssid_len: SSID length
1016  *
1017  * Return: PMKSA entry if the cache id and SSID matches
1018  */
1019 struct wlan_crypto_pmksa *
1020 wlan_crypto_get_fils_pmksa(struct wlan_objmgr_vdev *vdev,
1021 			   uint8_t *cache_id, uint8_t *ssid,
1022 			   uint8_t ssid_len);
1023 
1024 /**
1025  * wlan_crypto_pmksa_flush - called to flush saved pmksa
1026  * @crypto_params: crypto_params
1027  *
1028  * This function flush saved pmksa from crypto params.
1029  *
1030  * Return: QDF_STATUS_SUCCESS - in case of success
1031  */
1032 QDF_STATUS wlan_crypto_pmksa_flush(struct wlan_crypto_params *crypto_params);
1033 
1034 /**
1035  * wlan_crypto_set_vdev_param - called by ucfg to set crypto param
1036  * @vdev: vdev
1037  * @pmksa: pmksa to be set/del.
1038  * @set: set(set=1) or del(set=0) pmksa from the list.
1039  *
1040  * This function gets called from ucfg to set or del pmksa.
1041  * when given pmksa is NULL and set is 0, it is for flush all entries.
1042  *
1043  * Return: QDF_STATUS_SUCCESS - in case of success
1044  */
1045 QDF_STATUS wlan_crypto_set_del_pmksa(struct wlan_objmgr_vdev *vdev,
1046 				     struct wlan_crypto_pmksa *pmksa,
1047 				     bool set);
1048 
1049 /**
1050  * wlan_crypto_update_pmk_cache_ft - Updates the mobility domain information
1051  * for a BSSID in the PMKSA Cache table.
1052  * @vdev: vdev
1053  * @pmksa: pmksa to be updated.
1054  *
1055  * This function gets called from ucfg to update pmksa with mdid.
1056  * And flush the matching mdid entries.
1057  *
1058  * Return: QDF_STATUS_SUCCESS - in case of success
1059  */
1060 QDF_STATUS wlan_crypto_update_pmk_cache_ft(struct wlan_objmgr_vdev *vdev,
1061 					   struct wlan_crypto_pmksa *pmksa);
1062 
1063 #if defined(WLAN_SAE_SINGLE_PMK) && defined(WLAN_FEATURE_ROAM_OFFLOAD)
1064 /**
1065  * wlan_crypto_selective_clear_sae_single_pmk_entries - Clear the PMK entries
1066  * for BSS which have the single PMK flag set other than the current connected
1067  * AP
1068  * @vdev:       Vdev
1069  * @conn_bssid: Connected bssid
1070  */
1071 void
1072 wlan_crypto_selective_clear_sae_single_pmk_entries(
1073 		struct wlan_objmgr_vdev *vdev, struct qdf_mac_addr *conn_bssid);
1074 
1075 /**
1076  * wlan_crypto_set_sae_single_pmk_bss_cap - Set the peer SAE single pmk
1077  * feature supported status
1078  * @vdev: Vdev
1079  * @bssid: BSSID for which the flag is to be set
1080  * @single_pmk_capable_bss: Flag to indicate Sae single pmk supported BSSID or
1081  * not
1082  */
1083 void wlan_crypto_set_sae_single_pmk_bss_cap(struct wlan_objmgr_vdev *vdev,
1084 					    struct qdf_mac_addr *bssid,
1085 					    bool single_pmk_capable_bss);
1086 
1087 /**
1088  * wlan_crypto_set_sae_single_pmk_bss_cap - Set the peer SAE single pmk info
1089  * @vdev: Vdev
1090  * @roam_sync_pmksa: pmk info for roamed AP
1091  */
1092 void
1093 wlan_crypto_set_sae_single_pmk_info(struct wlan_objmgr_vdev *vdev,
1094 				    struct wlan_crypto_pmksa *roam_sync_pmksa);
1095 
1096 #else
1097 static inline void
1098 wlan_crypto_selective_clear_sae_single_pmk_entries(
1099 		struct wlan_objmgr_vdev *vdev, struct qdf_mac_addr *conn_bssid)
1100 {
1101 }
1102 
1103 static inline
1104 void wlan_crypto_set_sae_single_pmk_bss_cap(struct wlan_objmgr_vdev *vdev,
1105 					    struct qdf_mac_addr *bssid,
1106 					    bool single_pmk_capable_bss)
1107 {
1108 }
1109 
1110 static inline void
1111 wlan_crypto_set_sae_single_pmk_info(struct wlan_objmgr_vdev *vdev,
1112 				    struct wlan_crypto_pmksa *roam_sync_pmksa)
1113 {
1114 }
1115 #endif
1116 
1117 #if defined(WIFI_POS_CONVERGED) && defined(WLAN_FEATURE_RTT_11AZ_SUPPORT)
1118 QDF_STATUS
1119 wlan_crypto_set_ltf_keyseed(struct wlan_objmgr_psoc *psoc,
1120 			    struct wlan_crypto_ltf_keyseed_data *data);
1121 #else
1122 static inline QDF_STATUS
1123 wlan_crypto_set_ltf_keyseed(struct wlan_objmgr_psoc *psoc,
1124 			    struct wlan_crypto_ltf_keyseed_data *data)
1125 {
1126 	return QDF_STATUS_SUCCESS;
1127 }
1128 #endif
1129 
1130 #ifdef WLAN_FEATURE_FILS_SK
1131 /**
1132  * lim_create_fils_rik()- This API create rik using rrk coming from
1133  * supplicant.
1134  * @rrk: input rrk
1135  * @rrk_len: rrk length
1136  * @rik: Created rik
1137  * @rik_len: rik length to be filled
1138  *
1139  * rIK = KDF (K, S), where
1140  * K = rRK and
1141  * S = rIK Label + "\0" + cryptosuite + length
1142  * The rIK Label is the 8-bit ASCII string:
1143  * Re-authentication Integrity Key@ietf.org
1144  *
1145  * Return: QDF_STATUS
1146  */
1147 QDF_STATUS wlan_crypto_create_fils_rik(uint8_t *rrk, uint8_t rrk_len,
1148 				       uint8_t *rik, uint32_t *rik_len);
1149 #endif /* WLAN_FEATURE_FILS_SK */
1150 #endif /* end of _WLAN_CRYPTO_GLOBAL_API_H_ */
1151