hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/******************************************************************************
 *
 * Copyright(c) 2019 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#define _PHL_SEC_C_
#include "phl_headers.h"
 
#define RTW_PHL_EXT_KEY_LEN 32
#define RTW_SEC_KEY_TYPE_NUM 3
 
static enum rtw_phl_status
_phl_set_key(struct phl_info_t *phl_info,
             struct rtw_phl_stainfo_t *sta,
             struct phl_sec_param_h *crypt,
             u8 *keybuf)
{
   enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
   enum rtw_phl_status phl_status = RTW_PHL_STATUS_FAILURE;
 
   if(keybuf)
       PHL_INFO("Add_key:: enc_type(%d) key_id(%d) key_type(%d)\n",
            crypt->enc_type, crypt->keyid, crypt->key_type);
   hal_status = rtw_hal_set_key(phl_info->hal,
                                sta,
                                crypt->enc_type,
                                (crypt->key_len==RTW_PHL_EXT_KEY_LEN)?1:0,
                                crypt->spp,
                                crypt->keyid,
                                crypt->key_type,
                                keybuf);
   if (hal_status == RTW_HAL_STATUS_SUCCESS)
       phl_status = RTW_PHL_STATUS_SUCCESS;
 
   return phl_status;
}
 
#ifdef CONFIG_CMD_DISP
struct cmd_sec_param {
   struct rtw_phl_stainfo_t *sta;
   struct phl_sec_param_h *crypt;
   u8 *keybuf;
};
 
static void
_phl_cmd_set_key_done(void *drv_priv,
                      u8 *cmd,
                      u32 cmd_len,
                      enum rtw_phl_status status)
{
   struct cmd_sec_param *param = (struct cmd_sec_param *)cmd;
 
   if (param) {
       if (param->keybuf)
           _os_kmem_free(drv_priv,
                        param->keybuf,
                        param->crypt->key_len);
 
       if (param->crypt)
           _os_kmem_free(drv_priv,
                        param->crypt,
                        sizeof(struct phl_sec_param_h));
 
       _os_kmem_free(drv_priv, param, cmd_len);
   }
}
 
enum rtw_phl_status
_phl_cmd_set_key(void *phl,
                 struct rtw_phl_stainfo_t *sta,
                 struct phl_sec_param_h *crypt,
                 u8 *keybuf,
                 enum phl_cmd_type cmd_type,
                 u32 cmd_timeout)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
   void *drv = phl_to_drvpriv(phl_info);
   enum rtw_phl_status psts = RTW_PHL_STATUS_FAILURE;
 
   struct cmd_sec_param *param = NULL;
   u32 param_len = 0, crypt_len = 0;
 
   if (cmd_type == PHL_CMD_DIRECTLY) {
       psts = _phl_set_key(phl_info, sta, crypt, keybuf);
       goto _exit;
   }
 
   param_len = sizeof(struct cmd_sec_param);
   param = _os_kmem_alloc(drv, param_len);
   if (param == NULL) {
       PHL_ERR("%s: alloc param failed!\n", __func__);
       psts = RTW_PHL_STATUS_RESOURCE;
       goto error_param;
   }
   _os_mem_set(drv, param, 0, param_len);
   param->sta = sta;
 
   crypt_len = sizeof(struct phl_sec_param_h);
   param->crypt = _os_kmem_alloc(drv, crypt_len);
   if (param->crypt == NULL) {
       PHL_ERR("%s: alloc param->crypt failed!\n", __func__);
       psts = RTW_PHL_STATUS_RESOURCE;
       goto error_crypt;
   }
   _os_mem_set(drv, param->crypt, 0, crypt_len);
   _os_mem_cpy(drv, param->crypt, crypt, crypt_len);
 
   if (keybuf) { /* set key */
       param->keybuf = _os_kmem_alloc(drv, param->crypt->key_len);
       if (param->keybuf == NULL) {
           PHL_ERR("%s: alloc param->keybuf failed!\n", __func__);
           psts = RTW_PHL_STATUS_RESOURCE;
           goto error_key_buf;
       }
       _os_mem_cpy(drv, param->keybuf, keybuf, param->crypt->key_len);
   }
 
   psts = phl_cmd_enqueue(phl_info,
                          sta->rlink->hw_band,
                          MSG_EVT_SEC_KEY,
                          (u8 *)param,
                          param_len,
                          _phl_cmd_set_key_done,
                          cmd_type,
                          cmd_timeout);
 
   if (is_cmd_failure(psts)) {
       /* Send cmd success, but wait cmd fail*/
       psts = RTW_PHL_STATUS_FAILURE;
   } else if (psts != RTW_PHL_STATUS_SUCCESS) {
       /* Send cmd fail */
       psts = RTW_PHL_STATUS_FAILURE;
       goto error_cmd;
   }
 
   return psts;
 
