ray_cs.c 89 KB

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