2 * This file contains helper code to handle channel
3 * settings and keeping track of what is possible at
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 #include <net/cfg80211.h>
12 struct ieee80211_channel *
13 rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
14 int freq, enum nl80211_channel_type channel_type)
16 struct ieee80211_channel *chan;
17 struct ieee80211_sta_ht_cap *ht_cap;
19 chan = ieee80211_get_channel(&rdev->wiphy, freq);
21 /* Primary channel not allowed */
22 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
25 if (channel_type == NL80211_CHAN_HT40MINUS &&
26 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
28 else if (channel_type == NL80211_CHAN_HT40PLUS &&
29 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
32 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
34 if (channel_type != NL80211_CHAN_NO_HT) {
35 if (!ht_cap->ht_supported)
38 if (channel_type != NL80211_CHAN_HT20 &&
39 (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
40 ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
47 static bool can_beacon_sec_chan(struct wiphy *wiphy,
48 struct ieee80211_channel *chan,
49 enum nl80211_channel_type channel_type)
51 struct ieee80211_channel *sec_chan;
54 switch (channel_type) {
55 case NL80211_CHAN_HT40PLUS:
58 case NL80211_CHAN_HT40MINUS:
65 sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
69 /* we'll need a DFS capability later */
70 if (sec_chan->flags & (IEEE80211_CHAN_DISABLED |
71 IEEE80211_CHAN_PASSIVE_SCAN |
72 IEEE80211_CHAN_NO_IBSS |
73 IEEE80211_CHAN_RADAR))
79 int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
80 struct wireless_dev *wdev, int freq,
81 enum nl80211_channel_type channel_type)
83 struct ieee80211_channel *chan;
86 if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR)
90 ASSERT_WDEV_LOCK(wdev);
92 if (!netif_running(wdev->netdev))
96 if (!rdev->ops->set_channel)
99 chan = rdev_freq_to_chan(rdev, freq, channel_type);
103 /* Both channels should be able to initiate communication */
104 if (wdev && (wdev->iftype == NL80211_IFTYPE_ADHOC ||
105 wdev->iftype == NL80211_IFTYPE_AP ||
106 wdev->iftype == NL80211_IFTYPE_AP_VLAN ||
107 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
108 wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
109 switch (channel_type) {
110 case NL80211_CHAN_HT40PLUS:
111 case NL80211_CHAN_HT40MINUS:
112 if (!can_beacon_sec_chan(&rdev->wiphy, chan,
115 "cfg80211: Secondary channel not "
116 "allowed to initiate communication\n");
125 result = rdev->ops->set_channel(&rdev->wiphy,
126 wdev ? wdev->netdev : NULL,
132 wdev->channel = chan;