ray_cs.c 97 KB

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