cfg.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Implement cfg80211 ("iw") support.
  3. *
  4. * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
  5. * Holger Schurig <hs4233@mail.mn-solutions.de>
  6. *
  7. */
  8. #include <linux/slab.h>
  9. #include <net/cfg80211.h>
  10. #include "cfg.h"
  11. #include "cmd.h"
  12. #define CHAN2G(_channel, _freq, _flags) { \
  13. .band = IEEE80211_BAND_2GHZ, \
  14. .center_freq = (_freq), \
  15. .hw_value = (_channel), \
  16. .flags = (_flags), \
  17. .max_antenna_gain = 0, \
  18. .max_power = 30, \
  19. }
  20. static struct ieee80211_channel lbs_2ghz_channels[] = {
  21. CHAN2G(1, 2412, 0),
  22. CHAN2G(2, 2417, 0),
  23. CHAN2G(3, 2422, 0),
  24. CHAN2G(4, 2427, 0),
  25. CHAN2G(5, 2432, 0),
  26. CHAN2G(6, 2437, 0),
  27. CHAN2G(7, 2442, 0),
  28. CHAN2G(8, 2447, 0),
  29. CHAN2G(9, 2452, 0),
  30. CHAN2G(10, 2457, 0),
  31. CHAN2G(11, 2462, 0),
  32. CHAN2G(12, 2467, 0),
  33. CHAN2G(13, 2472, 0),
  34. CHAN2G(14, 2484, 0),
  35. };
  36. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  37. .bitrate = (_rate), \
  38. .hw_value = (_rateid), \
  39. .flags = (_flags), \
  40. }
  41. static struct ieee80211_rate lbs_rates[] = {
  42. RATETAB_ENT(10, 0x1, 0),
  43. RATETAB_ENT(20, 0x2, 0),
  44. RATETAB_ENT(55, 0x4, 0),
  45. RATETAB_ENT(110, 0x8, 0),
  46. RATETAB_ENT(60, 0x10, 0),
  47. RATETAB_ENT(90, 0x20, 0),
  48. RATETAB_ENT(120, 0x40, 0),
  49. RATETAB_ENT(180, 0x80, 0),
  50. RATETAB_ENT(240, 0x100, 0),
  51. RATETAB_ENT(360, 0x200, 0),
  52. RATETAB_ENT(480, 0x400, 0),
  53. RATETAB_ENT(540, 0x800, 0),
  54. };
  55. static struct ieee80211_supported_band lbs_band_2ghz = {
  56. .channels = lbs_2ghz_channels,
  57. .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
  58. .bitrates = lbs_rates,
  59. .n_bitrates = ARRAY_SIZE(lbs_rates),
  60. };
  61. static const u32 cipher_suites[] = {
  62. WLAN_CIPHER_SUITE_WEP40,
  63. WLAN_CIPHER_SUITE_WEP104,
  64. WLAN_CIPHER_SUITE_TKIP,
  65. WLAN_CIPHER_SUITE_CCMP,
  66. };
  67. static int lbs_cfg_set_channel(struct wiphy *wiphy,
  68. struct ieee80211_channel *chan,
  69. enum nl80211_channel_type channel_type)
  70. {
  71. struct lbs_private *priv = wiphy_priv(wiphy);
  72. int ret = -ENOTSUPP;
  73. lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d", chan->center_freq, channel_type);
  74. if (channel_type != NL80211_CHAN_NO_HT)
  75. goto out;
  76. ret = lbs_set_channel(priv, chan->hw_value);
  77. out:
  78. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  79. return ret;
  80. }
  81. static struct cfg80211_ops lbs_cfg80211_ops = {
  82. .set_channel = lbs_cfg_set_channel,
  83. };
  84. /*
  85. * At this time lbs_private *priv doesn't even exist, so we just allocate
  86. * memory and don't initialize the wiphy further. This is postponed until we
  87. * can talk to the firmware and happens at registration time in
  88. * lbs_cfg_wiphy_register().
  89. */
  90. struct wireless_dev *lbs_cfg_alloc(struct device *dev)
  91. {
  92. int ret = 0;
  93. struct wireless_dev *wdev;
  94. lbs_deb_enter(LBS_DEB_CFG80211);
  95. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  96. if (!wdev) {
  97. dev_err(dev, "cannot allocate wireless device\n");
  98. return ERR_PTR(-ENOMEM);
  99. }
  100. wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
  101. if (!wdev->wiphy) {
  102. dev_err(dev, "cannot allocate wiphy\n");
  103. ret = -ENOMEM;
  104. goto err_wiphy_new;
  105. }
  106. lbs_deb_leave(LBS_DEB_CFG80211);
  107. return wdev;
  108. err_wiphy_new:
  109. kfree(wdev);
  110. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  111. return ERR_PTR(ret);
  112. }
  113. /*
  114. * This function get's called after lbs_setup_firmware() determined the
  115. * firmware capabities. So we can setup the wiphy according to our
  116. * hardware/firmware.
  117. */
  118. int lbs_cfg_register(struct lbs_private *priv)
  119. {
  120. struct wireless_dev *wdev = priv->wdev;
  121. int ret;
  122. lbs_deb_enter(LBS_DEB_CFG80211);
  123. wdev->wiphy->max_scan_ssids = 1;
  124. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  125. /* TODO: BIT(NL80211_IFTYPE_ADHOC); */
  126. wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  127. /* TODO: honor priv->regioncode */
  128. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
  129. /*
  130. * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
  131. * never seen a firmware without WPA
  132. */
  133. wdev->wiphy->cipher_suites = cipher_suites;
  134. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  135. ret = wiphy_register(wdev->wiphy);
  136. if (ret < 0)
  137. lbs_pr_err("cannot register wiphy device\n");
  138. priv->wiphy_registered = true;
  139. ret = register_netdev(priv->dev);
  140. if (ret)
  141. lbs_pr_err("cannot register network device\n");
  142. lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
  143. return ret;
  144. }
  145. void lbs_cfg_free(struct lbs_private *priv)
  146. {
  147. struct wireless_dev *wdev = priv->wdev;
  148. lbs_deb_enter(LBS_DEB_CFG80211);
  149. if (!wdev)
  150. return;
  151. if (priv->wiphy_registered)
  152. wiphy_unregister(wdev->wiphy);
  153. if (wdev->wiphy)
  154. wiphy_free(wdev->wiphy);
  155. kfree(wdev);
  156. }