2 * Some IBSS support code for cfg80211.
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 #include <linux/etherdevice.h>
8 #include <linux/if_arp.h>
9 #include <net/cfg80211.h>
13 void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
15 struct wireless_dev *wdev = dev->ieee80211_ptr;
16 struct cfg80211_bss *bss;
17 #ifdef CONFIG_WIRELESS_EXT
18 union iwreq_data wrqu;
21 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
24 if (WARN_ON(!wdev->ssid_len))
27 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
28 wdev->ssid, wdev->ssid_len,
29 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
34 if (wdev->current_bss) {
35 cfg80211_unhold_bss(wdev->current_bss);
36 cfg80211_put_bss(&wdev->current_bss->pub);
39 cfg80211_hold_bss(bss_from_pub(bss));
40 wdev->current_bss = bss_from_pub(bss);
42 nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, gfp);
43 #ifdef CONFIG_WIRELESS_EXT
44 memset(&wrqu, 0, sizeof(wrqu));
45 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
46 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
49 EXPORT_SYMBOL(cfg80211_ibss_joined);
51 int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
52 struct net_device *dev,
53 struct cfg80211_ibss_params *params)
55 struct wireless_dev *wdev = dev->ieee80211_ptr;
61 #ifdef CONFIG_WIRELESS_EXT
62 wdev->wext.ibss.channel = params->channel;
64 err = rdev->ops->join_ibss(&rdev->wiphy, dev, params);
69 memcpy(wdev->ssid, params->ssid, params->ssid_len);
70 wdev->ssid_len = params->ssid_len;
75 void cfg80211_clear_ibss(struct net_device *dev, bool nowext)
77 struct wireless_dev *wdev = dev->ieee80211_ptr;
79 if (wdev->current_bss) {
80 cfg80211_unhold_bss(wdev->current_bss);
81 cfg80211_put_bss(&wdev->current_bss->pub);
84 wdev->current_bss = NULL;
86 #ifdef CONFIG_WIRELESS_EXT
88 wdev->wext.ibss.ssid_len = 0;
92 int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
93 struct net_device *dev, bool nowext)
95 struct wireless_dev *wdev = dev->ieee80211_ptr;
101 err = rdev->ops->leave_ibss(&rdev->wiphy, dev);
106 cfg80211_clear_ibss(dev, nowext);
111 #ifdef CONFIG_WIRELESS_EXT
112 static int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
113 struct wireless_dev *wdev)
115 enum ieee80211_band band;
118 if (!wdev->wext.ibss.beacon_interval)
119 wdev->wext.ibss.beacon_interval = 100;
121 /* try to find an IBSS channel if none requested ... */
122 if (!wdev->wext.ibss.channel) {
123 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
124 struct ieee80211_supported_band *sband;
125 struct ieee80211_channel *chan;
127 sband = rdev->wiphy.bands[band];
131 for (i = 0; i < sband->n_channels; i++) {
132 chan = &sband->channels[i];
133 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
135 if (chan->flags & IEEE80211_CHAN_DISABLED)
137 wdev->wext.ibss.channel = chan;
141 if (wdev->wext.ibss.channel)
145 if (!wdev->wext.ibss.channel)
149 /* don't join -- SSID is not there */
150 if (!wdev->wext.ibss.ssid_len)
153 if (!netif_running(wdev->netdev))
156 return cfg80211_join_ibss(wiphy_to_dev(wdev->wiphy),
157 wdev->netdev, &wdev->wext.ibss);
160 int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
161 struct iw_request_info *info,
162 struct iw_freq *freq, char *extra)
164 struct wireless_dev *wdev = dev->ieee80211_ptr;
165 struct ieee80211_channel *chan;
168 /* call only for ibss! */
169 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
172 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
175 chan = cfg80211_wext_freq(wdev->wiphy, freq);
176 if (chan && IS_ERR(chan))
177 return PTR_ERR(chan);
180 (chan->flags & IEEE80211_CHAN_NO_IBSS ||
181 chan->flags & IEEE80211_CHAN_DISABLED))
184 if (wdev->wext.ibss.channel == chan)
187 if (wdev->ssid_len) {
188 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
195 wdev->wext.ibss.channel = chan;
196 wdev->wext.ibss.channel_fixed = true;
198 /* cfg80211_ibss_wext_join will pick one if needed */
199 wdev->wext.ibss.channel_fixed = false;
202 return cfg80211_ibss_wext_join(wiphy_to_dev(wdev->wiphy), wdev);
204 /* temporary symbol - mark GPL - in the future the handler won't be */
205 EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_siwfreq);
207 int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
208 struct iw_request_info *info,
209 struct iw_freq *freq, char *extra)
211 struct wireless_dev *wdev = dev->ieee80211_ptr;
212 struct ieee80211_channel *chan = NULL;
214 /* call only for ibss! */
215 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
218 if (wdev->current_bss)
219 chan = wdev->current_bss->pub.channel;
220 else if (wdev->wext.ibss.channel)
221 chan = wdev->wext.ibss.channel;
224 freq->m = chan->center_freq;
229 /* no channel if not joining */
232 /* temporary symbol - mark GPL - in the future the handler won't be */
233 EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_giwfreq);
235 int cfg80211_ibss_wext_siwessid(struct net_device *dev,
236 struct iw_request_info *info,
237 struct iw_point *data, char *ssid)
239 struct wireless_dev *wdev = dev->ieee80211_ptr;
240 size_t len = data->length;
243 /* call only for ibss! */
244 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
247 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
250 if (wdev->ssid_len) {
251 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
257 /* iwconfig uses nul termination in SSID.. */
258 if (len > 0 && ssid[len - 1] == '\0')
261 wdev->wext.ibss.ssid = wdev->ssid;
262 memcpy(wdev->wext.ibss.ssid, ssid, len);
263 wdev->wext.ibss.ssid_len = len;
265 return cfg80211_ibss_wext_join(wiphy_to_dev(wdev->wiphy), wdev);
267 /* temporary symbol - mark GPL - in the future the handler won't be */
268 EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_siwessid);
270 int cfg80211_ibss_wext_giwessid(struct net_device *dev,
271 struct iw_request_info *info,
272 struct iw_point *data, char *ssid)
274 struct wireless_dev *wdev = dev->ieee80211_ptr;
276 /* call only for ibss! */
277 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
282 if (wdev->ssid_len) {
284 data->length = wdev->ssid_len;
285 memcpy(ssid, wdev->ssid, data->length);
286 } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) {
288 data->length = wdev->wext.ibss.ssid_len;
289 memcpy(ssid, wdev->wext.ibss.ssid, data->length);
294 /* temporary symbol - mark GPL - in the future the handler won't be */
295 EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_giwessid);
297 int cfg80211_ibss_wext_siwap(struct net_device *dev,
298 struct iw_request_info *info,
299 struct sockaddr *ap_addr, char *extra)
301 struct wireless_dev *wdev = dev->ieee80211_ptr;
302 u8 *bssid = ap_addr->sa_data;
305 /* call only for ibss! */
306 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
309 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
312 if (ap_addr->sa_family != ARPHRD_ETHER)
316 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
320 if (!bssid && !wdev->wext.ibss.bssid)
323 /* fixed already - and no change */
324 if (wdev->wext.ibss.bssid && bssid &&
325 compare_ether_addr(bssid, wdev->wext.ibss.bssid) == 0)
328 if (wdev->ssid_len) {
329 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
336 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
337 wdev->wext.ibss.bssid = wdev->wext.bssid;
339 wdev->wext.ibss.bssid = NULL;
341 return cfg80211_ibss_wext_join(wiphy_to_dev(wdev->wiphy), wdev);
343 /* temporary symbol - mark GPL - in the future the handler won't be */
344 EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_siwap);
346 int cfg80211_ibss_wext_giwap(struct net_device *dev,
347 struct iw_request_info *info,
348 struct sockaddr *ap_addr, char *extra)
350 struct wireless_dev *wdev = dev->ieee80211_ptr;
352 /* call only for ibss! */
353 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
356 ap_addr->sa_family = ARPHRD_ETHER;
358 if (wdev->current_bss)
359 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
361 memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN);
364 /* temporary symbol - mark GPL - in the future the handler won't be */
365 EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_giwap);