ray_cs.c 88 KB

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