Skip to content

Commit

Permalink
some scaffold & fixes to get wifi working
Browse files Browse the repository at this point in the history
  • Loading branch information
saoret.one committed Dec 1, 2008
1 parent 5d8bf89 commit 81840a8
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 111 deletions.
14 changes: 6 additions & 8 deletions archds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions arm7/mkdeps
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -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")){
Expand Down
2 changes: 1 addition & 1 deletion arm7/mkfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ OFILES=\
spi.$O\
rtc.$O\
audio.$O\
# dma.$O\
wifi.$O\
# dma.$O\
HFILES=\
../io.h\
Expand Down
10 changes: 10 additions & 0 deletions arm7/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
147 changes: 94 additions & 53 deletions ethernds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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],
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -286,6 +328,7 @@ static long
ctl(Ether* ether, void* buf, long n)
{
Ctlr *ctlr;
char *p;

DPRINT("ctl\n");

Expand All @@ -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);
Expand Down Expand Up @@ -405,7 +450,6 @@ txstart(Ether *ether)
}
}

#define IEEE80211_FCTL_FROMDS
enum {
WF_Data = 0x0008,
WF_Fromds = 0x0200,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -544,28 +588,25 @@ 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));
if(memcmp(ether->ea, ea, Eaddrlen) == 0)
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]));
Expand Down
Loading

0 comments on commit 81840a8

Please sign in to comment.