ray_cs.c 88 KB

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