cfg.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. printk(KERN_WARNING "%s: Monitor mode support is "
  98. "buggy in this firmware, not enabling\n",
  99. wiphy_name(wiphy));
  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, struct net_device *dev,
  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. return err;
  126. }
  127. static int orinoco_set_channel(struct wiphy *wiphy,
  128. struct net_device *netdev,
  129. struct ieee80211_channel *chan,
  130. enum nl80211_channel_type channel_type)
  131. {
  132. struct orinoco_private *priv = wiphy_priv(wiphy);
  133. int err = 0;
  134. unsigned long flags;
  135. int channel;
  136. if (!chan)
  137. return -EINVAL;
  138. if (channel_type != NL80211_CHAN_NO_HT)
  139. return -EINVAL;
  140. if (chan->band != IEEE80211_BAND_2GHZ)
  141. return -EINVAL;
  142. channel = ieee80211_freq_to_dsss_chan(chan->center_freq);
  143. if ((channel < 1) || (channel > NUM_CHANNELS) ||
  144. !(priv->channel_mask & (1 << (channel-1))))
  145. return -EINVAL;
  146. if (orinoco_lock(priv, &flags) != 0)
  147. return -EBUSY;
  148. priv->channel = channel;
  149. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  150. /* Fast channel change - no commit if successful */
  151. hermes_t *hw = &priv->hw;
  152. err = hw->ops->cmd_wait(hw, HERMES_CMD_TEST |
  153. HERMES_TEST_SET_CHANNEL,
  154. channel, NULL);
  155. }
  156. orinoco_unlock(priv, &flags);
  157. return err;
  158. }
  159. static int orinoco_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  160. {
  161. struct orinoco_private *priv = wiphy_priv(wiphy);
  162. int frag_value = -1;
  163. int rts_value = -1;
  164. int err = 0;
  165. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  166. /* Setting short retry not supported */
  167. err = -EINVAL;
  168. }
  169. if (changed & WIPHY_PARAM_RETRY_LONG) {
  170. /* Setting long retry not supported */
  171. err = -EINVAL;
  172. }
  173. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  174. /* Set fragmentation */
  175. if (priv->has_mwo) {
  176. if (wiphy->frag_threshold < 0)
  177. frag_value = 0;
  178. else {
  179. printk(KERN_WARNING "%s: Fixed fragmentation "
  180. "is not supported on this firmware. "
  181. "Using MWO robust instead.\n",
  182. priv->ndev->name);
  183. frag_value = 1;
  184. }
  185. } else {
  186. if (wiphy->frag_threshold < 0)
  187. frag_value = 2346;
  188. else if ((wiphy->frag_threshold < 257) ||
  189. (wiphy->frag_threshold > 2347))
  190. err = -EINVAL;
  191. else
  192. /* cfg80211 value is 257-2347 (odd only)
  193. * orinoco rid has range 256-2346 (even only) */
  194. frag_value = wiphy->frag_threshold & ~0x1;
  195. }
  196. }
  197. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  198. /* Set RTS.
  199. *
  200. * Prism documentation suggests default of 2432,
  201. * and a range of 0-3000.
  202. *
  203. * Current implementation uses 2347 as the default and
  204. * the upper limit.
  205. */
  206. if (wiphy->rts_threshold < 0)
  207. rts_value = 2347;
  208. else if (wiphy->rts_threshold > 2347)
  209. err = -EINVAL;
  210. else
  211. rts_value = wiphy->rts_threshold;
  212. }
  213. if (!err) {
  214. unsigned long flags;
  215. if (orinoco_lock(priv, &flags) != 0)
  216. return -EBUSY;
  217. if (frag_value >= 0) {
  218. if (priv->has_mwo)
  219. priv->mwo_robust = frag_value;
  220. else
  221. priv->frag_thresh = frag_value;
  222. }
  223. if (rts_value >= 0)
  224. priv->rts_thresh = rts_value;
  225. err = orinoco_commit(priv);
  226. orinoco_unlock(priv, &flags);
  227. }
  228. return err;
  229. }
  230. const struct cfg80211_ops orinoco_cfg_ops = {
  231. .change_virtual_intf = orinoco_change_vif,
  232. .set_channel = orinoco_set_channel,
  233. .scan = orinoco_scan,
  234. .set_wiphy_params = orinoco_set_wiphy_params,
  235. };