wext-compat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * cfg80211 - wext compat code
  3. *
  4. * This is temporary code until all wireless functionality is migrated
  5. * into cfg80211, when that happens all the exports here go away and
  6. * we directly assign the wireless handlers of wireless interfaces.
  7. *
  8. * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
  9. */
  10. #include <linux/wireless.h>
  11. #include <linux/nl80211.h>
  12. #include <net/iw_handler.h>
  13. #include <net/wireless.h>
  14. #include <net/cfg80211.h>
  15. #include "core.h"
  16. int cfg80211_wext_giwname(struct net_device *dev,
  17. struct iw_request_info *info,
  18. char *name, char *extra)
  19. {
  20. struct wireless_dev *wdev = dev->ieee80211_ptr;
  21. struct ieee80211_supported_band *sband;
  22. bool is_ht = false, is_a = false, is_b = false, is_g = false;
  23. if (!wdev)
  24. return -EOPNOTSUPP;
  25. sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
  26. if (sband) {
  27. is_a = true;
  28. is_ht |= sband->ht_cap.ht_supported;
  29. }
  30. sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
  31. if (sband) {
  32. int i;
  33. /* Check for mandatory rates */
  34. for (i = 0; i < sband->n_bitrates; i++) {
  35. if (sband->bitrates[i].bitrate == 10)
  36. is_b = true;
  37. if (sband->bitrates[i].bitrate == 60)
  38. is_g = true;
  39. }
  40. is_ht |= sband->ht_cap.ht_supported;
  41. }
  42. strcpy(name, "IEEE 802.11");
  43. if (is_a)
  44. strcat(name, "a");
  45. if (is_b)
  46. strcat(name, "b");
  47. if (is_g)
  48. strcat(name, "g");
  49. if (is_ht)
  50. strcat(name, "n");
  51. return 0;
  52. }
  53. EXPORT_SYMBOL(cfg80211_wext_giwname);
  54. int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
  55. u32 *mode, char *extra)
  56. {
  57. struct wireless_dev *wdev = dev->ieee80211_ptr;
  58. struct cfg80211_registered_device *rdev;
  59. struct vif_params vifparams;
  60. enum nl80211_iftype type;
  61. if (!wdev)
  62. return -EOPNOTSUPP;
  63. rdev = wiphy_to_dev(wdev->wiphy);
  64. if (!rdev->ops->change_virtual_intf)
  65. return -EOPNOTSUPP;
  66. /* don't support changing VLANs, you just re-create them */
  67. if (wdev->iftype == NL80211_IFTYPE_AP_VLAN)
  68. return -EOPNOTSUPP;
  69. switch (*mode) {
  70. case IW_MODE_INFRA:
  71. type = NL80211_IFTYPE_STATION;
  72. break;
  73. case IW_MODE_ADHOC:
  74. type = NL80211_IFTYPE_ADHOC;
  75. break;
  76. case IW_MODE_REPEAT:
  77. type = NL80211_IFTYPE_WDS;
  78. break;
  79. case IW_MODE_MONITOR:
  80. type = NL80211_IFTYPE_MONITOR;
  81. break;
  82. default:
  83. return -EINVAL;
  84. }
  85. memset(&vifparams, 0, sizeof(vifparams));
  86. return rdev->ops->change_virtual_intf(wdev->wiphy, dev->ifindex, type,
  87. NULL, &vifparams);
  88. }
  89. EXPORT_SYMBOL(cfg80211_wext_siwmode);
  90. int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
  91. u32 *mode, char *extra)
  92. {
  93. struct wireless_dev *wdev = dev->ieee80211_ptr;
  94. if (!wdev)
  95. return -EOPNOTSUPP;
  96. switch (wdev->iftype) {
  97. case NL80211_IFTYPE_AP:
  98. *mode = IW_MODE_MASTER;
  99. break;
  100. case NL80211_IFTYPE_STATION:
  101. *mode = IW_MODE_INFRA;
  102. break;
  103. case NL80211_IFTYPE_ADHOC:
  104. *mode = IW_MODE_ADHOC;
  105. break;
  106. case NL80211_IFTYPE_MONITOR:
  107. *mode = IW_MODE_MONITOR;
  108. break;
  109. case NL80211_IFTYPE_WDS:
  110. *mode = IW_MODE_REPEAT;
  111. break;
  112. case NL80211_IFTYPE_AP_VLAN:
  113. *mode = IW_MODE_SECOND; /* FIXME */
  114. break;
  115. default:
  116. *mode = IW_MODE_AUTO;
  117. break;
  118. }
  119. return 0;
  120. }
  121. EXPORT_SYMBOL(cfg80211_wext_giwmode);