xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/hal_g6/hal_cam.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #define _HAL_CAM_C_
16 #include "hal_headers.h"
17 
18 /**
19  * This function calls halmac api to configure security cam
20  * @hal: see struct hal_info_t
21  * @sta: sta info of specified address cam entry
22  * @type: encryption type of this key
23  * @ext_key: whether 256bit key or not
24  * @spp: spp mode
25  * @keyid: key index
26  * @keytype: specify unicast or multicast or bip key type
27  * @keybuf: key buffer length according to ext_key
28  * return enum RTW_HAL_STATUS
29  */
30 enum rtw_hal_status
rtw_hal_set_key(void * hal,struct rtw_phl_stainfo_t * sta,u8 type,u8 ext_key,u8 spp,u8 keyid,u8 keytype,u8 * keybuf)31 rtw_hal_set_key(void *hal, struct rtw_phl_stainfo_t *sta, u8 type, u8 ext_key, u8 spp,
32 				u8 keyid, u8 keytype, u8 *keybuf)
33 {
34 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
35 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
36 	u8 macid = (u8)sta->macid;
37 
38 	if (keybuf == NULL) {
39 		/* delete key */
40 		hal_status = rtw_hal_mac_delete_key(hal_info, macid, type, ext_key,
41 					spp, keyid, keytype);
42 	} else {
43 		/* add key */
44 		if (ext_key) {
45 			hal_status = rtw_hal_mac_add_key(hal_info, macid, type, ext_key,
46 					spp, keyid, keytype, keybuf);
47 			hal_status = rtw_hal_mac_add_key(hal_info, macid, type, ext_key, spp,
48 					keyid, keytype, (keybuf+16));
49 		} else {
50 			hal_status = rtw_hal_mac_add_key(hal_info, macid, type, 0,
51 					spp, keyid, keytype, keybuf);
52 		}
53 	}
54 
55 	return hal_status;
56 }
57 
58 u32
rtw_hal_search_key_idx(void * hal,struct rtw_phl_stainfo_t * sta,u8 keyid,u8 keytype)59 rtw_hal_search_key_idx(void *hal, struct rtw_phl_stainfo_t *sta,
60 						u8 keyid, u8 keytype)
61 {
62 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
63 	u32 sec_cam_idx = 0;
64 	u8 macid = (u8)sta->macid;
65 
66 	sec_cam_idx = rtw_hal_mac_search_key_idx(hal_info,
67 						 macid,
68 						 keyid,
69 						 keytype);
70 
71 	return sec_cam_idx;
72 }