ray_cs.c 98 KB

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