ray_cs.c 85 KB

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