ray_cs.c 89 KB

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