ray_cs.c 102 KB

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