From 81840a86539b484ae030b0ac071c8ad220bf2fd6 Mon Sep 17 00:00:00 2001 From: "saoret.one" Date: Mon, 1 Dec 2008 23:04:11 +0000 Subject: [PATCH] some scaffold & fixes to get wifi working --- archds.c | 14 ++-- arm7/mkdeps | 7 +- arm7/mkfile | 2 +- arm7/wifi.c | 10 +++ ethernds.c | 147 ++++++++++++++++++++++------------- guide | 8 +- io.h | 4 + main.c | 19 ----- mkfile | 5 ++ mksymtab | 11 ++- root/usr/inferno/lib/wmsetup | 34 ++++---- 11 files changed, 150 insertions(+), 111 deletions(-) diff --git a/archds.c b/archds.c index d709d46..b160d0d 100644 --- a/archds.c +++ b/archds.c @@ -230,18 +230,16 @@ archether(int ctlno, Ether *ether) IPCREG->ctl |= Ipcirqena; memset(ether->ea, 0xff, Eaddrlen); - nbfifoput(F9TWifi|F9WFrmac, (ulong)ether->ea); /* mac from arm7 */ + nbfifoput(F9TWifi|F9WFrmac, (ulong)uncached(ether->ea)); /* mac from arm7 */ if(1){ /* workaround for desmume */ - ushort i; - uchar maczero[Eaddrlen]; - - for(i=0; i < 1<<(8*sizeof(ushort))-1; i++); - memset(maczero, 0x00, Eaddrlen); - if(memcmp(ether->ea, maczero, Eaddrlen) == 0) + uchar i, maczero[Eaddrlen] = {0,0,0,0,0,0}; + + for(i=0; i < 1<<(8*sizeof(uchar))-1; i++); + if(memcmp(uncached(ether->ea), maczero, Eaddrlen) == 0) memset(ether->ea, 0x01, Eaddrlen); } - strcpy(opt, "power=on mode=managed crypt=off essid=THOMSON station=ds"); + strcpy(opt, "power=on mode=managed crypt=off channel=11 essid=default station=ds"); ether->nopt = tokenize(opt, (char **)ether->opt, nelem(ether->opt)); return 1; diff --git a/arm7/mkdeps b/arm7/mkdeps index a65dd5d..7790e67 100755 --- a/arm7/mkdeps +++ b/arm7/mkdeps @@ -1,5 +1,5 @@ # workaround to not maintain mkfiles in sync -# NOTE: maybe it's not a very good idea, but works for now +# NOTE: maybe not the best, but works for now $AWK -v 'conf='$CONF ' BEGIN{ @@ -12,9 +12,10 @@ $AWK -v 'conf='$CONF ' exit } - /^[O|H]FILES=/ {collect=1; next} + /^[O|H]FILES=/ {collect=1; next} - /^[ ]*$|^#/ {collect=0} + /^[ ]*$/ {collect=0} + /^[ ]*#/ {next} collect { if(match($1, ".+.\\$O")){ diff --git a/arm7/mkfile b/arm7/mkfile index 1a8388c..f52ff1a 100644 --- a/arm7/mkfile +++ b/arm7/mkfile @@ -16,8 +16,8 @@ OFILES=\ spi.$O\ rtc.$O\ audio.$O\ -# dma.$O\ wifi.$O\ +# dma.$O\ HFILES=\ ../io.h\ diff --git a/arm7/wifi.c b/arm7/wifi.c index e9c8e8b..a2008c6 100644 --- a/arm7/wifi.c +++ b/arm7/wifi.c @@ -22,6 +22,8 @@ Copyright (c) 2005 Stephen Stair #include "spi.h" #include "wifi.h" +#define DPRINT if(0)print + Wifi_Data wifi_data; nds_rx_packet *rx_packet = nil; @@ -1043,6 +1045,8 @@ static int Wifi_ProcessReassocResponse(int macbase, int framelen) ushort status; uchar tag_length; + DPRINT("wprr\n"); + USED(framelen); Wifi_MACCopy((ushort *) & packetheader, macbase, 0, 12); @@ -1115,6 +1119,8 @@ static int Wifi_ProcessAuthenticationFrame(int macbase, int framelen) ushort auth_sequence; ushort status; + DPRINT("wpaf\n"); + USED(framelen); Wifi_MACCopy((ushort *) & packetheader, macbase, 0, 12); @@ -1654,6 +1660,8 @@ static void Wifi_SendAuthPacket(int wepmode) int i; ushort *fixed_params; + DPRINT("wsaup\n"); + i = Wifi_GenMgtHeader(data, 0x00B0); // Auth fixed_params = (ushort *) (data + i); @@ -1708,6 +1716,8 @@ static void Wifi_SendAssocPacket(void) uchar data[96]; int i, j, numrates; + DPRINT("wsasp\n"); + i = Wifi_GenMgtHeader(data, 0x0000); if (wifi_data.curWepmode) { diff --git a/ethernds.c b/ethernds.c index 5259512..6d5a3e6 100644 --- a/ethernds.c +++ b/ethernds.c @@ -10,11 +10,14 @@ #include "../port/netif.h" #include "etherif.h" -#define DPRINT if(1)iprint +#define DPRINT if(debug)iprint +static int debug = 0; enum { WNameLen = 34, + WNKeys = 4, + WKeyLen = 14, }; typedef struct Stats Stats; @@ -27,6 +30,13 @@ struct Stats ulong txerrors; }; +typedef struct WKey WKey; +struct WKey +{ + ushort len; + char dat[WKeyLen]; +}; + typedef struct WFrame WFrame; struct WFrame { @@ -65,13 +75,17 @@ struct Ctlr { Block* waiting; /* waiting for space in FIFO */ int attached; - int ptype; int chan; - int crypt; // encryption off/on - int power; char netname[WNameLen]; char wantname[WNameLen]; char nodename[WNameLen]; + + int power; // hardware power up/down + int ptype; // AP mode/type + int crypt; // encryption off/on + int txkey; // transmit key + WKey keys[WNKeys]; // default keys + int scan; Stats; @@ -86,7 +100,7 @@ struct Ctlr { static long ifstat(Ether* ether, void* a, long n, ulong offset) { - Wifi_AccessPoint *app; + Wifi_AccessPoint *ap; char *p, *e, *tmp; Ctlr *ctlr; int i; @@ -107,29 +121,26 @@ ifstat(Ether* ether, void* a, long n, ulong offset) } e = tmp+READSTR; - fifoput(F9TWifi|F9WFscan, 0); - microdelay(13 * WIFI_CHANNEL_SCAN_DWEL); dcflush(ctlr->stats7, sizeof(ctlr->stats7)); fifoput(F9TWifi|F9WFstats, 0); - p = seprint(p, e, "txpkts: %lud (%lud bytes)\n", - (ulong) ctlr->stats7[WF_STAT_TXPKTS], (ulong) ctlr->stats7[WF_STAT_TXDATABYTES]); - p = seprint(p, e, "rxpkts: %lud (%lud bytes)\n", - (ulong) ctlr->stats7[WF_STAT_RXPKTS], (ulong) ctlr->stats7[WF_STAT_RXDATABYTES]); - p = seprint(p, e, "txdropped: %lud\n", ctlr->stats7[WF_STAT_TXQREJECT]); - - // raw stats - p = seprint(p, e, "raw txpkts: %lud (%lud bytes)\n", + p = seprint(p, e, "tx: %lud (%lud bytes) raw: %lud (%lud bytes)\n", + (ulong) ctlr->stats7[WF_STAT_TXPKTS], (ulong) ctlr->stats7[WF_STAT_TXDATABYTES], (ulong) ctlr->stats7[WF_STAT_TXRAWPKTS], (ulong) ctlr->stats7[WF_STAT_TXBYTES]); - p = seprint(p, e, "raw rxpkts: %lud (%lud bytes)\n", + p = seprint(p, e, "rx: %lud (%lud bytes) raw %lud (%lud bytes)\n", + (ulong) ctlr->stats7[WF_STAT_RXPKTS], (ulong) ctlr->stats7[WF_STAT_RXDATABYTES], (ulong) ctlr->stats7[WF_STAT_RXRAWPKTS], (ulong) ctlr->stats7[WF_STAT_RXBYTES]); - p = seprint(p, e, "rxoverruns: %lud\n", - (ulong) ctlr->stats7[WF_STAT_RXOVERRUN]); - - p = seprint(p, e, "ie: 0x%ux if: 0x%ux ints: %lud\n", + p = seprint(p, e, "txdropped: %lud rxovruns: %lud\n", + ctlr->stats7[WF_STAT_TXQREJECT], (ulong) ctlr->stats7[WF_STAT_RXOVERRUN]); + + p = seprint(p, e, "ie: 0x%ux if: 0x%ux ints: %lud tx: %lux/%lux\n", (ushort) ctlr->stats7[WF_STAT_DBG1], (ushort) ctlr->stats7[WF_STAT_DBG2], - (ulong) ctlr->stats7[WF_STAT_DBG6]); + (ulong) ctlr->stats7[WF_STAT_DBG6], + + (ulong) ctlr->stats7[WF_STAT_DBG3], + (ulong) ctlr->stats7[WF_STAT_DBG4] + ); p = seprint(p, e, "state (0x%ux): assoc %s%s%s auth %s pend %s%s%s\n", (ushort) ctlr->stats7[WF_STAT_DBG5], @@ -144,23 +155,34 @@ ifstat(Ether* ether, void* a, long n, ulong offset) ctlr->stats7[WF_STAT_DBG5] & WIFI_STATE_TXPENDING? "tx": "", ctlr->stats7[WF_STAT_DBG5] & WIFI_STATE_RXPENDING? "rx": "", ctlr->stats7[WF_STAT_DBG5] & WIFI_STATE_APQUERYPEND? "apqry": "" - ); + ); + ap = (Wifi_AccessPoint*) ctlr->aplist7; // order by signal quality - app = (Wifi_AccessPoint*) ctlr->aplist7; - for(i=0; i < WIFI_MAX_AP && *(ulong*)app; app++) - if (app->flags & WFLAG_APDATA_ACTIVE) - p = seprint(p, e, "%s ch=%d (0x%ux) sec=%s%s m=%s c=%s%s q=%d\n", - app->ssid, app->channel, app->flags, - (app->flags & WFLAG_APDATA_WEP? "wep": ""), - (app->flags & WFLAG_APDATA_WPA? "wpa": ""), - - (app->flags & WFLAG_APDATA_ADHOC? "hoc": "man"), - (app->flags & WFLAG_APDATA_COMPATIBLE? "c": ""), - (app->flags & WFLAG_APDATA_EXTCOMPATIBLE? "e": ""), - app->rssi + if (ctlr->scan) + for(i=0; i < WIFI_MAX_AP && *(ulong*)ap; ap++){ + if (ap->flags & WFLAG_APDATA_ACTIVE){ + p = seprint(p, e, "%s ch=%d (0x%ux) sec=%s%s%s m=%s c=%s%s", + ap->ssid, ap->channel, ap->flags, + (ap->flags & WFLAG_APDATA_WEP? "wep": ""), + (ap->flags & WFLAG_APDATA_WPA? "wpa": ""), + (ap->flags & (WFLAG_APDATA_WEP|WFLAG_APDATA_WPA)? "": "none"), + + (ap->flags & WFLAG_APDATA_ADHOC? "hoc": "man"), + (ap->flags & WFLAG_APDATA_COMPATIBLE? "c": ""), + (ap->flags & WFLAG_APDATA_EXTCOMPATIBLE? "e": "") ); + if(0) + p = seprint(p, e, " b=%x%x%x%x%x%x", + ap->bssid[0], ap->bssid[1], ap->bssid[2], ap->bssid[3], ap->bssid[4], ap->bssid[5]); + if(0) + p = seprint(p, e, " m=%x%x%x%x%x%x", + ap->macaddr[0], ap->macaddr[1], ap->macaddr[2], ap->macaddr[3], ap->macaddr[4], ap->macaddr[5]); + p = seprint(p, e, "\n"); + } + } + n = readstr(offset, a, n, tmp); poperror(); free(tmp); @@ -173,12 +195,10 @@ w_option(Ctlr* ctlr, char* buf, long n) { char *p; int i, r; + WKey *key; Cmdbuf *cb; - USED(ctlr); - /* TODO: complete parsing of ctl vars */ r = 0; - cb = parsecmd(buf, n); if(cb->nf < 2) r = -1; @@ -257,26 +277,48 @@ w_option(Ctlr* ctlr, char* buf, long n) nbfifoput(F9TWifi|F9WFwstate, ctlr->power); } } -/* else if(strncmp(cb->f[0], "key", 3) == 0){ + else if(strncmp(cb->f[0], "key", 3) == 0){ if((i = atoi(cb->f[0]+3)) >= 1 && i <= WNKeys){ ctlr->txkey = i-1; - key = &ctlr->keys.keys[ctlr->txkey]; + key = &ctlr->keys[ctlr->txkey]; key->len = strlen(cb->f[1]); if (key->len > WKeyLen) key->len = WKeyLen; memset(key->dat, 0, sizeof(key->dat)); memmove(key->dat, cb->f[1], key->len); + + //dcflush(key, key->len); + nbfifoput(F9TWifi|F9WFwwepkey, (ulong)key); } else r = -1; } else if(cistrcmp(cb->f[0], "txkey") == 0){ - if((i = atoi(cb->f[1])) >= 1 && i <= WNKeys) + if((i = atoi(cb->f[1])) >= 1 && i <= WNKeys){ ctlr->txkey = i-1; + nbfifoput(F9TWifi|F9WFwwepkeyid, (ulong)ctlr->txkey+1); + }else + r = -1; + } + else if(cistrcmp(cb->f[0], "scan") == 0){ + if(cistrcmp(cb->f[1], "off") == 0) + ctlr->scan = 0; + else if(cistrcmp(cb->f[1], "on") == 0) + ctlr->scan = 1; + else if((i = atoi(cb->f[1])) == 0 || i == 1) + ctlr->scan = i; else r = -1; + + if (ctlr->scan){ + nbfifoput(F9TWifi|F9WFscan, 0); + microdelay(13 * WIFI_CHANNEL_SCAN_DWEL); + } + } + else if(cistrcmp(cb->f[0], "debug") == 0){ + debug = atoi(cb->f[1]); } -*/ else + else r = -2; free(cb); return r; @@ -286,6 +328,7 @@ static long ctl(Ether* ether, void* buf, long n) { Ctlr *ctlr; + char *p; DPRINT("ctl\n"); @@ -297,6 +340,8 @@ ctl(Ether* ether, void* buf, long n) error(Eshutdown); ilock(ctlr); + if(p = strchr(buf, '=')) + *p = ' '; if(w_option(ctlr, buf, n)){ iunlock(ctlr); error(Ebadctl); @@ -405,7 +450,6 @@ txstart(Ether *ether) } } -#define IEEE80211_FCTL_FROMDS enum { WF_Data = 0x0008, WF_Fromds = 0x0200, @@ -516,7 +560,7 @@ interrupt(Ureg*, void *arg) if (type == I7WFrxdone) rxstart(ether); else if (type == I7WFtxdone) - ; + print("txdone\n"); intrclear(ether->irq, 0); iunlock(ctlr); } @@ -544,17 +588,14 @@ etherndsreset(Ether* ether) ilock(ctlr); /* Initialise stats buffer and send address to ARM7 */ - memset(ctlr->stats7, 0, sizeof(ctlr->stats7)); - dcflush(ctlr->stats7, sizeof(ctlr->stats7)); + memset(uncached(ctlr->stats7), 0, sizeof(ctlr->stats7)); nbfifoput(F9TWifi|F9WFwstats, (ulong)ctlr->stats7); /* Initialise AP list buffer and send address to ARM7 */ - memset(ctlr->aplist7, 0, sizeof(ctlr->aplist7)); - dcflush(ctlr->aplist7, sizeof(ctlr->aplist7)); + memset(uncached(ctlr->aplist7), 0, sizeof(ctlr->aplist7)); nbfifoput(F9TWifi|F9WFapquery, (ulong)ctlr->aplist7); - memset(&ctlr->rxpkt, 0, sizeof(ctlr->rxpkt)); - dcflush(&ctlr->rxpkt, sizeof(ctlr->rxpkt)); + memset(uncached(&ctlr->rxpkt), 0, sizeof(ctlr->rxpkt)); nbfifoput(F9TWifi|F9WFrxpkt, (ulong)&ctlr->rxpkt); memset(ea, 0, sizeof(ea)); @@ -562,10 +603,10 @@ etherndsreset(Ether* ether) panic("ethernet address not set"); for(i = 0; i < ether->nopt; i++){ - // - // The max. length of an 'opt' is ISAOPTLEN in dat.h. - // It should be > 16 to give reasonable name lengths. - // + /* + * The max. length of an 'opt' is ISAOPTLEN in dat.h. + * It should be > 16 to give reasonable name lengths. + */ if(p = strchr(ether->opt[i], '=')) *p = ' '; w_option(ctlr, ether->opt[i], strlen(ether->opt[i])); diff --git a/guide b/guide index ae5b8e0..df64323 100644 --- a/guide +++ b/guide @@ -7,16 +7,16 @@ git am -k -3 *.patch git archive --prefix=gds/ HEAD > gds.tar git checkout -u mount /mnt/usb -cp i*ds.nds /mnt/usb; sync -u umount /mnt/usb - i inm isds.p9 cp dsinit.b ../init i mk 'CONF=sds' vclean i mk 'CONF=sds' syms i mk 'CONF=sds' +u mount /mnt/usb +cp i*ds.nds /mnt/usb; sync +u umount /mnt/usb + desmume isds.nds desmume --disable-3d isds.nds wine $home/nogba-2.6a/'NO$GBA.EXE' isds.nds diff --git a/io.h b/io.h index 21013fb..54c8079 100644 --- a/io.h +++ b/io.h @@ -667,6 +667,10 @@ enum Arm7hasram = 1<<15, /* (0=ARM9 Priority, 1=ARM7 Priority) */ }; +/* quote: "should prevent the cache from eating us alive..." - sgstair */ +#define iscached(addr) (EWRAMZERO <= (addr) && (addr) < EWRAMTOP) +#define uncached(addr) ((ulong*)((ulong)(addr) + (EWRAMTOP - EWRAMZERO + 1))) + /* * discio interface */ diff --git a/main.c b/main.c index 44fe80c..9ae3f39 100644 --- a/main.c +++ b/main.c @@ -245,25 +245,6 @@ idlehands(void){ } /* stubs */ -void -setfsr(ulong x) { -USED(x); -} - -ulong -getfsr(){ -return 0; -} - -void -setfcr(ulong x) { -USED(x); -} - -ulong -getfcr(){ -return 0; -} void fpinit(void) diff --git a/mkfile b/mkfile index 5e4341e..ed883eb 100644 --- a/mkfile +++ b/mkfile @@ -63,6 +63,11 @@ i$CONF: $OBJ $CONF.c $CONF.root.h $LIBNAMES arm7/i$CONF arm7/i$CONF.p9: $ARM7SRC cd arm7; mk CONF'='$CONF +trap.t: trap.5 + cp trap.5 trap.t +trap.5: trap.c + 5c $CFLAGS trap.c + i$CONF.kfs: root/lib/proto/$CONF'proto' emu -c1 /os/ds/root/dis/mkkfs /os/ds/$prereq /os/ds/$target || true diff --git a/mksymtab b/mksymtab index 1fa9496..a7870bf 100755 --- a/mksymtab +++ b/mksymtab @@ -7,8 +7,13 @@ echo '00000000 .arm' inm -n $* | sed 's|.*: ||' | sort -f -k 2 | awk \ ' + function zeropad(a, z) { + for (i = z - length(a); i > 0; i--) + a = "0" a + return a + } { - addr=strtonum("0x" $1) + addr=zeropad($1,8) sym=$3 if (match($2, "[tTlL]")) @@ -19,9 +24,9 @@ inm -n $* | sed 's|.*: ||' | sort -f -k 2 | awk \ sect=".bss" if (sect != osect) - printf ("\n%08X %s\n", addr, sect) + printf ("\n%s %s\n", addr, sect) osect=sect - printf ("%08X %s\n", addr, sym) + printf ("%s %s\n", addr, sym) } ' ) diff --git a/root/usr/inferno/lib/wmsetup b/root/usr/inferno/lib/wmsetup index e639d91..47c1093 100755 --- a/root/usr/inferno/lib/wmsetup +++ b/root/usr/inferno/lib/wmsetup @@ -1,4 +1,6 @@ #!/dis/sh script +load std +load expr wmrun bind -a '#A' /dev # audio wmrun bind -b /icons/tinytk /icons/tk @@ -8,29 +10,21 @@ menu Kbd { wm/keyboard } menu Pen { wm/pen } menu Halt { wmrun shutdown -h } -#wmrun auth/factotum -#wmrun wm/date +wmrun wm/sh -w 250 -h 130 -ic ' + fn rrtc { cat ''#r/rtc''; echo } + fn rnes { cat /net/ether0/ifstats } + fn wnec { echo -n $* > /net/ether0/0/ctl } -wmrun wm/keyboard -t -wmrun wm/about -wmrun wm/sh -w 240 -h 130 -ic ' - echo welcome `{cat /dev/user}!; - - cat /dev/ndsfw + cat /net/ether0/clone > /dev/null + wnec scan on +# rnes -# echo /dev/ndsrom works! > /dev/ndsrom -# cat /dev/ndsrom | read -o 0 19 + wnec channel 11 + wnec essid cain + rnes -# echo /dev/ndssram works! > /dev/ndssram -# cat /dev/ndssram | read -o 0 20 - - echo show ints - echo '' 0x04000208/X - 0x04000210/X - 0x04000214/X'' | mdb /dev/ndsmem - - cat /net/ether0/ifstats - auplay /usr/inferno/lib/invhit.iaf + echo date + auplay /usr/inferno/lib/invhit.iaf '