ray_cs.c 85 KB

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