ray_cs.c 100 KB

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