ray_cs.c 88 KB

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