ray_cs.c 85 KB

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