ray_cs.c 96 KB

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