cfg.c 6.5 KB

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