wavelan.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /*
  2. Lucent Wavelan IEEE 802.11 pcmcia.
  3. There is almost no documentation for the card.
  4. the driver is done using both the FreeBSD, Linux and
  5. original Plan 9 drivers as `documentation'.
  6. Has been used with the card plugged in during all up time.
  7. no cards removals/insertions yet.
  8. For known BUGS see the comments below. Besides,
  9. the driver keeps interrupts disabled for just too
  10. long. When it gets robust, locks should be revisited.
  11. BUGS: check endian, alignment and mem/io issues;
  12. multicast;
  13. receive watchdog interrupts.
  14. TODO: automatic power management;
  15. improve locking.
  16. */
  17. #include "u.h"
  18. #include "../port/lib.h"
  19. #include "mem.h"
  20. #include "dat.h"
  21. #include "fns.h"
  22. #include "io.h"
  23. #include "../port/error.h"
  24. #include "../port/netif.h"
  25. #include "etherif.h"
  26. #include "wavelan.h"
  27. enum
  28. {
  29. MSperTick= 50, /* ms between ticks of kproc */
  30. };
  31. /*
  32. * When we're using a PCI device and memory-mapped I/O,
  33. * the registers are spaced out as though each takes 32 bits,
  34. * even though they are only 16-bit registers. Thus,
  35. * ctlr->mmb[reg] is the right way to access register reg,
  36. * even though a priori you'd expect to use ctlr->mmb[reg/2].
  37. */
  38. void
  39. csr_outs(Ctlr *ctlr, int reg, ushort arg)
  40. {
  41. if(ctlr->mmb)
  42. ctlr->mmb[reg] = arg;
  43. else
  44. outs(ctlr->iob+reg, arg);
  45. }
  46. ushort
  47. csr_ins(Ctlr *ctlr, int reg)
  48. {
  49. if(ctlr->mmb)
  50. return ctlr->mmb[reg];
  51. else
  52. return ins(ctlr->iob+reg);
  53. }
  54. static void
  55. csr_ack(Ctlr *ctlr, int ev)
  56. {
  57. csr_outs(ctlr, WR_EvAck, ev);
  58. }
  59. static void
  60. csr_inss(Ctlr *ctlr, int reg, void *dat, int ndat)
  61. {
  62. ushort *rp, *wp;
  63. if(ctlr->mmb){
  64. rp = &ctlr->mmb[reg];
  65. wp = dat;
  66. while(ndat-- > 0)
  67. *wp++ = *rp;
  68. }else
  69. inss(ctlr->iob+reg, dat, ndat);
  70. }
  71. static void
  72. csr_outss(Ctlr *ctlr, int reg, void *dat, int ndat)
  73. {
  74. ushort *rp, *wp;
  75. if(ctlr->mmb){
  76. rp = dat;
  77. wp = &ctlr->mmb[reg];
  78. while(ndat-- > 0)
  79. *wp = *rp++;
  80. }else
  81. outss(ctlr->iob+reg, dat, ndat);
  82. }
  83. // w_... routines do not ilock the Ctlr and should
  84. // be called locked.
  85. void
  86. w_intdis(Ctlr* ctlr)
  87. {
  88. csr_outs(ctlr, WR_IntEna, 0);
  89. csr_ack(ctlr, 0xffff);
  90. }
  91. static void
  92. w_intena(Ctlr* ctlr)
  93. {
  94. csr_outs(ctlr, WR_IntEna, WEvs);
  95. }
  96. int
  97. w_cmd(Ctlr *ctlr, ushort cmd, ushort arg)
  98. {
  99. int i, rc;
  100. for(i=0; i<WTmOut; i++)
  101. if((csr_ins(ctlr, WR_Cmd)&WCmdBusy) == 0)
  102. break;
  103. if(i==WTmOut){
  104. print("#l%d: issuing cmd %.4ux: %.4ux\n", ctlr->ctlrno, cmd, csr_ins(ctlr, WR_Cmd));
  105. return -1;
  106. }
  107. csr_outs(ctlr, WR_Parm0, arg);
  108. csr_outs(ctlr, WR_Cmd, cmd);
  109. for(i=0; i<WTmOut; i++)
  110. if(csr_ins(ctlr, WR_EvSts)&WCmdEv)
  111. break;
  112. if(i==WTmOut){
  113. /*
  114. * WCmdIni can take a really long time.
  115. */
  116. enum { IniTmOut = 2000 };
  117. for(i=0; i<IniTmOut; i++){
  118. if(csr_ins(ctlr, WR_EvSts)&WCmdEv)
  119. break;
  120. microdelay(100);
  121. }
  122. if(i < IniTmOut)
  123. if(0) print("#l%d: long cmd %.4ux %d\n", ctlr->ctlrno, cmd, i);
  124. if(i == IniTmOut){
  125. print("#l%d: execing cmd %.4ux: %.4ux\n", ctlr->ctlrno, cmd, csr_ins(ctlr, WR_EvSts));
  126. return -1;
  127. }
  128. }
  129. rc = csr_ins(ctlr, WR_Sts);
  130. csr_ack(ctlr, WCmdEv);
  131. if((rc&WCmdMsk) != (cmd&WCmdMsk)){
  132. print("#l%d: cmd %.4ux: status %.4ux\n", ctlr->ctlrno, cmd, rc);
  133. return -1;
  134. }
  135. if(rc&WResSts){
  136. /*
  137. * Don't print; this happens on every WCmdAccWr for some reason.
  138. */
  139. if(0) print("#l%d: cmd %.4ux: status %.4ux\n", ctlr->ctlrno, cmd, rc);
  140. return -1;
  141. }
  142. return 0;
  143. }
  144. static int
  145. w_seek(Ctlr* ctlr, ushort id, ushort offset, int chan)
  146. {
  147. int i, rc;
  148. static ushort sel[] = { WR_Sel0, WR_Sel1 };
  149. static ushort off[] = { WR_Off0, WR_Off1 };
  150. if(chan != 0 && chan != 1)
  151. panic("wavelan: bad chan\n");
  152. csr_outs(ctlr, sel[chan], id);
  153. csr_outs(ctlr, off[chan], offset);
  154. for (i=0; i<WTmOut; i++){
  155. rc = csr_ins(ctlr, off[chan]);
  156. if((rc & (WBusyOff|WErrOff)) == 0)
  157. return 0;
  158. }
  159. return -1;
  160. }
  161. int
  162. w_inltv(Ctlr* ctlr, Wltv* ltv)
  163. {
  164. int len;
  165. ushort code;
  166. if(w_cmd(ctlr, WCmdAccRd, ltv->type)){
  167. DEBUG("wavelan: access read failed\n");
  168. return -1;
  169. }
  170. if(w_seek(ctlr,ltv->type,0,1)){
  171. DEBUG("wavelan: seek failed\n");
  172. return -1;
  173. }
  174. len = csr_ins(ctlr, WR_Data1);
  175. if(len > ltv->len)
  176. return -1;
  177. ltv->len = len;
  178. if((code=csr_ins(ctlr, WR_Data1)) != ltv->type){
  179. USED(code);
  180. DEBUG("wavelan: type %x != code %x\n",ltv->type,code);
  181. return -1;
  182. }
  183. if(ltv->len > 0)
  184. csr_inss(ctlr, WR_Data1, &ltv->val, ltv->len-1);
  185. return 0;
  186. }
  187. static void
  188. w_outltv(Ctlr* ctlr, Wltv* ltv)
  189. {
  190. if(w_seek(ctlr,ltv->type, 0, 1))
  191. return;
  192. csr_outss(ctlr, WR_Data1, ltv, ltv->len+1);
  193. w_cmd(ctlr, WCmdAccWr, ltv->type);
  194. }
  195. void
  196. ltv_outs(Ctlr* ctlr, int type, ushort val)
  197. {
  198. Wltv ltv;
  199. ltv.len = 2;
  200. ltv.type = type;
  201. ltv.val = val;
  202. w_outltv(ctlr, &ltv);
  203. }
  204. int
  205. ltv_ins(Ctlr* ctlr, int type)
  206. {
  207. Wltv ltv;
  208. ltv.len = 2;
  209. ltv.type = type;
  210. ltv.val = 0;
  211. if(w_inltv(ctlr, &ltv))
  212. return -1;
  213. return ltv.val;
  214. }
  215. static void
  216. ltv_outstr(Ctlr* ctlr, int type, char* val)
  217. {
  218. Wltv ltv;
  219. int len;
  220. len = strlen(val);
  221. if(len > sizeof(ltv.s))
  222. len = sizeof(ltv.s);
  223. memset(&ltv, 0, sizeof(ltv));
  224. ltv.len = (sizeof(ltv.type)+sizeof(ltv.slen)+sizeof(ltv.s))/2;
  225. ltv.type = type;
  226. // This should be ltv.slen = len; according to Axel Belinfante
  227. ltv.slen = len;
  228. strncpy(ltv.s, val, len);
  229. w_outltv(ctlr, &ltv);
  230. }
  231. static char Unkname[] = "who knows";
  232. static char Nilname[] = "card does not tell";
  233. static char*
  234. ltv_inname(Ctlr* ctlr, int type)
  235. {
  236. static Wltv ltv;
  237. int len;
  238. memset(&ltv,0,sizeof(ltv));
  239. ltv.len = WNameLen/2+2;
  240. ltv.type = type;
  241. if(w_inltv(ctlr, &ltv))
  242. return Unkname;
  243. len = ltv.slen;
  244. if(len == 0 || ltv.s[0] == 0)
  245. return Nilname;
  246. if(len >= sizeof ltv.s)
  247. len = sizeof ltv.s - 1;
  248. ltv.s[len] = '\0';
  249. return ltv.s;
  250. }
  251. static int
  252. w_read(Ctlr* ctlr, int type, int off, void* buf, ulong len)
  253. {
  254. if(w_seek(ctlr, type, off, 1)){
  255. DEBUG("wavelan: w_read: seek failed");
  256. return 0;
  257. }
  258. csr_inss(ctlr, WR_Data1, buf, len/2);
  259. return len;
  260. }
  261. static int
  262. w_write(Ctlr* ctlr, int type, int off, void* buf, ulong len)
  263. {
  264. if(w_seek(ctlr, type, off, 0)){
  265. DEBUG("wavelan: w_write: seek failed\n");
  266. return 0;
  267. }
  268. csr_outss(ctlr, WR_Data0, buf, len/2);
  269. csr_outs(ctlr, WR_Data0, 0xdead);
  270. csr_outs(ctlr, WR_Data0, 0xbeef);
  271. if(w_seek(ctlr, type, off + len, 0)){
  272. DEBUG("wavelan: write seek failed\n");
  273. return 0;
  274. }
  275. if(csr_ins(ctlr, WR_Data0) == 0xdead && csr_ins(ctlr, WR_Data0) == 0xbeef)
  276. return len;
  277. DEBUG("wavelan: Hermes bug byte.\n");
  278. return 0;
  279. }
  280. static int
  281. w_alloc(Ctlr* ctlr, int len)
  282. {
  283. int rc;
  284. int i,j;
  285. if(w_cmd(ctlr, WCmdMalloc, len)==0)
  286. for (i = 0; i<WTmOut; i++)
  287. if(csr_ins(ctlr, WR_EvSts) & WAllocEv){
  288. csr_ack(ctlr, WAllocEv);
  289. rc=csr_ins(ctlr, WR_Alloc);
  290. if(w_seek(ctlr, rc, 0, 0))
  291. return -1;
  292. len = len/2;
  293. for (j=0; j<len; j++)
  294. csr_outs(ctlr, WR_Data0, 0);
  295. return rc;
  296. }
  297. return -1;
  298. }
  299. static int
  300. w_enable(Ether* ether)
  301. {
  302. Wltv ltv;
  303. Ctlr* ctlr = (Ctlr*) ether->ctlr;
  304. if(!ctlr)
  305. return -1;
  306. w_intdis(ctlr);
  307. w_cmd(ctlr, WCmdDis, 0);
  308. w_intdis(ctlr);
  309. if(w_cmd(ctlr, WCmdIni, 0))
  310. return -1;
  311. w_intdis(ctlr);
  312. ltv_outs(ctlr, WTyp_Tick, 8);
  313. ltv_outs(ctlr, WTyp_MaxLen, ctlr->maxlen);
  314. ltv_outs(ctlr, WTyp_Ptype, ctlr->ptype);
  315. ltv_outs(ctlr, WTyp_CreateIBSS, ctlr->createibss);
  316. ltv_outs(ctlr, WTyp_RtsThres, ctlr->rtsthres);
  317. ltv_outs(ctlr, WTyp_TxRate, ctlr->txrate);
  318. ltv_outs(ctlr, WTyp_ApDens, ctlr->apdensity);
  319. ltv_outs(ctlr, WTyp_PMWait, ctlr->pmwait);
  320. ltv_outs(ctlr, WTyp_PM, ctlr->pmena);
  321. if(*ctlr->netname)
  322. ltv_outstr(ctlr, WTyp_NetName, ctlr->netname);
  323. if(*ctlr->wantname)
  324. ltv_outstr(ctlr, WTyp_WantName, ctlr->wantname);
  325. ltv_outs(ctlr, WTyp_Chan, ctlr->chan);
  326. if(*ctlr->nodename)
  327. ltv_outstr(ctlr, WTyp_NodeName, ctlr->nodename);
  328. ltv.len = 4;
  329. ltv.type = WTyp_Mac;
  330. memmove(ltv.addr, ether->ea, Eaddrlen);
  331. w_outltv(ctlr, &ltv);
  332. ltv_outs(ctlr, WTyp_Prom, (ether->prom?1:0));
  333. if(ctlr->hascrypt && ctlr->crypt){
  334. ltv_outs(ctlr, WTyp_Crypt, ctlr->crypt);
  335. ltv_outs(ctlr, WTyp_TxKey, ctlr->txkey);
  336. w_outltv(ctlr, &ctlr->keys);
  337. ltv_outs(ctlr, WTyp_XClear, ctlr->xclear);
  338. }
  339. // BUG: set multicast addresses
  340. if(w_cmd(ctlr, WCmdEna, 0)){
  341. DEBUG("wavelan: Enable failed");
  342. return -1;
  343. }
  344. ctlr->txdid = w_alloc(ctlr, 1518 + sizeof(WFrame) + 8);
  345. ctlr->txmid = w_alloc(ctlr, 1518 + sizeof(WFrame) + 8);
  346. if(ctlr->txdid == -1 || ctlr->txmid == -1)
  347. DEBUG("wavelan: alloc failed");
  348. ctlr->txbusy = 0;
  349. w_intena(ctlr);
  350. return 0;
  351. }
  352. static void
  353. w_rxdone(Ether* ether)
  354. {
  355. Ctlr* ctlr = (Ctlr*) ether->ctlr;
  356. int len, sp;
  357. WFrame f;
  358. Block* bp=0;
  359. Etherpkt* ep;
  360. sp = csr_ins(ctlr, WR_RXId);
  361. len = w_read(ctlr, sp, 0, &f, sizeof(f));
  362. if(len == 0){
  363. DEBUG("wavelan: read frame error\n");
  364. goto rxerror;
  365. }
  366. if(f.sts&WF_Err){
  367. goto rxerror;
  368. }
  369. switch(f.sts){
  370. case WF_1042:
  371. case WF_Tunnel:
  372. case WF_WMP:
  373. len = f.dlen + WSnapHdrLen;
  374. bp = iallocb(ETHERHDRSIZE + len + 2);
  375. if(!bp)
  376. goto rxerror;
  377. ep = (Etherpkt*) bp->wp;
  378. memmove(ep->d, f.addr1, Eaddrlen);
  379. memmove(ep->s, f.addr2, Eaddrlen);
  380. memmove(ep->type,&f.type,2);
  381. bp->wp += ETHERHDRSIZE;
  382. if(w_read(ctlr, sp, WF_802_11_Off, bp->wp, len+2) == 0){
  383. DEBUG("wavelan: read 802.11 error\n");
  384. goto rxerror;
  385. }
  386. bp->wp = bp->rp+(ETHERHDRSIZE+f.dlen);
  387. break;
  388. default:
  389. len = ETHERHDRSIZE + f.dlen + 2;
  390. bp = iallocb(len);
  391. if(!bp)
  392. goto rxerror;
  393. if(w_read(ctlr, sp, WF_802_3_Off, bp->wp, len) == 0){
  394. DEBUG("wavelan: read 800.3 error\n");
  395. goto rxerror;
  396. }
  397. bp->wp += len;
  398. }
  399. ctlr->nrx++;
  400. etheriq(ether,bp,1);
  401. ctlr->signal = ((ctlr->signal*15)+((f.qinfo>>8) & 0xFF))/16;
  402. ctlr->noise = ((ctlr->noise*15)+(f.qinfo & 0xFF))/16;
  403. return;
  404. rxerror:
  405. freeb(bp);
  406. ctlr->nrxerr++;
  407. }
  408. static void
  409. w_txstart(Ether* ether)
  410. {
  411. Etherpkt *pkt;
  412. Ctlr *ctlr;
  413. Block *bp;
  414. int len, off;
  415. if((ctlr = ether->ctlr) == nil || (ctlr->state & (Attached|Power)) != (Attached|Power) || ctlr->txbusy)
  416. return;
  417. if((bp = qget(ether->oq)) == nil)
  418. return;
  419. pkt = (Etherpkt*)bp->rp;
  420. //
  421. // If the packet header type field is > 1500 it is an IP or
  422. // ARP datagram, otherwise it is an 802.3 packet. See RFC1042.
  423. //
  424. memset(&ctlr->txf, 0, sizeof(ctlr->txf));
  425. if(((pkt->type[0]<<8)|pkt->type[1]) > 1500){
  426. ctlr->txf.framectl = WF_Data;
  427. memmove(ctlr->txf.addr1, pkt->d, Eaddrlen);
  428. memmove(ctlr->txf.addr2, pkt->s, Eaddrlen);
  429. memmove(ctlr->txf.dstaddr, pkt->d, Eaddrlen);
  430. memmove(ctlr->txf.srcaddr, pkt->s, Eaddrlen);
  431. memmove(&ctlr->txf.type, pkt->type, 2);
  432. bp->rp += ETHERHDRSIZE;
  433. len = BLEN(bp);
  434. off = WF_802_11_Off;
  435. ctlr->txf.dlen = len+ETHERHDRSIZE-WSnapHdrLen;
  436. hnputs((uchar*)&ctlr->txf.dat[0], WSnap0);
  437. hnputs((uchar*)&ctlr->txf.dat[1], WSnap1);
  438. hnputs((uchar*)&ctlr->txf.len, len+ETHERHDRSIZE-WSnapHdrLen);
  439. }
  440. else{
  441. len = BLEN(bp);
  442. off = WF_802_3_Off;
  443. ctlr->txf.dlen = len;
  444. }
  445. w_write(ctlr, ctlr->txdid, 0, &ctlr->txf, sizeof(ctlr->txf));
  446. w_write(ctlr, ctlr->txdid, off, bp->rp, len+2);
  447. if(w_cmd(ctlr, WCmdReclaim|WCmdTx, ctlr->txdid)){
  448. DEBUG("wavelan: transmit failed\n");
  449. ctlr->ntxerr++;
  450. }
  451. else{
  452. ctlr->txbusy = 1;
  453. ctlr->txtmout = 2;
  454. }
  455. freeb(bp);
  456. }
  457. static void
  458. w_txdone(Ctlr* ctlr, int sts)
  459. {
  460. ctlr->txbusy = 0;
  461. ctlr->txtmout = 0;
  462. if(sts & WTxErrEv)
  463. ctlr->ntxerr++;
  464. else
  465. ctlr->ntx++;
  466. }
  467. /* save the stats info in the ctlr struct */
  468. static void
  469. w_stats(Ctlr* ctlr, int len)
  470. {
  471. int i, rc;
  472. ulong* p = (ulong*)&ctlr->WStats;
  473. ulong* pend = (ulong*)&ctlr->end;
  474. for (i = 0; i < len && p < pend; i++){
  475. rc = csr_ins(ctlr, WR_Data1);
  476. if(rc > 0xf000)
  477. rc = ~rc & 0xffff;
  478. p[i] += rc;
  479. }
  480. }
  481. /* send the base station scan info to any readers */
  482. static void
  483. w_scaninfo(Ether* ether, Ctlr *ctlr, int len)
  484. {
  485. int i, j;
  486. Netfile **ep, *f, **fp;
  487. Block *bp;
  488. WScan *wsp;
  489. ushort *scanbuf;
  490. scanbuf = malloc(len*2);
  491. if(scanbuf == nil)
  492. return;
  493. for (i = 0; i < len ; i++)
  494. scanbuf[i] = csr_ins(ctlr, WR_Data1);
  495. /* calculate number of samples */
  496. len /= 25;
  497. if(len == 0)
  498. goto out;
  499. i = ether->scan;
  500. ep = &ether->f[Ntypes];
  501. for(fp = ether->f; fp < ep && i > 0; fp++){
  502. f = *fp;
  503. if(f == nil || f->scan == 0)
  504. continue;
  505. bp = iallocb(100*len);
  506. if(bp == nil)
  507. break;
  508. for(j = 0; j < len; j++){
  509. wsp = (WScan*)(&scanbuf[j*25]);
  510. if(wsp->ssid_len > 32)
  511. wsp->ssid_len = 32;
  512. bp->wp = (uchar*)seprint((char*)bp->wp, (char*)bp->lim,
  513. "ssid=%.*s;bssid=%E;signal=%d;noise=%d;chan=%d%s\n",
  514. wsp->ssid_len, wsp->ssid, wsp->bssid, wsp->signal,
  515. wsp->noise, wsp->chan, (wsp->capinfo&(1<<4))?";wep":"");
  516. }
  517. qpass(f->in, bp);
  518. i--;
  519. }
  520. out:
  521. free(scanbuf);
  522. }
  523. static int
  524. w_info(Ether *ether, Ctlr* ctlr)
  525. {
  526. int sp;
  527. Wltv ltv;
  528. sp = csr_ins(ctlr, WR_InfoId);
  529. ltv.len = ltv.type = 0;
  530. w_read(ctlr, sp, 0, &ltv, 4);
  531. ltv.len--;
  532. switch(ltv.type){
  533. case WTyp_Stats:
  534. w_stats(ctlr, ltv.len);
  535. return 0;
  536. case WTyp_Scan:
  537. w_scaninfo(ether, ctlr, ltv.len);
  538. return 0;
  539. }
  540. return -1;
  541. }
  542. /* set scanning interval */
  543. static void
  544. w_scanbs(void *a, uint secs)
  545. {
  546. Ether *ether = a;
  547. Ctlr* ctlr = (Ctlr*) ether->ctlr;
  548. ctlr->scanticks = secs*(1000/MSperTick);
  549. }
  550. static void
  551. w_intr(Ether *ether)
  552. {
  553. int rc, txid;
  554. Ctlr* ctlr = (Ctlr*) ether->ctlr;
  555. if((ctlr->state & Power) == 0)
  556. return;
  557. if((ctlr->state & Attached) == 0){
  558. csr_ack(ctlr, 0xffff);
  559. csr_outs(ctlr, WR_IntEna, 0);
  560. return;
  561. }
  562. rc = csr_ins(ctlr, WR_EvSts);
  563. csr_ack(ctlr, ~WEvs); // Not interested in them
  564. if(rc & WRXEv){
  565. w_rxdone(ether);
  566. csr_ack(ctlr, WRXEv);
  567. }
  568. if(rc & WTXEv){
  569. w_txdone(ctlr, rc);
  570. csr_ack(ctlr, WTXEv);
  571. }
  572. if(rc & WAllocEv){
  573. ctlr->nalloc++;
  574. txid = csr_ins(ctlr, WR_Alloc);
  575. csr_ack(ctlr, WAllocEv);
  576. if(txid == ctlr->txdid){
  577. if((rc & WTXEv) == 0)
  578. w_txdone(ctlr, rc);
  579. }
  580. }
  581. if(rc & WInfoEv){
  582. ctlr->ninfo++;
  583. w_info(ether, ctlr);
  584. csr_ack(ctlr, WInfoEv);
  585. }
  586. if(rc & WTxErrEv){
  587. w_txdone(ctlr, rc);
  588. csr_ack(ctlr, WTxErrEv);
  589. }
  590. if(rc & WIDropEv){
  591. ctlr->nidrop++;
  592. csr_ack(ctlr, WIDropEv);
  593. }
  594. w_txstart(ether);
  595. }
  596. // Watcher to ensure that the card still works properly and
  597. // to request WStats updates once a minute.
  598. // BUG: it runs much more often, see the comment below.
  599. static void
  600. w_timer(void* arg)
  601. {
  602. Ether* ether = (Ether*) arg;
  603. Ctlr* ctlr = (Ctlr*)ether->ctlr;
  604. ctlr->timerproc = up;
  605. for(;;){
  606. tsleep(&up->sleep, return0, 0, MSperTick);
  607. ctlr = (Ctlr*)ether->ctlr;
  608. if(ctlr == 0)
  609. break;
  610. if((ctlr->state & (Attached|Power)) != (Attached|Power))
  611. continue;
  612. ctlr->ticks++;
  613. ilock(ctlr);
  614. // Seems that the card gets frames BUT does
  615. // not send the interrupt; this is a problem because
  616. // I suspect it runs out of receive buffers and
  617. // stops receiving until a transmit watchdog
  618. // reenables the card.
  619. // The problem is serious because it leads to
  620. // poor rtts.
  621. // This can be seen clearly by commenting out
  622. // the next if and doing a ping: it will stop
  623. // receiving (although the icmp replies are being
  624. // issued from the remote) after a few seconds.
  625. // Of course this `bug' could be because I'm reading
  626. // the card frames in the wrong way; due to the
  627. // lack of documentation I cannot know.
  628. if(csr_ins(ctlr, WR_EvSts)&WEvs){
  629. ctlr->tickintr++;
  630. w_intr(ether);
  631. }
  632. if((ctlr->ticks % 10) == 0) {
  633. if(ctlr->txtmout && --ctlr->txtmout == 0){
  634. ctlr->nwatchdogs++;
  635. w_txdone(ctlr, WTxErrEv);
  636. if(w_enable(ether)){
  637. DEBUG("wavelan: wdog enable failed\n");
  638. }
  639. w_txstart(ether);
  640. }
  641. if((ctlr->ticks % 120) == 0)
  642. if(ctlr->txbusy == 0)
  643. w_cmd(ctlr, WCmdEnquire, WTyp_Stats);
  644. if(ctlr->scanticks > 0)
  645. if((ctlr->ticks % ctlr->scanticks) == 0)
  646. if(ctlr->txbusy == 0)
  647. w_cmd(ctlr, WCmdEnquire, WTyp_Scan);
  648. }
  649. iunlock(ctlr);
  650. }
  651. pexit("terminated", 0);
  652. }
  653. void
  654. w_multicast(void*, uchar*, int)
  655. {
  656. // BUG: to be added.
  657. }
  658. void
  659. w_attach(Ether* ether)
  660. {
  661. Ctlr* ctlr;
  662. char name[64];
  663. int rc;
  664. if(ether->ctlr == 0)
  665. return;
  666. snprint(name, sizeof(name), "#l%dtimer", ether->ctlrno);
  667. ctlr = (Ctlr*) ether->ctlr;
  668. if((ctlr->state & Attached) == 0){
  669. ilock(ctlr);
  670. rc = w_enable(ether);
  671. iunlock(ctlr);
  672. if(rc == 0){
  673. ctlr->state |= Attached;
  674. kproc(name, w_timer, ether);
  675. } else
  676. print("#l%d: enable failed\n",ether->ctlrno);
  677. }
  678. }
  679. void
  680. w_detach(Ether* ether)
  681. {
  682. Ctlr* ctlr;
  683. char name[64];
  684. if(ether->ctlr == nil)
  685. return;
  686. snprint(name, sizeof(name), "#l%dtimer", ether->ctlrno);
  687. ctlr = (Ctlr*) ether->ctlr;
  688. if(ctlr->state & Attached){
  689. ilock(ctlr);
  690. w_intdis(ctlr);
  691. if(ctlr->timerproc){
  692. if(!postnote(ctlr->timerproc, 1, "kill", NExit))
  693. print("timerproc note not posted\n");
  694. print("w_detach, killing 0x%p\n", ctlr->timerproc);
  695. }
  696. ctlr->state &= ~Attached;
  697. iunlock(ctlr);
  698. }
  699. ether->ctlr = nil;
  700. }
  701. void
  702. w_power(Ether* ether, int on)
  703. {
  704. Ctlr *ctlr;
  705. ctlr = (Ctlr*) ether->ctlr;
  706. ilock(ctlr);
  707. iprint("w_power %d\n", on);
  708. if(on){
  709. if((ctlr->state & Power) == 0){
  710. if (wavelanreset(ether, ctlr) < 0){
  711. iprint("w_power: reset failed\n");
  712. iunlock(ctlr);
  713. w_detach(ether);
  714. free(ctlr);
  715. return;
  716. }
  717. if(ctlr->state & Attached)
  718. w_enable(ether);
  719. ctlr->state |= Power;
  720. }
  721. }else{
  722. if(ctlr->state & Power){
  723. if(ctlr->state & Attached)
  724. w_intdis(ctlr);
  725. ctlr->state &= ~Power;
  726. }
  727. }
  728. iunlock(ctlr);
  729. }
  730. #define PRINTSTAT(fmt,val) l += snprint(p+l, READSTR-l, (fmt), (val))
  731. #define PRINTSTR(fmt) l += snprint(p+l, READSTR-l, (fmt))
  732. long
  733. w_ifstat(Ether* ether, void* a, long n, ulong offset)
  734. {
  735. Ctlr *ctlr = (Ctlr*) ether->ctlr;
  736. char *k, *p;
  737. int i, l, txid;
  738. ether->oerrs = ctlr->ntxerr;
  739. ether->crcs = ctlr->nrxfcserr;
  740. ether->frames = 0;
  741. ether->buffs = ctlr->nrxdropnobuf;
  742. ether->overflows = 0;
  743. //
  744. // Offset must be zero or there's a possibility the
  745. // new data won't match the previous read.
  746. //
  747. if(n == 0 || offset != 0)
  748. return 0;
  749. p = malloc(READSTR);
  750. l = 0;
  751. PRINTSTAT("Signal: %d\n", ctlr->signal-149);
  752. PRINTSTAT("Noise: %d\n", ctlr->noise-149);
  753. PRINTSTAT("SNR: %ud\n", ctlr->signal-ctlr->noise);
  754. PRINTSTAT("Interrupts: %lud\n", ctlr->nints);
  755. PRINTSTAT("Double Interrupts: %lud\n", ctlr->ndoubleint);
  756. PRINTSTAT("TxPackets: %lud\n", ctlr->ntx);
  757. PRINTSTAT("RxPackets: %lud\n", ctlr->nrx);
  758. PRINTSTAT("TxErrors: %lud\n", ctlr->ntxerr);
  759. PRINTSTAT("RxErrors: %lud\n", ctlr->nrxerr);
  760. PRINTSTAT("TxRequests: %lud\n", ctlr->ntxrq);
  761. PRINTSTAT("AllocEvs: %lud\n", ctlr->nalloc);
  762. PRINTSTAT("InfoEvs: %lud\n", ctlr->ninfo);
  763. PRINTSTAT("InfoDrop: %lud\n", ctlr->nidrop);
  764. PRINTSTAT("WatchDogs: %lud\n", ctlr->nwatchdogs);
  765. PRINTSTAT("Ticks: %ud\n", ctlr->ticks);
  766. PRINTSTAT("TickIntr: %ud\n", ctlr->tickintr);
  767. k = ((ctlr->state & Attached) ? "attached" : "not attached");
  768. PRINTSTAT("Card %s", k);
  769. k = ((ctlr->state & Power) ? "on" : "off");
  770. PRINTSTAT(", power %s", k);
  771. k = ((ctlr->txbusy)? ", txbusy" : "");
  772. PRINTSTAT("%s\n", k);
  773. if(ctlr->hascrypt){
  774. PRINTSTR("Keys: ");
  775. for (i = 0; i < WNKeys; i++){
  776. if(ctlr->keys.keys[i].len == 0)
  777. PRINTSTR("none ");
  778. else if(SEEKEYS == 0)
  779. PRINTSTR("set ");
  780. else
  781. PRINTSTAT("%s ", ctlr->keys.keys[i].dat);
  782. }
  783. PRINTSTR("\n");
  784. }
  785. // real card stats
  786. ilock(ctlr);
  787. PRINTSTR("\nCard stats: \n");
  788. PRINTSTAT("Status: %ux\n", csr_ins(ctlr, WR_Sts));
  789. PRINTSTAT("Event status: %ux\n", csr_ins(ctlr, WR_EvSts));
  790. i = ltv_ins(ctlr, WTyp_Ptype);
  791. PRINTSTAT("Port type: %d\n", i);
  792. PRINTSTAT("Transmit rate: %d\n", ltv_ins(ctlr, WTyp_TxRate));
  793. PRINTSTAT("Current Transmit rate: %d\n",
  794. ltv_ins(ctlr, WTyp_CurTxRate));
  795. PRINTSTAT("Channel: %d\n", ltv_ins(ctlr, WTyp_Chan));
  796. PRINTSTAT("AP density: %d\n", ltv_ins(ctlr, WTyp_ApDens));
  797. PRINTSTAT("Promiscuous mode: %d\n", ltv_ins(ctlr, WTyp_Prom));
  798. if(i == WPTypeAdHoc)
  799. PRINTSTAT("SSID name: %s\n", ltv_inname(ctlr, WTyp_NetName));
  800. else {
  801. Wltv ltv;
  802. PRINTSTAT("Current name: %s\n", ltv_inname(ctlr, WTyp_CurName));
  803. ltv.type = WTyp_BaseID;
  804. ltv.len = 4;
  805. if(w_inltv(ctlr, &ltv))
  806. print("#l%d: unable to read base station mac addr\n", ether->ctlrno);
  807. l += snprint(p+l, READSTR-l, "Base station: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
  808. ltv.addr[0], ltv.addr[1], ltv.addr[2], ltv.addr[3], ltv.addr[4], ltv.addr[5]);
  809. }
  810. PRINTSTAT("Net name: %s\n", ltv_inname(ctlr, WTyp_WantName));
  811. PRINTSTAT("Node name: %s\n", ltv_inname(ctlr, WTyp_NodeName));
  812. if(ltv_ins(ctlr, WTyp_HasCrypt) == 0)
  813. PRINTSTR("WEP: not supported\n");
  814. else {
  815. if(ltv_ins(ctlr, WTyp_Crypt) == 0)
  816. PRINTSTR("WEP: disabled\n");
  817. else{
  818. PRINTSTR("WEP: enabled\n");
  819. k = ((ctlr->xclear)? "excluded": "included");
  820. PRINTSTAT("Clear packets: %s\n", k);
  821. txid = ltv_ins(ctlr, WTyp_TxKey);
  822. PRINTSTAT("Transmit key id: %d\n", txid);
  823. }
  824. }
  825. iunlock(ctlr);
  826. PRINTSTAT("ntxuframes: %lud\n", ctlr->ntxuframes);
  827. PRINTSTAT("ntxmframes: %lud\n", ctlr->ntxmframes);
  828. PRINTSTAT("ntxfrags: %lud\n", ctlr->ntxfrags);
  829. PRINTSTAT("ntxubytes: %lud\n", ctlr->ntxubytes);
  830. PRINTSTAT("ntxmbytes: %lud\n", ctlr->ntxmbytes);
  831. PRINTSTAT("ntxdeferred: %lud\n", ctlr->ntxdeferred);
  832. PRINTSTAT("ntxsretries: %lud\n", ctlr->ntxsretries);
  833. PRINTSTAT("ntxmultiretries: %lud\n", ctlr->ntxmultiretries);
  834. PRINTSTAT("ntxretrylimit: %lud\n", ctlr->ntxretrylimit);
  835. PRINTSTAT("ntxdiscards: %lud\n", ctlr->ntxdiscards);
  836. PRINTSTAT("nrxuframes: %lud\n", ctlr->nrxuframes);
  837. PRINTSTAT("nrxmframes: %lud\n", ctlr->nrxmframes);
  838. PRINTSTAT("nrxfrags: %lud\n", ctlr->nrxfrags);
  839. PRINTSTAT("nrxubytes: %lud\n", ctlr->nrxubytes);
  840. PRINTSTAT("nrxmbytes: %lud\n", ctlr->nrxmbytes);
  841. PRINTSTAT("nrxfcserr: %lud\n", ctlr->nrxfcserr);
  842. PRINTSTAT("nrxdropnobuf: %lud\n", ctlr->nrxdropnobuf);
  843. PRINTSTAT("nrxdropnosa: %lud\n", ctlr->nrxdropnosa);
  844. PRINTSTAT("nrxcantdecrypt: %lud\n", ctlr->nrxcantdecrypt);
  845. PRINTSTAT("nrxmsgfrag: %lud\n", ctlr->nrxmsgfrag);
  846. PRINTSTAT("nrxmsgbadfrag: %lud\n", ctlr->nrxmsgbadfrag);
  847. USED(l);
  848. n = readstr(offset, a, n, p);
  849. free(p);
  850. return n;
  851. }
  852. #undef PRINTSTR
  853. #undef PRINTSTAT
  854. static int
  855. parsekey(WKey* key, char* a)
  856. {
  857. int i, k, len, n;
  858. char buf[WMaxKeyLen];
  859. len = strlen(a);
  860. if(len == WMinKeyLen || len == WMaxKeyLen){
  861. memset(key->dat, 0, sizeof(key->dat));
  862. memmove(key->dat, a, len);
  863. key->len = len;
  864. return 0;
  865. }
  866. else if(len == WMinKeyLen*2 || len == WMaxKeyLen*2){
  867. k = 0;
  868. for(i = 0; i < len; i++){
  869. if(*a >= '0' && *a <= '9')
  870. n = *a++ - '0';
  871. else if(*a >= 'a' && *a <= 'f')
  872. n = *a++ - 'a' + 10;
  873. else if(*a >= 'A' && *a <= 'F')
  874. n = *a++ - 'A' + 10;
  875. else
  876. return -1;
  877. if(i & 1){
  878. buf[k] |= n;
  879. k++;
  880. }
  881. else
  882. buf[k] = n<<4;
  883. }
  884. memset(key->dat, 0, sizeof(key->dat));
  885. memmove(key->dat, buf, k);
  886. key->len = k;
  887. return 0;
  888. }
  889. return -1;
  890. }
  891. int
  892. w_option(Ctlr* ctlr, char* buf, long n)
  893. {
  894. char *p;
  895. int i, r;
  896. Cmdbuf *cb;
  897. r = 0;
  898. cb = parsecmd(buf, n);
  899. if(cb->nf < 2)
  900. r = -1;
  901. else if(cistrcmp(cb->f[0], "essid") == 0){
  902. if(cistrcmp(cb->f[1],"default") == 0)
  903. p = "";
  904. else
  905. p = cb->f[1];
  906. if(ctlr->ptype == WPTypeAdHoc){
  907. memset(ctlr->netname, 0, sizeof(ctlr->netname));
  908. strncpy(ctlr->netname, p, WNameLen);
  909. }
  910. else{
  911. memset(ctlr->wantname, 0, sizeof(ctlr->wantname));
  912. strncpy(ctlr->wantname, p, WNameLen);
  913. }
  914. }
  915. else if(cistrcmp(cb->f[0], "station") == 0){
  916. memset(ctlr->nodename, 0, sizeof(ctlr->nodename));
  917. strncpy(ctlr->nodename, cb->f[1], WNameLen);
  918. }
  919. else if(cistrcmp(cb->f[0], "channel") == 0){
  920. if((i = atoi(cb->f[1])) >= 1 && i <= 16)
  921. ctlr->chan = i;
  922. else
  923. r = -1;
  924. }
  925. else if(cistrcmp(cb->f[0], "mode") == 0){
  926. if(cistrcmp(cb->f[1], "managed") == 0)
  927. ctlr->ptype = WPTypeManaged;
  928. else if(cistrcmp(cb->f[1], "wds") == 0)
  929. ctlr->ptype = WPTypeWDS;
  930. else if(cistrcmp(cb->f[1], "adhoc") == 0)
  931. ctlr->ptype = WPTypeAdHoc;
  932. else if((i = atoi(cb->f[1])) >= 0 && i <= 3)
  933. ctlr->ptype = i;
  934. else
  935. r = -1;
  936. }
  937. else if(cistrcmp(cb->f[0], "ibss") == 0){
  938. if(cistrcmp(cb->f[1], "on") == 0)
  939. ctlr->createibss = 1;
  940. else
  941. ctlr->createibss = 0;
  942. }
  943. else if(cistrcmp(cb->f[0], "crypt") == 0){
  944. if(cistrcmp(cb->f[1], "off") == 0)
  945. ctlr->crypt = 0;
  946. else if(cistrcmp(cb->f[1], "on") == 0 && ctlr->hascrypt)
  947. ctlr->crypt = 1;
  948. else
  949. r = -1;
  950. }
  951. else if(cistrcmp(cb->f[0], "clear") == 0){
  952. if(cistrcmp(cb->f[1], "on") == 0)
  953. ctlr->xclear = 0;
  954. else if(cistrcmp(cb->f[1], "off") == 0 && ctlr->hascrypt)
  955. ctlr->xclear = 1;
  956. else
  957. r = -1;
  958. }
  959. else if(cistrncmp(cb->f[0], "key", 3) == 0){
  960. if((i = atoi(cb->f[0]+3)) >= 1 && i <= WNKeys){
  961. ctlr->txkey = i-1;
  962. if(parsekey(&ctlr->keys.keys[ctlr->txkey], cb->f[1]))
  963. r = -1;
  964. }
  965. else
  966. r = -1;
  967. }
  968. else if(cistrcmp(cb->f[0], "txkey") == 0){
  969. if((i = atoi(cb->f[1])) >= 1 && i <= WNKeys)
  970. ctlr->txkey = i-1;
  971. else
  972. r = -1;
  973. }
  974. else if(cistrcmp(cb->f[0], "pm") == 0){
  975. if(cistrcmp(cb->f[1], "off") == 0)
  976. ctlr->pmena = 0;
  977. else if(cistrcmp(cb->f[1], "on") == 0){
  978. ctlr->pmena = 1;
  979. if(cb->nf == 3){
  980. i = atoi(cb->f[2]);
  981. // check range here? what are the units?
  982. ctlr->pmwait = i;
  983. }
  984. }
  985. else
  986. r = -1;
  987. }
  988. else
  989. r = -2;
  990. free(cb);
  991. return r;
  992. }
  993. long
  994. w_ctl(Ether* ether, void* buf, long n)
  995. {
  996. Ctlr *ctlr;
  997. if((ctlr = ether->ctlr) == nil)
  998. error(Enonexist);
  999. if((ctlr->state & Attached) == 0)
  1000. error(Eshutdown);
  1001. ilock(ctlr);
  1002. if(w_option(ctlr, buf, n)){
  1003. iunlock(ctlr);
  1004. error(Ebadctl);
  1005. }
  1006. if(ctlr->txbusy)
  1007. w_txdone(ctlr, WTxErrEv);
  1008. w_enable(ether);
  1009. w_txstart(ether);
  1010. iunlock(ctlr);
  1011. return n;
  1012. }
  1013. void
  1014. w_transmit(Ether* ether)
  1015. {
  1016. Ctlr* ctlr = ether->ctlr;
  1017. if(ctlr == 0)
  1018. return;
  1019. ilock(ctlr);
  1020. ctlr->ntxrq++;
  1021. w_txstart(ether);
  1022. iunlock(ctlr);
  1023. }
  1024. void
  1025. w_promiscuous(void* arg, int on)
  1026. {
  1027. Ether* ether = (Ether*)arg;
  1028. Ctlr* ctlr = ether->ctlr;
  1029. if(ctlr == nil)
  1030. error("card not found");
  1031. if((ctlr->state & Attached) == 0)
  1032. error("card not attached");
  1033. ilock(ctlr);
  1034. ltv_outs(ctlr, WTyp_Prom, (on?1:0));
  1035. iunlock(ctlr);
  1036. }
  1037. void
  1038. w_interrupt(Ureg* ,void* arg)
  1039. {
  1040. Ether* ether = (Ether*) arg;
  1041. Ctlr* ctlr = (Ctlr*) ether->ctlr;
  1042. if(ctlr == 0)
  1043. return;
  1044. ilock(ctlr);
  1045. ctlr->nints++;
  1046. w_intr(ether);
  1047. iunlock(ctlr);
  1048. }
  1049. int
  1050. wavelanreset(Ether* ether, Ctlr *ctlr)
  1051. {
  1052. Wltv ltv;
  1053. iprint("wavelanreset, iob 0x%ux\n", ctlr->iob);
  1054. w_intdis(ctlr);
  1055. if(w_cmd(ctlr,WCmdIni,0)){
  1056. iprint("#l%d: init failed\n", ether->ctlrno);
  1057. return -1;
  1058. }
  1059. w_intdis(ctlr);
  1060. ltv_outs(ctlr, WTyp_Tick, 8);
  1061. ctlr->chan = 0;
  1062. ctlr->ptype = WDfltPType;
  1063. ctlr->txkey = 0;
  1064. ctlr->createibss = 0;
  1065. ctlr->keys.len = sizeof(WKey)*WNKeys/2 + 1;
  1066. ctlr->keys.type = WTyp_Keys;
  1067. if(ctlr->hascrypt = ltv_ins(ctlr, WTyp_HasCrypt))
  1068. ctlr->crypt = 1;
  1069. *ctlr->netname = *ctlr->wantname = 0;
  1070. strcpy(ctlr->nodename, "Plan 9 STA");
  1071. ctlr->netname[WNameLen-1] = 0;
  1072. ctlr->wantname[WNameLen-1] = 0;
  1073. ctlr->nodename[WNameLen-1] =0;
  1074. ltv.type = WTyp_Mac;
  1075. ltv.len = 4;
  1076. if(w_inltv(ctlr, &ltv)){
  1077. iprint("#l%d: unable to read mac addr\n",
  1078. ether->ctlrno);
  1079. return -1;
  1080. }
  1081. memmove(ether->ea, ltv.addr, Eaddrlen);
  1082. if(ctlr->chan == 0)
  1083. ctlr->chan = ltv_ins(ctlr, WTyp_Chan);
  1084. ctlr->apdensity = WDfltApDens;
  1085. ctlr->rtsthres = WDfltRtsThres;
  1086. ctlr->txrate = WDfltTxRate;
  1087. ctlr->maxlen = WMaxLen;
  1088. ctlr->pmena = 0;
  1089. ctlr->pmwait = 100;
  1090. ctlr->signal = 1;
  1091. ctlr->noise = 1;
  1092. ctlr->state |= Power;
  1093. // free old Ctlr struct if resetting after suspend
  1094. if(ether->ctlr && ether->ctlr != ctlr)
  1095. free(ether->ctlr);
  1096. // link to ether
  1097. ether->ctlr = ctlr;
  1098. ether->mbps = 10;
  1099. ether->attach = w_attach;
  1100. ether->detach = w_detach;
  1101. ether->interrupt = w_interrupt;
  1102. ether->transmit = w_transmit;
  1103. ether->ifstat = w_ifstat;
  1104. ether->ctl = w_ctl;
  1105. ether->power = w_power;
  1106. ether->promiscuous = w_promiscuous;
  1107. ether->multicast = w_multicast;
  1108. ether->scanbs = w_scanbs;
  1109. ether->arg = ether;
  1110. DEBUG("#l%d: irq %d port %lx type %s",
  1111. ether->ctlrno, ether->irq, ether->port, ether->type);
  1112. DEBUG(" %2.2ux%2.2ux%2.2ux%2.2ux%2.2ux%2.2ux\n",
  1113. ether->ea[0], ether->ea[1], ether->ea[2],
  1114. ether->ea[3], ether->ea[4], ether->ea[5]);
  1115. return 0;
  1116. }
  1117. char* wavenames[] = {
  1118. "WaveLAN/IEEE",
  1119. "TrueMobile 1150",
  1120. "Instant Wireless ; Network PC CARD",
  1121. "Instant Wireless Network PC Card",
  1122. "Avaya Wireless PC Card",
  1123. "AirLancer MC-11",
  1124. "INTERSIL;HFA384x/IEEE;Version 01.02;",
  1125. nil,
  1126. };