ray_cs.c 97 KB

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