| 1 |
/* |
| 2 |
* This file is part of the flashrom project. |
| 3 |
* |
| 4 |
* Copyright 2021 Google LLC |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; version 2 of the License. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include <stdlib.h> |
| 17 |
|
| 18 |
#include <include/test.h> |
| 19 |
#include "io_mock.h" |
| 20 |
#include "libusb_wraps.h" |
| 21 |
|
| 22 |
void *__wrap_usb_dev_get_by_vid_pid_number( |
| 23 |
libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num) |
| 24 |
{ |
| 25 |
LOG_ME; |
| 26 |
return not_null(); |
| 27 |
} |
| 28 |
|
| 29 |
int __wrap_libusb_init(libusb_context **ctx) |
| 30 |
{ |
| 31 |
LOG_ME; |
| 32 |
if (get_io() && get_io()->libusb_init) |
| 33 |
return get_io()->libusb_init(get_io()->state, ctx); |
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
void __wrap_libusb_set_debug(libusb_context *ctx, int level) |
| 38 |
{ |
| 39 |
LOG_ME; |
| 40 |
} |
| 41 |
|
| 42 |
int __wrap_libusb_set_option(libusb_context *ctx, int option, ...) |
| 43 |
{ |
| 44 |
LOG_ME; |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
int __wrap_libusb_open(libusb_device *dev, libusb_device_handle **devh) |
| 49 |
{ |
| 50 |
LOG_ME; |
| 51 |
return 0; |
| 52 |
} |
| 53 |
|
| 54 |
int __wrap_libusb_set_auto_detach_kernel_driver(libusb_device_handle *devh, int enable) |
| 55 |
{ |
| 56 |
LOG_ME; |
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
int __wrap_libusb_detach_kernel_driver(libusb_device_handle *dev_handle, int interface_number) |
| 61 |
{ |
| 62 |
LOG_ME; |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
int __wrap_libusb_attach_kernel_driver(libusb_device_handle *dev_handle, int interface_number) |
| 67 |
{ |
| 68 |
LOG_ME; |
| 69 |
return 0; |
| 70 |
} |
| 71 |
|
| 72 |
struct libusb_device_handle *__wrap_libusb_open_device_with_vid_pid( |
| 73 |
libusb_context *ctx, uint16_t vendor_id, uint16_t product_id) |
| 74 |
{ |
| 75 |
LOG_ME; |
| 76 |
return not_null(); |
| 77 |
} |
| 78 |
|
| 79 |
libusb_device *__wrap_libusb_get_device(libusb_device_handle *dev_handle) |
| 80 |
{ |
| 81 |
LOG_ME; |
| 82 |
return not_null(); |
| 83 |
} |
| 84 |
|
| 85 |
ssize_t __wrap_libusb_get_device_list(libusb_context *ctx, libusb_device ***list) |
| 86 |
{ |
| 87 |
LOG_ME; |
| 88 |
if (get_io() && get_io()->libusb_get_device_list) |
| 89 |
return get_io()->libusb_get_device_list(get_io()->state, ctx, list); |
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
void __wrap_libusb_free_device_list(libusb_device **list, int unref_devices) |
| 94 |
{ |
| 95 |
LOG_ME; |
| 96 |
if (get_io() && get_io()->libusb_free_device_list) |
| 97 |
get_io()->libusb_free_device_list(get_io()->state, list, unref_devices); |
| 98 |
} |
| 99 |
|
| 100 |
uint8_t __wrap_libusb_get_bus_number(libusb_device *dev) |
| 101 |
{ |
| 102 |
LOG_ME; |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
uint8_t __wrap_libusb_get_device_address(libusb_device *dev) |
| 107 |
{ |
| 108 |
LOG_ME; |
| 109 |
return USB_DEVICE_ADDRESS; |
| 110 |
} |
| 111 |
|
| 112 |
int __wrap_libusb_get_device_descriptor(libusb_device *dev, struct libusb_device_descriptor *desc) |
| 113 |
{ |
| 114 |
LOG_ME; |
| 115 |
if (get_io() && get_io()->libusb_get_device_descriptor) |
| 116 |
return get_io()->libusb_get_device_descriptor(get_io()->state, dev, desc); |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
int __wrap_libusb_get_config_descriptor( |
| 121 |
libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config) |
| 122 |
{ |
| 123 |
LOG_ME; |
| 124 |
if (get_io() && get_io()->libusb_get_config_descriptor) |
| 125 |
return get_io()->libusb_get_config_descriptor(get_io()->state, dev, config_index, config); |
| 126 |
return 0; |
| 127 |
} |
| 128 |
|
| 129 |
void __wrap_libusb_free_config_descriptor(struct libusb_config_descriptor *config) |
| 130 |
{ |
| 131 |
LOG_ME; |
| 132 |
if (get_io() && get_io()->libusb_free_config_descriptor) |
| 133 |
return get_io()->libusb_free_config_descriptor(get_io()->state, config); |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
int __wrap_libusb_get_configuration(libusb_device_handle *devh, int *config) |
| 138 |
{ |
| 139 |
LOG_ME; |
| 140 |
return 0; |
| 141 |
} |
| 142 |
|
| 143 |
int __wrap_libusb_set_configuration(libusb_device_handle *devh, int config) |
| 144 |
{ |
| 145 |
LOG_ME; |
| 146 |
return 0; |
| 147 |
} |
| 148 |
|
| 149 |
int __wrap_libusb_claim_interface(libusb_device_handle *devh, int interface_number) |
| 150 |
{ |
| 151 |
LOG_ME; |
| 152 |
return 0; |
| 153 |
} |
| 154 |
|
| 155 |
int __wrap_libusb_control_transfer(libusb_device_handle *devh, uint8_t bmRequestType, |
| 156 |
uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, |
| 157 |
uint16_t wLength, unsigned int timeout) |
| 158 |
{ |
| 159 |
LOG_ME; |
| 160 |
if (get_io() && get_io()->libusb_control_transfer) |
| 161 |
return get_io()->libusb_control_transfer(get_io()->state, |
| 162 |
devh, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout); |
| 163 |
return 0; |
| 164 |
} |
| 165 |
|
| 166 |
int __wrap_libusb_release_interface(libusb_device_handle *devh, int interface_number) |
| 167 |
{ |
| 168 |
LOG_ME; |
| 169 |
return 0; |
| 170 |
} |
| 171 |
|
| 172 |
void __wrap_libusb_close(libusb_device_handle *devh) |
| 173 |
{ |
| 174 |
LOG_ME; |
| 175 |
} |
| 176 |
|
| 177 |
libusb_device *__wrap_libusb_ref_device(libusb_device *dev) |
| 178 |
{ |
| 179 |
LOG_ME; |
| 180 |
return NULL; |
| 181 |
} |
| 182 |
|
| 183 |
void __wrap_libusb_unref_device(libusb_device *dev) |
| 184 |
{ |
| 185 |
LOG_ME; |
| 186 |
} |
| 187 |
|
| 188 |
struct libusb_transfer *__wrap_libusb_alloc_transfer(int iso_packets) |
| 189 |
{ |
| 190 |
LOG_ME; |
| 191 |
if (get_io() && get_io()->libusb_alloc_transfer) |
| 192 |
return get_io()->libusb_alloc_transfer(get_io()->state, iso_packets); |
| 193 |
return not_null(); |
| 194 |
} |
| 195 |
|
| 196 |
int __wrap_libusb_submit_transfer(struct libusb_transfer *transfer) |
| 197 |
{ |
| 198 |
LOG_ME; |
| 199 |
if (get_io() && get_io()->libusb_submit_transfer) |
| 200 |
return get_io()->libusb_submit_transfer(get_io()->state, transfer); |
| 201 |
return 0; |
| 202 |
} |
| 203 |
|
| 204 |
void __wrap_libusb_free_transfer(struct libusb_transfer *transfer) |
| 205 |
{ |
| 206 |
LOG_ME; |
| 207 |
if (get_io() && get_io()->libusb_free_transfer) |
| 208 |
get_io()->libusb_free_transfer(get_io()->state, transfer); |
| 209 |
} |
| 210 |
|
| 211 |
int __wrap_libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv) |
| 212 |
{ |
| 213 |
LOG_ME; |
| 214 |
if (get_io() && get_io()->libusb_handle_events_timeout) |
| 215 |
get_io()->libusb_handle_events_timeout(get_io()->state, ctx, tv); |
| 216 |
return 0; |
| 217 |
} |
| 218 |
|
| 219 |
void __wrap_libusb_exit(libusb_context *ctx) |
| 220 |
{ |
| 221 |
LOG_ME; |
| 222 |
} |