08e28b8f
achemin1
Correction includ...
|
1
|
#include <libusb-1.0/libusb.h>
|
533260c1
achemin1
Ajout des lecture...
|
2
|
#include <stdio.h>
|
b79c0c43
gperson
ajout de code,Ver...
|
3
4
|
#include <stdlib.h>
|
b24d2980
achemin1
Nettoyage du code...
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
void usbinit(){
printf("Hello usbinit\n");
}
void usbclose(){
printf("Hello usbclose\n");
}
void displayDevices(){
printf("Hello list of device");
}
void displayDeviceEndpoints(){
printf("Hello endpoint\n");
}
/*int main() {
|
533260c1
achemin1
Ajout des lecture...
|
23
24
25
26
27
28
29
30
31
|
// initiate the usb thing
libusb_context *context;
int statusInit = libusb_init(&context);
if (statusInit != 0) {
perror("libusb_init");
exit(-1);
}
|
b24d2980
achemin1
Nettoyage du code...
|
32
|
/* ... some code ...*//*
|
533260c1
achemin1
Ajout des lecture...
|
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
|
// actually enumerates all the usb and gives some infos abot the usb things
libusb_device **list;
ssize_t count = libusb_get_device_list(context, &list);
if (count < 0) {
perror("libusb_get_device_list");
exit(-1);
}
ssize_t i = 0;
for (i = 0; i < count; i++) {
libusb_device *device = list[i];
struct libusb_device_descriptor desc;
int status = libusb_get_device_descriptor(device, &desc);
if (status != 0)
continue;
uint8_t bus = libusb_get_bus_number(device);
uint8_t address = libusb_get_device_address(device);
printf("Device Found @ (Bus:Address) %d:%d\n", bus, address);
printf("Vendor ID 0x0%x\n", desc.idVendor);
printf("Product ID 0x0%x\n", desc.idProduct);
// Ouverture du périphérique
libusb_device_handle *handle;
int statusDevice = libusb_open(device, &handle);
if (statusDevice != 0) {
perror("libusb_open");
exit(-1);
}
|
c8f6b178
achemin1
Affichage valeur ...
|
65
|
|
3d1c6506
achemin1
Affichage de l'ex...
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Si le méchant noyau est passé avant vous :
/*int interface = 0; // TEST : FONCTIONNE MAIS CORRESPOND A QUOI?
if (libusb_kernel_driver_active(handle, interface)) {
int statusKDriver = libusb_detach_kernel_driver(handle, interface);
if (statusKDriver != 0) {
perror("libusb_detach_kernel_driver");
exit(-1);
}
}*/
/*// lectures des configs?
int configuration = 0; // valueof("bConfigurationValue");
int statusConfig = libusb_set_configuration(handle, configuration);
if (statusConfig != 0) {
perror("libusb_set_configuration"); /*exit(-1);*/
|
fef05237
achemin1
ajout condition p...
|
81
|
/* }
|
b24d2980
achemin1
Nettoyage du code...
|
82
|
*//*
|
533260c1
achemin1
Ajout des lecture...
|
83
84
85
86
87
|
int MAXLEN_DESCRIPTOR_STRING = 200;
uint8_t desc_idx = 2;
uint16_t langid = 16;
unsigned char data[200];
|
fef05237
achemin1
ajout condition p...
|
88
89
90
91
92
93
94
95
|
// TEST 16
for (desc_idx = 0; desc_idx < 16; desc_idx++) {
int statusAscii = libusb_get_string_descriptor_ascii(
handle, desc_idx, data, MAXLEN_DESCRIPTOR_STRING);
if (statusAscii == -9) // TEST seems to be LIBUSB_ERROR
break;
printf("Descriptor string : %s ; %i\n", data, statusAscii);
}
|
c8f6b178
achemin1
Affichage valeur ...
|
96
|
|
3d1c6506
achemin1
Affichage de l'ex...
|
97
98
99
100
|
// 4.2 configuration du périph usb
struct libusb_config_descriptor *config;
int statusFetchConfig =
libusb_get_active_config_descriptor(device, &config);
|
c8f6b178
achemin1
Affichage valeur ...
|
101
102
|
if (statusFetchConfig != 0) {
perror("libusb_get_active_config_descriptor");
|
3d1c6506
achemin1
Affichage de l'ex...
|
103
|
// exit(-1);
|
c8f6b178
achemin1
Affichage valeur ...
|
104
105
|
}
printf("Config.bConfigurationValue : %d\n", config->bConfigurationValue);
|
3d1c6506
achemin1
Affichage de l'ex...
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
printf("Config/ bLength:%d;bDescriptorType:%d;bNumInterfaces:%d",
config->bLength, config->bDescriptorType, config->bNumInterfaces);
// itération de l'interface
for (int indexInterface = 0; indexInterface < config->bNumInterfaces;
indexInterface++) {
// struct libusb_interface * interface =
// &config->interface[indexInterface];
printf("^%d", indexInterface);
printf("Alt%d", config->interface[indexInterface].num_altsetting);
}
printf("\n");
/*
//appropriation de l'interface
int statusClaimInterface=libusb_claim_interface(handle,interface);
if(status!=0){ perror("libusb_claim_interface"); exit(-1); }
/* ... some code ... */
/*
|
c8f6b178
achemin1
Affichage valeur ...
|
128
129
|
|
3d1c6506
achemin1
Affichage de l'ex...
|
130
131
132
|
status=libusb_release_interface(handle,interface);
if(status!=0){ perror("libusb_release_interface"); exit(-1); }
*/
|
c8f6b178
achemin1
Affichage valeur ...
|
133
|
|
533260c1
achemin1
Ajout des lecture...
|
134
|
/* ... some ... code */
|
b24d2980
achemin1
Nettoyage du code...
|
135
136
|
/*libusb_close(handle);
}*/
|
b79c0c43
gperson
ajout de code,Ver...
|
137
|
|
b24d2980
achemin1
Nettoyage du code...
|
138
|
/* libusb_free_device_list(list, 1);
|
b79c0c43
gperson
ajout de code,Ver...
|
139
|
|
533260c1
achemin1
Ajout des lecture...
|
140
141
|
libusb_exit(context);
return 0;
|
b24d2980
achemin1
Nettoyage du code...
|
142
|
}*/
|