1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
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.
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
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
29 static struct country_code_to_enum_rd allcountries
[] = {
30 {COUNTRY_CODE_FCC
, "US"},
31 {COUNTRY_CODE_IC
, "US"},
32 {COUNTRY_CODE_ETSI
, "EC"},
33 {COUNTRY_CODE_SPAIN
, "EC"},
34 {COUNTRY_CODE_FRANCE
, "EC"},
35 {COUNTRY_CODE_MKK
, "JP"},
36 {COUNTRY_CODE_MKK1
, "JP"},
37 {COUNTRY_CODE_ISRAEL
, "EC"},
38 {COUNTRY_CODE_TELEC
, "JP"},
39 {COUNTRY_CODE_MIC
, "JP"},
40 {COUNTRY_CODE_GLOBAL_DOMAIN
, "JP"},
41 {COUNTRY_CODE_WORLD_WIDE_13
, "EC"},
42 {COUNTRY_CODE_TELEC_NETGEAR
, "EC"},
46 *Only these channels all allow active
47 *scan on all world regulatory domains
49 #define RTL819x_2GHZ_CH01_11 \
50 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
53 *We enable active scan on these a case
54 *by case basis by regulatory domain
56 #define RTL819x_2GHZ_CH12_13 \
57 REG_RULE(2467-10, 2472+10, 40, 0, 20,\
58 NL80211_RRF_PASSIVE_SCAN)
60 #define RTL819x_2GHZ_CH14 \
61 REG_RULE(2484-10, 2484+10, 40, 0, 20, \
62 NL80211_RRF_PASSIVE_SCAN | \
65 /* 5G chan 36 - chan 64*/
66 #define RTL819x_5GHZ_5150_5350 \
67 REG_RULE(5150-10, 5350+10, 80, 0, 30, \
68 NL80211_RRF_PASSIVE_SCAN | \
71 /* 5G chan 100 - chan 165*/
72 #define RTL819x_5GHZ_5470_5850 \
73 REG_RULE(5470-10, 5850+10, 80, 0, 30, \
74 NL80211_RRF_PASSIVE_SCAN | \
77 /* 5G chan 149 - chan 165*/
78 #define RTL819x_5GHZ_5725_5850 \
79 REG_RULE(5725-10, 5850+10, 80, 0, 30, \
80 NL80211_RRF_PASSIVE_SCAN | \
83 #define RTL819x_5GHZ_ALL \
84 (RTL819x_5GHZ_5150_5350, RTL819x_5GHZ_5470_5850)
86 static const struct ieee80211_regdomain rtl_regdom_11
= {
94 static const struct ieee80211_regdomain rtl_regdom_12_13
= {
103 static const struct ieee80211_regdomain rtl_regdom_no_midband
= {
107 RTL819x_2GHZ_CH01_11
,
108 RTL819x_5GHZ_5150_5350
,
109 RTL819x_5GHZ_5725_5850
,
113 static const struct ieee80211_regdomain rtl_regdom_60_64
= {
117 RTL819x_2GHZ_CH01_11
,
118 RTL819x_2GHZ_CH12_13
,
119 RTL819x_5GHZ_5725_5850
,
123 static const struct ieee80211_regdomain rtl_regdom_14_60_64
= {
127 RTL819x_2GHZ_CH01_11
,
128 RTL819x_2GHZ_CH12_13
,
130 RTL819x_5GHZ_5725_5850
,
134 static const struct ieee80211_regdomain rtl_regdom_14
= {
138 RTL819x_2GHZ_CH01_11
,
139 RTL819x_2GHZ_CH12_13
,
144 static bool _rtl_is_radar_freq(u16 center_freq
)
146 return center_freq
>= 5260 && center_freq
<= 5700;
149 static void _rtl_reg_apply_beaconing_flags(struct wiphy
*wiphy
,
150 enum nl80211_reg_initiator initiator
)
152 enum ieee80211_band band
;
153 struct ieee80211_supported_band
*sband
;
154 const struct ieee80211_reg_rule
*reg_rule
;
155 struct ieee80211_channel
*ch
;
158 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
159 if (!wiphy
->bands
[band
])
162 sband
= wiphy
->bands
[band
];
164 for (i
= 0; i
< sband
->n_channels
; i
++) {
165 ch
= &sband
->channels
[i
];
166 if (_rtl_is_radar_freq(ch
->center_freq
) ||
167 (ch
->flags
& IEEE80211_CHAN_RADAR
))
169 if (initiator
== NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
170 reg_rule
= freq_reg_info(wiphy
,
172 if (IS_ERR(reg_rule
))
176 *If 11d had a rule for this channel ensure
177 *we enable adhoc/beaconing if it allows us to
178 *use it. Note that we would have disabled it
179 *by applying our static world regdomain by
180 *default during init, prior to calling our
184 if (!(reg_rule
->flags
& NL80211_RRF_NO_IBSS
))
185 ch
->flags
&= ~IEEE80211_CHAN_NO_IBSS
;
186 if (!(reg_rule
->flags
&
187 NL80211_RRF_PASSIVE_SCAN
))
189 ~IEEE80211_CHAN_PASSIVE_SCAN
;
191 if (ch
->beacon_found
)
192 ch
->flags
&= ~(IEEE80211_CHAN_NO_IBSS
|
193 IEEE80211_CHAN_PASSIVE_SCAN
);
199 /* Allows active scan scan on Ch 12 and 13 */
200 static void _rtl_reg_apply_active_scan_flags(struct wiphy
*wiphy
,
201 enum nl80211_reg_initiator
204 struct ieee80211_supported_band
*sband
;
205 struct ieee80211_channel
*ch
;
206 const struct ieee80211_reg_rule
*reg_rule
;
208 if (!wiphy
->bands
[IEEE80211_BAND_2GHZ
])
210 sband
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
213 *If no country IE has been received always enable active scan
214 *on these channels. This is only done for specific regulatory SKUs
216 if (initiator
!= NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
217 ch
= &sband
->channels
[11]; /* CH 12 */
218 if (ch
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
219 ch
->flags
&= ~IEEE80211_CHAN_PASSIVE_SCAN
;
220 ch
= &sband
->channels
[12]; /* CH 13 */
221 if (ch
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
222 ch
->flags
&= ~IEEE80211_CHAN_PASSIVE_SCAN
;
227 *If a country IE has been recieved check its rule for this
228 *channel first before enabling active scan. The passive scan
229 *would have been enforced by the initial processing of our
230 *custom regulatory domain.
233 ch
= &sband
->channels
[11]; /* CH 12 */
234 reg_rule
= freq_reg_info(wiphy
, ch
->center_freq
);
235 if (!IS_ERR(reg_rule
)) {
236 if (!(reg_rule
->flags
& NL80211_RRF_PASSIVE_SCAN
))
237 if (ch
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
238 ch
->flags
&= ~IEEE80211_CHAN_PASSIVE_SCAN
;
241 ch
= &sband
->channels
[12]; /* CH 13 */
242 reg_rule
= freq_reg_info(wiphy
, ch
->center_freq
);
243 if (!IS_ERR(reg_rule
)) {
244 if (!(reg_rule
->flags
& NL80211_RRF_PASSIVE_SCAN
))
245 if (ch
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
246 ch
->flags
&= ~IEEE80211_CHAN_PASSIVE_SCAN
;
251 *Always apply Radar/DFS rules on
252 *freq range 5260 MHz - 5700 MHz
254 static void _rtl_reg_apply_radar_flags(struct wiphy
*wiphy
)
256 struct ieee80211_supported_band
*sband
;
257 struct ieee80211_channel
*ch
;
260 if (!wiphy
->bands
[IEEE80211_BAND_5GHZ
])
263 sband
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
265 for (i
= 0; i
< sband
->n_channels
; i
++) {
266 ch
= &sband
->channels
[i
];
267 if (!_rtl_is_radar_freq(ch
->center_freq
))
271 *We always enable radar detection/DFS on this
272 *frequency range. Additionally we also apply on
273 *this frequency range:
274 *- If STA mode does not yet have DFS supports disable
276 *- If adhoc mode does not support DFS yet then disable
277 * adhoc in the frequency.
278 *- If AP mode does not yet support radar detection/DFS
279 *do not allow AP mode
281 if (!(ch
->flags
& IEEE80211_CHAN_DISABLED
))
282 ch
->flags
|= IEEE80211_CHAN_RADAR
|
283 IEEE80211_CHAN_NO_IBSS
|
284 IEEE80211_CHAN_PASSIVE_SCAN
;
288 static void _rtl_reg_apply_world_flags(struct wiphy
*wiphy
,
289 enum nl80211_reg_initiator initiator
,
290 struct rtl_regulatory
*reg
)
292 _rtl_reg_apply_beaconing_flags(wiphy
, initiator
);
293 _rtl_reg_apply_active_scan_flags(wiphy
, initiator
);
297 static void _rtl_dump_channel_map(struct wiphy
*wiphy
)
299 enum ieee80211_band band
;
300 struct ieee80211_supported_band
*sband
;
301 struct ieee80211_channel
*ch
;
304 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
305 if (!wiphy
->bands
[band
])
307 sband
= wiphy
->bands
[band
];
308 for (i
= 0; i
< sband
->n_channels
; i
++)
309 ch
= &sband
->channels
[i
];
313 static int _rtl92e_reg_notifier_apply(struct wiphy
*wiphy
,
314 struct regulatory_request
*request
,
315 struct rtl_regulatory
*reg
)
317 /* We always apply this */
318 _rtl_reg_apply_radar_flags(wiphy
);
320 switch (request
->initiator
) {
321 case NL80211_REGDOM_SET_BY_DRIVER
:
322 case NL80211_REGDOM_SET_BY_CORE
:
323 case NL80211_REGDOM_SET_BY_USER
:
325 case NL80211_REGDOM_SET_BY_COUNTRY_IE
:
326 _rtl_reg_apply_world_flags(wiphy
, request
->initiator
, reg
);
330 _rtl_dump_channel_map(wiphy
);
335 static const struct ieee80211_regdomain
*_rtl_regdomain_select(
336 struct rtl_regulatory
*reg
)
338 switch (reg
->country_code
) {
339 case COUNTRY_CODE_FCC
:
340 return &rtl_regdom_no_midband
;
341 case COUNTRY_CODE_IC
:
342 return &rtl_regdom_11
;
343 case COUNTRY_CODE_ETSI
:
344 case COUNTRY_CODE_TELEC_NETGEAR
:
345 return &rtl_regdom_60_64
;
346 case COUNTRY_CODE_SPAIN
:
347 case COUNTRY_CODE_FRANCE
:
348 case COUNTRY_CODE_ISRAEL
:
349 case COUNTRY_CODE_WORLD_WIDE_13
:
350 return &rtl_regdom_12_13
;
351 case COUNTRY_CODE_MKK
:
352 case COUNTRY_CODE_MKK1
:
353 case COUNTRY_CODE_TELEC
:
354 case COUNTRY_CODE_MIC
:
355 return &rtl_regdom_14_60_64
;
356 case COUNTRY_CODE_GLOBAL_DOMAIN
:
357 return &rtl_regdom_14
;
359 return &rtl_regdom_no_midband
;
363 static int _rtl92e_regd_init_wiphy(struct rtl_regulatory
*reg
,
365 void (*reg_notifier
)(struct wiphy
*wiphy
,
366 struct regulatory_request
*
369 const struct ieee80211_regdomain
*regd
;
371 wiphy
->reg_notifier
= reg_notifier
;
373 wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
;
374 wiphy
->regulatory_flags
&= ~REGULATORY_STRICT_REG
;
375 wiphy
->regulatory_flags
&= ~REGULATORY_DISABLE_BEACON_HINTS
;
377 regd
= _rtl_regdomain_select(reg
);
378 wiphy_apply_custom_regulatory(wiphy
, regd
);
379 _rtl_reg_apply_radar_flags(wiphy
);
380 _rtl_reg_apply_world_flags(wiphy
, NL80211_REGDOM_SET_BY_DRIVER
, reg
);
384 static struct country_code_to_enum_rd
*_rtl_regd_find_country(u16 countrycode
)
388 for (i
= 0; i
< ARRAY_SIZE(allcountries
); i
++) {
389 if (allcountries
[i
].countrycode
== countrycode
)
390 return &allcountries
[i
];
395 int rtl92e_regd_init(struct ieee80211_hw
*hw
,
396 void (*reg_notifier
)(struct wiphy
*wiphy
,
397 struct regulatory_request
*request
))
399 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
400 struct wiphy
*wiphy
= hw
->wiphy
;
401 struct country_code_to_enum_rd
*country
= NULL
;
403 if (wiphy
== NULL
|| &rtlpriv
->regd
== NULL
)
406 /* init country_code from efuse channel plan */
407 rtlpriv
->regd
.country_code
= rtlpriv
->efuse
.channel_plan
;
409 RT_TRACE(COMP_REGD
, DBG_TRACE
,
410 (KERN_DEBUG
"rtl: EEPROM regdomain: 0x%0x\n",
411 rtlpriv
->regd
.country_code
));
413 if (rtlpriv
->regd
.country_code
>= COUNTRY_CODE_MAX
) {
414 RT_TRACE(COMP_REGD
, DBG_DMESG
,
415 ("rtl: EEPROM indicates invalid contry code world wide 13 should be used\n"));
417 rtlpriv
->regd
.country_code
= COUNTRY_CODE_WORLD_WIDE_13
;
420 country
= _rtl_regd_find_country(rtlpriv
->regd
.country_code
);
423 rtlpriv
->regd
.alpha2
[0] = country
->iso_name
[0];
424 rtlpriv
->regd
.alpha2
[1] = country
->iso_name
[1];
426 rtlpriv
->regd
.alpha2
[0] = '0';
427 rtlpriv
->regd
.alpha2
[1] = '0';
430 RT_TRACE(COMP_REGD
, DBG_TRACE
,
431 (KERN_DEBUG
"rtl: Country alpha2 being used: %c%c\n",
432 rtlpriv
->regd
.alpha2
[0], rtlpriv
->regd
.alpha2
[1]));
434 _rtl92e_regd_init_wiphy(&rtlpriv
->regd
, wiphy
, reg_notifier
);
439 void rtl92e_reg_notifier(struct wiphy
*wiphy
,
440 struct regulatory_request
*request
)
442 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
443 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
445 RT_TRACE(COMP_REGD
, DBG_LOUD
, ("\n"));
447 _rtl92e_reg_notifier_apply(wiphy
, request
, &rtlpriv
->regd
);