cfg.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 + 1;
  75. wiphy->retry_short = priv->short_retry_limit;
  76. wiphy->retry_long = priv->long_retry_limit;
  77. return wiphy_register(wiphy);
  78. }
  79. static int orinoco_change_vif(struct wiphy *wiphy, struct net_device *dev,
  80. enum nl80211_iftype type, u32 *flags,
  81. struct vif_params *params)
  82. {
  83. struct orinoco_private *priv = wiphy_priv(wiphy);
  84. int err = 0;
  85. unsigned long lock;
  86. if (orinoco_lock(priv, &lock) != 0)
  87. return -EBUSY;
  88. switch (type) {
  89. case NL80211_IFTYPE_ADHOC:
  90. if (!priv->has_ibss && !priv->has_port3)
  91. err = -EINVAL;
  92. break;
  93. case NL80211_IFTYPE_STATION:
  94. break;
  95. case NL80211_IFTYPE_MONITOR:
  96. if (priv->broken_monitor && !force_monitor) {
  97. wiphy_warn(wiphy,
  98. "Monitor mode support is buggy in this firmware, not enabling\n");
  99. err = -EINVAL;
  100. }
  101. break;
  102. default:
  103. err = -EINVAL;
  104. }
  105. if (!err) {
  106. priv->iw_mode = type;
  107. set_port_type(priv);
  108. err = orinoco_commit(priv);
  109. }
  110. orinoco_unlock(priv, &lock);
  111. return err;
  112. }
  113. static int orinoco_scan(struct wiphy *wiphy, struct net_device *dev,
  114. struct cfg80211_scan_request *request)
  115. {
  116. struct orinoco_private *priv = wiphy_priv(wiphy);
  117. int err;
  118. if (!request)
  119. return -EINVAL;
  120. if (priv->scan_request && priv->scan_request != request)
  121. return -EBUSY;
  122. priv->scan_request = request;
  123. err = orinoco_hw_trigger_scan(priv, request->ssids);
  124. /* On error the we aren't processing the request */
  125. if (err)
  126. priv->scan_request = NULL;
  127. return err;
  128. }
  129. static int orinoco_set_channel(struct wiphy *wiphy,
  130. struct net_device *netdev,
  131. struct ieee80211_channel *chan,
  132. enum nl80211_channel_type channel_type)
  133. {
  134. struct orinoco_private *priv = wiphy_priv(wiphy);
  135. int err = 0;
  136. unsigned long flags;
  137. int channel;
  138. if (!chan)
  139. return -EINVAL;
  140. if (channel_type != NL80211_CHAN_NO_HT)
  141. return -EINVAL;
  142. if (chan->band != IEEE80211_BAND_2GHZ)
  143. return -EINVAL;
  144. channel = ieee80211_freq_to_dsss_chan(chan->center_freq);
  145. if ((channel < 1) || (channel > NUM_CHANNELS) ||
  146. !(priv->channel_mask & (1 << (channel - 1))))
  147. return -EINVAL;
  148. if (orinoco_lock(priv, &flags) != 0)
  149. return -EBUSY;
  150. priv->channel = channel;
  151. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  152. /* Fast channel change - no commit if successful */
  153. struct hermes *hw = &priv->hw;
  154. err = hw->ops->cmd_wait(hw, HERMES_CMD_TEST |
  155. HERMES_TEST_SET_CHANNEL,
  156. channel, NULL);
  157. }
  158. orinoco_unlock(priv, &flags);
  159. return err;
  160. }
  161. static int orinoco_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  162. {
  163. struct orinoco_private *priv = wiphy_priv(wiphy);
  164. int frag_value = -1;
  165. int rts_value = -1;
  166. int err = 0;
  167. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  168. /* Setting short retry not supported */
  169. err = -EINVAL;
  170. }
  171. if (changed & WIPHY_PARAM_RETRY_LONG) {
  172. /* Setting long retry not supported */
  173. err = -EINVAL;
  174. }
  175. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  176. /* Set fragmentation */
  177. if (priv->has_mwo) {
  178. if (wiphy->frag_threshold < 0)
  179. frag_value = 0;
  180. else {
  181. printk(KERN_WARNING "%s: Fixed fragmentation "
  182. "is not supported on this firmware. "
  183. "Using MWO robust instead.\n",
  184. priv->ndev->name);
  185. frag_value = 1;
  186. }
  187. } else {
  188. if (wiphy->frag_threshold < 0)
  189. frag_value = 2346;
  190. else if ((wiphy->frag_threshold < 257) ||
  191. (wiphy->frag_threshold > 2347))
  192. err = -EINVAL;
  193. else
  194. /* cfg80211 value is 257-2347 (odd only)
  195. * orinoco rid has range 256-2346 (even only) */
  196. frag_value = wiphy->frag_threshold & ~0x1;
  197. }
  198. }
  199. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  200. /* Set RTS.
  201. *
  202. * Prism documentation suggests default of 2432,
  203. * and a range of 0-3000.
  204. *
  205. * Current implementation uses 2347 as the default and
  206. * the upper limit.
  207. */
  208. if (wiphy->rts_threshold < 0)
  209. rts_value = 2347;
  210. else if (wiphy->rts_threshold > 2347)
  211. err = -EINVAL;
  212. else
  213. rts_value = wiphy->rts_threshold;
  214. }
  215. if (!err) {
  216. unsigned long flags;
  217. if (orinoco_lock(priv, &flags) != 0)
  218. return -EBUSY;
  219. if (frag_value >= 0) {
  220. if (priv->has_mwo)
  221. priv->mwo_robust = frag_value;
  222. else
  223. priv->frag_thresh = frag_value;
  224. }
  225. if (rts_value >= 0)
  226. priv->rts_thresh = rts_value;
  227. err = orinoco_commit(priv);
  228. orinoco_unlock(priv, &flags);
  229. }
  230. return err;
  231. }
  232. const struct cfg80211_ops orinoco_cfg_ops = {
  233. .change_virtual_intf = orinoco_change_vif,
  234. .set_channel = orinoco_set_channel,
  235. .scan = orinoco_scan,
  236. .set_wiphy_params = orinoco_set_wiphy_params,
  237. };