ray_cs.c 84 KB

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