Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/os_dep/linux/wifi_regd.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2009-2010 - 2017 Realtek Corporation.
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of version 2 of the GNU General Public License as
7
* published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
*****************************************************************************/
15
16
#include <drv_types.h>
17
18
#ifdef CONFIG_IOCTL_CFG80211
19
20
#include <rtw_wifi_regd.h>
21
22
/*
23
*Only these channels all allow active
24
*scan on all world regulatory domains
25
*/
26
27
/* 2G chan 01 - chan 11 */
28
#define RTW_2GHZ_CH01_11 \
29
REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
30
31
/*
32
*We enable active scan on these a case
33
*by case basis by regulatory domain
34
*/
35
36
/* 2G chan 12 - chan 13, PASSIV SCAN */
37
#define RTW_2GHZ_CH12_13 \
38
REG_RULE(2467-10, 2472+10, 40, 0, 20, \
39
NL80211_RRF_PASSIVE_SCAN)
40
41
/* 5G chan 36 - chan 165 */
42
#define RTW_5GHZ_5150_5850 \
43
REG_RULE(5150-10, 5850+10, 40, 0, 30, \
44
NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
45
46
static const struct ieee80211_regdomain rtw_regdom_rd = {
47
.n_reg_rules = 3,
48
.alpha2 = "99",
49
.reg_rules = {
50
RTW_2GHZ_CH01_11,
51
RTW_2GHZ_CH12_13,
52
RTW_5GHZ_5150_5850,
53
}
54
};
55
56
#if 0
57
/*
58
* REG_RULE(freq start, freq end, bandwidth, max gain, eirp, reg_flags)
59
*/
60
61
static struct country_code_to_enum_rd allCountries[] = {
62
{COUNTRY_CODE_USER, "RD"},
63
};
64
65
/* 2G chan 14, PASSIVS SCAN, NO OFDM (B only) */
66
#define RTW_2GHZ_CH14 \
67
REG_RULE(2484-10, 2484+10, 40, 0, 20, \
68
NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
69
70
/* 5G chan 36 - chan 64 */
71
#define RTW_5GHZ_5150_5350 \
72
REG_RULE(5150-10, 5350+10, 40, 0, 30, \
73
NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
74
75
/* 5G chan 100 - chan 165 */
76
#define RTW_5GHZ_5470_5850 \
77
REG_RULE(5470-10, 5850+10, 40, 0, 30, \
78
NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
79
80
/* 5G chan 149 - chan 165 */
81
#define RTW_5GHZ_5725_5850 \
82
REG_RULE(5725-10, 5850+10, 40, 0, 30, \
83
NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
84
85
86
static const struct ieee80211_regdomain rtw_regdom_11 = {
87
.n_reg_rules = 1,
88
.alpha2 = "99",
89
.reg_rules = {
90
RTW_2GHZ_CH01_11,
91
}
92
};
93
94
static const struct ieee80211_regdomain rtw_regdom_12_13 = {
95
.n_reg_rules = 2,
96
.alpha2 = "99",
97
.reg_rules = {
98
RTW_2GHZ_CH01_11,
99
RTW_2GHZ_CH12_13,
100
}
101
};
102
103
static const struct ieee80211_regdomain rtw_regdom_no_midband = {
104
.n_reg_rules = 3,
105
.alpha2 = "99",
106
.reg_rules = {
107
RTW_2GHZ_CH01_11,
108
RTW_5GHZ_5150_5350,
109
RTW_5GHZ_5725_5850,
110
}
111
};
112
113
static const struct ieee80211_regdomain rtw_regdom_60_64 = {
114
.n_reg_rules = 3,
115
.alpha2 = "99",
116
.reg_rules = {
117
RTW_2GHZ_CH01_11,
118
RTW_2GHZ_CH12_13,
119
RTW_5GHZ_5725_5850,
120
}
121
};
122
123
static const struct ieee80211_regdomain rtw_regdom_14_60_64 = {
124
.n_reg_rules = 4,
125
.alpha2 = "99",
126
.reg_rules = {
127
RTW_2GHZ_CH01_11,
128
RTW_2GHZ_CH12_13,
129
RTW_2GHZ_CH14,
130
RTW_5GHZ_5725_5850,
131
}
132
};
133
134
static const struct ieee80211_regdomain rtw_regdom_14 = {
135
.n_reg_rules = 3,
136
.alpha2 = "99",
137
.reg_rules = {
138
RTW_2GHZ_CH01_11,
139
RTW_2GHZ_CH12_13,
140
RTW_2GHZ_CH14,
141
}
142
};
143
144
145
static struct rtw_regulatory *rtw_regd;
146
#endif
147
148
#if 0 /* not_yet */
149
static void _rtw_reg_apply_beaconing_flags(struct wiphy *wiphy,
150
enum nl80211_reg_initiator initiator)
151
{
152
enum nl80211_band band;
153
struct ieee80211_supported_band *sband;
154
const struct ieee80211_reg_rule *reg_rule;
155
struct ieee80211_channel *ch;
156
unsigned int i;
157
u32 bandwidth = 0;
158
int r;
159
160
for (band = 0; band < NUM_NL80211_BANDS; band++) {
161
162
if (!wiphy->bands[band])
163
continue;
164
165
sband = wiphy->bands[band];
166
167
for (i = 0; i < sband->n_channels; i++) {
168
ch = &sband->channels[i];
169
if (rtw_is_dfs_ch(ch->hw_value) ||
170
(ch->flags & IEEE80211_CHAN_RADAR))
171
continue;
172
if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
173
r = freq_reg_info(wiphy, ch->center_freq,
174
bandwidth, &reg_rule);
175
if (r)
176
continue;
177
178
/*
179
*If 11d had a rule for this channel ensure
180
*we enable adhoc/beaconing if it allows us to
181
*use it. Note that we would have disabled it
182
*by applying our static world regdomain by
183
*default during init, prior to calling our
184
*regulatory_hint().
185
*/
186
187
if (!(reg_rule->flags & NL80211_RRF_NO_IBSS))
188
ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
189
if (!
190
(reg_rule->flags &
191
NL80211_RRF_PASSIVE_SCAN))
192
ch->flags &=
193
~IEEE80211_CHAN_PASSIVE_SCAN;
194
} else {
195
if (ch->beacon_found)
196
ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
197
IEEE80211_CHAN_PASSIVE_SCAN);
198
}
199
}
200
}
201
}
202
203
/* Allows active scan scan on Ch 12 and 13 */
204
static void _rtw_reg_apply_active_scan_flags(struct wiphy *wiphy,
205
enum nl80211_reg_initiator
206
initiator)
207
{
208
struct ieee80211_supported_band *sband;
209
struct ieee80211_channel *ch;
210
const struct ieee80211_reg_rule *reg_rule;
211
u32 bandwidth = 0;
212
int r;
213
214
if (!wiphy->bands[NL80211_BAND_2GHZ])
215
return;
216
sband = wiphy->bands[NL80211_BAND_2GHZ];
217
218
/*
219
* If no country IE has been received always enable active scan
220
* on these channels. This is only done for specific regulatory SKUs
221
*/
222
if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
223
ch = &sband->channels[11]; /* CH 12 */
224
if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
225
ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
226
ch = &sband->channels[12]; /* CH 13 */
227
if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
228
ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
229
return;
230
}
231
232
/*
233
* If a country IE has been received check its rule for this
234
* channel first before enabling active scan. The passive scan
235
* would have been enforced by the initial processing of our
236
* custom regulatory domain.
237
*/
238
239
ch = &sband->channels[11]; /* CH 12 */
240
r = freq_reg_info(wiphy, ch->center_freq, bandwidth, &reg_rule);
241
if (!r) {
242
if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
243
if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
244
ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
245
}
246
247
ch = &sband->channels[12]; /* CH 13 */
248
r = freq_reg_info(wiphy, ch->center_freq, bandwidth, &reg_rule);
249
if (!r) {
250
if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
251
if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
252
ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
253
}
254
}
255
#endif
256
257
void rtw_regd_apply_flags(struct wiphy *wiphy)
258
{
259
struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
260
struct rf_ctl_t *rfctl = dvobj_to_rfctl(dvobj);
261
RT_CHANNEL_INFO *channel_set = rfctl->channel_set;
262
u8 max_chan_nums = rfctl->max_chan_nums;
263
264
struct ieee80211_supported_band *sband;
265
struct ieee80211_channel *ch;
266
unsigned int i, j;
267
u16 channel;
268
u32 freq;
269
270
/* all channels disable */
271
for (i = 0; i < NUM_NL80211_BANDS; i++) {
272
sband = wiphy->bands[i];
273
274
if (sband) {
275
for (j = 0; j < sband->n_channels; j++) {
276
ch = &sband->channels[j];
277
278
if (ch)
279
ch->flags = IEEE80211_CHAN_DISABLED;
280
}
281
}
282
}
283
284
/* channels apply by channel plans. */
285
for (i = 0; i < max_chan_nums; i++) {
286
channel = channel_set[i].ChannelNum;
287
freq = rtw_ch2freq(channel);
288
289
ch = ieee80211_get_channel(wiphy, freq);
290
if (!ch)
291
continue;
292
293
if (channel_set[i].ScanType == SCAN_PASSIVE
294
#if defined(CONFIG_DFS_MASTER)
295
&& rtw_odm_dfs_domain_unknown(dvobj)
296
#endif
297
) {
298
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
299
ch->flags = (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_PASSIVE_SCAN);
300
#else
301
ch->flags = IEEE80211_CHAN_NO_IR;
302
#endif
303
} else
304
ch->flags = 0;
305
306
#ifdef CONFIG_DFS
307
if (rtw_is_dfs_ch(ch->hw_value)
308
#if defined(CONFIG_DFS_MASTER)
309
&& rtw_odm_dfs_domain_unknown(dvobj)
310
#endif
311
) {
312
ch->flags |= IEEE80211_CHAN_RADAR;
313
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
314
ch->flags |= (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_PASSIVE_SCAN);
315
#else
316
ch->flags |= IEEE80211_CHAN_NO_IR;
317
#endif
318
}
319
#endif /* CONFIG_DFS */
320
}
321
}
322
323
static const struct ieee80211_regdomain *_rtw_regdomain_select(struct
324
rtw_regulatory
325
*reg)
326
{
327
#if 0
328
switch (reg->country_code) {
329
case COUNTRY_CODE_USER:
330
default:
331
return &rtw_regdom_rd;
332
}
333
#else
334
return &rtw_regdom_rd;
335
#endif
336
}
337
338
static void rtw_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
339
{
340
switch (request->initiator) {
341
case NL80211_REGDOM_SET_BY_DRIVER:
342
RTW_INFO("%s: %s\n", __func__, "NL80211_REGDOM_SET_BY_DRIVER");
343
break;
344
case NL80211_REGDOM_SET_BY_CORE:
345
RTW_INFO("%s: %s\n", __func__, "NL80211_REGDOM_SET_BY_CORE");
346
break;
347
case NL80211_REGDOM_SET_BY_USER:
348
RTW_INFO("%s: %s alpha2:%c%c\n", __func__, "NL80211_REGDOM_SET_BY_USER"
349
, request->alpha2[0], request->alpha2[1]);
350
rtw_set_country(wiphy_to_adapter(wiphy), request->alpha2);
351
break;
352
case NL80211_REGDOM_SET_BY_COUNTRY_IE:
353
RTW_INFO("%s: %s\n", __func__, "NL80211_REGDOM_SET_BY_COUNTRY_IE");
354
break;
355
}
356
357
rtw_regd_apply_flags(wiphy);
358
}
359
360
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0))
361
static int rtw_reg_notifier_return(struct wiphy *wiphy, struct regulatory_request *request)
362
{
363
rtw_reg_notifier(wiphy, request);
364
return 0;
365
}
366
#endif
367
368
static void _rtw_regd_init_wiphy(struct rtw_regulatory *reg, struct wiphy *wiphy)
369
{
370
const struct ieee80211_regdomain *regd;
371
372
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0))
373
wiphy->reg_notifier = rtw_reg_notifier_return;
374
#else
375
wiphy->reg_notifier = rtw_reg_notifier;
376
#endif
377
378
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
379
wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
380
wiphy->flags &= ~WIPHY_FLAG_STRICT_REGULATORY;
381
wiphy->flags &= ~WIPHY_FLAG_DISABLE_BEACON_HINTS;
382
#else
383
wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
384
wiphy->regulatory_flags &= ~REGULATORY_STRICT_REG;
385
wiphy->regulatory_flags &= ~REGULATORY_DISABLE_BEACON_HINTS;
386
#endif
387
388
regd = _rtw_regdomain_select(reg);
389
wiphy_apply_custom_regulatory(wiphy, regd);
390
391
rtw_regd_apply_flags(wiphy);
392
}
393
394
int rtw_regd_init(struct wiphy *wiphy)
395
{
396
#if 0
397
if (rtw_regd == NULL) {
398
rtw_regd = (struct rtw_regulatory *)
399
rtw_malloc(sizeof(struct rtw_regulatory));
400
401
rtw_regd->alpha2[0] = '9';
402
rtw_regd->alpha2[1] = '9';
403
404
rtw_regd->country_code = COUNTRY_CODE_USER;
405
}
406
407
RTW_INFO("%s: Country alpha2 being used: %c%c\n",
408
__func__, rtw_regd->alpha2[0], rtw_regd->alpha2[1]);
409
#endif
410
411
_rtw_regd_init_wiphy(NULL, wiphy);
412
413
return 0;
414
}
415
#endif /* CONFIG_IOCTL_CFG80211 */
416
417