ray_cs.c 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886
  1. /*=============================================================================
  2. *
  3. * A PCMCIA client driver for the Raylink wireless LAN card.
  4. * The starting point for this module was the skeleton.c in the
  5. * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
  6. *
  7. *
  8. * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
  9. *
  10. * This driver is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 only of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * It is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  22. *
  23. * Changes:
  24. * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
  25. * - reorganize kmallocs in ray_attach, checking all for failure
  26. * and releasing the previous allocations if one fails
  27. *
  28. * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
  29. * - Audit copy_to_user in ioctl(SIOCGIWESSID)
  30. *
  31. =============================================================================*/
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/slab.h>
  37. #include <linux/string.h>
  38. #include <linux/timer.h>
  39. #include <linux/init.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/etherdevice.h>
  42. #include <linux/if_arp.h>
  43. #include <linux/ioport.h>
  44. #include <linux/skbuff.h>
  45. #include <linux/ethtool.h>
  46. #include <pcmcia/cs_types.h>
  47. #include <pcmcia/cs.h>
  48. #include <pcmcia/cistpl.h>
  49. #include <pcmcia/cisreg.h>
  50. #include <pcmcia/ds.h>
  51. #include <pcmcia/mem_op.h>
  52. #include <linux/wireless.h>
  53. #include <net/iw_handler.h>
  54. #include <asm/io.h>
  55. #include <asm/system.h>
  56. #include <asm/byteorder.h>
  57. #include <asm/uaccess.h>
  58. /* Warning : these stuff will slow down the driver... */
  59. #define WIRELESS_SPY /* Enable spying addresses */
  60. /* Definitions we need for spy */
  61. typedef struct iw_statistics iw_stats;
  62. typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
  63. #include "rayctl.h"
  64. #include "ray_cs.h"
  65. /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
  66. you do not define PCMCIA_DEBUG at all, all the debug code will be
  67. left out. If you compile with PCMCIA_DEBUG=0, the debug code will
  68. be present but disabled -- but it can then be enabled for specific
  69. modules at load time with a 'pc_debug=#' option to insmod.
  70. */
  71. #ifdef RAYLINK_DEBUG
  72. #define PCMCIA_DEBUG RAYLINK_DEBUG
  73. #endif
  74. #ifdef PCMCIA_DEBUG
  75. static int ray_debug;
  76. static int pc_debug = PCMCIA_DEBUG;
  77. module_param(pc_debug, int, 0);
  78. /* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */
  79. #define DEBUG(n, args...) if (pc_debug>(n)) printk(args);
  80. #else
  81. #define DEBUG(n, args...)
  82. #endif
  83. /** Prototypes based on PCMCIA skeleton driver *******************************/
  84. static int ray_config(struct pcmcia_device *link);
  85. static void ray_release(struct pcmcia_device *link);
  86. static void ray_detach(struct pcmcia_device *p_dev);
  87. /***** Prototypes indicated by device structure ******************************/
  88. static int ray_dev_close(struct net_device *dev);
  89. static int ray_dev_config(struct net_device *dev, struct ifmap *map);
  90. static struct net_device_stats *ray_get_stats(struct net_device *dev);
  91. static int ray_dev_init(struct net_device *dev);
  92. static const struct ethtool_ops netdev_ethtool_ops;
  93. static int ray_open(struct net_device *dev);
  94. static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev);
  95. static void set_multicast_list(struct net_device *dev);
  96. static void ray_update_multi_list(struct net_device *dev, int all);
  97. static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
  98. unsigned char *data, int len);
  99. static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type,
  100. unsigned char *data);
  101. static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
  102. static iw_stats * ray_get_wireless_stats(struct net_device * dev);
  103. static const struct iw_handler_def ray_handler_def;
  104. /***** Prototypes for raylink functions **************************************/
  105. static int asc_to_int(char a);
  106. static void authenticate(ray_dev_t *local);
  107. static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
  108. static void authenticate_timeout(u_long);
  109. static int get_free_ccs(ray_dev_t *local);
  110. static int get_free_tx_ccs(ray_dev_t *local);
  111. static void init_startup_params(ray_dev_t *local);
  112. static int parse_addr(char *in_str, UCHAR *out);
  113. static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev, UCHAR type);
  114. static int ray_init(struct net_device *dev);
  115. static int interrupt_ecf(ray_dev_t *local, int ccs);
  116. static void ray_reset(struct net_device *dev);
  117. static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
  118. static void verify_dl_startup(u_long);
  119. /* Prototypes for interrpt time functions **********************************/
  120. static irqreturn_t ray_interrupt (int reg, void *dev_id, struct pt_regs *regs);
  121. static void clear_interrupt(ray_dev_t *local);
  122. static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
  123. unsigned int pkt_addr, int rx_len);
  124. static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
  125. static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
  126. static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
  127. static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
  128. unsigned int pkt_addr, int rx_len);
  129. static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,
  130. int rx_len);
  131. static void associate(ray_dev_t *local);
  132. /* Card command functions */
  133. static int dl_startup_params(struct net_device *dev);
  134. static void join_net(u_long local);
  135. static void start_net(u_long local);
  136. /* void start_net(ray_dev_t *local); */
  137. /*===========================================================================*/
  138. /* Parameters that can be set with 'insmod' */
  139. /* ADHOC=0, Infrastructure=1 */
  140. static int net_type = ADHOC;
  141. /* Hop dwell time in Kus (1024 us units defined by 802.11) */
  142. static int hop_dwell = 128;
  143. /* Beacon period in Kus */
  144. static int beacon_period = 256;
  145. /* power save mode (0 = off, 1 = save power) */
  146. static int psm;
  147. /* String for network's Extended Service Set ID. 32 Characters max */
  148. static char *essid;
  149. /* Default to encapsulation unless translation requested */
  150. static int translate = 1;
  151. static int country = USA;
  152. static int sniffer;
  153. static int bc;
  154. /* 48 bit physical card address if overriding card's real physical
  155. * address is required. Since IEEE 802.11 addresses are 48 bits
  156. * like ethernet, an int can't be used, so a string is used. To
  157. * allow use of addresses starting with a decimal digit, the first
  158. * character must be a letter and will be ignored. This letter is
  159. * followed by up to 12 hex digits which are the address. If less
  160. * than 12 digits are used, the address will be left filled with 0's.
  161. * Note that bit 0 of the first byte is the broadcast bit, and evil
  162. * things will happen if it is not 0 in a card address.
  163. */
  164. static char *phy_addr = NULL;
  165. /* A struct pcmcia_device structure has fields for most things that are needed
  166. to keep track of a socket, but there will usually be some device
  167. specific information that also needs to be kept track of. The
  168. 'priv' pointer in a struct pcmcia_device structure can be used to point to
  169. a device-specific private data structure, like this.
  170. */
  171. static unsigned int ray_mem_speed = 500;
  172. /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
  173. static struct pcmcia_device *this_device = NULL;
  174. MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
  175. MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
  176. MODULE_LICENSE("GPL");
  177. module_param(net_type, int, 0);
  178. module_param(hop_dwell, int, 0);
  179. module_param(beacon_period, int, 0);
  180. module_param(psm, int, 0);
  181. module_param(essid, charp, 0);
  182. module_param(translate, int, 0);
  183. module_param(country, int, 0);
  184. module_param(sniffer, int, 0);
  185. module_param(bc, int, 0);
  186. module_param(phy_addr, charp, 0);
  187. module_param(ray_mem_speed, int, 0);
  188. static UCHAR b5_default_startup_parms[] = {
  189. 0, 0, /* Adhoc station */
  190. 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
  191. 0, 0, 0, 0, 0, 0, 0, 0,
  192. 0, 0, 0, 0, 0, 0, 0, 0,
  193. 0, 0, 0, 0, 0, 0, 0, 0,
  194. 1, 0, /* Active scan, CA Mode */
  195. 0, 0, 0, 0, 0, 0, /* No default MAC addr */
  196. 0x7f, 0xff, /* Frag threshold */
  197. 0x00, 0x80, /* Hop time 128 Kus*/
  198. 0x01, 0x00, /* Beacon period 256 Kus */
  199. 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
  200. 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
  201. 0x7f, 0xff, /* RTS threshold */
  202. 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
  203. 0x05, /* assoc resp timeout thresh */
  204. 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max*/
  205. 0, /* Promiscuous mode */
  206. 0x0c, 0x0bd, /* Unique word */
  207. 0x32, /* Slot time */
  208. 0xff, 0xff, /* roam-low snr, low snr count */
  209. 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
  210. 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
  211. /* b4 - b5 differences start here */
  212. 0x00, 0x3f, /* CW max */
  213. 0x00, 0x0f, /* CW min */
  214. 0x04, 0x08, /* Noise gain, limit offset */
  215. 0x28, 0x28, /* det rssi, med busy offsets */
  216. 7, /* det sync thresh */
  217. 0, 2, 2, /* test mode, min, max */
  218. 0, /* allow broadcast SSID probe resp */
  219. 0, 0, /* privacy must start, can join */
  220. 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
  221. };
  222. static UCHAR b4_default_startup_parms[] = {
  223. 0, 0, /* Adhoc station */
  224. 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
  225. 0, 0, 0, 0, 0, 0, 0, 0,
  226. 0, 0, 0, 0, 0, 0, 0, 0,
  227. 0, 0, 0, 0, 0, 0, 0, 0,
  228. 1, 0, /* Active scan, CA Mode */
  229. 0, 0, 0, 0, 0, 0, /* No default MAC addr */
  230. 0x7f, 0xff, /* Frag threshold */
  231. 0x02, 0x00, /* Hop time */
  232. 0x00, 0x01, /* Beacon period */
  233. 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
  234. 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
  235. 0x7f, 0xff, /* RTS threshold */
  236. 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
  237. 0x05, /* assoc resp timeout thresh */
  238. 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max*/
  239. 0, /* Promiscuous mode */
  240. 0x0c, 0x0bd, /* Unique word */
  241. 0x4e, /* Slot time (TBD seems wrong)*/
  242. 0xff, 0xff, /* roam-low snr, low snr count */
  243. 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
  244. 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
  245. /* b4 - b5 differences start here */
  246. 0x3f, 0x0f, /* CW max, min */
  247. 0x04, 0x08, /* Noise gain, limit offset */
  248. 0x28, 0x28, /* det rssi, med busy offsets */
  249. 7, /* det sync thresh */
  250. 0, 2, 2 /* test mode, min, max*/
  251. };
  252. /*===========================================================================*/
  253. static unsigned char eth2_llc[] = {0xaa, 0xaa, 3, 0, 0, 0};
  254. static char hop_pattern_length[] = { 1,
  255. USA_HOP_MOD, EUROPE_HOP_MOD,
  256. JAPAN_HOP_MOD, KOREA_HOP_MOD,
  257. SPAIN_HOP_MOD, FRANCE_HOP_MOD,
  258. ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
  259. JAPAN_TEST_HOP_MOD
  260. };
  261. static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
  262. /*=============================================================================
  263. ray_attach() creates an "instance" of the driver, allocating
  264. local data structures for one device. The device is registered
  265. with Card Services.
  266. The dev_link structure is initialized, but we don't actually
  267. configure the card at this point -- we wait until we receive a
  268. card insertion event.
  269. =============================================================================*/
  270. static int ray_probe(struct pcmcia_device *p_dev)
  271. {
  272. ray_dev_t *local;
  273. struct net_device *dev;
  274. DEBUG(1, "ray_attach()\n");
  275. /* Allocate space for private device-specific data */
  276. dev = alloc_etherdev(sizeof(ray_dev_t));
  277. if (!dev)
  278. goto fail_alloc_dev;
  279. local = dev->priv;
  280. local->finder = p_dev;
  281. /* The io structure describes IO port mapping. None used here */
  282. p_dev->io.NumPorts1 = 0;
  283. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  284. p_dev->io.IOAddrLines = 5;
  285. /* Interrupt setup. For PCMCIA, driver takes what's given */
  286. p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  287. p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
  288. p_dev->irq.Handler = &ray_interrupt;
  289. /* General socket configuration */
  290. p_dev->conf.Attributes = CONF_ENABLE_IRQ;
  291. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  292. p_dev->conf.ConfigIndex = 1;
  293. p_dev->conf.Present = PRESENT_OPTION;
  294. p_dev->priv = dev;
  295. p_dev->irq.Instance = dev;
  296. local->finder = p_dev;
  297. local->card_status = CARD_INSERTED;
  298. local->authentication_state = UNAUTHENTICATED;
  299. local->num_multi = 0;
  300. DEBUG(2,"ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
  301. p_dev,dev,local,&ray_interrupt);
  302. /* Raylink entries in the device structure */
  303. dev->hard_start_xmit = &ray_dev_start_xmit;
  304. dev->set_config = &ray_dev_config;
  305. dev->get_stats = &ray_get_stats;
  306. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  307. dev->wireless_handlers = &ray_handler_def;
  308. #ifdef WIRELESS_SPY
  309. local->wireless_data.spy_data = &local->spy_data;
  310. dev->wireless_data = &local->wireless_data;
  311. #endif /* WIRELESS_SPY */
  312. dev->set_multicast_list = &set_multicast_list;
  313. DEBUG(2,"ray_cs ray_attach calling ether_setup.)\n");
  314. SET_MODULE_OWNER(dev);
  315. dev->init = &ray_dev_init;
  316. dev->open = &ray_open;
  317. dev->stop = &ray_dev_close;
  318. netif_stop_queue(dev);
  319. init_timer(&local->timer);
  320. this_device = p_dev;
  321. return ray_config(p_dev);
  322. fail_alloc_dev:
  323. return -ENOMEM;
  324. } /* ray_attach */
  325. /*=============================================================================
  326. This deletes a driver "instance". The device is de-registered
  327. with Card Services. If it has been released, all local data
  328. structures are freed. Otherwise, the structures will be freed
  329. when the device is released.
  330. =============================================================================*/
  331. static void ray_detach(struct pcmcia_device *link)
  332. {
  333. struct net_device *dev;
  334. ray_dev_t *local;
  335. DEBUG(1, "ray_detach(0x%p)\n", link);
  336. this_device = NULL;
  337. dev = link->priv;
  338. ray_release(link);
  339. local = (ray_dev_t *)dev->priv;
  340. del_timer(&local->timer);
  341. if (link->priv) {
  342. if (link->dev_node) unregister_netdev(dev);
  343. free_netdev(dev);
  344. }
  345. DEBUG(2,"ray_cs ray_detach ending\n");
  346. } /* ray_detach */
  347. /*=============================================================================
  348. ray_config() is run after a CARD_INSERTION event
  349. is received, to configure the PCMCIA socket, and to make the
  350. ethernet device available to the system.
  351. =============================================================================*/
  352. #define CS_CHECK(fn, ret) \
  353. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  354. #define MAX_TUPLE_SIZE 128
  355. static int ray_config(struct pcmcia_device *link)
  356. {
  357. tuple_t tuple;
  358. cisparse_t parse;
  359. int last_fn = 0, last_ret = 0;
  360. int i;
  361. u_char buf[MAX_TUPLE_SIZE];
  362. win_req_t req;
  363. memreq_t mem;
  364. struct net_device *dev = (struct net_device *)link->priv;
  365. ray_dev_t *local = (ray_dev_t *)dev->priv;
  366. DEBUG(1, "ray_config(0x%p)\n", link);
  367. /* This reads the card's CONFIG tuple to find its configuration regs */
  368. tuple.DesiredTuple = CISTPL_CONFIG;
  369. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  370. tuple.TupleData = buf;
  371. tuple.TupleDataMax = MAX_TUPLE_SIZE;
  372. tuple.TupleOffset = 0;
  373. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  374. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
  375. link->conf.ConfigBase = parse.config.base;
  376. link->conf.Present = parse.config.rmask[0];
  377. /* Determine card type and firmware version */
  378. buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
  379. tuple.DesiredTuple = CISTPL_VERS_1;
  380. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  381. tuple.TupleData = buf;
  382. tuple.TupleDataMax = MAX_TUPLE_SIZE;
  383. tuple.TupleOffset = 2;
  384. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  385. for (i=0; i<tuple.TupleDataLen - 4; i++)
  386. if (buf[i] == 0) buf[i] = ' ';
  387. printk(KERN_INFO "ray_cs Detected: %s\n",buf);
  388. /* Now allocate an interrupt line. Note that this does not
  389. actually assign a handler to the interrupt.
  390. */
  391. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  392. dev->irq = link->irq.AssignedIRQ;
  393. /* This actually configures the PCMCIA socket -- setting up
  394. the I/O windows and the interrupt mapping.
  395. */
  396. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  397. /*** Set up 32k window for shared memory (transmit and control) ************/
  398. req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
  399. req.Base = 0;
  400. req.Size = 0x8000;
  401. req.AccessSpeed = ray_mem_speed;
  402. CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
  403. mem.CardOffset = 0x0000; mem.Page = 0;
  404. CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
  405. local->sram = ioremap(req.Base,req.Size);
  406. /*** Set up 16k window for shared memory (receive buffer) ***************/
  407. req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
  408. req.Base = 0;
  409. req.Size = 0x4000;
  410. req.AccessSpeed = ray_mem_speed;
  411. CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->rmem_handle));
  412. mem.CardOffset = 0x8000; mem.Page = 0;
  413. CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem));
  414. local->rmem = ioremap(req.Base,req.Size);
  415. /*** Set up window for attribute memory ***********************************/
  416. req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
  417. req.Base = 0;
  418. req.Size = 0x1000;
  419. req.AccessSpeed = ray_mem_speed;
  420. CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->amem_handle));
  421. mem.CardOffset = 0x0000; mem.Page = 0;
  422. CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem));
  423. local->amem = ioremap(req.Base,req.Size);
  424. DEBUG(3,"ray_config sram=%p\n",local->sram);
  425. DEBUG(3,"ray_config rmem=%p\n",local->rmem);
  426. DEBUG(3,"ray_config amem=%p\n",local->amem);
  427. if (ray_init(dev) < 0) {
  428. ray_release(link);
  429. return -ENODEV;
  430. }
  431. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  432. i = register_netdev(dev);
  433. if (i != 0) {
  434. printk("ray_config register_netdev() failed\n");
  435. ray_release(link);
  436. return i;
  437. }
  438. strcpy(local->node.dev_name, dev->name);
  439. link->dev_node = &local->node;
  440. printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ",
  441. dev->name, dev->irq);
  442. for (i = 0; i < 6; i++)
  443. printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
  444. return 0;
  445. cs_failed:
  446. cs_error(link, last_fn, last_ret);
  447. ray_release(link);
  448. return -ENODEV;
  449. } /* ray_config */
  450. static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
  451. {
  452. return dev->sram + CCS_BASE;
  453. }
  454. static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
  455. {
  456. /*
  457. * This looks nonsensical, since there is a separate
  458. * RCS_BASE. But the difference between a "struct rcs"
  459. * and a "struct ccs" ends up being in the _index_ off
  460. * the base, so the base pointer is the same for both
  461. * ccs/rcs.
  462. */
  463. return dev->sram + CCS_BASE;
  464. }
  465. /*===========================================================================*/
  466. static int ray_init(struct net_device *dev)
  467. {
  468. int i;
  469. UCHAR *p;
  470. struct ccs __iomem *pccs;
  471. ray_dev_t *local = (ray_dev_t *)dev->priv;
  472. struct pcmcia_device *link = local->finder;
  473. DEBUG(1, "ray_init(0x%p)\n", dev);
  474. if (!(pcmcia_dev_present(link))) {
  475. DEBUG(0,"ray_init - device not present\n");
  476. return -1;
  477. }
  478. local->net_type = net_type;
  479. local->sta_type = TYPE_STA;
  480. /* Copy the startup results to local memory */
  481. memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,\
  482. sizeof(struct startup_res_6));
  483. /* Check Power up test status and get mac address from card */
  484. if (local->startup_res.startup_word != 0x80) {
  485. printk(KERN_INFO "ray_init ERROR card status = %2x\n",
  486. local->startup_res.startup_word);
  487. local->card_status = CARD_INIT_ERROR;
  488. return -1;
  489. }
  490. local->fw_ver = local->startup_res.firmware_version[0];
  491. local->fw_bld = local->startup_res.firmware_version[1];
  492. local->fw_var = local->startup_res.firmware_version[2];
  493. DEBUG(1,"ray_init firmware version %d.%d \n",local->fw_ver, local->fw_bld);
  494. local->tib_length = 0x20;
  495. if ((local->fw_ver == 5) && (local->fw_bld >= 30))
  496. local->tib_length = local->startup_res.tib_length;
  497. DEBUG(2,"ray_init tib_length = 0x%02x\n", local->tib_length);
  498. /* Initialize CCS's to buffer free state */
  499. pccs = ccs_base(local);
  500. for (i=0; i<NUMBER_OF_CCS; i++) {
  501. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  502. }
  503. init_startup_params(local);
  504. /* copy mac address to startup parameters */
  505. if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr))
  506. {
  507. p = local->sparm.b4.a_mac_addr;
  508. }
  509. else
  510. {
  511. memcpy(&local->sparm.b4.a_mac_addr,
  512. &local->startup_res.station_addr, ADDRLEN);
  513. p = local->sparm.b4.a_mac_addr;
  514. }
  515. clear_interrupt(local); /* Clear any interrupt from the card */
  516. local->card_status = CARD_AWAITING_PARAM;
  517. DEBUG(2,"ray_init ending\n");
  518. return 0;
  519. } /* ray_init */
  520. /*===========================================================================*/
  521. /* Download startup parameters to the card and command it to read them */
  522. static int dl_startup_params(struct net_device *dev)
  523. {
  524. int ccsindex;
  525. ray_dev_t *local = (ray_dev_t *)dev->priv;
  526. struct ccs __iomem *pccs;
  527. struct pcmcia_device *link = local->finder;
  528. DEBUG(1,"dl_startup_params entered\n");
  529. if (!(pcmcia_dev_present(link))) {
  530. DEBUG(2,"ray_cs dl_startup_params - device not present\n");
  531. return -1;
  532. }
  533. /* Copy parameters to host to ECF area */
  534. if (local->fw_ver == 0x55)
  535. memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
  536. sizeof(struct b4_startup_params));
  537. else
  538. memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
  539. sizeof(struct b5_startup_params));
  540. /* Fill in the CCS fields for the ECF */
  541. if ((ccsindex = get_free_ccs(local)) < 0) return -1;
  542. local->dl_param_ccs = ccsindex;
  543. pccs = ccs_base(local) + ccsindex;
  544. writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
  545. DEBUG(2,"dl_startup_params start ccsindex = %d\n", local->dl_param_ccs);
  546. /* Interrupt the firmware to process the command */
  547. if (interrupt_ecf(local, ccsindex)) {
  548. printk(KERN_INFO "ray dl_startup_params failed - "
  549. "ECF not ready for intr\n");
  550. local->card_status = CARD_DL_PARAM_ERROR;
  551. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  552. return -2;
  553. }
  554. local->card_status = CARD_DL_PARAM;
  555. /* Start kernel timer to wait for dl startup to complete. */
  556. local->timer.expires = jiffies + HZ/2;
  557. local->timer.data = (long)local;
  558. local->timer.function = &verify_dl_startup;
  559. add_timer(&local->timer);
  560. DEBUG(2,"ray_cs dl_startup_params started timer for verify_dl_startup\n");
  561. return 0;
  562. } /* dl_startup_params */
  563. /*===========================================================================*/
  564. static void init_startup_params(ray_dev_t *local)
  565. {
  566. int i;
  567. if (country > JAPAN_TEST) country = USA;
  568. else
  569. if (country < USA) country = USA;
  570. /* structure for hop time and beacon period is defined here using
  571. * New 802.11D6.1 format. Card firmware is still using old format
  572. * until version 6.
  573. * Before After
  574. * a_hop_time ms byte a_hop_time ms byte
  575. * a_hop_time 2s byte a_hop_time ls byte
  576. * a_hop_time ls byte a_beacon_period ms byte
  577. * a_beacon_period a_beacon_period ls byte
  578. *
  579. * a_hop_time = uS a_hop_time = KuS
  580. * a_beacon_period = hops a_beacon_period = KuS
  581. */ /* 64ms = 010000 */
  582. if (local->fw_ver == 0x55) {
  583. memcpy((UCHAR *)&local->sparm.b4, b4_default_startup_parms,
  584. sizeof(struct b4_startup_params));
  585. /* Translate sane kus input values to old build 4/5 format */
  586. /* i = hop time in uS truncated to 3 bytes */
  587. i = (hop_dwell * 1024) & 0xffffff;
  588. local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
  589. local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
  590. local->sparm.b4.a_beacon_period[0] = 0;
  591. local->sparm.b4.a_beacon_period[1] =
  592. ((beacon_period/hop_dwell) - 1) & 0xff;
  593. local->sparm.b4.a_curr_country_code = country;
  594. local->sparm.b4.a_hop_pattern_length =
  595. hop_pattern_length[(int)country] - 1;
  596. if (bc)
  597. {
  598. local->sparm.b4.a_ack_timeout = 0x50;
  599. local->sparm.b4.a_sifs = 0x3f;
  600. }
  601. }
  602. else { /* Version 5 uses real kus values */
  603. memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,
  604. sizeof(struct b5_startup_params));
  605. local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
  606. local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
  607. local->sparm.b5.a_beacon_period[0] = (beacon_period >> 8) & 0xff;
  608. local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
  609. if (psm)
  610. local->sparm.b5.a_power_mgt_state = 1;
  611. local->sparm.b5.a_curr_country_code = country;
  612. local->sparm.b5.a_hop_pattern_length =
  613. hop_pattern_length[(int)country];
  614. }
  615. local->sparm.b4.a_network_type = net_type & 0x01;
  616. local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
  617. if (essid != NULL)
  618. strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
  619. } /* init_startup_params */
  620. /*===========================================================================*/
  621. static void verify_dl_startup(u_long data)
  622. {
  623. ray_dev_t *local = (ray_dev_t *)data;
  624. struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
  625. UCHAR status;
  626. struct pcmcia_device *link = local->finder;
  627. if (!(pcmcia_dev_present(link))) {
  628. DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
  629. return;
  630. }
  631. #ifdef PCMCIA_DEBUG
  632. if (pc_debug > 2) {
  633. int i;
  634. printk(KERN_DEBUG "verify_dl_startup parameters sent via ccs %d:\n",
  635. local->dl_param_ccs);
  636. for (i=0; i<sizeof(struct b5_startup_params); i++) {
  637. printk(" %2x", (unsigned int) readb(local->sram + HOST_TO_ECF_BASE + i));
  638. }
  639. printk("\n");
  640. }
  641. #endif
  642. status = readb(&pccs->buffer_status);
  643. if (status!= CCS_BUFFER_FREE)
  644. {
  645. printk(KERN_INFO "Download startup params failed. Status = %d\n",
  646. status);
  647. local->card_status = CARD_DL_PARAM_ERROR;
  648. return;
  649. }
  650. if (local->sparm.b4.a_network_type == ADHOC)
  651. start_net((u_long)local);
  652. else
  653. join_net((u_long)local);
  654. return;
  655. } /* end verify_dl_startup */
  656. /*===========================================================================*/
  657. /* Command card to start a network */
  658. static void start_net(u_long data)
  659. {
  660. ray_dev_t *local = (ray_dev_t *)data;
  661. struct ccs __iomem *pccs;
  662. int ccsindex;
  663. struct pcmcia_device *link = local->finder;
  664. if (!(pcmcia_dev_present(link))) {
  665. DEBUG(2,"ray_cs start_net - device not present\n");
  666. return;
  667. }
  668. /* Fill in the CCS fields for the ECF */
  669. if ((ccsindex = get_free_ccs(local)) < 0) return;
  670. pccs = ccs_base(local) + ccsindex;
  671. writeb(CCS_START_NETWORK, &pccs->cmd);
  672. writeb(0, &pccs->var.start_network.update_param);
  673. /* Interrupt the firmware to process the command */
  674. if (interrupt_ecf(local, ccsindex)) {
  675. DEBUG(1,"ray start net failed - card not ready for intr\n");
  676. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  677. return;
  678. }
  679. local->card_status = CARD_DOING_ACQ;
  680. return;
  681. } /* end start_net */
  682. /*===========================================================================*/
  683. /* Command card to join a network */
  684. static void join_net(u_long data)
  685. {
  686. ray_dev_t *local = (ray_dev_t *)data;
  687. struct ccs __iomem *pccs;
  688. int ccsindex;
  689. struct pcmcia_device *link = local->finder;
  690. if (!(pcmcia_dev_present(link))) {
  691. DEBUG(2,"ray_cs join_net - device not present\n");
  692. return;
  693. }
  694. /* Fill in the CCS fields for the ECF */
  695. if ((ccsindex = get_free_ccs(local)) < 0) return;
  696. pccs = ccs_base(local) + ccsindex;
  697. writeb(CCS_JOIN_NETWORK, &pccs->cmd);
  698. writeb(0, &pccs->var.join_network.update_param);
  699. writeb(0, &pccs->var.join_network.net_initiated);
  700. /* Interrupt the firmware to process the command */
  701. if (interrupt_ecf(local, ccsindex)) {
  702. DEBUG(1,"ray join net failed - card not ready for intr\n");
  703. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  704. return;
  705. }
  706. local->card_status = CARD_DOING_ACQ;
  707. return;
  708. }
  709. /*============================================================================
  710. After a card is removed, ray_release() will unregister the net
  711. device, and release the PCMCIA configuration. If the device is
  712. still open, this will be postponed until it is closed.
  713. =============================================================================*/
  714. static void ray_release(struct pcmcia_device *link)
  715. {
  716. struct net_device *dev = link->priv;
  717. ray_dev_t *local = dev->priv;
  718. int i;
  719. DEBUG(1, "ray_release(0x%p)\n", link);
  720. del_timer(&local->timer);
  721. iounmap(local->sram);
  722. iounmap(local->rmem);
  723. iounmap(local->amem);
  724. /* Do bother checking to see if these succeed or not */
  725. i = pcmcia_release_window(local->amem_handle);
  726. if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
  727. i = pcmcia_release_window(local->rmem_handle);
  728. if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
  729. pcmcia_disable_device(link);
  730. DEBUG(2,"ray_release ending\n");
  731. }
  732. static int ray_suspend(struct pcmcia_device *link)
  733. {
  734. struct net_device *dev = link->priv;
  735. if (link->open)
  736. netif_device_detach(dev);
  737. return 0;
  738. }
  739. static int ray_resume(struct pcmcia_device *link)
  740. {
  741. struct net_device *dev = link->priv;
  742. if (link->open) {
  743. ray_reset(dev);
  744. netif_device_attach(dev);
  745. }
  746. return 0;
  747. }
  748. /*===========================================================================*/
  749. int ray_dev_init(struct net_device *dev)
  750. {
  751. #ifdef RAY_IMMEDIATE_INIT
  752. int i;
  753. #endif /* RAY_IMMEDIATE_INIT */
  754. ray_dev_t *local = dev->priv;
  755. struct pcmcia_device *link = local->finder;
  756. DEBUG(1,"ray_dev_init(dev=%p)\n",dev);
  757. if (!(pcmcia_dev_present(link))) {
  758. DEBUG(2,"ray_dev_init - device not present\n");
  759. return -1;
  760. }
  761. #ifdef RAY_IMMEDIATE_INIT
  762. /* Download startup parameters */
  763. if ( (i = dl_startup_params(dev)) < 0)
  764. {
  765. printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
  766. "returns 0x%x\n",i);
  767. return -1;
  768. }
  769. #else /* RAY_IMMEDIATE_INIT */
  770. /* Postpone the card init so that we can still configure the card,
  771. * for example using the Wireless Extensions. The init will happen
  772. * in ray_open() - Jean II */
  773. DEBUG(1,"ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
  774. local->card_status);
  775. #endif /* RAY_IMMEDIATE_INIT */
  776. /* copy mac and broadcast addresses to linux device */
  777. memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
  778. memset(dev->broadcast, 0xff, ETH_ALEN);
  779. DEBUG(2,"ray_dev_init ending\n");
  780. return 0;
  781. }
  782. /*===========================================================================*/
  783. static int ray_dev_config(struct net_device *dev, struct ifmap *map)
  784. {
  785. ray_dev_t *local = dev->priv;
  786. struct pcmcia_device *link = local->finder;
  787. /* Dummy routine to satisfy device structure */
  788. DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);
  789. if (!(pcmcia_dev_present(link))) {
  790. DEBUG(2,"ray_dev_config - device not present\n");
  791. return -1;
  792. }
  793. return 0;
  794. }
  795. /*===========================================================================*/
  796. static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
  797. {
  798. ray_dev_t *local = dev->priv;
  799. struct pcmcia_device *link = local->finder;
  800. short length = skb->len;
  801. if (!(pcmcia_dev_present(link))) {
  802. DEBUG(2,"ray_dev_start_xmit - device not present\n");
  803. return -1;
  804. }
  805. DEBUG(3,"ray_dev_start_xmit(skb=%p, dev=%p)\n",skb,dev);
  806. if (local->authentication_state == NEED_TO_AUTH) {
  807. DEBUG(0,"ray_cs Sending authentication request.\n");
  808. if (!build_auth_frame (local, local->auth_id, OPEN_AUTH_REQUEST)) {
  809. local->authentication_state = AUTHENTICATED;
  810. netif_stop_queue(dev);
  811. return 1;
  812. }
  813. }
  814. if (length < ETH_ZLEN)
  815. {
  816. if (skb_padto(skb, ETH_ZLEN))
  817. return 0;
  818. length = ETH_ZLEN;
  819. }
  820. switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) {
  821. case XMIT_NO_CCS:
  822. case XMIT_NEED_AUTH:
  823. netif_stop_queue(dev);
  824. return 1;
  825. case XMIT_NO_INTR:
  826. case XMIT_MSG_BAD:
  827. case XMIT_OK:
  828. default:
  829. dev->trans_start = jiffies;
  830. dev_kfree_skb(skb);
  831. return 0;
  832. }
  833. return 0;
  834. } /* ray_dev_start_xmit */
  835. /*===========================================================================*/
  836. static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,
  837. UCHAR msg_type)
  838. {
  839. ray_dev_t *local = (ray_dev_t *)dev->priv;
  840. struct ccs __iomem *pccs;
  841. int ccsindex;
  842. int offset;
  843. struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
  844. short int addr; /* Address of xmit buffer in card space */
  845. DEBUG(3,"ray_hw_xmit(data=%p, len=%d, dev=%p)\n",data,len,dev);
  846. if (len + TX_HEADER_LENGTH > TX_BUF_SIZE)
  847. {
  848. printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len);
  849. return XMIT_MSG_BAD;
  850. }
  851. switch (ccsindex = get_free_tx_ccs(local)) {
  852. case ECCSBUSY:
  853. DEBUG(2,"ray_hw_xmit tx_ccs table busy\n");
  854. case ECCSFULL:
  855. DEBUG(2,"ray_hw_xmit No free tx ccs\n");
  856. case ECARDGONE:
  857. netif_stop_queue(dev);
  858. return XMIT_NO_CCS;
  859. default:
  860. break;
  861. }
  862. addr = TX_BUF_BASE + (ccsindex << 11);
  863. if (msg_type == DATA_TYPE) {
  864. local->stats.tx_bytes += len;
  865. local->stats.tx_packets++;
  866. }
  867. ptx = local->sram + addr;
  868. ray_build_header(local, ptx, msg_type, data);
  869. if (translate) {
  870. offset = translate_frame(local, ptx, data, len);
  871. }
  872. else { /* Encapsulate frame */
  873. /* TBD TIB length will move address of ptx->var */
  874. memcpy_toio(&ptx->var, data, len);
  875. offset = 0;
  876. }
  877. /* fill in the CCS */
  878. pccs = ccs_base(local) + ccsindex;
  879. len += TX_HEADER_LENGTH + offset;
  880. writeb(CCS_TX_REQUEST, &pccs->cmd);
  881. writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
  882. writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
  883. writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
  884. writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
  885. /* TBD still need psm_cam? */
  886. writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
  887. writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
  888. writeb(0, &pccs->var.tx_request.antenna);
  889. DEBUG(3,"ray_hw_xmit default_tx_rate = 0x%x\n",\
  890. local->net_default_tx_rate);
  891. /* Interrupt the firmware to process the command */
  892. if (interrupt_ecf(local, ccsindex)) {
  893. DEBUG(2,"ray_hw_xmit failed - ECF not ready for intr\n");
  894. /* TBD very inefficient to copy packet to buffer, and then not
  895. send it, but the alternative is to queue the messages and that
  896. won't be done for a while. Maybe set tbusy until a CCS is free?
  897. */
  898. writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
  899. return XMIT_NO_INTR;
  900. }
  901. return XMIT_OK;
  902. } /* end ray_hw_xmit */
  903. /*===========================================================================*/
  904. static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, unsigned char *data,
  905. int len)
  906. {
  907. unsigned short int proto = ((struct ethhdr *)data)->h_proto;
  908. if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
  909. DEBUG(3,"ray_cs translate_frame DIX II\n");
  910. /* Copy LLC header to card buffer */
  911. memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
  912. memcpy_toio( ((void __iomem *)&ptx->var) + sizeof(eth2_llc), (UCHAR *)&proto, 2);
  913. if ((proto == 0xf380) || (proto == 0x3781)) {
  914. /* This is the selective translation table, only 2 entries */
  915. writeb(0xf8, &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
  916. }
  917. /* Copy body of ethernet packet without ethernet header */
  918. memcpy_toio((void __iomem *)&ptx->var + sizeof(struct snaphdr_t), \
  919. data + ETH_HLEN, len - ETH_HLEN);
  920. return (int) sizeof(struct snaphdr_t) - ETH_HLEN;
  921. }
  922. else { /* already 802 type, and proto is length */
  923. DEBUG(3,"ray_cs translate_frame 802\n");
  924. if (proto == 0xffff) { /* evil netware IPX 802.3 without LLC */
  925. DEBUG(3,"ray_cs translate_frame evil IPX\n");
  926. memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
  927. return 0 - ETH_HLEN;
  928. }
  929. memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
  930. return 0 - ETH_HLEN;
  931. }
  932. /* TBD do other frame types */
  933. } /* end translate_frame */
  934. /*===========================================================================*/
  935. static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type,
  936. unsigned char *data)
  937. {
  938. writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
  939. /*** IEEE 802.11 Address field assignments *************
  940. TODS FROMDS addr_1 addr_2 addr_3 addr_4
  941. Adhoc 0 0 dest src (terminal) BSSID N/A
  942. AP to Terminal 0 1 dest AP(BSSID) source N/A
  943. Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
  944. AP to AP 1 1 dest AP src AP dest source
  945. *******************************************************/
  946. if (local->net_type == ADHOC) {
  947. writeb(0, &ptx->mac.frame_ctl_2);
  948. memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, 2 * ADDRLEN);
  949. memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
  950. }
  951. else /* infrastructure */
  952. {
  953. if (local->sparm.b4.a_acting_as_ap_status)
  954. {
  955. writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
  956. memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, ADDRLEN);
  957. memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
  958. memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_source, ADDRLEN);
  959. }
  960. else /* Terminal */
  961. {
  962. writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
  963. memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
  964. memcpy_toio(ptx->mac.addr_2, ((struct ethhdr *)data)->h_source, ADDRLEN);
  965. memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_dest, ADDRLEN);
  966. }
  967. }
  968. } /* end encapsulate_frame */
  969. /*===========================================================================*/
  970. static void netdev_get_drvinfo(struct net_device *dev,
  971. struct ethtool_drvinfo *info)
  972. {
  973. strcpy(info->driver, "ray_cs");
  974. }
  975. static const struct ethtool_ops netdev_ethtool_ops = {
  976. .get_drvinfo = netdev_get_drvinfo,
  977. };
  978. /*====================================================================*/
  979. /*------------------------------------------------------------------*/
  980. /*
  981. * Wireless Handler : get protocol name
  982. */
  983. static int ray_get_name(struct net_device *dev,
  984. struct iw_request_info *info,
  985. char *cwrq,
  986. char *extra)
  987. {
  988. strcpy(cwrq, "IEEE 802.11-FH");
  989. return 0;
  990. }
  991. /*------------------------------------------------------------------*/
  992. /*
  993. * Wireless Handler : set frequency
  994. */
  995. static int ray_set_freq(struct net_device *dev,
  996. struct iw_request_info *info,
  997. struct iw_freq *fwrq,
  998. char *extra)
  999. {
  1000. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1001. int err = -EINPROGRESS; /* Call commit handler */
  1002. /* Reject if card is already initialised */
  1003. if(local->card_status != CARD_AWAITING_PARAM)
  1004. return -EBUSY;
  1005. /* Setting by channel number */
  1006. if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
  1007. err = -EOPNOTSUPP;
  1008. else
  1009. local->sparm.b5.a_hop_pattern = fwrq->m;
  1010. return err;
  1011. }
  1012. /*------------------------------------------------------------------*/
  1013. /*
  1014. * Wireless Handler : get frequency
  1015. */
  1016. static int ray_get_freq(struct net_device *dev,
  1017. struct iw_request_info *info,
  1018. struct iw_freq *fwrq,
  1019. char *extra)
  1020. {
  1021. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1022. fwrq->m = local->sparm.b5.a_hop_pattern;
  1023. fwrq->e = 0;
  1024. return 0;
  1025. }
  1026. /*------------------------------------------------------------------*/
  1027. /*
  1028. * Wireless Handler : set ESSID
  1029. */
  1030. static int ray_set_essid(struct net_device *dev,
  1031. struct iw_request_info *info,
  1032. struct iw_point *dwrq,
  1033. char *extra)
  1034. {
  1035. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1036. /* Reject if card is already initialised */
  1037. if(local->card_status != CARD_AWAITING_PARAM)
  1038. return -EBUSY;
  1039. /* Check if we asked for `any' */
  1040. if(dwrq->flags == 0) {
  1041. /* Corey : can you do that ? */
  1042. return -EOPNOTSUPP;
  1043. } else {
  1044. /* Check the size of the string */
  1045. if(dwrq->length > IW_ESSID_MAX_SIZE) {
  1046. return -E2BIG;
  1047. }
  1048. /* Set the ESSID in the card */
  1049. memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
  1050. memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
  1051. }
  1052. return -EINPROGRESS; /* Call commit handler */
  1053. }
  1054. /*------------------------------------------------------------------*/
  1055. /*
  1056. * Wireless Handler : get ESSID
  1057. */
  1058. static int ray_get_essid(struct net_device *dev,
  1059. struct iw_request_info *info,
  1060. struct iw_point *dwrq,
  1061. char *extra)
  1062. {
  1063. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1064. /* Get the essid that was set */
  1065. memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
  1066. extra[IW_ESSID_MAX_SIZE] = '\0';
  1067. /* Push it out ! */
  1068. dwrq->length = strlen(extra);
  1069. dwrq->flags = 1; /* active */
  1070. return 0;
  1071. }
  1072. /*------------------------------------------------------------------*/
  1073. /*
  1074. * Wireless Handler : get AP address
  1075. */
  1076. static int ray_get_wap(struct net_device *dev,
  1077. struct iw_request_info *info,
  1078. struct sockaddr *awrq,
  1079. char *extra)
  1080. {
  1081. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1082. memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
  1083. awrq->sa_family = ARPHRD_ETHER;
  1084. return 0;
  1085. }
  1086. /*------------------------------------------------------------------*/
  1087. /*
  1088. * Wireless Handler : set Bit-Rate
  1089. */
  1090. static int ray_set_rate(struct net_device *dev,
  1091. struct iw_request_info *info,
  1092. struct iw_param *vwrq,
  1093. char *extra)
  1094. {
  1095. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1096. /* Reject if card is already initialised */
  1097. if(local->card_status != CARD_AWAITING_PARAM)
  1098. return -EBUSY;
  1099. /* Check if rate is in range */
  1100. if((vwrq->value != 1000000) && (vwrq->value != 2000000))
  1101. return -EINVAL;
  1102. /* Hack for 1.5 Mb/s instead of 2 Mb/s */
  1103. if((local->fw_ver == 0x55) && /* Please check */
  1104. (vwrq->value == 2000000))
  1105. local->net_default_tx_rate = 3;
  1106. else
  1107. local->net_default_tx_rate = vwrq->value/500000;
  1108. return 0;
  1109. }
  1110. /*------------------------------------------------------------------*/
  1111. /*
  1112. * Wireless Handler : get Bit-Rate
  1113. */
  1114. static int ray_get_rate(struct net_device *dev,
  1115. struct iw_request_info *info,
  1116. struct iw_param *vwrq,
  1117. char *extra)
  1118. {
  1119. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1120. if(local->net_default_tx_rate == 3)
  1121. vwrq->value = 2000000; /* Hum... */
  1122. else
  1123. vwrq->value = local->net_default_tx_rate * 500000;
  1124. vwrq->fixed = 0; /* We are in auto mode */
  1125. return 0;
  1126. }
  1127. /*------------------------------------------------------------------*/
  1128. /*
  1129. * Wireless Handler : set RTS threshold
  1130. */
  1131. static int ray_set_rts(struct net_device *dev,
  1132. struct iw_request_info *info,
  1133. struct iw_param *vwrq,
  1134. char *extra)
  1135. {
  1136. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1137. int rthr = vwrq->value;
  1138. /* Reject if card is already initialised */
  1139. if(local->card_status != CARD_AWAITING_PARAM)
  1140. return -EBUSY;
  1141. /* if(wrq->u.rts.fixed == 0) we should complain */
  1142. if(vwrq->disabled)
  1143. rthr = 32767;
  1144. else {
  1145. if((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
  1146. return -EINVAL;
  1147. }
  1148. local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
  1149. local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
  1150. return -EINPROGRESS; /* Call commit handler */
  1151. }
  1152. /*------------------------------------------------------------------*/
  1153. /*
  1154. * Wireless Handler : get RTS threshold
  1155. */
  1156. static int ray_get_rts(struct net_device *dev,
  1157. struct iw_request_info *info,
  1158. struct iw_param *vwrq,
  1159. char *extra)
  1160. {
  1161. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1162. vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
  1163. + local->sparm.b5.a_rts_threshold[1];
  1164. vwrq->disabled = (vwrq->value == 32767);
  1165. vwrq->fixed = 1;
  1166. return 0;
  1167. }
  1168. /*------------------------------------------------------------------*/
  1169. /*
  1170. * Wireless Handler : set Fragmentation threshold
  1171. */
  1172. static int ray_set_frag(struct net_device *dev,
  1173. struct iw_request_info *info,
  1174. struct iw_param *vwrq,
  1175. char *extra)
  1176. {
  1177. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1178. int fthr = vwrq->value;
  1179. /* Reject if card is already initialised */
  1180. if(local->card_status != CARD_AWAITING_PARAM)
  1181. return -EBUSY;
  1182. /* if(wrq->u.frag.fixed == 0) should complain */
  1183. if(vwrq->disabled)
  1184. fthr = 32767;
  1185. else {
  1186. if((fthr < 256) || (fthr > 2347)) /* To check out ! */
  1187. return -EINVAL;
  1188. }
  1189. local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
  1190. local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
  1191. return -EINPROGRESS; /* Call commit handler */
  1192. }
  1193. /*------------------------------------------------------------------*/
  1194. /*
  1195. * Wireless Handler : get Fragmentation threshold
  1196. */
  1197. static int ray_get_frag(struct net_device *dev,
  1198. struct iw_request_info *info,
  1199. struct iw_param *vwrq,
  1200. char *extra)
  1201. {
  1202. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1203. vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
  1204. + local->sparm.b5.a_frag_threshold[1];
  1205. vwrq->disabled = (vwrq->value == 32767);
  1206. vwrq->fixed = 1;
  1207. return 0;
  1208. }
  1209. /*------------------------------------------------------------------*/
  1210. /*
  1211. * Wireless Handler : set Mode of Operation
  1212. */
  1213. static int ray_set_mode(struct net_device *dev,
  1214. struct iw_request_info *info,
  1215. __u32 *uwrq,
  1216. char *extra)
  1217. {
  1218. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1219. int err = -EINPROGRESS; /* Call commit handler */
  1220. char card_mode = 1;
  1221. /* Reject if card is already initialised */
  1222. if(local->card_status != CARD_AWAITING_PARAM)
  1223. return -EBUSY;
  1224. switch (*uwrq)
  1225. {
  1226. case IW_MODE_ADHOC:
  1227. card_mode = 0;
  1228. // Fall through
  1229. case IW_MODE_INFRA:
  1230. local->sparm.b5.a_network_type = card_mode;
  1231. break;
  1232. default:
  1233. err = -EINVAL;
  1234. }
  1235. return err;
  1236. }
  1237. /*------------------------------------------------------------------*/
  1238. /*
  1239. * Wireless Handler : get Mode of Operation
  1240. */
  1241. static int ray_get_mode(struct net_device *dev,
  1242. struct iw_request_info *info,
  1243. __u32 *uwrq,
  1244. char *extra)
  1245. {
  1246. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1247. if(local->sparm.b5.a_network_type)
  1248. *uwrq = IW_MODE_INFRA;
  1249. else
  1250. *uwrq = IW_MODE_ADHOC;
  1251. return 0;
  1252. }
  1253. /*------------------------------------------------------------------*/
  1254. /*
  1255. * Wireless Handler : get range info
  1256. */
  1257. static int ray_get_range(struct net_device *dev,
  1258. struct iw_request_info *info,
  1259. struct iw_point *dwrq,
  1260. char *extra)
  1261. {
  1262. struct iw_range *range = (struct iw_range *) extra;
  1263. memset((char *) range, 0, sizeof(struct iw_range));
  1264. /* Set the length (very important for backward compatibility) */
  1265. dwrq->length = sizeof(struct iw_range);
  1266. /* Set the Wireless Extension versions */
  1267. range->we_version_compiled = WIRELESS_EXT;
  1268. range->we_version_source = 9;
  1269. /* Set information in the range struct */
  1270. range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
  1271. range->num_channels = hop_pattern_length[(int)country];
  1272. range->num_frequency = 0;
  1273. range->max_qual.qual = 0;
  1274. range->max_qual.level = 255; /* What's the correct value ? */
  1275. range->max_qual.noise = 255; /* Idem */
  1276. range->num_bitrates = 2;
  1277. range->bitrate[0] = 1000000; /* 1 Mb/s */
  1278. range->bitrate[1] = 2000000; /* 2 Mb/s */
  1279. return 0;
  1280. }
  1281. /*------------------------------------------------------------------*/
  1282. /*
  1283. * Wireless Private Handler : set framing mode
  1284. */
  1285. static int ray_set_framing(struct net_device *dev,
  1286. struct iw_request_info *info,
  1287. union iwreq_data *wrqu,
  1288. char *extra)
  1289. {
  1290. translate = *(extra); /* Set framing mode */
  1291. return 0;
  1292. }
  1293. /*------------------------------------------------------------------*/
  1294. /*
  1295. * Wireless Private Handler : get framing mode
  1296. */
  1297. static int ray_get_framing(struct net_device *dev,
  1298. struct iw_request_info *info,
  1299. union iwreq_data *wrqu,
  1300. char *extra)
  1301. {
  1302. *(extra) = translate;
  1303. return 0;
  1304. }
  1305. /*------------------------------------------------------------------*/
  1306. /*
  1307. * Wireless Private Handler : get country
  1308. */
  1309. static int ray_get_country(struct net_device *dev,
  1310. struct iw_request_info *info,
  1311. union iwreq_data *wrqu,
  1312. char *extra)
  1313. {
  1314. *(extra) = country;
  1315. return 0;
  1316. }
  1317. /*------------------------------------------------------------------*/
  1318. /*
  1319. * Commit handler : called after a bunch of SET operations
  1320. */
  1321. static int ray_commit(struct net_device *dev,
  1322. struct iw_request_info *info, /* NULL */
  1323. void *zwrq, /* NULL */
  1324. char *extra) /* NULL */
  1325. {
  1326. return 0;
  1327. }
  1328. /*------------------------------------------------------------------*/
  1329. /*
  1330. * Stats handler : return Wireless Stats
  1331. */
  1332. static iw_stats * ray_get_wireless_stats(struct net_device * dev)
  1333. {
  1334. ray_dev_t * local = (ray_dev_t *) dev->priv;
  1335. struct pcmcia_device *link = local->finder;
  1336. struct status __iomem *p = local->sram + STATUS_BASE;
  1337. if(local == (ray_dev_t *) NULL)
  1338. return (iw_stats *) NULL;
  1339. local->wstats.status = local->card_status;
  1340. #ifdef WIRELESS_SPY
  1341. if((local->spy_data.spy_number > 0) && (local->sparm.b5.a_network_type == 0))
  1342. {
  1343. /* Get it from the first node in spy list */
  1344. local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
  1345. local->wstats.qual.level = local->spy_data.spy_stat[0].level;
  1346. local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
  1347. local->wstats.qual.updated = local->spy_data.spy_stat[0].updated;
  1348. }
  1349. #endif /* WIRELESS_SPY */
  1350. if(pcmcia_dev_present(link)) {
  1351. local->wstats.qual.noise = readb(&p->rxnoise);
  1352. local->wstats.qual.updated |= 4;
  1353. }
  1354. return &local->wstats;
  1355. } /* end ray_get_wireless_stats */
  1356. /*------------------------------------------------------------------*/
  1357. /*
  1358. * Structures to export the Wireless Handlers
  1359. */
  1360. static const iw_handler ray_handler[] = {
  1361. [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) ray_commit,
  1362. [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) ray_get_name,
  1363. [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) ray_set_freq,
  1364. [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) ray_get_freq,
  1365. [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) ray_set_mode,
  1366. [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) ray_get_mode,
  1367. [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) ray_get_range,
  1368. #ifdef WIRELESS_SPY
  1369. [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
  1370. [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
  1371. [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
  1372. [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
  1373. #endif /* WIRELESS_SPY */
  1374. [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) ray_get_wap,
  1375. [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) ray_set_essid,
  1376. [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) ray_get_essid,
  1377. [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) ray_set_rate,
  1378. [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) ray_get_rate,
  1379. [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) ray_set_rts,
  1380. [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) ray_get_rts,
  1381. [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) ray_set_frag,
  1382. [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) ray_get_frag,
  1383. };
  1384. #define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
  1385. #define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
  1386. #define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
  1387. static const iw_handler ray_private_handler[] = {
  1388. [0] = (iw_handler) ray_set_framing,
  1389. [1] = (iw_handler) ray_get_framing,
  1390. [3] = (iw_handler) ray_get_country,
  1391. };
  1392. static const struct iw_priv_args ray_private_args[] = {
  1393. /* cmd, set_args, get_args, name */
  1394. { SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "set_framing" },
  1395. { SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_framing" },
  1396. { SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_country" },
  1397. };
  1398. static const struct iw_handler_def ray_handler_def =
  1399. {
  1400. .num_standard = sizeof(ray_handler)/sizeof(iw_handler),
  1401. .num_private = sizeof(ray_private_handler)/sizeof(iw_handler),
  1402. .num_private_args = sizeof(ray_private_args)/sizeof(struct iw_priv_args),
  1403. .standard = ray_handler,
  1404. .private = ray_private_handler,
  1405. .private_args = ray_private_args,
  1406. .get_wireless_stats = ray_get_wireless_stats,
  1407. };
  1408. /*===========================================================================*/
  1409. static int ray_open(struct net_device *dev)
  1410. {
  1411. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1412. struct pcmcia_device *link;
  1413. link = local->finder;
  1414. DEBUG(1, "ray_open('%s')\n", dev->name);
  1415. if (link->open == 0)
  1416. local->num_multi = 0;
  1417. link->open++;
  1418. /* If the card is not started, time to start it ! - Jean II */
  1419. if(local->card_status == CARD_AWAITING_PARAM) {
  1420. int i;
  1421. DEBUG(1,"ray_open: doing init now !\n");
  1422. /* Download startup parameters */
  1423. if ( (i = dl_startup_params(dev)) < 0)
  1424. {
  1425. printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
  1426. "returns 0x%x\n",i);
  1427. return -1;
  1428. }
  1429. }
  1430. if (sniffer) netif_stop_queue(dev);
  1431. else netif_start_queue(dev);
  1432. DEBUG(2,"ray_open ending\n");
  1433. return 0;
  1434. } /* end ray_open */
  1435. /*===========================================================================*/
  1436. static int ray_dev_close(struct net_device *dev)
  1437. {
  1438. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1439. struct pcmcia_device *link;
  1440. link = local->finder;
  1441. DEBUG(1, "ray_dev_close('%s')\n", dev->name);
  1442. link->open--;
  1443. netif_stop_queue(dev);
  1444. /* In here, we should stop the hardware (stop card from beeing active)
  1445. * and set local->card_status to CARD_AWAITING_PARAM, so that while the
  1446. * card is closed we can chage its configuration.
  1447. * Probably also need a COR reset to get sane state - Jean II */
  1448. return 0;
  1449. } /* end ray_dev_close */
  1450. /*===========================================================================*/
  1451. static void ray_reset(struct net_device *dev) {
  1452. DEBUG(1,"ray_reset entered\n");
  1453. return;
  1454. }
  1455. /*===========================================================================*/
  1456. /* Cause a firmware interrupt if it is ready for one */
  1457. /* Return nonzero if not ready */
  1458. static int interrupt_ecf(ray_dev_t *local, int ccs)
  1459. {
  1460. int i = 50;
  1461. struct pcmcia_device *link = local->finder;
  1462. if (!(pcmcia_dev_present(link))) {
  1463. DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
  1464. return -1;
  1465. }
  1466. DEBUG(2,"interrupt_ecf(local=%p, ccs = 0x%x\n",local,ccs);
  1467. while ( i &&
  1468. (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & ECF_INTR_SET))
  1469. i--;
  1470. if (i == 0) {
  1471. DEBUG(2,"ray_cs interrupt_ecf card not ready for interrupt\n");
  1472. return -1;
  1473. }
  1474. /* Fill the mailbox, then kick the card */
  1475. writeb(ccs, local->sram + SCB_BASE);
  1476. writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
  1477. return 0;
  1478. } /* interrupt_ecf */
  1479. /*===========================================================================*/
  1480. /* Get next free transmit CCS */
  1481. /* Return - index of current tx ccs */
  1482. static int get_free_tx_ccs(ray_dev_t *local)
  1483. {
  1484. int i;
  1485. struct ccs __iomem *pccs = ccs_base(local);
  1486. struct pcmcia_device *link = local->finder;
  1487. if (!(pcmcia_dev_present(link))) {
  1488. DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
  1489. return ECARDGONE;
  1490. }
  1491. if (test_and_set_bit(0,&local->tx_ccs_lock)) {
  1492. DEBUG(1,"ray_cs tx_ccs_lock busy\n");
  1493. return ECCSBUSY;
  1494. }
  1495. for (i=0; i < NUMBER_OF_TX_CCS; i++) {
  1496. if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
  1497. writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
  1498. writeb(CCS_END_LIST, &(pccs+i)->link);
  1499. local->tx_ccs_lock = 0;
  1500. return i;
  1501. }
  1502. }
  1503. local->tx_ccs_lock = 0;
  1504. DEBUG(2,"ray_cs ERROR no free tx CCS for raylink card\n");
  1505. return ECCSFULL;
  1506. } /* get_free_tx_ccs */
  1507. /*===========================================================================*/
  1508. /* Get next free CCS */
  1509. /* Return - index of current ccs */
  1510. static int get_free_ccs(ray_dev_t *local)
  1511. {
  1512. int i;
  1513. struct ccs __iomem *pccs = ccs_base(local);
  1514. struct pcmcia_device *link = local->finder;
  1515. if (!(pcmcia_dev_present(link))) {
  1516. DEBUG(2,"ray_cs get_free_ccs - device not present\n");
  1517. return ECARDGONE;
  1518. }
  1519. if (test_and_set_bit(0,&local->ccs_lock)) {
  1520. DEBUG(1,"ray_cs ccs_lock busy\n");
  1521. return ECCSBUSY;
  1522. }
  1523. for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
  1524. if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
  1525. writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
  1526. writeb(CCS_END_LIST, &(pccs+i)->link);
  1527. local->ccs_lock = 0;
  1528. return i;
  1529. }
  1530. }
  1531. local->ccs_lock = 0;
  1532. DEBUG(1,"ray_cs ERROR no free CCS for raylink card\n");
  1533. return ECCSFULL;
  1534. } /* get_free_ccs */
  1535. /*===========================================================================*/
  1536. static void authenticate_timeout(u_long data)
  1537. {
  1538. ray_dev_t *local = (ray_dev_t *)data;
  1539. del_timer(&local->timer);
  1540. printk(KERN_INFO "ray_cs Authentication with access point failed"
  1541. " - timeout\n");
  1542. join_net((u_long)local);
  1543. }
  1544. /*===========================================================================*/
  1545. static int asc_to_int(char a)
  1546. {
  1547. if (a < '0') return -1;
  1548. if (a <= '9') return (a - '0');
  1549. if (a < 'A') return -1;
  1550. if (a <= 'F') return (10 + a - 'A');
  1551. if (a < 'a') return -1;
  1552. if (a <= 'f') return (10 + a - 'a');
  1553. return -1;
  1554. }
  1555. /*===========================================================================*/
  1556. static int parse_addr(char *in_str, UCHAR *out)
  1557. {
  1558. int len;
  1559. int i,j,k;
  1560. int status;
  1561. if (in_str == NULL) return 0;
  1562. if ((len = strlen(in_str)) < 2) return 0;
  1563. memset(out, 0, ADDRLEN);
  1564. status = 1;
  1565. j = len - 1;
  1566. if (j > 12) j = 12;
  1567. i = 5;
  1568. while (j > 0)
  1569. {
  1570. if ((k = asc_to_int(in_str[j--])) != -1) out[i] = k;
  1571. else return 0;
  1572. if (j == 0) break;
  1573. if ((k = asc_to_int(in_str[j--])) != -1) out[i] += k << 4;
  1574. else return 0;
  1575. if (!i--) break;
  1576. }
  1577. return status;
  1578. }
  1579. /*===========================================================================*/
  1580. static struct net_device_stats *ray_get_stats(struct net_device *dev)
  1581. {
  1582. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1583. struct pcmcia_device *link = local->finder;
  1584. struct status __iomem *p = local->sram + STATUS_BASE;
  1585. if (!(pcmcia_dev_present(link))) {
  1586. DEBUG(2,"ray_cs net_device_stats - device not present\n");
  1587. return &local->stats;
  1588. }
  1589. if (readb(&p->mrx_overflow_for_host))
  1590. {
  1591. local->stats.rx_over_errors += ntohs(readb(&p->mrx_overflow));
  1592. writeb(0,&p->mrx_overflow);
  1593. writeb(0,&p->mrx_overflow_for_host);
  1594. }
  1595. if (readb(&p->mrx_checksum_error_for_host))
  1596. {
  1597. local->stats.rx_crc_errors += ntohs(readb(&p->mrx_checksum_error));
  1598. writeb(0,&p->mrx_checksum_error);
  1599. writeb(0,&p->mrx_checksum_error_for_host);
  1600. }
  1601. if (readb(&p->rx_hec_error_for_host))
  1602. {
  1603. local->stats.rx_frame_errors += ntohs(readb(&p->rx_hec_error));
  1604. writeb(0,&p->rx_hec_error);
  1605. writeb(0,&p->rx_hec_error_for_host);
  1606. }
  1607. return &local->stats;
  1608. }
  1609. /*===========================================================================*/
  1610. static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
  1611. {
  1612. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1613. struct pcmcia_device *link = local->finder;
  1614. int ccsindex;
  1615. int i;
  1616. struct ccs __iomem *pccs;
  1617. if (!(pcmcia_dev_present(link))) {
  1618. DEBUG(2,"ray_update_parm - device not present\n");
  1619. return;
  1620. }
  1621. if ((ccsindex = get_free_ccs(local)) < 0)
  1622. {
  1623. DEBUG(0,"ray_update_parm - No free ccs\n");
  1624. return;
  1625. }
  1626. pccs = ccs_base(local) + ccsindex;
  1627. writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
  1628. writeb(objid, &pccs->var.update_param.object_id);
  1629. writeb(1, &pccs->var.update_param.number_objects);
  1630. writeb(0, &pccs->var.update_param.failure_cause);
  1631. for (i=0; i<len; i++) {
  1632. writeb(value[i], local->sram + HOST_TO_ECF_BASE);
  1633. }
  1634. /* Interrupt the firmware to process the command */
  1635. if (interrupt_ecf(local, ccsindex)) {
  1636. DEBUG(0,"ray_cs associate failed - ECF not ready for intr\n");
  1637. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  1638. }
  1639. }
  1640. /*===========================================================================*/
  1641. static void ray_update_multi_list(struct net_device *dev, int all)
  1642. {
  1643. struct dev_mc_list *dmi, **dmip;
  1644. int ccsindex;
  1645. struct ccs __iomem *pccs;
  1646. int i = 0;
  1647. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1648. struct pcmcia_device *link = local->finder;
  1649. void __iomem *p = local->sram + HOST_TO_ECF_BASE;
  1650. if (!(pcmcia_dev_present(link))) {
  1651. DEBUG(2,"ray_update_multi_list - device not present\n");
  1652. return;
  1653. }
  1654. else
  1655. DEBUG(2,"ray_update_multi_list(%p)\n",dev);
  1656. if ((ccsindex = get_free_ccs(local)) < 0)
  1657. {
  1658. DEBUG(1,"ray_update_multi - No free ccs\n");
  1659. return;
  1660. }
  1661. pccs = ccs_base(local) + ccsindex;
  1662. writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
  1663. if (all) {
  1664. writeb(0xff, &pccs->var);
  1665. local->num_multi = 0xff;
  1666. }
  1667. else {
  1668. /* Copy the kernel's list of MC addresses to card */
  1669. for (dmip=&dev->mc_list; (dmi=*dmip)!=NULL; dmip=&dmi->next) {
  1670. memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
  1671. DEBUG(1,"ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",dmi->dmi_addr[0],dmi->dmi_addr[1],dmi->dmi_addr[2],dmi->dmi_addr[3],dmi->dmi_addr[4],dmi->dmi_addr[5]);
  1672. p += ETH_ALEN;
  1673. i++;
  1674. }
  1675. if (i > 256/ADDRLEN) i = 256/ADDRLEN;
  1676. writeb((UCHAR)i, &pccs->var);
  1677. DEBUG(1,"ray_cs update_multi %d addresses in list\n", i);
  1678. /* Interrupt the firmware to process the command */
  1679. local->num_multi = i;
  1680. }
  1681. if (interrupt_ecf(local, ccsindex)) {
  1682. DEBUG(1,"ray_cs update_multi failed - ECF not ready for intr\n");
  1683. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  1684. }
  1685. } /* end ray_update_multi_list */
  1686. /*===========================================================================*/
  1687. static void set_multicast_list(struct net_device *dev)
  1688. {
  1689. ray_dev_t *local = (ray_dev_t *)dev->priv;
  1690. UCHAR promisc;
  1691. DEBUG(2,"ray_cs set_multicast_list(%p)\n",dev);
  1692. if (dev->flags & IFF_PROMISC)
  1693. {
  1694. if (local->sparm.b5.a_promiscuous_mode == 0) {
  1695. DEBUG(1,"ray_cs set_multicast_list promisc on\n");
  1696. local->sparm.b5.a_promiscuous_mode = 1;
  1697. promisc = 1;
  1698. ray_update_parm(dev, OBJID_promiscuous_mode, \
  1699. &promisc, sizeof(promisc));
  1700. }
  1701. }
  1702. else {
  1703. if (local->sparm.b5.a_promiscuous_mode == 1) {
  1704. DEBUG(1,"ray_cs set_multicast_list promisc off\n");
  1705. local->sparm.b5.a_promiscuous_mode = 0;
  1706. promisc = 0;
  1707. ray_update_parm(dev, OBJID_promiscuous_mode, \
  1708. &promisc, sizeof(promisc));
  1709. }
  1710. }
  1711. if (dev->flags & IFF_ALLMULTI) ray_update_multi_list(dev, 1);
  1712. else
  1713. {
  1714. if (local->num_multi != dev->mc_count) ray_update_multi_list(dev, 0);
  1715. }
  1716. } /* end set_multicast_list */
  1717. /*=============================================================================
  1718. * All routines below here are run at interrupt time.
  1719. =============================================================================*/
  1720. static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
  1721. {
  1722. struct net_device *dev = (struct net_device *)dev_id;
  1723. struct pcmcia_device *link;
  1724. ray_dev_t *local;
  1725. struct ccs __iomem *pccs;
  1726. struct rcs __iomem *prcs;
  1727. UCHAR rcsindex;
  1728. UCHAR tmp;
  1729. UCHAR cmd;
  1730. UCHAR status;
  1731. if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
  1732. return IRQ_NONE;
  1733. DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
  1734. local = (ray_dev_t *)dev->priv;
  1735. link = (struct pcmcia_device *)local->finder;
  1736. if (!pcmcia_dev_present(link)) {
  1737. DEBUG(2,"ray_cs interrupt from device not present or suspended.\n");
  1738. return IRQ_NONE;
  1739. }
  1740. rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
  1741. if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS))
  1742. {
  1743. DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
  1744. clear_interrupt(local);
  1745. return IRQ_HANDLED;
  1746. }
  1747. if (rcsindex < NUMBER_OF_CCS) /* If it's a returned CCS */
  1748. {
  1749. pccs = ccs_base(local) + rcsindex;
  1750. cmd = readb(&pccs->cmd);
  1751. status = readb(&pccs->buffer_status);
  1752. switch (cmd)
  1753. {
  1754. case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
  1755. del_timer(&local->timer);
  1756. if (status == CCS_COMMAND_COMPLETE) {
  1757. DEBUG(1,"ray_cs interrupt download_startup_parameters OK\n");
  1758. }
  1759. else {
  1760. DEBUG(1,"ray_cs interrupt download_startup_parameters fail\n");
  1761. }
  1762. break;
  1763. case CCS_UPDATE_PARAMS:
  1764. DEBUG(1,"ray_cs interrupt update params done\n");
  1765. if (status != CCS_COMMAND_COMPLETE) {
  1766. tmp = readb(&pccs->var.update_param.failure_cause);
  1767. DEBUG(0,"ray_cs interrupt update params failed - reason %d\n",tmp);
  1768. }
  1769. break;
  1770. case CCS_REPORT_PARAMS:
  1771. DEBUG(1,"ray_cs interrupt report params done\n");
  1772. break;
  1773. case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
  1774. DEBUG(1,"ray_cs interrupt CCS Update Multicast List done\n");
  1775. break;
  1776. case CCS_UPDATE_POWER_SAVINGS_MODE:
  1777. DEBUG(1,"ray_cs interrupt update power save mode done\n");
  1778. break;
  1779. case CCS_START_NETWORK:
  1780. case CCS_JOIN_NETWORK:
  1781. if (status == CCS_COMMAND_COMPLETE) {
  1782. if (readb(&pccs->var.start_network.net_initiated) == 1) {
  1783. DEBUG(0,"ray_cs interrupt network \"%s\" started\n",\
  1784. local->sparm.b4.a_current_ess_id);
  1785. }
  1786. else {
  1787. DEBUG(0,"ray_cs interrupt network \"%s\" joined\n",\
  1788. local->sparm.b4.a_current_ess_id);
  1789. }
  1790. memcpy_fromio(&local->bss_id,pccs->var.start_network.bssid,ADDRLEN);
  1791. if (local->fw_ver == 0x55) local->net_default_tx_rate = 3;
  1792. else local->net_default_tx_rate =
  1793. readb(&pccs->var.start_network.net_default_tx_rate);
  1794. local->encryption = readb(&pccs->var.start_network.encryption);
  1795. if (!sniffer && (local->net_type == INFRA)
  1796. && !(local->sparm.b4.a_acting_as_ap_status)) {
  1797. authenticate(local);
  1798. }
  1799. local->card_status = CARD_ACQ_COMPLETE;
  1800. }
  1801. else {
  1802. local->card_status = CARD_ACQ_FAILED;
  1803. del_timer(&local->timer);
  1804. local->timer.expires = jiffies + HZ*5;
  1805. local->timer.data = (long)local;
  1806. if (status == CCS_START_NETWORK) {
  1807. DEBUG(0,"ray_cs interrupt network \"%s\" start failed\n",\
  1808. local->sparm.b4.a_current_ess_id);
  1809. local->timer.function = &start_net;
  1810. }
  1811. else {
  1812. DEBUG(0,"ray_cs interrupt network \"%s\" join failed\n",\
  1813. local->sparm.b4.a_current_ess_id);
  1814. local->timer.function = &join_net;
  1815. }
  1816. add_timer(&local->timer);
  1817. }
  1818. break;
  1819. case CCS_START_ASSOCIATION:
  1820. if (status == CCS_COMMAND_COMPLETE) {
  1821. local->card_status = CARD_ASSOC_COMPLETE;
  1822. DEBUG(0,"ray_cs association successful\n");
  1823. }
  1824. else
  1825. {
  1826. DEBUG(0,"ray_cs association failed,\n");
  1827. local->card_status = CARD_ASSOC_FAILED;
  1828. join_net((u_long)local);
  1829. }
  1830. break;
  1831. case CCS_TX_REQUEST:
  1832. if (status == CCS_COMMAND_COMPLETE) {
  1833. DEBUG(3,"ray_cs interrupt tx request complete\n");
  1834. }
  1835. else {
  1836. DEBUG(1,"ray_cs interrupt tx request failed\n");
  1837. }
  1838. if (!sniffer) netif_start_queue(dev);
  1839. netif_wake_queue(dev);
  1840. break;
  1841. case CCS_TEST_MEMORY:
  1842. DEBUG(1,"ray_cs interrupt mem test done\n");
  1843. break;
  1844. case CCS_SHUTDOWN:
  1845. DEBUG(1,"ray_cs interrupt Unexpected CCS returned - Shutdown\n");
  1846. break;
  1847. case CCS_DUMP_MEMORY:
  1848. DEBUG(1,"ray_cs interrupt dump memory done\n");
  1849. break;
  1850. case CCS_START_TIMER:
  1851. DEBUG(2,"ray_cs interrupt DING - raylink timer expired\n");
  1852. break;
  1853. default:
  1854. DEBUG(1,"ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",\
  1855. rcsindex, cmd);
  1856. }
  1857. writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
  1858. }
  1859. else /* It's an RCS */
  1860. {
  1861. prcs = rcs_base(local) + rcsindex;
  1862. switch (readb(&prcs->interrupt_id))
  1863. {
  1864. case PROCESS_RX_PACKET:
  1865. ray_rx(dev, local, prcs);
  1866. break;
  1867. case REJOIN_NET_COMPLETE:
  1868. DEBUG(1,"ray_cs interrupt rejoin net complete\n");
  1869. local->card_status = CARD_ACQ_COMPLETE;
  1870. /* do we need to clear tx buffers CCS's? */
  1871. if (local->sparm.b4.a_network_type == ADHOC) {
  1872. if (!sniffer) netif_start_queue(dev);
  1873. }
  1874. else {
  1875. memcpy_fromio(&local->bss_id, prcs->var.rejoin_net_complete.bssid, ADDRLEN);
  1876. DEBUG(1,"ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",\
  1877. local->bss_id[0], local->bss_id[1], local->bss_id[2],\
  1878. local->bss_id[3], local->bss_id[4], local->bss_id[5]);
  1879. if (!sniffer) authenticate(local);
  1880. }
  1881. break;
  1882. case ROAMING_INITIATED:
  1883. DEBUG(1,"ray_cs interrupt roaming initiated\n");
  1884. netif_stop_queue(dev);
  1885. local->card_status = CARD_DOING_ACQ;
  1886. break;
  1887. case JAPAN_CALL_SIGN_RXD:
  1888. DEBUG(1,"ray_cs interrupt japan call sign rx\n");
  1889. break;
  1890. default:
  1891. DEBUG(1,"ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",\
  1892. rcsindex, (unsigned int) readb(&prcs->interrupt_id));
  1893. break;
  1894. }
  1895. writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
  1896. }
  1897. clear_interrupt(local);
  1898. return IRQ_HANDLED;
  1899. } /* ray_interrupt */
  1900. /*===========================================================================*/
  1901. static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs)
  1902. {
  1903. int rx_len;
  1904. unsigned int pkt_addr;
  1905. void __iomem *pmsg;
  1906. DEBUG(4,"ray_rx process rx packet\n");
  1907. /* Calculate address of packet within Rx buffer */
  1908. pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
  1909. + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
  1910. /* Length of first packet fragment */
  1911. rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
  1912. + readb(&prcs->var.rx_packet.rx_data_length[1]);
  1913. local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
  1914. pmsg = local->rmem + pkt_addr;
  1915. switch(readb(pmsg))
  1916. {
  1917. case DATA_TYPE:
  1918. DEBUG(4,"ray_rx data type\n");
  1919. rx_data(dev, prcs, pkt_addr, rx_len);
  1920. break;
  1921. case AUTHENTIC_TYPE:
  1922. DEBUG(4,"ray_rx authentic type\n");
  1923. if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
  1924. else rx_authenticate(local, prcs, pkt_addr, rx_len);
  1925. break;
  1926. case DEAUTHENTIC_TYPE:
  1927. DEBUG(4,"ray_rx deauth type\n");
  1928. if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
  1929. else rx_deauthenticate(local, prcs, pkt_addr, rx_len);
  1930. break;
  1931. case NULL_MSG_TYPE:
  1932. DEBUG(3,"ray_cs rx NULL msg\n");
  1933. break;
  1934. case BEACON_TYPE:
  1935. DEBUG(4,"ray_rx beacon type\n");
  1936. if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
  1937. copy_from_rx_buff(local, (UCHAR *)&local->last_bcn, pkt_addr,
  1938. rx_len < sizeof(struct beacon_rx) ?
  1939. rx_len : sizeof(struct beacon_rx));
  1940. local->beacon_rxed = 1;
  1941. /* Get the statistics so the card counters never overflow */
  1942. ray_get_stats(dev);
  1943. break;
  1944. default:
  1945. DEBUG(0,"ray_cs unknown pkt type %2x\n", (unsigned int) readb(pmsg));
  1946. break;
  1947. }
  1948. } /* end ray_rx */
  1949. /*===========================================================================*/
  1950. static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,
  1951. int rx_len)
  1952. {
  1953. struct sk_buff *skb = NULL;
  1954. struct rcs __iomem *prcslink = prcs;
  1955. ray_dev_t *local = dev->priv;
  1956. UCHAR *rx_ptr;
  1957. int total_len;
  1958. int tmp;
  1959. #ifdef WIRELESS_SPY
  1960. int siglev = local->last_rsl;
  1961. u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
  1962. #endif
  1963. if (!sniffer) {
  1964. if (translate) {
  1965. /* TBD length needs fixing for translated header */
  1966. if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
  1967. rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
  1968. {
  1969. DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
  1970. return;
  1971. }
  1972. }
  1973. else /* encapsulated ethernet */ {
  1974. if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
  1975. rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
  1976. {
  1977. DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
  1978. return;
  1979. }
  1980. }
  1981. }
  1982. DEBUG(4,"ray_cs rx_data packet\n");
  1983. /* If fragmented packet, verify sizes of fragments add up */
  1984. if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
  1985. DEBUG(1,"ray_cs rx'ed fragment\n");
  1986. tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
  1987. + readb(&prcs->var.rx_packet.totalpacketlength[1]);
  1988. total_len = tmp;
  1989. prcslink = prcs;
  1990. do {
  1991. tmp -= (readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
  1992. + readb(&prcslink->var.rx_packet.rx_data_length[1]);
  1993. if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) == 0xFF
  1994. || tmp < 0) break;
  1995. prcslink = rcs_base(local)
  1996. + readb(&prcslink->link_field);
  1997. } while (1);
  1998. if (tmp < 0)
  1999. {
  2000. DEBUG(0,"ray_cs rx_data fragment lengths don't add up\n");
  2001. local->stats.rx_dropped++;
  2002. release_frag_chain(local, prcs);
  2003. return;
  2004. }
  2005. }
  2006. else { /* Single unfragmented packet */
  2007. total_len = rx_len;
  2008. }
  2009. skb = dev_alloc_skb( total_len+5 );
  2010. if (skb == NULL)
  2011. {
  2012. DEBUG(0,"ray_cs rx_data could not allocate skb\n");
  2013. local->stats.rx_dropped++;
  2014. if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
  2015. release_frag_chain(local, prcs);
  2016. return;
  2017. }
  2018. skb_reserve( skb, 2); /* Align IP on 16 byte (TBD check this)*/
  2019. skb->dev = dev;
  2020. DEBUG(4,"ray_cs rx_data total_len = %x, rx_len = %x\n",total_len,rx_len);
  2021. /************************/
  2022. /* Reserve enough room for the whole damn packet. */
  2023. rx_ptr = skb_put( skb, total_len);
  2024. /* Copy the whole packet to sk_buff */
  2025. rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
  2026. /* Get source address */
  2027. #ifdef WIRELESS_SPY
  2028. memcpy(linksrcaddr, ((struct mac_header *)skb->data)->addr_2, ETH_ALEN);
  2029. #endif
  2030. /* Now, deal with encapsulation/translation/sniffer */
  2031. if (!sniffer) {
  2032. if (!translate) {
  2033. /* Encapsulated ethernet, so just lop off 802.11 MAC header */
  2034. /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
  2035. skb_pull( skb, RX_MAC_HEADER_LENGTH);
  2036. }
  2037. else {
  2038. /* Do translation */
  2039. untranslate(local, skb, total_len);
  2040. }
  2041. }
  2042. else
  2043. { /* sniffer mode, so just pass whole packet */ };
  2044. /************************/
  2045. /* Now pick up the rest of the fragments if any */
  2046. tmp = 17;
  2047. if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
  2048. prcslink = prcs;
  2049. DEBUG(1,"ray_cs rx_data in fragment loop\n");
  2050. do {
  2051. prcslink = rcs_base(local)
  2052. + readb(&prcslink->var.rx_packet.next_frag_rcs_index);
  2053. rx_len = (( readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
  2054. + readb(&prcslink->var.rx_packet.rx_data_length[1]))
  2055. & RX_BUFF_END;
  2056. pkt_addr = (( readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 8)
  2057. + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
  2058. & RX_BUFF_END;
  2059. rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
  2060. } while (tmp-- &&
  2061. readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 0xFF);
  2062. release_frag_chain(local, prcs);
  2063. }
  2064. skb->protocol = eth_type_trans(skb,dev);
  2065. netif_rx(skb);
  2066. dev->last_rx = jiffies;
  2067. local->stats.rx_packets++;
  2068. local->stats.rx_bytes += total_len;
  2069. /* Gather signal strength per address */
  2070. #ifdef WIRELESS_SPY
  2071. /* For the Access Point or the node having started the ad-hoc net
  2072. * note : ad-hoc work only in some specific configurations, but we
  2073. * kludge in ray_get_wireless_stats... */
  2074. if(!memcmp(linksrcaddr, local->bss_id, ETH_ALEN))
  2075. {
  2076. /* Update statistics */
  2077. /*local->wstats.qual.qual = none ? */
  2078. local->wstats.qual.level = siglev;
  2079. /*local->wstats.qual.noise = none ? */
  2080. local->wstats.qual.updated = 0x2;
  2081. }
  2082. /* Now, update the spy stuff */
  2083. {
  2084. struct iw_quality wstats;
  2085. wstats.level = siglev;
  2086. /* wstats.noise = none ? */
  2087. /* wstats.qual = none ? */
  2088. wstats.updated = 0x2;
  2089. /* Update spy records */
  2090. wireless_spy_update(dev, linksrcaddr, &wstats);
  2091. }
  2092. #endif /* WIRELESS_SPY */
  2093. } /* end rx_data */
  2094. /*===========================================================================*/
  2095. static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
  2096. {
  2097. snaphdr_t *psnap = (snaphdr_t *)(skb->data + RX_MAC_HEADER_LENGTH);
  2098. struct mac_header *pmac = (struct mac_header *)skb->data;
  2099. unsigned short type = *(unsigned short *)psnap->ethertype;
  2100. unsigned int xsap = *(unsigned int *)psnap & 0x00ffffff;
  2101. unsigned int org = (*(unsigned int *)psnap->org) & 0x00ffffff;
  2102. int delta;
  2103. struct ethhdr *peth;
  2104. UCHAR srcaddr[ADDRLEN];
  2105. UCHAR destaddr[ADDRLEN];
  2106. if (pmac->frame_ctl_2 & FC2_FROM_DS) {
  2107. if (pmac->frame_ctl_2 & FC2_TO_DS) { /* AP to AP */
  2108. memcpy(destaddr, pmac->addr_3, ADDRLEN);
  2109. memcpy(srcaddr, ((unsigned char *)pmac->addr_3) + ADDRLEN, ADDRLEN);
  2110. } else { /* AP to terminal */
  2111. memcpy(destaddr, pmac->addr_1, ADDRLEN);
  2112. memcpy(srcaddr, pmac->addr_3, ADDRLEN);
  2113. }
  2114. } else { /* Terminal to AP */
  2115. if (pmac->frame_ctl_2 & FC2_TO_DS) {
  2116. memcpy(destaddr, pmac->addr_3, ADDRLEN);
  2117. memcpy(srcaddr, pmac->addr_2, ADDRLEN);
  2118. } else { /* Adhoc */
  2119. memcpy(destaddr, pmac->addr_1, ADDRLEN);
  2120. memcpy(srcaddr, pmac->addr_2, ADDRLEN);
  2121. }
  2122. }
  2123. #ifdef PCMCIA_DEBUG
  2124. if (pc_debug > 3) {
  2125. int i;
  2126. printk(KERN_DEBUG "skb->data before untranslate");
  2127. for (i=0;i<64;i++)
  2128. printk("%02x ",skb->data[i]);
  2129. printk("\n" KERN_DEBUG "type = %08x, xsap = %08x, org = %08x\n",
  2130. type,xsap,org);
  2131. printk(KERN_DEBUG "untranslate skb->data = %p\n",skb->data);
  2132. }
  2133. #endif
  2134. if ( xsap != SNAP_ID) {
  2135. /* not a snap type so leave it alone */
  2136. DEBUG(3,"ray_cs untranslate NOT SNAP %x\n", *(unsigned int *)psnap & 0x00ffffff);
  2137. delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
  2138. peth = (struct ethhdr *)(skb->data + delta);
  2139. peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
  2140. }
  2141. else { /* Its a SNAP */
  2142. if (org == BRIDGE_ENCAP) { /* EtherII and nuke the LLC */
  2143. DEBUG(3,"ray_cs untranslate Bridge encap\n");
  2144. delta = RX_MAC_HEADER_LENGTH
  2145. + sizeof(struct snaphdr_t) - ETH_HLEN;
  2146. peth = (struct ethhdr *)(skb->data + delta);
  2147. peth->h_proto = type;
  2148. }
  2149. else {
  2150. if (org == RFC1042_ENCAP) {
  2151. switch (type) {
  2152. case RAY_IPX_TYPE:
  2153. case APPLEARP_TYPE:
  2154. DEBUG(3,"ray_cs untranslate RFC IPX/AARP\n");
  2155. delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
  2156. peth = (struct ethhdr *)(skb->data + delta);
  2157. peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
  2158. break;
  2159. default:
  2160. DEBUG(3,"ray_cs untranslate RFC default\n");
  2161. delta = RX_MAC_HEADER_LENGTH +
  2162. sizeof(struct snaphdr_t) - ETH_HLEN;
  2163. peth = (struct ethhdr *)(skb->data + delta);
  2164. peth->h_proto = type;
  2165. break;
  2166. }
  2167. }
  2168. else {
  2169. printk("ray_cs untranslate very confused by packet\n");
  2170. delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
  2171. peth = (struct ethhdr *)(skb->data + delta);
  2172. peth->h_proto = type;
  2173. }
  2174. }
  2175. }
  2176. /* TBD reserve skb_reserve(skb, delta); */
  2177. skb_pull(skb, delta);
  2178. DEBUG(3,"untranslate after skb_pull(%d), skb->data = %p\n",delta,skb->data);
  2179. memcpy(peth->h_dest, destaddr, ADDRLEN);
  2180. memcpy(peth->h_source, srcaddr, ADDRLEN);
  2181. #ifdef PCMCIA_DEBUG
  2182. if (pc_debug > 3) {
  2183. int i;
  2184. printk(KERN_DEBUG "skb->data after untranslate:");
  2185. for (i=0;i<64;i++)
  2186. printk("%02x ",skb->data[i]);
  2187. printk("\n");
  2188. }
  2189. #endif
  2190. } /* end untranslate */
  2191. /*===========================================================================*/
  2192. /* Copy data from circular receive buffer to PC memory.
  2193. * dest = destination address in PC memory
  2194. * pkt_addr = source address in receive buffer
  2195. * len = length of packet to copy
  2196. */
  2197. static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int length)
  2198. {
  2199. int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
  2200. if (wrap_bytes <= 0)
  2201. {
  2202. memcpy_fromio(dest,local->rmem + pkt_addr,length);
  2203. }
  2204. else /* Packet wrapped in circular buffer */
  2205. {
  2206. memcpy_fromio(dest,local->rmem+pkt_addr,length - wrap_bytes);
  2207. memcpy_fromio(dest + length - wrap_bytes, local->rmem, wrap_bytes);
  2208. }
  2209. return length;
  2210. }
  2211. /*===========================================================================*/
  2212. static void release_frag_chain(ray_dev_t *local, struct rcs __iomem * prcs)
  2213. {
  2214. struct rcs __iomem *prcslink = prcs;
  2215. int tmp = 17;
  2216. unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
  2217. while (tmp--) {
  2218. writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
  2219. if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
  2220. DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
  2221. break;
  2222. }
  2223. prcslink = rcs_base(local) + rcsindex;
  2224. rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
  2225. }
  2226. writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
  2227. }
  2228. /*===========================================================================*/
  2229. static void authenticate(ray_dev_t *local)
  2230. {
  2231. struct pcmcia_device *link = local->finder;
  2232. DEBUG(0,"ray_cs Starting authentication.\n");
  2233. if (!(pcmcia_dev_present(link))) {
  2234. DEBUG(2,"ray_cs authenticate - device not present\n");
  2235. return;
  2236. }
  2237. del_timer(&local->timer);
  2238. if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
  2239. local->timer.function = &join_net;
  2240. }
  2241. else {
  2242. local->timer.function = &authenticate_timeout;
  2243. }
  2244. local->timer.expires = jiffies + HZ*2;
  2245. local->timer.data = (long)local;
  2246. add_timer(&local->timer);
  2247. local->authentication_state = AWAITING_RESPONSE;
  2248. } /* end authenticate */
  2249. /*===========================================================================*/
  2250. static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
  2251. unsigned int pkt_addr, int rx_len)
  2252. {
  2253. UCHAR buff[256];
  2254. struct rx_msg *msg = (struct rx_msg *)buff;
  2255. del_timer(&local->timer);
  2256. copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
  2257. /* if we are trying to get authenticated */
  2258. if (local->sparm.b4.a_network_type == ADHOC) {
  2259. DEBUG(1,"ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n", msg->var[0],msg->var[1],msg->var[2],msg->var[3],msg->var[4],msg->var[5]);
  2260. if (msg->var[2] == 1) {
  2261. DEBUG(0,"ray_cs Sending authentication response.\n");
  2262. if (!build_auth_frame (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
  2263. local->authentication_state = NEED_TO_AUTH;
  2264. memcpy(local->auth_id, msg->mac.addr_2, ADDRLEN);
  2265. }
  2266. }
  2267. }
  2268. else /* Infrastructure network */
  2269. {
  2270. if (local->authentication_state == AWAITING_RESPONSE) {
  2271. /* Verify authentication sequence #2 and success */
  2272. if (msg->var[2] == 2) {
  2273. if ((msg->var[3] | msg->var[4]) == 0) {
  2274. DEBUG(1,"Authentication successful\n");
  2275. local->card_status = CARD_AUTH_COMPLETE;
  2276. associate(local);
  2277. local->authentication_state = AUTHENTICATED;
  2278. }
  2279. else {
  2280. DEBUG(0,"Authentication refused\n");
  2281. local->card_status = CARD_AUTH_REFUSED;
  2282. join_net((u_long)local);
  2283. local->authentication_state = UNAUTHENTICATED;
  2284. }
  2285. }
  2286. }
  2287. }
  2288. } /* end rx_authenticate */
  2289. /*===========================================================================*/
  2290. static void associate(ray_dev_t *local)
  2291. {
  2292. struct ccs __iomem *pccs;
  2293. struct pcmcia_device *link = local->finder;
  2294. struct net_device *dev = link->priv;
  2295. int ccsindex;
  2296. if (!(pcmcia_dev_present(link))) {
  2297. DEBUG(2,"ray_cs associate - device not present\n");
  2298. return;
  2299. }
  2300. /* If no tx buffers available, return*/
  2301. if ((ccsindex = get_free_ccs(local)) < 0)
  2302. {
  2303. /* TBD should never be here but... what if we are? */
  2304. DEBUG(1,"ray_cs associate - No free ccs\n");
  2305. return;
  2306. }
  2307. DEBUG(1,"ray_cs Starting association with access point\n");
  2308. pccs = ccs_base(local) + ccsindex;
  2309. /* fill in the CCS */
  2310. writeb(CCS_START_ASSOCIATION, &pccs->cmd);
  2311. /* Interrupt the firmware to process the command */
  2312. if (interrupt_ecf(local, ccsindex)) {
  2313. DEBUG(1,"ray_cs associate failed - ECF not ready for intr\n");
  2314. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  2315. del_timer(&local->timer);
  2316. local->timer.expires = jiffies + HZ*2;
  2317. local->timer.data = (long)local;
  2318. local->timer.function = &join_net;
  2319. add_timer(&local->timer);
  2320. local->card_status = CARD_ASSOC_FAILED;
  2321. return;
  2322. }
  2323. if (!sniffer) netif_start_queue(dev);
  2324. } /* end associate */
  2325. /*===========================================================================*/
  2326. static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
  2327. unsigned int pkt_addr, int rx_len)
  2328. {
  2329. /* UCHAR buff[256];
  2330. struct rx_msg *msg = (struct rx_msg *)buff;
  2331. */
  2332. DEBUG(0,"Deauthentication frame received\n");
  2333. local->authentication_state = UNAUTHENTICATED;
  2334. /* Need to reauthenticate or rejoin depending on reason code */
  2335. /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
  2336. */
  2337. }
  2338. /*===========================================================================*/
  2339. static void clear_interrupt(ray_dev_t *local)
  2340. {
  2341. writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
  2342. }
  2343. /*===========================================================================*/
  2344. #ifdef CONFIG_PROC_FS
  2345. #define MAXDATA (PAGE_SIZE - 80)
  2346. static char *card_status[] = {
  2347. "Card inserted - uninitialized", /* 0 */
  2348. "Card not downloaded", /* 1 */
  2349. "Waiting for download parameters", /* 2 */
  2350. "Card doing acquisition", /* 3 */
  2351. "Acquisition complete", /* 4 */
  2352. "Authentication complete", /* 5 */
  2353. "Association complete", /* 6 */
  2354. "???", "???", "???", "???", /* 7 8 9 10 undefined */
  2355. "Card init error", /* 11 */
  2356. "Download parameters error", /* 12 */
  2357. "???", /* 13 */
  2358. "Acquisition failed", /* 14 */
  2359. "Authentication refused", /* 15 */
  2360. "Association failed" /* 16 */
  2361. };
  2362. static char *nettype[] = {"Adhoc", "Infra "};
  2363. static char *framing[] = {"Encapsulation", "Translation"}
  2364. ;
  2365. /*===========================================================================*/
  2366. static int ray_cs_proc_read(char *buf, char **start, off_t offset, int len)
  2367. {
  2368. /* Print current values which are not available via other means
  2369. * eg ifconfig
  2370. */
  2371. int i;
  2372. struct pcmcia_device *link;
  2373. struct net_device *dev;
  2374. ray_dev_t *local;
  2375. UCHAR *p;
  2376. struct freq_hop_element *pfh;
  2377. UCHAR c[33];
  2378. link = this_device;
  2379. if (!link)
  2380. return 0;
  2381. dev = (struct net_device *)link->priv;
  2382. if (!dev)
  2383. return 0;
  2384. local = (ray_dev_t *)dev->priv;
  2385. if (!local)
  2386. return 0;
  2387. len = 0;
  2388. len += sprintf(buf + len, "Raylink Wireless LAN driver status\n");
  2389. len += sprintf(buf + len, "%s\n", rcsid);
  2390. /* build 4 does not report version, and field is 0x55 after memtest */
  2391. len += sprintf(buf + len, "Firmware version = ");
  2392. if (local->fw_ver == 0x55)
  2393. len += sprintf(buf + len, "4 - Use dump_cis for more details\n");
  2394. else
  2395. len += sprintf(buf + len, "%2d.%02d.%02d\n",
  2396. local->fw_ver, local->fw_bld, local->fw_var);
  2397. for (i=0; i<32; i++) c[i] = local->sparm.b5.a_current_ess_id[i];
  2398. c[32] = 0;
  2399. len += sprintf(buf + len, "%s network ESSID = \"%s\"\n",
  2400. nettype[local->sparm.b5.a_network_type], c);
  2401. p = local->bss_id;
  2402. len += sprintf(buf + len,
  2403. "BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
  2404. p[0],p[1],p[2],p[3],p[4],p[5]);
  2405. len += sprintf(buf + len, "Country code = %d\n",
  2406. local->sparm.b5.a_curr_country_code);
  2407. i = local->card_status;
  2408. if (i < 0) i = 10;
  2409. if (i > 16) i = 10;
  2410. len += sprintf(buf + len, "Card status = %s\n", card_status[i]);
  2411. len += sprintf(buf + len, "Framing mode = %s\n",framing[translate]);
  2412. len += sprintf(buf + len, "Last pkt signal lvl = %d\n", local->last_rsl);
  2413. if (local->beacon_rxed) {
  2414. /* Pull some fields out of last beacon received */
  2415. len += sprintf(buf + len, "Beacon Interval = %d Kus\n",
  2416. local->last_bcn.beacon_intvl[0]
  2417. + 256 * local->last_bcn.beacon_intvl[1]);
  2418. p = local->last_bcn.elements;
  2419. if (p[0] == C_ESSID_ELEMENT_ID) p += p[1] + 2;
  2420. else {
  2421. len += sprintf(buf + len, "Parse beacon failed at essid element id = %d\n",p[0]);
  2422. return len;
  2423. }
  2424. if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
  2425. len += sprintf(buf + len, "Supported rate codes = ");
  2426. for (i=2; i<p[1] + 2; i++)
  2427. len += sprintf(buf + len, "0x%02x ", p[i]);
  2428. len += sprintf(buf + len, "\n");
  2429. p += p[1] + 2;
  2430. }
  2431. else {
  2432. len += sprintf(buf + len, "Parse beacon failed at rates element\n");
  2433. return len;
  2434. }
  2435. if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
  2436. pfh = (struct freq_hop_element *)p;
  2437. len += sprintf(buf + len, "Hop dwell = %d Kus\n",
  2438. pfh->dwell_time[0] + 256 * pfh->dwell_time[1]);
  2439. len += sprintf(buf + len, "Hop set = %d \n", pfh->hop_set);
  2440. len += sprintf(buf + len, "Hop pattern = %d \n", pfh->hop_pattern);
  2441. len += sprintf(buf + len, "Hop index = %d \n", pfh->hop_index);
  2442. p += p[1] + 2;
  2443. }
  2444. else {
  2445. len += sprintf(buf + len, "Parse beacon failed at FH param element\n");
  2446. return len;
  2447. }
  2448. } else {
  2449. len += sprintf(buf + len, "No beacons received\n");
  2450. }
  2451. return len;
  2452. }
  2453. #endif
  2454. /*===========================================================================*/
  2455. static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
  2456. {
  2457. int addr;
  2458. struct ccs __iomem *pccs;
  2459. struct tx_msg __iomem *ptx;
  2460. int ccsindex;
  2461. /* If no tx buffers available, return */
  2462. if ((ccsindex = get_free_tx_ccs(local)) < 0)
  2463. {
  2464. DEBUG(1,"ray_cs send authenticate - No free tx ccs\n");
  2465. return -1;
  2466. }
  2467. pccs = ccs_base(local) + ccsindex;
  2468. /* Address in card space */
  2469. addr = TX_BUF_BASE + (ccsindex << 11);
  2470. /* fill in the CCS */
  2471. writeb(CCS_TX_REQUEST, &pccs->cmd);
  2472. writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
  2473. writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
  2474. writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
  2475. writeb(TX_AUTHENTICATE_LENGTH_LSB,pccs->var.tx_request.tx_data_length + 1);
  2476. writeb(0, &pccs->var.tx_request.pow_sav_mode);
  2477. ptx = local->sram + addr;
  2478. /* fill in the mac header */
  2479. writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
  2480. writeb(0, &ptx->mac.frame_ctl_2);
  2481. memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
  2482. memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
  2483. memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
  2484. /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
  2485. memset_io(ptx->var, 0, 6);
  2486. writeb(auth_type & 0xff, ptx->var + 2);
  2487. /* Interrupt the firmware to process the command */
  2488. if (interrupt_ecf(local, ccsindex)) {
  2489. DEBUG(1,"ray_cs send authentication request failed - ECF not ready for intr\n");
  2490. writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
  2491. return -1;
  2492. }
  2493. return 0;
  2494. } /* End build_auth_frame */
  2495. /*===========================================================================*/
  2496. #ifdef CONFIG_PROC_FS
  2497. static void raycs_write(const char *name, write_proc_t *w, void *data)
  2498. {
  2499. struct proc_dir_entry * entry = create_proc_entry(name, S_IFREG | S_IWUSR, NULL);
  2500. if (entry) {
  2501. entry->write_proc = w;
  2502. entry->data = data;
  2503. }
  2504. }
  2505. static int write_essid(struct file *file, const char __user *buffer, unsigned long count, void *data)
  2506. {
  2507. static char proc_essid[33];
  2508. int len = count;
  2509. if (len > 32)
  2510. len = 32;
  2511. memset(proc_essid, 0, 33);
  2512. if (copy_from_user(proc_essid, buffer, len))
  2513. return -EFAULT;
  2514. essid = proc_essid;
  2515. return count;
  2516. }
  2517. static int write_int(struct file *file, const char __user *buffer, unsigned long count, void *data)
  2518. {
  2519. static char proc_number[10];
  2520. char *p;
  2521. int nr, len;
  2522. if (!count)
  2523. return 0;
  2524. if (count > 9)
  2525. return -EINVAL;
  2526. if (copy_from_user(proc_number, buffer, count))
  2527. return -EFAULT;
  2528. p = proc_number;
  2529. nr = 0;
  2530. len = count;
  2531. do {
  2532. unsigned int c = *p - '0';
  2533. if (c > 9)
  2534. return -EINVAL;
  2535. nr = nr*10 + c;
  2536. p++;
  2537. } while (--len);
  2538. *(int *)data = nr;
  2539. return count;
  2540. }
  2541. #endif
  2542. static struct pcmcia_device_id ray_ids[] = {
  2543. PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
  2544. PCMCIA_DEVICE_NULL,
  2545. };
  2546. MODULE_DEVICE_TABLE(pcmcia, ray_ids);
  2547. static struct pcmcia_driver ray_driver = {
  2548. .owner = THIS_MODULE,
  2549. .drv = {
  2550. .name = "ray_cs",
  2551. },
  2552. .probe = ray_probe,
  2553. .remove = ray_detach,
  2554. .id_table = ray_ids,
  2555. .suspend = ray_suspend,
  2556. .resume = ray_resume,
  2557. };
  2558. static int __init init_ray_cs(void)
  2559. {
  2560. int rc;
  2561. DEBUG(1, "%s\n", rcsid);
  2562. rc = pcmcia_register_driver(&ray_driver);
  2563. DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",rc);
  2564. #ifdef CONFIG_PROC_FS
  2565. proc_mkdir("driver/ray_cs", NULL);
  2566. create_proc_info_entry("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_read);
  2567. raycs_write("driver/ray_cs/essid", write_essid, NULL);
  2568. raycs_write("driver/ray_cs/net_type", write_int, &net_type);
  2569. raycs_write("driver/ray_cs/translate", write_int, &translate);
  2570. #endif
  2571. if (translate != 0) translate = 1;
  2572. return 0;
  2573. } /* init_ray_cs */
  2574. /*===========================================================================*/
  2575. static void __exit exit_ray_cs(void)
  2576. {
  2577. DEBUG(0, "ray_cs: cleanup_module\n");
  2578. #ifdef CONFIG_PROC_FS
  2579. remove_proc_entry("driver/ray_cs/ray_cs", NULL);
  2580. remove_proc_entry("driver/ray_cs/essid", NULL);
  2581. remove_proc_entry("driver/ray_cs/net_type", NULL);
  2582. remove_proc_entry("driver/ray_cs/translate", NULL);
  2583. remove_proc_entry("driver/ray_cs", NULL);
  2584. #endif
  2585. pcmcia_unregister_driver(&ray_driver);
  2586. } /* exit_ray_cs */
  2587. module_init(init_ray_cs);
  2588. module_exit(exit_ray_cs);
  2589. /*===========================================================================*/