├── .gitignore ├── README.md ├── pom.xml └── src └── main └── java └── org └── beblue └── jna └── usb ├── LibUSB.java ├── LibUSBConstants.java ├── devtools └── UsbStructInfo.java ├── usb_bus.java ├── usb_config_descriptor.java ├── usb_dev_handle.java ├── usb_device.java ├── usb_device_descriptor.java ├── usb_endpoint_descriptor.java ├── usb_interface.java └── usb_interface_descriptor.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | # Eclipse and Maven files # 9 | .classpath 10 | .project 11 | .settings/ 12 | target/ 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libusb4j 2 | ======== 3 | 4 | Enables libusb (0.1) from within Java using the JNA (Java Native Access) library. 5 | 6 | Call for Help 7 | -------- 8 | If you know [JNA][1], [libusb][2], or maybe just C or Java, please consider spending some time on this project, as it is in need of some professional help. 9 | [I][3] don't know much about C, libusb, or JNA myself. The primary reason I forked the project is that before I didn't find the way to get the source code convenient. 10 | As it turned out, this project is too immature for me to use, which is why I'd like people to chip in. 11 | 12 | 13 | Origin 14 | -------- 15 | 16 | A Maven-compatible fork of Mario Boikov's libusb4j 17 | 18 | Mario is the original author. See his project [here][4] 19 | Marco (a.k.a. hybris0) forked the project and published it [here][5] 20 | 21 | I then took the newest fork (the one by Marco) and forked it again, which is what you see here. 22 | I converted it to Maven and published it on [github][6]. 23 | 24 | Usage 25 | -------- 26 | 27 | Run `mvn install` to be able to use libusb4j as a dependency in other projects. 28 | 29 | If you'd like to modify the source code, here are some pointers 30 | * Clone the repo and import it as an "Existing Maven Project" into Eclipse (requires m2e). 31 | * Don't forget about the [LGPL license][7] 32 | * Feel free to contact me if you found/fixed bugs or made any other changes worth sharing here. 33 | 34 | License 35 | -------- 36 | 37 | The project is licensed under the [LGPL license][4] v2.1 or later. 38 | This means you can modify the code, but you also have to publish the modifications under the LGPL. 39 | You can use the library in closed-source projects. 40 | 41 | [1]: https://github.com/twall/jna 42 | [2]: http://www.libusb.org/ 43 | [3]: https://github.com/derabbink 44 | [4]: https://launchpad.net/libusb4j "libusb4j on launchpad.net" 45 | [5]: http://kenai.com/projects/libusb4j "libusb4j on kenai.com" 46 | [6]: https://github.com/derabbink/libusb4j "project website on github" 47 | [7]: http://www.gnu.org/copyleft/lesser.html "LGPL license" 48 | 49 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.abbink 4 | libusb4j 5 | 0.0.1-SNAPSHOT 6 | libusb4j 7 | A maven port of the ant based libusb4j from http://kenai.com/projects/libusb4j 8 | 9 | 10 | com.sun.jna 11 | jna 12 | 3.0.9 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/LibUSB.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import java.nio.Buffer; 22 | 23 | import com.sun.jna.Library; 24 | import com.sun.jna.Native; 25 | 26 | public interface LibUSB extends Library { 27 | 28 | 29 | LibUSB libUSB = (LibUSB) Native.loadLibrary("usb", LibUSB.class); 30 | 31 | /* Core Operations. */ 32 | void usb_init(); 33 | 34 | int usb_find_busses(); 35 | 36 | int usb_find_devices(); 37 | 38 | usb_bus usb_get_busses(); 39 | 40 | /* Device operations. */ 41 | usb_dev_handle usb_open(usb_device dev); 42 | 43 | int usb_close(usb_dev_handle dev); 44 | 45 | int usb_set_configuration(usb_dev_handle dev, int configuration); 46 | 47 | int usb_set_altinterface(usb_dev_handle dev, int alternate); 48 | 49 | int usb_resetep(usb_dev_handle dev, int ep); 50 | 51 | int usb_clear_halt(usb_dev_handle dev, int ep); 52 | 53 | int usb_reset(usb_dev_handle dev); 54 | 55 | /** 56 | * int usb_claim_interface(usb_dev_handle *dev, int interface); 57 | * 58 | * @param usb_dev_handle 59 | * @param interf 60 | * @return 61 | */ 62 | int usb_claim_interface(usb_dev_handle dev, int interf); 63 | 64 | int usb_release_interface(usb_dev_handle dev, int interf); 65 | 66 | /* Control operations. */ 67 | int usb_control_msg(usb_dev_handle dev, int requesttype, int request, 68 | int value, int index, byte[] bytes, int size, int timeout); 69 | 70 | int usb_control_msg(usb_dev_handle dev, int requesttype, int request, 71 | int value, int index, Buffer bytes, int size, int timeout); 72 | 73 | int usb_get_string(usb_dev_handle dev, int index, int langid, byte[] buf, 74 | int buflen); 75 | 76 | int usb_get_string(usb_dev_handle dev, int index, int langid, Buffer buf, 77 | int buflen); 78 | 79 | int usb_get_string_simple(usb_dev_handle dev, int index, byte[] buf, 80 | int buflen); 81 | 82 | int usb_get_string_simple(usb_dev_handle dev, int index, Buffer buf, 83 | int buflen); 84 | 85 | int usb_get_descriptor(usb_dev_handle udev, byte type, byte index, 86 | byte[] buf, int size); 87 | 88 | int usb_get_descriptor(usb_dev_handle udev, byte type, byte index, 89 | Buffer buf, int size); 90 | 91 | int usb_get_descriptor_by_endpoint(usb_dev_handle udev, int ep, byte type, 92 | byte index, byte[] buf, int size); 93 | 94 | int usb_get_descriptor_by_endpoint(usb_dev_handle udev, int ep, byte type, 95 | byte index, Buffer buf, int size); 96 | 97 | /* Bulk operations. */ 98 | int usb_bulk_write(usb_dev_handle dev, int ep, byte[] bytes, int size, 99 | int timeout); 100 | 101 | int usb_bulk_write(usb_dev_handle dev, int ep, Buffer bytes, int size, 102 | int timeout); 103 | 104 | int usb_bulk_read(usb_dev_handle dev, int ep, byte[] bytes, int size, 105 | int timeout); 106 | 107 | int usb_bulk_read(usb_dev_handle dev, int ep, Buffer bytes, int size, 108 | int timeout); 109 | 110 | /* Interrupt operations. */ 111 | /** 112 | * int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int 113 | * size, int timeout); 114 | */ 115 | int usb_interrupt_write(usb_dev_handle dev, int ep, Buffer bytes, int size, 116 | int timeout); 117 | 118 | int usb_interrupt_write(usb_dev_handle dev, int ep, byte[] bytes, int size, 119 | int timeout); 120 | 121 | int usb_interrupt_read(usb_dev_handle dev, int ep, Buffer bytes, int size, 122 | int timeout); 123 | 124 | int usb_interrupt_read(usb_dev_handle dev, int ep, byte[] bytes, int size, 125 | int timeout); 126 | 127 | /* Non portable */ 128 | /** 129 | * @throws UnsatisfiedLinkError 130 | * if this function does not exist on the running platform. 131 | */ 132 | int usb_get_driver_np(usb_dev_handle dev, int interf, Buffer name, 133 | int namelen); 134 | 135 | int usb_get_driver_np(usb_dev_handle dev, int interf, byte[] name, 136 | int namelen); 137 | 138 | /** 139 | * @throws UnsatisfiedLinkError 140 | * if this function does not exist on the running platform. 141 | */ 142 | int usb_detach_kernel_driver_np(usb_dev_handle dev, int interf); 143 | 144 | /* Uncategorised operations. */ 145 | void usb_set_debug(int level); 146 | 147 | /* 148 | * Check if the returned string need to be freed. If so, then use Pointer 149 | * instead. 150 | */ 151 | String usb_strerror(); 152 | 153 | usb_device usb_device(usb_dev_handle dev); 154 | } 155 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/LibUSBConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.beblue.jna.usb; 6 | 7 | /** 8 | * 9 | * @author marcopar 10 | */ 11 | public class LibUSBConstants { 12 | 13 | public static int PATH_MAX = 4096; 14 | 15 | static { 16 | if (System.getProperty("os.name").toLowerCase().contains("linux")) { 17 | PATH_MAX = 4096; 18 | } else if (System.getProperty("os.name").toLowerCase().contains("windows")) { 19 | PATH_MAX = 256; 20 | } else if (System.getProperty("os.name").toLowerCase().contains("mac")) { 21 | PATH_MAX = 1024; 22 | } else { 23 | PATH_MAX = 4096; 24 | } 25 | } 26 | /* 27 | * Device and/or Interface Class codes 28 | */ 29 | byte USB_CLASS_PER_INTERFACE = 0; 30 | /* for DeviceClass */ 31 | byte USB_CLASS_AUDIO = 1; 32 | byte USB_CLASS_COMM = 2; 33 | byte USB_CLASS_HID = 3; 34 | byte USB_CLASS_PRINTER = 7; 35 | byte USB_CLASS_PTP = 6; 36 | byte USB_CLASS_MASS_STORAGE = 8; 37 | byte USB_CLASS_HUB = 9; 38 | byte USB_CLASS_DATA = 10; 39 | byte USB_CLASS_VENDOR_SPEC = (byte)0xff; 40 | /* 41 | * Descriptor types 42 | */ 43 | byte USB_DT_DEVICE = 0x01; 44 | byte USB_DT_CONFIG = 0x02; 45 | byte USB_DT_STRING = 0x03; 46 | byte USB_DT_INTERFACE = 0x04; 47 | byte USB_DT_ENDPOINT = 0x05; 48 | byte USB_DT_HID = 0x21; 49 | byte USB_DT_REPORT = 0x22; 50 | byte USB_DT_PHYSICAL = 0x23; 51 | byte USB_DT_HUB = 0x29; 52 | /* 53 | * Descriptor sizes per descriptor type 54 | */ 55 | byte USB_DT_DEVICE_SIZE = 18; 56 | byte USB_DT_CONFIG_SIZE = 9; 57 | byte USB_DT_INTERFACE_SIZE = 9; 58 | byte USB_DT_ENDPOINT_SIZE = 7; 59 | byte USB_DT_ENDPOINT_AUDIO_SIZE = 9; 60 | /* Audio extension */ 61 | byte USB_DT_HUB_NONVAR_SIZE = 7; 62 | byte USB_MAXENDPOINTS = 32; 63 | byte USB_ENDPOINT_ADDRESS_MASK = 0x0f; 64 | /* in bEndpointAddress */ 65 | byte USB_ENDPOINT_DIR_MASK = (byte)0x80; 66 | byte USB_ENDPOINT_TYPE_MASK = 0x03; 67 | /* in bmAttributes */ 68 | byte USB_ENDPOINT_TYPE_CONTROL = 0; 69 | byte USB_ENDPOINT_TYPE_ISOCHRONOUS = 1; 70 | byte USB_ENDPOINT_TYPE_BULK = 2; 71 | byte USB_ENDPOINT_TYPE_INTERRUPT = 3; 72 | /* Interface descriptor */ 73 | byte USB_MAXINTERFACES = 32; 74 | byte USB_MAXALTSETTING = (byte)128; /* Hard limit */ 75 | 76 | byte USB_MAXCONFIG = 8; 77 | /* 78 | * Standard requests 79 | */ 80 | byte USB_REQ_GET_STATUS = 0x00; 81 | byte USB_REQ_CLEAR_FEATURE = 0x01; 82 | /* 0x02 is reserved */ 83 | byte USB_REQ_SET_FEATURE = 0x03; 84 | /* 0x04 is reserved */ 85 | byte USB_REQ_SET_ADDRESS = 0x05; 86 | byte USB_REQ_GET_DESCRIPTOR = 0x06; 87 | byte USB_REQ_SET_DESCRIPTOR = 0x07; 88 | byte USB_REQ_GET_CONFIGURATION = 0x08; 89 | byte USB_REQ_SET_CONFIGURATION = 0x09; 90 | byte USB_REQ_GET_INTERFACE = 0x0A; 91 | byte USB_REQ_SET_INTERFACE = 0x0B; 92 | byte USB_REQ_SYNCH_FRAME = 0x0C; 93 | byte USB_TYPE_STANDARD = (0x00 << 5); 94 | byte USB_TYPE_CLASS = (0x01 << 5); 95 | byte USB_TYPE_VENDOR = (0x02 << 5); 96 | byte USB_TYPE_RESERVED = (0x03 << 5); 97 | byte USB_RECIP_DEVICE = 0x00; 98 | byte USB_RECIP_INTERFACE = 0x01; 99 | byte USB_RECIP_ENDPOINT = 0x02; 100 | byte USB_RECIP_OTHER = 0x03; 101 | /* 102 | * Various libusb API related stuff 103 | */ 104 | byte USB_ENDPOINT_IN = (byte)0x80; 105 | byte USB_ENDPOINT_OUT = 0x00; 106 | /* Error codes */ 107 | int USB_ERROR_BEGIN = 500000; 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/devtools/UsbStructInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb.devtools; 20 | 21 | import org.beblue.jna.usb.usb_bus; 22 | import org.beblue.jna.usb.usb_config_descriptor; 23 | import org.beblue.jna.usb.usb_dev_handle; 24 | import org.beblue.jna.usb.usb_device; 25 | import org.beblue.jna.usb.usb_device_descriptor; 26 | import org.beblue.jna.usb.usb_endpoint_descriptor; 27 | import org.beblue.jna.usb.usb_interface; 28 | import org.beblue.jna.usb.usb_interface_descriptor; 29 | 30 | /** 31 | * Prints detailed information about all usb structures. 32 | * 33 | * @author Mario Boikov 34 | * 35 | */ 36 | public class UsbStructInfo { 37 | 38 | public static void main(String[] args) { 39 | System.out.printf("usb_bus == %s\n", new usb_bus().toString()); 40 | 41 | System.out.printf("usb_cfg_desc == %s\n", new usb_config_descriptor().toString()); 42 | 43 | System.out.printf("usb_dev_handle == %s\n", new usb_dev_handle().toString()); 44 | 45 | System.out.printf("usb_dev_desc == %s\n", new usb_device_descriptor().toString()); 46 | 47 | System.out.printf("usb_device == %s\n", new usb_device().toString()); 48 | 49 | System.out.printf("usb_endpoint_desc == %s\n", 50 | new usb_endpoint_descriptor().toString()); 51 | 52 | System.out.printf("usb_interface_desc == %s\n", 53 | new usb_interface_descriptor().toString()); 54 | 55 | System.out.printf("usb_interface == %s\n", new usb_interface().toString()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_bus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Structure; 22 | import com.sun.jna.Pointer; 23 | 24 | /** 25 | * This class represents the native structure struct usb_bus. 26 | * 27 | * @author Mario Boikov 28 | * 29 | */ 30 | public class usb_bus extends Structure { 31 | 32 | public static class ByReference extends usb_bus implements 33 | Structure.ByReference { 34 | // public ByReference() { 35 | // super(); 36 | // } 37 | } 38 | // public usb_bus() { 39 | // super(); 40 | // } 41 | // 42 | // public usb_bus(Pointer p) { 43 | // super(); 44 | // useMemory(p); 45 | // read(); 46 | // } 47 | /** 48 | * struct usb_bus *next; 49 | */ 50 | public usb_bus.ByReference next; 51 | /** 52 | * struct usb_bus *prev; 53 | */ 54 | public usb_bus.ByReference prev; 55 | /** 56 | * char dirname[PATH_MAX + 1]; 57 | */ 58 | public byte[] dirname = new byte[LibUSBConstants.PATH_MAX + 1]; 59 | /** 60 | * struct usb_device *devices; 61 | */ 62 | public usb_device.ByReference devices; 63 | /** 64 | * uint32_t location; 65 | */ 66 | public int location; 67 | /** 68 | * struct usb_device *root_dev; 69 | */ 70 | public usb_device.ByReference root_dev; 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_config_descriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Structure; 22 | import com.sun.jna.ptr.ByteByReference; 23 | 24 | /** 25 | * This class represents the native structure 26 | * struct usb_config_descriptor. 27 | * 28 | * @author Mario Boikov 29 | * 30 | */ 31 | public class usb_config_descriptor extends Structure { 32 | 33 | public static class ByReference extends usb_config_descriptor implements 34 | Structure.ByReference { 35 | } 36 | /** 37 | * uint8_t bLength; 38 | */ 39 | public byte bLength; 40 | /** 41 | * uint8_t bDescriptorType; 42 | */ 43 | public byte bDescriptorType; 44 | /** 45 | * uint16_t wTotalLength; 46 | */ 47 | public short wTotalLength; 48 | /** 49 | * uint8_t bNumInterfaces; 50 | */ 51 | public byte bNumInterfaces; 52 | /** 53 | * uint8_t bConfigurationValue; 54 | */ 55 | public byte bConfigurationValue; 56 | /** 57 | * uint8_t iConfiguration; 58 | */ 59 | public byte iConfiguration; 60 | /** 61 | * uint8_t bmAttributes; 62 | */ 63 | public byte bmAttributes; 64 | /** 65 | * uint8_t MaxPower; 66 | */ 67 | public byte MaxPower; 68 | /** 69 | * struct usb_interface *interface; 70 | */ 71 | public usb_interface.ByReference interf; 72 | /** 73 | * unsigned char *extra; 74 | */ 75 | public ByteByReference extra; 76 | /** 77 | * int extralen; 78 | */ 79 | public int extralen; 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_dev_handle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.PointerType; 22 | 23 | /** 24 | * This class represents the native structure struct usb_dev_handle 25 | * . 26 | * 27 | * @author Mario Boikov 28 | * 29 | */ 30 | public class usb_dev_handle extends PointerType { 31 | // This seems to be a private structure in the native library. 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_device.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Pointer; 22 | import com.sun.jna.Structure; 23 | import com.sun.jna.ptr.PointerByReference; 24 | 25 | /** 26 | * This class represents the native structure struct usb_device. 27 | * 28 | * @author Mario Boikov 29 | * 30 | */ 31 | public class usb_device extends Structure { 32 | 33 | public static class ByReference extends usb_device implements 34 | Structure.ByReference { 35 | } 36 | /** 37 | * struct usb_device *next; 38 | */ 39 | public usb_device.ByReference next; 40 | /** 41 | * struct usb_device *prev; 42 | */ 43 | public usb_device.ByReference prev; 44 | /** 45 | * char filename[PATH_MAX + 1]; 46 | */ 47 | public byte[] filename = new byte[LibUSBConstants.PATH_MAX + 1]; 48 | /** 49 | * struct usb_bus *bus; 50 | */ 51 | // usb_bus.ByReference did not work, I'm not sure why. 52 | //public Pointer /* usb_bus.ByReference */bus; 53 | public usb_bus.ByReference bus; 54 | /** 55 | * struct usb_device_descriptor descriptor; 56 | */ 57 | public usb_device_descriptor descriptor; 58 | /** 59 | * struct usb_config_descriptor *config; 60 | */ 61 | public usb_config_descriptor.ByReference config; 62 | /** 63 | * void *dev; Darwin support 64 | */ 65 | public Pointer dev; 66 | /** 67 | * uint8_t devnum; 68 | */ 69 | public byte devnum; 70 | /** 71 | * unsigned char num_children; 72 | */ 73 | public byte num_children; 74 | /** 75 | * struct usb_device **children; 76 | */ 77 | public PointerByReference children; 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_device_descriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Structure; 22 | 23 | /** 24 | * This class represents the native structure usb_device_descriptor 25 | * . 26 | * 27 | * @author Mario Boikov 28 | * 29 | */ 30 | public class usb_device_descriptor extends Structure { 31 | 32 | /** 33 | * uint8_t bLength; 34 | */ 35 | public byte bLength; 36 | /** 37 | * uint8_t bDescriptorType; 38 | */ 39 | public byte bDescriptorType; 40 | /** 41 | * uint16_t bcdUSB; 42 | */ 43 | public short bcdUSB; 44 | /** 45 | * uint8_t bDeviceClass; 46 | */ 47 | public byte bDeviceClass; 48 | /** 49 | * uint8_t bDeviceSubClass; 50 | */ 51 | public byte bDeviceSubClass; 52 | /** 53 | * uint8_t bDeviceProtocol; 54 | */ 55 | public byte bDeviceProtocol; 56 | /** 57 | * uint8_t bMaxPacketSize0; 58 | */ 59 | public byte bMaxPacketSize0; 60 | /** 61 | * uint16_t idVendor; 62 | */ 63 | public short idVendor; 64 | /** 65 | * uint16_t idProduct; 66 | */ 67 | public short idProduct; 68 | /** 69 | * uint16_t bcdDevice; 70 | */ 71 | public short bcdDevice; 72 | /** 73 | * uint8_t iManufacturer; 74 | */ 75 | public byte iManufacturer; 76 | /** 77 | * uint8_t iProduct; 78 | */ 79 | public byte iProduct; 80 | /** 81 | * uint8_t iSerialNumber; 82 | */ 83 | public byte iSerialNumber; 84 | /** 85 | * uint8_t bNumConfigurations; 86 | */ 87 | public byte bNumConfigurations; 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_endpoint_descriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Pointer; 22 | import com.sun.jna.Structure; 23 | import com.sun.jna.ptr.ByteByReference; 24 | 25 | /** 26 | * This class represents the native structure 27 | * struct usb_endpoint_descriptor. 28 | * 29 | * @author Mario Boikov 30 | * 31 | */ 32 | public class usb_endpoint_descriptor extends Structure { 33 | 34 | public static class ByReference extends usb_endpoint_descriptor implements 35 | Structure.ByReference { 36 | } 37 | /** 38 | * uint8_t bLength; 39 | */ 40 | public byte bLength; 41 | /** 42 | * uint8_t bDescriptorType; 43 | */ 44 | public byte bDescriptorType; 45 | /** 46 | * uint8_t bEndpointAddress; 47 | */ 48 | public byte bEndpointAddress; 49 | /** 50 | * uint8_t bmAttributes; 51 | */ 52 | public byte bmAttributes; 53 | /** 54 | * uint16_t wMaxPacketSize; 55 | */ 56 | public short wMaxPacketSize; 57 | /** 58 | * uint8_t bInterval; 59 | */ 60 | public byte bInterval; 61 | /** 62 | * uint8_t bRefresh; 63 | */ 64 | public byte bRefresh; 65 | /** 66 | * uint8_t bSynchAddress; 67 | */ 68 | public byte bSynchAddress; 69 | /** 70 | * unsigned char *extra; 71 | */ 72 | public ByteByReference extra; 73 | /** 74 | * int extralen; 75 | */ 76 | public int extralen; 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_interface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Structure; 22 | 23 | /** 24 | * This class represents the native structure struct usb_interface. 25 | * 26 | * @author Mario Boikov 27 | * 28 | */ 29 | public class usb_interface extends Structure { 30 | 31 | public static class ByReference extends usb_interface implements 32 | Structure.ByReference { 33 | } 34 | /** 35 | * struct usb_interface_descriptor *altsetting; 36 | */ 37 | public usb_interface_descriptor.ByReference altsetting; 38 | /** 39 | * int num_altsetting; 40 | */ 41 | public int num_altsetting; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/beblue/jna/usb/usb_interface_descriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libusb4j - libusb for java using JNA. 3 | * Copyright (C) 2008 Mario Boikov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library 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 GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | package org.beblue.jna.usb; 20 | 21 | import com.sun.jna.Pointer; 22 | import com.sun.jna.Structure; 23 | import com.sun.jna.ptr.ByteByReference; 24 | 25 | /** 26 | * This class represents the native structure 27 | * struct usb_interface_descriptor. 28 | * 29 | * @author Mario Boikov 30 | * 31 | */ 32 | public class usb_interface_descriptor extends Structure { 33 | 34 | public static class ByReference extends usb_interface_descriptor implements 35 | Structure.ByReference { 36 | } 37 | /** 38 | * uint8_t bLength; 39 | */ 40 | public byte bLength; 41 | /** 42 | * uint8_t bDescriptorType; 43 | */ 44 | public byte bDescriptorType; 45 | /** 46 | * uint8_t bInterfaceNumber; 47 | */ 48 | public byte bInterfaceNumber; 49 | /** 50 | * uint8_t bAlternateSetting; 51 | */ 52 | public byte bAlternateSetting; 53 | /** 54 | * uint8_t bNumEndpoints; 55 | */ 56 | public byte bNumEndpoints; 57 | /** 58 | * uint8_t bInterfaceClass; 59 | */ 60 | public byte bInterfaceClass; 61 | /** 62 | * uint8_t bInterfaceSubClass; 63 | */ 64 | public byte bInterfaceSubClass; 65 | /** 66 | * uint8_t bInterfaceProtocol; 67 | */ 68 | public byte bInterfaceProtocol; 69 | /** 70 | * uint8_t iInterface; 71 | */ 72 | public byte iInterface; 73 | /** 74 | * struct usb_endpoint_descriptor *endpoint; 75 | */ 76 | public usb_endpoint_descriptor.ByReference endpoint; 77 | /** 78 | * unsigned char *extra; 79 | */ 80 | public ByteByReference extra; 81 | /** 82 | * int extralen; 83 | */ 84 | public int extralen; 85 | } 86 | --------------------------------------------------------------------------------