Start point

This commit is contained in:
2025-02-19 16:17:08 +01:00
commit 8bc6932e36
223 changed files with 63668 additions and 0 deletions

152
lib/libusb/android/README Normal file
View File

@@ -0,0 +1,152 @@
libusb for Android
==================
Building:
---------
To build libusb for Android do the following:
1. Download the latest NDK from:
http://developer.android.com/tools/sdk/ndk/index.html
2. Extract the NDK.
3. Open a shell and make sure there exist an NDK global variable
set to the directory where you extracted the NDK.
4. Change directory to libusb's "android/jni"
5. Run "$NDK/ndk-build".
The libusb library, examples and tests can then be found in:
"android/libs/$ARCH"
Where $ARCH is one of:
armeabi
armeabi-v7a
mips
mips64
x86
x86_64
Installing:
-----------
If you wish to use libusb from native code in own Android application
then you should add the following line to your Android.mk file:
include $(PATH_TO_LIBUSB_SRC)/android/jni/libusb.mk
You will then need to add the following lines to the build
configuration for each native binary which uses libusb:
LOCAL_C_INCLUDES += $(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
The Android build system will then correctly include libusb in the
application package (APK) file, provided ndk-build is invoked before
the package is built.
Runtime Permissions:
--------------------
The Runtime Permissions on Android can be transferred from Java to Native
over the following approach:
JAVA:
--> Obtain USB permissions over the android.hardware.usb.UsbManager class
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
for (UsbDevice usbDevice : deviceList.values()) {
usbManager.requestPermission(usbDevice, mPermissionIntent);
}
--> Get the native FileDescriptor of the UsbDevice and transfer it to
Native over JNI or JNA
UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(camDevice);
int fileDescriptor = usbDeviceConnection.getFileDescriptor();
--> JNA sample method:
JNA.INSTANCE.set_the_native_Descriptor(fileDescriptor);
NATIVE:
--> Initialize libusb on Android
set_the_native_Descriptor(int fileDescriptor) {
libusb_context *ctx;
libusb_device_handle *devh;
libusb_set_option(&ctx, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
libusb_init(&ctx);
libusb_wrap_sys_device(NULL, (intptr_t)fileDescriptor, &devh);
}
/* From this point you can regularly use all libusb functions as usual */
About LIBUSB_OPTION_NO_DEVICE_DISCOVERY:
The method libusb_set_option(&ctx, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL)
does not affect the ctx.
It allows initializing libusb on unrooted Android devices by skipping
the device enumeration.
Rooted Devices:
---------------
For rooted devices the code using libusb could be executed as root
using the "su" command. An alternative would be to use the "su" command
to change the permissions on the appropriate /dev/bus/usb/ files.
Users have reported success in using android.hardware.usb.UsbManager
to request permission to use the UsbDevice and then opening the
device. The difficulties in this method is that there is no guarantee
that it will continue to work in the future Android versions, it
requires invoking Java APIs and running code to match each
android.hardware.usb.UsbDevice to a libusb_device.
For a rooted device it is possible to install libusb into the system
image of a running device:
1. Enable ADB on the device.
2. Connect the device to a machine running ADB.
3. Execute the following commands on the machine
running ADB:
# Make the system partition writable
adb shell su -c "mount -o remount,rw /system"
# Install libusb
adb push obj/local/armeabi/libusb1.0.so /sdcard/
adb shell su -c "cat > /system/lib/libusb1.0.so < /sdcard/libusb1.0.so"
adb shell rm /sdcard/libusb1.0.so
# Install the samples and tests
for B in listdevs fxload xusb sam3u_benchmark hotplugtest stress
do
adb push "obj/local/armeabi/$B" /sdcard/
adb shell su -c "cat > /system/bin/$B < /sdcard/$B"
adb shell su -c "chmod 0755 /system/bin/$B"
adb shell rm "/sdcard/$B"
done
# Make the system partition read only again
adb shell su -c "mount -o remount,ro /system"
# Run listdevs to
adb shell su -c "listdevs"
4. If your device only has a single OTG port then ADB can generally
be switched to using Wifi with the following commands when connected
via USB:
adb shell netcfg
# Note the wifi IP address of the phone
adb tcpip 5555
# Use the IP address from netcfg
adb connect 192.168.1.123:5555

View File

@@ -0,0 +1,55 @@
/*
* Android build config for libusb
* Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Define to the attribute for default visibility. */
#define DEFAULT_VISIBILITY __attribute__ ((visibility ("default")))
/* Define to 1 to start with debug message logging enabled. */
/* #undef ENABLE_DEBUG_LOGGING */
/* Define to 1 to enable message logging. */
#define ENABLE_LOGGING 1
/* Define to 1 if you have the <asm/types.h> header file. */
#define HAVE_ASM_TYPES_H 1
/* Define to 1 if you have the `clock_gettime' function. */
#define HAVE_CLOCK_GETTIME 1
/* Define to 1 if the system has the type `nfds_t'. */
#define HAVE_NFDS_T 1
/* Define to 1 if you have the `pipe2' function. */
#define HAVE_PIPE2 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if compiling for a POSIX platform. */
#define PLATFORM_POSIX 1
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) __attribute__ ((__format__ (__printf__, a, b)))
/* Define to 1 to output logging messages to the systemwide log. */
#define USE_SYSTEM_LOGGING_FACILITY 1
/* Enable GNU extensions. */
#define _GNU_SOURCE 1

View File

@@ -0,0 +1,301 @@
/*
* libusb example program for reading out USB descriptors on unrooted Android
* (based on testlibusb.c)
*
* Copyright 2020-2021 Peter Stoiber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Please contact the author if you need another license.
* This Repository is provided "as is", without warranties of any kind.
*/
/*
* This example creates a shared object which can be accessed over JNA or JNI from Java or Kotlin in Android.
* Hint: If you are using Android Studio, set the "Debug type" to "Java Only" to receive debug messages.
*/
/*
* Usage:
* First, you have to connect your USB device from the Java side.
* Use the android.hardware.usb class to find the USB device, claim the interfaces, and open the usb_device_connection
* Obtain the native File Descriptor --> usb_device_connection.getFileDescriptor()
* Pass the received int value to the unrooted_usb_description method of this code (over JNA)
*/
/*
* libusb can only be included in Android projects using NDK for now. (CMake is not supported at the moment)
* Clone the libusb git repo into your Android project and include the Android.mk file in your build.gradle.
*/
/*
Example JNA Approach:
public interface unrooted_sample extends Library {
public static final unrooted_sample INSTANCE = Native.load("unrooted_android", unrooted_sample.class);
public int unrooted_usb_description (int fileDescriptor);
}
unrooted_sample.INSTANCE.unrooted_usb_description( usbDeviceConnection.getFileDescriptor());
*/
#include <jni.h>
#include <string.h>
#include "unrooted_android.h"
#include "libusb.h"
#include <android/log.h>
#define LOG_TAG "LibUsb"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
int verbose = 0;
static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
{
LOGD(" USB 3.0 Endpoint Companion:\n");
LOGD(" bMaxBurst: %u\n", ep_comp->bMaxBurst);
LOGD(" bmAttributes: %02xh\n", ep_comp->bmAttributes);
LOGD(" wBytesPerInterval: %u\n", ep_comp->wBytesPerInterval);
}
static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
{
int i, ret;
LOGD(" Endpoint:\n");
LOGD(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
LOGD(" bmAttributes: %02xh\n", endpoint->bmAttributes);
LOGD(" wMaxPacketSize: %u\n", endpoint->wMaxPacketSize);
LOGD(" bInterval: %u\n", endpoint->bInterval);
LOGD(" bRefresh: %u\n", endpoint->bRefresh);
LOGD(" bSynchAddress: %u\n", endpoint->bSynchAddress);
for (i = 0; i < endpoint->extra_length;) {
if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {
struct libusb_ss_endpoint_companion_descriptor *ep_comp;
ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);
if (LIBUSB_SUCCESS != ret)
continue;
print_endpoint_comp(ep_comp);
libusb_free_ss_endpoint_companion_descriptor(ep_comp);
}
i += endpoint->extra[i];
}
}
static void print_altsetting(const struct libusb_interface_descriptor *interface)
{
uint8_t i;
LOGD(" Interface:\n");
LOGD(" bInterfaceNumber: %u\n", interface->bInterfaceNumber);
LOGD(" bAlternateSetting: %u\n", interface->bAlternateSetting);
LOGD(" bNumEndpoints: %u\n", interface->bNumEndpoints);
LOGD(" bInterfaceClass: %u\n", interface->bInterfaceClass);
LOGD(" bInterfaceSubClass: %u\n", interface->bInterfaceSubClass);
LOGD(" bInterfaceProtocol: %u\n", interface->bInterfaceProtocol);
LOGD(" iInterface: %u\n", interface->iInterface);
for (i = 0; i < interface->bNumEndpoints; i++)
print_endpoint(&interface->endpoint[i]);
}
static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
{
LOGD(" USB 2.0 Extension Capabilities:\n");
LOGD(" bDevCapabilityType: %u\n", usb_2_0_ext_cap->bDevCapabilityType);
LOGD(" bmAttributes: %08xh\n", usb_2_0_ext_cap->bmAttributes);
}
static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
{
LOGD(" USB 3.0 Capabilities:\n");
LOGD(" bDevCapabilityType: %u\n", ss_usb_cap->bDevCapabilityType);
LOGD(" bmAttributes: %02xh\n", ss_usb_cap->bmAttributes);
LOGD(" wSpeedSupported: %u\n", ss_usb_cap->wSpeedSupported);
LOGD(" bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport);
LOGD(" bU1devExitLat: %u\n", ss_usb_cap->bU1DevExitLat);
LOGD(" bU2devExitLat: %u\n", ss_usb_cap->bU2DevExitLat);
}
static void print_bos(libusb_device_handle *handle)
{
struct libusb_bos_descriptor *bos;
uint8_t i;
int ret;
ret = libusb_get_bos_descriptor(handle, &bos);
if (ret < 0)
return;
LOGD(" Binary Object Store (BOS):\n");
LOGD(" wTotalLength: %u\n", bos->wTotalLength);
LOGD(" bNumDeviceCaps: %u\n", bos->bNumDeviceCaps);
for (i = 0; i < bos->bNumDeviceCaps; i++) {
struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i];
if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension);
if (ret < 0)
return;
print_2_0_ext_cap(usb_2_0_extension);
libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
} else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap;
ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap);
if (ret < 0)
return;
print_ss_usb_cap(ss_dev_cap);
libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap);
}
}
libusb_free_bos_descriptor(bos);
}
static void print_interface(const struct libusb_interface *interface)
{
int i;
for (i = 0; i < interface->num_altsetting; i++)
print_altsetting(&interface->altsetting[i]);
}
static void print_configuration(struct libusb_config_descriptor *config)
{
uint8_t i;
LOGD(" Configuration:\n");
LOGD(" wTotalLength: %u\n", config->wTotalLength);
LOGD(" bNumInterfaces: %u\n", config->bNumInterfaces);
LOGD(" bConfigurationValue: %u\n", config->bConfigurationValue);
LOGD(" iConfiguration: %u\n", config->iConfiguration);
LOGD(" bmAttributes: %02xh\n", config->bmAttributes);
LOGD(" MaxPower: %u\n", config->MaxPower);
for (i = 0; i < config->bNumInterfaces; i++)
print_interface(&config->interface[i]);
}
static void print_device(libusb_device *dev, libusb_device_handle *handle)
{
struct libusb_device_descriptor desc;
unsigned char string[256];
const char *speed;
int ret;
uint8_t i;
switch (libusb_get_device_speed(dev)) {
case LIBUSB_SPEED_LOW: speed = "1.5M"; break;
case LIBUSB_SPEED_FULL: speed = "12M"; break;
case LIBUSB_SPEED_HIGH: speed = "480M"; break;
case LIBUSB_SPEED_SUPER: speed = "5G"; break;
case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
case LIBUSB_SPEED_SUPER_PLUS_X2: speed = "20G"; break;
default: speed = "Unknown";
}
ret = libusb_get_device_descriptor(dev, &desc);
if (ret < 0) {
LOGD("failed to get device descriptor");
return;
}
LOGD("Dev (bus %u, device %u): %04X - %04X speed: %s\n",
libusb_get_bus_number(dev), libusb_get_device_address(dev),
desc.idVendor, desc.idProduct, speed);
if (!handle)
libusb_open(dev, &handle);
if (handle) {
if (desc.iManufacturer) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
if (ret > 0)
LOGD(" Manufacturer: %s\n", (char *)string);
}
if (desc.iProduct) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
if (ret > 0)
LOGD(" Product: %s\n", (char *)string);
}
if (desc.iSerialNumber && verbose) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
if (ret > 0)
LOGD(" Serial Number: %s\n", (char *)string);
}
}
if (verbose) {
for (i = 0; i < desc.bNumConfigurations; i++) {
struct libusb_config_descriptor *config;
ret = libusb_get_config_descriptor(dev, i, &config);
if (LIBUSB_SUCCESS != ret) {
LOGD(" Couldn't retrieve descriptors\n");
continue;
}
print_configuration(config);
libusb_free_config_descriptor(config);
}
if (handle && desc.bcdUSB >= 0x0201)
print_bos(handle);
}
if (handle)
libusb_close(handle);
}
/* fileDescriptor = the native file descriptor obtained in Java and transferred to native over JNA, for example */
int unrooted_usb_description(int fileDescriptor)
{
libusb_context *ctx = NULL;
libusb_device_handle *devh = NULL;
int r = 0;
verbose = 1;
r = libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
if (r != LIBUSB_SUCCESS) {
LOGD("libusb_set_option failed: %d\n", r);
return -1;
}
r = libusb_init(&ctx);
if (r < 0) {
LOGD("libusb_init failed: %d\n", r);
return r;
}
r = libusb_wrap_sys_device(ctx, (intptr_t)fileDescriptor, &devh);
if (r < 0) {
LOGD("libusb_wrap_sys_device failed: %d\n", r);
return r;
} else if (devh == NULL) {
LOGD("libusb_wrap_sys_device returned invalid handle\n");
return r;
}
print_device(libusb_get_device(devh), devh);
return r;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2021 Peter Stoiber
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Please contact the author if you need another license.
* This Repository is provided "as is", without warranties of any kind.
*/
#ifndef unrooted_android_H
#define unrooted_android_H
#ifdef __cplusplus
extern "C" {
#endif
extern int unrooted_usb_description(int fileDescriptor);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,23 @@
# Android build config for libusb, examples and tests
# Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/libusb.mk
include $(LOCAL_PATH)/examples.mk
include $(LOCAL_PATH)/tests.mk

View File

@@ -0,0 +1,40 @@
# Android application build config for libusb
# Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
APP_ABI := all
APP_CFLAGS := \
-std=gnu11 \
-Wall \
-Wextra \
-Wshadow \
-Wunused \
-Wwrite-strings \
-Werror=format-security \
-Werror=implicit-function-declaration \
-Werror=implicit-int \
-Werror=init-self \
-Werror=missing-prototypes \
-Werror=strict-prototypes \
-Werror=undef \
-Werror=uninitialized
# Workaround for MIPS toolchain linker being unable to find liblog dependency
# of shared object in NDK versions at least up to r9.
#
APP_LDFLAGS := -llog

View File

@@ -0,0 +1,168 @@
# Android build config for libusb examples
# Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH := $(call my-dir)
LIBUSB_ROOT_REL := ../..
LIBUSB_ROOT_ABS := $(LOCAL_PATH)/../..
ifeq ($(USE_PC_NAME),1)
LIBUSB_MODULE := usb-1.0
else
LIBUSB_MODULE := libusb1.0
endif
# dpfp
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/dpfp.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := dpfp
include $(BUILD_EXECUTABLE)
# dpfp_threaded
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/dpfp.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_CFLAGS := -DDPFP_THREADED -pthread
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := dpfp_threaded
include $(BUILD_EXECUTABLE)
# fxload
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/ezusb.c \
$(LIBUSB_ROOT_REL)/examples/fxload.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := fxload
include $(BUILD_EXECUTABLE)
# hotplugtest
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/hotplugtest.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := hotplugtest
include $(BUILD_EXECUTABLE)
# listdevs
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/listdevs.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := listdevs
include $(BUILD_EXECUTABLE)
# sam3u_benchmark
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/sam3u_benchmark.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := sam3u_benchmark
include $(BUILD_EXECUTABLE)
# xusb
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/examples/xusb.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := xusb
include $(BUILD_EXECUTABLE)
# unrooted_android
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/android/examples/unrooted_android.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += libusb1.0
LOCAL_LDLIBS += -llog
LOCAL_MODULE := unrooted_android
include $(BUILD_SHARED_LIBRARY)

View File

@@ -0,0 +1,60 @@
# Android build config for libusb
# Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH := $(call my-dir)
LIBUSB_ROOT_REL := ../..
LIBUSB_ROOT_ABS := $(LOCAL_PATH)/../..
# libusb
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/libusb/core.c \
$(LIBUSB_ROOT_REL)/libusb/descriptor.c \
$(LIBUSB_ROOT_REL)/libusb/hotplug.c \
$(LIBUSB_ROOT_REL)/libusb/io.c \
$(LIBUSB_ROOT_REL)/libusb/sync.c \
$(LIBUSB_ROOT_REL)/libusb/strerror.c \
$(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \
$(LIBUSB_ROOT_REL)/libusb/os/events_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)/libusb \
$(LIBUSB_ROOT_ABS)/libusb/os
LOCAL_EXPORT_C_INCLUDES := \
$(LIBUSB_ROOT_ABS)/libusb
LOCAL_CFLAGS := -fvisibility=hidden -pthread
LOCAL_LDLIBS := -llog
ifeq ($(USE_PC_NAME),1)
LOCAL_MODULE := usb-1.0
else
LOCAL_MODULE := libusb1.0
$(warning Building to legacy library name libusb1.0, which differs from pkg-config.)
$(warning Use ndk-build USE_PC_NAME=1 to change the module name to the compatible usb-1.0.)
$(warning USE_PC_NAME=1 may be the default in the future.)
endif
include $(BUILD_SHARED_LIBRARY)

View File

@@ -0,0 +1,45 @@
# Android build config for libusb tests
# Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
LOCAL_PATH := $(call my-dir)
LIBUSB_ROOT_REL := ../..
LIBUSB_ROOT_ABS := $(LOCAL_PATH)/../..
ifeq ($(USE_PC_NAME),1)
LIBUSB_MODULE := usb-1.0
else
LIBUSB_MODULE := libusb1.0
endif
# stress
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/tests/stress.c \
$(LIBUSB_ROOT_REL)/tests/testlib.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/.. \
$(LIBUSB_ROOT_ABS)
LOCAL_SHARED_LIBRARIES += $(LIBUSB_MODULE)
LOCAL_MODULE := stress
include $(BUILD_EXECUTABLE)