ray_cs.c 98 KB

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