ray_cs.c 88 KB

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