cfg.c 4.5 KB

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