-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathAmlUsbScanX3.cpp
More file actions
128 lines (101 loc) · 2.95 KB
/
AmlUsbScanX3.cpp
File metadata and controls
128 lines (101 loc) · 2.95 KB
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
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include "usbcompat.h"
#include "Amldbglog.h"
#include "AmlUsbScanX3.h"
struct AmlscanX {
const char *vendorName;
struct usb_device **resultDevice;
char *targetDevice;
char **candidateDevices;
int *nDevices;
};
static int gLevel;
static char gHasSetDebugLevel;
static int scanDevices (struct AmlscanX scan, const char *target) {
if (strcmp(scan.vendorName, "WorldCup Device") != 0) {
aml_printf("[Scan][ERR]L%03d:", 159);
aml_printf("Only supports scanning for [%s]\n", "WorldCup Device");
return 0;
}
usb_init();
usb_find_busses();
usb_find_devices();
int i = 0;
for (struct usb_bus *bus = usb_busses; bus != NULL; bus = bus->next) {
for (struct usb_device *dev = bus->devices; dev != NULL; dev = dev->next) {
if (dev->descriptor.idVendor != AML_ID_VENDOR ||
dev->descriptor.idProduct != AML_ID_PRODUCE) {
continue;
}
char buf[128];
snprintf(
buf, sizeof(buf), "Bus %03d Device %03d: ID %04x:%04x",
dev->bus ? dev->bus->location : 0, dev->devnum,
AML_ID_VENDOR, AML_ID_PRODUCE);
if (target == NULL) {
strcpy(scan.candidateDevices[i], buf);
} else if (strcmp(buf, target) == 0) {
*scan.resultDevice = dev;
return 1;
}
i++;
}
}
*scan.nDevices = i;
return 1;
}
int AmlScanUsbX3Devices (const char *vendorName, char **candidateDevices) {
int nDevices = 0;
struct AmlscanX scan = {vendorName, NULL, NULL, candidateDevices, &nDevices};
gLevel = 0;
if (gHasSetDebugLevel != 1) {
gHasSetDebugLevel = 1;
}
if (scanDevices(scan, NULL) == 0) {
aml_printf("AmlScanUsbX3Devices:scan usb devices failed\n");
nDevices = -1;
}
return nDevices;
}
struct usb_device *AmlGetDeviceHandle (
const char *vendorName, char *targetDevice) {
int nDevices = 0;
struct usb_device *resultDevice = NULL;
char *candidateDevices[8] = {};
struct AmlscanX scan = {
vendorName, &resultDevice, targetDevice, candidateDevices, &nDevices};
gLevel = 0;
for (int i = 0; i <= 7; ++i) {
candidateDevices[i] = (char *) malloc(0x100);
memset(candidateDevices[i], 0, 0x100);
}
if (scanDevices(scan, targetDevice) == 0) {
aml_printf("get usb devices handle failed\n");
resultDevice = NULL;
}
for (int i = 0; i <= 7; ++i) {
if (candidateDevices[i]) {
free(candidateDevices[i]);
}
}
return resultDevice;
}
int AmlGetMsNumber (char *targetDevice, int a2, char *vendorName) {
(void) targetDevice;
(void) a2;
(void) vendorName;
aml_printf("%s L%d not implemented", "AmlGetMsNumber", 292);
return 0;
}
int AmlGetNeedDriver (unsigned short idVendor, unsigned short idProduct) {
(void) idVendor;
(void) idProduct;
aml_printf("%s L%d not implemented", "AmlGetNeedDriver", 301);
return 0;
}
int AmlDisableSuspendForUsb (void) {
aml_printf("%s L%d not implemented", "AmlDisableSuspendForUsb", 311);
return 0;
}