ray_cs.c 85 KB

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