ray_cs.c 89 KB

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