ray_cs.c 97 KB

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