ray_cs.c 85 KB

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