1 /*
2  * Copyright (c) 2011-2015, 2017-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 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  *
22  * This file lim_security_utils.h contains the utility definitions
23  * related to WEP encryption/decryption etc.
24  * Author:        Chandra Modumudi
25  * Date:          02/13/02
26  * History:-
27  * Date           Modified by    Modification Information
28  * --------------------------------------------------------------------
29  */
30 #ifndef __LIM_SECURITY_UTILS_H
31 #define __LIM_SECURITY_UTILS_H
32 #include "sir_mac_prot_def.h"      /* for tSirMacAuthFrameBody */
33 
34 #define LIM_ENCR_AUTH_BODY_LEN  (SIR_MAC_AUTH_FRAME_INFO_LEN + \
35 				 SIR_MAC_AUTH_CHALLENGE_BODY_LEN + \
36 				 SIR_MAC_WEP_IV_LENGTH + \
37 				 SIR_MAC_WEP_ICV_LENGTH)
38 
39 #define LIM_ENCR_AUTH_BODY_LEN_SAP  (SIR_MAC_AUTH_FRAME_INFO_LEN + \
40 					 SIR_MAC_SAP_AUTH_CHALLENGE_LENGTH + \
41 					 SIR_MAC_CHALLENGE_ID_LEN + \
42 					 SIR_MAC_WEP_IV_LENGTH + \
43 					 SIR_MAC_WEP_ICV_LENGTH)
44 
45 #define LIM_ENCR_AUTH_INFO_LEN	(SIR_MAC_AUTH_FRAME_INFO_LEN +\
46 				 SIR_MAC_WEP_IV_LENGTH + \
47 				 SIR_MAC_WEP_ICV_LENGTH + \
48 				 SIR_MAC_CHALLENGE_ID_LEN)
49 
50 
51 struct tLimPreAuthNode;
52 
53 uint8_t lim_is_auth_algo_supported(struct mac_context *, tAniAuthType,
54 				   struct pe_session *);
55 
56 /* MAC based authentication related functions */
57 void lim_init_pre_auth_list(struct mac_context *);
58 void lim_delete_pre_auth_list(struct mac_context *);
59 struct tLimPreAuthNode *lim_search_pre_auth_list(struct mac_context *,
60 						 tSirMacAddr);
61 
62 #ifdef WLAN_FEATURE_11BE_MLO
63 /**
64  * lim_search_pre_auth_list_by_mld_addr() - This function is called when
65  * Authentication frame is received by AP (or at a STA in IBSS supporting MAC
66  * based authentication) to search using MLD address if a STA is in the middle
67  * of MAC Authentication transaction sequence.
68  * @mac: MAC context
69  * @mldaddr: MLD address of the STA that sent
70  *
71  * Return: Pointer to pre-auth node if found, else NULL
72  */
73 struct tLimPreAuthNode *lim_search_pre_auth_list_by_mld_addr(
74 							struct mac_context *mac,
75 							tSirMacAddr mldaddr);
76 #endif
77 void lim_add_pre_auth_node(struct mac_context *, struct tLimPreAuthNode *);
78 void lim_delete_pre_auth_node(struct mac_context *, tSirMacAddr);
79 void lim_release_pre_auth_node(struct mac_context *mac,
80 			       tpLimPreAuthNode pAuthNode);
81 void lim_restore_from_auth_state(struct mac_context *,
82 				tSirResultCodes, uint16_t, struct pe_session *);
83 uint8_t lim_delete_open_auth_pre_auth_node(struct mac_context *mac_ctx);
84 
85 /* Encryption/Decryption related functions */
86 void lim_compute_crc32(uint8_t *, uint8_t *, uint16_t);
87 void lim_rc4(uint8_t *, uint8_t *, uint8_t *, uint32_t, uint16_t);
88 void lim_encrypt_auth_frame(struct mac_context *, uint8_t, uint8_t *, uint8_t *,
89 			    uint8_t *, uint32_t);
90 uint8_t lim_decrypt_auth_frame(struct mac_context *, uint8_t *, uint8_t *,
91 			       uint8_t *, uint32_t, uint16_t);
92 
93 #define  PTAPS  0xedb88320
94 
lim_crc_update(uint32_t crc,uint8_t x)95 static inline uint32_t lim_crc_update(uint32_t crc, uint8_t x)
96 {
97 
98 	/* Update CRC computation for 8 bits contained in x */
99 	/* */
100 	uint32_t z;
101 	uint32_t fb;
102 	int i;
103 
104 	z = crc ^ x;
105 	for (i = 0; i < 8; i++) {
106 		fb = z & 1;
107 		z >>= 1;
108 		if (fb)
109 			z ^= PTAPS;
110 	}
111 	return z;
112 }
113 
114 #endif /* __LIM_SECURITY_UTILS_H */
115