ray_cs.c 87 KB

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