Index: head/devel/android-tools-fastboot/files/usb_freebsd.cpp =================================================================== --- head/devel/android-tools-fastboot/files/usb_freebsd.cpp (revision 512190) +++ head/devel/android-tools-fastboot/files/usb_freebsd.cpp (nonexistent) @@ -1,223 +0,0 @@ -/* - * Copyright (C) 2011 Hans Petter Selasky. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -#include - -#include "usb.h" - -struct usb_handle { - libusb_device_handle *handle; - libusb_device *dev; - unsigned char ep_in; - unsigned char ep_out; - unsigned char iface; -}; - -class LibusbUsbTransport : public UsbTransport { -public: - explicit LibusbUsbTransport(std::unique_ptr handle, uint32_t ms_timeout): - h(std::move(handle)), ms_timeout_(ms_timeout) {} - ~LibusbUsbTransport() override; - - ssize_t Read(void *_data, size_t len) override; - ssize_t Write(const void *_data, size_t len) override; - int Close() override; - int Reset() override; - -private: - std::unique_ptr h; - const uint32_t ms_timeout_; - - DISALLOW_COPY_AND_ASSIGN(LibusbUsbTransport); -}; - -static int -probe(std::unique_ptr &h, ifc_match_func callback) -{ - usb_ifc_info info; - libusb_device_descriptor ddesc; - libusb_config_descriptor *pcfg; - int i, j; - - if (libusb_open(h->dev, &h->handle) < 0) - return (-1); - - if (libusb_get_device_descriptor(h->dev, &ddesc) < 0) { - libusb_close(h->handle); - return (-1); - } - memset(&info, 0, sizeof(info)); - - info.dev_vendor = ddesc.idVendor; - info.dev_product = ddesc.idProduct; - info.dev_class = ddesc.bDeviceClass; - info.dev_subclass = ddesc.bDeviceSubClass; - info.dev_protocol = ddesc.bDeviceProtocol; - info.writable = 1; - - snprintf(info.device_path, sizeof(info.device_path), "usb:%d:%d", - libusb_get_bus_number(h->dev), libusb_get_device_address(h->dev)); - - if (ddesc.iSerialNumber != 0) { - libusb_get_string_descriptor_ascii(h->handle, ddesc.iSerialNumber, - (unsigned char *)info.serial_number, sizeof(info.serial_number)); - } - if (libusb_get_active_config_descriptor(h->dev, &pcfg)) { - libusb_close(h->handle); - return (-1); - } - - for (i = 0; i < pcfg->bNumInterfaces; i++) { - - h->ep_in = 0; - h->ep_out = 0; - h->iface = i; - - for (j = 0; j < pcfg->interface[i].altsetting[0].bNumEndpoints; j++) { - - unsigned char temp = pcfg->interface[i].altsetting[0]. - endpoint[j].bEndpointAddress; - unsigned char type = pcfg->interface[i].altsetting[0]. - endpoint[j].bmAttributes & 0x03; - - /* check for BULK endpoint */ - if ((type & 0x03) == 0x02) { - /* check for IN endpoint */ - if (temp & 0x80) - h->ep_in = temp; - else - h->ep_out = temp; - } - } - - info.ifc_class = pcfg->interface[i].altsetting[0].bInterfaceClass; - info.ifc_subclass = pcfg->interface[i].altsetting[0].bInterfaceSubClass; - info.ifc_protocol = pcfg->interface[i].altsetting[0].bInterfaceProtocol; - info.has_bulk_in = (h->ep_in != 0); - info.has_bulk_out = (h->ep_out != 0); - - if (libusb_claim_interface(h->handle, h->iface) < 0) - continue; - - if (callback(&info) == 0) { - libusb_free_config_descriptor(pcfg); - return (0); - } - libusb_release_interface(h->handle, h->iface); - } - - libusb_free_config_descriptor(pcfg); - libusb_close(h->handle); - return (-1); -} - -static std::unique_ptr -enumerate(ifc_match_func callback) -{ - static libusb_context *ctx = NULL; - std::unique_ptr h; - libusb_device **ppdev; - ssize_t ndev; - ssize_t x; - - if (ctx == NULL) - libusb_init(&ctx); - - ndev = libusb_get_device_list(ctx, &ppdev); - for (x = 0; x < ndev; x++) { - - h.reset(new usb_handle); - - h->dev = ppdev[x]; - - if (probe(h, callback) == 0) { - libusb_ref_device(h->dev); - libusb_free_device_list(ppdev, 1); - return (h); - } - } - h.reset(); - libusb_free_device_list(ppdev, 1); - return (nullptr); -} - -ssize_t -LibusbUsbTransport::Write(const void *_data, size_t len) -{ - int actlen; - - if (libusb_bulk_transfer(h->handle, h->ep_out, - (unsigned char *)_data, len, &actlen, ms_timeout_) < 0) - return (-1); - return (actlen); -} - -ssize_t -LibusbUsbTransport::Read(void *_data, size_t len) -{ - int actlen; - - if (libusb_bulk_transfer(h->handle, h->ep_in, - (unsigned char *)_data, len, &actlen, ms_timeout_) < 0) - return (-1); - return (actlen); -} - -LibusbUsbTransport::~LibusbUsbTransport() -{ - Close(); -} - -int -LibusbUsbTransport::Close() -{ - libusb_close(h->handle); - h->handle = NULL; - libusb_unref_device(h->dev); - h.reset(); - return (0); -} - -int -LibusbUsbTransport::Reset() -{ - if (libusb_reset_device(h->handle)) - return (-1); - return (0); -} - -UsbTransport * -usb_open(ifc_match_func callback, uint32_t timeout_ms) -{ - std::unique_ptr h = enumerate(callback); - return (h ? new LibusbUsbTransport(std::move(h), timeout_ms) : nullptr); -} Property changes on: head/devel/android-tools-fastboot/files/usb_freebsd.cpp ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/android-tools-fastboot/files/Makefile =================================================================== --- head/devel/android-tools-fastboot/files/Makefile (revision 512190) +++ head/devel/android-tools-fastboot/files/Makefile (revision 512191) @@ -1,122 +1,122 @@ # $FreeBSD$ PROG_CXX=fastboot BINDIR?=/usr/bin FILESDIR?=${DOCDIR}/${PROG} FILES= README.md SRCS+= bootimg_utils.cpp SRCS+= fastboot.cpp SRCS+= fastboot_driver.cpp SRCS+= ../fastboot/fs.cpp SRCS+= main.cpp SRCS+= socket.cpp SRCS+= tcp.cpp SRCS+= udp.cpp SRCS+= util.cpp .PATH: ${EXTRADIR} -SRCS+= usb_freebsd.cpp +SRCS+= usb_libusb.cpp # required by fastboot, diagnose_usb and libziparchive .PATH: ${.CURDIR}/../base SRCS+= errors_unix.cpp SRCS+= file.cpp SRCS+= logging.cpp SRCS+= mapped_file.cpp SRCS+= parsenetaddress.cpp SRCS+= stringprintf.cpp SRCS+= strings.cpp SRCS+= threads.cpp # required by fastboot .PATH: ${.CURDIR}/../diagnose_usb SRCS+= diagnose_usb.cpp # required by fs_mgr/liblp .PATH: ${.CURDIR}/../extras/ext4_utils SRCS+= ext4_sb.cpp SRCS+= ext4_utils.cpp # required by fastboot .PATH: ${.CURDIR}/../fs_mgr/liblp SRCS+= images.cpp SRCS+= partition_opener.cpp SRCS+= reader.cpp SRCS+= utility.cpp SRCS+= writer.cpp # required by fastboot .PATH: ${.CURDIR}/../libcutils SRCS+= android_get_control_file.cpp SRCS+= ../libcutils/sockets.cpp SRCS+= socket_inaddr_any_server_unix.cpp SRCS+= socket_network_client_unix.cpp SRCS+= sockets_unix.cpp # DragonFly, NetBSD, OpenBSD CPPFLAGS.sockets.cpp+= -o ${.TARGET} # required by base and libutils .PATH: ${.CURDIR}/../liblog SRCS+= config_read.cpp SRCS+= config_write.cpp SRCS+= fake_log_device.cpp SRCS+= fake_writer.cpp SRCS+= logger_lock.cpp SRCS+= logger_name.cpp SRCS+= logger_write.cpp SRCS+= logprint.cpp SRCS+= stderr_write.cpp # required by fastboot .PATH: ${.CURDIR}/../libsparse SRCS+= backed_block.cpp SRCS+= output_file.cpp SRCS+= sparse.cpp SRCS+= sparse_crc32.cpp SRCS+= sparse_err.cpp SRCS+= sparse_read.cpp # required by fastboot .PATH: ${.CURDIR}/../libziparchive SRCS+= zip_archive.cc CPPFLAGS+= -DPLATFORM_TOOLS_VERSION="\"${VERSION:U0.0.0}\"" CPPFLAGS+= -Doff64_t=off_t CPPFLAGS+= -Dftruncate64=ftruncate CPPFLAGS+= -Dlseek64=lseek CPPFLAGS+= -Dmmap64=mmap CPPFLAGS+= -Dpread64=pread CPPFLAGS+= -DFAKE_LOG_DEVICE=1 CPPFLAGS+= -I${.CURDIR} CPPFLAGS+= -I${.CURDIR}/../include CPPFLAGS+= -I${.CURDIR}/../mkbootimg/include/bootimg CPPFLAGS+= -I${.CURDIR}/../base/include CPPFLAGS+= -I${.CURDIR}/../diagnose_usb/include CPPFLAGS+= -I${.CURDIR}/../extras/ext4_utils/include CPPFLAGS+= -I${.CURDIR}/../fs_mgr/liblp/include CPPFLAGS+= -I${.CURDIR}/../libsparse/include CPPFLAGS+= -I${.CURDIR}/../libziparchive/include CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}} CPPFLAGS+= $$(${PKG_CONFIG} libcrypto --cflags 2>/dev/null) CPPFLAGS+= $$(${PKG_CONFIG} libusb-1.0 --cflags 2>/dev/null) CXXFLAGS+= -D__STDC_LIMIT_MACROS # DragonFly CXXFLAGS+= -std=gnu++17 .ifndef COMPILE.c CFLAGS+= ${CPPFLAGS} CXXFLAGS+= ${CPPFLAGS} .endif LDADD+= $$(${PKG_CONFIG} libcrypto --libs 2>/dev/null || echo -lcrypto) LDADD+= $$(${PKG_CONFIG} libusb-1.0 --libs 2>/dev/null || echo -lusb) LDADD+= -lz \-lpthread DPADD+= ${LIBPTHREAD} ${LIBUSB} ${LIBZ} PKG_CONFIG?= pkg-config beforeinstall: ${INSTALL} -d ${DESTDIR}${FILESDIR} .include Index: head/devel/android-tools-fastboot/files/usb_libusb.cpp =================================================================== --- head/devel/android-tools-fastboot/files/usb_libusb.cpp (nonexistent) +++ head/devel/android-tools-fastboot/files/usb_libusb.cpp (revision 512191) @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2011 Hans Petter Selasky. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include + +#include "usb.h" + +struct usb_handle { + libusb_device_handle *handle; + libusb_device *dev; + unsigned char ep_in; + unsigned char ep_out; + unsigned char iface; +}; + +class LibusbUsbTransport : public UsbTransport { +public: + explicit LibusbUsbTransport(std::unique_ptr handle, uint32_t ms_timeout): + h(std::move(handle)), ms_timeout_(ms_timeout) {} + ~LibusbUsbTransport() override; + + ssize_t Read(void *_data, size_t len) override; + ssize_t Write(const void *_data, size_t len) override; + int Close() override; + int Reset() override; + +private: + std::unique_ptr h; + const uint32_t ms_timeout_; + + DISALLOW_COPY_AND_ASSIGN(LibusbUsbTransport); +}; + +static int +probe(std::unique_ptr &h, ifc_match_func callback) +{ + usb_ifc_info info; + libusb_device_descriptor ddesc; + libusb_config_descriptor *pcfg; + int i, j; + + if (libusb_open(h->dev, &h->handle) < 0) + return (-1); + + if (libusb_get_device_descriptor(h->dev, &ddesc) < 0) { + libusb_close(h->handle); + return (-1); + } + memset(&info, 0, sizeof(info)); + + info.dev_vendor = ddesc.idVendor; + info.dev_product = ddesc.idProduct; + info.dev_class = ddesc.bDeviceClass; + info.dev_subclass = ddesc.bDeviceSubClass; + info.dev_protocol = ddesc.bDeviceProtocol; + info.writable = 1; + + snprintf(info.device_path, sizeof(info.device_path), "usb:%d:%d", + libusb_get_bus_number(h->dev), libusb_get_device_address(h->dev)); + + if (ddesc.iSerialNumber != 0) { + libusb_get_string_descriptor_ascii(h->handle, ddesc.iSerialNumber, + (unsigned char *)info.serial_number, sizeof(info.serial_number)); + } + if (libusb_get_active_config_descriptor(h->dev, &pcfg)) { + libusb_close(h->handle); + return (-1); + } + + for (i = 0; i < pcfg->bNumInterfaces; i++) { + + h->ep_in = 0; + h->ep_out = 0; + h->iface = i; + + for (j = 0; j < pcfg->interface[i].altsetting[0].bNumEndpoints; j++) { + + unsigned char temp = pcfg->interface[i].altsetting[0]. + endpoint[j].bEndpointAddress; + unsigned char type = pcfg->interface[i].altsetting[0]. + endpoint[j].bmAttributes & 0x03; + + /* check for BULK endpoint */ + if ((type & 0x03) == 0x02) { + /* check for IN endpoint */ + if (temp & 0x80) + h->ep_in = temp; + else + h->ep_out = temp; + } + } + + info.ifc_class = pcfg->interface[i].altsetting[0].bInterfaceClass; + info.ifc_subclass = pcfg->interface[i].altsetting[0].bInterfaceSubClass; + info.ifc_protocol = pcfg->interface[i].altsetting[0].bInterfaceProtocol; + info.has_bulk_in = (h->ep_in != 0); + info.has_bulk_out = (h->ep_out != 0); + + if (libusb_claim_interface(h->handle, h->iface) < 0) + continue; + + if (callback(&info) == 0) { + libusb_free_config_descriptor(pcfg); + return (0); + } + libusb_release_interface(h->handle, h->iface); + } + + libusb_free_config_descriptor(pcfg); + libusb_close(h->handle); + return (-1); +} + +static std::unique_ptr +enumerate(ifc_match_func callback) +{ + static libusb_context *ctx = NULL; + std::unique_ptr h; + libusb_device **ppdev; + ssize_t ndev; + ssize_t x; + + if (ctx == NULL) + libusb_init(&ctx); + + ndev = libusb_get_device_list(ctx, &ppdev); + for (x = 0; x < ndev; x++) { + + h.reset(new usb_handle); + + h->dev = ppdev[x]; + + if (probe(h, callback) == 0) { + libusb_ref_device(h->dev); + libusb_free_device_list(ppdev, 1); + return (h); + } + } + h.reset(); + libusb_free_device_list(ppdev, 1); + return (nullptr); +} + +ssize_t +LibusbUsbTransport::Write(const void *_data, size_t len) +{ + int actlen; + + if (libusb_bulk_transfer(h->handle, h->ep_out, + (unsigned char *)_data, len, &actlen, ms_timeout_) < 0) + return (-1); + return (actlen); +} + +ssize_t +LibusbUsbTransport::Read(void *_data, size_t len) +{ + int actlen; + + if (libusb_bulk_transfer(h->handle, h->ep_in, + (unsigned char *)_data, len, &actlen, ms_timeout_) < 0) + return (-1); + return (actlen); +} + +LibusbUsbTransport::~LibusbUsbTransport() +{ + Close(); +} + +int +LibusbUsbTransport::Close() +{ + libusb_close(h->handle); + h->handle = NULL; + libusb_unref_device(h->dev); + h.reset(); + return (0); +} + +int +LibusbUsbTransport::Reset() +{ + if (libusb_reset_device(h->handle)) + return (-1); + return (0); +} + +UsbTransport * +usb_open(ifc_match_func callback, uint32_t timeout_ms) +{ + std::unique_ptr h = enumerate(callback); + return (h ? new LibusbUsbTransport(std::move(h), timeout_ms) : nullptr); +} Property changes on: head/devel/android-tools-fastboot/files/usb_libusb.cpp ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property