ray_cs.c 88 KB

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