1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2009-2010 Realtek Corporation.
6 *****************************************************************************/
11 #include <rtw_wifi_regd.h>
14 * REG_RULE(freq start, freq end, bandwidth, max gain, eirp, reg_flags)
18 * Only these channels all allow active
19 * scan on all world regulatory domains
22 /* 2G chan 01 - chan 11 */
23 #define RTW_2GHZ_CH01_11 \
24 REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0)
27 * We enable active scan on these a case
28 * by case basis by regulatory domain
31 /* 2G chan 12 - chan 13, PASSIV SCAN */
32 #define RTW_2GHZ_CH12_13 \
33 REG_RULE(2467 - 10, 2472 + 10, 40, 0, 20, \
34 NL80211_RRF_PASSIVE_SCAN)
36 static const struct ieee80211_regdomain rtw_regdom_rd = {
45 static int rtw_ieee80211_channel_to_frequency(int chan, int band)
47 /* see 802.11 17.3.8.3.2 and Annex J
48 * there are overlapping channel numbers in 5GHz and 2GHz bands
51 /* NL80211_BAND_2GHZ */
55 return 2407 + chan * 5;
57 return 0; /* not supported */
60 static void _rtw_reg_apply_flags(struct wiphy *wiphy)
62 struct adapter *padapter = wiphy_to_adapter(wiphy);
63 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
64 struct rt_channel_info *channel_set = pmlmeext->channel_set;
65 u8 max_chan_nums = pmlmeext->max_chan_nums;
67 struct ieee80211_supported_band *sband;
68 struct ieee80211_channel *ch;
73 /* all channels disable */
74 for (i = 0; i < NUM_NL80211_BANDS; i++) {
75 sband = wiphy->bands[i];
78 for (j = 0; j < sband->n_channels; j++) {
79 ch = &sband->channels[j];
82 ch->flags = IEEE80211_CHAN_DISABLED;
87 /* channels apply by channel plans. */
88 for (i = 0; i < max_chan_nums; i++) {
89 channel = channel_set[i].ChannelNum;
91 rtw_ieee80211_channel_to_frequency(channel,
94 ch = ieee80211_get_channel(wiphy, freq);
96 if (channel_set[i].ScanType == SCAN_PASSIVE)
97 ch->flags = IEEE80211_CHAN_NO_IR;
104 static int _rtw_reg_notifier_apply(struct wiphy *wiphy,
105 struct regulatory_request *request,
106 struct rtw_regulatory *reg)
108 /* Hard code flags */
109 _rtw_reg_apply_flags(wiphy);
113 static const struct ieee80211_regdomain *_rtw_regdomain_select(struct
117 return &rtw_regdom_rd;
120 static void _rtw_regd_init_wiphy(struct rtw_regulatory *reg,
122 void (*reg_notifier)(struct wiphy *wiphy,
127 const struct ieee80211_regdomain *regd;
129 wiphy->reg_notifier = reg_notifier;
131 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
132 wiphy->regulatory_flags &= ~REGULATORY_STRICT_REG;
133 wiphy->regulatory_flags &= ~REGULATORY_DISABLE_BEACON_HINTS;
135 regd = _rtw_regdomain_select(reg);
136 wiphy_apply_custom_regulatory(wiphy, regd);
138 /* Hard code flags */
139 _rtw_reg_apply_flags(wiphy);
142 void rtw_regd_init(struct wiphy *wiphy,
143 void (*reg_notifier)(struct wiphy *wiphy,
144 struct regulatory_request *request))
146 _rtw_regd_init_wiphy(NULL, wiphy, reg_notifier);
149 void rtw_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
151 struct rtw_regulatory *reg = NULL;
153 _rtw_reg_notifier_apply(wiphy, request, reg);