ray_cs.c 89 KB

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