ray_cs.c 89 KB

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