ray_cs.c 98 KB

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