summaryrefslogtreecommitdiff
path: root/module/usb.m
blob: ccd31550970a12d9674f2a7fd1a23fcd89b87bab (plain)
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
121
122
123
124
125
126
127
128
129
130
Usb: module
{
	PATH: con "/dis/lib/usb/usb.dis";
	DATABASEPATH: con "/lib/usbdb";
	RH2D: con 0<<7;
	RD2H: con 1<<7;
	Rstandard: con 0<<5;
	Rclass: con 1<<5;
	Rvendor: con 2<<5;
	Rdevice: con 0;
	Rinterface: con 1;
	Rendpt: con 2;
	Rother: con 3;
	
	GET_STATUS: con 0;
	CLEAR_FEATURE: con 1;
	SET_FEATURE: con 3;
	SET_ADDRESS: con 5;
	GET_DESCRIPTOR: con 6;
	SET_DESCRIPTOR: con 7;
	GET_CONFIGURATION: con 8;
	SET_CONFIGURATION: con 9;
	GET_INTERFACE: con 10;
	SET_INTERFACE: con 11;
	SYNCH_FRAME: con 12;
	
	DEVICE: con 1;
	CONFIGURATION: con 2;
	STRING: con 3;
	INTERFACE: con 4;
	ENDPOINT: con 5;
	HID: con 16r21;
	REPORT: con 16r22;
	PHYSICAL: con 16r23;
	HUB: con 16r29;

	CL_AUDIO: con 1;
	CL_COMMS: con 2;
	CL_HID: con 3;
	CL_PRINTER: con 7;
	CL_MASS: con 8;
	CL_HUB: con 9;
	CL_DATA: con 10;

	DDEVLEN: con 18;
	DCONFLEN: con 9;
	DINTERLEN: con 9;
	DENDPLEN: con 7;
	DHUBLEN: con 9;
	DHIDLEN: con 9;

	PORT_CONNECTION: con 0;
	PORT_ENABLE: con 1;
	PORT_SUSPEND: con 2;
	PORT_OVER_CURRENT: con 3;
	PORT_RESET: con 4;
	PORT_POWER: con 8;
	PORT_LOW_SPEED: con 9;

	Endpt: adt {
		addr: int;
		d2h:	int;
		attr:	int;
		etype:	int;
		isotype:	int;
		maxpkt: int;
		interval: int;
	};

	Econtrol, Eiso, Ebulk, Eintr: con iota;	# Endpt.etype
	Eunknown, Easync, Eadapt, Esync: con iota;	# Endpt.isotype
	
	NendPt: con 16;
	
	Device: adt {
		usbmajor, usbminor, relmajor, relminor: int;
		class, subclass, proto, maxpkt0, vid, did, nconf: int;
	};

	AltInterface: adt {
		id: int;
		class, subclass, proto: int;
		ep: array of ref Endpt;
	};

	Interface: adt {
		altiface: list of ref AltInterface;
	};

	Configuration: adt {
		id: int;
		attr: int;
		powerma: int;
		iface: array of Interface;
	};

	init: fn();
	get2: fn(b: array of byte): int;
	put2: fn(buf: array of byte, v: int);
	get4: fn(b: array of byte): int;
	put4: fn(buf: array of byte, v: int);
	bigget2: fn(b: array of byte): int;
	bigput2: fn(buf: array of byte, v: int);
	bigget4: fn(b: array of byte): int;
	bigput4: fn(buf: array of byte, v: int);
	memset: fn(b: array of byte, v: int);
	strtol: fn(s: string, base: int): (int, string);
	sclass: fn(class, subclass, proto: int): string;
	
	get_descriptor: fn(fd: ref Sys->FD, rtyp: int, dtyp: int, dindex: int, langid: int, buf: array of byte): int;
	get_standard_descriptor: fn(fd: ref Sys->FD, dtyp: int, index: int, buf: array of byte): int;
	get_class_descriptor: fn(fd: ref Sys->FD, dtyp: int, index: int, buf: array of byte): int;
	get_vendor_descriptor: fn(fd: ref Sys->FD, dtyp: int, index: int, buf: array of byte): int;
	get_status: fn(fd: ref Sys->FD, port: int): int;
	set_address: fn(fd: ref Sys->FD, address: int): int;
	set_configuration: fn(fd: ref Sys->FD, n: int): int;
	setclear_feature: fn(fd: ref Sys->FD, rtyp: int, value: int, index: int, on: int): int;
	setup: fn(setupfd: ref Sys->FD, typ, req, value, index: int, outbuf: array of byte, inbuf: array of byte): int;
	get_parsed_configuration_descriptor: fn(fd: ref Sys->FD, n: int): ref Configuration;
	get_parsed_device_descriptor: fn(fd: ref Sys->FD): ref Device;

	dump_configuration: fn(fd: ref Sys->FD, conf: ref Configuration);
};

UsbDriver: module
{
	MOUSEPATH: con "/appl/cmd/usb/usbmouse.dis";
	init: fn(usb: Usb, setupfd, ctlfd: ref Sys->FD, dev: ref Usb->Device, conf: array of ref Usb->Configuration, path: string): int;
	shutdown: fn();
};