chan.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_freq_to_chan(struct cfg80211_registered_device *rdev,
  12. int freq, enum nl80211_channel_type channel_type)
  13. {
  14. struct ieee80211_channel *chan;
  15. struct ieee80211_sta_ht_cap *ht_cap;
  16. chan = ieee80211_get_channel(&rdev->wiphy, freq);
  17. /* Primary channel not allowed */
  18. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  19. return NULL;
  20. if (channel_type == NL80211_CHAN_HT40MINUS &&
  21. chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
  22. return NULL;
  23. else if (channel_type == NL80211_CHAN_HT40PLUS &&
  24. chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
  25. return NULL;
  26. ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
  27. if (channel_type != NL80211_CHAN_NO_HT) {
  28. if (!ht_cap->ht_supported)
  29. return NULL;
  30. if (channel_type != NL80211_CHAN_HT20 &&
  31. (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
  32. ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
  33. return NULL;
  34. }
  35. return chan;
  36. }
  37. int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
  38. struct wireless_dev *wdev, int freq,
  39. enum nl80211_channel_type channel_type)
  40. {
  41. struct ieee80211_channel *chan;
  42. int result;
  43. if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR)
  44. wdev = NULL;
  45. if (wdev) {
  46. ASSERT_WDEV_LOCK(wdev);
  47. if (!netif_running(wdev->netdev))
  48. return -ENETDOWN;
  49. }
  50. if (!rdev->ops->set_channel)
  51. return -EOPNOTSUPP;
  52. chan = rdev_freq_to_chan(rdev, freq, channel_type);
  53. if (!chan)
  54. return -EINVAL;
  55. result = rdev->ops->set_channel(&rdev->wiphy,
  56. wdev ? wdev->netdev : NULL,
  57. chan, channel_type);
  58. if (result)
  59. return result;
  60. if (wdev)
  61. wdev->channel = chan;
  62. return 0;
  63. }