ray_cs.c 84 KB

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