ray_cs.c 97 KB

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