chan.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. int freq, enum nl80211_channel_type channel_type)
  38. {
  39. struct ieee80211_channel *chan;
  40. struct ieee80211_sta_ht_cap *ht_cap;
  41. int result;
  42. if (rdev_fixed_channel(rdev, NULL))
  43. return -EBUSY;
  44. if (!rdev->ops->set_channel)
  45. return -EOPNOTSUPP;
  46. chan = ieee80211_get_channel(&rdev->wiphy, freq);
  47. /* Primary channel not allowed */
  48. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  49. return -EINVAL;
  50. if (channel_type == NL80211_CHAN_HT40MINUS &&
  51. chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
  52. return -EINVAL;
  53. else if (channel_type == NL80211_CHAN_HT40PLUS &&
  54. chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
  55. return -EINVAL;
  56. ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
  57. if (channel_type != NL80211_CHAN_NO_HT) {
  58. if (!ht_cap->ht_supported)
  59. return -EINVAL;
  60. if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
  61. ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
  62. return -EINVAL;
  63. }
  64. result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
  65. if (result)
  66. return result;
  67. rdev->channel = chan;
  68. return 0;
  69. }