cfg.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* cfg80211 support
  2. *
  3. * See copyright notice in main.c
  4. */
  5. #include <linux/ieee80211.h>
  6. #include <net/cfg80211.h>
  7. #include "hw.h"
  8. #include "main.h"
  9. #include "orinoco.h"
  10. #include "cfg.h"
  11. /* Supported bitrates. Must agree with hw.c */
  12. static struct ieee80211_rate orinoco_rates[] = {
  13. { .bitrate = 10 },
  14. { .bitrate = 20 },
  15. { .bitrate = 55 },
  16. { .bitrate = 110 },
  17. };
  18. static const void * const orinoco_wiphy_privid = &orinoco_wiphy_privid;
  19. /* Called after orinoco_private is allocated. */
  20. void orinoco_wiphy_init(struct wiphy *wiphy)
  21. {
  22. struct orinoco_private *priv = wiphy_priv(wiphy);
  23. wiphy->privid = orinoco_wiphy_privid;
  24. set_wiphy_dev(wiphy, priv->dev);
  25. }
  26. /* Called after firmware is initialised */
  27. int orinoco_wiphy_register(struct wiphy *wiphy)
  28. {
  29. struct orinoco_private *priv = wiphy_priv(wiphy);
  30. int i, channels = 0;
  31. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  32. wiphy->max_scan_ssids = 1;
  33. else
  34. wiphy->max_scan_ssids = 0;
  35. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  36. /* TODO: should we set if we only have demo ad-hoc?
  37. * (priv->has_port3)
  38. */
  39. if (priv->has_ibss)
  40. wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  41. if (!priv->broken_monitor || force_monitor)
  42. wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  43. priv->band.bitrates = orinoco_rates;
  44. priv->band.n_bitrates = ARRAY_SIZE(orinoco_rates);
  45. /* Only support channels allowed by the card EEPROM */
  46. for (i = 0; i < NUM_CHANNELS; i++) {
  47. if (priv->channel_mask & (1 << i)) {
  48. priv->channels[i].center_freq =
  49. ieee80211_dsss_chan_to_freq(i+1);
  50. channels++;
  51. }
  52. }
  53. priv->band.channels = priv->channels;
  54. priv->band.n_channels = channels;
  55. wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
  56. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  57. i = 0;
  58. if (priv->has_wep) {
  59. priv->cipher_suites[i] = WLAN_CIPHER_SUITE_WEP40;
  60. i++;
  61. if (priv->has_big_wep) {
  62. priv->cipher_suites[i] = WLAN_CIPHER_SUITE_WEP104;
  63. i++;
  64. }
  65. }
  66. if (priv->has_wpa) {
  67. priv->cipher_suites[i] = WLAN_CIPHER_SUITE_TKIP;
  68. i++;
  69. }
  70. wiphy->cipher_suites = priv->cipher_suites;
  71. wiphy->n_cipher_suites = i;
  72. wiphy->rts_threshold = priv->rts_thresh;
  73. if (!priv->has_mwo)
  74. wiphy->frag_threshold = priv->frag_thresh;
  75. return wiphy_register(wiphy);
  76. }
  77. static int orinoco_change_vif(struct wiphy *wiphy, struct net_device *dev,
  78. enum nl80211_iftype type, u32 *flags,
  79. struct vif_params *params)
  80. {
  81. struct orinoco_private *priv = wiphy_priv(wiphy);
  82. int err = 0;
  83. unsigned long lock;
  84. if (orinoco_lock(priv, &lock) != 0)
  85. return -EBUSY;
  86. switch (type) {
  87. case NL80211_IFTYPE_ADHOC:
  88. if (!priv->has_ibss && !priv->has_port3)
  89. err = -EINVAL;
  90. break;
  91. case NL80211_IFTYPE_STATION:
  92. break;
  93. case NL80211_IFTYPE_MONITOR:
  94. if (priv->broken_monitor && !force_monitor) {
  95. printk(KERN_WARNING "%s: Monitor mode support is "
  96. "buggy in this firmware, not enabling\n",
  97. wiphy_name(wiphy));
  98. err = -EINVAL;
  99. }
  100. break;
  101. default:
  102. err = -EINVAL;
  103. }
  104. if (!err) {
  105. priv->iw_mode = type;
  106. set_port_type(priv);
  107. err = orinoco_commit(priv);
  108. }
  109. orinoco_unlock(priv, &lock);
  110. return err;
  111. }
  112. static int orinoco_scan(struct wiphy *wiphy, struct net_device *dev,
  113. struct cfg80211_scan_request *request)
  114. {
  115. struct orinoco_private *priv = wiphy_priv(wiphy);
  116. int err;
  117. if (!request)
  118. return -EINVAL;
  119. if (priv->scan_request && priv->scan_request != request)
  120. return -EBUSY;
  121. priv->scan_request = request;
  122. err = orinoco_hw_trigger_scan(priv, request->ssids);
  123. return err;
  124. }
  125. static int orinoco_set_channel(struct wiphy *wiphy,
  126. struct ieee80211_channel *chan,
  127. enum nl80211_channel_type channel_type)
  128. {
  129. struct orinoco_private *priv = wiphy_priv(wiphy);
  130. int err = 0;
  131. unsigned long flags;
  132. int channel;
  133. if (!chan)
  134. return -EINVAL;
  135. if (channel_type != NL80211_CHAN_NO_HT)
  136. return -EINVAL;
  137. if (chan->band != IEEE80211_BAND_2GHZ)
  138. return -EINVAL;
  139. channel = ieee80211_freq_to_dsss_chan(chan->center_freq);
  140. if ((channel < 1) || (channel > NUM_CHANNELS) ||
  141. !(priv->channel_mask & (1 << (channel-1))))
  142. return -EINVAL;
  143. if (orinoco_lock(priv, &flags) != 0)
  144. return -EBUSY;
  145. priv->channel = channel;
  146. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  147. /* Fast channel change - no commit if successful */
  148. hermes_t *hw = &priv->hw;
  149. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  150. HERMES_TEST_SET_CHANNEL,
  151. channel, NULL);
  152. }
  153. orinoco_unlock(priv, &flags);
  154. return err;
  155. }
  156. const struct cfg80211_ops orinoco_cfg_ops = {
  157. .change_virtual_intf = orinoco_change_vif,
  158. .set_channel = orinoco_set_channel,
  159. .scan = orinoco_scan,
  160. };