ray_cs.c 89 KB

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