summaryrefslogtreecommitdiffstats
path: root/tests/libusb_wraps.c
blob: 85bb963bcd11caecd730e9191ef00b0865a2cc7a (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * This file is part of the flashrom project.
 *
 * Copyright 2021 Google LLC
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <stdlib.h>

#include <include/test.h>
#include "io_mock.h"
#include "libusb_wraps.h"

void *__wrap_usb_dev_get_by_vid_pid_number(
		libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num)
{
	LOG_ME;
	return not_null();
}

int __wrap_libusb_init(libusb_context **ctx)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_init)
		return get_io()->libusb_init(get_io()->state, ctx);
	return 0;
}

int __wrap_libusb_open(libusb_device *dev, libusb_device_handle **devh)
{
	LOG_ME;
	return 0;
}

int __wrap_libusb_set_auto_detach_kernel_driver(libusb_device_handle *devh, int enable)
{
	LOG_ME;
	return 0;
}

int __wrap_libusb_detach_kernel_driver(libusb_device_handle *dev_handle, int interface_number)
{
	LOG_ME;
	return 0;
}

int __wrap_libusb_attach_kernel_driver(libusb_device_handle *dev_handle, int interface_number)
{
	LOG_ME;
	return 0;
}

ssize_t __wrap_libusb_get_device_list(libusb_context *ctx, libusb_device ***list)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_get_device_list)
		return get_io()->libusb_get_device_list(get_io()->state, ctx, list);
	return 0;
}

void __wrap_libusb_free_device_list(libusb_device **list, int unref_devices)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_free_device_list)
		get_io()->libusb_free_device_list(get_io()->state, list, unref_devices);
}

uint8_t __wrap_libusb_get_bus_number(libusb_device *dev)
{
	LOG_ME;
	return 0;
}

uint8_t __wrap_libusb_get_device_address(libusb_device *dev)
{
	LOG_ME;
	return USB_DEVICE_ADDRESS;
}

int __wrap_libusb_get_device_descriptor(libusb_device *dev, struct libusb_device_descriptor *desc)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_get_device_descriptor)
		return get_io()->libusb_get_device_descriptor(get_io()->state, dev, desc);
	return 0;
}

int __wrap_libusb_get_config_descriptor(
		libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_get_config_descriptor)
		return get_io()->libusb_get_config_descriptor(get_io()->state, dev, config_index, config);
	return 0;
}

void __wrap_libusb_free_config_descriptor(struct libusb_config_descriptor *config)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_free_config_descriptor)
		return get_io()->libusb_free_config_descriptor(get_io()->state, config);
	return;
}

int __wrap_libusb_get_configuration(libusb_device_handle *devh, int *config)
{
	LOG_ME;
	return 0;
}

int __wrap_libusb_set_configuration(libusb_device_handle *devh, int config)
{
	LOG_ME;
	return 0;
}

int __wrap_libusb_claim_interface(libusb_device_handle *devh, int interface_number)
{
	LOG_ME;
	return 0;
}

int __wrap_libusb_control_transfer(libusb_device_handle *devh, uint8_t bmRequestType,
		uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data,
		uint16_t wLength, unsigned int timeout)
{
	LOG_ME;
	if (get_io() && get_io()->libusb_control_transfer)
		return get_io()->libusb_control_transfer(get_io()->state,
				devh, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout);
	return 0;
}

int __wrap_libusb_release_interface(libusb_device_handle *devh, int interface_number)
{
	LOG_ME;
	return 0;
}

void __wrap_libusb_close(libusb_device_handle *devh)
{
	LOG_ME;
}

libusb_device *__wrap_libusb_ref_device(libusb_device *dev)
{
	LOG_ME;
	return NULL;
}

void __wrap_libusb_unref_device(libusb_device *dev)
{
	LOG_ME;
}

void __wrap_libusb_exit(libusb_context *ctx)
{
	LOG_ME;
}