ray_cs.c 86 KB

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