chan.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * This file contains helper code to handle channel
  3. * settings and keeping track of what is possible at
  4. * any point in time.
  5. *
  6. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  7. */
  8. #include <net/cfg80211.h>
  9. #include "core.h"
  10. struct ieee80211_channel *
  11. rdev_fixed_channel(struct cfg80211_registered_device *rdev,
  12. struct wireless_dev *for_wdev)
  13. {
  14. struct wireless_dev *wdev;
  15. struct ieee80211_channel *result = NULL;
  16. WARN_ON(!mutex_is_locked(&rdev->devlist_mtx));
  17. list_for_each_entry(wdev, &rdev->netdev_list, list) {
  18. if (wdev == for_wdev)
  19. continue;
  20. /*
  21. * Lock manually to tell lockdep about allowed
  22. * nesting here if for_wdev->mtx is held already.
  23. * This is ok as it's all under the rdev devlist
  24. * mutex and as such can only be done once at any
  25. * given time.
  26. */
  27. mutex_lock_nested(&wdev->mtx, SINGLE_DEPTH_NESTING);
  28. if (wdev->current_bss)
  29. result = wdev->current_bss->pub.channel;
  30. wdev_unlock(wdev);
  31. if (result)
  32. break;
  33. }
  34. return result;
  35. }
  36. int rdev_set_freq(struct cfg80211_registered_device *rdev,
  37. struct wireless_dev *for_wdev,
  38. int freq, enum nl80211_channel_type channel_type)
  39. {
  40. struct ieee80211_channel *chan;
  41. struct ieee80211_sta_ht_cap *ht_cap;
  42. int result;
  43. if (rdev_fixed_channel(rdev, for_wdev))
  44. return -EBUSY;
  45. if (!rdev->ops->set_channel)
  46. return -EOPNOTSUPP;
  47. chan = ieee80211_get_channel(&rdev->wiphy, freq);
  48. /* Primary channel not allowed */
  49. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  50. return -EINVAL;
  51. if (channel_type == NL80211_CHAN_HT40MINUS &&
  52. chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
  53. return -EINVAL;
  54. else if (channel_type == NL80211_CHAN_HT40PLUS &&
  55. chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
  56. return -EINVAL;
  57. ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
  58. if (channel_type != NL80211_CHAN_NO_HT) {
  59. if (!ht_cap->ht_supported)
  60. return -EINVAL;
  61. if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
  62. ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
  63. return -EINVAL;
  64. }
  65. result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
  66. if (result)
  67. return result;
  68. rdev->channel = chan;
  69. return 0;
  70. }