ray_cs.c 89 KB

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