ray_cs.c 85 KB

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