chan.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <linux/export.h>
  9. #include <net/cfg80211.h>
  10. #include "core.h"
  11. struct ieee80211_channel *
  12. rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
  13. int freq, enum nl80211_channel_type channel_type)
  14. {
  15. struct ieee80211_channel *chan;
  16. struct ieee80211_sta_ht_cap *ht_cap;
  17. chan = ieee80211_get_channel(&rdev->wiphy, freq);
  18. /* Primary channel not allowed */
  19. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  20. return NULL;
  21. if (channel_type == NL80211_CHAN_HT40MINUS &&
  22. chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
  23. return NULL;
  24. else if (channel_type == NL80211_CHAN_HT40PLUS &&
  25. chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
  26. return NULL;
  27. ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
  28. if (channel_type != NL80211_CHAN_NO_HT) {
  29. if (!ht_cap->ht_supported)
  30. return NULL;
  31. if (channel_type != NL80211_CHAN_HT20 &&
  32. (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
  33. ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
  34. return NULL;
  35. }
  36. return chan;
  37. }
  38. bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
  39. struct ieee80211_channel *chan,
  40. enum nl80211_channel_type channel_type)
  41. {
  42. struct ieee80211_channel *sec_chan;
  43. int diff;
  44. switch (channel_type) {
  45. case NL80211_CHAN_HT40PLUS:
  46. diff = 20;
  47. break;
  48. case NL80211_CHAN_HT40MINUS:
  49. diff = -20;
  50. break;
  51. default:
  52. return true;
  53. }
  54. sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
  55. if (!sec_chan)
  56. return false;
  57. /* we'll need a DFS capability later */
  58. if (sec_chan->flags & (IEEE80211_CHAN_DISABLED |
  59. IEEE80211_CHAN_PASSIVE_SCAN |
  60. IEEE80211_CHAN_NO_IBSS |
  61. IEEE80211_CHAN_RADAR))
  62. return false;
  63. return true;
  64. }
  65. EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
  66. int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
  67. int freq, enum nl80211_channel_type chantype)
  68. {
  69. struct ieee80211_channel *chan;
  70. if (!rdev->ops->set_monitor_channel)
  71. return -EOPNOTSUPP;
  72. chan = rdev_freq_to_chan(rdev, freq, chantype);
  73. if (!chan)
  74. return -EINVAL;
  75. return rdev->ops->set_monitor_channel(&rdev->wiphy, chan, chantype);
  76. }