chan.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
  31. ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
  32. return NULL;
  33. }
  34. return chan;
  35. }
  36. int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
  37. struct wireless_dev *wdev, int freq,
  38. enum nl80211_channel_type channel_type)
  39. {
  40. struct ieee80211_channel *chan;
  41. int result;
  42. if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR)
  43. wdev = NULL;
  44. if (wdev) {
  45. ASSERT_WDEV_LOCK(wdev);
  46. if (!netif_running(wdev->netdev))
  47. return -ENETDOWN;
  48. }
  49. if (!rdev->ops->set_channel)
  50. return -EOPNOTSUPP;
  51. chan = rdev_freq_to_chan(rdev, freq, channel_type);
  52. if (!chan)
  53. return -EINVAL;
  54. result = rdev->ops->set_channel(&rdev->wiphy,
  55. wdev ? wdev->netdev : NULL,
  56. chan, channel_type);
  57. if (result)
  58. return result;
  59. if (wdev)
  60. wdev->channel = chan;
  61. return 0;
  62. }