Subversion Repositories freemyipod

Rev

Rev 901 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 901 Rev 916
Line 24... Line 24...
24
 
24
 
25
#include "emcore.h"
25
#include "emcore.h"
26
#include "util.h"
26
#include "util.h"
27
#include "usb.h"
27
#include "usb.h"
28
 
28
 
29
libusb_context *usb_ctx = NULL;
29
libusb_context *usb_ctx;
30
libusb_device_handle *usb_handle = NULL;
30
libusb_device_handle *usb_handle;
31
uint8_t usb_iface_num = 0;
31
uint8_t usb_iface_num;
32
 
32
 
33
int32_t usb_init(void) {
33
int32_t usb_init(void) {
34
    int32_t res;
34
    int32_t res;
35
 
35
 
36
#ifdef DEBUG
36
#ifdef DEBUG
Line 51... Line 51...
51
    return LIBUSB_SUCCESS;
51
    return LIBUSB_SUCCESS;
52
}
52
}
53
 
53
 
54
int32_t usb_find(uint16_t vendor_id, uint16_t product_id, uint8_t *reattach) {
54
int32_t usb_find(uint16_t vendor_id, uint16_t product_id, uint8_t *reattach) {
55
    libusb_device **devs, *dev = NULL;
55
    libusb_device **devs, *dev = NULL;
56
    ssize_t devs_cnt, i, j, k, l;
56
    ssize_t devs_cnt, i;
-
 
57
    uint8_t found = 0, j, k;
-
 
58
    int l;
57
    int32_t res;
59
    int32_t res;
58
    uint8_t found = 0;
-
 
59
    struct libusb_device_descriptor dev_desc;
60
    struct libusb_device_descriptor dev_desc;
60
    struct libusb_config_descriptor *cfg_desc;
61
    struct libusb_config_descriptor *cfg_desc;
61
    const struct libusb_interface *iface;
62
    const struct libusb_interface *iface;
62
    const struct libusb_interface_descriptor *iface_desc;
63
    const struct libusb_interface_descriptor *iface_desc;
63
 
64
 
Line 70... Line 71...
70
    if (devs_cnt < 0) {
71
    if (devs_cnt < 0) {
71
        return devs_cnt;
72
        return devs_cnt;
72
    }
73
    }
73
 
74
 
74
#ifdef DEBUG
75
#ifdef DEBUG
75
    fprintf(stderr, "Found %Zd USB devices!\n", devs_cnt);
76
    fprintf(stderr, "Found %zd USB devices!\n", devs_cnt);
76
#endif
77
#endif
77
    for (i = 0; i < devs_cnt; ++i) {
78
    for (i = 0; i < devs_cnt; ++i) {
78
        dev = devs[i];
79
        dev = devs[i];
79
#ifdef DEBUG
80
#ifdef DEBUG
80
        fprintf(stderr, "Getting device descriptor of USB device %d...\n", i);
81
        fprintf(stderr, "Getting device descriptor of USB device %zd...\n", i);
81
#endif
82
#endif
82
        res = libusb_get_device_descriptor(dev, &dev_desc);
83
        res = libusb_get_device_descriptor(dev, &dev_desc);
83
 
84
 
84
        if (res != LIBUSB_SUCCESS) {
85
        if (res != LIBUSB_SUCCESS) {
85
#ifdef DEBUG
86
#ifdef DEBUG
86
            fprintf(stderr, "Unable to get device descriptor of device %d!\n", i);
87
            fprintf(stderr, "Unable to get device descriptor of device %zd!\n", i);
87
#endif
88
#endif
88
            continue;
89
            continue;
89
        }
90
        }
90
 
91
 
91
#ifdef DEBUG
92
#ifdef DEBUG
Line 106... Line 107...
106
#endif
107
#endif
107
            continue;
108
            continue;
108
        }
109
        }
109
 
110
 
110
#ifdef DEBUG
111
#ifdef DEBUG
111
        fprintf(stderr, "Found %Zd configs...\n", dev_desc.bNumConfigurations);
112
        fprintf(stderr, "Found %u configs...\n", dev_desc.bNumConfigurations);
112
#endif
113
#endif
113
 
114
 
114
        for (j = 0; j < dev_desc.bNumConfigurations; ++j) {
115
        for (j = 0; j < dev_desc.bNumConfigurations; ++j) {
115
#ifdef DEBUG
116
#ifdef DEBUG
116
            fprintf(stderr, "Getting config descriptor %Zd of device...\n", j);
117
            fprintf(stderr, "Getting config descriptor %u of device...\n", j);
117
#endif
118
#endif
118
 
119
 
119
            res = libusb_get_config_descriptor(dev, j, &cfg_desc);
120
            res = libusb_get_config_descriptor(dev, j, &cfg_desc);
120
 
121
 
121
            if (res != LIBUSB_SUCCESS) {
122
            if (res != LIBUSB_SUCCESS) {
Line 153... Line 154...
153
 
154
 
154
                        continue;
155
                        continue;
155
                    }
156
                    }
156
                    
157
                    
157
#ifdef DEBUG
158
#ifdef DEBUG
158
                    fprintf(stderr, "emCORE Debugger interface at %Zd\n", iface_desc->bInterfaceNumber);
159
                    fprintf(stderr, "emCORE Debugger interface at %u\n", iface_desc->bInterfaceNumber);
159
#endif
160
#endif
160
 
161
 
161
                    usb_iface_num = iface_desc->bInterfaceNumber;
162
                    usb_iface_num = iface_desc->bInterfaceNumber;
162
                    found = 1;
163
                    found = 1;
163
                    goto outside_search_loop;
164
                    goto outside_search_loop;