blob: b8adbb78ffa991f273bbdabdd8ecea790ee79dfb [file] [log] [blame]
Dan Shid2d11132020-04-26 00:22:55 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.tests.usbgadget.libusb;
17
18import com.sun.jna.Library;
19import com.sun.jna.Pointer;
20import com.sun.jna.ptr.PointerByReference;
21
22/** JNA adapter for <a href="https://libusb.info">libusb</a>. */
23public interface IUsbNative extends Library {
24 /**
25 * Initialize libusb, must be called before calling any other function.
26 *
27 * @param context output location for context pointer
28 * @return 0 on success, or an error code
29 */
30 int libusb_init(PointerByReference context);
31
32 /**
33 * Deinitialize libusb.
34 *
35 * @param ctx context to deinitialize
36 */
37 void libusb_exit(Pointer ctx);
38
39 /**
40 * Returns a list of USB devices currently attached to the system.
41 *
42 * @param ctx context to operate on
43 * @param list output location for a list of devices
44 * @return number of devices, or an error code
45 */
46 int libusb_get_device_list(Pointer ctx, PointerByReference list);
47
48 /**
49 * Get the USB device descriptor for a given device.
50 *
51 * @param dev device
52 * @param desc output location for the descriptor data
53 * @return 0 on success, or an error code
54 */
55 int libusb_get_device_descriptor(Pointer dev, DeviceDescriptor[] desc);
56
57 /**
58 * Get a USB configuration descriptor based on its index.
59 *
60 * @param dev device
61 * @param config_index config index
62 * @param config a USB configuration descriptor pointer
63 * @return 0 on success, or an error code
64 */
65 int libusb_get_config_descriptor(Pointer dev, int config_index, PointerByReference config);
66}