ray_cs.c 88 KB

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