ray_cs.c 88 KB

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