• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: WiFi和bt共存特性文件.
15  * Create: 2020-7-9
16  */
17 
18 #ifndef __HMAC_BTCOEX_C__
19 #define __HMAC_BTCOEX_C__
20 
21 /*****************************************************************************
22   1 头文件包含
23 *****************************************************************************/
24 #include "hmac_btcoex.h"
25 #include "mac_data.h"
26 #include "hmac_device.h"
27 #include "hal_rf.h"
28 #include "hal_device_fsm.h"
29 
30 #include "hmac_alg_notify.h"
31 #include "hmac_scan.h"
32 #include "hmac_m2s.h"
33 #include "wlan_spec.h"
34 #include "wlan_msg.h"
35 #include "hmac_fcs.h"
36 #include "oal_netbuf_data.h"
37 #include "hmac_ext_if.h"
38 #include "mac_data.h"
39 #include "hmac_resource.h"
40 #include "hmac_vap.h"
41 #include "hmac_user.h"
42 #include "hmac_fsm.h"
43 #include "hmac_mgmt_sta.h"
44 #include "hmac_mgmt_bss_comm.h"
45 #include "hmac_btcoex_ba.h"
46 #include "hmac_btcoex_btsta.h"
47 #include "hmac_btcoex_m2s.h"
48 #include "hmac_btcoex_notify.h"
49 #include "hmac_btcoex_ps.h"
50 #include "hmac_feature_interface.h"
51 #include "frw_util_notifier.h"
52 #include "frw_ext_if.h"
53 #include "msg_btcoex_rom.h"
54 #include "hmac_ccpriv.h"
55 #ifdef __cplusplus
56 #if __cplusplus
57 extern "C" {
58 #endif
59 #endif
60 
61 #undef THIS_FILE_ID
62 #define THIS_FILE_ID DIAG_FILE_ID_WIFI_HOST_HMAC_BTCOEX_C
63 
64 #undef THIS_MOD_ID
65 #define THIS_MOD_ID DIAG_MOD_ID_WIFI_HOST
66 
67 osal_u8 g_btcoex_wlan_busy_status = OSAL_FALSE;
68 
69 osal_u8 g_rx_win_size_siso[BTCOEX_RX_WINDOW_SIZE_GRADE_BUTT][BTCOEX_RX_WINDOW_SIZE_INDEX_BUTT] = {
70     {2, 4, 8, 64}, {4, 8, 32, 64}
71 };
72 
73 osal_u8 g_rx_ba_win_size[WLAN_BW_CAP_BUTT][BTCOEX_RX_WINDOW_SIZE_INDEX_BUTT] = {
74     {2, 4, 8, 64},  // 20M
75     {4, 8, 32, 64}  // 40M
76 };
77 
78 /****************************************
79               音乐    电话    数传
80     2G/20M      0       0       0
81     5G/20M      0       0       0
82     2G/40M      0       1       1
83     5G/40M      0       0       1
84     5G/80M      1       1       1
85 *****************************************/
86 osal_u8 g_rx_win_size_grage_siso[WLAN_BAND_BUTT][WLAN_BW_CAP_BUTT][BTCOEX_ACTIVE_MODE_BUTT] = {
87     /* 2G */
88     /* 20M */ /* 40M */
89     /* 音乐, 电话, 数传 */
90     {{0, 0, 0}, {0, 1, 1}, {1, 1, 1}, {1, 1, 1}},
91     /* 5G */
92     /* 20M */ /* 40M */ /* 80M */
93     /* 音乐, 电话, 数传 */
94     {{0, 0, 0}, {0, 0, 1}, {1, 1, 1}, {1, 1, 1}}
95 };
96 
97 #if defined(WLAN_MAX_NSS_NUM) && defined(WLAN_SINGLE_NSS) && (WLAN_MAX_NSS_NUM != WLAN_SINGLE_NSS)
98 osal_u8 g_rx_win_size_mimo[BTCOEX_RX_WINDOW_SIZE_GRADE_BUTT][BTCOEX_RX_WINDOW_SIZE_INDEX_BUTT] = {
99     {2, 4, 8, 64}, {8, 16, 32, 64}
100 };
101 /****************************************
102               音乐    电话    数传
103     2G/20M      0       0       0
104     5G/20M      0       0       0
105     2G/40M      0       1       1
106     5G/40M      0       0       1
107     5G/80M      1       1       1
108 *****************************************/
109 osal_u8 g_rx_win_size_grage_mimo[WLAN_BAND_BUTT][WLAN_BW_CAP_BUTT][BTCOEX_ACTIVE_MODE_BUTT] = {
110     /* 2G */
111     /* 20M */ /* 40M */
112     /* 音乐, 电话, 数传 */
113     {{1, 0, 1}, {1, 0, 1}, {1, 1, 1}, {1, 1, 1}},
114     /* 5G */
115     /* 20M */ /* 40M */ /* 80M */
116     /* 音乐, 电话, 数传 */
117     {{0, 0, 0}, {0, 0, 1}, {1, 1, 1}, {1, 1, 1}}
118 };
119 
120 osal_u16 g_aus_btcoex_rate_thresholds_mimo[WLAN_BAND_BUTT][WLAN_BW_CAP_BUTT][BTCOEX_RATE_THRESHOLD_BUTT] = {
121     /* 2G */
122     /* 20M */ /* 40M */
123     {{23, 70}, {50, 170}, {0, 0},     {0, 0}},
124     /* 5G */
125     /* 20M */ /* 40M */ /* 80M */
126     {{23, 90}, {50, 180}, {108, 360}, {0, 0}}
127 };
128 #endif
129 
130 osal_u16 g_occupied_point[BTCOEX_LINKLOSS_OCCUPIED_NUMBER];
131 
132 hmac_device_btcoex_stru *g_hmac_device_btcoex;
133 /*****************************************************************************
134   函数实现
135 *****************************************************************************/
hmac_get_g_btcoex_wlan_busy_status(osal_void)136 OSAL_STATIC osal_u8 hmac_get_g_btcoex_wlan_busy_status(osal_void)
137 {
138     return g_btcoex_wlan_busy_status;
139 }
hmac_set_g_btcoex_wlan_busy_status(osal_u8 wlan_busy)140 OSAL_STATIC osal_void hmac_set_g_btcoex_wlan_busy_status(osal_u8 wlan_busy)
141 {
142     g_btcoex_wlan_busy_status = wlan_busy;
143     return;
144 }
hmac_get_g_rx_ba_win_size(osal_u32 index1,osal_u32 index2)145 osal_u8 hmac_get_g_rx_ba_win_size(osal_u32 index1, osal_u32 index2)
146 {
147     return g_rx_ba_win_size[index1][index2];
148 }
hmac_get_g_rx_win_size_siso(osal_u32 index1,osal_u32 index2)149 osal_u8 hmac_get_g_rx_win_size_siso(osal_u32 index1, osal_u32 index2)
150 {
151     return g_rx_win_size_siso[index1][index2];
152 }
hmac_get_g_rx_win_size_grage_siso(osal_u32 index1,osal_u32 index2,osal_u32 index3)153 osal_u8 hmac_get_g_rx_win_size_grage_siso(osal_u32 index1, osal_u32 index2, osal_u32 index3)
154 {
155     return g_rx_win_size_grage_siso[index1][index2][index3];
156 }
157 #if (defined(WLAN_MAX_NSS_NUM) && defined(WLAN_SINGLE_NSS) && WLAN_MAX_NSS_NUM != WLAN_SINGLE_NSS)
hmac_get_g_rx_win_size_mimo(osal_u32 index1,osal_u32 index2)158 osal_u8 hmac_get_g_rx_win_size_mimo(osal_u32 index1, osal_u32 index2)
159 {
160     return g_rx_win_size_mimo[index1][index2];
161 }
hmac_get_g_rx_win_size_grage_mimo(osal_u32 index1,osal_u32 index2,osal_u32 index3)162 osal_u8 hmac_get_g_rx_win_size_grage_mimo(osal_u32 index1, osal_u32 index2, osal_u32 index3)
163 {
164     return g_rx_win_size_grage_mimo[index1][index2][index3];
165 }
166 #endif
167 
168 /*****************************************************************************
169  函数名:      hmac_btcoex_find_all_valid_sta_per_device
170  功能描述  : hal device上找到所有满足btcoex处理要求的sta。
171            (1)暂时只考虑sta和gc(02只考虑legacy sta, 03新增考虑sta gc )
172            (2)处理已经up或者pause,关联上的vap,对于速率统计等,都是基于user的,需要关联成功,
173            ps机制要处理前景扫描状态,不采用此接口。
174 *****************************************************************************/
hmac_btcoex_find_all_valid_sta_per_device(const hal_to_dmac_device_stru * hal_device,osal_u8 * vap_id,osal_u16 vap_id_len)175 osal_u8 hmac_btcoex_find_all_valid_sta_per_device(const hal_to_dmac_device_stru *hal_device, osal_u8 *vap_id,
176     osal_u16 vap_id_len)
177 {
178     hmac_vap_stru *hmac_vap = OSAL_NULL;
179     osal_u8 vap_index;
180     osal_u8 up_vap_num;
181     osal_u8 valid_sta_num = 0;
182     osal_u8 mac_vap_id[WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE] = {0};
183     unref_param(vap_id_len);
184 
185     /* 找到所有up的vap设备 */
186     up_vap_num = hal_device_find_all_up_vap(hal_device, mac_vap_id, WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE);
187     for (vap_index = 0; vap_index < up_vap_num; vap_index++) {
188         hmac_vap = (hmac_vap_stru *)mac_res_get_hmac_vap(mac_vap_id[vap_index]);
189         if (hmac_vap == OSAL_NULL) {
190             oam_error_log1(0, OAM_SF_COEX,
191                 "vap_id[%d] hmac_btcoex_find_all_valid_sta_per_device::hmac_vap IS NULL.", mac_vap_id[vap_index]);
192             continue;
193         }
194 
195         /* 1.非sta的话,不需要考虑 */
196         if (is_ap(hmac_vap)) {
197             continue;
198         }
199 
200         /* 2.valid sta 统计(02和03在此做区分) */
201         if (mac_btcoex_check_valid_sta(hmac_vap) == OSAL_TRUE) {
202             /* 找到sta,进行赋值 */
203             vap_id[valid_sta_num++] = hmac_vap->vap_id;
204         }
205     }
206 
207     return valid_sta_num;
208 }
209 
210 /*****************************************************************************
211  函 数 名  : hmac_btcoex_find_all_valid_ap_per_device
212  功能描述  : hal device上找到所有满足btcoex处理要求的ap
213              (1)暂时只考虑ap和go(02只考虑legacy ap, 03新增考虑sta go )
214 *****************************************************************************/
hmac_btcoex_find_all_valid_ap_per_device(const hal_to_dmac_device_stru * hal_device,osal_u8 * vap_id,osal_u16 vap_id_size)215 osal_u8 hmac_btcoex_find_all_valid_ap_per_device(const hal_to_dmac_device_stru *hal_device, osal_u8 *vap_id,
216     osal_u16 vap_id_size)
217 {
218     hmac_vap_stru *hmac_vap = OSAL_NULL;
219     osal_u8 vap_index;
220     osal_u8 up_vap_num;
221     osal_u8 valid_ap_num = 0;
222     osal_u8 mac_vap_id[WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE] = {0};
223 
224     unref_param(vap_id_size);
225 
226     /* 找到所有up的vap设备 */
227     up_vap_num = hal_device_find_all_up_vap(hal_device, mac_vap_id, WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE);
228     for (vap_index = 0; vap_index < up_vap_num; vap_index++) {
229         hmac_vap = (hmac_vap_stru *)mac_res_get_hmac_vap(mac_vap_id[vap_index]);
230         if (hmac_vap == OSAL_NULL) {
231             oam_error_log1(0, OAM_SF_COEX,
232                 "vap_id[%d] hmac_btcoex_find_all_valid_ap_per_device::hmac_vap IS NULL.", mac_vap_id[vap_index]);
233             continue;
234         }
235 
236         /* 1.非ap的话,不需要考虑 */
237         if (is_sta(hmac_vap)) {
238             continue;
239         }
240 
241         /* 2.valid ap 统计(02和03在此做区分) */
242         if (mac_btcoex_check_valid_ap(hmac_vap) == OSAL_TRUE) {
243             /* 找到ap,进行赋值 */
244             vap_id[valid_ap_num++] = hmac_vap->vap_id;
245         }
246     }
247 
248     return valid_ap_num;
249 }
250 
251 /*****************************************************************************
252  函 数 名  : hmac_btcoex_rx_average_rate_calculate
253  功能描述  : 统计Wifi的平均速率
254 *****************************************************************************/
hmac_btcoex_rx_average_rate_calculate(hmac_user_btcoex_rx_info_stru * btcoex_wifi_rx_rate_info,osal_u32 * rx_rate,osal_u16 * rx_count)255 static INLINE__ osal_void hmac_btcoex_rx_average_rate_calculate(hmac_user_btcoex_rx_info_stru *btcoex_wifi_rx_rate_info,
256     osal_u32 *rx_rate, osal_u16 *rx_count)
257 {
258     unref_param(rx_rate);
259 
260     if (btcoex_wifi_rx_rate_info->rx_rate_stat_count == 0) {
261         btcoex_wifi_rx_rate_info->rx_rate_mbps = 0;
262         *rx_count = 0;
263         return;
264     }
265 
266     /* 计算完之后需要重新清零,做下一次统计计数 */
267     (osal_void)memset_s(btcoex_wifi_rx_rate_info, sizeof(hmac_user_btcoex_rx_info_stru),
268                       0, sizeof(hmac_user_btcoex_rx_info_stru));
269 }
270 
hmac_btcoex_rx_rate_statistics_flag_callback(osal_void * arg)271 osal_u32 hmac_btcoex_rx_rate_statistics_flag_callback(osal_void *arg)
272 {
273     hal_btcoex_btble_status_stru *btcoex_btble_status = OSAL_NULL;
274     hmac_vap_btcoex_rx_statistics_stru *btcoex_rx_stat = OSAL_NULL;
275     hmac_user_btcoex_rx_info_stru *btcoex_rx_info = OSAL_NULL;
276     hmac_vap_stru *hmac_vap = OSAL_NULL;
277     hmac_user_stru *hmac_user = OSAL_NULL;
278 
279     hmac_vap = (hmac_vap_stru *)arg;
280     if (mac_btcoex_check_valid_sta(hmac_vap) == OSAL_FALSE) {
281         return OAL_SUCC;
282     }
283 
284     hmac_user = (hmac_user_stru *)mac_res_get_hmac_user_etc(hmac_vap->assoc_vap_id);
285     if (osal_unlikely(hmac_user == OSAL_NULL)) {
286         oam_warning_log2(0, 0, "vap_id[%d] {hmac_btcoex_rx_rate_statistics_flag_callback::hmac_user[%d] null.}",
287             hmac_vap->vap_id, hmac_vap->assoc_vap_id);
288         return OAL_ERR_CODE_PTR_NULL;
289     }
290 
291     btcoex_btble_status = hal_btcoex_btble_status();
292     btcoex_rx_stat = &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_rx_statistics);
293     btcoex_rx_info = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_rx_info);
294 
295     /* BT业务结束 */
296     if (btcoex_btble_status->bt_status.bt_status.bt_ba == OSAL_FALSE) {
297         hmac_user_btcoex_delba_stru *btcoex_delba;
298         btcoex_delba = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_delba);
299         btcoex_rx_stat->rx_rate_statistics_flag = OSAL_FALSE;
300         frw_destroy_timer_entry(&(btcoex_rx_stat->bt_coex_statistics_timer));
301         frw_destroy_timer_entry(&(btcoex_rx_stat->bt_coex_low_rate_timer));
302 
303         if (btcoex_delba->ba_size_real_index != BTCOEX_RX_WINDOW_SIZE_INDEX_3) {
304             btcoex_delba->ba_size_real_index = BTCOEX_RX_WINDOW_SIZE_INDEX_3;
305             btcoex_delba->ba_size_expect_index = BTCOEX_RX_WINDOW_SIZE_INDEX_3;
306             hmac_btcoex_update_ba_size(hmac_vap, btcoex_delba, btcoex_btble_status);
307             hmac_btcoex_delba_trigger(hmac_vap, OSAL_TRUE, btcoex_delba);
308         }
309 
310         (osal_void)memset_s(btcoex_rx_info, sizeof(hmac_user_btcoex_rx_info_stru),
311             0, sizeof(hmac_user_btcoex_rx_info_stru));
312         return OAL_SUCC;
313     }
314 
315     if (btcoex_rx_info->rx_rate_stat_count < BTCOEX_RX_COUNT_LIMIT) {
316         (osal_void)memset_s(btcoex_rx_info, sizeof(hmac_user_btcoex_rx_info_stru),
317             0, sizeof(hmac_user_btcoex_rx_info_stru));
318         return OAL_SUCC;
319     }
320 
321     btcoex_rx_stat->rx_rate_statistics_timeout = OSAL_TRUE;
322     return OAL_SUCC;
323 }
324 
325 /*****************************************************************************
326  函 数 名  : hmac_config_btcoex_assoc_state_syn
327  功能描述  : 同步共存下mac的状态
328 *****************************************************************************/
hmac_config_btcoex_assoc_state_syn(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user)329 OSAL_STATIC osal_u32 hmac_config_btcoex_assoc_state_syn(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user)
330 {
331     hmac_device_stru *hmac_device = hmac_res_get_mac_dev_etc(0);
332     hal_to_dmac_device_stru *hal_device = hmac_vap->hal_device;
333     hal_btcoex_btble_status_stru *status = OSAL_NULL;
334     hmac_user_btcoex_delba_stru *btcoex_delba = OSAL_NULL;
335     ble_status_stru *ble_status = OSAL_NULL;
336     bt_status_stru *bt_status = OSAL_NULL;
337     oal_bool_enum_uint8 dbac_running_ret;
338 
339     /* 初始化premmpt能力 */
340     hmac_btcoex_init_preempt(hmac_vap, hmac_user, OSAL_FALSE);
341 
342     status = hal_btcoex_btble_status();
343     btcoex_delba = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_delba);
344     btcoex_delba->ba_size_expect_index = BTCOEX_RX_WINDOW_SIZE_INDEX_3;
345     btcoex_delba->ba_size_real_index = BTCOEX_RX_WINDOW_SIZE_INDEX_3;
346 
347     /* 初始化delba空间流能力,选择合适删减BA门限 */
348     btcoex_delba->user_nss_num = hmac_user->avail_num_spatial_stream;
349 
350     oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {hmac_config_btcoex_assoc_state_syn::user_nss_num[%d].}",
351         hmac_vap->vap_id, btcoex_delba->user_nss_num);
352 
353     hmac_btcoex_update_rx_rate_threshold(hmac_vap, btcoex_delba);
354 
355     /* 更新当前bt状态信息 可能wifi刚打开,bt业务中断没有过来,要自己本地刷新下那些寄存器,来判断蓝牙业务 */
356     hal_update_btcoex_btble_status(status);
357 
358     ble_status = &status->ble_status.ble_status;
359     bt_status = &status->bt_status.bt_status;
360 
361     /* 2.删建聚合逻辑判断,当前dbdc和dbac都不处理,sta侧dbac和dbac都会在该接口之前完成,切信道的dbac不管 */
362     /* BTCOEX STA, 并且当前没有切换到c1 siso,并且dbdc或者dbac没有启动,才需要处理 */
363     dbac_running_ret = mac_is_dbac_running(hmac_device);
364     /* dbdc 2g入网vap判断当前状态,无论是c1/c0SISO还是mimo,都需要处理 */
365 #ifdef _PRE_WLAN_FEATURE_BT_SUPPORT
366     if (mac_btcoex_check_valid_vap(hmac_vap) == OSAL_TRUE) {
367         /* 1.当前6slot/ldac下即使c1 siso下也不是空分,降低聚合时间保证上行性能稳定;
368            2.需要提前配置,dbdc/c1 siso也需要处理,因此放置在这里; 3.纯5g场景不需要处理,反而影响性能
369            4. 中断标志过来,本身和6slot是互斥的,不冲突 */
370         /* ldac场景下,mimo和siso都需要此档位 ,六时隙时是否为2 */
371         hmac_alg_bt_aggr_time_uint8 aggr_time = (bt_status->bt_ldac == 1 || bt_status->bt_6slot == 2) ?
372             HMAC_ALG_BT_AGGR_TIME_1MS : HMAC_ALG_BT_AGGR_TIME_OFF;
373         hmac_alg_cfg_btcoex_state_notify(hal_device, aggr_time);
374     }
375 #endif
376 
377     /* 1.刷新状态信息通知蓝牙 */
378     if (is_sta(hmac_vap) || (is_ap(hmac_vap) && (hmac_vap->user_nums == 1))) {
379         /* 关联时刷新状态信息通知bt,sta关联时 */
380         hmac_btcoex_set_freq_and_work_state_hal_device(hal_device);
381         hmac_btcoex_set_vap_ps_frame(hmac_vap, OSAL_TRUE);
382     }
383 
384     /* 这两个条件判断返回,需要在通知bt sta关联状态之后,否则影响bt业务优先级配置,出现5G下性能影响 */
385     /* BT无影响聚合相关业务时,恢复wifi控制聚合 */
386     if (bt_status->bt_transfer == 0 && bt_status->bt_ba == 0) {
387         btcoex_delba->ba_size = 0;
388         hmac_btcoex_delba_trigger(hmac_vap, OSAL_FALSE, btcoex_delba);
389         oam_warning_log1(0, OAM_SF_COEX,
390             "vap_id[%d] {hmac_config_btcoex_assoc_state_syn::bt not working, ba size to default.}", hmac_vap->vap_id);
391         return OAL_SUCC;
392     }
393 
394     if (mac_btcoex_check_valid_sta(hmac_vap) == OSAL_FALSE || hal_m2s_check_btcoex_on(hal_device) == OSAL_TRUE ||
395         (dbac_running_ret == OSAL_TRUE)) {
396         oam_warning_log3(0, OAM_SF_COEX,
397             "{hmac_config_btcoex_assoc_state_syn::ba process skip! valid_sta[%d]m2s_on[%d]DBAC[%d].}",
398             mac_btcoex_check_valid_sta(hmac_vap), hal_m2s_check_btcoex_on(hal_device), dbac_running_ret);
399         return OAL_SUCC;
400     }
401 
402     hmac_config_btcoex_assoc_state_proc(hmac_vap, ble_status, btcoex_delba, bt_status, status);
403     hmac_btcoex_set_dev_ps_frame(hal_device);
404 
405     return OAL_SUCC;
406 }
407 
408 /*****************************************************************************
409  函 数 名  : hmac_btcoex_set_wlan_priority
410  功能描述  : 软件设定高优先级保护
411 *****************************************************************************/
hmac_btcoex_set_wlan_priority(hmac_vap_stru * hmac_vap,oal_bool_enum_uint8 value,osal_u8 timeout_ms)412 OSAL_STATIC osal_void hmac_btcoex_set_wlan_priority(hmac_vap_stru *hmac_vap, oal_bool_enum_uint8 value,
413     osal_u8 timeout_ms)
414 {
415     hmac_vap_btcoex_occupied_stru *btcoex_occupied = &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_occupied);
416     osal_u32 now_ms;
417     oal_bool_enum_uint8 set_on = OSAL_FALSE;
418     hal_to_dmac_device_stru *hal_device = OSAL_NULL;
419 
420     if (hmac_vap->channel.band == WLAN_BAND_5G) {
421         /* 5G不需要拉priority处理 */
422         return;
423     }
424 
425     /* 定时器超时处理函数等流程中,可能vap已经删除,此时才执行,hal device是空指针,需要增加判断保护  */
426     hal_device = hmac_vap->hal_device;
427     if (hal_device == OSAL_NULL) {
428         oam_warning_log1(0, OAM_SF_COEX,
429             "vap_id[%d] {hmac_btcoex_set_wlan_priority:: hal_device null}", hmac_vap->vap_id);
430         return;
431     }
432 
433     /* 需要拉高prio */
434     if (value == OSAL_TRUE) {
435         /* 当前没有拉高prio并且可以拉高prio */
436         if (btcoex_occupied->prio_occupied_state == OSAL_FALSE) {
437             /* 尽量不要和上一次拉低相隔太近 */
438             now_ms = (osal_u32)osal_get_time_stamp_ms();
439             if (now_ms - btcoex_occupied->timestamp > BTCOEX_PRI_DURATION_TIME) {
440                 frw_destroy_timer_entry(&btcoex_occupied->bt_coex_priority_timer);
441                 /* 启动priority定时器 */
442                 frw_create_timer_entry(&btcoex_occupied->bt_coex_priority_timer,
443                     hmac_btcoex_wlan_priority_timeout_callback, timeout_ms, (osal_void *)hmac_vap,
444                     OSAL_FALSE);
445                 btcoex_occupied->prio_occupied_state = OSAL_TRUE;
446                 set_on = OSAL_TRUE;
447             }
448         }
449     } else { /* 需要拉低prio */
450         if (btcoex_occupied->prio_occupied_state == OSAL_TRUE) {
451             btcoex_occupied->prio_occupied_state = OSAL_FALSE;
452             btcoex_occupied->timestamp = (osal_u32)osal_get_time_stamp_ms();
453         }
454         set_on = OSAL_TRUE;
455     }
456 
457     if (set_on == OSAL_TRUE) {
458         /* 设置软件配置优先级 */
459         hal_set_btcoex_hw_priority_en(((value == OSAL_TRUE) ? OSAL_FALSE : OSAL_TRUE));
460     }
461 }
462 
463 /*****************************************************************************
464  函 数 名  : hmac_btcoex_wlan_priority_timeout_callback()
465  功能描述  : 软件设定高优先级保护超时函数
466 *****************************************************************************/
hmac_btcoex_wlan_priority_timeout_callback(osal_void * arg)467 osal_u32 hmac_btcoex_wlan_priority_timeout_callback(osal_void *arg)
468 {
469     hmac_vap_stru *hmac_vap = (hmac_vap_stru *)arg;
470 
471     if (hmac_vap == OSAL_NULL) {
472         oam_warning_log0(0, OAM_SF_COEX, "{hmac_btcoex_wlan_priority_timeout_callback:: hmac_vap null}");
473         return OAL_ERR_CODE_PTR_NULL;
474     }
475 
476     hmac_btcoex_set_wlan_priority(hmac_vap, OSAL_FALSE, 0);
477 
478     return OAL_SUCC;
479 }
480 
481 /*****************************************************************************
482  功能描述  : 处理vap_up,给BT发送中断
483 *****************************************************************************/
hmac_btcoex_vap_up_handle(osal_void * notify_data)484 OSAL_STATIC osal_bool hmac_btcoex_vap_up_handle(osal_void *notify_data)
485 {
486     hmac_vap_stru *hmac_vap = (hmac_vap_stru *)notify_data;
487     hmac_device_stru *hmac_device = hmac_res_get_mac_dev_etc(0);
488     oal_bool_enum_uint8 state_change = OSAL_FALSE;
489     hal_btcoex_btble_status_stru *status = hal_btcoex_btble_status();
490 
491     if (hmac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP) {
492         hal_set_btcoex_wifi_status_notify(HAL_BTCOEX_WIFI_STATE_AP_MODE, OSAL_TRUE);
493 
494         /* 状态发生变化 */
495         state_change = OSAL_TRUE;
496     }
497 
498     if (hmac_device->vap_num == 1) {
499         hal_set_btcoex_wifi_status_notify(HAL_BTCOEX_WIFI_STATE_ON, OSAL_TRUE);
500 
501         /* 状态发生变化 */
502         state_change = OSAL_TRUE;
503     }
504 
505     if (state_change == OSAL_TRUE) {
506         /* 状态变化,通知bt */
507         hal_coex_sw_irq_set(HAL_COEX_SW_IRQ_BT);
508     }
509 
510     /* 更新btble状态 */
511     hal_update_btcoex_btble_status(status);
512 
513     oam_warning_log_alter(0, OAM_SF_COEX,
514         "{hmac_btcoex_vap_up_handle::::status resv:%d, send:%d, data_transfer:%d, a2dp:%d, bt_on:%d.}",
515         /* 5代表5后面有5个待打印参数 */
516         5, status->bt_status.bt_status.bt_data_rcv,
517         status->bt_status.bt_status.bt_data_send,
518         status->bt_status.bt_status.bt_transfer,
519         status->bt_status.bt_status.bt_a2dp,
520         status->bt_status.bt_status.bt_on);
521 
522     if (status->bt_status.bt_status.bt_on != 0) {
523         /* 开启MAC BT共存 */
524         hal_set_btcoex_sw_all_abort_ctrl(OSAL_TRUE);
525     }
526     return OSAL_TRUE;
527 }
528 
529 /*****************************************************************************
530  函 数 名  : hmac_btcoex_update_rx_rate_threshold
531  功能描述  : 获取速率门限
532 *****************************************************************************/
hmac_btcoex_update_rx_rate_threshold(const hmac_vap_stru * hmac_vap,hmac_user_btcoex_delba_stru * btcoex_delba)533 osal_void hmac_btcoex_update_rx_rate_threshold(const hmac_vap_stru *hmac_vap, hmac_user_btcoex_delba_stru *btcoex_delba)
534 {
535     wlan_channel_band_enum_uint8 band;
536     wlan_bw_cap_enum_uint8 bandwidth;
537     static const osal_u16 btcoex_rate_thresholds_siso[WLAN_BAND_BUTT][WLAN_BW_CAP_BUTT][BTCOEX_RATE_THRESHOLD_BUTT] = {
538         /* 2G */
539         /* 20M */ /* 40M */
540         {{23, 60}, {50, 130}, {0, 0},     {0, 0}},
541         /* 5G */
542         /* 20M */ /* 40M */ /* 80M */
543         {{23, 80}, {50, 160}, {108, 340}, {0, 0}}
544     };
545 
546     band = hmac_vap->channel.band;
547     hmac_vap_get_bandwidth_cap_etc(hmac_vap, &bandwidth);
548 
549     if ((band >= WLAN_BAND_BUTT) || (bandwidth >= WLAN_BW_CAP_BUTT)) {
550         oam_error_log3(0, 0, "vap_id[%d] {hmac_btcoex_update_rx_rate_threshold::band %d, bw %d exceed scale!}",
551             hmac_vap->vap_id, band, bandwidth);
552         return;
553     }
554 
555     if (btcoex_delba->user_nss_num >= WLAN_DOUBLE_NSS) {
556 #if defined(WLAN_MAX_NSS_NUM) && defined(WLAN_SINGLE_NSS) && (WLAN_MAX_NSS_NUM != WLAN_SINGLE_NSS)
557         btcoex_delba->rx_rate_threshold_min =
558             g_aus_btcoex_rate_thresholds_mimo[band][bandwidth][BTCOEX_RATE_THRESHOLD_MIN];
559         btcoex_delba->rx_rate_threshold_max =
560             g_aus_btcoex_rate_thresholds_mimo[band][bandwidth][BTCOEX_RATE_THRESHOLD_MAX];
561 #endif
562     } else {
563         btcoex_delba->rx_rate_threshold_min =
564             btcoex_rate_thresholds_siso[band][bandwidth][BTCOEX_RATE_THRESHOLD_MIN];
565         btcoex_delba->rx_rate_threshold_max =
566             btcoex_rate_thresholds_siso[band][bandwidth][BTCOEX_RATE_THRESHOLD_MAX];
567     }
568 
569     oam_warning_log4(0, OAM_SF_COEX,
570         "{hmac_btcoex_update_rx_rate_threshold:: min: %d, max: %d, band %d, bandwidth %d.}",
571         btcoex_delba->rx_rate_threshold_min, btcoex_delba->rx_rate_threshold_max, band, bandwidth);
572 }
573 
574 /*****************************************************************************
575  函 数 名  : hmac_btcoex_user_spatial_stream_change_notify
576  功能描述  : user空间流变化,需要刷新bt下速率门限值(siso还是mimo)
577 *****************************************************************************/
hmac_btcoex_user_spatial_stream_change_notify(const hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user)578 OSAL_STATIC osal_void hmac_btcoex_user_spatial_stream_change_notify(const hmac_vap_stru *hmac_vap,
579     hmac_user_stru *hmac_user)
580 {
581     hmac_user_btcoex_delba_stru *btcoex_delba = OSAL_NULL;
582 
583     if (mac_btcoex_check_valid_sta(hmac_vap) == OSAL_FALSE) {
584         return;
585     }
586 
587     btcoex_delba = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_delba);
588     btcoex_delba->user_nss_num = hmac_user->avail_num_spatial_stream;
589 
590     /* user空间流发生变化,重新刷新速率门限 */
591     hmac_btcoex_update_rx_rate_threshold(hmac_vap, btcoex_delba);
592 }
593 
594 /*****************************************************************************
595  函 数 名  : hmac_btcoex_lower_rate_aggregation_adjust
596  功能描述  : 接收降速后处理,调整聚合
597 *****************************************************************************/
hmac_btcoex_lower_rate_aggregation_adjust(const hal_to_dmac_device_stru * hal_device,const hal_btcoex_btble_status_stru * btble_status,hmac_user_btcoex_delba_stru * btcoex_delba,hmac_vap_stru * hmac_vap,osal_u32 rx_rate)598 OSAL_STATIC osal_void hmac_btcoex_lower_rate_aggregation_adjust(const hal_to_dmac_device_stru *hal_device,
599     const hal_btcoex_btble_status_stru *btble_status, hmac_user_btcoex_delba_stru *btcoex_delba,
600     hmac_vap_stru *hmac_vap, osal_u32 rx_rate)
601 {
602     osal_u32 th_min = btcoex_delba->rx_rate_threshold_min;
603     osal_u32 th_max = btcoex_delba->rx_rate_threshold_max;
604 
605     if (hal_device->hal_alg_stat.alg_distance_stat < HAL_ALG_USER_DISTANCE_FAR) {
606         /* BA聚合个数调整 1.DEC下速率小于min;2.INC下速率大于max;3.DEC下实际聚合等于index3,速率小于等于 min+max%2 */
607         if ((btcoex_delba->ba_size_tendence == BTCOEX_RX_WINDOW_SIZE_DECREASE &&  (rx_rate < th_min)) ||
608             ((btcoex_delba->ba_size_tendence == BTCOEX_RX_WINDOW_SIZE_INCREASE) &&  (rx_rate > th_max)) ||
609             ((btcoex_delba->ba_size_tendence == BTCOEX_RX_WINDOW_SIZE_DECREASE) &&
610             (btcoex_delba->ba_size_real_index == BTCOEX_RX_WINDOW_SIZE_INDEX_3) &&
611             (rx_rate < (th_min + (th_max >> 1))))) {
612             btcoex_delba->ba_size_real_index = btcoex_delba->ba_size_expect_index;
613             hmac_btcoex_update_ba_size(hmac_vap, btcoex_delba, btble_status);
614 
615             /* 主动触发删减BA逻辑,需要在收到addba rsp帧时候恢复此标记 */
616             hmac_btcoex_delba_trigger(hmac_vap, OSAL_TRUE, btcoex_delba);
617 
618             oam_warning_log_alter(0, OAM_SF_COEX,
619                 "{hmac_btcoex_lower_rate_callback:change:%d,rate:%d,tendence:%d,indx:%d,threshMin:%d,threshMax:%d}",
620                 /* 6代表6后面有6个待打印参数 */
621                 6, btcoex_delba->ba_size, rx_rate, btcoex_delba->ba_size_tendence,
622                 btcoex_delba->ba_size_real_index, th_min, th_max);
623         } else {
624             /* 保持现有聚合不变 */
625             btcoex_delba->ba_size_expect_index = btcoex_delba->ba_size_real_index;
626             hmac_btcoex_update_ba_size(hmac_vap, btcoex_delba, btble_status);
627             oam_warning_log3(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_lower_rate_callback:keep at:%d, rate:%d}",
628                 hmac_vap->vap_id, btcoex_delba->ba_size, rx_rate);
629         }
630     }
631     return;
632 }
633 
634 /*****************************************************************************
635  函 数 名  : hmac_btcoex_lower_rate_callback
636  功能描述  : 接收降速后处理
637 *****************************************************************************/
hmac_btcoex_lower_rate_callback(osal_void * arg)638 OSAL_STATIC osal_u32 hmac_btcoex_lower_rate_callback(osal_void *arg)
639 {
640     osal_u32 rx_rate = 0;
641     osal_u16 rx_count = 0;
642 
643     hmac_vap_stru *hmac_vap = (hmac_vap_stru *)arg;
644     hal_to_dmac_chip_stru *hal_chip = hmac_vap->hal_chip;
645     hmac_user_stru *hmac_user = OSAL_NULL;
646     hal_to_dmac_device_stru *hal_device = OSAL_NULL;
647     hmac_user_btcoex_delba_stru *btcoex_delba = OSAL_NULL;
648     hal_btcoex_btble_status_stru *btble_status = OSAL_NULL;
649     hmac_user_btcoex_rx_info_stru *btcoex_rx_info = OSAL_NULL;
650 
651     if (hal_chip == OSAL_NULL) {
652         oam_warning_log1(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_init_preempt:: HAL_CHIP null}", hmac_vap->vap_id);
653         return OAL_ERR_CODE_PTR_NULL;
654     }
655 
656     hmac_user = (hmac_user_stru *)mac_res_get_hmac_user_etc(hmac_vap->assoc_vap_id);
657     if (osal_unlikely(hmac_user == OSAL_NULL)) {
658         oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {DmacBtcoexLowerRateCallback:NULL%d",
659             hmac_vap->vap_id, hmac_vap->assoc_vap_id);
660         return OAL_ERR_CODE_PTR_NULL;
661     }
662 
663     hal_device = hmac_vap->hal_device;
664     if (osal_unlikely(hal_device == OSAL_NULL)) {
665         oam_warning_log1(0, 0, "vap_id[%d] {hmac_btcoex_lower_rate_callback::hal_device null.}", hmac_vap->vap_id);
666         return OAL_ERR_CODE_PTR_NULL;
667     }
668 
669     btcoex_delba = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_delba);
670     btble_status = hal_btcoex_btble_status();
671     btcoex_rx_info = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_rx_info);
672 
673     if (btcoex_delba->get_addba_req_flag == OSAL_FALSE) {
674         hmac_btcoex_rx_average_rate_calculate(btcoex_rx_info, &rx_rate, &rx_count);
675         hmac_btcoex_lower_rate_aggregation_adjust(hal_device, btble_status, btcoex_delba, hmac_vap, rx_rate);
676     } else {
677         btcoex_delba->ba_size_real_index = btcoex_delba->ba_size_expect_index;
678         oam_warning_log1(0, 0, "vap_id[%d] {hmac_btcoex_lower_rate_callback:rece addba req before delba}",
679             hmac_vap->vap_id);
680     }
681 
682     frw_timer_restart_timer(
683         &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_rx_statistics.bt_coex_statistics_timer),
684         BTCOEX_RX_STATISTICS_TIME, OSAL_TRUE);
685 
686     return OAL_SUCC;
687 }
688 
hmac_btcoex_lower_rate_switch(const hmac_vap_stru * hmac_vap,hmac_user_btcoex_delba_stru * btcoex_delba,osal_u32 rx_rate,osal_u8 is_siso)689 OSAL_STATIC osal_void hmac_btcoex_lower_rate_switch(const hmac_vap_stru *hmac_vap,
690     hmac_user_btcoex_delba_stru *btcoex_delba, osal_u32 rx_rate, osal_u8 is_siso)
691 {
692     osal_u32 rate_threshold_min = btcoex_delba->rx_rate_threshold_min;
693     osal_u32 rate_threshold_max = btcoex_delba->rx_rate_threshold_max;
694     switch (btcoex_delba->ba_size_expect_index) {
695         case BTCOEX_RX_WINDOW_SIZE_INDEX_3:
696             if (rx_rate < (rate_threshold_min + (rate_threshold_max >> 1))) {
697                 btcoex_delba->ba_size_expect_index--;
698                 btcoex_delba->ba_size_tendence = BTCOEX_RX_WINDOW_SIZE_DECREASE;
699             }
700             break;
701 
702         /* 降低到2档之后,期望稳定在2档,只能降 */
703         case BTCOEX_RX_WINDOW_SIZE_INDEX_2:
704             if (rx_rate < rate_threshold_min) {
705                 btcoex_delba->ba_size_expect_index--;
706                 btcoex_delba->ba_size_tendence = BTCOEX_RX_WINDOW_SIZE_DECREASE;
707             }
708             break;
709 
710         /* 降低到1档之后,可以退到0档,0档之后不再变化,也可以探测到2档,尽量稳定在2档 */
711         case BTCOEX_RX_WINDOW_SIZE_INDEX_1:
712             if (rx_rate < rate_threshold_min) {
713                 btcoex_delba->ba_size_expect_index--;
714                 btcoex_delba->ba_size_tendence = BTCOEX_RX_WINDOW_SIZE_DECREASE;
715             } else if (rx_rate > rate_threshold_max) {
716                 btcoex_delba->ba_size_expect_index++;
717                 btcoex_delba->ba_size_tendence = BTCOEX_RX_WINDOW_SIZE_INCREASE;
718             }
719             break;
720 
721         case BTCOEX_RX_WINDOW_SIZE_INDEX_0:
722             if ((is_siso == OSAL_TRUE) && (rx_rate > rate_threshold_max)) {
723                 btcoex_delba->ba_size_expect_index++;
724                 btcoex_delba->ba_size_tendence = BTCOEX_RX_WINDOW_SIZE_INCREASE;
725             } else {
726                 oam_warning_log1(0, OAM_SF_COEX,
727                     "vap_id[%d] {hmac_btcoex_lower_rate_switch::KEEP at BTCOEX_RX_WINDOW_SIZE_INDEX_0.}",
728                     hmac_vap->vap_id);
729             }
730             break;
731 
732         default:
733             oam_error_log2(0, OAM_SF_COEX,
734                 "vap_id[%d] {hmac_btcoex_lower_rate_switch::ba_size_expect_index error:%d.}", hmac_vap->vap_id,
735                 btcoex_delba->ba_size_expect_index);
736             break;
737     }
738 }
739 
hmac_btcoex_lower_rate_distance(hmac_vap_stru * hmac_vap,hmac_user_btcoex_delba_stru * btcoex_delba,osal_u32 rx_rate,osal_u16 rx_count)740 OSAL_STATIC osal_void hmac_btcoex_lower_rate_distance(hmac_vap_stru *hmac_vap,
741     hmac_user_btcoex_delba_stru *btcoex_delba, osal_u32 rx_rate, osal_u16 rx_count)
742 {
743     hmac_vap_btcoex_rx_statistics_stru *btcoex_rx_stat =
744         &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_rx_statistics);
745 
746     hal_to_dmac_chip_stru *hal_chip = hmac_vap->hal_chip;
747     if (hal_chip == OSAL_NULL) {
748         oam_warning_log1(0, 0, "vap_id[%d] {hmac_btcoex_lower_rate_process:: GET_HAL_CHIP null}", hmac_vap->vap_id);
749         return;
750     }
751     /* 处理近场速率 */
752     if (hmac_vap->hal_device->hal_alg_stat.alg_distance_stat < HAL_ALG_USER_DISTANCE_FAR) {
753         osal_u8 is_siso = OSAL_FALSE;
754         hal_btcoex_btble_status_stru *status = hal_btcoex_btble_status();
755         bt_status_stru *bt_status = &(status->bt_status.bt_status);
756 
757         /* 1. 电话固定聚合 */
758         if (status->bt_status.bt_status.bt_6slot != 0) {
759             return;
760         }
761 
762         /* 初始配置 */
763         btcoex_delba->ba_size_tendence = BTCOEX_RX_WINDOW_SIZE_HOLD;
764         btcoex_delba->ba_size_expect_index = btcoex_delba->ba_size_real_index;
765 
766         /* 2. 音乐2G mimo 20M暂时固定2档,40M固定3档 */
767         if ((hmac_vap->channel.band == WLAN_BAND_2G) && (bt_status->bt_a2dp != 0) &&
768             (btcoex_delba->user_nss_num == WLAN_DOUBLE_NSS)) {
769             hmac_btcoex_lower_rate_switch(hmac_vap, btcoex_delba, rx_rate, is_siso);
770         } else if (hmac_vap->channel.band == WLAN_BAND_5G) {
771             /* 3.5G不处理 */
772         } else { /* 4. siso场景 */
773             is_siso = OSAL_TRUE;
774             hmac_btcoex_lower_rate_switch(hmac_vap, btcoex_delba, rx_rate, is_siso);
775         }
776 
777         if (btcoex_delba->ba_size_tendence != BTCOEX_RX_WINDOW_SIZE_HOLD) {
778             hmac_btcoex_update_ba_size(hmac_vap, btcoex_delba, status);
779             hmac_btcoex_delba_trigger(hmac_vap, OSAL_FALSE, btcoex_delba);
780             oam_warning_log4(0, OAM_SF_COEX,
781                 "vap_id[%d] {hmac_btcoex_lower_rate_process::ba_size will change to:%d in 5s,rate:%d,count:%d.}",
782                 hmac_vap->vap_id, btcoex_delba->ba_size, rx_rate, rx_count);
783             btcoex_delba->get_addba_req_flag = OSAL_FALSE;
784             frw_timer_stop_timer(&(btcoex_rx_stat->bt_coex_statistics_timer));
785             frw_create_timer_entry(&(btcoex_rx_stat->bt_coex_low_rate_timer), hmac_btcoex_lower_rate_callback,
786                 BTCOEX_RX_LOW_RATE_TIME, (osal_void *)hmac_vap, OSAL_FALSE);
787         }
788     }
789 }
790 
791 /*****************************************************************************
792  函 数 名  : hmac_btcoex_bt_low_rate_process
793  功能描述  : 接收降速后处理
794 *****************************************************************************/
hmac_btcoex_lower_rate_process(hmac_vap_stru * hmac_vap)795 OSAL_STATIC osal_void hmac_btcoex_lower_rate_process(hmac_vap_stru *hmac_vap)
796 {
797     osal_u32 rx_rate = 0;
798     osal_u16 rx_count = 0;
799     hmac_user_stru *hmac_user = OSAL_NULL;
800     hmac_vap_btcoex_rx_statistics_stru *btcoex_rx_stat = OSAL_NULL;
801     hmac_user_btcoex_rx_info_stru *btcoex_rx_info = OSAL_NULL;
802     hmac_user_btcoex_delba_stru *btcoex_delba = OSAL_NULL;
803 
804     if (mac_btcoex_check_valid_sta(hmac_vap) == OSAL_FALSE) {
805         /* 速率统计发现不存在要求vap时应该对vap下速率统计结果清零,user去关联会自动清 */
806         return;
807     }
808 
809     /* STA模式获取user */
810     hmac_user = (hmac_user_stru *)mac_res_get_hmac_user_etc(hmac_vap->assoc_vap_id);
811     if (osal_unlikely(hmac_user == OSAL_NULL)) {
812         oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_lower_rate_process::hmac_user[%d] null.}",
813             hmac_vap->vap_id, hmac_vap->assoc_vap_id);
814         return;
815     }
816 
817     btcoex_rx_stat = &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_rx_statistics);
818     btcoex_rx_info = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_rx_info);
819     btcoex_delba = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_delba);
820 
821     /* 累加接收速率 */
822     if (btcoex_rx_stat->rx_rate_statistics_flag != OSAL_TRUE) {
823         return;
824     }
825     if (hmac_user->rx_rate != 0) {
826         /* 如果用户不存在,去关联,pst_dmac_user_btcoex_rx_info也会被清零 */
827         btcoex_rx_info->rx_rate_mbps += hmac_user->rx_rate;
828         btcoex_rx_info->rx_rate_stat_count++;
829     }
830 
831     /* 计算接收速率 */
832     if (btcoex_rx_stat->rx_rate_statistics_timeout == 0) {
833         return;
834     }
835     btcoex_rx_stat->rx_rate_statistics_timeout = OSAL_FALSE;
836     hmac_btcoex_rx_average_rate_calculate(btcoex_rx_info, &rx_rate, &rx_count);
837     hmac_btcoex_lower_rate_distance(hmac_vap, btcoex_delba, rx_rate, rx_count);
838 }
839 
840 /*****************************************************************************
841  函 数 名  : hmac_btcoex_release_rx_prot
842  功能描述  : 共存对于关键帧的操作
843 *****************************************************************************/
hmac_btcoex_release_rx_prot(hmac_vap_stru * hmac_vap,osal_u8 data_type)844 OSAL_STATIC osal_void hmac_btcoex_release_rx_prot(hmac_vap_stru *hmac_vap, osal_u8 data_type)
845 {
846     bt_status_stru *bt_status = OSAL_NULL;
847     hal_to_dmac_chip_stru *hal_chip = OSAL_NULL;
848     hal_btcoex_btble_status_stru *status = OSAL_NULL;
849 
850     hal_chip = hmac_vap->hal_chip;
851     if (hal_chip == OSAL_NULL) {
852         oam_warning_log1(0, 0, "vap_id[%d] {hmac_btcoex_release_rx_prot:: GET_HAL_CHIP null}", hmac_vap->vap_id);
853         return;
854     }
855     status = hal_btcoex_btble_status();
856 
857     bt_status = &(status->bt_status.bt_status);
858     if ((bt_status->bt_on == OSAL_FALSE) || (data_type == MAC_DATA_BUTT)) {
859         return;
860     }
861 
862     if (data_type <= MAC_DATA_ARP_RSP) {
863         {
864             hmac_btcoex_set_wlan_priority(hmac_vap, OSAL_FALSE, 0);
865         }
866     }
867 }
868 
869 /*****************************************************************************
870  功能描述  : 共存对于关键帧的发送保护
871 *****************************************************************************/
hmac_btcoex_tx_mgmt_frame(const hmac_vap_stru * hmac_vap,const mac_ieee80211_frame_stru * mac_header)872 OSAL_STATIC osal_void hmac_btcoex_tx_mgmt_frame(const hmac_vap_stru *hmac_vap,
873     const mac_ieee80211_frame_stru *mac_header)
874 {
875     hal_to_dmac_chip_stru *hal_chip = hmac_vap->hal_chip;
876     hal_to_dmac_device_stru *hal_device = hmac_vap->hal_device;
877     hal_btcoex_btble_status_stru *status = OSAL_NULL;
878     bt_status_stru *bt_status = OSAL_NULL;
879     osal_u8 mgmt_type;
880 
881     if ((hal_chip == OSAL_NULL) || (hal_device == OSAL_NULL)) {
882         oam_warning_log1(0, 0, "{hmac_btcoex_tx_mgmt_frame:: null point, chip[%x]}", (uintptr_t)hal_chip);
883         return;
884     }
885 
886     /* 当前软件仅对管理帧做保护 */
887     status = hal_btcoex_btble_status();
888     bt_status = &(status->bt_status.bt_status);
889     if ((bt_status->bt_on == OSAL_FALSE) || (mac_header->frame_control.type != WLAN_MANAGEMENT)) {
890         return;
891     }
892 
893     mgmt_type = mac_header->frame_control.sub_type;
894     if (hmac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA) {
895         /* probe req广播帧不收ack,不拉优先级,ldac和sco都可能造成蓝牙卡顿,可能影响wifi扫描个数 */
896         if ((mgmt_type == WLAN_AUTH) || (mgmt_type == WLAN_ASSOC_REQ) || (mgmt_type == WLAN_REASSOC_REQ) ||
897             (mgmt_type == WLAN_DEAUTH) || (mgmt_type == WLAN_DISASOC) || (mgmt_type == WLAN_ACTION)) {
898             hmac_btcoex_set_mgmt_priority(hmac_vap, BTCOEX_PRIO_TIMEOUT_10MS);
899         }
900     } else if (hmac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP) {
901             /* probe rsp以及P2P相关action帧在空口中会大量发送,拉优先级太久会造成蓝牙卡顿 */
902         if ((mgmt_type == WLAN_ASSOC_RSP) || (mgmt_type == WLAN_AUTH) || (mgmt_type == WLAN_BEACON) ||
903             (mgmt_type == WLAN_DISASOC) || (mgmt_type == WLAN_DEAUTH) || (mgmt_type == WLAN_REASSOC_RSP)) {
904             hmac_btcoex_set_mgmt_priority(hmac_vap, BTCOEX_PRIO_TIMEOUT_10MS);
905         }
906     }
907 }
908 
hmac_btcoex_protect_frame(hmac_vap_stru * hmac_vap,osal_u8 data_type)909 OSAL_STATIC osal_void hmac_btcoex_protect_frame(hmac_vap_stru *hmac_vap, osal_u8 data_type)
910 {
911     switch (data_type) {
912         case MAC_DATA_DHCP:
913             hmac_btcoex_set_wlan_priority(hmac_vap, OSAL_TRUE, BTCOEX_PRIO_TIMEOUT_100MS);
914             break;
915 
916         case MAC_DATA_ARP_RSP:
917         case MAC_DATA_ARP_REQ:
918             /* arp rsp帧发出后没有响应帧来拉低,此时保证发送正常即可,采用管理帧发送保护即可 */
919             // 多用户时,arp帧交互转发较多,也可能造成拉时间过长
920             hmac_btcoex_set_wlan_priority(hmac_vap, OSAL_TRUE, BTCOEX_PRIO_TIMEOUT_50MS);
921             break;
922 
923         /* 为提高p2p配对成功率/漫游成功率,在非BT电话场景下,保护EAPOL帧收发 */
924         case MAC_DATA_EAPOL:
925             /* 需要等待对端响应帧 */
926             hmac_btcoex_set_wlan_priority(hmac_vap, OSAL_TRUE, BTCOEX_PRIO_TIMEOUT_100MS);
927             break;
928         default:
929             break;
930         /* 三类关键帧发送时间太短,此类关键帧发送状态通知给bt意义不大 */
931     }
932 }
933 
934 
hmac_btcoex_protect_tx_vip_frame(hmac_vap_stru * hmac_vap,osal_u8 data_type)935 OSAL_STATIC osal_void hmac_btcoex_protect_tx_vip_frame(hmac_vap_stru *hmac_vap, osal_u8 data_type)
936 {
937     hal_btcoex_btble_status_stru *status = hal_btcoex_btble_status();
938 
939     if (hmac_vap->vap_mode == WLAN_VAP_MODE_BSS_AP) {
940         hmac_btcoex_protect_frame(hmac_vap, data_type);
941     } else if (hmac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA &&
942         status->bt_status.bt_status.bt_ldac == OSAL_FALSE) {
943         hmac_btcoex_protect_frame(hmac_vap, data_type);
944     }
945 }
946 
947 /*****************************************************************************
948  函 数 名  : hmac_btcoex_tx_vip_frame_ect
949  功能描述  : 共存对于关键帧的发送保护
950 *****************************************************************************/
hmac_btcoex_tx_vip_frame_ect(hmac_vap_stru * hmac_vap,const oal_netbuf_head_stru * buff_head,osal_u8 mpdu_num)951 OSAL_STATIC osal_void hmac_btcoex_tx_vip_frame_ect(hmac_vap_stru *hmac_vap, const oal_netbuf_head_stru *buff_head,
952     osal_u8 mpdu_num)
953 {
954     hal_to_dmac_chip_stru *hal_chip = OSAL_NULL;
955     oal_netbuf_stru *netbuf = OSAL_NULL;
956     oal_netbuf_stru *netbuf_tmp = OSAL_NULL;
957     osal_u8 data_type;
958     mac_tx_ctl_stru *cb = OSAL_NULL;
959     osal_u8 mpdu_idx;
960 
961     hal_chip = hmac_vap->hal_chip;
962     if (hal_chip == OSAL_NULL) {
963         oam_warning_log1(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_tx_vip_frame:: GET_HAL_CHIP null}", hmac_vap->vap_id);
964         return;
965     }
966 
967     /* EAPOL帧,DHCP和ARP帧的共存保护 */
968     netbuf = (oal_netbuf_stru *)buff_head->next;
969     for (mpdu_idx = 0; mpdu_idx < mpdu_num; mpdu_idx++) {
970         if (netbuf == OSAL_NULL) {
971             return;
972         }
973 
974         netbuf_tmp = oal_get_netbuf_next(netbuf);
975         cb = (mac_tx_ctl_stru *)oal_netbuf_cb(netbuf);
976         netbuf = netbuf_tmp;
977         if (cb->frame_type != WLAN_CB_FRAME_TYPE_DATA) {
978             continue;
979         }
980 
981         data_type = cb->frame_subtype;
982         if (data_type > MAC_DATA_ARP_REQ) {
983             continue;
984         }
985 
986         hmac_btcoex_protect_tx_vip_frame(hmac_vap, data_type);
987     }
988 }
989 
hmac_btcoex_tx_vip_frame(hmac_vap_stru * hmac_vap,const oal_netbuf_head_stru * buff_head,osal_u8 mpdu_num)990 WIFI_HMAC_TCM_TEXT WIFI_TCM_TEXT OSAL_STATIC osal_void hmac_btcoex_tx_vip_frame(hmac_vap_stru *hmac_vap,
991     const oal_netbuf_head_stru *buff_head, osal_u8 mpdu_num)
992 {
993     hal_btcoex_btble_status_stru *status = hal_btcoex_btble_status();
994     if (status->bt_status.bt_status.bt_on == 0) {
995         return;
996     }
997     hmac_btcoex_tx_vip_frame_ect(hmac_vap, buff_head, mpdu_num);
998 }
999 /*****************************************************************************
1000  函 数 名  : hmac_btcoex_linkloss_init
1001  功能描述  : init BTCOEX下linkloss参数
1002 *****************************************************************************/
hmac_btcoex_linkloss_init(osal_void * notify_data)1003 OSAL_STATIC osal_bool hmac_btcoex_linkloss_init(osal_void *notify_data)
1004 {
1005     osal_u8 loop_idx;
1006     hmac_vap_stru *hmac_vap = (hmac_vap_stru *)notify_data;
1007     hmac_vap_btcoex_occupied_stru *vap_btcoex_occupied =
1008         &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_occupied);
1009     /* 该字段在高5位,故右移3 */
1010     g_occupied_point[0] = hmac_vap->linkloss_info.linkloss_info[WLAN_LINKLOSS_MODE_BT].int_linkloss_threshold >> 3;
1011 
1012     for (loop_idx = 0; loop_idx < BTCOEX_LINKLOSS_OCCUPIED_NUMBER - 1; loop_idx++) {
1013         g_occupied_point[loop_idx + 1] = g_occupied_point[loop_idx] + g_occupied_point[0];
1014     }
1015 
1016     vap_btcoex_occupied->linkloss_index = 1;
1017     vap_btcoex_occupied->linkloss_occupied_times = 0;
1018     return OSAL_TRUE;
1019 }
1020 
1021 /*****************************************************************************
1022  函 数 名  : hmac_btcoex_linkloss_update_threshold
1023  功能描述  : update BTCOEX下linkloss参数
1024 *****************************************************************************/
hmac_btcoex_linkloss_update_threshold(hmac_vap_stru * hmac_vap)1025 OSAL_STATIC osal_void hmac_btcoex_linkloss_update_threshold(hmac_vap_stru *hmac_vap)
1026 {
1027     osal_u8 loop_idx;
1028     hmac_vap_btcoex_occupied_stru *btcoex_occupied = &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_occupied);
1029 
1030     g_occupied_point[0] = get_current_linkloss_threshold(hmac_vap) >> 3; /* 该字段在高5位,故右移3 */
1031 
1032     for (loop_idx = 0; loop_idx < BTCOEX_LINKLOSS_OCCUPIED_NUMBER - 1; loop_idx++) {
1033         g_occupied_point[loop_idx + 1] = g_occupied_point[loop_idx] + g_occupied_point[0];
1034     }
1035 
1036     btcoex_occupied->linkloss_index = 1;
1037     btcoex_occupied->linkloss_occupied_times = 0;
1038 }
1039 
1040 /* 由于host侧tbtt消息存在时延,发消息到device侧,将下个tbtt时间WiFi优先级拉最高 */
hmac_btcoex_device_occupied(hmac_vap_stru * hmac_vap,osal_u16 utime)1041 OSAL_STATIC osal_void hmac_btcoex_device_occupied(hmac_vap_stru *hmac_vap, osal_u16 utime)
1042 {
1043     osal_s32 ret;
1044     frw_msg msg = {0};
1045 
1046     /* 5G不需要拉occupy处理 */
1047     if (hmac_vap->channel.band == WLAN_BAND_5G) {
1048         oam_warning_log1(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_device_occupied:: 5G donot need to set occupied.}",
1049             hmac_vap->vap_id);
1050         return;
1051     }
1052 
1053     msg.data = (osal_u8 *)&utime;
1054     msg.data_len = (osal_u16)sizeof(osal_u16);
1055     ret = frw_send_msg_to_device(0, WLAN_MSG_H2D_C_CFG_BTCOEX_SYNC_OCCUPIED_TIME, &msg, OSAL_FALSE);
1056     if (osal_unlikely(ret != OAL_SUCC)) {
1057         oam_error_log1(0, OAM_SF_COEX, "{hmac_btcoex_device_occupoed:: frw_send_msg [%d].}", ret);
1058     }
1059 }
1060 
1061 /*****************************************************************************
1062  功能描述  : BTCOEX下beacon occupied参数更新处理
1063 *****************************************************************************/
hmac_btcoex_beacon_occupied_handler(osal_void * notify_data)1064 OSAL_STATIC osal_bool hmac_btcoex_beacon_occupied_handler(osal_void *notify_data)
1065 {
1066     osal_u32 beacon_count_new;
1067     hmac_vap_btcoex_occupied_stru *btcoex_occupied = OSAL_NULL;
1068     hal_btcoex_btble_status_stru *status = OSAL_NULL;
1069     hmac_vap_stru *hmac_vap = (hmac_vap_stru *)notify_data;
1070     status = hal_btcoex_btble_status();
1071     /* 入参确认不为空 */
1072     if (status->bt_status.bt_status.bt_on == OSAL_FALSE) {
1073         return OSAL_TRUE;
1074     }
1075 
1076     /* 每5个beacon发送失败上报一次BEACON MISS中断,所以在发出了5个beacon后,计数减1 */
1077     beacon_count_new = hal_btcoex_update_ap_beacon_count();
1078     btcoex_occupied = &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_occupied);
1079     if (beacon_count_new - btcoex_occupied->ap_beacon_count >= 5) { /* 间隔5个beacon上报一次中断 */
1080         /* 如果存在大于5的情况,则可能出现过TBTT中断丢失,实际确有发生beacon miss计数无法清零的情况 */
1081         if (beacon_count_new - btcoex_occupied->ap_beacon_count > 5) { /* 间隔5个beacon上报一次中断 */
1082             oam_warning_log3(0, OAM_SF_COEX,
1083                 "vap_id[%d] {hmac_btcoex_beacon_occupied_handler::TBTT interrupt miss: beacon cnt [%d] record[%d]!}",
1084                 hmac_vap->vap_id, beacon_count_new, btcoex_occupied->ap_beacon_count);
1085         }
1086 
1087         btcoex_occupied->ap_beacon_count = beacon_count_new;
1088         btcoex_occupied->beacon_miss_cnt = oal_sub(btcoex_occupied->beacon_miss_cnt, 1);
1089     } else if (beacon_count_new < btcoex_occupied->ap_beacon_count) {
1090         /* 防止硬件的beacon计数翻转 */
1091         btcoex_occupied->ap_beacon_count = beacon_count_new;
1092     }
1093 
1094     if (status->bt_status.bt_status.bt_page != 0) {
1095         /* 达到30个beacon miss就拉高occupied */
1096         if (btcoex_occupied->beacon_miss_cnt > 5) { /* 每上报5次Beacon miss对应30个beacon帧丢失 */
1097             hmac_btcoex_device_occupied(hmac_vap, 10000); // 10000表示10ms
1098         }
1099     }
1100     return OSAL_TRUE;
1101 }
1102 
1103 /*****************************************************************************
1104  函 数 名  : hmac_btcoex_beacon_miss_handler
1105  功能描述  : BTCOEX下beacon miss处理
1106 *****************************************************************************/
hmac_btcoex_beacon_miss_handler(hmac_vap_stru * hmac_vap,frw_msg * msg)1107 OSAL_STATIC osal_s32 hmac_btcoex_beacon_miss_handler(hmac_vap_stru *hmac_vap, frw_msg *msg)
1108 {
1109     hmac_vap_stru *hmac_vap_tmp = OSAL_NULL;
1110     osal_u8 beacon_miss_cnt;
1111     osal_u8 vap_idx;
1112     osal_u8 valid_vap_num;
1113     osal_u8         mac_vap_id[WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE] = {0};
1114     hmac_vap_stru     *hmac_vap_all[WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE] = {OSAL_NULL};
1115     hal_to_dmac_device_stru *hal_device = hmac_vap->hal_device;
1116 
1117     unref_param(msg);
1118 
1119     /* valid的vap设备都做对应处理 */
1120     valid_vap_num = hmac_btcoex_find_all_valid_ap_per_device(hal_device, mac_vap_id,
1121         WLAN_SERVICE_VAP_MAX_NUM_PER_DEVICE);
1122 
1123     for (vap_idx = 0; vap_idx < valid_vap_num; vap_idx++) {
1124         hmac_vap_all[vap_idx] = (hmac_vap_stru *)mac_res_get_hmac_vap(mac_vap_id[vap_idx]);
1125         if (hmac_vap_all[vap_idx] == OSAL_NULL) {
1126             oam_error_log0(0, OAM_SF_COEX, "{hmac_btcoex_beacon_miss_handler::hmac_vap IS NULL.}");
1127             return OAL_FAIL;
1128         }
1129 
1130         hmac_vap_tmp = (hmac_vap_stru *)(hmac_vap_all[vap_idx]);
1131         hmac_btcoex_get_vap_info(hmac_vap_tmp)->hmac_vap_btcoex_occupied.beacon_miss_cnt++;
1132         beacon_miss_cnt = hmac_btcoex_get_vap_info(hmac_vap_tmp)->hmac_vap_btcoex_occupied.beacon_miss_cnt;
1133         oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_beacon_miss_handler:: miss cnt:%d}",
1134             mac_vap_id[vap_idx], beacon_miss_cnt);
1135     }
1136     return OAL_SUCC;
1137 }
1138 
1139 /*****************************************************************************
1140  函 数 名  : hmac_btcoex_set_occupied_period
1141  功能描述  : 配置occupied_period值,03在5G下不执行
1142 *****************************************************************************/
hmac_btcoex_set_occupied_period(const hmac_vap_stru * hmac_vap,osal_u16 occupied_period)1143 OSAL_STATIC osal_void  hmac_btcoex_set_occupied_period(const hmac_vap_stru *hmac_vap, osal_u16 occupied_period)
1144 {
1145     if (hmac_vap->channel.band == WLAN_BAND_5G) {
1146         /* 5G不需要拉occupy处理 */
1147         oam_warning_log1(0, 0, "vap_id[%d] {hmac_btcoex_set_occupied_period:: 5G donot need to set occupied.}",
1148             hmac_vap->vap_id);
1149     } else {
1150         hal_set_btcoex_occupied_period(occupied_period);
1151     }
1152 }
1153 
1154 /*****************************************************************************
1155  函 数 名  : hmac_btcoex_linkloss_occupied_process
1156  功能描述  : BTCOEX下linkloss occupied参数更新处理
1157 *****************************************************************************/
hmac_btcoex_linkloss_occupied_process(const hal_to_dmac_chip_stru * hal_chip,const hal_to_dmac_device_stru * hal_device,hmac_vap_stru * hmac_vap)1158 OSAL_STATIC osal_void hmac_btcoex_linkloss_occupied_process(const hal_to_dmac_chip_stru *hal_chip,
1159     const hal_to_dmac_device_stru *hal_device, hmac_vap_stru *hmac_vap)
1160 {
1161     hmac_vap_linkloss_stru *linkloss_info = OSAL_NULL;
1162     hmac_vap_btcoex_occupied_stru *btcoex_occupied = OSAL_NULL;
1163     osal_u16 linkloss_threshold, linkloss, linkloss_tmp;
1164     osal_u8 linkloss_times;
1165 
1166     if (hal_btcoex_btble_status()->bt_status.bt_status.bt_on == OSAL_FALSE) {
1167         return;
1168     }
1169 
1170     linkloss_info = &(hmac_vap->linkloss_info);
1171     btcoex_occupied = &(hmac_btcoex_get_vap_info(hmac_vap)->hmac_vap_btcoex_occupied);
1172     linkloss_threshold = get_current_linkloss_threshold(hmac_vap);
1173     linkloss = get_current_linkloss_cnt(hmac_vap);
1174     linkloss_times = linkloss_info->linkloss_times;
1175     unref_param(hal_device);
1176     unref_param(hal_chip);
1177 
1178     if (linkloss_threshold == 0) {
1179         return;
1180     }
1181     /* linkloss 大于1/4门限值进行处理 */
1182     if (linkloss < (linkloss_threshold >> 2)) { /* 右移2位,取linkloss_threshold高6位做比较 */
1183         return;
1184     }
1185 
1186     /* 门限值为异常值,即beacon周期很大 */
1187     if (linkloss_threshold <= WLAN_LINKLOSS_MIN_THRESHOLD) {
1188         hmac_btcoex_set_occupied_period(hmac_vap, COEX_LINKLOSS_OCCUP_PERIOD);
1189         oam_warning_log4(0, OAM_SF_COEX,
1190             "vap_id[%d] {hmac_btcoex_linkloss_occupied_process::occupied time=[%d], linkloss=[%d], threshold=[%d].}",
1191             hmac_vap->vap_id, COEX_LINKLOSS_OCCUP_PERIOD, linkloss, linkloss_threshold);
1192         return;
1193     }
1194 
1195     linkloss_tmp = g_occupied_point[btcoex_occupied->linkloss_index] + btcoex_occupied->occupied_times;
1196     if (linkloss > linkloss_tmp) {
1197         btcoex_occupied->occupied_times = 0;
1198         btcoex_occupied->linkloss_index++;
1199     } else if (linkloss == linkloss_tmp) {
1200         /* 在整个linkloss阶段拉高occupied 6-7个阶段, 每个阶段为300ms,每100ms拉一次20ms, 连续拉3次 */
1201         btcoex_occupied->occupied_times += linkloss_times;
1202         if (btcoex_occupied->occupied_times > (linkloss_times << 1)) {
1203             btcoex_occupied->occupied_times = 0;
1204             btcoex_occupied->linkloss_index++;
1205             if (btcoex_occupied->linkloss_index > BTCOEX_LINKLOSS_OCCUPIED_NUMBER - 1) {
1206                 btcoex_occupied->linkloss_index = 1;
1207             }
1208         }
1209         hmac_btcoex_device_occupied(hmac_vap, COEX_LINKLOSS_OCCUP_PERIOD);
1210         oam_warning_log4(0, OAM_SF_COEX,
1211             "vap_id[%d] {hmac_btcoex_linkloss_occupied_process::occupied time=[%d], linkloss=[%d], threshold=[%d].}",
1212             hmac_vap->vap_id, COEX_LINKLOSS_OCCUP_PERIOD, linkloss, linkloss_threshold);
1213     }
1214 }
1215 
1216 /*****************************************************************************
1217  函 数 名  : hmac_btcoex_rx_rate_process_check
1218  功能描述  : rx方向检查是否需要进行rate统计处理
1219 *****************************************************************************/
hmac_btcoex_rx_rate_process_check(hmac_vap_stru * hmac_vap,osal_u8 frame_subtype,osal_u8 data_type,oal_bool_enum_uint8 ampdu)1220 OSAL_STATIC osal_void hmac_btcoex_rx_rate_process_check(hmac_vap_stru *hmac_vap, osal_u8 frame_subtype,
1221     osal_u8 data_type, oal_bool_enum_uint8 ampdu)
1222 {
1223     /* 业务数据帧才做统计,qos null data等默认采用最低速率发送,不纳入统计,提高业务数据帧准确性 */
1224     if (frame_subtype != WLAN_QOS_NULL_FRAME && data_type > MAC_DATA_ARP_REQ) {
1225         if (ampdu == OSAL_TRUE) {
1226             hmac_btcoex_lower_rate_process(hmac_vap);
1227         }
1228     }
1229 }
1230 
1231 /*****************************************************************************
1232  函 数 名  : hmac_btcoex_roam_succ_handler
1233  功能描述  : BTCOEX下roam成功之后处理
1234              (1)从2G漫游到5G,03需要清统计信息,认为无影响
1235              (2)从5G漫游到2G, 03需要重新开启统计信息
1236              (3)漫游目前只是处理legacy sta, 该接口根据当前band来清状态或者配置参数,02不需要处理
1237 *****************************************************************************/
hmac_btcoex_roam_succ_handler(hmac_vap_stru * hmac_vap)1238 OSAL_STATIC osal_void hmac_btcoex_roam_succ_handler(hmac_vap_stru *hmac_vap)
1239 {
1240     hmac_user_stru *hmac_user = OSAL_NULL;
1241     hmac_user_btcoex_delba_stru *btcoex_delba = OSAL_NULL;
1242 
1243     /* 漫游一定是legacy sta,直接按照如下方式获取用户 */
1244     hmac_user = (hmac_user_stru *)mac_res_get_hmac_user_etc(hmac_vap->assoc_vap_id);
1245     if (osal_unlikely(hmac_user == OSAL_NULL)) {
1246         oam_error_log1(0, OAM_SF_COEX, "{hmac_btcoex_roam_succ_handler::hmac_user[%d] null.}",
1247             hmac_vap->assoc_vap_id);
1248         return;
1249     }
1250 
1251     /* 漫游成功之后,处于2G,需要启动业务配置 */
1252     if (mac_btcoex_check_valid_sta(hmac_vap) == OSAL_TRUE) {
1253         hmac_config_btcoex_assoc_state_syn(hmac_vap, hmac_user);
1254 
1255         oam_warning_log1(0, OAM_SF_COEX,
1256             "vap_id[%d] {hmac_btcoex_roam_succ_handler::wifi is on 2G, ba size to bt control.}", hmac_vap->vap_id);
1257     } else { /* 处于5G,需要删除配置,默认5G所有信息删除 */
1258         hmac_config_btcoex_disassoc_state_syn(hmac_vap);
1259 
1260         /* 有bt业务,需要恢复wifi控 */
1261         if (hal_btcoex_btble_status()->bt_status.bt_status.bt_on != 0) {
1262             btcoex_delba = &(hmac_btcoex_get_user_info(hmac_user)->hmac_user_btcoex_delba);
1263 
1264             btcoex_delba->ba_size = 0;
1265             hmac_btcoex_delba_trigger(hmac_vap, OSAL_FALSE, btcoex_delba);
1266 
1267             oam_warning_log1(0, OAM_SF_COEX,
1268                 "vap_id[%d] {hmac_btcoex_roam_succ_handler::wifi is on 5G, ba size to default.}", hmac_vap->vap_id);
1269         }
1270     }
1271 }
1272 
1273 /*****************************************************************************
1274  函 数 名  : hmac_btcoex_set_mgmt_priority
1275  功能描述  : 软件设定管理帧的高优先级保护, 暂时只是考虑关联管理帧,后续管理帧和控制帧
1276              需要考虑如果已经在拉高状态,尽量不处理,因为可能是vip帧拉高,避免覆盖
1277 *****************************************************************************/
hmac_btcoex_set_mgmt_priority(const hmac_vap_stru * hmac_vap,osal_u16 timeout_ms)1278 osal_void hmac_btcoex_set_mgmt_priority(const hmac_vap_stru *hmac_vap, osal_u16 timeout_ms)
1279 {
1280     if (hmac_vap->channel.band == WLAN_BAND_5G) {
1281         /* 5G不需要拉priority处理 */
1282         return;
1283     }
1284     oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_set_mgmt_priority::set timeout_us:%d}",
1285         hmac_vap->vap_id, timeout_ms);
1286 
1287     /* 16'hffff:持续拉高priority    16'h0:拉低priority   others:按配置的时间拉高priority */
1288     hal_set_btcoex_priority_period(timeout_ms);
1289 }
1290 
hmac_btcoex_restart_ps_timer(hal_to_dmac_device_stru * hal_device)1291 osal_void hmac_btcoex_restart_ps_timer(hal_to_dmac_device_stru *hal_device)
1292 {
1293     /* 如果定时器创建了,需要按照新的时间来刷新 */
1294     if (hal_device->btcoex_powersave_timer.is_registerd == OSAL_TRUE) {
1295         frw_destroy_timer_entry(&(hal_device->btcoex_powersave_timer));
1296         /* ps机制启动时,需要根据当前状态,刷新超时定时器时间,因为对应业务存在时,不会再来ps中断,需要此处来刷时间 */
1297         hmac_btcoex_ps_timeout_update_time(hal_device);
1298         frw_create_timer_entry(&(hal_device->btcoex_powersave_timer), hmac_btcoex_pow_save_callback,
1299             hal_device->btcoex_sw_preempt.timeout_ms, (osal_void *)hal_device, OSAL_FALSE);
1300     }
1301 }
1302 
1303 /* 在ble多连接和遥控器场景下,根据不同的带宽、频段进行BA_Size调整 */
hmac_btcoex_ble_action_req(hmac_vap_stru * hmac_vap,const hal_btcoex_btble_status_stru * status_old,hal_btcoex_btble_status_stru * status_new)1304 OSAL_STATIC osal_void hmac_btcoex_ble_action_req(hmac_vap_stru *hmac_vap,
1305     const hal_btcoex_btble_status_stru *status_old, hal_btcoex_btble_status_stru *status_new)
1306 {
1307     /* BA删建处理 */
1308     if (status_old->action_req.ble_req.req_ba != status_new->action_req.ble_req.req_ba) {
1309         hmac_btcoex_action_dela_ba_handler(hmac_vap);
1310         oam_warning_log1(0, OAM_SF_COEX, "{hmac_btcoex_ble_action_req::req_ba change to %u}",
1311             status_new->action_req.ble_req.req_ba);
1312     }
1313 
1314     /* PS申请处理 */
1315     if (status_old->action_req.ble_req.req_ps != status_new->action_req.ble_req.req_ps) {
1316         hmac_btcoex_ps_status_handler();
1317         oam_warning_log1(0, OAM_SF_COEX, "{hmac_btcoex_ble_action_req::req_ba change to %u}",
1318             status_new->action_req.ble_req.req_ps);
1319     }
1320 }
1321 
1322 /*****************************************************************************
1323  函 数 名  : hmac_btcoex_ps_status_handler
1324  功能描述  : BT音乐场景,识别bt ps进行ps操作
1325 *****************************************************************************/
hmac_btcoex_ps_status_handler(osal_void)1326 osal_void hmac_btcoex_ps_status_handler(osal_void)
1327 {
1328     oal_bool_enum_uint8 bt_acl_status;
1329     hmac_device_stru *hmac_device = hmac_res_get_mac_dev_etc(0);
1330     hal_chip_stru *hal_chip = hal_get_chip_stru(); /* 获取chip指针 */
1331     hal_device_stru *hal_device = &(hal_chip->device); /* 暂时只是处理主路的STA */
1332     hal_to_dmac_device_stru *h2d_device = &hal_device->hal_device_base;
1333 
1334     bt_acl_status = hal_btcoex_btble_status()->action_req.ble_req.req_ps;
1335     if (h2d_device->btcoex_sw_preempt.last_acl_status == bt_acl_status) {
1336         return;
1337     }
1338     if (bt_acl_status) {
1339         h2d_device->btcoex_sw_preempt.ps_on_cnt++;
1340         hmac_btcoex_ps_on_proc(hmac_device, h2d_device, hal_chip);
1341     } else {
1342         h2d_device->btcoex_sw_preempt.ps_off_cnt++;
1343         if (h2d_device->btcoex_powersave_timer.is_registerd == OSAL_TRUE) {
1344             frw_destroy_timer_entry(&(h2d_device->btcoex_powersave_timer));
1345         }
1346         /* 在scan状态时候,扫描不进入低功耗,此时不用担心低功耗,如果扫描来时 */
1347         if (h2d_device->hal_dev_fsm.oal_fsm.cur_state == HAL_DEVICE_SCAN_STATE) {
1348             hmac_btcoex_ps_off_scan_state_proc(hmac_device, h2d_device);
1349         } else {
1350             hmac_btcoex_ps_off_no_scan_state_proc(h2d_device);
1351         }
1352 
1353         h2d_device->btcoex_sw_preempt.sw_preempt_type = HAL_BTCOEX_SW_POWSAVE_IDLE; /* preempt机制置为IDLE形式 */
1354     }
1355     h2d_device->btcoex_sw_preempt.last_acl_status = bt_acl_status; /* 软件记录上一次的acl状态 */
1356 }
1357 
1358 /*****************************************************************************
1359  函 数 名  : hmac_btcoex_status_change_handler
1360  功能描述  : 状态寄存器处理消息入口
1361 *****************************************************************************/
hmac_btcoex_status_change_handler(hmac_vap_stru * hmac_vap,frw_msg * msg)1362 OSAL_STATIC osal_s32 hmac_btcoex_status_change_handler(hmac_vap_stru *hmac_vap, frw_msg *msg)
1363 {
1364     osal_s32 ret;
1365     hal_btcoex_btble_status_stru *status_old = hal_btcoex_btble_status_last();
1366     hal_btcoex_btble_status_stru *status_curr = hal_btcoex_btble_status();
1367     hal_btcoex_btble_status_msg_stru *status_msg = (hal_btcoex_btble_status_msg_stru *)msg->data;
1368 
1369     if ((msg->data_len != sizeof(hal_btcoex_btble_status_msg_stru)) || (msg->data == OSAL_NULL)) {
1370         oam_error_log1(0, OAM_SF_COEX, "{hmac_btcoex_status_change_handler::msg invalid len=%d!}",
1371             msg->data_len);
1372     }
1373 
1374     hal_btcoex_sync_btble_status(status_msg);
1375 #ifdef _PRE_WLAN_FEATURE_BT_SUPPORT
1376     hmac_btcoex_status_dispatch(hmac_vap, status_old, status_curr);
1377 #endif
1378     hmac_btcoex_ble_action_req(hmac_vap, status_old, status_curr);
1379     ret = memcpy_s(status_old, sizeof(hal_btcoex_btble_status_stru), status_curr,
1380         sizeof(hal_btcoex_btble_status_stru));
1381     if (ret != EOK) {
1382         oam_error_log1(0, OAM_SF_COEX, "{hmac_btcoex_status_change_handler::memcpy_s failed code = %d!}", ret);
1383     }
1384     return OAL_SUCC;
1385 }
1386 
1387 /*****************************************************************************
1388  函 数 名  : hmac_btcoex_blacklist_handle_init
1389  功能描述  : 初始化黑名单方案
1390              (1)黑名单用户时,删用户,并聚合个数为8,再次关联也始终聚合8个
1391              (2)黑名单用户时,addba rsp为37不聚合,蓝牙业务结束时利用漫游重关联,聚合64恢复wifi性能
1392              增加一个user结构下开关功能
1393 
1394              方案1缺点: 删用户要断流;蓝牙业务结束,wifi性能不恢复;黑名单用户始终存在,开关wifi性能也不恢复
1395  输入参数  : 无
1396  输出参数  : 无
1397 *****************************************************************************/
hmac_btcoex_blacklist_handle_init(hmac_user_stru * hmac_user)1398 osal_void hmac_btcoex_blacklist_handle_init(hmac_user_stru *hmac_user)
1399 {
1400     /* 03采用方案2,02采用方案1 */
1401     hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_addba_req.blacklist_tpye = BTCOEX_BLACKLIST_TPYE_NOT_AGGR;
1402 
1403     oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_blacklist_handle_init::blacklist_tpye[%d]!}",
1404         hmac_user->vap_id,
1405         hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_addba_req.blacklist_tpye);
1406 }
1407 
1408 /*****************************************************************************
1409  函 数 名  : hmac_btcoex_check_exception_in_list_etc
1410  功能描述  : hmac检查异常兼容性AP的地址
1411  输入参数  : 无
1412  输出参数  : 无
1413 *****************************************************************************/
hmac_btcoex_check_exception_in_list_etc(osal_u8 * addr)1414 OAL_STATIC osal_u32 hmac_btcoex_check_exception_in_list_etc(osal_u8 *addr)
1415 {
1416     hmac_btcoex_delba_exception_stru *btcoex_exception;
1417     osal_u8                         index;
1418 
1419     for (index = 0; index < BTCOEX_BSS_NUM_IN_BLACKLIST; index++) {
1420         btcoex_exception = &(g_hmac_device_btcoex->hmac_btcoex_delba_exception[index]);
1421         if ((btcoex_exception->used != 0) &&
1422             (oal_compare_mac_addr(btcoex_exception->user_mac_addr, addr) == 0)) {
1423             oam_warning_log4(0, OAM_SF_COEX,
1424                 "{hmac_btcoex_check_exception_in_list_etc::Find in blacklist, addr->%02x:%02x:%02x:%02x:XX:XX.}",
1425                 addr[0], addr[1], addr[2], addr[3]);    /* 2,3 MAC地址 */
1426             return OAL_TRUE;
1427         }
1428     }
1429 
1430     return OAL_FALSE;
1431 }
1432 
1433 /*****************************************************************************
1434  函 数 名  : hmac_btcoex_add_exception_to_list
1435  功能描述  : hmac记录异常兼容性AP的地址
1436  输入参数  : 无
1437  输出参数  : 无
1438 *****************************************************************************/
hmac_btcoex_add_exception_to_list(hmac_vap_stru * hmac_vap,osal_u8 * auc_mac_addr)1439 OAL_STATIC osal_void hmac_btcoex_add_exception_to_list(hmac_vap_stru *hmac_vap, osal_u8 *auc_mac_addr)
1440 {
1441     hmac_btcoex_delba_exception_stru *btcoex_exception;
1442     unref_param(hmac_vap);
1443 
1444     if (g_hmac_device_btcoex->exception_bss_index >= BTCOEX_BSS_NUM_IN_BLACKLIST) {
1445         oam_warning_log2(0, OAM_SF_COEX, "vap_id[%d] {hmac_btcoex_add_exception_to_list::already reach max num:%d.}",
1446             hmac_vap->vap_id, BTCOEX_BSS_NUM_IN_BLACKLIST);
1447         g_hmac_device_btcoex->exception_bss_index = 0;
1448     }
1449     btcoex_exception =
1450         &(g_hmac_device_btcoex->hmac_btcoex_delba_exception[g_hmac_device_btcoex->exception_bss_index]);
1451     oal_set_mac_addr(btcoex_exception->user_mac_addr, auc_mac_addr);
1452     btcoex_exception->type = 0;
1453     btcoex_exception->used = 1;
1454 
1455     g_hmac_device_btcoex->exception_bss_index++;
1456 }
1457 
1458 /*****************************************************************************
1459  函 数 名  : hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc
1460  功能描述  : hmac记录异常兼容性AP的地址
1461  输入参数  : 无
1462  输出参数  : 无
1463 *****************************************************************************/
hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,mac_ieee80211_frame_stru * frame_hdr,const osal_u8 * action)1464 OSAL_STATIC osal_void hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc(hmac_vap_stru *hmac_vap,
1465     hmac_user_stru *hmac_user, mac_ieee80211_frame_stru *frame_hdr, const osal_u8 *action)
1466 {
1467     hmac_btcoex_addba_req_stru     *btcoex_addba_req;
1468     hmac_user_btcoex_stru          *hmac_user_btcoex;
1469     osal_u16                      baw_start;
1470     osal_u8                       tid;
1471 
1472     hmac_user_btcoex = hmac_btcoex_get_user_info(hmac_user);
1473 
1474     btcoex_addba_req = &(hmac_user_btcoex->hmac_btcoex_addba_req);
1475 
1476     /* 两次收到addba req的start num一样且不是重传帧,认为对端移窗卡死  */
1477     if (frame_hdr->frame_control.retry == OAL_TRUE &&
1478         frame_hdr->seq_num == btcoex_addba_req->last_seq_num) {
1479         oam_warning_log0(0, OAM_SF_COEX,
1480             "{hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc::retry addba req.}");
1481         return;
1482     }
1483 
1484     /*******************************************************************/
1485     /*       ADDBA Request Frame - Frame Body                          */
1486     /* --------------------------------------------------------------- */
1487     /* | Category | Action | Dialog | Parameters | Timeout | SSN     | */
1488     /* --------------------------------------------------------------- */
1489     /* | 1        | 1      | 1      | 2          | 2       | 2       | */
1490     /* --------------------------------------------------------------- */
1491     /*                                                                 */
1492     /*******************************************************************/
1493     baw_start = (action[7] >> 4) | (action[8] << 4);     /* 7,8 索引 左移右移4位 */
1494     tid = (action[3] & 0x3C) >> 2;   /* 3 索引,右移2位 */
1495     if (tid != 0) {
1496         oam_warning_log0(0, OAM_SF_COEX,
1497             "{hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc::tid != 0.}");
1498         return;
1499     }
1500 
1501     if ((baw_start != 0) && (baw_start == btcoex_addba_req->last_baw_start) &&
1502         (hmac_user_btcoex->rx_no_pkt_count > 2)) {   /* 计数次数大于2 */
1503         oam_warning_log1(0, OAM_SF_COEX,
1504             "{hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc::baw_start:%d, delba will forbidden.}",
1505             baw_start);
1506 
1507         /* 黑名单ba处理标记 */
1508         btcoex_addba_req->ba_handle_allow = OAL_FALSE;
1509 
1510         if (hmac_btcoex_check_exception_in_list_etc(frame_hdr->address2) == OAL_FALSE) {
1511             oam_warning_log0(0, OAM_SF_COEX,
1512                 "{hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc::write down to file.}");
1513             hmac_btcoex_add_exception_to_list(hmac_vap, frame_hdr->address2);
1514         }
1515 
1516         if (hmac_btcoex_get_blacklist_type(hmac_user) == BTCOEX_BLACKLIST_TPYE_FIX_BASIZE) {
1517             /* 发送去认证帧到AP */
1518             hmac_mgmt_send_disassoc_frame_etc(hmac_vap, frame_hdr->address2,
1519                 MAC_UNSPEC_REASON, hmac_user->cap_info.pmf_active);
1520             oam_warning_log1(0, OAM_SF_DFT,
1521                 "hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc:send DISASSOC,err code[%d]", MAC_UNSPEC_REASON);
1522 
1523             /* 删除对应用户 */
1524             hmac_user_del_etc(hmac_vap, hmac_user);
1525 
1526             hmac_sta_handle_disassoc_rsp_etc(hmac_vap, MAC_AUTH_NOT_VALID);
1527         }
1528     }
1529 
1530     btcoex_addba_req->last_baw_start = baw_start;
1531     btcoex_addba_req->last_seq_num = frame_hdr->seq_num;
1532 }
1533 
1534 /*****************************************************************************
1535  功能描述  : user add初始化处理
1536 *****************************************************************************/
hmac_btcoex_proc_user_add(hmac_user_stru * hmac_user)1537 OSAL_STATIC osal_u32 hmac_btcoex_proc_user_add(hmac_user_stru *hmac_user)
1538 {
1539     hmac_user_btcoex_stru *user_btcoex_info = OSAL_NULL;
1540     osal_u32 ret;
1541 
1542     user_btcoex_info = (hmac_user_btcoex_stru *)osal_kmalloc(sizeof(hmac_user_btcoex_stru), OSAL_GFP_KERNEL);
1543     if (user_btcoex_info == OSAL_NULL) {
1544         oam_error_log0(0, OAM_SF_M2S, "hmac_btcoex_proc_user_add mem alloc fail");
1545         return OAL_ERR_CODE_PTR_NULL;
1546     }
1547     (osal_void)memset_s(user_btcoex_info, sizeof(hmac_user_btcoex_stru), 0, sizeof(hmac_user_btcoex_stru));
1548 
1549     /* 注册特性数据结构 */
1550     ret = hmac_user_feature_registered(hmac_user, WLAN_FEATURE_INDEX_BTCOEX, user_btcoex_info);
1551     if (ret != OAL_SUCC) {
1552         oam_error_log1(0, OAM_SF_M2S, "hmac_btcoex_proc_user_add register feature fail(%u)", ret);
1553         osal_kfree(user_btcoex_info);
1554     }
1555 
1556     return ret;
1557 }
1558 
1559 /*****************************************************************************
1560  功能描述  : user del去初始化处理
1561 *****************************************************************************/
hmac_btcoex_proc_user_del(osal_void * notify_data)1562 OSAL_STATIC osal_bool hmac_btcoex_proc_user_del(osal_void *notify_data)
1563 {
1564     hmac_user_btcoex_stru *user_btcoex_info = OSAL_NULL;
1565     hmac_user_stru *hmac_user = (hmac_user_stru *)notify_data;
1566 
1567     user_btcoex_info = (hmac_user_btcoex_stru *)hmac_user_get_feature_ptr(hmac_user, WLAN_FEATURE_INDEX_BTCOEX);
1568     if (user_btcoex_info == OSAL_NULL) {
1569         oam_error_log0(0, OAM_SF_M2S, "hmac_btcoex_proc_user_del get feature fail");
1570         return OSAL_FALSE;
1571     }
1572 
1573     hmac_user_feature_unregister(hmac_user, WLAN_FEATURE_INDEX_BTCOEX);
1574     osal_kfree(user_btcoex_info);
1575     return OSAL_TRUE;
1576 }
1577 
1578 /*****************************************************************************
1579  功能描述  : vap add初始化处理
1580 *****************************************************************************/
hmac_btcoex_proc_vap_add(hmac_vap_stru * hmac_vap)1581 OSAL_STATIC osal_u32 hmac_btcoex_proc_vap_add(hmac_vap_stru *hmac_vap)
1582 {
1583     hmac_vap_btcoex_stru *vap_btcoex_info = OSAL_NULL;
1584     osal_u32 ret;
1585 
1586     vap_btcoex_info = (hmac_vap_btcoex_stru *)osal_kmalloc(sizeof(hmac_vap_btcoex_stru), OSAL_GFP_KERNEL);
1587     if (vap_btcoex_info == OSAL_NULL) {
1588         oam_error_log0(0, OAM_SF_M2S, "hmac_btcoex_proc_vap_add mem alloc fail");
1589         return OAL_ERR_CODE_PTR_NULL;
1590     }
1591     (osal_void)memset_s(vap_btcoex_info, sizeof(hmac_vap_btcoex_stru), 0, sizeof(hmac_vap_btcoex_stru));
1592 
1593     /* 注册特性数据结构 */
1594     ret = hmac_vap_feature_registered(hmac_vap, WLAN_FEATURE_INDEX_BTCOEX, vap_btcoex_info);
1595     if (ret != OAL_SUCC) {
1596         oam_error_log1(0, OAM_SF_M2S, "hmac_btcoex_proc_vap_add register feature fail(%u)", ret);
1597         osal_kfree(vap_btcoex_info);
1598     }
1599 
1600     return ret;
1601 }
1602 
1603 /*****************************************************************************
1604  功能描述  : vap del去初始化处理
1605 *****************************************************************************/
hmac_btcoex_proc_vap_del(osal_void * notify_data)1606 OSAL_STATIC osal_bool hmac_btcoex_proc_vap_del(osal_void *notify_data)
1607 {
1608     hmac_vap_btcoex_stru *vap_btcoex_info = OSAL_NULL;
1609     hmac_vap_stru *hmac_vap = (hmac_vap_stru *)notify_data;
1610 
1611     vap_btcoex_info = (hmac_vap_btcoex_stru *)hmac_vap_get_feature_ptr(hmac_vap, WLAN_FEATURE_INDEX_BTCOEX);
1612     if (vap_btcoex_info == OSAL_NULL) {
1613         oam_error_log0(0, OAM_SF_M2S, "hmac_btcoex_proc_vap_del get feature fail");
1614         return OSAL_FALSE;
1615     }
1616 
1617     hmac_vap_feature_unregister(hmac_vap, WLAN_FEATURE_INDEX_BTCOEX);
1618     osal_kfree(vap_btcoex_info);
1619     return OSAL_TRUE;
1620 }
1621 
1622 /*****************************************************************************
1623  功能描述  : device add初始化处理
1624 *****************************************************************************/
hmac_btcoex_proc_device_add(osal_void)1625 OSAL_STATIC osal_u32 hmac_btcoex_proc_device_add(osal_void)
1626 {
1627     g_hmac_device_btcoex = (hmac_device_btcoex_stru *)osal_kmalloc(sizeof(hmac_device_btcoex_stru), OSAL_GFP_KERNEL);
1628     if (g_hmac_device_btcoex == OSAL_NULL) {
1629         oam_error_log0(0, OAM_SF_M2S, "hmac_btcoex_proc_device_add mem alloc fail");
1630         return OAL_FAIL;
1631     }
1632     (osal_void)memset_s(g_hmac_device_btcoex, sizeof(hmac_device_btcoex_stru), 0, sizeof(hmac_device_btcoex_stru));
1633     return OAL_SUCC;
1634 }
1635 
1636 /*****************************************************************************
1637  功能描述  : device del去初始化处理
1638 *****************************************************************************/
hmac_btcoex_proc_device_del(osal_void)1639 OSAL_STATIC osal_void hmac_btcoex_proc_device_del(osal_void)
1640 {
1641     if (g_hmac_device_btcoex == OSAL_NULL) {
1642         oam_error_log0(0, OAM_SF_M2S, "hmac_btcoex_proc_device_del excute fail");
1643         return;
1644     }
1645     osal_kfree(g_hmac_device_btcoex);
1646     g_hmac_device_btcoex = OSAL_NULL;
1647 }
1648 
1649 /*****************************************************************************
1650  函 数 名  : hmac_btcoex_abort_end_time
1651  功能描述  : HAL层中的btcoex中断对应的事件处理函数
1652 *****************************************************************************/
hmac_btcoex_abort_end_time(hmac_vap_stru * hmac_vap,frw_msg * msg)1653 OSAL_STATIC osal_s32 hmac_btcoex_abort_end_time(hmac_vap_stru *hmac_vap, frw_msg *msg)
1654 {
1655     hal_btcoex_statistics_stru *tmp_sta = OSAL_NULL;
1656     hal_btcoex_statistics_stru *btcoex_statistics = OSAL_NULL;
1657 
1658     unref_param(hmac_vap);
1659     tmp_sta = (hal_btcoex_statistics_stru *)(msg->data);
1660     btcoex_statistics = hal_btcoex_statistics();
1661     btcoex_statistics->abort_duration_us = tmp_sta->abort_duration_us;
1662     btcoex_statistics->abort_duration_ = tmp_sta->abort_duration_;
1663     return OAL_SUCC;
1664 }
1665 
hmac_btcoex_recover_coex_priority(hmac_vap_stru * hmac_vap)1666 OSAL_STATIC osal_void hmac_btcoex_recover_coex_priority(hmac_vap_stru *hmac_vap)
1667 {
1668     hmac_btcoex_set_wlan_priority(hmac_vap, OSAL_FALSE, 0);
1669     hmac_btcoex_set_occupied_period(hmac_vap, 0);
1670 }
1671 
hmac_btcoex_recover_coex_priority_clear(hmac_vap_stru * hmac_vap,const hmac_device_stru * hmac_device)1672 OSAL_STATIC osal_void hmac_btcoex_recover_coex_priority_clear(hmac_vap_stru *hmac_vap,
1673     const hmac_device_stru *hmac_device)
1674 {
1675     hmac_btcoex_recover_coex_priority(hmac_vap);
1676     /* 若当前删除的vap是最后一个,将WIFI状态清除 */
1677     if (hmac_device->vap_num == 1) {
1678         hal_btcoex_clear_reg();
1679     }
1680 }
1681 
hmac_btcoex_check_exception_in_list(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,osal_u8 * addr_sa)1682 OSAL_STATIC osal_void hmac_btcoex_check_exception_in_list(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
1683     osal_u8 *addr_sa)
1684 {
1685     hmac_btcoex_blacklist_handle_init(hmac_user);
1686     if (hmac_btcoex_check_exception_in_list_etc(addr_sa) == OAL_TRUE) {
1687         if (hmac_btcoex_get_blacklist_type(hmac_user) == BTCOEX_BLACKLIST_TPYE_FIX_BASIZE) {
1688             oam_warning_log1(0, OAM_SF_COEX,
1689                 "vap_id[%d] {hmac_btcoex_check_exception_in_list::mac_addr in blacklist.}",
1690                 hmac_vap->vap_id);
1691             hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_addba_req.ba_handle_allow = OAL_FALSE;
1692         } else {
1693             hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_addba_req.ba_handle_allow = OAL_TRUE;
1694         }
1695     } else {
1696         /* 初始允许建立聚合,两个方案保持对齐 */
1697         hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_addba_req.ba_handle_allow = OAL_TRUE;
1698     }
1699 }
1700 
hmac_btcoex_rx_process_ect(hmac_vap_stru * hmac_vap,osal_u8 frame_subtype,oal_netbuf_stru * netbuf,oal_bool_enum_uint8 ampdu)1701 WIFI_HMAC_TCM_TEXT WIFI_TCM_TEXT OSAL_STATIC osal_void hmac_btcoex_rx_process_ect(hmac_vap_stru *hmac_vap,
1702     osal_u8 frame_subtype, oal_netbuf_stru *netbuf, oal_bool_enum_uint8 ampdu)
1703 {
1704     osal_u8 data_type;
1705     hal_btcoex_btble_status_stru *status = hal_btcoex_btble_status();
1706     if (status->bt_status.bt_status.bt_on == OSAL_FALSE) {
1707         return;
1708     }
1709 
1710     data_type = hmac_get_rx_data_type_etc(netbuf);
1711     hmac_btcoex_release_rx_prot(hmac_vap, data_type);
1712     /* ps帧发出去后,还收到对端的数据属于正常,要考虑再发一帧的优化暂时不需要 */
1713     hmac_btcoex_rx_rate_process_check(hmac_vap, frame_subtype, data_type, ampdu);
1714 }
1715 
1716 /* 下面会定义一些调用hal层函数的函数接口,用于解耦 */
hmac_btcoex_hal_get_btstatus_bton(osal_void)1717 OSAL_STATIC osal_u16 hmac_btcoex_hal_get_btstatus_bton(osal_void)
1718 {
1719     return hal_btcoex_get_bt_run();
1720 }
1721 
hmac_btcoex_hal_blinkloss_clean(hmac_vap_stru * hmac_vap)1722 OSAL_STATIC osal_void hmac_btcoex_hal_blinkloss_clean(hmac_vap_stru *hmac_vap)
1723 {
1724     hmac_vap_btcoex_occupied_stru *btcoex_occupied = OSAL_NULL;
1725     hmac_vap_btcoex_stru *btcoex_info = hmac_btcoex_get_vap_info(hmac_vap);
1726     if (btcoex_info == OSAL_NULL) {
1727         return;
1728     }
1729     btcoex_occupied = &(btcoex_info->hmac_vap_btcoex_occupied);
1730     btcoex_occupied->linkloss_index = 1;
1731     btcoex_occupied->linkloss_occupied_times = 0;
1732 }
1733 
hmac_btcoex_check_user_req_declined(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user)1734 OSAL_STATIC osal_u32 hmac_btcoex_check_user_req_declined(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user)
1735 {
1736     if (mac_btcoex_check_valid_sta(hmac_vap) == OAL_TRUE) {
1737         if (hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_addba_req.ba_handle_allow == OAL_FALSE) {
1738             oam_warning_log1(0, OAM_SF_BA,
1739                 "vap_id[%d] {hmac_mgmt_check_set_rx_ba_ok_etc::btcoex blacklist user, not addba!",
1740                 hmac_vap->vap_id);
1741             return OAL_TRUE;
1742         }
1743     }
1744     return OAL_FALSE;
1745 }
1746 
hmac_btcoex_hal_set_aging_time(const hmac_vap_stru * hmac_vap,osal_u32 * aging_time)1747 OSAL_STATIC osal_u32 hmac_btcoex_hal_set_aging_time(const hmac_vap_stru *hmac_vap, osal_u32 *aging_time)
1748 {
1749     if (hmac_vap->hal_chip == OSAL_NULL) {
1750         return OAL_FAIL;
1751     }
1752     if (hal_btcoex_btble_status()->bt_status.bt_status.bt_ba != 0) {
1753         /* bt_ba为true时,aging_time为2倍WLAN_P2PGO_USER_AGING_TIME */
1754         *aging_time = 2 * WLAN_P2PGO_USER_AGING_TIME;
1755     }
1756     return OAL_SUCC;
1757 }
1758 
hmac_btcoex_set_txop_alg(hal_tx_txop_alg_stru * txop_alg)1759 OSAL_STATIC osal_void hmac_btcoex_set_txop_alg(hal_tx_txop_alg_stru *txop_alg)
1760 {
1761     if (hal_btcoex_btble_status()->bt_status.bt_status.bt_sco != 0) {
1762         hal_txop_alg_get_tx_dscr(txop_alg)[0].tx_count = 1;
1763     }
1764 }
1765 
hmac_btcoex_check_sw_preempt_type(const hmac_vap_stru * hmac_vap,const hal_to_dmac_device_stru * hal_device)1766 OSAL_STATIC osal_u32 hmac_btcoex_check_sw_preempt_type(const hmac_vap_stru *hmac_vap,
1767     const hal_to_dmac_device_stru *hal_device)
1768 {
1769     if (hal_device->btcoex_sw_preempt.sw_preempt_type == HAL_BTCOEX_SW_POWSAVE_WORK) {
1770         oam_warning_log1(0, 0, "vap_id[%d] {hmac_is_need_enqueue_fake::BT ps is working.}", hmac_vap->vap_id);
1771         return OSAL_TRUE;
1772     }
1773     return OSAL_FALSE;
1774 }
1775 
hmac_btcoex_hal_set_btcoex_wifi_status(const hmac_vap_stru * hmac_vap,osal_u32 status)1776 OSAL_STATIC osal_void hmac_btcoex_hal_set_btcoex_wifi_status(const hmac_vap_stru *hmac_vap, osal_u32 status)
1777 {
1778     hal_set_btcoex_wifi_status_notify(HAL_BTCOEX_WIFI_STATE_SCAN, status);
1779     if (hmac_vap->p2p_mode == WLAN_P2P_DEV_MODE) {
1780         hal_set_btcoex_wifi_status_notify(HAL_BTCOEX_WIFI_STATE_P2P_SCAN, status);
1781     }
1782     hal_coex_sw_irq_set(HAL_COEX_SW_IRQ_BT);
1783 }
1784 
hmac_btcoex_hal_end_scan_check_ps(hal_to_dmac_device_stru * hal_device,hmac_vap_stru * hmac_vap)1785 OSAL_STATIC osal_u32 hmac_btcoex_hal_end_scan_check_ps(hal_to_dmac_device_stru *hal_device, hmac_vap_stru *hmac_vap)
1786 {
1787     if (hal_device->btcoex_sw_preempt.sw_preempt_type == HAL_BTCOEX_SW_POWSAVE_WORK) {
1788         hal_device->btcoex_sw_preempt.sw_preempt_type = HAL_BTCOEX_SW_POWSAVE_SCAN_END;
1789         oam_warning_log1(0, OAM_SF_COEX,
1790             "vap_id[%d] {hmac_scan_prepare_end:: normal scan end delay by btcoex!}", hmac_vap->vap_id);
1791         return OSAL_TRUE;
1792     }
1793     return OSAL_FALSE;
1794 }
1795 
hmac_btcoex_update_bss_list_protocol(mac_bss_dscr_stru * bss_dscr,osal_u8 * frame_body,osal_u16 frame_len)1796 OSAL_STATIC osal_void hmac_btcoex_update_bss_list_protocol(mac_bss_dscr_stru *bss_dscr, osal_u8 *frame_body,
1797     osal_u16 frame_len)
1798 {
1799     osal_u8 *ie;
1800     osal_u8 *ie_a;
1801     ie = hmac_find_vendor_ie_etc(MAC_WLAN_CHIP_OUI_RALINK, MAC_WLAN_CHIP_OUI_TYPE_RALINK, frame_body, frame_len);
1802     ie_a = hmac_find_vendor_ie_etc(MAC_WLAN_CHIP_OUI_RALINK, MAC_WLAN_CHIP_OUI_TYPE_RALINK1, frame_body, frame_len);
1803     bss_dscr->btcoex_ps_blacklist_chip_oui = ((ie != OAL_PTR_NULL) || (ie_a != OAL_PTR_NULL)) ? OAL_TRUE : OAL_FALSE;
1804 }
1805 
hmac_btcoex_check_ap_type_blacklist(hmac_vap_stru * hmac_vap,osal_u8 * mac_addr,wlan_nss_enum_uint8 * support_max_nss)1806 OSAL_STATIC osal_u32 hmac_btcoex_check_ap_type_blacklist(hmac_vap_stru *hmac_vap, osal_u8 *mac_addr,
1807     wlan_nss_enum_uint8 *support_max_nss)
1808 {
1809     mac_bss_dscr_stru *bss_dscr = OSAL_NULL;
1810     /* 关联ap识别: AP OUI + chip OUI + 双流 + 2G 需要dmac侧刷新ps机制时one pkt帧发送类型 */
1811     if ((mac_is_dlink_ap(mac_addr) == OSAL_TRUE) || (mac_is_haier_ap(mac_addr) == OSAL_TRUE)) {
1812         bss_dscr = (mac_bss_dscr_stru *)hmac_scan_get_scanned_bss_by_bssid(hmac_vap, mac_addr);
1813         if (bss_dscr != OAL_PTR_NULL) {
1814 #ifdef _PRE_WLAN_FEATURE_M2S
1815             *support_max_nss = bss_dscr->support_max_nss;
1816 #endif
1817             if ((bss_dscr->btcoex_ps_blacklist_chip_oui == OSAL_TRUE) && (*support_max_nss == WLAN_DOUBLE_NSS) &&
1818                 (hmac_vap->channel.band == WLAN_BAND_2G)) {
1819                 oam_warning_log1(0, OAM_SF_COEX,
1820                     "vap_id[%d] hmac_compability_ap_tpye_identify_etc: btcoex ps whitelist!",
1821                     hmac_vap->vap_id);
1822                 return OSAL_FALSE;
1823             }
1824         }
1825     }
1826     return OSAL_TRUE;
1827 }
1828 
hmac_btcoex_clear_arp_timer(hmac_user_stru * hmac_user)1829 OSAL_STATIC osal_void hmac_btcoex_clear_arp_timer(hmac_user_stru *hmac_user)
1830 {
1831     /* 清理arp探测timer */
1832     if (hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_arp_req_process.delba_opt_timer.is_registerd == OAL_TRUE) {
1833         frw_destroy_timer_entry(&(hmac_btcoex_get_user_info(hmac_user)->hmac_btcoex_arp_req_process.delba_opt_timer));
1834     }
1835 }
1836 
hmac_btcoex_keepalive_timer_ect(osal_u32 * aging_time)1837 OSAL_STATIC osal_void hmac_btcoex_keepalive_timer_ect(osal_u32 *aging_time)
1838 {
1839     if (hal_btcoex_btble_status()->bt_status.bt_status.bt_on != 0) {
1840         /* 蓝牙共存时,aging_time为2倍WLAN_P2PGO_USER_AGING_TIME */
1841         *aging_time = 2 * WLAN_P2PGO_USER_AGING_TIME;
1842     }
1843 }
1844 
hmac_btcoex_compatibility_set_ps_type(hmac_vap_stru * hmac_vap)1845 OSAL_STATIC osal_void hmac_btcoex_compatibility_set_ps_type(hmac_vap_stru *hmac_vap)
1846 {
1847     hmac_vap_btcoex_stru *btcoex_info = hmac_btcoex_get_vap_info(hmac_vap);
1848     if (btcoex_info == OSAL_NULL) {
1849         return;
1850     }
1851     btcoex_info->ps_type = HAL_BTCOEX_HW_POWSAVE_NULLDATA;
1852 }
1853 
hmac_btcoex_compatibility_set_ap_type(hmac_vap_stru * hmac_vap,mac_ap_type_enum_uint8 ap_type)1854 OSAL_STATIC osal_void hmac_btcoex_compatibility_set_ap_type(hmac_vap_stru *hmac_vap, mac_ap_type_enum_uint8 ap_type)
1855 {
1856     hmac_vap_btcoex_stru *btcoex_info = hmac_btcoex_get_vap_info(hmac_vap);
1857     if (btcoex_info == OSAL_NULL) {
1858         return;
1859     }
1860     /* 如果是兼容性ap,需要刷新one pkt帧类型 */
1861     if (ap_type == MAC_AP_TYPE_BTCOEX_PS_BLACKLIST) {
1862         btcoex_info->ps_type = HAL_BTCOEX_HW_POWSAVE_SELFCTS;
1863     } else {
1864         btcoex_info->ps_type = HAL_BTCOEX_HW_POWSAVE_NULLDATA;
1865     }
1866 }
1867 
hmac_btcoex_hal_user_add_handle(hmac_vap_stru * hmac_vap,mac_user_type_enum_uint8 user_type)1868 OSAL_STATIC osal_void hmac_btcoex_hal_user_add_handle(hmac_vap_stru *hmac_vap, mac_user_type_enum_uint8 user_type)
1869 {
1870     if (hmac_vap->vap_mode == WLAN_VAP_MODE_BSS_STA && user_type == MAC_USER_TYPE_DEFAULT) {
1871         // 入网流程开始,发起auth
1872         hal_set_btcoex_wifi_status_notify(HAL_BTCOEX_WIFI_STATE_AUTH_MODE, OSAL_TRUE);
1873     }
1874 }
1875 
hmac_btcoex_vap_resume_tx_by_chl(hmac_vap_stru * hmac_vap,const hal_to_dmac_device_stru * hal_device)1876 OSAL_STATIC osal_void hmac_btcoex_vap_resume_tx_by_chl(hmac_vap_stru *hmac_vap,
1877     const hal_to_dmac_device_stru *hal_device)
1878 {
1879     if ((hmac_vap->hal_device != OSAL_NULL) &&
1880         (hmac_vap->hal_device->btcoex_sw_preempt.sw_preempt_subtype == HAL_BTCOEX_SW_POWSAVE_SUB_CONNECT)) {
1881         /* 状态恢复 */
1882         hmac_vap->hal_device->btcoex_sw_preempt.sw_preempt_subtype = HAL_BTCOEX_SW_POWSAVE_SUB_ACTIVE;
1883         oam_warning_log1(0, 0, "{hmac_vap_resume_tx_by_chl:: vap[%d] is up because powsave when connect!}",
1884             hmac_vap->vap_id);
1885     } else if (osal_likely(hal_device != OSAL_NULL)) {
1886         oam_warning_log3(0, 0, "{hmac_vap_resume_tx_by_chl::vap id=%d, state[%d], preempt state[%d].}",
1887             hmac_vap->vap_id, hmac_vap->vap_state,
1888             hal_device->btcoex_sw_preempt.sw_preempt_type);
1889     }
1890 }
1891 
hmac_btcoex_vap_config_sw_preempt_subtype(hal_to_dmac_device_stru * hal_device)1892 OSAL_STATIC osal_void hmac_btcoex_vap_config_sw_preempt_subtype(hal_to_dmac_device_stru *hal_device)
1893 {
1894     if (hal_device->btcoex_sw_preempt.sw_preempt_type == HAL_BTCOEX_SW_POWSAVE_WORK) {
1895         /* 如果设备在关联过程中已经处于ps状态, 子状态置为connect状态 */
1896         hal_device->btcoex_sw_preempt.sw_preempt_subtype = HAL_BTCOEX_SW_POWSAVE_SUB_CONNECT;
1897     }
1898 }
1899 
hmac_btcoex_device_exit_destroy_timer(hal_to_dmac_device_stru * hal_device)1900 OSAL_STATIC osal_void hmac_btcoex_device_exit_destroy_timer(hal_to_dmac_device_stru *hal_device)
1901 {
1902     frw_destroy_timer_entry(&(hal_device->btcoex_powersave_timer));
1903     frw_destroy_timer_entry(&(hal_device->device_btcoex_mgr.s2m_resume_timer));
1904     frw_destroy_timer_entry(&(hal_device->device_btcoex_mgr.bt_coex_s2m_siso_ap_timer));
1905 }
1906 
hmac_btcoex_report_linkloss_info(const hmac_vap_stru * hmac_sta)1907 OSAL_STATIC osal_void hmac_btcoex_report_linkloss_info(const hmac_vap_stru *hmac_sta)
1908 {
1909     oam_warning_log4(0, OAM_SF_ANY,
1910         "vap_id[%d] bt_linkloss_info: bt_link_loss_cnt =%d, bt_linkloss_threshold = %d, bt state is bt_on/off =%d",
1911         hmac_sta->vap_id, hmac_sta->linkloss_info.linkloss_info[WLAN_LINKLOSS_MODE_BT].link_loss,
1912         hmac_sta->linkloss_info.linkloss_info[WLAN_LINKLOSS_MODE_BT].linkloss_threshold,
1913         hal_btcoex_btble_status()->bt_status.bt_status.bt_on);
1914 }
1915 
hmac_btcoex_sw_preempt_type_check(hal_to_dmac_device_stru * hal_device)1916 OSAL_STATIC osal_u32 hmac_btcoex_sw_preempt_type_check(hal_to_dmac_device_stru *hal_device)
1917 {
1918     /* 如果已经处于btcoex ps状态下, 不需要再执行restore动作 */
1919     if (hal_device->btcoex_sw_preempt.sw_preempt_type == HAL_BTCOEX_SW_POWSAVE_WORK) {
1920         oam_warning_log0(0, OAM_SF_M2S, "{hmac_m2s_switch::btcoex ps is working not need to switch end.}");
1921         return OSAL_TRUE;
1922     }
1923     return OSAL_FALSE;
1924 }
1925 
1926 #ifdef _PRE_WLAN_SUPPORT_CCPRIV_CMD
1927 #ifdef _PRE_WIFI_PRINTK
hmac_btcoex_status_info_dump(const hal_to_dmac_device_stru * hal_device,hal_chip_stru * hal_chip)1928 osal_void hmac_btcoex_status_info_dump(const hal_to_dmac_device_stru *hal_device, hal_chip_stru *hal_chip)
1929 {
1930     hal_btcoex_btble_status_stru *status = OSAL_NULL;
1931     osal_u32 abort_start = 0;
1932     osal_u32 abort_done = 0;
1933     osal_u32 abort_end = 0;
1934     status = hal_btcoex_btble_status();
1935 
1936     wifi_printf("btcoex info:\r\n");
1937     wifi_printf("  sw_preempt_type=%u, ps_stop=%u, ps_pause=%u, pri_forbit=%u\r\n",
1938         hal_device->btcoex_sw_preempt.sw_preempt_type, hal_device->btcoex_sw_preempt.ps_stop,
1939         hal_device->btcoex_sw_preempt.ps_pause, hal_device->btcoex_sw_preempt.coex_pri_forbit);
1940 
1941     wifi_printf("  bt_status=0x%04x, ble_status=0x%04x\r\n",
1942         status->bt_status.bt_status_reg,
1943         status->ble_status.ble_status_reg);
1944 
1945     wifi_printf("  ps_on_cnt=%u ps_off_cnt=%u, ps_timeout_cnt=%u\r\n",
1946         hal_device->btcoex_sw_preempt.ps_on_cnt,
1947         hal_device->btcoex_sw_preempt.ps_off_cnt,
1948         hal_device->btcoex_sw_preempt.ps_timeout_cnt);
1949 
1950     hal_btcoex_get_abort_cnt(&hal_chip->hal_chip_base, &abort_start, &abort_done, &abort_end);
1951     wifi_printf("  abort_start=%u abort_done=%u, abort_end=%u\r\n",
1952         abort_start, abort_done, abort_end);
1953 }
1954 #endif
1955 /*****************************************************************************
1956  函 数 名  : hmac_btcoex_set_dump
1957  功能描述  : BTCOEX设置device日志打印
1958 *****************************************************************************/
hmac_btcoex_set_dump(hal_to_dmac_device_stru * hal_device,osal_u8 flag)1959 OSAL_STATIC osal_void hmac_btcoex_set_dump(hal_to_dmac_device_stru *hal_device, osal_u8 flag)
1960 {
1961     osal_s32 ret;
1962     frw_msg msg = {0};
1963 
1964     unref_param(hal_device);
1965 
1966     frw_msg_init((osal_u8 *)&flag, sizeof(flag), OSAL_NULL, 0, &msg);
1967     ret = frw_send_msg_to_device(0, WLAN_MSG_H2D_C_CFG_SET_BTCOEX_DUMP, &msg, OSAL_TRUE);
1968     if (ret != OAL_SUCC) {
1969         oam_error_log2(0, OAM_SF_COEX, "{hmac_btcoex_set_dump send msg fail, flag=%u ret=%d}",
1970             flag, ret);
1971     }
1972     return;
1973 }
1974 
hmac_ccpriv_btcoex_info(hmac_vap_stru * hmac_vap,const osal_s8 * param)1975 OSAL_STATIC osal_s32 hmac_ccpriv_btcoex_info(hmac_vap_stru *hmac_vap, const osal_s8 *param)
1976 {
1977     osal_s8 ac_name[CCPRIV_CMD_NAME_MAX_LEN] = {0};
1978     osal_s32 ret;
1979     osal_char *end = OSAL_NULL;
1980     osal_u8 dump_flag = 0;
1981     osal_u64 value;
1982 #ifdef _PRE_WIFI_PRINTK
1983     hal_chip_stru *hal_chip = hal_get_chip_stru();
1984 #endif
1985     ret = hmac_ccpriv_get_one_arg(&param, ac_name, OAL_SIZEOF(ac_name));
1986     if (ret != OAL_SUCC) {
1987         oam_warning_log1(0, OAM_SF_COEX, "{hmac_ccpriv_btcoex_info::wal_get_cmd_one_arg err [%d]!}", ret);
1988         return ret;
1989     }
1990     value = (osal_u64)osal_strtol((const char *)ac_name, &end, 16);
1991     dump_flag = *(osal_u8 *)&value; /* 16进制参数解析 */
1992 
1993     /* 函数入参本身非空消息机制已检查 */
1994     if (hmac_vap == OSAL_NULL || hmac_vap->hal_device == OSAL_NULL) {
1995         oam_warning_log0(0, OAM_SF_CFG, "{hmac_ccpriv_btcoex_info:msg is null}");
1996         return OAL_ERR_CODE_PTR_NULL;
1997     }
1998 #ifdef _PRE_WIFI_PRINTK
1999     hmac_btcoex_status_info_dump(hmac_vap->hal_device, hal_chip);
2000 #endif
2001     hmac_btcoex_set_dump(hmac_vap->hal_device, dump_flag);
2002 
2003     return OAL_SUCC;
2004 }
2005 #endif
2006 
hmac_btcoex_hal_wifi_busy_notify(osal_u32 tx_throughput_mbps,osal_u32 rx_throughput_mbps)2007 OSAL_STATIC osal_void hmac_btcoex_hal_wifi_busy_notify(osal_u32 tx_throughput_mbps, osal_u32 rx_throughput_mbps)
2008 {
2009     osal_u8 wlan_busy;
2010     osal_u32 throughput_mbps;
2011     osal_u32 tx_avg_throughput;
2012     osal_u32 rx_avg_throughput;
2013     osal_u8 coex_wifi_status = hmac_get_g_btcoex_wlan_busy_status();
2014     static osal_u8 btcoex_stat_flag = OSAL_FALSE;
2015     static hmac_btcoex_throughput_stru btcoex_throughput = {0};
2016 
2017     if (btcoex_stat_flag == OSAL_FALSE) {
2018         btcoex_throughput.tx_throughput = (osal_u16)tx_throughput_mbps;
2019         btcoex_throughput.rx_throughput = (osal_u16)rx_throughput_mbps;
2020         btcoex_stat_flag = OSAL_TRUE;
2021         return;
2022     }
2023 
2024     tx_avg_throughput = (tx_throughput_mbps + btcoex_throughput.tx_throughput) / 2; /* 2,计算tx吞吐量平均值 */
2025     rx_avg_throughput = (rx_throughput_mbps + btcoex_throughput.rx_throughput) / 2; /* 2,计算rx吞吐量平均值 */
2026     throughput_mbps = tx_avg_throughput + rx_avg_throughput;
2027     btcoex_stat_flag = OSAL_FALSE;
2028     /* 20,如果吞吐量大于20mb/s,通知蓝牙调整优先级策略 */
2029     if (throughput_mbps > 20) {
2030         wlan_busy = OSAL_TRUE;
2031     } else if (throughput_mbps < 15) { /* 如果的吞吐量小于15mb/s,通知蓝牙调整优先级策略 */
2032         wlan_busy = OSAL_FALSE;
2033     } else {
2034         return;
2035     }
2036 
2037     if (coex_wifi_status == wlan_busy) {
2038         return;
2039     }
2040 
2041     hal_set_btcoex_wifi_status_notify(HAL_BTCOEX_WIFI_BUSY_STATUS, wlan_busy);
2042     hmac_set_g_btcoex_wlan_busy_status(wlan_busy);
2043     hal_coex_sw_irq_set(OSAL_TRUE);
2044     return;
2045 }
2046 
2047 #ifdef _PRE_WLAN_FEATURE_EXT_BTCOEX
hmac_get_btcoex_mode_cfg(const osal_s8 * param,hmac_extcoex_mode_stru * extcoex_cfg)2048 OSAL_STATIC osal_s32 hmac_get_btcoex_mode_cfg(const osal_s8 *param, hmac_extcoex_mode_stru *extcoex_cfg)
2049 {
2050     osal_s32 ret;
2051     osal_s32 value;
2052 
2053     ret = hmac_ccpriv_get_digit_with_range(&param, HMAC_EXTCOEX_2A, HMAC_EXTCOEX_4, &value);
2054     if (ret != OAL_SUCC) {
2055         oam_warning_log1(0, OAM_SF_COEX, "{hmac_get_btcoex_mode_cfg::get ext_coex_mode err [%d]!}", ret);
2056         return ret;
2057     }
2058     extcoex_cfg->extcoex_wire_mode = (osal_u8)value;
2059 
2060     ret = hmac_ccpriv_get_digit_with_range(&param, HMAC_EXTCOEX_WIFI_BT, HMAC_EXTCOEX_WIFI_BSLE_BT, &value);
2061     if (ret != OAL_SUCC) {
2062         oam_warning_log1(0, OAM_SF_COEX, "{hmac_get_btcoex_mode_cfg::get ext_coex_mode err [%d]!}", ret);
2063         return ret;
2064     }
2065     extcoex_cfg->extcoex_mode = (osal_u8)value;
2066 
2067     ret = hmac_ccpriv_get_digit_with_range(&param, OSAL_FALSE, OSAL_TRUE, &value);
2068     if (ret != OAL_SUCC) {
2069         oam_warning_log1(0, OAM_SF_COEX, "{hmac_get_btcoex_mode_cfg::get ext_coex_mode err [%d]!}", ret);
2070         return ret;
2071     }
2072     extcoex_cfg->share_ant = (osal_u8)value;
2073 
2074     ret = hmac_ccpriv_get_digit_with_range(&param, OSAL_FALSE, OSAL_TRUE, &value);
2075     if (ret != OAL_SUCC) {
2076         oam_warning_log1(0, OAM_SF_COEX, "{hmac_get_btcoex_mode_cfg::get ext_coex_mode err [%d]!}", ret);
2077         return ret;
2078     }
2079     extcoex_cfg->preempt_enable = (osal_u8)value;
2080 
2081     return OAL_SUCC;
2082 }
2083 
hmac_extcoex_off(hmac_vap_btcoex_stru * hmac_vap_btcoex)2084 OSAL_STATIC osal_void hmac_extcoex_off(hmac_vap_btcoex_stru *hmac_vap_btcoex)
2085 {
2086     hmac_vap_btcoex->all_abort_preempt_type = HAL_BTCOEX_HW_POWSAVE_NOFRAME;
2087     hal_set_extcoex_off();
2088     hal_dev_sync_extcoex_status_to_dev(OSAL_FALSE);
2089     return;
2090 }
2091 
hmac_extcoex_on(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,hmac_vap_btcoex_stru * hmac_vap_btcoex,hmac_extcoex_mode_stru extcoex_cfg,osal_u8 assoc_state)2092 OSAL_STATIC osal_void hmac_extcoex_on(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
2093     hmac_vap_btcoex_stru *hmac_vap_btcoex, hmac_extcoex_mode_stru extcoex_cfg, osal_u8 assoc_state)
2094 {
2095     hal_extcoex_common_init(extcoex_cfg.preempt_enable);
2096     hal_extcoex_mode_init(extcoex_cfg.extcoex_wire_mode, extcoex_cfg.extcoex_mode, extcoex_cfg.share_ant);
2097     if (assoc_state == OSAL_TRUE) {
2098         hmac_btcoex_init_preempt(hmac_vap, hmac_user, extcoex_cfg.preempt_enable);
2099         hal_set_extcoex_preemp(extcoex_cfg.preempt_enable); /* 使能preempt */
2100     } else {
2101         hmac_vap_btcoex->all_abort_preempt_type = HAL_BTCOEX_HW_POWSAVE_NOFRAME;
2102         hal_set_extcoex_preemp(0x0); /* 不使能preempt */
2103     }
2104     hal_set_extcoex_gpio();
2105     hal_dev_sync_extcoex_status_to_dev(OSAL_TRUE);
2106     return;
2107 }
2108 
2109 /*****************************************************************************
2110  函 数 名  : hmac_ccpriv_btcoex_mode_config
2111  功能描述  : 设置外部共存使能,模式,共天线,preempt
2112 *****************************************************************************/
hmac_ccpriv_btcoex_mode_config(hmac_vap_stru * hmac_vap,const osal_s8 * param)2113 OSAL_STATIC osal_s32 hmac_ccpriv_btcoex_mode_config(hmac_vap_stru *hmac_vap, const osal_s8 *param)
2114 {
2115     hmac_user_stru *hmac_user = OAL_PTR_NULL;
2116     hmac_vap_btcoex_stru *hmac_vap_btcoex = OAL_PTR_NULL;
2117     osal_u8 assoc_state = OSAL_TRUE;
2118     hmac_extcoex_mode_stru extcoex_cfg;
2119     osal_u32 value;
2120     osal_s32 ret;
2121 
2122     if (hmac_vap == OSAL_NULL) {
2123         oam_warning_log0(0, OAM_SF_CFG, "{hmac_ccpriv_btcoex_mode_config:vap is null}");
2124         return OAL_ERR_CODE_PTR_NULL;
2125     }
2126 
2127     hmac_vap_btcoex = hmac_btcoex_get_vap_info(hmac_vap);
2128     if (hmac_vap_btcoex == OSAL_NULL) {
2129         oam_warning_log0(0, OAM_SF_CFG, "{hmac_ccpriv_btcoex_mode_config:vap info is null}");
2130         return OAL_ERR_CODE_PTR_NULL;
2131     }
2132 
2133     if (is_legacy_ap(hmac_vap)) {
2134         assoc_state = OSAL_FALSE;
2135     } else {
2136         hmac_user = (hmac_user_stru *)mac_res_get_hmac_user_etc(hmac_vap->assoc_vap_id);
2137         if (hmac_user == OAL_PTR_NULL || hmac_user->user_asoc_state != MAC_USER_STATE_ASSOC) {
2138             assoc_state = OSAL_FALSE;
2139         }
2140     }
2141 
2142     ret = hmac_ccpriv_get_digit_with_range(&param, HMAC_EXTCOEX_OFF, HMAC_EXTCOEX_ON, (osal_s32 *)&value);
2143     if (ret != OAL_SUCC) {
2144         oam_warning_log1(0, OAM_SF_COEX, "{hmac_ccpriv_btcoex_mode_config::get coex enable err [%d]!}", ret);
2145         return ret;
2146     }
2147 
2148     if (value == HMAC_EXTCOEX_OFF) {
2149         hmac_extcoex_off(hmac_vap_btcoex);
2150         return OAL_SUCC;
2151     }
2152     extcoex_cfg.eanble = (osal_u8)value;
2153 
2154     ret = hmac_get_btcoex_mode_cfg(param, &extcoex_cfg);
2155     if (ret != OAL_SUCC) {
2156         oam_error_log1(0, OAM_SF_COEX, "{hmac_ccpriv_btcoex_mode_config::get_extcoex_mode_cfg fail [%d]!}", ret);
2157         return ret;
2158     }
2159 
2160     hmac_extcoex_on(hmac_vap, hmac_user, hmac_vap_btcoex, extcoex_cfg, assoc_state);
2161     return OAL_SUCC;
2162 }
2163 
2164 /*****************************************************************************
2165  函 数 名  : hmac_ccpriv_btcoex_timer_config
2166  功能描述  : 设置外部共存timer提前量
2167 *****************************************************************************/
hmac_ccpriv_btcoex_timer_config(hmac_vap_stru * hmac_vap,const osal_s8 * param)2168 OSAL_STATIC osal_s32 hmac_ccpriv_btcoex_timer_config(hmac_vap_stru *hmac_vap, const osal_s8 *param)
2169 {
2170     osal_s32 t1_timer;
2171     osal_s32 t2_timer;
2172     osal_s32 ret;
2173 
2174     if (hmac_vap == OSAL_NULL) {
2175         oam_warning_log0(0, OAM_SF_CFG, "{hmac_ccpriv_btcoex_timer_config:vap is null}");
2176         return OAL_ERR_CODE_PTR_NULL;
2177     }
2178 
2179     ret = hmac_ccpriv_get_digit_with_range(&param, T1_TIMER_MIN, T1_TIMER_MAX, &t1_timer);
2180     if (ret != OAL_SUCC) {
2181         oam_warning_log1(0, OAM_SF_COEX, "{hmac_ccpriv_btcoex_timer_config::get t1_timer err [%d]!}", ret);
2182         return ret;
2183     }
2184 
2185     ret = hmac_ccpriv_get_digit_with_range(&param, T2_TIMER_MIN, T2_TIMER_MAX, &t2_timer);
2186     if (ret != OAL_SUCC) {
2187         oam_warning_log1(0, OAM_SF_COEX, "{hmac_ccpriv_btcoex_timer_config::get t2_timer err [%d]!}", ret);
2188         return ret;
2189     }
2190 
2191     hal_set_g_extcoex_timer(HMAC_EXTCOEX_T1_TIMER, (osal_u8)t1_timer);
2192     hal_set_g_extcoex_timer(HMAC_EXTCOEX_T2_TIMER, (osal_u8)t2_timer);
2193     hal_set_g_extcoex_timer(HMAC_EXTCOEX_T4_TIMER, (osal_u8)(t1_timer - TIMER_GAP));
2194     hal_set_extcoex_timer((osal_u16)t1_timer, (osal_u16)t2_timer, (osal_u16)(t1_timer - TIMER_GAP));
2195 
2196     return OAL_SUCC;
2197 }
2198 
2199 /*****************************************************************************
2200  函 数 名  : hmac_ccpriv_btcoex_coex_switch_config
2201  功能描述  : 设置外部共存coex_switch电平控制位,1,高电平有效,0,低电平有效
2202 *****************************************************************************/
hmac_ccpriv_btcoex_coex_switch_config(hmac_vap_stru * hmac_vap,const osal_s8 * param)2203 OSAL_STATIC osal_s32 hmac_ccpriv_btcoex_coex_switch_config(hmac_vap_stru *hmac_vap, const osal_s8 *param)
2204 {
2205     osal_s32 coex_switch;
2206     osal_s32 ret;
2207 
2208     if (hmac_vap == OSAL_NULL) {
2209         oam_warning_log0(0, OAM_SF_CFG, "{hmac_ccpriv_btcoex_coex_switch_config:vap is null}");
2210         return OAL_ERR_CODE_PTR_NULL;
2211     }
2212 
2213     ret = hmac_ccpriv_get_digit_with_range(&param, COEX_SWITCH_LEVEL_HIGH, COEX_SWITCH_LEVEL_LOW, &coex_switch);
2214     if (ret != OAL_SUCC) {
2215         oam_warning_log1(0, OAM_SF_COEX, "{hmac_ccpriv_btcoex_coex_switch_config::get coex enable err [%d]!}", ret);
2216         return ret;
2217     }
2218     hal_set_extcoex_switch_config((osal_u16)coex_switch);
2219 
2220     return OAL_SUCC;
2221 }
2222 #endif
2223 
hmac_btcoex_feature_hook_register(osal_void)2224 OSAL_STATIC osal_void hmac_btcoex_feature_hook_register(osal_void)
2225 {
2226     /* 对外接口注册 */
2227     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_RECOVER_COEX_PRIORITY, hmac_btcoex_recover_coex_priority);
2228     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_RECOVER_COEX_PRIORITY_CLEAR, hmac_btcoex_recover_coex_priority_clear);
2229     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_RX_PROCESS_ECT, hmac_btcoex_rx_process_ect);
2230     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_SET_WLAN_PRIORITY, hmac_btcoex_set_wlan_priority);
2231     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_UPDATE_THRESHOLD, hmac_btcoex_linkloss_update_threshold);
2232     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_LINKLOSS_OCCUPIED, hmac_btcoex_linkloss_occupied_process);
2233     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_ASSOC_STATE_SYN, hmac_config_btcoex_assoc_state_syn);
2234     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_ROAM_SUCC_HANDLER, hmac_btcoex_roam_succ_handler);
2235     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_CHECK_IN_LIST, hmac_btcoex_check_exception_in_list);
2236     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_PROC_USER_ADD, hmac_btcoex_proc_user_add);
2237     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_PROC_VAP_ADD, hmac_btcoex_proc_vap_add);
2238     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_TX_MGMT_FRAME, hmac_btcoex_tx_mgmt_frame);
2239     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_TX_VIP_FRAME, hmac_btcoex_tx_vip_frame);
2240     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_USER_SPATIAL_STREAM_CHANGE,
2241         hmac_btcoex_user_spatial_stream_change_notify);
2242     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_CHECK_RX_SAME_BAW_START_FROM_ADDBA_REQ,
2243         hmac_btcoex_check_rx_same_baw_start_from_addba_req_etc);
2244     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_SET_TXOP_ALG, hmac_btcoex_set_txop_alg);
2245     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_UPDATE_BSS_LIST_PROTOCOL, hmac_btcoex_update_bss_list_protocol);
2246     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_CHECK_AP_TYPE_BLACKLIST, hmac_btcoex_check_ap_type_blacklist);
2247     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_CLEAR_ARP_TIMER, hmac_btcoex_clear_arp_timer);
2248     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_KEEPALIVE_TIMER_ECT, hmac_btcoex_keepalive_timer_ect);
2249     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_COMPATIBILITY_SET_PS_TYPE, hmac_btcoex_compatibility_set_ps_type);
2250     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_COMPATIBILITY_SET_AP_TYPE, hmac_btcoex_compatibility_set_ap_type);
2251     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_VAP_RESUME_TX_BY_CHL, hmac_btcoex_vap_resume_tx_by_chl);
2252     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_VAP_CONFIG_SW_PREEMPT_SUBTYPE,
2253         hmac_btcoex_vap_config_sw_preempt_subtype);
2254     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_DEVICE_EXIT_DESTROY_TIMER, hmac_btcoex_device_exit_destroy_timer);
2255     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_REPORT_LINKLOSS_INFO, hmac_btcoex_report_linkloss_info);
2256     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_SW_PREEMPT_TYPE_CHECK, hmac_btcoex_sw_preempt_type_check);
2257 
2258     /* 一些调用hal层函数的对外接口 */
2259     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_GET_BTSTATUS_BTON, hmac_btcoex_hal_get_btstatus_bton);
2260     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_LINKLOSS_CLEAN, hmac_btcoex_hal_blinkloss_clean);
2261     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_CHECK_USER_REQ_DECLINED, hmac_btcoex_check_user_req_declined);
2262     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_CHECK_SET_AGING_TIME, hmac_btcoex_hal_set_aging_time);
2263     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_CHECK_SW_PREEMPT_TYPE, hmac_btcoex_check_sw_preempt_type);
2264     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_SET_BTCOEX_WIFI_STATUS, hmac_btcoex_hal_set_btcoex_wifi_status);
2265     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_END_SCAN_CHECK_PS, hmac_btcoex_hal_end_scan_check_ps);
2266     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_USER_ADD_HANDLE, hmac_btcoex_hal_user_add_handle);
2267     hmac_feature_hook_register(HMAC_FHOOK_BTCOEX_HAL_WIFI_BUSY_NOTIFY, hmac_btcoex_hal_wifi_busy_notify);
2268 }
2269 
hmac_btcoex_init_ect(osal_void)2270 OSAL_STATIC osal_u32 hmac_btcoex_init_ect(osal_void)
2271 {
2272     osal_u32 ret = OAL_SUCC;
2273     /* notify注册 */
2274     frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_DEL_USER_FEATURE, hmac_btcoex_proc_user_del);
2275     frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_DEL_VAP_FEATURE, hmac_btcoex_proc_vap_del);
2276     frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_TBTT_AP, hmac_btcoex_beacon_occupied_handler);
2277     frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_LINKLOSS_INIT, hmac_btcoex_linkloss_init);
2278     frw_util_notifier_register(WLAN_UTIL_NOTIFIER_EVENT_START_VAP_EXIT, hmac_btcoex_vap_up_handle);
2279     /* 对外接口注册 */
2280     hmac_btcoex_feature_hook_register();
2281     /* 消息接口注册 */
2282     ret |= (osal_u32)frw_msg_hook_register(WLAN_MSG_D2H_BT_STATUS_CHANGE, hmac_btcoex_status_change_handler);
2283     ret |= (osal_u32)frw_msg_hook_register(WLAN_MSG_D2H_MISS_BEACON, hmac_btcoex_beacon_miss_handler);
2284     ret |= (osal_u32)frw_msg_hook_register(WLAN_MSG_D2H_BT_ABORT_END, hmac_btcoex_abort_end_time);
2285 #ifdef _PRE_WLAN_SUPPORT_CCPRIV_CMD
2286     /* ccpriv命令注册 */
2287     hmac_ccpriv_register((const osal_s8 *)"btcoex_info", hmac_ccpriv_btcoex_info);
2288 #endif
2289 #ifdef _PRE_WLAN_FEATURE_EXT_BTCOEX
2290     hmac_ccpriv_register((const osal_s8 *)"btcoex_mode", hmac_ccpriv_btcoex_mode_config);
2291     hmac_ccpriv_register((const osal_s8 *)"btcoex_timer", hmac_ccpriv_btcoex_timer_config);
2292     hmac_ccpriv_register((const osal_s8 *)"btcoex_coex_switch", hmac_ccpriv_btcoex_coex_switch_config);
2293 #endif
2294     /* 结构体初始化 */
2295     ret |= hmac_btcoex_proc_device_add();
2296     if (ret != OAL_SUCC) {
2297         wifi_printf("hmac_btcoex_init_etc:: MGMT RX IN register_netbuf_hooks error\r\n");
2298     }
2299     return ret;
2300 }
2301 
hmac_btcoex_feature_hook_unregister(osal_void)2302 OSAL_STATIC osal_void hmac_btcoex_feature_hook_unregister(osal_void)
2303 {
2304     /* 对外接口去注册 */
2305     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_RECOVER_COEX_PRIORITY);
2306     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_RECOVER_COEX_PRIORITY_CLEAR);
2307     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_RX_PROCESS_ECT);
2308     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_SET_WLAN_PRIORITY);
2309     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_UPDATE_THRESHOLD);
2310     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_LINKLOSS_OCCUPIED);
2311     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_ASSOC_STATE_SYN);
2312     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_ROAM_SUCC_HANDLER);
2313     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_CHECK_IN_LIST);
2314     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_PROC_USER_ADD);
2315     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_PROC_VAP_ADD);
2316     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_TX_MGMT_FRAME);
2317     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_TX_VIP_FRAME);
2318     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_USER_SPATIAL_STREAM_CHANGE);
2319     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_CHECK_RX_SAME_BAW_START_FROM_ADDBA_REQ);
2320     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_SET_TXOP_ALG);
2321     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_UPDATE_BSS_LIST_PROTOCOL);
2322     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_CHECK_AP_TYPE_BLACKLIST);
2323     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_CLEAR_ARP_TIMER);
2324     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_KEEPALIVE_TIMER_ECT);
2325     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_COMPATIBILITY_SET_PS_TYPE);
2326     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_COMPATIBILITY_SET_AP_TYPE);
2327     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_VAP_RESUME_TX_BY_CHL);
2328     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_VAP_CONFIG_SW_PREEMPT_SUBTYPE);
2329     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_DEVICE_EXIT_DESTROY_TIMER);
2330     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_REPORT_LINKLOSS_INFO);
2331     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_SW_PREEMPT_TYPE_CHECK);
2332     /* 一些调用hal层函数的对外接口 */
2333     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_GET_BTSTATUS_BTON);
2334     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_LINKLOSS_CLEAN);
2335     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_CHECK_USER_REQ_DECLINED);
2336     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_CHECK_SET_AGING_TIME);
2337     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_CHECK_SW_PREEMPT_TYPE);
2338     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_SET_BTCOEX_WIFI_STATUS);
2339     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_END_SCAN_CHECK_PS);
2340     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_USER_ADD_HANDLE);
2341     hmac_feature_hook_unregister(HMAC_FHOOK_BTCOEX_HAL_WIFI_BUSY_NOTIFY);
2342 }
2343 
hmac_btcoex_deinit_ect(osal_void)2344 OSAL_STATIC osal_void hmac_btcoex_deinit_ect(osal_void)
2345 {
2346     /* notify去注册 */
2347     frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_DEL_USER_FEATURE, hmac_btcoex_proc_user_del);
2348     frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_DEL_VAP_FEATURE, hmac_btcoex_proc_vap_del);
2349     frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_TBTT_AP, hmac_btcoex_beacon_occupied_handler);
2350     frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_LINKLOSS_INIT, hmac_btcoex_linkloss_init);
2351     frw_util_notifier_unregister(WLAN_UTIL_NOTIFIER_EVENT_START_VAP_EXIT, hmac_btcoex_vap_up_handle);
2352     /* 对外接口去注册 */
2353     hmac_btcoex_feature_hook_unregister();
2354 #ifdef _PRE_WLAN_SUPPORT_CCPRIV_CMD
2355     /* ccpriv命令去注册 */
2356     hmac_ccpriv_unregister((const osal_s8 *)"btcoex_info");
2357 #endif
2358 #ifdef _PRE_WLAN_FEATURE_EXT_BTCOEX
2359     hmac_ccpriv_unregister((const osal_s8 *)"btcoex_mode");
2360     hmac_ccpriv_unregister((const osal_s8 *)"btcoex_timer");
2361     hmac_ccpriv_unregister((const osal_s8 *)"btcoex_coex_switch");
2362 #endif
2363     /* 结构体销毁 */
2364     hmac_btcoex_proc_device_del();
2365     return;
2366 }
2367 
hmac_btcoex_init(osal_void)2368 osal_u32 hmac_btcoex_init(osal_void)
2369 {
2370     osal_u32 ret = OAL_SUCC;
2371     ret |= hmac_btcoex_init_ect();
2372     ret |= hmac_btcoex_ba_init();
2373     ret |= hmac_btcoex_m2s_init();
2374     ret |= hmac_btcoex_notify_init();
2375     ret |= hmac_btcoex_ps_init();
2376     if (ret != OAL_SUCC) {
2377         wifi_printf("hmac_btcoex_init:: MGMT RX IN register_netbuf_hooks error\r\n");
2378     }
2379     return ret;
2380 }
2381 
hmac_btcoex_deinit(osal_void)2382 osal_void hmac_btcoex_deinit(osal_void)
2383 {
2384     hmac_btcoex_deinit_ect();
2385     hmac_btcoex_ba_deinit();
2386     hmac_btcoex_m2s_deinit();
2387     hmac_btcoex_notify_deinit();
2388     hmac_btcoex_ps_deinit();
2389 }
2390 
2391 #ifdef __cplusplus
2392 #if __cplusplus
2393 }
2394 #endif
2395 #endif
2396 
2397 #endif /* end of __HMAC_BTCOEX_C__ */
2398 
2399