1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
typedef struct Ether Ether;
typedef struct Etherops Etherops;
typedef struct Conn Conn;
typedef struct Cinfo Cinfo;
typedef struct Buf Buf;
typedef struct Etherpkt Etherpkt;
enum
{
/* controller ids */
Cdc = 0,
A8817x, /* Asis */
A88178,
A88179,
A88772,
Eaddrlen = 6,
Epktlen = 1514,
Ehdrsize = 2*Eaddrlen + 2,
Maxpkt = 2000, /* no jumbo packets here */
Nconns = 8, /* max number of connections */
Nbufs = 8, /* max number of buffers */
Scether = 6, /* ethernet cdc subclass */
Fnheader = 0, /* Functions */
Fnunion = 6,
Fnether = 15,
Cdcunion = 6, /* CDC Union descriptor subtype */
};
struct Buf
{
int type;
int ndata;
uchar* rp;
uchar data[Hdrsize+Maxpkt];
};
struct Conn
{
Ref; /* one per file in use */
int nb;
int type;
int headersonly;
int prom;
Channel*rc; /* [2] of Buf* */
};
struct Etherops
{
int (*init)(Ether*, int *epin, int *epout);
long (*bread)(Ether*, Buf*);
long (*bwrite)(Ether*, Buf*);
int (*ctl)(Ether*, char*);
int (*promiscuous)(Ether*, int);
int (*multicast)(Ether*, uchar*, int);
char* (*seprintstats)(char*, char*, Ether*);
void (*free)(Ether*);
void* aux;
};
struct Ether
{
QLock;
QLock wlck; /* write one at a time */
int epinid; /* epin address */
int epoutid; /* epout address */
Dev* dev;
Dev* epin;
Dev* epout;
int cid; /* ctlr id */
int phy; /* phy id */
Ref prom; /* nb. of promiscuous conns */
int exiting; /* shutting down */
int wrexited; /* write process died */
uchar addr[Eaddrlen]; /* mac */
int nconns; /* nb. of entries used in... */
Conn* conns[Nconns]; /* connections */
int nabufs; /* nb. of allocated buffers */
int nbufs; /* nb. of buffers in use */
int nblock; /* nonblocking (output)? */
long nin;
long nout;
long nierrs;
long noerrs;
int mbps;
int nmcasts;
Channel*rc; /* read channel (of Buf*) */
Channel*wc; /* write channel (of Buf*) */
Channel*bc; /* free buf. chan. (of Buf*) */
Etherops;
Usbfs fs;
};
struct Cinfo
{
int vid; /* usb vendor id */
int did; /* usb device/product id */
int cid; /* controller id assigned by us */
};
struct Etherpkt
{
uchar d[Eaddrlen];
uchar s[Eaddrlen];
uchar type[2];
uchar data[1500];
};
int ethermain(Dev *dev, int argc, char **argv);
int asixreset(Ether*);
int cdcreset(Ether*);
int parseaddr(uchar *m, char *s);
void dumpframe(char *tag, void *p, int n);
extern Cinfo cinfo[];
extern int etherdebug;
#define deprint if(etherdebug)fprint
|