1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #include "../include/osdep_service.h"
5 #include "../include/drv_types.h"
6
7 #include "../include/hal_intf.h"
8 #include "../include/hal_com.h"
9 #include "../include/rtl8188e_hal.h"
10
11 #define _HAL_INIT_C_
12
13 #define CHAN_PLAN_HW 0x80
14
15 u8 /* return the final channel plan decision */
hal_com_get_channel_plan(struct adapter * padapter,u8 hw_channel_plan,u8 sw_channel_plan,u8 def_channel_plan,bool load_fail)16 hal_com_get_channel_plan(struct adapter *padapter, u8 hw_channel_plan,
17 u8 sw_channel_plan, u8 def_channel_plan,
18 bool load_fail)
19 {
20 u8 sw_cfg;
21 u8 chnlplan;
22
23 sw_cfg = true;
24 if (!load_fail) {
25 if (!rtw_is_channel_plan_valid(sw_channel_plan))
26 sw_cfg = false;
27 if (hw_channel_plan & CHAN_PLAN_HW)
28 sw_cfg = false;
29 }
30
31 if (sw_cfg)
32 chnlplan = sw_channel_plan;
33 else
34 chnlplan = hw_channel_plan & (~CHAN_PLAN_HW);
35
36 if (!rtw_is_channel_plan_valid(chnlplan))
37 chnlplan = def_channel_plan;
38
39 return chnlplan;
40 }
41
MRateToHwRate(u8 rate)42 u8 MRateToHwRate(u8 rate)
43 {
44 u8 ret = DESC_RATE1M;
45
46 switch (rate) {
47 /* CCK and OFDM non-HT rates */
48 case IEEE80211_CCK_RATE_1MB:
49 ret = DESC_RATE1M;
50 break;
51 case IEEE80211_CCK_RATE_2MB:
52 ret = DESC_RATE2M;
53 break;
54 case IEEE80211_CCK_RATE_5MB:
55 ret = DESC_RATE5_5M;
56 break;
57 case IEEE80211_CCK_RATE_11MB:
58 ret = DESC_RATE11M;
59 break;
60 case IEEE80211_OFDM_RATE_6MB:
61 ret = DESC_RATE6M;
62 break;
63 case IEEE80211_OFDM_RATE_9MB:
64 ret = DESC_RATE9M;
65 break;
66 case IEEE80211_OFDM_RATE_12MB:
67 ret = DESC_RATE12M;
68 break;
69 case IEEE80211_OFDM_RATE_18MB:
70 ret = DESC_RATE18M;
71 break;
72 case IEEE80211_OFDM_RATE_24MB:
73 ret = DESC_RATE24M;
74 break;
75 case IEEE80211_OFDM_RATE_36MB:
76 ret = DESC_RATE36M;
77 break;
78 case IEEE80211_OFDM_RATE_48MB:
79 ret = DESC_RATE48M;
80 break;
81 case IEEE80211_OFDM_RATE_54MB:
82 ret = DESC_RATE54M;
83 break;
84 default:
85 break;
86 }
87 return ret;
88 }
89
HalSetBrateCfg(struct adapter * adapt,u8 * brates,u16 * rate_cfg)90 void HalSetBrateCfg(struct adapter *adapt, u8 *brates, u16 *rate_cfg)
91 {
92 u8 i, is_brate, brate;
93
94 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
95 is_brate = brates[i] & IEEE80211_BASIC_RATE_MASK;
96 brate = brates[i] & 0x7f;
97
98 if (is_brate) {
99 switch (brate) {
100 case IEEE80211_CCK_RATE_1MB:
101 *rate_cfg |= RATE_1M;
102 break;
103 case IEEE80211_CCK_RATE_2MB:
104 *rate_cfg |= RATE_2M;
105 break;
106 case IEEE80211_CCK_RATE_5MB:
107 *rate_cfg |= RATE_5_5M;
108 break;
109 case IEEE80211_CCK_RATE_11MB:
110 *rate_cfg |= RATE_11M;
111 break;
112 case IEEE80211_OFDM_RATE_6MB:
113 *rate_cfg |= RATE_6M;
114 break;
115 case IEEE80211_OFDM_RATE_9MB:
116 *rate_cfg |= RATE_9M;
117 break;
118 case IEEE80211_OFDM_RATE_12MB:
119 *rate_cfg |= RATE_12M;
120 break;
121 case IEEE80211_OFDM_RATE_18MB:
122 *rate_cfg |= RATE_18M;
123 break;
124 case IEEE80211_OFDM_RATE_24MB:
125 *rate_cfg |= RATE_24M;
126 break;
127 case IEEE80211_OFDM_RATE_36MB:
128 *rate_cfg |= RATE_36M;
129 break;
130 case IEEE80211_OFDM_RATE_48MB:
131 *rate_cfg |= RATE_48M;
132 break;
133 case IEEE80211_OFDM_RATE_54MB:
134 *rate_cfg |= RATE_54M;
135 break;
136 }
137 }
138 }
139 }
140