ray_cs.c 89 KB

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