main.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434
  1. /* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c)
  2. *
  3. * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
  4. * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
  5. *
  6. * Current maintainers (as of 29 September 2003) are:
  7. * Pavel Roskin <proski AT gnu.org>
  8. * and David Gibson <hermes AT gibson.dropbear.id.au>
  9. *
  10. * (C) Copyright David Gibson, IBM Corporation 2001-2003.
  11. * Copyright (C) 2000 David Gibson, Linuxcare Australia.
  12. * With some help from :
  13. * Copyright (C) 2001 Jean Tourrilhes, HP Labs
  14. * Copyright (C) 2001 Benjamin Herrenschmidt
  15. *
  16. * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
  17. *
  18. * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
  19. * AT fasta.fh-dortmund.de>
  20. * http://www.stud.fh-dortmund.de/~andy/wvlan/
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * The initial developer of the original code is David A. Hinds
  33. * <dahinds AT users.sourceforge.net>. Portions created by David
  34. * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
  35. * Reserved.
  36. *
  37. * Alternatively, the contents of this file may be used under the
  38. * terms of the GNU General Public License version 2 (the "GPL"), in
  39. * which case the provisions of the GPL are applicable instead of the
  40. * above. If you wish to allow the use of your version of this file
  41. * only under the terms of the GPL and not to allow others to use your
  42. * version of this file under the MPL, indicate your decision by
  43. * deleting the provisions above and replace them with the notice and
  44. * other provisions required by the GPL. If you do not delete the
  45. * provisions above, a recipient may use your version of this file
  46. * under either the MPL or the GPL. */
  47. /*
  48. * TODO
  49. * o Handle de-encapsulation within network layer, provide 802.11
  50. * headers (patch from Thomas 'Dent' Mirlacher)
  51. * o Fix possible races in SPY handling.
  52. * o Disconnect wireless extensions from fundamental configuration.
  53. * o (maybe) Software WEP support (patch from Stano Meduna).
  54. * o (maybe) Use multiple Tx buffers - driver handling queue
  55. * rather than firmware.
  56. */
  57. /* Locking and synchronization:
  58. *
  59. * The basic principle is that everything is serialized through a
  60. * single spinlock, priv->lock. The lock is used in user, bh and irq
  61. * context, so when taken outside hardirq context it should always be
  62. * taken with interrupts disabled. The lock protects both the
  63. * hardware and the struct orinoco_private.
  64. *
  65. * Another flag, priv->hw_unavailable indicates that the hardware is
  66. * unavailable for an extended period of time (e.g. suspended, or in
  67. * the middle of a hard reset). This flag is protected by the
  68. * spinlock. All code which touches the hardware should check the
  69. * flag after taking the lock, and if it is set, give up on whatever
  70. * they are doing and drop the lock again. The orinoco_lock()
  71. * function handles this (it unlocks and returns -EBUSY if
  72. * hw_unavailable is non-zero).
  73. */
  74. #define DRIVER_NAME "orinoco"
  75. #include <linux/module.h>
  76. #include <linux/kernel.h>
  77. #include <linux/init.h>
  78. #include <linux/delay.h>
  79. #include <linux/device.h>
  80. #include <linux/netdevice.h>
  81. #include <linux/etherdevice.h>
  82. #include <linux/ethtool.h>
  83. #include <linux/suspend.h>
  84. #include <linux/if_arp.h>
  85. #include <linux/wireless.h>
  86. #include <linux/ieee80211.h>
  87. #include <net/iw_handler.h>
  88. #include <net/cfg80211.h>
  89. #include "hermes_rid.h"
  90. #include "hermes_dld.h"
  91. #include "hw.h"
  92. #include "scan.h"
  93. #include "mic.h"
  94. #include "fw.h"
  95. #include "wext.h"
  96. #include "cfg.h"
  97. #include "main.h"
  98. #include "orinoco.h"
  99. /********************************************************************/
  100. /* Module information */
  101. /********************************************************************/
  102. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
  103. "David Gibson <hermes@gibson.dropbear.id.au>");
  104. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
  105. "and similar wireless cards");
  106. MODULE_LICENSE("Dual MPL/GPL");
  107. /* Level of debugging. Used in the macros in orinoco.h */
  108. #ifdef ORINOCO_DEBUG
  109. int orinoco_debug = ORINOCO_DEBUG;
  110. EXPORT_SYMBOL(orinoco_debug);
  111. module_param(orinoco_debug, int, 0644);
  112. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  113. #endif
  114. static int suppress_linkstatus; /* = 0 */
  115. module_param(suppress_linkstatus, bool, 0644);
  116. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  117. static int ignore_disconnect; /* = 0 */
  118. module_param(ignore_disconnect, int, 0644);
  119. MODULE_PARM_DESC(ignore_disconnect,
  120. "Don't report lost link to the network layer");
  121. int force_monitor; /* = 0 */
  122. module_param(force_monitor, int, 0644);
  123. MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
  124. /********************************************************************/
  125. /* Internal constants */
  126. /********************************************************************/
  127. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  128. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  129. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  130. #define ORINOCO_MIN_MTU 256
  131. #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
  132. #define MAX_IRQLOOPS_PER_IRQ 10
  133. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  134. * how many events the
  135. * device could
  136. * legitimately generate */
  137. #define DUMMY_FID 0xFFFF
  138. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  139. HERMES_MAX_MULTICAST : 0)*/
  140. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  141. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  142. | HERMES_EV_TX | HERMES_EV_TXEXC \
  143. | HERMES_EV_WTERR | HERMES_EV_INFO \
  144. | HERMES_EV_INFDROP)
  145. static const struct ethtool_ops orinoco_ethtool_ops;
  146. /********************************************************************/
  147. /* Data types */
  148. /********************************************************************/
  149. /* Beginning of the Tx descriptor, used in TxExc handling */
  150. struct hermes_txexc_data {
  151. struct hermes_tx_descriptor desc;
  152. __le16 frame_ctl;
  153. __le16 duration_id;
  154. u8 addr1[ETH_ALEN];
  155. } __attribute__ ((packed));
  156. /* Rx frame header except compatibility 802.3 header */
  157. struct hermes_rx_descriptor {
  158. /* Control */
  159. __le16 status;
  160. __le32 time;
  161. u8 silence;
  162. u8 signal;
  163. u8 rate;
  164. u8 rxflow;
  165. __le32 reserved;
  166. /* 802.11 header */
  167. __le16 frame_ctl;
  168. __le16 duration_id;
  169. u8 addr1[ETH_ALEN];
  170. u8 addr2[ETH_ALEN];
  171. u8 addr3[ETH_ALEN];
  172. __le16 seq_ctl;
  173. u8 addr4[ETH_ALEN];
  174. /* Data length */
  175. __le16 data_len;
  176. } __attribute__ ((packed));
  177. struct orinoco_rx_data {
  178. struct hermes_rx_descriptor *desc;
  179. struct sk_buff *skb;
  180. struct list_head list;
  181. };
  182. /********************************************************************/
  183. /* Function prototypes */
  184. /********************************************************************/
  185. static void __orinoco_set_multicast_list(struct net_device *dev);
  186. /********************************************************************/
  187. /* Internal helper functions */
  188. /********************************************************************/
  189. void set_port_type(struct orinoco_private *priv)
  190. {
  191. switch (priv->iw_mode) {
  192. case IW_MODE_INFRA:
  193. priv->port_type = 1;
  194. priv->createibss = 0;
  195. break;
  196. case IW_MODE_ADHOC:
  197. if (priv->prefer_port3) {
  198. priv->port_type = 3;
  199. priv->createibss = 0;
  200. } else {
  201. priv->port_type = priv->ibss_port;
  202. priv->createibss = 1;
  203. }
  204. break;
  205. case IW_MODE_MONITOR:
  206. priv->port_type = 3;
  207. priv->createibss = 0;
  208. break;
  209. default:
  210. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  211. priv->ndev->name);
  212. }
  213. }
  214. /********************************************************************/
  215. /* Device methods */
  216. /********************************************************************/
  217. static int orinoco_open(struct net_device *dev)
  218. {
  219. struct orinoco_private *priv = ndev_priv(dev);
  220. unsigned long flags;
  221. int err;
  222. if (orinoco_lock(priv, &flags) != 0)
  223. return -EBUSY;
  224. err = __orinoco_up(priv);
  225. if (!err)
  226. priv->open = 1;
  227. orinoco_unlock(priv, &flags);
  228. return err;
  229. }
  230. static int orinoco_stop(struct net_device *dev)
  231. {
  232. struct orinoco_private *priv = ndev_priv(dev);
  233. int err = 0;
  234. /* We mustn't use orinoco_lock() here, because we need to be
  235. able to close the interface even if hw_unavailable is set
  236. (e.g. as we're released after a PC Card removal) */
  237. spin_lock_irq(&priv->lock);
  238. priv->open = 0;
  239. err = __orinoco_down(priv);
  240. spin_unlock_irq(&priv->lock);
  241. return err;
  242. }
  243. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  244. {
  245. struct orinoco_private *priv = ndev_priv(dev);
  246. return &priv->stats;
  247. }
  248. static void orinoco_set_multicast_list(struct net_device *dev)
  249. {
  250. struct orinoco_private *priv = ndev_priv(dev);
  251. unsigned long flags;
  252. if (orinoco_lock(priv, &flags) != 0) {
  253. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  254. "called when hw_unavailable\n", dev->name);
  255. return;
  256. }
  257. __orinoco_set_multicast_list(dev);
  258. orinoco_unlock(priv, &flags);
  259. }
  260. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  261. {
  262. struct orinoco_private *priv = ndev_priv(dev);
  263. if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
  264. return -EINVAL;
  265. /* MTU + encapsulation + header length */
  266. if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
  267. (priv->nicbuf_size - ETH_HLEN))
  268. return -EINVAL;
  269. dev->mtu = new_mtu;
  270. return 0;
  271. }
  272. /********************************************************************/
  273. /* Tx path */
  274. /********************************************************************/
  275. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  276. {
  277. struct orinoco_private *priv = ndev_priv(dev);
  278. struct net_device_stats *stats = &priv->stats;
  279. hermes_t *hw = &priv->hw;
  280. int err = 0;
  281. u16 txfid = priv->txfid;
  282. struct ethhdr *eh;
  283. int tx_control;
  284. unsigned long flags;
  285. if (!netif_running(dev)) {
  286. printk(KERN_ERR "%s: Tx on stopped device!\n",
  287. dev->name);
  288. return NETDEV_TX_BUSY;
  289. }
  290. if (netif_queue_stopped(dev)) {
  291. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  292. dev->name);
  293. return NETDEV_TX_BUSY;
  294. }
  295. if (orinoco_lock(priv, &flags) != 0) {
  296. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  297. dev->name);
  298. return NETDEV_TX_BUSY;
  299. }
  300. if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
  301. /* Oops, the firmware hasn't established a connection,
  302. silently drop the packet (this seems to be the
  303. safest approach). */
  304. goto drop;
  305. }
  306. /* Check packet length */
  307. if (skb->len < ETH_HLEN)
  308. goto drop;
  309. tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
  310. if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
  311. tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
  312. HERMES_TXCTRL_MIC;
  313. if (priv->has_alt_txcntl) {
  314. /* WPA enabled firmwares have tx_cntl at the end of
  315. * the 802.11 header. So write zeroed descriptor and
  316. * 802.11 header at the same time
  317. */
  318. char desc[HERMES_802_3_OFFSET];
  319. __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
  320. memset(&desc, 0, sizeof(desc));
  321. *txcntl = cpu_to_le16(tx_control);
  322. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  323. txfid, 0);
  324. if (err) {
  325. if (net_ratelimit())
  326. printk(KERN_ERR "%s: Error %d writing Tx "
  327. "descriptor to BAP\n", dev->name, err);
  328. goto busy;
  329. }
  330. } else {
  331. struct hermes_tx_descriptor desc;
  332. memset(&desc, 0, sizeof(desc));
  333. desc.tx_control = cpu_to_le16(tx_control);
  334. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  335. txfid, 0);
  336. if (err) {
  337. if (net_ratelimit())
  338. printk(KERN_ERR "%s: Error %d writing Tx "
  339. "descriptor to BAP\n", dev->name, err);
  340. goto busy;
  341. }
  342. /* Clear the 802.11 header and data length fields - some
  343. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  344. * if this isn't done. */
  345. hermes_clear_words(hw, HERMES_DATA0,
  346. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  347. }
  348. eh = (struct ethhdr *)skb->data;
  349. /* Encapsulate Ethernet-II frames */
  350. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  351. struct header_struct {
  352. struct ethhdr eth; /* 802.3 header */
  353. u8 encap[6]; /* 802.2 header */
  354. } __attribute__ ((packed)) hdr;
  355. /* Strip destination and source from the data */
  356. skb_pull(skb, 2 * ETH_ALEN);
  357. /* And move them to a separate header */
  358. memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
  359. hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
  360. memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
  361. /* Insert the SNAP header */
  362. if (skb_headroom(skb) < sizeof(hdr)) {
  363. printk(KERN_ERR
  364. "%s: Not enough headroom for 802.2 headers %d\n",
  365. dev->name, skb_headroom(skb));
  366. goto drop;
  367. }
  368. eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
  369. memcpy(eh, &hdr, sizeof(hdr));
  370. }
  371. err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
  372. txfid, HERMES_802_3_OFFSET);
  373. if (err) {
  374. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  375. dev->name, err);
  376. goto busy;
  377. }
  378. /* Calculate Michael MIC */
  379. if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
  380. u8 mic_buf[MICHAEL_MIC_LEN + 1];
  381. u8 *mic;
  382. size_t offset;
  383. size_t len;
  384. if (skb->len % 2) {
  385. /* MIC start is on an odd boundary */
  386. mic_buf[0] = skb->data[skb->len - 1];
  387. mic = &mic_buf[1];
  388. offset = skb->len - 1;
  389. len = MICHAEL_MIC_LEN + 1;
  390. } else {
  391. mic = &mic_buf[0];
  392. offset = skb->len;
  393. len = MICHAEL_MIC_LEN;
  394. }
  395. orinoco_mic(priv->tx_tfm_mic,
  396. priv->tkip_key[priv->tx_key].tx_mic,
  397. eh->h_dest, eh->h_source, 0 /* priority */,
  398. skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
  399. /* Write the MIC */
  400. err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
  401. txfid, HERMES_802_3_OFFSET + offset);
  402. if (err) {
  403. printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
  404. dev->name, err);
  405. goto busy;
  406. }
  407. }
  408. /* Finally, we actually initiate the send */
  409. netif_stop_queue(dev);
  410. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  411. txfid, NULL);
  412. if (err) {
  413. netif_start_queue(dev);
  414. if (net_ratelimit())
  415. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  416. dev->name, err);
  417. goto busy;
  418. }
  419. dev->trans_start = jiffies;
  420. stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
  421. goto ok;
  422. drop:
  423. stats->tx_errors++;
  424. stats->tx_dropped++;
  425. ok:
  426. orinoco_unlock(priv, &flags);
  427. dev_kfree_skb(skb);
  428. return NETDEV_TX_OK;
  429. busy:
  430. if (err == -EIO)
  431. schedule_work(&priv->reset_work);
  432. orinoco_unlock(priv, &flags);
  433. return NETDEV_TX_BUSY;
  434. }
  435. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  436. {
  437. struct orinoco_private *priv = ndev_priv(dev);
  438. u16 fid = hermes_read_regn(hw, ALLOCFID);
  439. if (fid != priv->txfid) {
  440. if (fid != DUMMY_FID)
  441. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  442. dev->name, fid);
  443. return;
  444. }
  445. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  446. }
  447. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  448. {
  449. struct orinoco_private *priv = ndev_priv(dev);
  450. struct net_device_stats *stats = &priv->stats;
  451. stats->tx_packets++;
  452. netif_wake_queue(dev);
  453. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  454. }
  455. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  456. {
  457. struct orinoco_private *priv = ndev_priv(dev);
  458. struct net_device_stats *stats = &priv->stats;
  459. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  460. u16 status;
  461. struct hermes_txexc_data hdr;
  462. int err = 0;
  463. if (fid == DUMMY_FID)
  464. return; /* Nothing's really happened */
  465. /* Read part of the frame header - we need status and addr1 */
  466. err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
  467. sizeof(struct hermes_txexc_data),
  468. fid, 0);
  469. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  470. stats->tx_errors++;
  471. if (err) {
  472. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  473. "(FID=%04X error %d)\n",
  474. dev->name, fid, err);
  475. return;
  476. }
  477. DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
  478. err, fid);
  479. /* We produce a TXDROP event only for retry or lifetime
  480. * exceeded, because that's the only status that really mean
  481. * that this particular node went away.
  482. * Other errors means that *we* screwed up. - Jean II */
  483. status = le16_to_cpu(hdr.desc.status);
  484. if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
  485. union iwreq_data wrqu;
  486. /* Copy 802.11 dest address.
  487. * We use the 802.11 header because the frame may
  488. * not be 802.3 or may be mangled...
  489. * In Ad-Hoc mode, it will be the node address.
  490. * In managed mode, it will be most likely the AP addr
  491. * User space will figure out how to convert it to
  492. * whatever it needs (IP address or else).
  493. * - Jean II */
  494. memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
  495. wrqu.addr.sa_family = ARPHRD_ETHER;
  496. /* Send event to user space */
  497. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  498. }
  499. netif_wake_queue(dev);
  500. }
  501. static void orinoco_tx_timeout(struct net_device *dev)
  502. {
  503. struct orinoco_private *priv = ndev_priv(dev);
  504. struct net_device_stats *stats = &priv->stats;
  505. struct hermes *hw = &priv->hw;
  506. printk(KERN_WARNING "%s: Tx timeout! "
  507. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  508. dev->name, hermes_read_regn(hw, ALLOCFID),
  509. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  510. stats->tx_errors++;
  511. schedule_work(&priv->reset_work);
  512. }
  513. /********************************************************************/
  514. /* Rx path (data frames) */
  515. /********************************************************************/
  516. /* Does the frame have a SNAP header indicating it should be
  517. * de-encapsulated to Ethernet-II? */
  518. static inline int is_ethersnap(void *_hdr)
  519. {
  520. u8 *hdr = _hdr;
  521. /* We de-encapsulate all packets which, a) have SNAP headers
  522. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  523. * and where b) the OUI of the SNAP header is 00:00:00 or
  524. * 00:00:f8 - we need both because different APs appear to use
  525. * different OUIs for some reason */
  526. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  527. && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
  528. }
  529. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  530. int level, int noise)
  531. {
  532. struct iw_quality wstats;
  533. wstats.level = level - 0x95;
  534. wstats.noise = noise - 0x95;
  535. wstats.qual = (level > noise) ? (level - noise) : 0;
  536. wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  537. /* Update spy records */
  538. wireless_spy_update(dev, mac, &wstats);
  539. }
  540. static void orinoco_stat_gather(struct net_device *dev,
  541. struct sk_buff *skb,
  542. struct hermes_rx_descriptor *desc)
  543. {
  544. struct orinoco_private *priv = ndev_priv(dev);
  545. /* Using spy support with lots of Rx packets, like in an
  546. * infrastructure (AP), will really slow down everything, because
  547. * the MAC address must be compared to each entry of the spy list.
  548. * If the user really asks for it (set some address in the
  549. * spy list), we do it, but he will pay the price.
  550. * Note that to get here, you need both WIRELESS_SPY
  551. * compiled in AND some addresses in the list !!!
  552. */
  553. /* Note : gcc will optimise the whole section away if
  554. * WIRELESS_SPY is not defined... - Jean II */
  555. if (SPY_NUMBER(priv)) {
  556. orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
  557. desc->signal, desc->silence);
  558. }
  559. }
  560. /*
  561. * orinoco_rx_monitor - handle received monitor frames.
  562. *
  563. * Arguments:
  564. * dev network device
  565. * rxfid received FID
  566. * desc rx descriptor of the frame
  567. *
  568. * Call context: interrupt
  569. */
  570. static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
  571. struct hermes_rx_descriptor *desc)
  572. {
  573. u32 hdrlen = 30; /* return full header by default */
  574. u32 datalen = 0;
  575. u16 fc;
  576. int err;
  577. int len;
  578. struct sk_buff *skb;
  579. struct orinoco_private *priv = ndev_priv(dev);
  580. struct net_device_stats *stats = &priv->stats;
  581. hermes_t *hw = &priv->hw;
  582. len = le16_to_cpu(desc->data_len);
  583. /* Determine the size of the header and the data */
  584. fc = le16_to_cpu(desc->frame_ctl);
  585. switch (fc & IEEE80211_FCTL_FTYPE) {
  586. case IEEE80211_FTYPE_DATA:
  587. if ((fc & IEEE80211_FCTL_TODS)
  588. && (fc & IEEE80211_FCTL_FROMDS))
  589. hdrlen = 30;
  590. else
  591. hdrlen = 24;
  592. datalen = len;
  593. break;
  594. case IEEE80211_FTYPE_MGMT:
  595. hdrlen = 24;
  596. datalen = len;
  597. break;
  598. case IEEE80211_FTYPE_CTL:
  599. switch (fc & IEEE80211_FCTL_STYPE) {
  600. case IEEE80211_STYPE_PSPOLL:
  601. case IEEE80211_STYPE_RTS:
  602. case IEEE80211_STYPE_CFEND:
  603. case IEEE80211_STYPE_CFENDACK:
  604. hdrlen = 16;
  605. break;
  606. case IEEE80211_STYPE_CTS:
  607. case IEEE80211_STYPE_ACK:
  608. hdrlen = 10;
  609. break;
  610. }
  611. break;
  612. default:
  613. /* Unknown frame type */
  614. break;
  615. }
  616. /* sanity check the length */
  617. if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
  618. printk(KERN_DEBUG "%s: oversized monitor frame, "
  619. "data length = %d\n", dev->name, datalen);
  620. stats->rx_length_errors++;
  621. goto update_stats;
  622. }
  623. skb = dev_alloc_skb(hdrlen + datalen);
  624. if (!skb) {
  625. printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
  626. dev->name);
  627. goto update_stats;
  628. }
  629. /* Copy the 802.11 header to the skb */
  630. memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
  631. skb_reset_mac_header(skb);
  632. /* If any, copy the data from the card to the skb */
  633. if (datalen > 0) {
  634. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
  635. ALIGN(datalen, 2), rxfid,
  636. HERMES_802_2_OFFSET);
  637. if (err) {
  638. printk(KERN_ERR "%s: error %d reading monitor frame\n",
  639. dev->name, err);
  640. goto drop;
  641. }
  642. }
  643. skb->dev = dev;
  644. skb->ip_summed = CHECKSUM_NONE;
  645. skb->pkt_type = PACKET_OTHERHOST;
  646. skb->protocol = cpu_to_be16(ETH_P_802_2);
  647. stats->rx_packets++;
  648. stats->rx_bytes += skb->len;
  649. netif_rx(skb);
  650. return;
  651. drop:
  652. dev_kfree_skb_irq(skb);
  653. update_stats:
  654. stats->rx_errors++;
  655. stats->rx_dropped++;
  656. }
  657. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  658. {
  659. struct orinoco_private *priv = ndev_priv(dev);
  660. struct net_device_stats *stats = &priv->stats;
  661. struct iw_statistics *wstats = &priv->wstats;
  662. struct sk_buff *skb = NULL;
  663. u16 rxfid, status;
  664. int length;
  665. struct hermes_rx_descriptor *desc;
  666. struct orinoco_rx_data *rx_data;
  667. int err;
  668. desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
  669. if (!desc) {
  670. printk(KERN_WARNING
  671. "%s: Can't allocate space for RX descriptor\n",
  672. dev->name);
  673. goto update_stats;
  674. }
  675. rxfid = hermes_read_regn(hw, RXFID);
  676. err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
  677. rxfid, 0);
  678. if (err) {
  679. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  680. "Frame dropped.\n", dev->name, err);
  681. goto update_stats;
  682. }
  683. status = le16_to_cpu(desc->status);
  684. if (status & HERMES_RXSTAT_BADCRC) {
  685. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
  686. dev->name);
  687. stats->rx_crc_errors++;
  688. goto update_stats;
  689. }
  690. /* Handle frames in monitor mode */
  691. if (priv->iw_mode == IW_MODE_MONITOR) {
  692. orinoco_rx_monitor(dev, rxfid, desc);
  693. goto out;
  694. }
  695. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  696. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  697. dev->name);
  698. wstats->discard.code++;
  699. goto update_stats;
  700. }
  701. length = le16_to_cpu(desc->data_len);
  702. /* Sanity checks */
  703. if (length < 3) { /* No for even an 802.2 LLC header */
  704. /* At least on Symbol firmware with PCF we get quite a
  705. lot of these legitimately - Poll frames with no
  706. data. */
  707. goto out;
  708. }
  709. if (length > IEEE80211_MAX_DATA_LEN) {
  710. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  711. dev->name, length);
  712. stats->rx_length_errors++;
  713. goto update_stats;
  714. }
  715. /* Payload size does not include Michael MIC. Increase payload
  716. * size to read it together with the data. */
  717. if (status & HERMES_RXSTAT_MIC)
  718. length += MICHAEL_MIC_LEN;
  719. /* We need space for the packet data itself, plus an ethernet
  720. header, plus 2 bytes so we can align the IP header on a
  721. 32bit boundary, plus 1 byte so we can read in odd length
  722. packets from the card, which has an IO granularity of 16
  723. bits */
  724. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  725. if (!skb) {
  726. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  727. dev->name);
  728. goto update_stats;
  729. }
  730. /* We'll prepend the header, so reserve space for it. The worst
  731. case is no decapsulation, when 802.3 header is prepended and
  732. nothing is removed. 2 is for aligning the IP header. */
  733. skb_reserve(skb, ETH_HLEN + 2);
  734. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
  735. ALIGN(length, 2), rxfid,
  736. HERMES_802_2_OFFSET);
  737. if (err) {
  738. printk(KERN_ERR "%s: error %d reading frame. "
  739. "Frame dropped.\n", dev->name, err);
  740. goto drop;
  741. }
  742. /* Add desc and skb to rx queue */
  743. rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
  744. if (!rx_data) {
  745. printk(KERN_WARNING "%s: Can't allocate RX packet\n",
  746. dev->name);
  747. goto drop;
  748. }
  749. rx_data->desc = desc;
  750. rx_data->skb = skb;
  751. list_add_tail(&rx_data->list, &priv->rx_list);
  752. tasklet_schedule(&priv->rx_tasklet);
  753. return;
  754. drop:
  755. dev_kfree_skb_irq(skb);
  756. update_stats:
  757. stats->rx_errors++;
  758. stats->rx_dropped++;
  759. out:
  760. kfree(desc);
  761. }
  762. static void orinoco_rx(struct net_device *dev,
  763. struct hermes_rx_descriptor *desc,
  764. struct sk_buff *skb)
  765. {
  766. struct orinoco_private *priv = ndev_priv(dev);
  767. struct net_device_stats *stats = &priv->stats;
  768. u16 status, fc;
  769. int length;
  770. struct ethhdr *hdr;
  771. status = le16_to_cpu(desc->status);
  772. length = le16_to_cpu(desc->data_len);
  773. fc = le16_to_cpu(desc->frame_ctl);
  774. /* Calculate and check MIC */
  775. if (status & HERMES_RXSTAT_MIC) {
  776. int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
  777. HERMES_MIC_KEY_ID_SHIFT);
  778. u8 mic[MICHAEL_MIC_LEN];
  779. u8 *rxmic;
  780. u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
  781. desc->addr3 : desc->addr2;
  782. /* Extract Michael MIC from payload */
  783. rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
  784. skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
  785. length -= MICHAEL_MIC_LEN;
  786. orinoco_mic(priv->rx_tfm_mic,
  787. priv->tkip_key[key_id].rx_mic,
  788. desc->addr1,
  789. src,
  790. 0, /* priority or QoS? */
  791. skb->data,
  792. skb->len,
  793. &mic[0]);
  794. if (memcmp(mic, rxmic,
  795. MICHAEL_MIC_LEN)) {
  796. union iwreq_data wrqu;
  797. struct iw_michaelmicfailure wxmic;
  798. printk(KERN_WARNING "%s: "
  799. "Invalid Michael MIC in data frame from %pM, "
  800. "using key %i\n",
  801. dev->name, src, key_id);
  802. /* TODO: update stats */
  803. /* Notify userspace */
  804. memset(&wxmic, 0, sizeof(wxmic));
  805. wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
  806. wxmic.flags |= (desc->addr1[0] & 1) ?
  807. IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
  808. wxmic.src_addr.sa_family = ARPHRD_ETHER;
  809. memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
  810. (void) orinoco_hw_get_tkip_iv(priv, key_id,
  811. &wxmic.tsc[0]);
  812. memset(&wrqu, 0, sizeof(wrqu));
  813. wrqu.data.length = sizeof(wxmic);
  814. wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
  815. (char *) &wxmic);
  816. goto drop;
  817. }
  818. }
  819. /* Handle decapsulation
  820. * In most cases, the firmware tell us about SNAP frames.
  821. * For some reason, the SNAP frames sent by LinkSys APs
  822. * are not properly recognised by most firmwares.
  823. * So, check ourselves */
  824. if (length >= ENCAPS_OVERHEAD &&
  825. (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  826. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  827. is_ethersnap(skb->data))) {
  828. /* These indicate a SNAP within 802.2 LLC within
  829. 802.11 frame which we'll need to de-encapsulate to
  830. the original EthernetII frame. */
  831. hdr = (struct ethhdr *)skb_push(skb,
  832. ETH_HLEN - ENCAPS_OVERHEAD);
  833. } else {
  834. /* 802.3 frame - prepend 802.3 header as is */
  835. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
  836. hdr->h_proto = htons(length);
  837. }
  838. memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
  839. if (fc & IEEE80211_FCTL_FROMDS)
  840. memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
  841. else
  842. memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
  843. skb->protocol = eth_type_trans(skb, dev);
  844. skb->ip_summed = CHECKSUM_NONE;
  845. if (fc & IEEE80211_FCTL_TODS)
  846. skb->pkt_type = PACKET_OTHERHOST;
  847. /* Process the wireless stats if needed */
  848. orinoco_stat_gather(dev, skb, desc);
  849. /* Pass the packet to the networking stack */
  850. netif_rx(skb);
  851. stats->rx_packets++;
  852. stats->rx_bytes += length;
  853. return;
  854. drop:
  855. dev_kfree_skb(skb);
  856. stats->rx_errors++;
  857. stats->rx_dropped++;
  858. }
  859. static void orinoco_rx_isr_tasklet(unsigned long data)
  860. {
  861. struct orinoco_private *priv = (struct orinoco_private *) data;
  862. struct net_device *dev = priv->ndev;
  863. struct orinoco_rx_data *rx_data, *temp;
  864. struct hermes_rx_descriptor *desc;
  865. struct sk_buff *skb;
  866. unsigned long flags;
  867. /* orinoco_rx requires the driver lock, and we also need to
  868. * protect priv->rx_list, so just hold the lock over the
  869. * lot.
  870. *
  871. * If orinoco_lock fails, we've unplugged the card. In this
  872. * case just abort. */
  873. if (orinoco_lock(priv, &flags) != 0)
  874. return;
  875. /* extract desc and skb from queue */
  876. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  877. desc = rx_data->desc;
  878. skb = rx_data->skb;
  879. list_del(&rx_data->list);
  880. kfree(rx_data);
  881. orinoco_rx(dev, desc, skb);
  882. kfree(desc);
  883. }
  884. orinoco_unlock(priv, &flags);
  885. }
  886. /********************************************************************/
  887. /* Rx path (info frames) */
  888. /********************************************************************/
  889. static void print_linkstatus(struct net_device *dev, u16 status)
  890. {
  891. char *s;
  892. if (suppress_linkstatus)
  893. return;
  894. switch (status) {
  895. case HERMES_LINKSTATUS_NOT_CONNECTED:
  896. s = "Not Connected";
  897. break;
  898. case HERMES_LINKSTATUS_CONNECTED:
  899. s = "Connected";
  900. break;
  901. case HERMES_LINKSTATUS_DISCONNECTED:
  902. s = "Disconnected";
  903. break;
  904. case HERMES_LINKSTATUS_AP_CHANGE:
  905. s = "AP Changed";
  906. break;
  907. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  908. s = "AP Out of Range";
  909. break;
  910. case HERMES_LINKSTATUS_AP_IN_RANGE:
  911. s = "AP In Range";
  912. break;
  913. case HERMES_LINKSTATUS_ASSOC_FAILED:
  914. s = "Association Failed";
  915. break;
  916. default:
  917. s = "UNKNOWN";
  918. }
  919. printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
  920. dev->name, s, status);
  921. }
  922. /* Search scan results for requested BSSID, join it if found */
  923. static void orinoco_join_ap(struct work_struct *work)
  924. {
  925. struct orinoco_private *priv =
  926. container_of(work, struct orinoco_private, join_work);
  927. struct net_device *dev = priv->ndev;
  928. struct hermes *hw = &priv->hw;
  929. int err;
  930. unsigned long flags;
  931. struct join_req {
  932. u8 bssid[ETH_ALEN];
  933. __le16 channel;
  934. } __attribute__ ((packed)) req;
  935. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  936. struct prism2_scan_apinfo *atom = NULL;
  937. int offset = 4;
  938. int found = 0;
  939. u8 *buf;
  940. u16 len;
  941. /* Allocate buffer for scan results */
  942. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  943. if (!buf)
  944. return;
  945. if (orinoco_lock(priv, &flags) != 0)
  946. goto fail_lock;
  947. /* Sanity checks in case user changed something in the meantime */
  948. if (!priv->bssid_fixed)
  949. goto out;
  950. if (strlen(priv->desired_essid) == 0)
  951. goto out;
  952. /* Read scan results from the firmware */
  953. err = hermes_read_ltv(hw, USER_BAP,
  954. HERMES_RID_SCANRESULTSTABLE,
  955. MAX_SCAN_LEN, &len, buf);
  956. if (err) {
  957. printk(KERN_ERR "%s: Cannot read scan results\n",
  958. dev->name);
  959. goto out;
  960. }
  961. len = HERMES_RECLEN_TO_BYTES(len);
  962. /* Go through the scan results looking for the channel of the AP
  963. * we were requested to join */
  964. for (; offset + atom_len <= len; offset += atom_len) {
  965. atom = (struct prism2_scan_apinfo *) (buf + offset);
  966. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
  967. found = 1;
  968. break;
  969. }
  970. }
  971. if (!found) {
  972. DEBUG(1, "%s: Requested AP not found in scan results\n",
  973. dev->name);
  974. goto out;
  975. }
  976. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  977. req.channel = atom->channel; /* both are little-endian */
  978. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  979. &req);
  980. if (err)
  981. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  982. out:
  983. orinoco_unlock(priv, &flags);
  984. fail_lock:
  985. kfree(buf);
  986. }
  987. /* Send new BSSID to userspace */
  988. static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
  989. {
  990. struct net_device *dev = priv->ndev;
  991. struct hermes *hw = &priv->hw;
  992. union iwreq_data wrqu;
  993. int err;
  994. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  995. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  996. if (err != 0)
  997. return;
  998. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  999. /* Send event to user space */
  1000. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1001. }
  1002. static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
  1003. {
  1004. struct net_device *dev = priv->ndev;
  1005. struct hermes *hw = &priv->hw;
  1006. union iwreq_data wrqu;
  1007. int err;
  1008. u8 buf[88];
  1009. u8 *ie;
  1010. if (!priv->has_wpa)
  1011. return;
  1012. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
  1013. sizeof(buf), NULL, &buf);
  1014. if (err != 0)
  1015. return;
  1016. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1017. if (ie) {
  1018. int rem = sizeof(buf) - (ie - &buf[0]);
  1019. wrqu.data.length = ie[1] + 2;
  1020. if (wrqu.data.length > rem)
  1021. wrqu.data.length = rem;
  1022. if (wrqu.data.length)
  1023. /* Send event to user space */
  1024. wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
  1025. }
  1026. }
  1027. static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
  1028. {
  1029. struct net_device *dev = priv->ndev;
  1030. struct hermes *hw = &priv->hw;
  1031. union iwreq_data wrqu;
  1032. int err;
  1033. u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
  1034. u8 *ie;
  1035. if (!priv->has_wpa)
  1036. return;
  1037. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
  1038. sizeof(buf), NULL, &buf);
  1039. if (err != 0)
  1040. return;
  1041. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1042. if (ie) {
  1043. int rem = sizeof(buf) - (ie - &buf[0]);
  1044. wrqu.data.length = ie[1] + 2;
  1045. if (wrqu.data.length > rem)
  1046. wrqu.data.length = rem;
  1047. if (wrqu.data.length)
  1048. /* Send event to user space */
  1049. wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
  1050. }
  1051. }
  1052. static void orinoco_send_wevents(struct work_struct *work)
  1053. {
  1054. struct orinoco_private *priv =
  1055. container_of(work, struct orinoco_private, wevent_work);
  1056. unsigned long flags;
  1057. if (orinoco_lock(priv, &flags) != 0)
  1058. return;
  1059. orinoco_send_assocreqie_wevent(priv);
  1060. orinoco_send_assocrespie_wevent(priv);
  1061. orinoco_send_bssid_wevent(priv);
  1062. orinoco_unlock(priv, &flags);
  1063. }
  1064. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1065. {
  1066. struct orinoco_private *priv = ndev_priv(dev);
  1067. u16 infofid;
  1068. struct {
  1069. __le16 len;
  1070. __le16 type;
  1071. } __attribute__ ((packed)) info;
  1072. int len, type;
  1073. int err;
  1074. /* This is an answer to an INQUIRE command that we did earlier,
  1075. * or an information "event" generated by the card
  1076. * The controller return to us a pseudo frame containing
  1077. * the information in question - Jean II */
  1078. infofid = hermes_read_regn(hw, INFOFID);
  1079. /* Read the info frame header - don't try too hard */
  1080. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1081. infofid, 0);
  1082. if (err) {
  1083. printk(KERN_ERR "%s: error %d reading info frame. "
  1084. "Frame dropped.\n", dev->name, err);
  1085. return;
  1086. }
  1087. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1088. type = le16_to_cpu(info.type);
  1089. switch (type) {
  1090. case HERMES_INQ_TALLIES: {
  1091. struct hermes_tallies_frame tallies;
  1092. struct iw_statistics *wstats = &priv->wstats;
  1093. if (len > sizeof(tallies)) {
  1094. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1095. dev->name, len);
  1096. len = sizeof(tallies);
  1097. }
  1098. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1099. infofid, sizeof(info));
  1100. if (err)
  1101. break;
  1102. /* Increment our various counters */
  1103. /* wstats->discard.nwid - no wrong BSSID stuff */
  1104. wstats->discard.code +=
  1105. le16_to_cpu(tallies.RxWEPUndecryptable);
  1106. if (len == sizeof(tallies))
  1107. wstats->discard.code +=
  1108. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1109. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1110. wstats->discard.misc +=
  1111. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1112. wstats->discard.fragment +=
  1113. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1114. wstats->discard.retries +=
  1115. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1116. /* wstats->miss.beacon - no match */
  1117. }
  1118. break;
  1119. case HERMES_INQ_LINKSTATUS: {
  1120. struct hermes_linkstatus linkstatus;
  1121. u16 newstatus;
  1122. int connected;
  1123. if (priv->iw_mode == IW_MODE_MONITOR)
  1124. break;
  1125. if (len != sizeof(linkstatus)) {
  1126. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1127. dev->name, len);
  1128. break;
  1129. }
  1130. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1131. infofid, sizeof(info));
  1132. if (err)
  1133. break;
  1134. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1135. /* Symbol firmware uses "out of range" to signal that
  1136. * the hostscan frame can be requested. */
  1137. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1138. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1139. priv->has_hostscan && priv->scan_inprogress) {
  1140. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1141. break;
  1142. }
  1143. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1144. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1145. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1146. if (connected)
  1147. netif_carrier_on(dev);
  1148. else if (!ignore_disconnect)
  1149. netif_carrier_off(dev);
  1150. if (newstatus != priv->last_linkstatus) {
  1151. priv->last_linkstatus = newstatus;
  1152. print_linkstatus(dev, newstatus);
  1153. /* The info frame contains only one word which is the
  1154. * status (see hermes.h). The status is pretty boring
  1155. * in itself, that's why we export the new BSSID...
  1156. * Jean II */
  1157. schedule_work(&priv->wevent_work);
  1158. }
  1159. }
  1160. break;
  1161. case HERMES_INQ_SCAN:
  1162. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1163. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1164. schedule_work(&priv->join_work);
  1165. break;
  1166. }
  1167. /* fall through */
  1168. case HERMES_INQ_HOSTSCAN:
  1169. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1170. /* Result of a scanning. Contains information about
  1171. * cells in the vicinity - Jean II */
  1172. union iwreq_data wrqu;
  1173. unsigned char *buf;
  1174. /* Scan is no longer in progress */
  1175. priv->scan_inprogress = 0;
  1176. /* Sanity check */
  1177. if (len > 4096) {
  1178. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1179. dev->name, len);
  1180. break;
  1181. }
  1182. /* Allocate buffer for results */
  1183. buf = kmalloc(len, GFP_ATOMIC);
  1184. if (buf == NULL)
  1185. /* No memory, so can't printk()... */
  1186. break;
  1187. /* Read scan data */
  1188. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1189. infofid, sizeof(info));
  1190. if (err) {
  1191. kfree(buf);
  1192. break;
  1193. }
  1194. #ifdef ORINOCO_DEBUG
  1195. {
  1196. int i;
  1197. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1198. for (i = 1; i < (len * 2); i++)
  1199. printk(":%02X", buf[i]);
  1200. printk("]\n");
  1201. }
  1202. #endif /* ORINOCO_DEBUG */
  1203. if (orinoco_process_scan_results(priv, buf, len) == 0) {
  1204. /* Send an empty event to user space.
  1205. * We don't send the received data on the event because
  1206. * it would require us to do complex transcoding, and
  1207. * we want to minimise the work done in the irq handler
  1208. * Use a request to extract the data - Jean II */
  1209. wrqu.data.length = 0;
  1210. wrqu.data.flags = 0;
  1211. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1212. }
  1213. kfree(buf);
  1214. }
  1215. break;
  1216. case HERMES_INQ_CHANNELINFO:
  1217. {
  1218. struct agere_ext_scan_info *bss;
  1219. if (!priv->scan_inprogress) {
  1220. printk(KERN_DEBUG "%s: Got chaninfo without scan, "
  1221. "len=%d\n", dev->name, len);
  1222. break;
  1223. }
  1224. /* An empty result indicates that the scan is complete */
  1225. if (len == 0) {
  1226. union iwreq_data wrqu;
  1227. /* Scan is no longer in progress */
  1228. priv->scan_inprogress = 0;
  1229. wrqu.data.length = 0;
  1230. wrqu.data.flags = 0;
  1231. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1232. break;
  1233. }
  1234. /* Sanity check */
  1235. else if (len > sizeof(*bss)) {
  1236. printk(KERN_WARNING
  1237. "%s: Ext scan results too large (%d bytes). "
  1238. "Truncating results to %zd bytes.\n",
  1239. dev->name, len, sizeof(*bss));
  1240. len = sizeof(*bss);
  1241. } else if (len < (offsetof(struct agere_ext_scan_info,
  1242. data) + 2)) {
  1243. /* Drop this result now so we don't have to
  1244. * keep checking later */
  1245. printk(KERN_WARNING
  1246. "%s: Ext scan results too short (%d bytes)\n",
  1247. dev->name, len);
  1248. break;
  1249. }
  1250. bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
  1251. if (bss == NULL)
  1252. break;
  1253. /* Read scan data */
  1254. err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
  1255. infofid, sizeof(info));
  1256. if (err) {
  1257. kfree(bss);
  1258. break;
  1259. }
  1260. orinoco_add_ext_scan_result(priv, bss);
  1261. kfree(bss);
  1262. break;
  1263. }
  1264. case HERMES_INQ_SEC_STAT_AGERE:
  1265. /* Security status (Agere specific) */
  1266. /* Ignore this frame for now */
  1267. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1268. break;
  1269. /* fall through */
  1270. default:
  1271. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1272. "type 0x%04x, length %d\n", dev->name, type, len);
  1273. /* We don't actually do anything about it */
  1274. break;
  1275. }
  1276. }
  1277. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1278. {
  1279. if (net_ratelimit())
  1280. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1281. }
  1282. /********************************************************************/
  1283. /* Internal hardware control routines */
  1284. /********************************************************************/
  1285. int __orinoco_up(struct orinoco_private *priv)
  1286. {
  1287. struct net_device *dev = priv->ndev;
  1288. struct hermes *hw = &priv->hw;
  1289. int err;
  1290. netif_carrier_off(dev); /* just to make sure */
  1291. err = __orinoco_program_rids(dev);
  1292. if (err) {
  1293. printk(KERN_ERR "%s: Error %d configuring card\n",
  1294. dev->name, err);
  1295. return err;
  1296. }
  1297. /* Fire things up again */
  1298. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1299. err = hermes_enable_port(hw, 0);
  1300. if (err) {
  1301. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1302. dev->name, err);
  1303. return err;
  1304. }
  1305. netif_start_queue(dev);
  1306. return 0;
  1307. }
  1308. EXPORT_SYMBOL(__orinoco_up);
  1309. int __orinoco_down(struct orinoco_private *priv)
  1310. {
  1311. struct net_device *dev = priv->ndev;
  1312. struct hermes *hw = &priv->hw;
  1313. int err;
  1314. netif_stop_queue(dev);
  1315. if (!priv->hw_unavailable) {
  1316. if (!priv->broken_disableport) {
  1317. err = hermes_disable_port(hw, 0);
  1318. if (err) {
  1319. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1320. * to have problems disabling the port, oh
  1321. * well, too bad. */
  1322. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1323. dev->name, err);
  1324. priv->broken_disableport = 1;
  1325. }
  1326. }
  1327. hermes_set_irqmask(hw, 0);
  1328. hermes_write_regn(hw, EVACK, 0xffff);
  1329. }
  1330. /* firmware will have to reassociate */
  1331. netif_carrier_off(dev);
  1332. priv->last_linkstatus = 0xffff;
  1333. return 0;
  1334. }
  1335. EXPORT_SYMBOL(__orinoco_down);
  1336. int orinoco_reinit_firmware(struct orinoco_private *priv)
  1337. {
  1338. struct hermes *hw = &priv->hw;
  1339. int err;
  1340. err = hermes_init(hw);
  1341. if (priv->do_fw_download && !err) {
  1342. err = orinoco_download(priv);
  1343. if (err)
  1344. priv->do_fw_download = 0;
  1345. }
  1346. if (!err)
  1347. err = orinoco_hw_allocate_fid(priv);
  1348. return err;
  1349. }
  1350. EXPORT_SYMBOL(orinoco_reinit_firmware);
  1351. int __orinoco_program_rids(struct net_device *dev)
  1352. {
  1353. struct orinoco_private *priv = ndev_priv(dev);
  1354. hermes_t *hw = &priv->hw;
  1355. int err;
  1356. struct hermes_idstring idbuf;
  1357. /* Set the MAC address */
  1358. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1359. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1360. if (err) {
  1361. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1362. dev->name, err);
  1363. return err;
  1364. }
  1365. /* Set up the link mode */
  1366. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1367. priv->port_type);
  1368. if (err) {
  1369. printk(KERN_ERR "%s: Error %d setting port type\n",
  1370. dev->name, err);
  1371. return err;
  1372. }
  1373. /* Set the channel/frequency */
  1374. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  1375. err = hermes_write_wordrec(hw, USER_BAP,
  1376. HERMES_RID_CNFOWNCHANNEL,
  1377. priv->channel);
  1378. if (err) {
  1379. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  1380. dev->name, err, priv->channel);
  1381. return err;
  1382. }
  1383. }
  1384. if (priv->has_ibss) {
  1385. u16 createibss;
  1386. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1387. printk(KERN_WARNING "%s: This firmware requires an "
  1388. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1389. /* With wvlan_cs, in this case, we would crash.
  1390. * hopefully, this driver will behave better...
  1391. * Jean II */
  1392. createibss = 0;
  1393. } else {
  1394. createibss = priv->createibss;
  1395. }
  1396. err = hermes_write_wordrec(hw, USER_BAP,
  1397. HERMES_RID_CNFCREATEIBSS,
  1398. createibss);
  1399. if (err) {
  1400. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1401. dev->name, err);
  1402. return err;
  1403. }
  1404. }
  1405. /* Set the desired BSSID */
  1406. err = __orinoco_hw_set_wap(priv);
  1407. if (err) {
  1408. printk(KERN_ERR "%s: Error %d setting AP address\n",
  1409. dev->name, err);
  1410. return err;
  1411. }
  1412. /* Set the desired ESSID */
  1413. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1414. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1415. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1416. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1417. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1418. &idbuf);
  1419. if (err) {
  1420. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1421. dev->name, err);
  1422. return err;
  1423. }
  1424. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1425. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1426. &idbuf);
  1427. if (err) {
  1428. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1429. dev->name, err);
  1430. return err;
  1431. }
  1432. /* Set the station name */
  1433. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1434. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1435. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1436. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1437. &idbuf);
  1438. if (err) {
  1439. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1440. dev->name, err);
  1441. return err;
  1442. }
  1443. /* Set AP density */
  1444. if (priv->has_sensitivity) {
  1445. err = hermes_write_wordrec(hw, USER_BAP,
  1446. HERMES_RID_CNFSYSTEMSCALE,
  1447. priv->ap_density);
  1448. if (err) {
  1449. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1450. "Disabling sensitivity control\n",
  1451. dev->name, err);
  1452. priv->has_sensitivity = 0;
  1453. }
  1454. }
  1455. /* Set RTS threshold */
  1456. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1457. priv->rts_thresh);
  1458. if (err) {
  1459. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1460. dev->name, err);
  1461. return err;
  1462. }
  1463. /* Set fragmentation threshold or MWO robustness */
  1464. if (priv->has_mwo)
  1465. err = hermes_write_wordrec(hw, USER_BAP,
  1466. HERMES_RID_CNFMWOROBUST_AGERE,
  1467. priv->mwo_robust);
  1468. else
  1469. err = hermes_write_wordrec(hw, USER_BAP,
  1470. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1471. priv->frag_thresh);
  1472. if (err) {
  1473. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1474. dev->name, err);
  1475. return err;
  1476. }
  1477. /* Set bitrate */
  1478. err = __orinoco_hw_set_bitrate(priv);
  1479. if (err) {
  1480. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1481. dev->name, err);
  1482. return err;
  1483. }
  1484. /* Set power management */
  1485. if (priv->has_pm) {
  1486. err = hermes_write_wordrec(hw, USER_BAP,
  1487. HERMES_RID_CNFPMENABLED,
  1488. priv->pm_on);
  1489. if (err) {
  1490. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1491. dev->name, err);
  1492. return err;
  1493. }
  1494. err = hermes_write_wordrec(hw, USER_BAP,
  1495. HERMES_RID_CNFMULTICASTRECEIVE,
  1496. priv->pm_mcast);
  1497. if (err) {
  1498. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1499. dev->name, err);
  1500. return err;
  1501. }
  1502. err = hermes_write_wordrec(hw, USER_BAP,
  1503. HERMES_RID_CNFMAXSLEEPDURATION,
  1504. priv->pm_period);
  1505. if (err) {
  1506. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1507. dev->name, err);
  1508. return err;
  1509. }
  1510. err = hermes_write_wordrec(hw, USER_BAP,
  1511. HERMES_RID_CNFPMHOLDOVERDURATION,
  1512. priv->pm_timeout);
  1513. if (err) {
  1514. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1515. dev->name, err);
  1516. return err;
  1517. }
  1518. }
  1519. /* Set preamble - only for Symbol so far... */
  1520. if (priv->has_preamble) {
  1521. err = hermes_write_wordrec(hw, USER_BAP,
  1522. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1523. priv->preamble);
  1524. if (err) {
  1525. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1526. dev->name, err);
  1527. return err;
  1528. }
  1529. }
  1530. /* Set up encryption */
  1531. if (priv->has_wep || priv->has_wpa) {
  1532. err = __orinoco_hw_setup_enc(priv);
  1533. if (err) {
  1534. printk(KERN_ERR "%s: Error %d activating encryption\n",
  1535. dev->name, err);
  1536. return err;
  1537. }
  1538. }
  1539. if (priv->iw_mode == IW_MODE_MONITOR) {
  1540. /* Enable monitor mode */
  1541. dev->type = ARPHRD_IEEE80211;
  1542. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1543. HERMES_TEST_MONITOR, 0, NULL);
  1544. } else {
  1545. /* Disable monitor mode */
  1546. dev->type = ARPHRD_ETHER;
  1547. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1548. HERMES_TEST_STOP, 0, NULL);
  1549. }
  1550. if (err)
  1551. return err;
  1552. /* Set promiscuity / multicast*/
  1553. priv->promiscuous = 0;
  1554. priv->mc_count = 0;
  1555. /* FIXME: what about netif_tx_lock */
  1556. __orinoco_set_multicast_list(dev);
  1557. return 0;
  1558. }
  1559. /* FIXME: return int? */
  1560. static void
  1561. __orinoco_set_multicast_list(struct net_device *dev)
  1562. {
  1563. struct orinoco_private *priv = ndev_priv(dev);
  1564. int err = 0;
  1565. int promisc, mc_count;
  1566. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1567. * into promiscuous mode and let the upper levels deal. */
  1568. if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1569. (dev->mc_count > MAX_MULTICAST(priv))) {
  1570. promisc = 1;
  1571. mc_count = 0;
  1572. } else {
  1573. promisc = 0;
  1574. mc_count = dev->mc_count;
  1575. }
  1576. err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
  1577. promisc);
  1578. }
  1579. /* This must be called from user context, without locks held - use
  1580. * schedule_work() */
  1581. void orinoco_reset(struct work_struct *work)
  1582. {
  1583. struct orinoco_private *priv =
  1584. container_of(work, struct orinoco_private, reset_work);
  1585. struct net_device *dev = priv->ndev;
  1586. struct hermes *hw = &priv->hw;
  1587. int err;
  1588. unsigned long flags;
  1589. if (orinoco_lock(priv, &flags) != 0)
  1590. /* When the hardware becomes available again, whatever
  1591. * detects that is responsible for re-initializing
  1592. * it. So no need for anything further */
  1593. return;
  1594. netif_stop_queue(dev);
  1595. /* Shut off interrupts. Depending on what state the hardware
  1596. * is in, this might not work, but we'll try anyway */
  1597. hermes_set_irqmask(hw, 0);
  1598. hermes_write_regn(hw, EVACK, 0xffff);
  1599. priv->hw_unavailable++;
  1600. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  1601. netif_carrier_off(dev);
  1602. orinoco_unlock(priv, &flags);
  1603. /* Scanning support: Cleanup of driver struct */
  1604. orinoco_clear_scan_results(priv, 0);
  1605. priv->scan_inprogress = 0;
  1606. if (priv->hard_reset) {
  1607. err = (*priv->hard_reset)(priv);
  1608. if (err) {
  1609. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  1610. "performing hard reset\n", dev->name, err);
  1611. goto disable;
  1612. }
  1613. }
  1614. err = orinoco_reinit_firmware(priv);
  1615. if (err) {
  1616. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  1617. dev->name, err);
  1618. goto disable;
  1619. }
  1620. /* This has to be called from user context */
  1621. spin_lock_irq(&priv->lock);
  1622. priv->hw_unavailable--;
  1623. /* priv->open or priv->hw_unavailable might have changed while
  1624. * we dropped the lock */
  1625. if (priv->open && (!priv->hw_unavailable)) {
  1626. err = __orinoco_up(priv);
  1627. if (err) {
  1628. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  1629. dev->name, err);
  1630. } else
  1631. dev->trans_start = jiffies;
  1632. }
  1633. spin_unlock_irq(&priv->lock);
  1634. return;
  1635. disable:
  1636. hermes_set_irqmask(hw, 0);
  1637. netif_device_detach(dev);
  1638. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  1639. }
  1640. /********************************************************************/
  1641. /* Interrupt handler */
  1642. /********************************************************************/
  1643. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  1644. {
  1645. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  1646. }
  1647. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  1648. {
  1649. /* This seems to happen a fair bit under load, but ignoring it
  1650. seems to work fine...*/
  1651. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  1652. dev->name);
  1653. }
  1654. irqreturn_t orinoco_interrupt(int irq, void *dev_id)
  1655. {
  1656. struct orinoco_private *priv = dev_id;
  1657. struct net_device *dev = priv->ndev;
  1658. hermes_t *hw = &priv->hw;
  1659. int count = MAX_IRQLOOPS_PER_IRQ;
  1660. u16 evstat, events;
  1661. /* These are used to detect a runaway interrupt situation.
  1662. *
  1663. * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  1664. * we panic and shut down the hardware
  1665. */
  1666. /* jiffies value the last time we were called */
  1667. static int last_irq_jiffy; /* = 0 */
  1668. static int loops_this_jiffy; /* = 0 */
  1669. unsigned long flags;
  1670. if (orinoco_lock(priv, &flags) != 0) {
  1671. /* If hw is unavailable - we don't know if the irq was
  1672. * for us or not */
  1673. return IRQ_HANDLED;
  1674. }
  1675. evstat = hermes_read_regn(hw, EVSTAT);
  1676. events = evstat & hw->inten;
  1677. if (!events) {
  1678. orinoco_unlock(priv, &flags);
  1679. return IRQ_NONE;
  1680. }
  1681. if (jiffies != last_irq_jiffy)
  1682. loops_this_jiffy = 0;
  1683. last_irq_jiffy = jiffies;
  1684. while (events && count--) {
  1685. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  1686. printk(KERN_WARNING "%s: IRQ handler is looping too "
  1687. "much! Resetting.\n", dev->name);
  1688. /* Disable interrupts for now */
  1689. hermes_set_irqmask(hw, 0);
  1690. schedule_work(&priv->reset_work);
  1691. break;
  1692. }
  1693. /* Check the card hasn't been removed */
  1694. if (!hermes_present(hw)) {
  1695. DEBUG(0, "orinoco_interrupt(): card removed\n");
  1696. break;
  1697. }
  1698. if (events & HERMES_EV_TICK)
  1699. __orinoco_ev_tick(dev, hw);
  1700. if (events & HERMES_EV_WTERR)
  1701. __orinoco_ev_wterr(dev, hw);
  1702. if (events & HERMES_EV_INFDROP)
  1703. __orinoco_ev_infdrop(dev, hw);
  1704. if (events & HERMES_EV_INFO)
  1705. __orinoco_ev_info(dev, hw);
  1706. if (events & HERMES_EV_RX)
  1707. __orinoco_ev_rx(dev, hw);
  1708. if (events & HERMES_EV_TXEXC)
  1709. __orinoco_ev_txexc(dev, hw);
  1710. if (events & HERMES_EV_TX)
  1711. __orinoco_ev_tx(dev, hw);
  1712. if (events & HERMES_EV_ALLOC)
  1713. __orinoco_ev_alloc(dev, hw);
  1714. hermes_write_regn(hw, EVACK, evstat);
  1715. evstat = hermes_read_regn(hw, EVSTAT);
  1716. events = evstat & hw->inten;
  1717. };
  1718. orinoco_unlock(priv, &flags);
  1719. return IRQ_HANDLED;
  1720. }
  1721. EXPORT_SYMBOL(orinoco_interrupt);
  1722. /********************************************************************/
  1723. /* Power management */
  1724. /********************************************************************/
  1725. #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
  1726. static int orinoco_pm_notifier(struct notifier_block *notifier,
  1727. unsigned long pm_event,
  1728. void *unused)
  1729. {
  1730. struct orinoco_private *priv = container_of(notifier,
  1731. struct orinoco_private,
  1732. pm_notifier);
  1733. /* All we need to do is cache the firmware before suspend, and
  1734. * release it when we come out.
  1735. *
  1736. * Only need to do this if we're downloading firmware. */
  1737. if (!priv->do_fw_download)
  1738. return NOTIFY_DONE;
  1739. switch (pm_event) {
  1740. case PM_HIBERNATION_PREPARE:
  1741. case PM_SUSPEND_PREPARE:
  1742. orinoco_cache_fw(priv, 0);
  1743. break;
  1744. case PM_POST_RESTORE:
  1745. /* Restore from hibernation failed. We need to clean
  1746. * up in exactly the same way, so fall through. */
  1747. case PM_POST_HIBERNATION:
  1748. case PM_POST_SUSPEND:
  1749. orinoco_uncache_fw(priv);
  1750. break;
  1751. case PM_RESTORE_PREPARE:
  1752. default:
  1753. break;
  1754. }
  1755. return NOTIFY_DONE;
  1756. }
  1757. static void orinoco_register_pm_notifier(struct orinoco_private *priv)
  1758. {
  1759. priv->pm_notifier.notifier_call = orinoco_pm_notifier;
  1760. register_pm_notifier(&priv->pm_notifier);
  1761. }
  1762. static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
  1763. {
  1764. unregister_pm_notifier(&priv->pm_notifier);
  1765. }
  1766. #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
  1767. #define orinoco_register_pm_notifier(priv) do { } while(0)
  1768. #define orinoco_unregister_pm_notifier(priv) do { } while(0)
  1769. #endif
  1770. /********************************************************************/
  1771. /* Initialization */
  1772. /********************************************************************/
  1773. int orinoco_init(struct orinoco_private *priv)
  1774. {
  1775. struct device *dev = priv->dev;
  1776. struct wiphy *wiphy = priv_to_wiphy(priv);
  1777. hermes_t *hw = &priv->hw;
  1778. int err = 0;
  1779. /* No need to lock, the hw_unavailable flag is already set in
  1780. * alloc_orinocodev() */
  1781. priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
  1782. /* Initialize the firmware */
  1783. err = hermes_init(hw);
  1784. if (err != 0) {
  1785. dev_err(dev, "Failed to initialize firmware (err = %d)\n",
  1786. err);
  1787. goto out;
  1788. }
  1789. err = determine_fw_capabilities(priv);
  1790. if (err != 0) {
  1791. dev_err(dev, "Incompatible firmware, aborting\n");
  1792. goto out;
  1793. }
  1794. if (priv->do_fw_download) {
  1795. #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
  1796. orinoco_cache_fw(priv, 0);
  1797. #endif
  1798. err = orinoco_download(priv);
  1799. if (err)
  1800. priv->do_fw_download = 0;
  1801. /* Check firmware version again */
  1802. err = determine_fw_capabilities(priv);
  1803. if (err != 0) {
  1804. dev_err(dev, "Incompatible firmware, aborting\n");
  1805. goto out;
  1806. }
  1807. }
  1808. if (priv->has_port3)
  1809. dev_info(dev, "Ad-hoc demo mode supported\n");
  1810. if (priv->has_ibss)
  1811. dev_info(dev, "IEEE standard IBSS ad-hoc mode supported\n");
  1812. if (priv->has_wep)
  1813. dev_info(dev, "WEP supported, %s-bit key\n",
  1814. priv->has_big_wep ? "104" : "40");
  1815. if (priv->has_wpa) {
  1816. dev_info(dev, "WPA-PSK supported\n");
  1817. if (orinoco_mic_init(priv)) {
  1818. dev_err(dev, "Failed to setup MIC crypto algorithm. "
  1819. "Disabling WPA support\n");
  1820. priv->has_wpa = 0;
  1821. }
  1822. }
  1823. /* Now we have the firmware capabilities, allocate appropiate
  1824. * sized scan buffers */
  1825. if (orinoco_bss_data_allocate(priv))
  1826. goto out;
  1827. orinoco_bss_data_init(priv);
  1828. err = orinoco_hw_read_card_settings(priv, wiphy->perm_addr);
  1829. if (err)
  1830. goto out;
  1831. err = orinoco_hw_allocate_fid(priv);
  1832. if (err) {
  1833. dev_err(dev, "Failed to allocate NIC buffer!\n");
  1834. goto out;
  1835. }
  1836. /* Set up the default configuration */
  1837. priv->iw_mode = IW_MODE_INFRA;
  1838. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  1839. priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
  1840. set_port_type(priv);
  1841. priv->channel = 0; /* use firmware default */
  1842. priv->promiscuous = 0;
  1843. priv->encode_alg = IW_ENCODE_ALG_NONE;
  1844. priv->tx_key = 0;
  1845. priv->wpa_enabled = 0;
  1846. priv->tkip_cm_active = 0;
  1847. priv->key_mgmt = 0;
  1848. priv->wpa_ie_len = 0;
  1849. priv->wpa_ie = NULL;
  1850. if (orinoco_wiphy_register(wiphy)) {
  1851. err = -ENODEV;
  1852. goto out;
  1853. }
  1854. /* Make the hardware available, as long as it hasn't been
  1855. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  1856. spin_lock_irq(&priv->lock);
  1857. priv->hw_unavailable--;
  1858. spin_unlock_irq(&priv->lock);
  1859. dev_dbg(dev, "Ready\n");
  1860. out:
  1861. return err;
  1862. }
  1863. EXPORT_SYMBOL(orinoco_init);
  1864. static const struct net_device_ops orinoco_netdev_ops = {
  1865. .ndo_open = orinoco_open,
  1866. .ndo_stop = orinoco_stop,
  1867. .ndo_start_xmit = orinoco_xmit,
  1868. .ndo_set_multicast_list = orinoco_set_multicast_list,
  1869. .ndo_change_mtu = orinoco_change_mtu,
  1870. .ndo_tx_timeout = orinoco_tx_timeout,
  1871. .ndo_get_stats = orinoco_get_stats,
  1872. };
  1873. /* Allocate private data.
  1874. *
  1875. * This driver has a number of structures associated with it
  1876. * netdev - Net device structure for each network interface
  1877. * wiphy - structure associated with wireless phy
  1878. * wireless_dev (wdev) - structure for each wireless interface
  1879. * hw - structure for hermes chip info
  1880. * card - card specific structure for use by the card driver
  1881. * (airport, orinoco_cs)
  1882. * priv - orinoco private data
  1883. * device - generic linux device structure
  1884. *
  1885. * +---------+ +---------+
  1886. * | wiphy | | netdev |
  1887. * | +-------+ | +-------+
  1888. * | | priv | | | wdev |
  1889. * | | +-----+ +-+-------+
  1890. * | | | hw |
  1891. * | +-+-----+
  1892. * | | card |
  1893. * +-+-------+
  1894. *
  1895. * priv has a link to netdev and device
  1896. * wdev has a link to wiphy
  1897. */
  1898. struct orinoco_private
  1899. *alloc_orinocodev(int sizeof_card,
  1900. struct device *device,
  1901. int (*hard_reset)(struct orinoco_private *),
  1902. int (*stop_fw)(struct orinoco_private *, int))
  1903. {
  1904. struct orinoco_private *priv;
  1905. struct wiphy *wiphy;
  1906. /* allocate wiphy
  1907. * NOTE: We only support a single virtual interface
  1908. * but this may change when monitor mode is added
  1909. */
  1910. wiphy = wiphy_new(&orinoco_cfg_ops,
  1911. sizeof(struct orinoco_private) + sizeof_card);
  1912. if (!wiphy)
  1913. return NULL;
  1914. priv = wiphy_priv(wiphy);
  1915. priv->dev = device;
  1916. if (sizeof_card)
  1917. priv->card = (void *)((unsigned long)priv
  1918. + sizeof(struct orinoco_private));
  1919. else
  1920. priv->card = NULL;
  1921. orinoco_wiphy_init(wiphy);
  1922. #ifdef WIRELESS_SPY
  1923. priv->wireless_data.spy_data = &priv->spy_data;
  1924. #endif
  1925. /* Set up default callbacks */
  1926. priv->hard_reset = hard_reset;
  1927. priv->stop_fw = stop_fw;
  1928. spin_lock_init(&priv->lock);
  1929. priv->open = 0;
  1930. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  1931. * before anything else touches the
  1932. * hardware */
  1933. INIT_WORK(&priv->reset_work, orinoco_reset);
  1934. INIT_WORK(&priv->join_work, orinoco_join_ap);
  1935. INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
  1936. INIT_LIST_HEAD(&priv->rx_list);
  1937. tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
  1938. (unsigned long) priv);
  1939. priv->last_linkstatus = 0xffff;
  1940. #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
  1941. priv->cached_pri_fw = NULL;
  1942. priv->cached_fw = NULL;
  1943. #endif
  1944. /* Register PM notifiers */
  1945. orinoco_register_pm_notifier(priv);
  1946. return priv;
  1947. }
  1948. EXPORT_SYMBOL(alloc_orinocodev);
  1949. /* We can only support a single interface. We provide a separate
  1950. * function to set it up to distinguish between hardware
  1951. * initialisation and interface setup.
  1952. *
  1953. * The base_addr and irq parameters are passed on to netdev for use
  1954. * with SIOCGIFMAP.
  1955. */
  1956. int orinoco_if_add(struct orinoco_private *priv,
  1957. unsigned long base_addr,
  1958. unsigned int irq)
  1959. {
  1960. struct wiphy *wiphy = priv_to_wiphy(priv);
  1961. struct wireless_dev *wdev;
  1962. struct net_device *dev;
  1963. int ret;
  1964. dev = alloc_etherdev(sizeof(struct wireless_dev));
  1965. if (!dev)
  1966. return -ENOMEM;
  1967. /* Initialise wireless_dev */
  1968. wdev = netdev_priv(dev);
  1969. wdev->wiphy = wiphy;
  1970. wdev->iftype = NL80211_IFTYPE_STATION;
  1971. /* Setup / override net_device fields */
  1972. dev->ieee80211_ptr = wdev;
  1973. dev->netdev_ops = &orinoco_netdev_ops;
  1974. dev->watchdog_timeo = HZ; /* 1 second timeout */
  1975. dev->ethtool_ops = &orinoco_ethtool_ops;
  1976. dev->wireless_handlers = &orinoco_handler_def;
  1977. #ifdef WIRELESS_SPY
  1978. dev->wireless_data = &priv->wireless_data;
  1979. #endif
  1980. /* we use the default eth_mac_addr for setting the MAC addr */
  1981. /* Reserve space in skb for the SNAP header */
  1982. dev->hard_header_len += ENCAPS_OVERHEAD;
  1983. netif_carrier_off(dev);
  1984. memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
  1985. dev->base_addr = base_addr;
  1986. dev->irq = irq;
  1987. SET_NETDEV_DEV(dev, priv->dev);
  1988. ret = register_netdev(dev);
  1989. if (ret)
  1990. goto fail;
  1991. priv->ndev = dev;
  1992. /* Report what we've done */
  1993. dev_dbg(priv->dev, "Registerred interface %s.\n", dev->name);
  1994. return 0;
  1995. fail:
  1996. free_netdev(dev);
  1997. return ret;
  1998. }
  1999. EXPORT_SYMBOL(orinoco_if_add);
  2000. void orinoco_if_del(struct orinoco_private *priv)
  2001. {
  2002. struct net_device *dev = priv->ndev;
  2003. unregister_netdev(dev);
  2004. free_netdev(dev);
  2005. }
  2006. EXPORT_SYMBOL(orinoco_if_del);
  2007. void free_orinocodev(struct orinoco_private *priv)
  2008. {
  2009. struct wiphy *wiphy = priv_to_wiphy(priv);
  2010. struct orinoco_rx_data *rx_data, *temp;
  2011. wiphy_unregister(wiphy);
  2012. /* If the tasklet is scheduled when we call tasklet_kill it
  2013. * will run one final time. However the tasklet will only
  2014. * drain priv->rx_list if the hw is still available. */
  2015. tasklet_kill(&priv->rx_tasklet);
  2016. /* Explicitly drain priv->rx_list */
  2017. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  2018. list_del(&rx_data->list);
  2019. dev_kfree_skb(rx_data->skb);
  2020. kfree(rx_data->desc);
  2021. kfree(rx_data);
  2022. }
  2023. orinoco_unregister_pm_notifier(priv);
  2024. orinoco_uncache_fw(priv);
  2025. priv->wpa_ie_len = 0;
  2026. kfree(priv->wpa_ie);
  2027. orinoco_mic_free(priv);
  2028. orinoco_bss_data_free(priv);
  2029. wiphy_free(wiphy);
  2030. }
  2031. EXPORT_SYMBOL(free_orinocodev);
  2032. static void orinoco_get_drvinfo(struct net_device *dev,
  2033. struct ethtool_drvinfo *info)
  2034. {
  2035. struct orinoco_private *priv = ndev_priv(dev);
  2036. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  2037. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  2038. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  2039. if (dev->dev.parent)
  2040. strncpy(info->bus_info, dev_name(dev->dev.parent),
  2041. sizeof(info->bus_info) - 1);
  2042. else
  2043. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  2044. "PCMCIA %p", priv->hw.iobase);
  2045. }
  2046. static const struct ethtool_ops orinoco_ethtool_ops = {
  2047. .get_drvinfo = orinoco_get_drvinfo,
  2048. .get_link = ethtool_op_get_link,
  2049. };
  2050. /********************************************************************/
  2051. /* Module initialization */
  2052. /********************************************************************/
  2053. /* Can't be declared "const" or the whole __initdata section will
  2054. * become const */
  2055. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  2056. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  2057. "Pavel Roskin <proski@gnu.org>, et al)";
  2058. static int __init init_orinoco(void)
  2059. {
  2060. printk(KERN_DEBUG "%s\n", version);
  2061. return 0;
  2062. }
  2063. static void __exit exit_orinoco(void)
  2064. {
  2065. }
  2066. module_init(init_orinoco);
  2067. module_exit(exit_orinoco);