error_cmd:
   if (param->keybuf)
       _os_kmem_free(drv, param->keybuf, param->crypt->key_len);
error_key_buf:
   if (param->crypt)
       _os_kmem_free(drv, param->crypt, crypt_len);
 
error_crypt:
   if (param)
       _os_kmem_free(drv, param, param_len);
 
error_param:
_exit:
   return psts;
}
 
enum rtw_phl_status
phl_cmd_set_key_hdl(struct phl_info_t *phl_info, u8 *param)
{
   struct cmd_sec_param *cmd_sec_param = (struct cmd_sec_param *)param;
 
   return _phl_set_key(phl_info,
                       cmd_sec_param->sta,
                       cmd_sec_param->crypt,
                       cmd_sec_param->keybuf);
}
#endif /* CONFIG_CMD_DISP */
 
enum rtw_phl_status
rtw_phl_cmd_add_key(void *phl,
                    struct rtw_phl_stainfo_t *sta,
                    struct phl_sec_param_h *crypt,
                    u8 *keybuf,
                    enum phl_cmd_type cmd_type,
                    u32 cmd_timeout)
{
#ifdef CONFIG_CMD_DISP
   return _phl_cmd_set_key(phl, sta, crypt, keybuf, cmd_type, cmd_timeout);
#else
   PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s: not support add key cmd\n",
             __func__);
 
   return _phl_set_key((struct phl_info_t *)phl, sta, crypt, keybuf);
#endif /* CONFIG_CMD_DISP */
}
 
enum rtw_phl_status
rtw_phl_cmd_del_key(void *phl,
                    struct rtw_phl_stainfo_t *sta,
                    struct phl_sec_param_h *crypt,
                    enum phl_cmd_type cmd_type,
                    u32 cmd_timeout)
{
#ifdef CONFIG_CMD_DISP
   return _phl_cmd_set_key(phl, sta, crypt, NULL, cmd_type, cmd_timeout);
#else
   PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s: not support del key cmd\n",
             __func__);
 
   return _phl_set_key((struct phl_info_t *)phl, sta, crypt, NULL);
#endif /* CONFIG_CMD_DISP */
}
 
u8 rtw_phl_trans_sec_mode(u8 unicast, u8 multicast)
{
   u8    ret = RTW_SEC_ENT_MODE_0;
 
   if (RTW_ENC_NONE == unicast && RTW_ENC_NONE == multicast) {
       ret = RTW_SEC_ENT_MODE_0;
   } else if ((RTW_ENC_WEP40 == unicast && RTW_ENC_WEP40 == multicast) ||
       (RTW_ENC_WEP104 == unicast && RTW_ENC_WEP104 == multicast)) {
       ret = RTW_SEC_ENT_MODE_1;
   } else if (RTW_ENC_WEP40 == multicast || RTW_ENC_WEP104 == multicast) {
       ret = RTW_SEC_ENT_MODE_3;
   } else {
       ret = RTW_SEC_ENT_MODE_2;
   }
 
   return ret;
}
 
u8 rtw_phl_get_sec_cam_idx(void *phl,
                           struct rtw_phl_stainfo_t *sta,
                           u8 keyid,
                           u8 key_type)
{
   u8 ret = 0;
   struct phl_info_t *phl_info = (struct phl_info_t *)phl;
 
   ret = (u8) rtw_hal_search_key_idx(phl_info->hal, sta, keyid, key_type);
 
   return ret;
}