sync source from dev branch 98/11198/1
authoryoonki.park <yoonki.park@samsung.com>
Tue, 22 Oct 2013 15:02:34 +0000 (00:02 +0900)
committeryoonki.park <yoonki.park@samsung.com>
Tue, 22 Oct 2013 15:02:34 +0000 (00:02 +0900)
Change-Id: I986409d255ee315acec3a2222a8898d1f4da0fee
Signed-off-by: yoonki.park <yoonki.park@samsung.com>
33 files changed:
Makefile
deps/libusb/AUTHORS [deleted file]
deps/libusb/COPYING [deleted file]
deps/libusb/LICENSE [deleted file]
deps/libusb/Makefile [deleted file]
deps/libusb/darwin.c [deleted file]
deps/libusb/descriptors.c [deleted file]
deps/libusb/error.c [deleted file]
deps/libusb/error.h [deleted file]
deps/libusb/linux.c [deleted file]
deps/libusb/linux.h [deleted file]
deps/libusb/usb.c [deleted file]
deps/libusb/usb.h [deleted file]
deps/libusb/usbi.h [deleted file]
deps/libusb/windows.c [deleted file]
deps/libusb/winusb.h [deleted file]
package/changelog
package/pkginfo.manifest
src/command_function.c
src/commandline.c
src/common_modules.h
src/file_sync_client.c
src/sdb.c
src/sdb_client.c
src/sockets.c
src/transport.c
src/transport_local.c
src/usb_windows.c [new file with mode: 0644]
src/utils.c
src/utils.h
src/utils_backend.h
src/utils_unix.c
src/utils_windows.c

index fc83b0528d0a6a4006240459407895a64fd8bd6d..45c645e25e4308796fed9caa17016f3a95080bbc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,6 @@ ifeq ($(HOST_OS),linux)
        LOCAL_OTHER_SRC := src/fdevent.c src/fdevent_unix.c
        LOCAL_LFLAGS := -lrt -lpthread -ludev
        LOCAL_CFLAGS := -DOS_LINUX -DHAVE_FORKEXEC -DHAVE_TERMIO_H -DHAVE_SYMLINKS -DSDB_HOST=1 -DSDB_HOST_ON_TARGET=1 -D_FILE_OFFSET_BITS=64
-       HAS_LIBUSB := false
 endif
 
 ifeq ($(HOST_OS),darwin)
@@ -31,11 +30,10 @@ ifeq ($(HOST_OS),darwin)
        LOCAL_OTHER_SRC := src/fdevent.c src/fdevent_unix.c
        LOCAL_LFLAGS := -lpthread -framework CoreFoundation -framework IOKit -framework Carbon
        LOCAL_CFLAGS := -DOS_DARWIN -DHAVE_FORKEXEC -DHAVE_TERMIO_H -DHAVE_SYMLINKS -mmacosx-version-min=10.4 -DSDB_HOST=1 -DSDB_HOST_ON_TARGET=1
-       HAS_LIBUSB := false
 endif
 
 ifeq ($(HOST_OS),mingw32)
-       LOCAL_USB_SRC := deps/libusb/windows.c
+       LOCAL_USB_SRC := src/usb_windows.c
        LOCAL_UTIL_SRC := src/utils_windows.c
        LOCAL_OTHER_SRC := src/fdevent.c  src/fdevent_windows.c
        LOCAL_CFLAGS := -DOS_WINDOWS
@@ -81,10 +79,6 @@ all : $(MODULE)
 
 sdb : $(SDB_SRC_FILES)
        mkdir -p $(OBJDIR)
-ifeq ($(HAS_LIBUSB),true)
-       make -C ./deps/libusb
-       make install -C ./deps/libusb
-endif
        $(CC) $(SDB_CFLAGS) -o $(OBJDIR)/$(MODULE) $(SDB_SRC_FILES) $(LOCAL_IFLAGS) $(SDB_LFLAGS) $(STATIC_LFLAGS)
 
 clean :
diff --git a/deps/libusb/AUTHORS b/deps/libusb/AUTHORS
deleted file mode 100644 (file)
index d2beff9..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Daniel Drake <dsd@gentoo.org>
-
diff --git a/deps/libusb/COPYING b/deps/libusb/COPYING
deleted file mode 100644 (file)
index 5ab7695..0000000
+++ /dev/null
@@ -1,504 +0,0 @@
-                 GNU LESSER GENERAL PUBLIC LICENSE
-                      Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL.  It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
-                           Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
-  This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it.  You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
-  When we speak of free software, we are referring to freedom of use,
-not price.  Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
-  To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights.  These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
-  For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you.  You must make sure that they, too, receive or can get the source
-code.  If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it.  And you must show them these terms so they know their rights.
-
-  We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
-  To protect each distributor, we want to make it very clear that
-there is no warranty for the free library.  Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-\f
-  Finally, software patents pose a constant threat to the existence of
-any free program.  We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder.  Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
-  Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License.  This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License.  We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
-  When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library.  The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom.  The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
-  We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License.  It also provides other free software developers Less
-of an advantage over competing non-free programs.  These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries.  However, the Lesser license provides advantages in certain
-special circumstances.
-
-  For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard.  To achieve this, non-free programs must be
-allowed to use the library.  A more frequent case is that a free
-library does the same job as widely used non-free libraries.  In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
-  In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software.  For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
-  Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.  Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library".  The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-\f
-                 GNU LESSER GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
-  A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
-  The "Library", below, refers to any such software library or work
-which has been distributed under these terms.  A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language.  (Hereinafter, translation is
-included without limitation in the term "modification".)
-
-  "Source code" for a work means the preferred form of the work for
-making modifications to it.  For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
-  Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it).  Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-  
-  1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
-  You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-\f
-  2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) The modified work must itself be a software library.
-
-    b) You must cause the files modified to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    c) You must cause the whole of the work to be licensed at no
-    charge to all third parties under the terms of this License.
-
-    d) If a facility in the modified Library refers to a function or a
-    table of data to be supplied by an application program that uses
-    the facility, other than as an argument passed when the facility
-    is invoked, then you must make a good faith effort to ensure that,
-    in the event an application does not supply such function or
-    table, the facility still operates, and performs whatever part of
-    its purpose remains meaningful.
-
-    (For example, a function in a library to compute square roots has
-    a purpose that is entirely well-defined independent of the
-    application.  Therefore, Subsection 2d requires that any
-    application-supplied function or table used by this function must
-    be optional: if the application does not supply it, the square
-    root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library.  To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License.  (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.)  Do not make any other change in
-these notices.
-\f
-  Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
-  This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
-  4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
-  If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library".  Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
-  However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library".  The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
-  When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library.  The
-threshold for this to be true is not precisely defined by law.
-
-  If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work.  (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
-  Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-\f
-  6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
-  You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License.  You must supply a copy of this License.  If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License.  Also, you must do one
-of these things:
-
-    a) Accompany the work with the complete corresponding
-    machine-readable source code for the Library including whatever
-    changes were used in the work (which must be distributed under
-    Sections 1 and 2 above); and, if the work is an executable linked
-    with the Library, with the complete machine-readable "work that
-    uses the Library", as object code and/or source code, so that the
-    user can modify the Library and then relink to produce a modified
-    executable containing the modified Library.  (It is understood
-    that the user who changes the contents of definitions files in the
-    Library will not necessarily be able to recompile the application
-    to use the modified definitions.)
-
-    b) Use a suitable shared library mechanism for linking with the
-    Library.  A suitable mechanism is one that (1) uses at run time a
-    copy of the library already present on the user's computer system,
-    rather than copying library functions into the executable, and (2)
-    will operate properly with a modified version of the library, if
-    the user installs one, as long as the modified version is
-    interface-compatible with the version that the work was made with.
-
-    c) Accompany the work with a written offer, valid for at
-    least three years, to give the same user the materials
-    specified in Subsection 6a, above, for a charge no more
-    than the cost of performing this distribution.
-
-    d) If distribution of the work is made by offering access to copy
-    from a designated place, offer equivalent access to copy the above
-    specified materials from the same place.
-
-    e) Verify that the user has already received a copy of these
-    materials or that you have already sent this user a copy.
-
-  For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it.  However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
-  It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system.  Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-\f
-  7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
-    a) Accompany the combined library with a copy of the same work
-    based on the Library, uncombined with any other library
-    facilities.  This must be distributed under the terms of the
-    Sections above.
-
-    b) Give prominent notice with the combined library of the fact
-    that part of it is a work based on the Library, and explaining
-    where to find the accompanying uncombined form of the same work.
-
-  8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License.  Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License.  However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
-  9. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Library or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
-  10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-\f
-  11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded.  In such case, this License incorporates the limitation as if
-written in the body of this License.
-
-  13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation.  If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-\f
-  14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission.  For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this.  Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
-                           NO WARRANTY
-
-  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
-  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
-                    END OF TERMS AND CONDITIONS
-\f
-           How to Apply These Terms to Your New Libraries
-
-  If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change.  You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
-  To apply these terms, attach the following notices to the library.  It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the library's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    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
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the
-  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
-  <signature of Ty Coon>, 1 April 1990
-  Ty Coon, President of Vice
-
-That's all there is to it!
-
-
diff --git a/deps/libusb/LICENSE b/deps/libusb/LICENSE
deleted file mode 100644 (file)
index f98680a..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-libusb is covered by the LGPL:
-
-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 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., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
-
-----
-
-Alternatively, the files usb.h.in and/or usb.h may be licensed under the
-BSD license:
-
-Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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.
-3. The name of the author may not be used to endorse or promote products
-   derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
-
diff --git a/deps/libusb/Makefile b/deps/libusb/Makefile
deleted file mode 100644 (file)
index bb6054f..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-#
-# Makefile for libusb
-#
-
-#
-HOST_OS := $(shell uname -s | tr A-Z a-z | cut -d'_' -f1)
-
-# =========================================================
-
-ifeq ($(HOST_OS),darwin)
-       CC := /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
-else
-       CC := gcc
-endif
-
-#
-ifeq ($(HOST_OS),linux)
-       LOCAL_USB_SRC :=  linux.c error.c usb.c descriptors.c
-       LOCAL_LFLAGS := -lrt -lpthread
-       LOCAL_CFLAGS := -DOS_LINUX
-endif
-
-ifeq ($(HOST_OS),darwin)
-       LOCAL_USB_SRC := darwin.c error.c usb.c descriptors.c
-       LOCAL_LFLAGS := -lpthread -framework CoreFoundation -framework IOKit -framework Carbon
-       LOCAL_CFLAGS := -DOS_DARWIN -mmacosx-version-min=10.4
-endif
-
-MODULE = libusb.so
-
-all : $(MODULE)
-
-$(MODULE) : $(LOCAL_USB_SRC)
-       $(CC) -o $(MODULE) -fPIC $(LOCAL_USB_SRC) $(LOCAL_LFLAGS) $(LOCAL_CFLAGS) -shared
-
-install :
-       mkdir -p ../../bin
-       cp $(MODULE) ../../bin
-clean :
-       rm -rf $(MODULE)
-       rm -rf *.o
diff --git a/deps/libusb/darwin.c b/deps/libusb/darwin.c
deleted file mode 100644 (file)
index c330eb0..0000000
+++ /dev/null
@@ -1,1329 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * Darwin/MacOS X Support
- *
- * (c) 2002-2007 Nathan Hjelm <hjelmn@users.sourceforge.net>
- *
- * (07/25/2007):
- *   - Added a fix to ignore buggy (virtual?) hubs.
- * (06/26/2006):
- *   - Bulk functions no longer use async transfer functions.
- * (04/17/2005):
- *   - Lots of minor fixes.
- *   - Endpoint table now made by claim_interface to fix a bug.
- *   - Merged Read/Write to make modifications easier.
- * (03/25/2005):
- *   - Fixed a bug when using asynchronous callbacks within a multi-threaded application.
- * (03/14/2005):
- *   - Added an endpoint table to speed up bulk transfers.
- * 0.1.11 (02/22/2005):
- *   - Updated error checking in read/write routines to check completion codes.
- *   - Updated set_configuration so that the open interface is reclaimed before completion.
- *   - Fixed several typos.
- * 0.1.8 (01/12/2004):
- *   - Fixed several memory leaks.
- *   - Readded 10.0 support
- *   - Added support for USB fuctions defined in 10.3 and above
- * (01/02/2003):
- *   - Applied a patch by Philip Edelbrock <phil@edgedesign.us> that fixes a bug in usb_control_msg.
- * (12/16/2003):
- *   - Even better error printing.
- *   - Devices that cannot be opened can have their interfaces opened.
- * 0.1.6 (05/12/2002):
- *   - Fixed problem where libusb holds resources after program completion.
- *   - Mouse should no longer freeze up now.
- * 0.1.2 (02/13/2002):
- *   - Bulk functions should work properly now.
- * 0.1.1 (02/11/2002):
- *   - Fixed major bug (device and interface need to be released after use)
- * 0.1.0 (01/06/2002):
- *   - Tested driver with gphoto (works great as long as Image Capture isn't running)
- * 0.1d  (01/04/2002):
- *   - Implimented clear_halt and resetep
- *   - Uploaded to CVS.
- * 0.1b  (01/04/2002):
- *   - Added usb_debug line to bulk read and write function.
- * 0.1a  (01/03/2002):
- *   - Driver mostly completed using the macosx driver I wrote for my rioutil software.
- *
- * Derived from Linux version by Richard Tobin.
- * Also partly derived from BSD version.
- *
- * This library is covered by the LGPL, read LICENSE for details.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-
-/* standard includes for darwin/os10 (IOKit) */
-#include <mach/mach_port.h>
-#include <IOKit/IOCFBundle.h>
-#include <IOKit/usb/IOUSBLib.h>
-#include <IOKit/IOCFPlugIn.h>
-
-#include "usbi.h"
-
-/* some defines */
-/* IOUSBInterfaceInferface */
-#if defined (kIOUSBInterfaceInterfaceID220)
-
-// #warning "libusb being compiled for 10.4 or later"
-#define usb_interface_t IOUSBInterfaceInterface220
-#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
-#define InterfaceVersion 220
-
-#elif defined (kIOUSBInterfaceInterfaceID197)
-
-// #warning "libusb being compiled for 10.3 or later"
-#define usb_interface_t IOUSBInterfaceInterface197
-#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID197
-#define InterfaceVersion 197
-
-#elif defined (kIOUSBInterfaceInterfaceID190)
-
-// #warning "libusb being compiled for 10.2 or later"
-#define usb_interface_t IOUSBInterfaceInterface190
-#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID190
-#define InterfaceVersion 190
-
-#elif defined (kIOUSBInterfaceInterfaceID182)
-
-// #warning "libusb being compiled for 10.1 or later"
-#define usb_interface_t IOUSBInterfaceInterface182
-#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID182
-#define InterfaceVersion 182
-
-#else
-
-/* No timeout functions available! Time to upgrade your os. */
-#warning "libusb being compiled without support for timeout bulk functions! 10.0 and up"
-#define usb_interface_t IOUSBInterfaceInterface
-#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID
-#define LIBUSB_NO_TIMEOUT_INTERFACE
-#define InterfaceVersion 180
-
-#endif
-
-/* IOUSBDeviceInterface */
-#if defined (kIOUSBDeviceInterfaceID197)
-
-#define usb_device_t    IOUSBDeviceInterface197
-#define DeviceInterfaceID kIOUSBDeviceInterfaceID197
-#define DeviceVersion 197
-
-#elif defined (kIOUSBDeviceInterfaceID187)
-
-#define usb_device_t    IOUSBDeviceInterface187
-#define DeviceInterfaceID kIOUSBDeviceInterfaceID187
-#define DeviceVersion 187
-
-#elif defined (kIOUSBDeviceInterfaceID182)
-
-#define usb_device_t    IOUSBDeviceInterface182
-#define DeviceInterfaceID kIOUSBDeviceInterfaceID182
-#define DeviceVersion 182
-
-#else
-
-#define usb_device_t    IOUSBDeviceInterface
-#define DeviceInterfaceID kIOUSBDeviceInterfaceID
-#define LIBUSB_NO_TIMEOUT_DEVICE
-#define LIBUSB_NO_SEIZE_DEVICE
-#define DeviceVersion 180
-
-#endif
-
-typedef IOReturn io_return_t;
-typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
-typedef SInt32 s_int32_t;
-typedef IOReturn (*rw_async_func_t)(void *self, UInt8 pipeRef, void *buf, UInt32 size,
-                                   IOAsyncCallback1 callback, void *refcon);
-typedef IOReturn (*rw_async_to_func_t)(void *self, UInt8 pipeRef, void *buf, UInt32 size,
-                                      UInt32 noDataTimeout, UInt32 completionTimeout,
-                                      IOAsyncCallback1 callback, void *refcon);
-
-#if !defined(IO_OBJECT_NULL)
-#define IO_OBJECT_NULL ((io_object_t)0)
-#endif
-
-struct darwin_dev_handle {
-  usb_device_t **device;
-  usb_interface_t **interface;
-  int open;
-
-  /* stored translation table for pipes to endpoints */
-  int num_endpoints;
-  unsigned char *endpoint_addrs;
-};
-
-static IONotificationPortRef gNotifyPort;
-static mach_port_t masterPort = MACH_PORT_NULL;
-
-static void darwin_cleanup (void)
-{
-  IONotificationPortDestroy(gNotifyPort);
-  mach_port_deallocate(mach_task_self(), masterPort);
-}
-
-static char *darwin_error_str (int result) {
-  switch (result) {
-  case kIOReturnSuccess:
-    return "no error";
-  case kIOReturnNotOpen:
-    return "device not opened for exclusive access";
-  case kIOReturnNoDevice:
-    return "no connection to an IOService";
-  case kIOUSBNoAsyncPortErr:
-    return "no async port has been opened for interface";
-  case kIOReturnExclusiveAccess:
-    return "another process has device opened for exclusive access";
-  case kIOUSBPipeStalled:
-    return "pipe is stalled";
-  case kIOReturnError:
-    return "could not establish a connection to the Darwin kernel";
-  case kIOUSBTransactionTimeout:
-    return "transaction timed out";
-  case kIOReturnBadArgument:
-    return "invalid argument";
-  case kIOReturnAborted:
-    return "transaction aborted";
-  case kIOReturnNotResponding:
-    return "device not responding";
-  default:
-    return "unknown error";
-  }
-}
-
-/* not a valid errorno outside darwin.c */
-#define LUSBDARWINSTALL (ELAST+1)
-
-static int darwin_to_errno (int result) {
-  switch (result) {
-  case kIOReturnSuccess:
-    return 0;
-  case kIOReturnNotOpen:
-    return EBADF;
-  case kIOReturnNoDevice:
-  case kIOUSBNoAsyncPortErr:
-    return ENXIO;
-  case kIOReturnExclusiveAccess:
-    return EBUSY;
-  case kIOUSBPipeStalled:
-    return LUSBDARWINSTALL;
-  case kIOReturnBadArgument:
-    return EINVAL;
-  case kIOUSBTransactionTimeout:
-    return ETIMEDOUT;
-  case kIOReturnNotResponding:
-    return EIO;
-  case kIOReturnError:
-  default:
-    return 1;
-  }
-}
-
-static int usb_setup_iterator (io_iterator_t *deviceIterator)
-{
-  int result;
-  CFMutableDictionaryRef matchingDict;
-
-  /* set up the matching dictionary for class IOUSBDevice and its subclasses.
-     It will be consumed by the IOServiceGetMatchingServices call */
-  if ((matchingDict = IOServiceMatching(kIOUSBDeviceClassName)) == NULL) {
-    darwin_cleanup ();
-    
-    USB_ERROR_STR(-1, "libusb/darwin.c usb_setup_iterator: Could not create a matching dictionary.\n");
-  }
-
-  result = IOServiceGetMatchingServices(masterPort, matchingDict, deviceIterator);
-  matchingDict = NULL;
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR (-darwin_to_errno (result), "libusb/darwin.c usb_setup_iterator: IOServiceGetMatchingServices: %s\n",
-                  darwin_error_str(result));
-
-  return 0;
-}
-
-static usb_device_t **usb_get_next_device (io_iterator_t deviceIterator, UInt32 *locationp)
-{
-  io_cf_plugin_ref_t *plugInInterface = NULL;
-  usb_device_t **device;
-  io_service_t usbDevice;
-  long result, score;
-
-  if (!IOIteratorIsValid (deviceIterator) || !(usbDevice = IOIteratorNext(deviceIterator)))
-    return NULL;
-  
-  result = IOCreatePlugInInterfaceForService(usbDevice, kIOUSBDeviceUserClientTypeID,
-                                            kIOCFPlugInInterfaceID, &plugInInterface,
-                                            &score);
-  
-  result = IOObjectRelease(usbDevice);
-  if (result || !plugInInterface)
-    return NULL;
-  
-  (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(DeviceInterfaceID),
-                                    (LPVOID)&device);
-  
-  (*plugInInterface)->Stop(plugInInterface);
-  IODestroyPlugInInterface (plugInInterface);
-  plugInInterface = NULL;
-  
-  (*(device))->GetLocationID(device, locationp);
-
-  return device;
-}
-
-int usb_os_open(usb_dev_handle *dev)
-{
-  struct darwin_dev_handle *device;
-
-  io_return_t result;
-  io_iterator_t deviceIterator;
-
-  usb_device_t **darwin_device;
-
-  UInt32 location = *((UInt32 *)dev->device->dev);
-  UInt32 dlocation;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if (masterPort == MACH_PORT_NULL)
-    USB_ERROR(-EINVAL);
-
-  device = calloc(1, sizeof(struct darwin_dev_handle));
-  if (!device)
-    USB_ERROR(-ENOMEM);
-
-  if (usb_debug > 3)
-    fprintf(stderr, "usb_os_open: %04x:%04x\n",
-           dev->device->descriptor.idVendor,
-           dev->device->descriptor.idProduct);
-
-  if ((result = usb_setup_iterator (&deviceIterator)) < 0)
-    return result;
-
-  /* This port of libusb uses locations to keep track of devices. */
-  while ((darwin_device = usb_get_next_device (deviceIterator, &dlocation)) != NULL) {
-    if (dlocation == location)
-      break;
-
-    (*darwin_device)->Release(darwin_device);
-  }
-
-  IOObjectRelease(deviceIterator);
-  device->device = darwin_device;
-
-  if (device->device == NULL)
-    USB_ERROR_STR (-ENOENT, "usb_os_open: %s\n", "Device not found!");
-
-#if !defined (LIBUSB_NO_SEIZE_DEVICE)
-  result = (*(device->device))->USBDeviceOpenSeize (device->device);
-#else
-  /* No Seize in OS X 10.0 (Darwin 1.4) */
-  result = (*(device->device))->USBDeviceOpen (device->device);
-#endif
-
-  if (result != kIOReturnSuccess) {
-    switch (result) {
-    case kIOReturnExclusiveAccess:
-      if (usb_debug > 0)
-       fprintf (stderr, "usb_os_open(USBDeviceOpenSeize): %s\n", darwin_error_str(result));
-      break;
-    default:
-      (*(device->device))->Release (device->device);
-      USB_ERROR_STR(-darwin_to_errno (result), "usb_os_open(USBDeviceOpenSeize): %s",
-                   darwin_error_str(result));
-    }
-    
-    device->open = 0;
-  } else
-    device->open = 1;
-    
-  dev->impl_info = device;
-  dev->interface = -1;
-  dev->altsetting = -1;
-
-  device->num_endpoints  = 0;
-  device->endpoint_addrs = NULL;
-
-  return 0;
-}
-
-int usb_os_close(usb_dev_handle *dev)
-{
-  struct darwin_dev_handle *device;
-  io_return_t result;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR(-ENOENT);
-
-  usb_release_interface(dev, dev->interface);
-
-  if (usb_debug > 3)
-    fprintf(stderr, "usb_os_close: %04x:%04x\n",
-           dev->device->descriptor.idVendor,
-           dev->device->descriptor.idProduct);
-
-  if (device->open == 1)
-    result = (*(device->device))->USBDeviceClose(device->device);
-  else
-    result = kIOReturnSuccess;
-
-  /* device may not need to be released, but if it has to... */
-  (*(device->device))->Release(device->device);
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_os_close(USBDeviceClose): %s", darwin_error_str(result));
-
-  free (device);
-
-  return 0;
-}
-
-static int get_endpoints (struct darwin_dev_handle *device)
-{
-  io_return_t ret;
-
-  u_int8_t numep, direction, number;
-  u_int8_t dont_care1, dont_care3;
-  u_int16_t dont_care2;
-
-  int i;
-
-  if (device == NULL || device->interface == NULL)
-    return -EINVAL;
-
-  if (usb_debug > 1)
-    fprintf(stderr, "libusb/darwin.c get_endpoints: building table of endpoints.\n");
-
-  /* retrieve the total number of endpoints on this interface */
-  ret = (*(device->interface))->GetNumEndpoints(device->interface, &numep);
-  if ( ret ) {
-    if ( usb_debug > 1 )
-      fprintf ( stderr, "get_endpoints: interface is %p\n", device->interface );
-
-    USB_ERROR_STR ( -ret, "get_endpoints: can't get number of endpoints for interface" );
-  }
-
-  free (device->endpoint_addrs);
-  device->endpoint_addrs = calloc (sizeof (unsigned char), numep);
-
-  /* iterate through pipe references */
-  for (i = 1 ; i <= numep ; i++) {
-    ret = (*(device->interface))->GetPipeProperties(device->interface, i, &direction, &number,
-                                                   &dont_care1, &dont_care2, &dont_care3);
-
-    if (ret != kIOReturnSuccess) {
-      fprintf (stderr, "get_endpoints: an error occurred getting pipe information on pipe %d\n",
-              i );
-      USB_ERROR_STR(-darwin_to_errno(ret), "get_endpoints(GetPipeProperties): %s", darwin_error_str(ret));
-    }
-
-    if (usb_debug > 1)
-      fprintf (stderr, "get_endpoints: Pipe %i: DIR: %i number: %i\n", i, direction, number);
-
-    device->endpoint_addrs[i - 1] = ((direction << 7 & USB_ENDPOINT_DIR_MASK) |
-                                    (number & USB_ENDPOINT_ADDRESS_MASK));
-  }
-
-  device->num_endpoints = numep;
-
-  if (usb_debug > 1)
-    fprintf(stderr, "libusb/darwin.c get_endpoints: complete.\n");
-  
-  return 0;
-}
-
-static int claim_interface (usb_dev_handle *dev, int interface)
-{
-  io_iterator_t interface_iterator;
-  io_service_t  usbInterface = IO_OBJECT_NULL;
-  io_return_t result;
-  io_cf_plugin_ref_t *plugInInterface = NULL;
-
-  IOUSBFindInterfaceRequest request;
-
-  struct darwin_dev_handle *device;
-  long score;
-  int current_interface;
-
-  device = dev->impl_info;
-
-  request.bInterfaceClass = kIOUSBFindInterfaceDontCare;
-  request.bInterfaceSubClass = kIOUSBFindInterfaceDontCare;
-  request.bInterfaceProtocol = kIOUSBFindInterfaceDontCare;
-  request.bAlternateSetting = kIOUSBFindInterfaceDontCare;
-
-  result = (*(device->device))->CreateInterfaceIterator(device->device, &request, &interface_iterator);
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR (-darwin_to_errno(result), "claim_interface(CreateInterfaceIterator): %s",
-                  darwin_error_str(result));
-
-  for ( current_interface=0 ; current_interface <= interface ; current_interface++ ) {
-    usbInterface = IOIteratorNext(interface_iterator);
-    if ( usb_debug > 3 )
-      fprintf ( stderr, "Interface %d of device is 0x%08x\n",
-               current_interface, usbInterface );
-  }
-
-  current_interface--;
-
-  /* the interface iterator is no longer needed, release it */
-  IOObjectRelease(interface_iterator);
-
-  if (!usbInterface) {
-    u_int8_t nConfig;                       /* Index of configuration to use */
-    IOUSBConfigurationDescriptorPtr configDesc; /* to describe which configuration to select */
-    /* Only a composite class device with no vendor-specific driver will
-       be configured. Otherwise, we need to do it ourselves, or there
-       will be no interfaces for the device. */
-
-    if ( usb_debug > 3 )
-      fprintf ( stderr,"claim_interface: No interface found; selecting configuration\n" );
-
-    result = (*(device->device))->GetNumberOfConfigurations ( device->device, &nConfig );
-    if (result != kIOReturnSuccess)
-      USB_ERROR_STR(-darwin_to_errno(result), "claim_interface(GetNumberOfConfigurations): %s",
-                   darwin_error_str(result));
-    
-    if (nConfig < 1)
-      USB_ERROR_STR(-ENXIO ,"claim_interface(GetNumberOfConfigurations): no configurations");
-    else if ( nConfig > 1 && usb_debug > 0 )
-      fprintf ( stderr, "claim_interface: device has more than one"
-               " configuration, using the first (warning)\n" );
-
-    if ( usb_debug > 3 )
-      fprintf ( stderr, "claim_interface: device has %d configuration%s\n",
-               (int)nConfig, (nConfig>1?"s":"") );
-
-    /* Always use the first configuration */
-    result = (*(device->device))->GetConfigurationDescriptorPtr ( (device->device), 0, &configDesc );
-    if (result != kIOReturnSuccess) {
-      if (device->open == 1) {
-        (*(device->device))->USBDeviceClose ( (device->device) );
-        (*(device->device))->Release ( (device->device) );
-      }
-
-      USB_ERROR_STR(-darwin_to_errno(result), "claim_interface(GetConfigurationDescriptorPtr): %s",
-                   darwin_error_str(result));
-    } else if ( usb_debug > 3 )
-      fprintf ( stderr, "claim_interface: configuration value is %d\n",
-               configDesc->bConfigurationValue );
-
-    if (device->open == 1) {
-      result = (*(device->device))->SetConfiguration ( (device->device), configDesc->bConfigurationValue );
-
-      if (result != kIOReturnSuccess) {
-       (*(device->device))->USBDeviceClose ( (device->device) );
-       (*(device->device))->Release ( (device->device) );
-
-       USB_ERROR_STR(-darwin_to_errno(result), "claim_interface(SetConfiguration): %s",
-                     darwin_error_str(result));
-      }
-
-      dev->config = configDesc->bConfigurationValue;
-    }
-    
-    request.bInterfaceClass = kIOUSBFindInterfaceDontCare;
-    request.bInterfaceSubClass = kIOUSBFindInterfaceDontCare;
-    request.bInterfaceProtocol = kIOUSBFindInterfaceDontCare;
-    request.bAlternateSetting = kIOUSBFindInterfaceDontCare;
-
-    /* Now go back and get the chosen interface */
-    result = (*(device->device))->CreateInterfaceIterator(device->device, &request, &interface_iterator);
-    if (result != kIOReturnSuccess)
-      USB_ERROR_STR (-darwin_to_errno(result), "claim_interface(CreateInterfaceIterator): %s",
-                    darwin_error_str(result));
-
-    for (current_interface = 0 ; current_interface <= interface ; current_interface++) {
-      usbInterface = IOIteratorNext(interface_iterator);
-
-      if ( usb_debug > 3 )
-       fprintf ( stderr, "claim_interface: Interface %d of device is 0x%08x\n",
-                 current_interface, usbInterface );
-    }
-    current_interface--;
-
-    /* the interface iterator is no longer needed, release it */
-    IOObjectRelease(interface_iterator);
-
-    if (!usbInterface)
-      USB_ERROR_STR (-ENOENT, "claim_interface: interface iterator returned NULL");
-  }
-
-  result = IOCreatePlugInInterfaceForService(usbInterface,
-                                            kIOUSBInterfaceUserClientTypeID,
-                                            kIOCFPlugInInterfaceID,
-                                            &plugInInterface, &score);
-  /* No longer need the usbInterface object after getting the plug-in */
-  result = IOObjectRelease(usbInterface);
-  if (result || !plugInInterface)
-    USB_ERROR(-ENOENT);
-
-  /* Now create the device interface for the interface */
-  result = (*plugInInterface)->QueryInterface(plugInInterface,
-                                             CFUUIDGetUUIDBytes(InterfaceInterfaceID),
-                                             (LPVOID) &device->interface);
-
-  /* No longer need the intermediate plug-in */
-  (*plugInInterface)->Stop(plugInInterface);
-  IODestroyPlugInInterface (plugInInterface);
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "claim_interface(QueryInterface): %s",
-                 darwin_error_str(result));
-
-  if (!device->interface)
-    USB_ERROR(-EACCES);
-
-  if ( usb_debug > 3 )
-    fprintf ( stderr, "claim_interface: Interface %d of device from QueryInterface is %p\n",
-             current_interface, device->interface);
-
-  /* claim the interface */
-  result = (*(device->interface))->USBInterfaceOpen(device->interface);
-  if (result)
-    USB_ERROR_STR(-darwin_to_errno(result), "claim_interface(USBInterfaceOpen): %s",
-                 darwin_error_str(result));
-
-  result = get_endpoints (device);
-
-  if (result) {
-    /* this should not happen */
-    usb_release_interface (dev, interface);
-    USB_ERROR_STR ( result, "claim_interface: could not build endpoint table");
-  }
-
-  return 0;
-}
-
-int usb_set_configuration (usb_dev_handle *dev, int configuration)
-{
-  struct darwin_dev_handle *device;
-  io_return_t result;
-  int interface;
-
-  if ( usb_debug > 3 )
-    fprintf ( stderr, "usb_set_configuration: called for config %x\n", configuration );
-
-  if (!dev)
-    USB_ERROR_STR ( -ENXIO, "usb_set_configuration: called with null device\n" );
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR_STR ( -ENOENT, "usb_set_configuration: device not properly initialized" );
-
-  /* Setting configuration will invalidate the interface, so we need
-     to reclaim it. First, dispose of existing interface, if any. */
-  interface = dev->interface;
-
-  if ( device->interface )
-    usb_release_interface(dev, dev->interface);
-
-  result = (*(device->device))->SetConfiguration(device->device, configuration);
-
-  if (result)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_set_configuration(SetConfiguration): %s",
-                 darwin_error_str(result));
-
-  /* Reclaim interface */
-  if (interface != -1)
-    result = usb_claim_interface (dev, interface);
-
-  dev->config = configuration;
-
-  return result;
-}
-
-int usb_claim_interface(usb_dev_handle *dev, int interface)
-{
-  struct darwin_dev_handle *device = dev->impl_info;
-
-  io_return_t result;
-
-  if ( usb_debug > 3 )
-    fprintf ( stderr, "usb_claim_interface: called for interface %d\n", interface );
-
-  if (!device)
-    USB_ERROR_STR ( -ENOENT, "usb_claim_interface: device is NULL" );
-
-  if (!(device->device))
-    USB_ERROR_STR ( -EINVAL, "usb_claim_interface: device->device is NULL" );
-
-  /* If we have already claimed an interface, release it */
-  if ( device->interface )
-    usb_release_interface(dev, dev->interface);
-
-  result = claim_interface ( dev, interface );
-  if ( result )
-    USB_ERROR_STR ( result, "usb_claim_interface: couldn't claim interface" );
-
-  dev->interface = interface;
-
-  /* interface is claimed and async IO is set up: return 0 */
-  return 0;
-}
-
-int usb_release_interface(usb_dev_handle *dev, int interface)
-{
-  struct darwin_dev_handle *device;
-  io_return_t result;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR(-ENOENT);
-
-  /* interface is not open */
-  if (!device->interface)
-    return 0;
-
-  result = (*(device->interface))->USBInterfaceClose(device->interface);
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_release_interface(USBInterfaceClose): %s",
-                 darwin_error_str(result));
-
-  result = (*(device->interface))->Release(device->interface);
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_release_interface(Release): %s",
-                 darwin_error_str(result));
-
-  device->interface = NULL;
-
-  free (device->endpoint_addrs);
-
-  device->num_endpoints  = 0;
-  device->endpoint_addrs = NULL;
-
-  dev->interface = -1;
-  dev->altsetting = -1;
-
-  return 0;
-}
-
-int usb_set_altinterface(usb_dev_handle *dev, int alternate)
-{
-  struct darwin_dev_handle *device;
-  io_return_t result;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR(-ENOENT);
-
-  /* interface is not open */
-  if (!device->interface)
-    USB_ERROR_STR(-EACCES, "usb_set_altinterface: interface used without being claimed");
-
-  result = (*(device->interface))->SetAlternateInterface(device->interface, alternate);
-
-  if (result)
-    USB_ERROR_STR(result, "usb_set_altinterface: could not set alternate interface");
-
-  dev->altsetting = alternate;
-
-  result = get_endpoints (device);
-  if (result) {
-    /* this should not happen */
-    USB_ERROR_STR ( result, "usb_set_altinterface: could not build endpoint table");
-  }
-
-  return 0;
-}
-
-/* simple function that figures out what pipeRef is associated with an endpoint */
-static int ep_to_pipeRef (struct darwin_dev_handle *device, int ep)
-{
-  int i;
-
-  if (usb_debug > 1)
-    fprintf(stderr, "libusb/darwin.c ep_to_pipeRef: Converting ep address to pipeRef.\n");
-
-  for (i = 0 ; i < device->num_endpoints ; i++)
-    if (device->endpoint_addrs[i] == ep)
-      return i + 1;
-
-  /* No pipe found with the correct endpoint address */
-  if (usb_debug > 1)
-    fprintf(stderr, "libusb/darwin.c ep_to_pipeRef: No pipeRef found with endpoint address 0x%02x.\n", ep);
-  
-  return -1;
-}
-
-static int usb_bulk_transfer (usb_dev_handle *dev, int ep, char *bytes, u_int32_t size, int timeout, int usb_bt_read)
-{
-  struct darwin_dev_handle *device;
-
-  io_return_t result = -1;
-
-  int pipeRef;
-
-  u_int8_t  transferType, direction, number, interval;
-  u_int16_t maxPacketSize;
-
-  if (!dev)
-    USB_ERROR_STR ( -ENXIO, "libusb/darwin.c usb_bulk_transfer: Called with NULL device" );
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR_STR ( -ENOENT, "libusb/darwin.c usb_bulk_transfer: Device not open" );
-
-  /* interface is not open */
-  if (!device->interface)
-    USB_ERROR_STR(-EACCES, "libusb/darwin.c usb_bulk_transfer: Interface used before it was opened");
-
-
-  /* Set up transfer */
-  if ((pipeRef = ep_to_pipeRef(device, ep)) < 0)
-    USB_ERROR_STR ( -EINVAL, "libusb/darwin.c usb_bulk_transfer: Invalid pipe reference" );
-
-  (*(device->interface))->GetPipeProperties (device->interface, pipeRef, &direction, &number,
-                                            &transferType, &maxPacketSize, &interval);
-  /* Transfer set up complete */
-
-  if (usb_debug > 0)
-    fprintf (stderr, "libusb/darwin.c usb_bulk_transfer: Transfering %i bytes of data on endpoint 0x%02x\n", size, ep);
-
-  /* Do bulk transfer */
-  if (transferType == kUSBInterrupt && usb_debug > 3)
-    fprintf (stderr, "libusb/darwin.c usb_bulk_transfer: USB pipe is an interrupt pipe. Timeouts will not be used.\n");
-
-#if !defined(LIBUSB_NO_TIMEOUT_INTERFACE)
-  if ( transferType != kUSBInterrupt) {
-    if (usb_bt_read != 0)
-      result = (*(device->interface))->ReadPipeTO (device->interface, pipeRef, bytes, (UInt32 *)&size, timeout, timeout);
-    else
-      result = (*(device->interface))->WritePipeTO (device->interface, pipeRef, bytes, size, timeout, timeout);
-
-    /* pipe bits may need to be cleared after a timeout. should this be done here or in user code? */
-    if (result == kIOUSBTransactionTimeout && (*(device->interface))->GetPipeStatus (device->interface, pipeRef) == kIOUSBPipeStalled)
-      usb_clear_halt (dev, ep);
-  } else
-#endif
-  {
-    if (usb_bt_read != 0)
-      result = (*(device->interface))->ReadPipe (device->interface, pipeRef, bytes, (UInt32 *)&size);
-    else
-      result = (*(device->interface))->WritePipe (device->interface, pipeRef, bytes, size);
-  }
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR (-darwin_to_errno (result), "libusb/darwin.c usb_bulk_transfer: %s", darwin_error_str (result));
-
-  return size;
-}
-
-#if 0
-/* NOT USED */
-/* argument to handle multiple parameters to rw_completed */
-struct rw_complete_arg {
-  UInt32        io_size;
-  IOReturn      result;
-  CFRunLoopRef  cf_loop;
-};
-
-static void rw_completed(void *refcon, io_return_t result, void *io_size)
-{
-  struct rw_complete_arg *rw_arg = (struct rw_complete_arg *)refcon;
-
-  if (usb_debug > 2)
-    fprintf(stderr, "io async operation completed: %s, size=%lu, result=0x%08x\n", darwin_error_str(result),
-           (UInt32)io_size, result);
-
-  rw_arg->io_size = (UInt32)io_size;
-  rw_arg->result  = result;
-
-  CFRunLoopStop(rw_arg->cf_loop);
-}
-
-static int usb_bulk_transfer_async (usb_dev_handle *dev, int ep, char *bytes, int size, int timeout,
-                             rw_async_func_t rw_async, rw_async_to_func_t rw_async_to)
-{
-  struct darwin_dev_handle *device;
-
-  io_return_t result = -1;
-
-  CFRunLoopSourceRef cfSource;
-  int pipeRef;
-
-  struct rw_complete_arg rw_arg;
-
-  u_int8_t  transferType;
-
-  /* None of the values below are used in libusb for bulk transfers */
-  u_int8_t  direction, number, interval;
-  u_int16_t maxPacketSize;
-
-  if (!dev)
-    USB_ERROR_STR ( -ENXIO, "usb_bulk_transfer: Called with NULL device" );
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR_STR ( -ENOENT, "usb_bulk_transfer: Device not open" );
-
-  /* interface is not open */
-  if (!device->interface)
-    USB_ERROR_STR(-EACCES, "usb_bulk_transfer: Interface used before it was opened");
-
-
-  /* Set up transfer */
-  if ((pipeRef = ep_to_pipeRef(device, ep)) < 0)
-    USB_ERROR_STR ( -EINVAL, "usb_bulk_transfer: Invalid pipe reference" );
-
-  (*(device->interface))->GetPipeProperties (device->interface, pipeRef, &direction, &number,
-                                            &transferType, &maxPacketSize, &interval);
-
-  bzero((void *)&rw_arg, sizeof(struct rw_complete_arg));
-  rw_arg.cf_loop = CFRunLoopGetCurrent();
-  CFRetain (rw_arg.cf_loop);
-
-  (*(device->interface))->CreateInterfaceAsyncEventSource(device->interface, &cfSource);
-  CFRunLoopAddSource(rw_arg.cf_loop, cfSource, kCFRunLoopDefaultMode);
-  /* Transfer set up complete */
-
-  if (usb_debug > 0)
-    fprintf (stderr, "libusb/darwin.c usb_bulk_transfer: Transfering %i bytes of data on endpoint 0x%02x\n",
-            size, ep);
-
-  /* Bulk transfer */
-  if (transferType == kUSBInterrupt && usb_debug > 3)
-    fprintf (stderr, "libusb/darwin.c usb_bulk_transfer: USB pipe is an interrupt pipe. Timeouts will not be used.\n");
-
-  if ( transferType != kUSBInterrupt && rw_async_to != NULL)
-
-    result = rw_async_to (device->interface, pipeRef, bytes, size, timeout, timeout,
-                         (IOAsyncCallback1)rw_completed, (void *)&rw_arg);
-  else
-    result = rw_async (device->interface, pipeRef, bytes, size, (IOAsyncCallback1)rw_completed,
-                      (void *)&rw_arg);
-
-  if (result == kIOReturnSuccess) {
-    /* wait for write to complete */
-    if (CFRunLoopRunInMode(kCFRunLoopDefaultMode, (timeout+999)/1000, true) == kCFRunLoopRunTimedOut) {
-      (*(device->interface))->AbortPipe(device->interface, pipeRef);
-      CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); /* Pick up aborted callback */
-      if (usb_debug)
-       fprintf(stderr, "usb_bulk_transfer: timed out\n");
-    }
-  }
-
-  CFRunLoopRemoveSource(rw_arg.cf_loop, cfSource, kCFRunLoopDefaultMode);
-  CFRelease (rw_arg.cf_loop);
-  
-  /* Check the return code of both the write and completion functions. */
-  if (result != kIOReturnSuccess || (rw_arg.result != kIOReturnSuccess && 
-      rw_arg.result != kIOReturnAborted) ) {
-    int error_code;
-    char *error_str;
-
-    if (result == kIOReturnSuccess) {
-      error_code = darwin_to_errno (rw_arg.result);
-      error_str  = darwin_error_str (rw_arg.result);
-    } else {
-      error_code = darwin_to_errno(result);
-      error_str  = darwin_error_str (result);
-    }
-    
-    if (transferType != kUSBInterrupt && rw_async_to != NULL)
-      USB_ERROR_STR(-error_code, "usb_bulk_transfer (w/ Timeout): %s", error_str);
-    else
-      USB_ERROR_STR(-error_code, "usb_bulk_transfer (No Timeout): %s", error_str);
-  }
-
-  return rw_arg.io_size;
-}
-#endif
-
-int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout)
-{
-  int result;
-  
-  if (dev == NULL || dev->impl_info == NULL)
-    return -EINVAL;
-
-  if ((result = usb_bulk_transfer (dev, ep, bytes, size, timeout, 0)) < 0)
-    USB_ERROR_STR (result, "usb_bulk_write: An error occured during write (see messages above)");
-  
-  return result;
-}
-
-int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout)
-{
-  int result;
-  
-  if (dev == NULL || dev->impl_info == NULL)
-    return -EINVAL;
-
-  ep |= 0x80;
-
-  if ((result = usb_bulk_transfer (dev, ep, bytes, size, timeout, 1)) < 0)
-    USB_ERROR_STR (result, "usb_bulk_read: An error occured during read (see messages above)");
-  
-  return result;
-}
-
-/* interrupt endpoints appear to be treated the same as non-interrupt endpoints under OSX/Darwin */
-int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout)
-{
-  return usb_bulk_write (dev, ep, bytes, size, timeout);
-}
-
-int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout)
-{
-  return usb_bulk_read (dev, ep, bytes, size, timeout);
-}
-
-int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
-                   int value, int index, char *bytes, int size, int timeout)
-{
-  struct darwin_dev_handle *device = dev->impl_info;
-
-  io_return_t result;
-
-#if !defined (LIBUSB_NO_TIMEOUT_DEVICE)
-  IOUSBDevRequestTO urequest;
-#else
-  IOUSBDevRequest urequest;
-#endif
-
-  if (usb_debug >= 3)
-    fprintf(stderr, "libusb/darwin.c usb_control_msg (device: %s): %d %d %d %d %p %d %d\n",
-            dev->device->filename, requesttype, request, value, index, bytes, size, timeout);
-
-  bzero(&urequest, sizeof(urequest));
-
-  urequest.bmRequestType = requesttype;
-  urequest.bRequest = request;
-  urequest.wValue = value;
-  urequest.wIndex = index;
-  urequest.wLength = size;
-  urequest.pData = bytes;
-#if !defined (LIBUSB_NO_TIMEOUT_DEVICE)
-  urequest.completionTimeout = timeout;
-  urequest.noDataTimeout = timeout;
-
-  result = (*(device->device))->DeviceRequestTO(device->device, &urequest);
-#else
-  result = (*(device->device))->DeviceRequest(device->device, &urequest);
-#endif
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "libusb/darwin.c usb_control_msg(DeviceRequestTO): %s", darwin_error_str(result));
-
-  /* Bytes transfered is stored in the wLenDone field*/
-  return urequest.wLenDone;
-}
-
-int usb_os_find_busses(struct usb_bus **busses)
-{
-  struct usb_bus *fbus = NULL;
-
-  io_iterator_t deviceIterator;
-  io_return_t result;
-
-  usb_device_t **device;
-
-  UInt32 location;
-
-  char buf[20];
-  int i = 1;
-
-  /* Create a master port for communication with IOKit (this should
-     have been created if the user called usb_init() )*/
-  if (masterPort == MACH_PORT_NULL) {
-    usb_init ();
-
-    if (masterPort == MACH_PORT_NULL)
-      USB_ERROR(-ENOENT);
-  }
-
-  if ((result = usb_setup_iterator (&deviceIterator)) < 0)
-    return result;
-
-  while ((device = usb_get_next_device (deviceIterator, &location)) != NULL) {
-    struct usb_bus *bus;
-
-    if (location & 0x00ffffff)
-      continue;
-
-    bus = calloc(1, sizeof(struct usb_bus));
-    if (bus == NULL)
-      USB_ERROR(-ENOMEM);
-    
-    sprintf(buf, "%03i", i++);
-    bus->location = location;
-
-    strncpy(bus->dirname, buf, sizeof(bus->dirname) - 1);
-    bus->dirname[sizeof(bus->dirname) - 1] = 0;
-    
-    LIST_ADD(fbus, bus);
-    
-    if (usb_debug >= 2)
-      fprintf(stderr, "usb_os_find_busses: Found %s\n", bus->dirname);
-
-    (*(device))->Release(device);
-  }
-
-  IOObjectRelease(deviceIterator);
-
-  *busses = fbus;
-
-  return 0;
-}
-
-int usb_os_find_devices(struct usb_bus *bus, struct usb_device **devices)
-{
-  struct usb_device *fdev = NULL;
-
-  io_iterator_t deviceIterator;
-  io_return_t result;
-
-  usb_device_t **device;
-
-  u_int16_t address;
-  UInt32 location;
-  UInt32 bus_loc = bus->location;
-  int devnum;
-
-  /* for use in retrieving device description */
-  IOUSBDevRequest req;
-
-  /* a master port should have been created by usb_os_init */
-  if (masterPort == MACH_PORT_NULL)
-    USB_ERROR(-ENOENT);
-
-  if ((result = usb_setup_iterator (&deviceIterator)) < 0)
-    return result;
-
-  /* Set up request for device descriptor */
-  req.bmRequestType = USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
-  req.bRequest = kUSBRqGetDescriptor;
-  req.wValue = kUSBDeviceDesc << 8;
-  req.wIndex = 0;
-  req.wLength = sizeof(IOUSBDeviceDescriptor);
-
-  devnum = 0;
-
-  while ((device = usb_get_next_device (deviceIterator, &location)) != NULL) {
-    unsigned char device_desc[DEVICE_DESC_LENGTH];
-    UInt8 bDeviceClass, bDeviceSubClass;
-    UInt16 idVendor, idProduct;
-
-    result = (*(device))->GetDeviceAddress(device, (USBDeviceAddress *)&address);
-
-    if (result == kIOReturnSuccess) {
-      (*(device))->GetDeviceClass (device, &bDeviceClass);
-      (*(device))->GetDeviceSubClass (device, &bDeviceSubClass);
-      (*(device))->GetDeviceProduct (device, &idProduct);
-      (*(device))->GetDeviceVendor (device, &idVendor);
-
-      if ((location >> 24) == (bus_loc >> 24)) {
-       struct usb_device *dev;
-
-       if (usb_debug >= 2)
-         fprintf(stderr, "libusb/darwin.c usb_os_find_devices: Found USB device on bus 0x%08lx: 0x%08lx\n",
-                 bus_loc, location);
-
-       dev = calloc(1, sizeof(struct usb_device));
-       if (dev == NULL)
-         USB_ERROR(-ENOMEM);
-
-       dev->bus = bus;
-
-       /* retrieve device descriptor */
-       req.pData = device_desc;
-       result = (*(device))->DeviceRequest(device, &req);
-
-       if (result != kIOReturnSuccess) {
-         free (dev);
-
-         if (usb_debug)
-           fprintf (stderr, "libusb/darwin.c usb_os_find_devices: Could not retrieve device descriptor: %s. Skipping device.\n",
-                    darwin_error_str(result));
-       
-         /* release the device now */
-         (*(device))->Release(device);
-         continue; /* can't continue without a descriptor */
-       }
-
-       usb_parse_descriptor(device_desc, "bbwbbbbwwwbbbb", &dev->descriptor);
-
-       /* catch buggy hubs (which appear to be virtual). Apple's own USB prober has problems with these devices */
-       if (dev->descriptor.idProduct != idProduct) {
-         free (dev);
-
-         if (usb_debug)
-           fprintf (stderr, "libusb/darwin.c usb_os_find_devices: idProduct from iokit does not match idProduct in descriptor. Skipping device\n");
-
-         /* release the device now */
-          (*(device))->Release(device);
-          continue; /* can't continue without a descriptor */
-       }
-
-       dev->devnum = devnum++;
-
-       sprintf(dev->filename, "%03i-%04x-%04x-%02x-%02x", address, idVendor, idProduct, bDeviceClass, bDeviceSubClass);
-
-       dev->dev = (USBDeviceAddress *) calloc (1, 4);
-       if (dev->dev == NULL)
-         USB_ERROR(-ENOMEM);
-
-       memcpy(dev->dev, &location, 4);
-
-       LIST_ADD(fdev, dev);
-
-       if (usb_debug >= 2)
-         fprintf(stderr, "libusb/darwin.c usb_os_find_devices: Found %s on %s at location 0x%08lx\n",
-                 dev->filename, bus->dirname, location);
-      }
-    } else if (usb_debug)
-      fprintf (stderr, "libusb/darwin.c usb_os_find_devices: Could not retrieve device address: %s\n",
-              darwin_error_str(result));
-
-    /* release the device now */
-    (*(device))->Release(device);
-  }
-
-  IOObjectRelease(deviceIterator);
-
-  *devices = fdev;
-
-  if (usb_debug)
-    fprintf (stderr, "libusb/darwin.c usb_os_find_devices: Complete\n");
-
-  return 0;
-}
-
-int usb_os_determine_children(struct usb_bus *bus)
-{
-  /* Nothing yet */
-  return 0;
-}
-
-void usb_os_init(void)
-{
-  if (masterPort == MACH_PORT_NULL) {
-    IOMasterPort(masterPort, &masterPort);
-    
-    gNotifyPort = IONotificationPortCreate(masterPort);
-  }
-}
-
-void usb_os_cleanup (void)
-{
-  if (masterPort != MACH_PORT_NULL)
-    darwin_cleanup ();
-}
-
-int usb_resetep(usb_dev_handle *dev, unsigned int ep)
-{
-  struct darwin_dev_handle *device;
-
-  io_return_t result = -1;
-
-  int pipeRef;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR(-ENOENT);
-
-  /* interface is not open */
-  if (!device->interface)
-    USB_ERROR_STR(-EACCES, "usb_resetep: interface used without being claimed");
-
-  if ((pipeRef = ep_to_pipeRef(device, ep)) == -1)
-    USB_ERROR(-EINVAL);
-
-  result = (*(device->interface))->ResetPipe(device->interface, pipeRef);
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_resetep(ResetPipe): %s", darwin_error_str(result));
-
-  return 0;
-}
-
-int usb_clear_halt(usb_dev_handle *dev, unsigned int ep)
-{
-  struct darwin_dev_handle *device;
-
-  io_return_t result = -1;
-
-  int pipeRef;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR(-ENOENT);
-
-  /* interface is not open */
-  if (!device->interface)
-    USB_ERROR_STR(-EACCES, "usb_clear_halt: interface used without being claimed");
-
-  if ((pipeRef = ep_to_pipeRef(device, ep)) == -1)
-    USB_ERROR(-EINVAL);
-
-#if (InterfaceVersion < 190)
-  result = (*(device->interface))->ClearPipeStall(device->interface, pipeRef);
-#else
-  /* newer versions of darwin support clearing additional bits on the device's endpoint */
-  result = (*(device->interface))->ClearPipeStallBothEnds(device->interface, pipeRef);
-#endif
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_clear_halt(ClearPipeStall): %s", darwin_error_str(result));
-
-  return 0;
-}
-
-int usb_reset(usb_dev_handle *dev)
-{
-  struct darwin_dev_handle *device;
-  
-  io_return_t result;
-
-  if (!dev)
-    USB_ERROR(-ENXIO);
-
-  if ((device = dev->impl_info) == NULL)
-    USB_ERROR(-ENOENT);
-
-  if (!device->device)
-    USB_ERROR_STR(-ENOENT, "usb_reset: no such device");
-
-  result = (*(device->device))->ResetDevice(device->device);
-
-  if (result != kIOReturnSuccess)
-    USB_ERROR_STR(-darwin_to_errno(result), "usb_reset(ResetDevice): %s", darwin_error_str(result));
-  
-  return 0;
-}
diff --git a/deps/libusb/descriptors.c b/deps/libusb/descriptors.c
deleted file mode 100644 (file)
index f7fc784..0000000
+++ /dev/null
@@ -1,535 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * Parses descriptors
- *
- * Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
- *
- * This library is covered by the LGPL, read LICENSE for details.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include "usbi.h"
-
-int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
-       unsigned char type, unsigned char index, void *buf, int size)
-{
-  memset(buf, 0, size);
-
-  return usb_control_msg(udev, ep | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
-                        (type << 8) + index, 0, buf, size, 1000);
-}
-
-int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
-       unsigned char index, void *buf, int size)
-{
-  memset(buf, 0, size);
-
-  return usb_control_msg(udev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
-                        (type << 8) + index, 0, buf, size, 1000);
-}
-
-int usb_parse_descriptor(unsigned char *source, char *description, void *dest)
-{
-  unsigned char *sp = source, *dp = dest;
-  uint16_t w;
-  uint32_t d;
-  char *cp;
-
-  for (cp = description; *cp; cp++) {
-    switch (*cp) {
-    case 'b':  /* 8-bit byte */
-      *dp++ = *sp++;
-      break;
-    case 'w':  /* 16-bit word, convert from little endian to CPU */
-      w = (sp[1] << 8) | sp[0]; sp += 2;
-      dp += ((unsigned long)dp & 1);   /* Align to word boundary */
-      *((uint16_t *)dp) = w; dp += 2;
-      break;
-    case 'd':  /* 32-bit dword, convert from little endian to CPU */
-      d = (sp[3] << 24) | (sp[2] << 16) | (sp[1] << 8) | sp[0]; sp += 4;
-      dp += ((unsigned long)dp & 2);   /* Align to dword boundary */
-      *((uint32_t *)dp) = d; dp += 4;
-      break;
-    /* These two characters are undocumented and just a hack for Linux */
-    case 'W':  /* 16-bit word, keep CPU endianess */
-      dp += ((unsigned long)dp & 1);   /* Align to word boundary */
-      memcpy(dp, sp, 2); sp += 2; dp += 2;
-      break;
-    case 'D':  /* 32-bit dword, keep CPU endianess */
-      dp += ((unsigned long)dp & 2);   /* Align to dword boundary */
-      memcpy(dp, sp, 4); sp += 4; dp += 4;
-      break;
-    }
-  }
-
-  return sp - source;
-}
-
-/*
- * This code looks surprisingly similar to the code I wrote for the Linux
- * kernel. It's not a coincidence :)
- */
-
-static int usb_parse_endpoint(struct usb_endpoint_descriptor *endpoint, unsigned char *buffer, int size)
-{
-  struct usb_descriptor_header header;
-  unsigned char *begin;
-  int parsed = 0, len, numskipped;
-
-  usb_parse_descriptor(buffer, "bb", &header);
-
-  /* Everything should be fine being passed into here, but we sanity */
-  /*  check JIC */
-  if (header.bLength > size) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "ran out of descriptors parsing\n");
-    return -1;
-  }
-                
-  if (header.bDescriptorType != USB_DT_ENDPOINT) {
-    if (usb_debug >= 2)
-      fprintf(stderr, "unexpected descriptor 0x%X, expecting endpoint descriptor, type 0x%X\n",
-         header.bDescriptorType, USB_DT_ENDPOINT);
-    return parsed;
-  }
-
-  if (header.bLength >= ENDPOINT_AUDIO_DESC_LENGTH)
-    usb_parse_descriptor(buffer, "bbbbwbbb", endpoint);
-  else if (header.bLength >= ENDPOINT_DESC_LENGTH)
-    usb_parse_descriptor(buffer, "bbbbwb", endpoint);
-
-  buffer += header.bLength;
-  size -= header.bLength;
-  parsed += header.bLength;
-
-  /* Skip over the rest of the Class Specific or Vendor Specific */
-  /*  descriptors */
-  begin = buffer;
-  numskipped = 0;
-  while (size >= DESC_HEADER_LENGTH) {
-    usb_parse_descriptor(buffer, "bb", &header);
-
-    if (header.bLength < 2) {
-      if (usb_debug >= 1)
-        fprintf(stderr, "invalid descriptor length of %d\n", header.bLength);
-      return -1;
-    }
-
-    /* If we find another "proper" descriptor then we're done  */
-    if ((header.bDescriptorType == USB_DT_ENDPOINT) ||
-        (header.bDescriptorType == USB_DT_INTERFACE) ||
-        (header.bDescriptorType == USB_DT_CONFIG) ||
-        (header.bDescriptorType == USB_DT_DEVICE))
-      break;
-
-    if (usb_debug >= 1)
-      fprintf(stderr, "skipping descriptor 0x%X\n", header.bDescriptorType);
-    numskipped++;
-
-    buffer += header.bLength;
-    size -= header.bLength;
-    parsed += header.bLength;
-  }
-
-  if (numskipped && usb_debug >= 2)
-    fprintf(stderr, "skipped %d class/vendor specific endpoint descriptors\n", numskipped);
-
-  /* Copy any unknown descriptors into a storage area for drivers */
-  /*  to later parse */
-  len = (int)(buffer - begin);
-  if (!len) {
-    endpoint->extra = NULL;
-    endpoint->extralen = 0;
-    return parsed;
-  }
-
-  endpoint->extra = malloc(len);
-  if (!endpoint->extra) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "couldn't allocate memory for endpoint extra descriptors\n");
-    endpoint->extralen = 0;
-    return parsed;
-  }
-
-  memcpy(endpoint->extra, begin, len);
-  endpoint->extralen = len;
-
-  return parsed;
-}
-
-static int usb_parse_interface(struct usb_interface *interface,
-       unsigned char *buffer, int size)
-{
-  int i, len, numskipped, retval, parsed = 0;
-  struct usb_descriptor_header header;
-  struct usb_interface_descriptor *ifp;
-  unsigned char *begin;
-
-  interface->num_altsetting = 0;
-
-  while (size >= INTERFACE_DESC_LENGTH) {
-    interface->altsetting = realloc(interface->altsetting, sizeof(struct usb_interface_descriptor) * (interface->num_altsetting + 1));
-    if (!interface->altsetting) {
-      if (usb_debug >= 1)
-        fprintf(stderr, "couldn't malloc interface->altsetting\n");
-      return -1;
-    }
-
-    ifp = interface->altsetting + interface->num_altsetting;
-    interface->num_altsetting++;
-
-    usb_parse_descriptor(buffer, "bbbbbbbbb", ifp);
-
-    /* Skip over the interface */
-    buffer += ifp->bLength;
-    parsed += ifp->bLength;
-    size -= ifp->bLength;
-
-    begin = buffer;
-    numskipped = 0;
-
-    /* Skip over any interface, class or vendor descriptors */
-    while (size >= DESC_HEADER_LENGTH) {
-      usb_parse_descriptor(buffer, "bb", &header);
-
-      if (header.bLength < 2) {
-        if (usb_debug >= 1)
-          fprintf(stderr, "invalid descriptor length of %d\n", header.bLength);
-        return -1;
-      }
-
-      /* If we find another "proper" descriptor then we're done */
-      if ((header.bDescriptorType == USB_DT_INTERFACE) ||
-          (header.bDescriptorType == USB_DT_ENDPOINT) ||
-          (header.bDescriptorType == USB_DT_CONFIG) ||
-          (header.bDescriptorType == USB_DT_DEVICE))
-        break;
-
-      numskipped++;
-
-      buffer += header.bLength;
-      parsed += header.bLength;
-      size -= header.bLength;
-    }
-
-    if (numskipped && usb_debug >= 2)
-      fprintf(stderr, "skipped %d class/vendor specific interface descriptors\n", numskipped);
-
-    /* Copy any unknown descriptors into a storage area for */
-    /*  drivers to later parse */
-    len = (int)(buffer - begin);
-    if (!len) {
-      ifp->extra = NULL;
-      ifp->extralen = 0;
-    } else {
-      ifp->extra = malloc(len);
-      if (!ifp->extra) {
-        if (usb_debug >= 1)
-          fprintf(stderr, "couldn't allocate memory for interface extra descriptors\n");
-        ifp->extralen = 0;
-        return -1;
-      }
-      memcpy(ifp->extra, begin, len);
-      ifp->extralen = len;
-    }
-
-    /* Did we hit an unexpected descriptor? */
-    usb_parse_descriptor(buffer, "bb", &header);
-    if ((size >= DESC_HEADER_LENGTH) &&
-        ((header.bDescriptorType == USB_DT_CONFIG) ||
-        (header.bDescriptorType == USB_DT_DEVICE)))
-      return parsed;
-
-    if (ifp->bNumEndpoints > USB_MAXENDPOINTS) {
-      if (usb_debug >= 1)
-        fprintf(stderr, "too many endpoints\n");
-      return -1;
-    }
-
-    if (ifp->bNumEndpoints > 0) {
-      ifp->endpoint = (struct usb_endpoint_descriptor *)
-                       malloc(ifp->bNumEndpoints *
-                       sizeof(struct usb_endpoint_descriptor));
-      if (!ifp->endpoint) {
-        if (usb_debug >= 1)
-          fprintf(stderr, "couldn't allocate memory for ifp->endpoint\n");
-        return -1;      
-      }
-
-      memset(ifp->endpoint, 0, ifp->bNumEndpoints *
-             sizeof(struct usb_endpoint_descriptor));
-
-      for (i = 0; i < ifp->bNumEndpoints; i++) {
-        usb_parse_descriptor(buffer, "bb", &header);
-  
-        if (header.bLength > size) {
-          if (usb_debug >= 1)
-            fprintf(stderr, "ran out of descriptors parsing\n");
-          return -1;
-        }
-                
-        retval = usb_parse_endpoint(ifp->endpoint + i, buffer, size);
-        if (retval < 0)
-          return retval;
-
-        buffer += retval;
-        parsed += retval;
-        size -= retval;
-      }
-    } else
-      ifp->endpoint = NULL;
-
-    /* We check to see if it's an alternate to this one */
-    ifp = (struct usb_interface_descriptor *)buffer;
-    if (size < USB_DT_INTERFACE_SIZE ||
-        ifp->bDescriptorType != USB_DT_INTERFACE ||
-        !ifp->bAlternateSetting)
-      return parsed;
-  }
-
-  return parsed;
-}
-
-int usb_parse_configuration(struct usb_config_descriptor *config,
-       unsigned char *buffer)
-{
-  int i, retval, size;
-  struct usb_descriptor_header header;
-
-  usb_parse_descriptor(buffer, "bbwbbbbb", config);
-  size = config->wTotalLength;
-
-  if (config->bNumInterfaces > USB_MAXINTERFACES) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "too many interfaces\n");
-    return -1;
-  }
-
-  config->interface = (struct usb_interface *)
-                       malloc(config->bNumInterfaces *
-                       sizeof(struct usb_interface));
-  if (!config->interface) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "out of memory\n");
-    return -1;      
-  }
-
-  memset(config->interface, 0, config->bNumInterfaces * sizeof(struct usb_interface));
-
-  buffer += config->bLength;
-  size -= config->bLength;
-        
-  config->extra = NULL;
-  config->extralen = 0;
-
-  for (i = 0; i < config->bNumInterfaces; i++) {
-    int numskipped, len;
-    unsigned char *begin;
-
-    /* Skip over the rest of the Class Specific or Vendor */
-    /*  Specific descriptors */
-    begin = buffer;
-    numskipped = 0;
-    while (size >= DESC_HEADER_LENGTH) {
-      usb_parse_descriptor(buffer, "bb", &header);
-
-      if ((header.bLength > size) || (header.bLength < DESC_HEADER_LENGTH)) {
-        if (usb_debug >= 1)
-          fprintf(stderr, "invalid descriptor length of %d\n", header.bLength);
-        return -1;
-      }
-
-      /* If we find another "proper" descriptor then we're done */
-      if ((header.bDescriptorType == USB_DT_ENDPOINT) ||
-          (header.bDescriptorType == USB_DT_INTERFACE) ||
-          (header.bDescriptorType == USB_DT_CONFIG) ||
-          (header.bDescriptorType == USB_DT_DEVICE))
-        break;
-
-      if (usb_debug >= 2)
-        fprintf(stderr, "skipping descriptor 0x%X\n", header.bDescriptorType);
-      numskipped++;
-
-      buffer += header.bLength;
-      size -= header.bLength;
-    }
-
-    if (numskipped && usb_debug >= 2)
-      fprintf(stderr, "skipped %d class/vendor specific endpoint descriptors\n", numskipped);
-
-    /* Copy any unknown descriptors into a storage area for */
-    /*  drivers to later parse */
-    len = (int)(buffer - begin);
-    if (len) {
-      /* FIXME: We should realloc and append here */
-      if (!config->extralen) {
-        config->extra = malloc(len);
-        if (!config->extra) {
-          if (usb_debug >= 1)
-            fprintf(stderr, "couldn't allocate memory for config extra descriptors\n");
-          config->extralen = 0;
-          return -1;
-        }
-
-        memcpy(config->extra, begin, len);
-        config->extralen = len;
-      }
-    }
-
-    retval = usb_parse_interface(config->interface + i, buffer, size);
-    if (retval < 0)
-      return retval;
-
-    buffer += retval;
-    size -= retval;
-  }
-
-  return size;
-}
-
-void usb_destroy_configuration(struct usb_device *dev)
-{
-  int c, i, j, k;
-        
-  if (!dev->config)
-    return;
-
-  for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
-    struct usb_config_descriptor *cf = &dev->config[c];
-
-    if (!cf->interface)
-      continue;
-
-    for (i = 0; i < cf->bNumInterfaces; i++) {
-      struct usb_interface *ifp = &cf->interface[i];
-                                
-      if (!ifp->altsetting)
-        continue;
-
-      for (j = 0; j < ifp->num_altsetting; j++) {
-        struct usb_interface_descriptor *as = &ifp->altsetting[j];
-                                        
-        if (as->extra)
-          free(as->extra);
-
-        if (!as->endpoint)
-          continue;
-                                        
-        for (k = 0; k < as->bNumEndpoints; k++) {
-          if (as->endpoint[k].extra)
-            free(as->endpoint[k].extra);
-        }       
-        free(as->endpoint);
-      }
-
-      free(ifp->altsetting);
-    }
-
-    free(cf->interface);
-  }
-
-  free(dev->config);
-}
-
-void usb_fetch_and_parse_descriptors(usb_dev_handle *udev)
-{
-  struct usb_device *dev = udev->device;
-  int i;
-
-  if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "Too many configurations (%d > %d)\n", dev->descriptor.bNumConfigurations, USB_MAXCONFIG);
-    return;
-  }
-
-  if (dev->descriptor.bNumConfigurations < 1) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "Not enough configurations (%d < %d)\n", dev->descriptor.bNumConfigurations, 1);
-    return;
-  }
-
-  dev->config = (struct usb_config_descriptor *)malloc(dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor));
-  if (!dev->config) {
-    if (usb_debug >= 1)
-      fprintf(stderr, "Unable to allocate memory for config descriptor\n");
-    return;
-  }
-
-  memset(dev->config, 0, dev->descriptor.bNumConfigurations *
-       sizeof(struct usb_config_descriptor));
-
-  for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
-    unsigned char buffer[8], *bigbuffer;
-    struct usb_config_descriptor config;
-    int res;
-
-    /* Get the first 8 bytes so we can figure out what the total length is */
-    res = usb_get_descriptor(udev, USB_DT_CONFIG, i, buffer, 8);
-    if (res < 8) {
-      if (usb_debug >= 1) {
-        if (res < 0)
-          fprintf(stderr, "Unable to get descriptor (%d)\n", res);
-        else
-          fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", 8, res);
-      }
-
-      goto err;
-    }
-
-    usb_parse_descriptor(buffer, "bbw", &config);
-
-    bigbuffer = malloc(config.wTotalLength);
-    if (!bigbuffer) {
-      if (usb_debug >= 1)
-        fprintf(stderr, "Unable to allocate memory for descriptors\n");
-      goto err;
-    }
-
-    res = usb_get_descriptor(udev, USB_DT_CONFIG, i, bigbuffer, config.wTotalLength);
-    if (res < config.wTotalLength) {
-      if (usb_debug >= 1) {
-        if (res < 0)
-          fprintf(stderr, "Unable to get descriptor (%d)\n", res);
-        else
-          fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", config.wTotalLength, res);
-      }
-
-      free(bigbuffer);
-      goto err;
-    }
-
-    res = usb_parse_configuration(&dev->config[i], bigbuffer);
-    if (usb_debug >= 2) {
-      if (res > 0)
-        fprintf(stderr, "Descriptor data still left\n");
-      else if (res < 0)
-        fprintf(stderr, "Unable to parse descriptors\n");
-    }
-
-    free(bigbuffer);
-  }
-
-  return;
-
-err:
-  free(dev->config);
-
-  dev->config = NULL;
-}
-
diff --git a/deps/libusb/error.c b/deps/libusb/error.c
deleted file mode 100644 (file)
index 9212e86..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * USB Error messages
- *
- * Copyright (c) 2000-2001 Johannes Erdfelt <johannes@erdfelt.com>
- *
- * This library is covered by the LGPL, read LICENSE for details.
- */
-
-#include <errno.h>
-#include <string.h>
-
-#include "usb.h"
-#include "error.h"
-
-char usb_error_str[1024] = "";
-int usb_error_errno = 0;
-usb_error_type_t usb_error_type = USB_ERROR_TYPE_NONE;
-
-char *usb_strerror(void)
-{
-  switch (usb_error_type) {
-  case USB_ERROR_TYPE_NONE:
-    return "No error";
-  case USB_ERROR_TYPE_STRING:
-    return usb_error_str;
-  case USB_ERROR_TYPE_ERRNO:
-    if (usb_error_errno > -USB_ERROR_BEGIN)
-      return strerror(usb_error_errno);
-    else
-      /* Any error we don't know falls under here */
-      return "Unknown error";
-  }
-
-  return "Unknown error";
-}
-
diff --git a/deps/libusb/error.h b/deps/libusb/error.h
deleted file mode 100644 (file)
index c980e22..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef _ERROR_H_
-#define _ERROR_H_
-
-typedef enum {
-  USB_ERROR_TYPE_NONE = 0,
-  USB_ERROR_TYPE_STRING,
-  USB_ERROR_TYPE_ERRNO,
-} usb_error_type_t;
-
-extern char usb_error_str[1024];
-extern int usb_error_errno;
-extern usb_error_type_t usb_error_type;
-
-#define USB_ERROR(x) \
-       do { \
-          usb_error_type = USB_ERROR_TYPE_ERRNO; \
-          usb_error_errno = x; \
-         return x; \
-       } while (0)
-
-#define USB_ERROR_STR(x, format, args...) \
-       do { \
-         usb_error_type = USB_ERROR_TYPE_STRING; \
-         snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \
-          if (usb_debug >= 2) \
-            fprintf(stderr, "USB error: %s\n", usb_error_str); \
-         return x; \
-       } while (0)
-
-#endif /* _ERROR_H_ */
-
diff --git a/deps/libusb/linux.c b/deps/libusb/linux.c
deleted file mode 100644 (file)
index 6b13afb..0000000
+++ /dev/null
@@ -1,748 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * Linux USB support
- *
- * Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
- *
- * This library is covered by the LGPL, read LICENSE for details.
- */
-
-#include <stdlib.h>    /* getenv, etc */
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <dirent.h>
-
-#include "linux.h"
-#include "usbi.h"
-
-static char usb_path[PATH_MAX + 1] = "";
-
-static int device_open(struct usb_device *dev)
-{
-  char filename[PATH_MAX + 1];
-  int fd;
-
-  snprintf(filename, sizeof(filename) - 1, "%s/%s/%s",
-    usb_path, dev->bus->dirname, dev->filename);
-
-  fd = open(filename, O_RDWR);
-  if (fd < 0) {
-    fd = open(filename, O_RDONLY);
-    if (fd < 0)
-      USB_ERROR_STR(-errno, "failed to open %s: %s",
-       filename, strerror(errno));
-  }
-
-  return fd;
-}
-
-int usb_os_open(usb_dev_handle *dev)
-{
-  dev->fd = device_open(dev->device);
-
-  return 0;
-}
-
-int usb_os_close(usb_dev_handle *dev)
-{
-  if (dev->fd < 0)
-    return 0;
-
-  if (close(dev->fd) == -1)
-    /* Failing trying to close a file really isn't an error, so return 0 */
-    USB_ERROR_STR(0, "tried to close device fd %d: %s", dev->fd,
-       strerror(errno));
-
-  return 0;
-}
-
-int usb_set_configuration(usb_dev_handle *dev, int configuration)
-{
-  int ret;
-
-  ret = ioctl(dev->fd, IOCTL_USB_SETCONFIG, &configuration);
-  if (ret < 0)
-    USB_ERROR_STR(-errno, "could not set config %d: %s", configuration,
-       strerror(errno));
-
-  dev->config = configuration;
-
-  return 0;
-}
-
-int usb_claim_interface(usb_dev_handle *dev, int interface)
-{
-  int ret;
-
-  ret = ioctl(dev->fd, IOCTL_USB_CLAIMINTF, &interface);
-  if (ret < 0) {
-    if (errno == EBUSY && usb_debug > 0)
-      fprintf(stderr, "Check that you have permissions to write to %s/%s and, if you don't, that you set up hotplug (http://linux-hotplug.sourceforge.net/) correctly.\n", dev->bus->dirname, dev->device->filename);
-
-    USB_ERROR_STR(-errno, "could not claim interface %d: %s", interface,
-       strerror(errno));
-  }
-
-  dev->interface = interface;
-
-  return 0;
-}
-
-int usb_release_interface(usb_dev_handle *dev, int interface)
-{
-  int ret;
-
-  ret = ioctl(dev->fd, IOCTL_USB_RELEASEINTF, &interface);
-  if (ret < 0)
-    USB_ERROR_STR(-errno, "could not release intf %d: %s", interface,
-       strerror(errno));
-
-  dev->interface = -1;
-
-  return 0;
-}
-
-int usb_set_altinterface(usb_dev_handle *dev, int alternate)
-{
-  int ret;
-  struct usb_setinterface setintf;
-
-  if (dev->interface < 0)
-    USB_ERROR(-EINVAL);
-
-  setintf.interface = dev->interface;
-  setintf.altsetting = alternate;
-
-  ret = ioctl(dev->fd, IOCTL_USB_SETINTF, &setintf);
-  if (ret < 0)
-    USB_ERROR_STR(-errno, "could not set alt intf %d/%d: %s",
-       dev->interface, alternate, strerror(errno));
-
-  dev->altsetting = alternate;
-
-  return 0;
-}
-
-/*
- * Linux usbfs has a limit of one page size for synchronous bulk read/write.
- * 4096 is the most portable maximum we can do for now.
- * Linux usbfs has a limit of 16KB for the URB interface. We use this now
- * to get better performance for USB 2.0 devices.
- */
-#define MAX_READ_WRITE (16 * 1024)
-
-int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
-       int value, int index, char *bytes, int size, int timeout)
-{
-  struct usb_ctrltransfer ctrl;
-  int ret;
-
-  ctrl.bRequestType = requesttype;
-  ctrl.bRequest = request;
-  ctrl.wValue = value;
-  ctrl.wIndex = index;
-  ctrl.wLength = size;
-
-  ctrl.data = bytes;
-  ctrl.timeout = timeout;
-
-  ret = ioctl(dev->fd, IOCTL_USB_CONTROL, &ctrl);
-  if (ret < 0)
-    USB_ERROR_STR(-errno, "error sending control message: %s", strerror(errno));
-
-  return ret;
-}
-
-#define URB_USERCONTEXT_COOKIE         ((void *)0x1)
-
-/* Reading and writing are the same except for the endpoint */
-static int usb_urb_transfer(usb_dev_handle *dev, int ep, int urbtype,
-       char *bytes, int size, int timeout)
-{
-  struct usb_urb urb;
-  int bytesdone = 0, requested;
-  struct timeval tv, tv_ref, tv_now;
-  struct usb_urb *context;
-  int ret, waiting;
-
-  /*
-   * HACK: The use of urb.usercontext is a hack to get threaded applications
-   * sort of working again. Threaded support is still not recommended, but
-   * this should allow applications to work in the common cases. Basically,
-   * if we get the completion for an URB we're not waiting for, then we update
-   * the usercontext pointer to 1 for the other threads URB and it will see
-   * the change after it wakes up from the the timeout. Ugly, but it works.
-   */
-
-  /*
-   * Get actual time, and add the timeout value. The result is the absolute
-   * time where we have to quit waiting for an message.
-   */
-  gettimeofday(&tv_ref, NULL);
-  tv_ref.tv_sec = tv_ref.tv_sec + timeout / 1000;
-  tv_ref.tv_usec = tv_ref.tv_usec + (timeout % 1000) * 1000;
-
-  if (tv_ref.tv_usec > 1000000) {
-    tv_ref.tv_usec -= 1000000;
-    tv_ref.tv_sec++;
-  }
-
-  do {
-    fd_set writefds;
-
-    requested = size - bytesdone;
-    if (requested > MAX_READ_WRITE)
-      requested = MAX_READ_WRITE;
-
-    urb.type = urbtype;
-    urb.endpoint = ep;
-    urb.flags = 0;
-    urb.buffer = bytes + bytesdone;
-    urb.buffer_length = requested;
-    urb.signr = 0;
-    urb.actual_length = 0;
-    urb.number_of_packets = 0; /* don't do isochronous yet */
-    urb.usercontext = NULL;
-
-    ret = ioctl(dev->fd, IOCTL_USB_SUBMITURB, &urb);
-    if (ret < 0) {
-      USB_ERROR_STR(-errno, "error submitting URB: %s", strerror(errno));
-      return ret;
-    }
-
-    FD_ZERO(&writefds);
-    FD_SET(dev->fd, &writefds);
-
-restart:
-    waiting = 1;
-    context = NULL;
-    while (!urb.usercontext && ((ret = ioctl(dev->fd, IOCTL_USB_REAPURBNDELAY, &context)) == -1) && waiting) {
-      tv.tv_sec = 0;
-      tv.tv_usec = 1000; // 1 msec
-      select(dev->fd + 1, NULL, &writefds, NULL, &tv); //sub second wait
-
-      if (timeout) {
-        /* compare with actual time, as the select timeout is not that precise */
-        gettimeofday(&tv_now, NULL);
-
-        if ((tv_now.tv_sec > tv_ref.tv_sec) ||
-            ((tv_now.tv_sec == tv_ref.tv_sec) && (tv_now.tv_usec >= tv_ref.tv_usec)))
-          waiting = 0;
-      }
-    }
-
-    if (context && context != &urb) {
-      context->usercontext = URB_USERCONTEXT_COOKIE;
-      /* We need to restart since we got a successful URB, but not ours */
-      goto restart;
-    }
-
-    /*
-     * If there was an error, that wasn't EAGAIN (no completion), then
-     * something happened during the reaping and we should return that
-     * error now
-     */
-    if (ret < 0 && !urb.usercontext && errno != EAGAIN)
-      USB_ERROR_STR(-errno, "error reaping URB: %s", strerror(errno));
-
-    bytesdone += urb.actual_length;
-  } while ((ret == 0 || urb.usercontext) && bytesdone < size && urb.actual_length == requested);
-
-  /* If the URB didn't complete in success or error, then let's unlink it */
-  if (ret < 0 && !urb.usercontext) {
-    int rc;
-
-    if (!waiting)
-      rc = -ETIMEDOUT;
-    else
-      rc = urb.status;
-
-    ret = ioctl(dev->fd, IOCTL_USB_DISCARDURB, &urb);
-    if (ret < 0 && errno != EINVAL && usb_debug >= 1)
-      fprintf(stderr, "error discarding URB: %s", strerror(errno));
-
-    /*
-     * When the URB is unlinked, it gets moved to the completed list and
-     * then we need to reap it or else the next time we call this function,
-     * we'll get the previous completion and exit early
-     */
-    ioctl(dev->fd, IOCTL_USB_REAPURB, &context);
-
-    return rc;
-  }
-
-  return bytesdone;
-}
-
-int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout)
-{
-  /* Ensure the endpoint address is correct */
-  return usb_urb_transfer(dev, ep, USB_URB_TYPE_BULK, bytes, size,
-               timeout);
-}
-
-int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout)
-{
-  /* Ensure the endpoint address is correct */
-  ep |= USB_ENDPOINT_IN;
-  return usb_urb_transfer(dev, ep, USB_URB_TYPE_BULK, bytes, size,
-               timeout);
-}
-
-/*
- * FIXME: Packetize large buffers here. 2.4 HCDs (atleast, haven't checked
- * 2.5 HCDs yet) don't handle multi-packet Interrupt transfers. So we need
- * to lookup the endpoint packet size and packetize appropriately here.
- */
-int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout)
-{
-  /* Ensure the endpoint address is correct */
-  return usb_urb_transfer(dev, ep, USB_URB_TYPE_INTERRUPT, bytes, size,
-               timeout);
-}
-
-int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout)
-{
-  /* Ensure the endpoint address is correct */
-  ep |= USB_ENDPOINT_IN;
-  return usb_urb_transfer(dev, ep, USB_URB_TYPE_INTERRUPT, bytes, size,
-               timeout);
-}
-
-int usb_os_find_busses(struct usb_bus **busses)
-{
-  struct usb_bus *fbus = NULL;
-  DIR *dir;
-  struct dirent *entry;
-
-  dir = opendir(usb_path);
-  if (!dir)
-    USB_ERROR_STR(-errno, "couldn't opendir(%s): %s", usb_path,
-       strerror(errno));
-
-  while ((entry = readdir(dir)) != NULL) {
-    struct usb_bus *bus;
-
-    /* Skip anything starting with a . */
-    if (entry->d_name[0] == '.')
-      continue;
-
-    if (!strchr("0123456789", entry->d_name[strlen(entry->d_name) - 1])) {
-      if (usb_debug >= 2)
-        fprintf(stderr, "usb_os_find_busses: Skipping non bus directory %s\n",
-               entry->d_name);
-      continue;
-    }
-
-    bus = malloc(sizeof(*bus));
-    if (!bus)
-      USB_ERROR(-ENOMEM);
-
-    memset((void *)bus, 0, sizeof(*bus));
-
-    strncpy(bus->dirname, entry->d_name, sizeof(bus->dirname) - 1);
-    bus->dirname[sizeof(bus->dirname) - 1] = 0;
-
-    LIST_ADD(fbus, bus);
-
-    if (usb_debug >= 2)
-       fprintf(stderr, "usb_os_find_busses: Found %s\n", bus->dirname);
-  }
-
-  closedir(dir);
-
-  *busses = fbus;
-
-  return 0;
-}
-
-int usb_os_find_devices(struct usb_bus *bus, struct usb_device **devices)
-{
-  struct usb_device *fdev = NULL;
-  DIR *dir;
-  struct dirent *entry;
-  char dirpath[PATH_MAX + 1];
-
-  snprintf(dirpath, PATH_MAX, "%s/%s", usb_path, bus->dirname);
-
-  dir = opendir(dirpath);
-  if (!dir)
-    USB_ERROR_STR(-errno, "couldn't opendir(%s): %s", dirpath,
-       strerror(errno));
-
-  while ((entry = readdir(dir)) != NULL) {
-    unsigned char device_desc[DEVICE_DESC_LENGTH];
-    char filename[PATH_MAX + 1];
-    struct usb_device *dev;
-    struct usb_connectinfo connectinfo;
-    int i, fd, ret;
-
-    /* Skip anything starting with a . */
-    if (entry->d_name[0] == '.')
-      continue;
-
-    dev = malloc(sizeof(*dev));
-    if (!dev)
-      USB_ERROR(-ENOMEM);
-
-    memset((void *)dev, 0, sizeof(*dev));
-
-    dev->bus = bus;
-
-    strncpy(dev->filename, entry->d_name, sizeof(dev->filename) - 1);
-    dev->filename[sizeof(dev->filename) - 1] = 0;
-
-    snprintf(filename, sizeof(filename) - 1, "%s/%s", dirpath, entry->d_name);
-    fd = open(filename, O_RDWR);
-    if (fd < 0) {
-      fd = open(filename, O_RDONLY);
-      if (fd < 0) {
-        if (usb_debug >= 2)
-          fprintf(stderr, "usb_os_find_devices: Couldn't open %s\n",
-                  filename);
-
-        free(dev);
-        continue;
-      }
-    }
-
-    /* Get the device number */
-    ret = ioctl(fd, IOCTL_USB_CONNECTINFO, &connectinfo);
-    if (ret < 0) {
-      if (usb_debug)
-        fprintf(stderr, "usb_os_find_devices: couldn't get connect info\n");
-    } else
-      dev->devnum = connectinfo.devnum;
-
-    ret = read(fd, (void *)device_desc, DEVICE_DESC_LENGTH);
-    if (ret < 0) {
-      if (usb_debug)
-        fprintf(stderr, "usb_os_find_devices: Couldn't read descriptor\n");
-
-      free(dev);
-
-      goto err;
-    }
-
-    /*
-     * Linux kernel converts the words in this descriptor to CPU endian, so
-     * we use the undocumented W character for usb_parse_descriptor() that
-     * doesn't convert endianess when parsing the descriptor
-     */
-    usb_parse_descriptor(device_desc, "bbWbbbbWWWbbbb", &dev->descriptor);
-
-    LIST_ADD(fdev, dev);
-
-    if (usb_debug >= 2)
-      fprintf(stderr, "usb_os_find_devices: Found %s on %s\n",
-               dev->filename, bus->dirname);
-
-    /* Now try to fetch the rest of the descriptors */
-    if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG)
-      /* Silent since we'll try again later */
-      goto err;
-
-    if (dev->descriptor.bNumConfigurations < 1)
-      /* Silent since we'll try again later */
-      goto err;
-
-    dev->config = (struct usb_config_descriptor *)malloc(dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor));
-    if (!dev->config)
-      /* Silent since we'll try again later */
-      goto err;
-
-    memset(dev->config, 0, dev->descriptor.bNumConfigurations *
-          sizeof(struct usb_config_descriptor));
-
-    for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
-      unsigned char buffer[8], *bigbuffer;
-      struct usb_config_descriptor config;
-
-      /* Get the first 8 bytes so we can figure out what the total length is */
-      ret = read(fd, (void *)buffer, 8);
-      if (ret < 8) {
-        if (usb_debug >= 1) {
-          if (ret < 0)
-            fprintf(stderr, "Unable to get descriptor (%d)\n", ret);
-          else
-            fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", 8, ret);
-        }
-
-        goto err;
-      }
-
-      usb_parse_descriptor(buffer, "bbw", &config);
-
-      bigbuffer = malloc(config.wTotalLength);
-      if (!bigbuffer) {
-        if (usb_debug >= 1)
-          fprintf(stderr, "Unable to allocate memory for descriptors\n");
-        goto err;
-      }
-
-      /* Read the rest of the config descriptor */
-      memcpy(bigbuffer, buffer, 8);
-
-      ret = read(fd, (void *)(bigbuffer + 8), config.wTotalLength - 8);
-      if (ret < config.wTotalLength - 8) {
-        if (usb_debug >= 1) {
-          if (ret < 0)
-            fprintf(stderr, "Unable to get descriptor (%d)\n", ret);
-          else
-            fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", config.wTotalLength, ret);
-        }
-
-        free(bigbuffer);
-        goto err;
-      }
-
-      ret = usb_parse_configuration(&dev->config[i], bigbuffer);
-      if (usb_debug >= 2) {
-        if (ret > 0)
-          fprintf(stderr, "Descriptor data still left\n");
-        else if (ret < 0)
-          fprintf(stderr, "Unable to parse descriptors\n");
-      }
-
-      free(bigbuffer);
-    }
-
-err:
-    close(fd);
-  }
-
-  closedir(dir);
-
-  *devices = fdev;
-
-  return 0;
-}
-
-int usb_os_determine_children(struct usb_bus *bus)
-{
-  struct usb_device *dev, *devices[256];
-  struct usb_ioctl command;
-  int ret, i, i1;
-
-  /* Create a list of devices first */
-  memset(devices, 0, sizeof(devices));
-  for (dev = bus->devices; dev; dev = dev->next)
-    if (dev->devnum)
-      devices[dev->devnum] = dev;
-
-  /* Now fetch the children for each device */
-  for (dev = bus->devices; dev; dev = dev->next) {
-    struct usb_hub_portinfo portinfo;
-    int fd;
-
-    fd = device_open(dev);
-    if (fd < 0)
-      continue;
-
-    /* Query the hub driver for the children of this device */
-    if (dev->config && dev->config->interface && dev->config->interface->altsetting)
-      command.ifno = dev->config->interface->altsetting->bInterfaceNumber;
-    else
-      command.ifno = 0;
-    command.ioctl_code = IOCTL_USB_HUB_PORTINFO;
-    command.data = &portinfo;
-    ret = ioctl(fd, IOCTL_USB_IOCTL, &command);
-    if (ret < 0) {
-      /* errno == ENOSYS means the device probably wasn't a hub */
-      if (errno != ENOSYS && usb_debug > 1)
-        fprintf(stderr, "error obtaining child information: %s\n",
-               strerror(errno));
-
-      close(fd);
-      continue;
-    }
-
-    dev->num_children = 0;
-    for (i = 0; i < portinfo.numports; i++)
-      if (portinfo.port[i])
-        dev->num_children++;
-
-    /* Free any old children first */
-    free(dev->children);
-
-    dev->children = malloc(sizeof(struct usb_device *) * dev->num_children);
-    if (!dev->children) {
-      if (usb_debug > 1)
-        fprintf(stderr, "error allocating %zu bytes memory for dev->children\n",
-                sizeof(struct usb_device *) * dev->num_children);
-
-      dev->num_children = 0;
-      close(fd);
-      continue;
-    }
-
-    for (i = 0, i1 = 0; i < portinfo.numports; i++) {
-      if (!portinfo.port[i])
-        continue;
-
-      dev->children[i1++] = devices[portinfo.port[i]];
-
-      devices[portinfo.port[i]] = NULL;
-    }
-
-    close(fd);
-  }
-
-  /*
-   * There should be one device left in the devices list and that should be
-   * the root device
-   */
-  for (i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) {
-    if (devices[i])
-      bus->root_dev = devices[i];
-  }
-
-  return 0;
-}
-
-static int check_usb_vfs(const char *dirname)
-{
-  DIR *dir;
-  struct dirent *entry;
-  int found = 0;
-
-  dir = opendir(dirname);
-  if (!dir)
-    return 0;
-
-  while ((entry = readdir(dir)) != NULL) {
-    /* Skip anything starting with a . */
-    if (entry->d_name[0] == '.')
-      continue;
-
-    /* We assume if we find any files that it must be the right place */
-    found = 1;
-    break;
-  }
-
-  closedir(dir);
-
-  return found;
-}
-
-void usb_os_init(void)
-{
-  /* Find the path to the virtual filesystem */
-  if (getenv("USB_DEVFS_PATH")) {
-    if (check_usb_vfs(getenv("USB_DEVFS_PATH"))) {
-      strncpy(usb_path, getenv("USB_DEVFS_PATH"), sizeof(usb_path) - 1);
-      usb_path[sizeof(usb_path) - 1] = 0;
-    } else if (usb_debug)
-      fprintf(stderr, "usb_os_init: couldn't find USB VFS in USB_DEVFS_PATH\n");
-  }
-
-  if (!usb_path[0]) {
-    if (check_usb_vfs("/dev/bus/usb")) {
-      strncpy(usb_path, "/dev/bus/usb", sizeof(usb_path) - 1);
-      usb_path[sizeof(usb_path) - 1] = 0;
-    } else if (check_usb_vfs("/proc/bus/usb")) {
-      strncpy(usb_path, "/proc/bus/usb", sizeof(usb_path) - 1);
-      usb_path[sizeof(usb_path) - 1] = 0;
-    } else
-      usb_path[0] = 0; /* No path, no USB support */
-  }
-
-  if (usb_debug) {
-    if (usb_path[0])
-      fprintf(stderr, "usb_os_init: Found USB VFS at %s\n", usb_path);
-    else
-      fprintf(stderr, "usb_os_init: No USB VFS found, is it mounted?\n");
-  }
-}
-
-int usb_resetep(usb_dev_handle *dev, unsigned int ep)
-{
-  int ret;
-
-  ret = ioctl(dev->fd, IOCTL_USB_RESETEP, &ep);
-  if (ret)
-    USB_ERROR_STR(-errno, "could not reset ep %d: %s", ep,
-       strerror(errno));
-
-  return 0;
-}
-
-int usb_clear_halt(usb_dev_handle *dev, unsigned int ep)
-{
-  int ret;
-
-  ret = ioctl(dev->fd, IOCTL_USB_CLEAR_HALT, &ep);
-  if (ret)
-    USB_ERROR_STR(-errno, "could not clear/halt ep %d: %s", ep,
-       strerror(errno));
-
-  return 0;
-}
-
-int usb_reset(usb_dev_handle *dev)
-{
-  int ret;
-
-  ret = ioctl(dev->fd, IOCTL_USB_RESET, NULL);
-  if (ret)
-     USB_ERROR_STR(-errno, "could not reset: %s", strerror(errno));
-
-  return 0;
-}
-
-int usb_get_driver_np(usb_dev_handle *dev, int interface, char *name,
-       unsigned int namelen)
-{
-  struct usb_getdriver getdrv;
-  int ret;
-
-  getdrv.interface = interface;
-  ret = ioctl(dev->fd, IOCTL_USB_GETDRIVER, &getdrv);
-  if (ret)
-    USB_ERROR_STR(-errno, "could not get bound driver: %s", strerror(errno));
-
-  strncpy(name, getdrv.driver, namelen - 1);
-  name[namelen - 1] = 0;
-
-  return 0;
-}
-
-int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface)
-{
-  struct usb_ioctl command;
-  int ret;
-
-  command.ifno = interface;
-  command.ioctl_code = IOCTL_USB_DISCONNECT;
-  command.data = NULL;
-
-  ret = ioctl(dev->fd, IOCTL_USB_IOCTL, &command);
-  if (ret)
-    USB_ERROR_STR(-errno, "could not detach kernel driver from interface %d: %s",
-        interface, strerror(errno));
-
-  return 0;
-}
-
diff --git a/deps/libusb/linux.h b/deps/libusb/linux.h
deleted file mode 100644 (file)
index e544c09..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __LINUX_H__
-#define __LINUX_H__
-
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-
-struct usb_ctrltransfer {
-       /* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
-       u_int8_t  bRequestType;
-       u_int8_t  bRequest;
-       u_int16_t wValue;
-       u_int16_t wIndex;
-       u_int16_t wLength;
-
-       u_int32_t timeout;      /* in milliseconds */
-
-       /* pointer to data */
-       void *data;
-};
-
-struct usb_bulktransfer {
-       /* keep in sync with usbdevice_fs.h:usbdevfs_bulktransfer */
-       unsigned int ep;
-       unsigned int len;
-       unsigned int timeout;   /* in milliseconds */
-
-       /* pointer to data */
-       void *data;
-};
-
-struct usb_setinterface {
-       /* keep in sync with usbdevice_fs.h:usbdevfs_setinterface */
-       unsigned int interface;
-       unsigned int altsetting;
-};
-
-#define USB_MAXDRIVERNAME 255
-
-struct usb_getdriver {
-       unsigned int interface;
-       char driver[USB_MAXDRIVERNAME + 1];
-};
-
-#define USB_URB_DISABLE_SPD    1
-#define USB_URB_ISO_ASAP       2
-#define USB_URB_QUEUE_BULK     0x10
-
-#define USB_URB_TYPE_ISO       0
-#define USB_URB_TYPE_INTERRUPT 1
-#define USB_URB_TYPE_CONTROL   2
-#define USB_URB_TYPE_BULK      3
-
-struct usb_iso_packet_desc {
-       unsigned int length;
-       unsigned int actual_length;
-       unsigned int status;
-};
-
-struct usb_urb {
-       unsigned char type;
-       unsigned char endpoint;
-       int status;
-       unsigned int flags;
-       void *buffer;
-       int buffer_length;
-       int actual_length;
-       int start_frame;
-       int number_of_packets;
-       int error_count;
-       unsigned int signr;  /* signal to be sent on error, -1 if none should be sent */
-       void *usercontext;
-       struct usb_iso_packet_desc iso_frame_desc[0];
-};
-
-struct usb_connectinfo {
-       unsigned int devnum;
-       unsigned char slow;
-};
-
-struct usb_ioctl {
-       int ifno;       /* interface 0..N ; negative numbers reserved */
-       int ioctl_code; /* MUST encode size + direction of data so the
-                        * macros in <asm/ioctl.h> give correct values */
-       void *data;     /* param buffer (in, or out) */
-};
-
-struct usb_hub_portinfo {
-       unsigned char numports;
-       unsigned char port[127];        /* port to device num mapping */
-};
-
-#define IOCTL_USB_CONTROL      _IOWR('U', 0, struct usb_ctrltransfer)
-#define IOCTL_USB_BULK         _IOWR('U', 2, struct usb_bulktransfer)
-#define IOCTL_USB_RESETEP      _IOR('U', 3, unsigned int)
-#define IOCTL_USB_SETINTF      _IOR('U', 4, struct usb_setinterface)
-#define IOCTL_USB_SETCONFIG    _IOR('U', 5, unsigned int)
-#define IOCTL_USB_GETDRIVER    _IOW('U', 8, struct usb_getdriver)
-#define IOCTL_USB_SUBMITURB    _IOR('U', 10, struct usb_urb)
-#define IOCTL_USB_DISCARDURB   _IO('U', 11)
-#define IOCTL_USB_REAPURB      _IOW('U', 12, void *)
-#define IOCTL_USB_REAPURBNDELAY        _IOW('U', 13, void *)
-#define IOCTL_USB_CLAIMINTF    _IOR('U', 15, unsigned int)
-#define IOCTL_USB_RELEASEINTF  _IOR('U', 16, unsigned int)
-#define IOCTL_USB_CONNECTINFO  _IOW('U', 17, struct usb_connectinfo)
-#define IOCTL_USB_IOCTL         _IOWR('U', 18, struct usb_ioctl)
-#define IOCTL_USB_HUB_PORTINFO _IOR('U', 19, struct usb_hub_portinfo)
-#define IOCTL_USB_RESET                _IO('U', 20)
-#define IOCTL_USB_CLEAR_HALT   _IOR('U', 21, unsigned int)
-#define IOCTL_USB_DISCONNECT   _IO('U', 22)
-#define IOCTL_USB_CONNECT      _IO('U', 23)
-
-/*
- * IOCTL_USB_HUB_PORTINFO, IOCTL_USB_DISCONNECT and IOCTL_USB_CONNECT
- * all work via IOCTL_USB_IOCTL
- */
-
-#endif
-
diff --git a/deps/libusb/usb.c b/deps/libusb/usb.c
deleted file mode 100644 (file)
index ea4b375..0000000
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * Main API entry point
- *
- * Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
- *
- * This library is covered by the LGPL, read LICENSE for details.
- */
-
-#include <stdlib.h>    /* getenv */
-#include <stdio.h>     /* stderr */
-#include <string.h>    /* strcmp */
-#include <errno.h>
-
-#include "usbi.h"
-
-int usb_debug = 0;
-struct usb_bus *usb_busses = NULL;
-
-int usb_find_busses(void)
-{
-  struct usb_bus *busses, *bus;
-  int ret, changes = 0;
-
-  ret = usb_os_find_busses(&busses);
-  if (ret < 0)
-    return ret;
-
-  /*
-   * Now walk through all of the busses we know about and compare against
-   * this new list. Any duplicates will be removed from the new list.
-   * If we don't find it in the new list, the bus was removed. Any
-   * busses still in the new list, are new to us.
-   */
-  bus = usb_busses;
-  while (bus) {
-    int found = 0;
-    struct usb_bus *nbus, *tbus = bus->next;
-
-    nbus = busses;
-    while (nbus) {
-      struct usb_bus *tnbus = nbus->next;
-
-      if (!strcmp(bus->dirname, nbus->dirname)) {
-        /* Remove it from the new busses list */
-        LIST_DEL(busses, nbus);
-
-        usb_free_bus(nbus);
-        found = 1;
-        break;
-      }
-
-      nbus = tnbus;
-    }
-
-    if (!found) {
-      /* The bus was removed from the system */
-      LIST_DEL(usb_busses, bus);
-      usb_free_bus(bus);
-      changes++;
-    }
-
-    bus = tbus;
-  }
-
-  /*
-   * Anything on the *busses list is new. So add them to usb_busses and
-   * process them like the new bus it is.
-   */
-  bus = busses;
-  while (bus) {
-    struct usb_bus *tbus = bus->next;
-
-    /*
-     * Remove it from the temporary list first and add it to the real
-     * usb_busses list.
-     */
-    LIST_DEL(busses, bus);
-
-    LIST_ADD(usb_busses, bus);
-
-    changes++;
-
-    bus = tbus;
-  }
-
-  return changes;
-}
-
-int usb_find_devices(void)
-{
-  struct usb_bus *bus;
-  int ret, changes = 0;
-
-  for (bus = usb_busses; bus; bus = bus->next) {
-    struct usb_device *devices, *dev;
-
-    /* Find all of the devices and put them into a temporary list */
-    ret = usb_os_find_devices(bus, &devices);
-    if (ret < 0)
-      return ret;
-
-    /*
-     * Now walk through all of the devices we know about and compare
-     * against this new list. Any duplicates will be removed from the new
-     * list. If we don't find it in the new list, the device was removed.
-     * Any devices still in the new list, are new to us.
-     */
-    dev = bus->devices;
-    while (dev) {
-      int found = 0;
-      struct usb_device *ndev, *tdev = dev->next;
-
-      ndev = devices;
-      while (ndev) {
-        struct usb_device *tndev = ndev->next;
-
-        if (!strcmp(dev->filename, ndev->filename)) {
-          /* Remove it from the new devices list */
-          LIST_DEL(devices, ndev);
-
-          usb_free_dev(ndev);
-          found = 1;
-          break;
-        }
-
-        ndev = tndev;
-      }
-
-      if (!found) {
-        /* The device was removed from the system */
-        LIST_DEL(bus->devices, dev);
-        usb_free_dev(dev);
-        changes++;
-      }
-
-      dev = tdev;
-    }
-
-    /*
-     * Anything on the *devices list is new. So add them to bus->devices and
-     * process them like the new device it is.
-     */
-    dev = devices;
-    while (dev) {
-      struct usb_device *tdev = dev->next;
-
-      /*
-       * Remove it from the temporary list first and add it to the real
-       * bus->devices list.
-       */
-      LIST_DEL(devices, dev);
-
-      LIST_ADD(bus->devices, dev);
-
-      /*
-       * Some ports fetch the descriptors on scanning (like Linux) so we don't
-       * need to fetch them again.
-       */
-      if (!dev->config) {
-        usb_dev_handle *udev;
-
-        udev = usb_open(dev);
-        if (udev) {
-          usb_fetch_and_parse_descriptors(udev);
-
-          usb_close(udev);
-        }
-      }
-
-      changes++;
-
-      dev = tdev;
-    }
-
-    usb_os_determine_children(bus);
-  }
-
-  return changes;
-}
-
-void usb_set_debug(int level)
-{
-  if (usb_debug || level)
-    fprintf(stderr, "usb_set_debug: Setting debugging level to %d (%s)\n",
-       level, level ? "on" : "off");
-
-  usb_debug = level;
-}
-
-void usb_init(void)
-{
-  if (getenv("USB_DEBUG"))
-    usb_set_debug(atoi(getenv("USB_DEBUG")));
-
-  usb_os_init();
-}
-
-usb_dev_handle *usb_open(struct usb_device *dev)
-{
-  usb_dev_handle *udev;
-
-  udev = malloc(sizeof(*udev));
-  if (!udev)
-    return NULL;
-
-  udev->fd = -1;
-  udev->device = dev;
-  udev->bus = dev->bus;
-  udev->config = udev->interface = udev->altsetting = -1;
-
-  if (usb_os_open(udev) < 0) {
-    free(udev);
-    return NULL;
-  }
-
-  return udev;
-}
-
-int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
-       size_t buflen)
-{
-  /*
-   * We can't use usb_get_descriptor() because it's lacking the index
-   * parameter. This will be fixed in libusb 1.0
-   */
-  return usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
-                       (USB_DT_STRING << 8) + index, langid, buf, buflen, 1000);
-}
-
-int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf, size_t buflen)
-{
-  char tbuf[255];      /* Some devices choke on size > 255 */
-  int ret, langid, si, di;
-
-  /*
-   * Asking for the zero'th index is special - it returns a string
-   * descriptor that contains all the language IDs supported by the
-   * device. Typically there aren't many - often only one. The
-   * language IDs are 16 bit numbers, and they start at the third byte
-   * in the descriptor. See USB 2.0 specification, section 9.6.7, for
-   * more information on this. */
-  ret = usb_get_string(dev, 0, 0, tbuf, sizeof(tbuf));
-  if (ret < 0)
-    return ret;
-
-  if (ret < 4)
-    return -EIO;
-
-  langid = tbuf[2] | (tbuf[3] << 8);
-
-  ret = usb_get_string(dev, index, langid, tbuf, sizeof(tbuf));
-  if (ret < 0)
-    return ret;
-
-  if (tbuf[1] != USB_DT_STRING)
-    return -EIO;
-
-  if (tbuf[0] > ret)
-    return -EFBIG;
-
-  for (di = 0, si = 2; si < tbuf[0]; si += 2) {
-    if (di >= (buflen - 1))
-      break;
-
-    if (tbuf[si + 1])  /* high byte */
-      buf[di++] = '?';
-    else
-      buf[di++] = tbuf[si];
-  }
-
-  buf[di] = 0;
-
-  return di;
-}
-
-int usb_close(usb_dev_handle *dev)
-{
-  int ret;
-
-  ret = usb_os_close(dev);
-  free(dev);
-
-  return ret;
-}
-
-struct usb_device *usb_device(usb_dev_handle *dev)
-{
-  return dev->device;
-}
-
-void usb_free_dev(struct usb_device *dev)
-{
-  usb_destroy_configuration(dev);
-  free(dev->children);
-  free(dev);
-}
-
-struct usb_bus *usb_get_busses(void)
-{
-  return usb_busses;
-}
-
-void usb_free_bus(struct usb_bus *bus)
-{
-  free(bus);
-}
-
diff --git a/deps/libusb/usb.h b/deps/libusb/usb.h
deleted file mode 100644 (file)
index 35955b7..0000000
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * Prototypes, structure definitions and macros.
- *
- * Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
- *
- * This library is covered by the LGPL, read LICENSE for details.
- *
- * This file (and only this file) may alternatively be licensed under the
- * BSD license as well, read LICENSE for details.
- */
-#ifndef __USB_H__
-#define __USB_H__
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#include <dirent.h>
-
-/*
- * USB spec information
- *
- * This is all stuff grabbed from various USB specs and is pretty much
- * not subject to change
- */
-
-/*
- * Device and/or Interface Class codes
- */
-#define USB_CLASS_PER_INTERFACE                0       /* for DeviceClass */
-#define USB_CLASS_AUDIO                        1
-#define USB_CLASS_COMM                 2
-#define USB_CLASS_HID                  3
-#define USB_CLASS_PRINTER              7
-#define USB_CLASS_PTP                  6
-#define USB_CLASS_MASS_STORAGE         8
-#define USB_CLASS_HUB                  9
-#define USB_CLASS_DATA                 10
-#define USB_CLASS_VENDOR_SPEC          0xff
-
-/*
- * Descriptor types
- */
-#define USB_DT_DEVICE                  0x01
-#define USB_DT_CONFIG                  0x02
-#define USB_DT_STRING                  0x03
-#define USB_DT_INTERFACE               0x04
-#define USB_DT_ENDPOINT                        0x05
-
-#define USB_DT_HID                     0x21
-#define USB_DT_REPORT                  0x22
-#define USB_DT_PHYSICAL                        0x23
-#define USB_DT_HUB                     0x29
-
-/*
- * Descriptor sizes per descriptor type
- */
-#define USB_DT_DEVICE_SIZE             18
-#define USB_DT_CONFIG_SIZE             9
-#define USB_DT_INTERFACE_SIZE          9
-#define USB_DT_ENDPOINT_SIZE           7
-#define USB_DT_ENDPOINT_AUDIO_SIZE     9       /* Audio extension */
-#define USB_DT_HUB_NONVAR_SIZE         7
-
-/* All standard descriptors have these 2 fields in common */
-struct usb_descriptor_header {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-};
-
-/* String descriptor */
-struct usb_string_descriptor {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-       unsigned short wData[1];
-};
-
-/* HID descriptor */
-struct usb_hid_descriptor {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-       unsigned short bcdHID;
-       unsigned char  bCountryCode;
-       unsigned char  bNumDescriptors;
-       /* unsigned char  bReportDescriptorType; */
-       /* unsigned short wDescriptorLength; */
-       /* ... */
-};
-
-/* Endpoint descriptor */
-#define USB_MAXENDPOINTS       32
-struct usb_endpoint_descriptor {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-       unsigned char  bEndpointAddress;
-       unsigned char  bmAttributes;
-       unsigned short wMaxPacketSize;
-       unsigned char  bInterval;
-       unsigned char  bRefresh;
-       unsigned char  bSynchAddress;
-
-       unsigned char *extra;   /* Extra descriptors */
-       int extralen;
-};
-
-#define USB_ENDPOINT_ADDRESS_MASK      0x0f    /* in bEndpointAddress */
-#define USB_ENDPOINT_DIR_MASK          0x80
-
-#define USB_ENDPOINT_TYPE_MASK         0x03    /* in bmAttributes */
-#define USB_ENDPOINT_TYPE_CONTROL      0
-#define USB_ENDPOINT_TYPE_ISOCHRONOUS  1
-#define USB_ENDPOINT_TYPE_BULK         2
-#define USB_ENDPOINT_TYPE_INTERRUPT    3
-
-/* Interface descriptor */
-#define USB_MAXINTERFACES      32
-struct usb_interface_descriptor {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-       unsigned char  bInterfaceNumber;
-       unsigned char  bAlternateSetting;
-       unsigned char  bNumEndpoints;
-       unsigned char  bInterfaceClass;
-       unsigned char  bInterfaceSubClass;
-       unsigned char  bInterfaceProtocol;
-       unsigned char  iInterface;
-
-       struct usb_endpoint_descriptor *endpoint;
-
-       unsigned char *extra;   /* Extra descriptors */
-       int extralen;
-};
-
-#define USB_MAXALTSETTING      128     /* Hard limit */
-struct usb_interface {
-       struct usb_interface_descriptor *altsetting;
-
-       int num_altsetting;
-};
-
-/* Configuration descriptor information.. */
-#define USB_MAXCONFIG          8
-struct usb_config_descriptor {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-       unsigned short wTotalLength;
-       unsigned char  bNumInterfaces;
-       unsigned char  bConfigurationValue;
-       unsigned char  iConfiguration;
-       unsigned char  bmAttributes;
-       unsigned char  MaxPower;
-
-       struct usb_interface *interface;
-
-       unsigned char *extra;   /* Extra descriptors */
-       int extralen;
-};
-
-/* Device descriptor */
-struct usb_device_descriptor {
-       unsigned char  bLength;
-       unsigned char  bDescriptorType;
-       unsigned short bcdUSB;
-       unsigned char  bDeviceClass;
-       unsigned char  bDeviceSubClass;
-       unsigned char  bDeviceProtocol;
-       unsigned char  bMaxPacketSize0;
-       unsigned short idVendor;
-       unsigned short idProduct;
-       unsigned short bcdDevice;
-       unsigned char  iManufacturer;
-       unsigned char  iProduct;
-       unsigned char  iSerialNumber;
-       unsigned char  bNumConfigurations;
-};
-
-struct usb_ctrl_setup {
-       unsigned char  bRequestType;
-       unsigned char  bRequest;
-       unsigned short wValue;
-       unsigned short wIndex;
-       unsigned short wLength;
-};
-
-/*
- * Standard requests
- */
-#define USB_REQ_GET_STATUS             0x00
-#define USB_REQ_CLEAR_FEATURE          0x01
-/* 0x02 is reserved */
-#define USB_REQ_SET_FEATURE            0x03
-/* 0x04 is reserved */
-#define USB_REQ_SET_ADDRESS            0x05
-#define USB_REQ_GET_DESCRIPTOR         0x06
-#define USB_REQ_SET_DESCRIPTOR         0x07
-#define USB_REQ_GET_CONFIGURATION      0x08
-#define USB_REQ_SET_CONFIGURATION      0x09
-#define USB_REQ_GET_INTERFACE          0x0A
-#define USB_REQ_SET_INTERFACE          0x0B
-#define USB_REQ_SYNCH_FRAME            0x0C
-
-#define USB_TYPE_STANDARD              (0x00 << 5)
-#define USB_TYPE_CLASS                 (0x01 << 5)
-#define USB_TYPE_VENDOR                        (0x02 << 5)
-#define USB_TYPE_RESERVED              (0x03 << 5)
-
-#define USB_RECIP_DEVICE               0x00
-#define USB_RECIP_INTERFACE            0x01
-#define USB_RECIP_ENDPOINT             0x02
-#define USB_RECIP_OTHER                        0x03
-
-/*
- * Various libusb API related stuff
- */
-
-#define USB_ENDPOINT_IN                        0x80
-#define USB_ENDPOINT_OUT               0x00
-
-/* Error codes */
-#define USB_ERROR_BEGIN                        500000
-
-/*
- * This is supposed to look weird. This file is generated from autoconf
- * and I didn't want to make this too complicated.
- */
-#if _BIGENDIAN
-#define USB_LE16_TO_CPU(x) do { x = ((x & 0xff) << 8) | ((x & 0xff00) >> 8); } while(0)
-#else
-#define USB_LE16_TO_CPU(x)
-#endif
-
-/* Data types */
-struct usb_device;
-struct usb_bus;
-
-/*
- * To maintain compatibility with applications already built with libusb,
- * we must only add entries to the end of this structure. NEVER delete or
- * move members and only change types if you really know what you're doing.
- */
-struct usb_device {
-  struct usb_device *next, *prev;
-
-  char filename[PATH_MAX + 1];
-
-  struct usb_bus *bus;
-
-  struct usb_device_descriptor descriptor;
-  struct usb_config_descriptor *config;
-
-  void *dev;           /* Darwin support */
-
-  unsigned char devnum;
-
-  unsigned char num_children;
-  struct usb_device **children;
-};
-
-struct usb_bus {
-  struct usb_bus *next, *prev;
-
-  char dirname[PATH_MAX + 1];
-
-  struct usb_device *devices;
-  unsigned long location;
-
-  struct usb_device *root_dev;
-};
-
-struct usb_dev_handle;
-typedef struct usb_dev_handle usb_dev_handle;
-
-/* Variables */
-extern struct usb_bus *usb_busses;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Function prototypes */
-
-/* usb.c */
-usb_dev_handle *usb_open(struct usb_device *dev);
-int usb_close(usb_dev_handle *dev);
-int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
-       size_t buflen);
-int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
-       size_t buflen);
-
-/* descriptors.c */
-int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
-       unsigned char type, unsigned char index, void *buf, int size);
-int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
-       unsigned char index, void *buf, int size);
-
-/* <arch>.c */
-int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout);
-int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
-       int timeout);
-int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
-        int timeout);
-int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
-        int timeout);
-int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
-       int value, int index, char *bytes, int size, int timeout);
-int usb_set_configuration(usb_dev_handle *dev, int configuration);
-int usb_claim_interface(usb_dev_handle *dev, int interface);
-int usb_release_interface(usb_dev_handle *dev, int interface);
-int usb_set_altinterface(usb_dev_handle *dev, int alternate);
-int usb_resetep(usb_dev_handle *dev, unsigned int ep);
-int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
-int usb_reset(usb_dev_handle *dev);
-
-#if LINUX_API
-#define LIBUSB_HAS_GET_DRIVER_NP 1
-int usb_get_driver_np(usb_dev_handle *dev, int interface, char *name,
-       unsigned int namelen);
-#define LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 1
-int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface);
-#endif
-
-char *usb_strerror(void);
-
-void usb_init(void);
-void usb_set_debug(int level);
-int usb_find_busses(void);
-int usb_find_devices(void);
-struct usb_device *usb_device(usb_dev_handle *dev);
-struct usb_bus *usb_get_busses(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __USB_H__ */
-
diff --git a/deps/libusb/usbi.h b/deps/libusb/usbi.h
deleted file mode 100644 (file)
index d71b5c4..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef _USBI_H_
-#define _USBI_H_
-
-#include "usb.h"
-
-#include "error.h"
-
-extern int usb_debug;
-
-/* Some quick and generic macros for the simple kind of lists we use */
-#define LIST_ADD(begin, ent) \
-       do { \
-         if (begin) { \
-           ent->next = begin; \
-           ent->next->prev = ent; \
-         } else \
-           ent->next = NULL; \
-         ent->prev = NULL; \
-         begin = ent; \
-       } while(0)
-
-#define LIST_DEL(begin, ent) \
-       do { \
-         if (ent->prev) \
-           ent->prev->next = ent->next; \
-         else \
-           begin = ent->next; \
-         if (ent->next) \
-           ent->next->prev = ent->prev; \
-         ent->prev = NULL; \
-         ent->next = NULL; \
-       } while (0)
-
-#define DESC_HEADER_LENGTH             2
-#define DEVICE_DESC_LENGTH             18
-#define CONFIG_DESC_LENGTH             9
-#define INTERFACE_DESC_LENGTH          9
-#define ENDPOINT_DESC_LENGTH           7
-#define ENDPOINT_AUDIO_DESC_LENGTH     9
-
-struct usb_dev_handle {
-  int fd;
-
-  struct usb_bus *bus;
-  struct usb_device *device;
-
-  int config;
-  int interface;
-  int altsetting;
-
-  /* Added by RMT so implementations can store other per-open-device data */
-  void *impl_info;
-};
-
-/* descriptors.c */
-int usb_parse_descriptor(unsigned char *source, char *description, void *dest);
-int usb_parse_configuration(struct usb_config_descriptor *config,
-       unsigned char *buffer);
-void usb_fetch_and_parse_descriptors(usb_dev_handle *udev);
-void usb_destroy_configuration(struct usb_device *dev);
-
-/* OS specific routines */
-int usb_os_find_busses(struct usb_bus **busses);
-int usb_os_find_devices(struct usb_bus *bus, struct usb_device **devices);
-int usb_os_determine_children(struct usb_bus *bus);
-void usb_os_init(void);
-int usb_os_open(usb_dev_handle *dev);
-int usb_os_close(usb_dev_handle *dev);
-
-void usb_free_dev(struct usb_device *dev);
-void usb_free_bus(struct usb_bus *bus);
-
-#endif /* _USBI_H_ */
-
diff --git a/deps/libusb/windows.c b/deps/libusb/windows.c
deleted file mode 100755 (executable)
index 0afbef9..0000000
+++ /dev/null
@@ -1,558 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <windows.h>
-#include <setupapi.h>
-#include <winerror.h>
-#include "winusb.h"
-
-#include <limits.h>
-#include <stdio.h>
-#include <errno.h>
-#include "fdevent.h"
-#include "utils.h"
-#include "strutils.h"
-#include "linkedlist.h"
-
-#define   TRACE_TAG  TRACE_USB
-#include "sdb.h"
-#include "sdb_usb.h"
-
-struct usb_handle {
-    LIST_NODE* node;
-
-    HANDLE hnd;
-    WINUSB_INTERFACE_HANDLE fd;
-    char unique_node_path[PATH_MAX+1]; //MAX_DEVICE_ID_LEN <device-ID>\<instance-specific-ID>
-    UCHAR end_point[2];
-    unsigned int zero_mask;
-};
-usb_handle *usb_open(const char *device_path);
-int win_usb_close(usb_handle *dev);
-int usb_get_string_simple(usb_handle *dev, int index, char *buf, size_t buflen);
-void *device_poll_thread(void* unused);
-int usb_bulk_transfer(usb_handle* handle, BOOL is_read, const void *data, unsigned long length, unsigned long *actual_length, unsigned long timeout);
-void do_lsusb(void);
-
-// Class ID assigned to the device by aNdrOiduSb.sys
-static const GUID TIZEN_CLASSID = {0x9ca29f37, 0xdd62, 0x4aad, {0x82, 0x65, 0xcf, 0xf7, 0x88, 0xc8, 0xba, 0x89}};
-
-static LIST_NODE* handle_list = NULL;
-
-SDB_MUTEX_DEFINE( usb_lock );
-
-
-// winusb.dll entrypoints
-DLL_DECLARE(WINAPI, BOOL, WinUsb_Initialize, (HANDLE, PWINUSB_INTERFACE_HANDLE));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_Free, (WINUSB_INTERFACE_HANDLE));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_GetAssociatedInterface, (WINUSB_INTERFACE_HANDLE, UCHAR, PWINUSB_INTERFACE_HANDLE));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_GetDescriptor, (WINUSB_INTERFACE_HANDLE, UCHAR, UCHAR, USHORT, PUCHAR, ULONG, PULONG));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_QueryInterfaceSettings, (WINUSB_INTERFACE_HANDLE, UCHAR, PUSB_INTERFACE_DESCRIPTOR));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_QueryDeviceInformation, (WINUSB_INTERFACE_HANDLE, ULONG, PULONG, PVOID));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_SetCurrentAlternateSetting, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_GetCurrentAlternateSetting, (WINUSB_INTERFACE_HANDLE, PUCHAR));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_QueryPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, UCHAR, PWINUSB_PIPE_INFORMATION));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_SetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, ULONG, ULONG, PVOID));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_GetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, ULONG, PULONG, PVOID));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_ReadPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_WritePipe, (WINUSB_INTERFACE_HANDLE, UCHAR, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_ControlTransfer, (WINUSB_INTERFACE_HANDLE, WINUSB_SETUP_PACKET, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_ResetPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_AbortPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_FlushPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
-DLL_DECLARE(WINAPI, BOOL, WinUsb_GetOverlappedResult, (WINUSB_INTERFACE_HANDLE, LPOVERLAPPED, LPDWORD, BOOL));
-
-void win_usb_init(void) {
-    // Initialize DLL functions
-    if (!WinUsb_Initialize) {
-        DLL_LOAD(winusb.dll, WinUsb_Initialize);
-        DLL_LOAD(winusb.dll, WinUsb_Free);
-        DLL_LOAD(winusb.dll, WinUsb_GetAssociatedInterface);
-        DLL_LOAD(winusb.dll, WinUsb_GetDescriptor);
-        DLL_LOAD(winusb.dll, WinUsb_QueryInterfaceSettings);
-        DLL_LOAD(winusb.dll, WinUsb_QueryDeviceInformation);
-        DLL_LOAD(winusb.dll, WinUsb_SetCurrentAlternateSetting);
-        DLL_LOAD(winusb.dll, WinUsb_GetCurrentAlternateSetting);
-        DLL_LOAD(winusb.dll, WinUsb_QueryPipe);
-        DLL_LOAD(winusb.dll, WinUsb_SetPipePolicy);
-        DLL_LOAD(winusb.dll, WinUsb_GetPipePolicy);
-        DLL_LOAD(winusb.dll, WinUsb_ReadPipe);
-        DLL_LOAD(winusb.dll, WinUsb_WritePipe);
-        DLL_LOAD(winusb.dll, WinUsb_ControlTransfer);
-        DLL_LOAD(winusb.dll, WinUsb_ResetPipe);
-        DLL_LOAD(winusb.dll, WinUsb_AbortPipe);
-        DLL_LOAD(winusb.dll, WinUsb_FlushPipe);
-        DLL_LOAD(winusb.dll, WinUsb_GetOverlappedResult);
-    }
-}
-
-int is_device_registered(const char *node_path)
-{
-    int r = 0;
-    sdb_mutex_lock(&usb_lock, "usb is_device_registered");
-
-    LIST_NODE* cur_ptr = handle_list;
-    while(cur_ptr != NULL) {
-       usb_handle* usb = cur_ptr->data;
-       cur_ptr = cur_ptr->next_ptr;
-
-       if(!strcmp(usb->unique_node_path, node_path)) {
-               r = 1;
-               break;
-       }
-    }
-    sdb_mutex_unlock(&usb_lock, "usb is_device_registered");
-    return r;
-}
-
-usb_handle *usb_open(const char *device_path) {
-    // Allocate storage for handles
-    usb_handle* usb = calloc(1, sizeof(usb_handle));
-    s_strncpy(usb->unique_node_path, device_path, sizeof(usb->unique_node_path));
-
-    // Open generic handle to device
-    HANDLE hnd = CreateFile(device_path, GENERIC_WRITE | GENERIC_READ,
-            FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
-            FILE_FLAG_OVERLAPPED, NULL);
-
-    if (INVALID_HANDLE_VALUE == hnd) {
-        D("fail to create device file: %s due to: %d\n", device_path, GetLastError());
-       return NULL;
-    }
-
-    // Initialize WinUSB for this device and get a WinUSB handle for it
-    WINUSB_INTERFACE_HANDLE fd;
-    if (!WinUsb_Initialize(hnd, &fd)) {
-        return NULL;
-    }
-
-    // fetch USB device descriptor
-    USB_DEVICE_DESCRIPTOR         usb_device_descriptor;
-    unsigned long bytes_written;
-
-    if (!WinUsb_GetDescriptor(fd, USB_DEVICE_DESCRIPTOR_TYPE, 0, 0,
-            (PUCHAR)&usb_device_descriptor, sizeof(usb_device_descriptor), &bytes_written)) {
-        return NULL;
-    }
-
-    USB_INTERFACE_DESCRIPTOR      usb_interface_descriptor;
-
-    // fetch usb interface descriptor
-    UCHAR interface_number;
-    if (!WinUsb_GetCurrentAlternateSetting(fd, &interface_number)) {
-        return NULL;
-    }
-
-    if (!WinUsb_QueryInterfaceSettings(fd, interface_number, &usb_interface_descriptor)) {
-        return NULL;
-    }
-
-    if (2 != usb_interface_descriptor.bNumEndpoints) {
-        D("the number of endpoint should be two\n");
-        return NULL;
-    }
-
-    if (!is_sdb_interface(usb_device_descriptor.idVendor, usb_interface_descriptor.bInterfaceClass, usb_interface_descriptor.bInterfaceSubClass,
-            usb_interface_descriptor.bInterfaceProtocol)) {
-        return NULL;
-    }
-    UCHAR endpoint_index = 0;
-
-    for (endpoint_index = 0; endpoint_index < usb_interface_descriptor.bNumEndpoints; endpoint_index++) {
-        // fetch endpoint information
-        WINUSB_PIPE_INFORMATION pipe_info;
-        if (!WinUsb_QueryPipe(fd, interface_number, endpoint_index, &pipe_info)) {
-            return NULL;
-        }
-
-        if(usb_interface_descriptor.bInterfaceProtocol == 0x01) {
-            if (endpoint_index == 0) {
-                usb->zero_mask = pipe_info.MaximumPacketSize - 1;
-            }
-        }
-        // only interested in bulk type
-        if (UsbdPipeTypeBulk == pipe_info.PipeType) {
-            if (USB_ENDPOINT_DIRECTION_IN(pipe_info.PipeId)) {
-                D("builk in endpoint index: %d, id: %04x\n", endpoint_index, pipe_info.PipeId);
-                usb->end_point[0] = pipe_info.PipeId;
-            }
-
-            if (USB_ENDPOINT_DIRECTION_OUT(pipe_info.PipeId)) {
-                D("builk out endpoint index: %d, id: %04x\n", endpoint_index, pipe_info.PipeId);
-                usb->end_point[1] = pipe_info.PipeId;
-            }
-
-        }
-    }
-    usb->hnd = hnd;
-    usb->fd = fd;
-
-    return usb;
-}
-
-int register_device(usb_handle *hnd) {
-    if (is_device_registered(hnd->unique_node_path)) {
-        return 0;
-    }
-
-    sdb_mutex_lock(&usb_lock, "usb register_device");
-
-    hnd->node = prepend(&handle_list, hnd);
-
-    sdb_mutex_unlock(&usb_lock, "usb register_device");
-
-    return 1;
-}
-
-int usb_get_string_simple(usb_handle *dev, int index, char *buf, size_t buflen) {
-    unsigned char temp[MAXIMUM_USB_STRING_LENGTH];
-
-    ULONG actlen = 0;
-    //0x0409 for English (US)
-    if (!WinUsb_GetDescriptor(dev->fd, USB_STRING_DESCRIPTOR_TYPE, index, 0x0409, temp, sizeof(temp), &actlen)) {
-        return -GetLastError();
-    }
-    // Skip first two bytes of result (descriptor id and length), then take
-    // every other byte as a cheap way to convert Unicode to ASCII
-    unsigned int i, j;
-    for (i = 2, j = 0; i < actlen && j < (buflen - 1); i += 2, ++j)
-        buf[j] = temp[i];
-    buf[j] = '\0';
-
-    return strlen(buf);
-}
-
-static int get_serial_number(usb_handle *dev, char *buf, int buflen) {
-    USB_DEVICE_DESCRIPTOR         usb_device_descriptor;
-    ULONG actlen = 0;
-
-    if (!WinUsb_GetDescriptor(dev->fd, USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, (unsigned char*) &usb_device_descriptor,
-            sizeof(usb_device_descriptor), &actlen)) {
-        return 0;
-    }
-
-    return usb_get_string_simple(dev, usb_device_descriptor.iSerialNumber, buf, buflen);
-}
-
-int usb_find_devices(GUID deviceClassID) {
-    SP_DEVINFO_DATA deviceInfoData;
-    char devicePath[PATH_MAX + 1];
-    BOOL bResult = TRUE;
-    PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
-    int index = 0;
-
-    // from http://msdn.microsoft.com/en-us/library/windows/hardware/ff540174(v=vs.85).aspx
-    // Get information about all the installed devices for the specified device interface class.
-    HDEVINFO hDeviceInfo = SetupDiGetClassDevs(&deviceClassID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
-    if (hDeviceInfo == INVALID_HANDLE_VALUE) {
-        D("fail to find any device: %d\n", GetLastError());
-        return 0;
-    }
-
-    //Enumerate all the device interfaces in the device information set.
-    deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
-
-    for (index = 0; ; index++) {
-
-        //Get information about the device interface.
-        SP_DEVICE_INTERFACE_DATA interfaceData;
-        interfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
-
-        bResult = SetupDiEnumDeviceInterfaces(hDeviceInfo, NULL, &deviceClassID, index, &interfaceData);
-        // Check if last item
-        if (GetLastError() == ERROR_NO_MORE_ITEMS) {
-            break;
-        }
-
-        //Check for some other error
-        if (!bResult)
-        {
-            D("Error SetupDiEnumDeviceInterfaces: %d.\n", GetLastError());
-            break;
-        }
-
-        // Determine required size for interface detail data
-        ULONG requiredLength = 0;
-
-        //Interface data is returned in SP_DEVICE_INTERFACE_DETAIL_DATA
-        //which we need to allocate, so we have to call this function twice.
-        //First to get the size so that we know how much to allocate
-        //Second, the actual call with the allocated buffer
-        bResult = SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &interfaceData, NULL, 0, &requiredLength, NULL);
-
-        //Check for some other error
-        if (!bResult) {
-            if ((ERROR_INSUFFICIENT_BUFFER == GetLastError()) && (requiredLength > 0)) {
-                // Allocate storage for interface detail data
-                detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(requiredLength);
-
-                if (detailData == NULL) {
-                    D("fail to allocate memory\n");
-                    break;
-                }
-            } else {
-                D("Error SetupDiEnumDeviceInterfaces: %d.\n", GetLastError());
-                break;
-            }
-        }
-
-        // Finally, do fetch interface detail data
-        detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
-        //Now call it with the correct size and allocated buffer
-        bResult = SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &interfaceData, detailData, requiredLength, NULL,
-                &deviceInfoData);
-
-        //Check for some other error
-        if (!bResult) {
-            D("fail to setdup get device interface detail: %d\n", GetLastError());
-            if (detailData != NULL) {
-                free(detailData);
-            }
-            break;
-        }
-
-        //copy device path
-        s_strncpy(devicePath, detailData->DevicePath, sizeof(devicePath));
-
-        if (detailData != NULL) {
-            free(detailData);
-        }
-
-        if (!is_device_registered(devicePath)) {
-            struct usb_handle *hnd = usb_open(devicePath);
-            if (hnd != NULL) {
-                char serial[256];
-                if (get_serial_number(hnd, serial, sizeof(serial)) > 0) {
-                    D("register usb for: %s\n", serial);
-                    if (register_device(hnd)) {
-                        register_usb_transport(hnd, serial);
-                    } else {
-                        D("fail to register usb\n");
-                        win_usb_close(hnd);
-                        free(hnd);
-                    }
-                } else {
-                    D("fail to get usb serial name: kick? close?\n");
-                    win_usb_close(hnd);
-                    free(hnd);
-                }
-            }
-        }
-    }
-    //  Cleanup
-    bResult = SetupDiDestroyDeviceInfoList(hDeviceInfo);
-
-    return bResult;
-}
-
-void* device_poll_thread(void* sleep_msec) {
-    D("Created device thread\n");
-
-    int  mseconds = (int) sleep_msec;
-    while (1) {
-        do_lsusb();
-        sdb_sleep_ms(mseconds);
-    }
-
-    return NULL;
-}
-
-void sdb_usb_init() {
-    sdb_thread_t tid;
-
-    win_usb_init();
-    if (sdb_thread_create(&tid, device_poll_thread, (void*)3000)) {
-        LOG_FATAL("cannot create input thread\n");
-    }
-}
-
-void sdb_usb_cleanup() {
-    D("TODO: not imple yet\n");
-}
-
-int usb_bulk_transfer(usb_handle* handle, BOOL is_read, const void *data, unsigned long length, unsigned long *actual_length, unsigned long timeout) {
-    ULONG tmp = timeout;
-    UCHAR endpoint;
-
-    if (is_read) {
-        endpoint = handle->end_point[0];
-    } else {
-        endpoint = handle->end_point[1];
-    }
-    if (handle->fd == NULL) {
-        D("invalid handle\n");
-        return 0;
-    }
-
-    // do not complete within the specified time-out interval
-    if (!WinUsb_SetPipePolicy(handle->fd, endpoint, PIPE_TRANSFER_TIMEOUT, sizeof(tmp), &tmp)) {
-        D("fail to set timeout\n");
-        SetLastError(ERROR_SEM_TIMEOUT);
-        return 0;
-    }
-
-    // manual reset must be true (second param) as the reset occurs in read
-
-    OVERLAPPED overlapped;
-    ZeroMemory(&overlapped, sizeof(overlapped));
-    overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-
-    BOOL ret = TRUE;
-    ULONG transferred = 0;
-
-    if (is_read) {
-        ret = WinUsb_ReadPipe(handle->fd, endpoint, (UCHAR*) data, length, &transferred, &overlapped);
-    } else {
-        ret = WinUsb_WritePipe(handle->fd, endpoint, (UCHAR*) data, length, &transferred, &overlapped);
-    }
-
-    if (!ret && (ERROR_IO_PENDING != GetLastError())) {
-        if (NULL != overlapped.hEvent){
-            CloseHandle(overlapped.hEvent);
-        }
-        D("pipe error: (%ld/ld) error:%d\n", length, transferred, GetLastError());
-        return 0;
-    }
-
-    // wait for the operation to be IO completed
-    ret = WinUsb_GetOverlappedResult(handle->fd, &overlapped, &transferred, TRUE);
-
-    if (ret && (NULL != actual_length)) {
-        *actual_length = transferred;
-    }
-
-    if (NULL != overlapped.hEvent) {
-        CloseHandle(overlapped.hEvent);
-    }
-
-    return ret ? 1 : 0;
-}
-
-int sdb_usb_write(usb_handle* handle, const void* data, int len) {
-    unsigned long time_out = 5000;//5000;
-    unsigned long written = 0;
-    int ret;
-
-    D("+sdb_usb_write %d\n", len);
-
-    if (NULL != handle) {
-        ret = usb_bulk_transfer(handle, FALSE, (void*)data, (unsigned long)len, &written, time_out);
-        int saved_errno = GetLastError();
-        D("sdb_usb_write got(ret:%d): %ld, expected: %d, errno: %d\n",ret, written, len, saved_errno);
-
-        if (ret) {
-            if (written == (unsigned long) len) {
-                if (handle->zero_mask && (len & handle->zero_mask) == 0) {
-                    // Send a zero length packet
-                    usb_bulk_transfer(handle, FALSE, (void*)data, 0, &written, time_out);
-                }
-                return 0;
-            }
-        } else {
-            // assume ERROR_INVALID_HANDLE indicates we are disconnected
-            if (saved_errno == ERROR_INVALID_HANDLE) {
-                sdb_usb_kick(handle);
-            }
-        }
-        errno = saved_errno;
-    } else {
-        D("usb_write NULL handle\n");
-        SetLastError(ERROR_INVALID_HANDLE);
-    }
-
-    D("-sdb_usb_write failed: %d\n", errno);
-
-    return -1;
-}
-
-int sdb_usb_read(usb_handle *handle, void* data, int len) {
-    unsigned long n = 0;
-    int ret;
-
-    D("+sdb_usb_read %d\n", len);
-    if (NULL != handle) {
-        while (len > 0) {
-            int xfer = (len > 4096) ? 4096 : len;
-            ret = usb_bulk_transfer(handle, TRUE, (void*)data, (unsigned long)xfer, &n, (unsigned long)0);
-            int saved_errno = GetLastError();
-            D("sdb_usb_read got(ret:%d): %ld, expected: %d, errno: %d\n", ret, n, xfer, saved_errno);
-
-            if (ret) {
-                data += n;
-                len -= n;
-
-                if (len == 0)
-                    return 0;
-            } else {
-                // assume ERROR_INVALID_HANDLE indicates we are disconnected
-                if (saved_errno == ERROR_INVALID_HANDLE) {
-                    sdb_usb_kick(handle);
-                }
-                break;
-            }
-            errno = saved_errno;
-        }
-    } else {
-        D("sdb_usb_read NULL handle\n");
-        SetLastError(ERROR_INVALID_HANDLE);
-    }
-
-    D("-sdb_usb_read failed: %d\n", errno);
-
-    return -1;
-}
-
-int win_usb_close(usb_handle *handle) {
-    D("+usb win_usb_close\n");
-    if (NULL != handle) {
-        if (NULL != handle->fd) {
-            WinUsb_Free(handle->fd);
-            handle->fd = NULL;
-        }
-        if (NULL != handle->hnd) {
-            CloseHandle(handle->hnd);
-            handle->hnd = NULL;
-        }
-        handle = NULL;
-    }
-    D("-usb win_usb_close\n");
-    return 0;
-}
-
-void sdb_usb_kick(usb_handle* handle) {
-    D("+sdb_usb_kick: %p\n", handle);
-    // called from transport remote kick if already registered
-    // so only clean for win usb handle resources
-    sdb_mutex_lock(&usb_lock, "usb sdb_usb_kick");
-    win_usb_close(handle);
-    sdb_mutex_unlock(&usb_lock , "usb sdb_usb_kick");
-    D("-sdb_usb_kick: %p\n", handle);
-}
-
-int sdb_usb_close(usb_handle* handle) {
-    D("+sdb_usb_close: %p\n", handle);
-    if (NULL != handle) {
-        sdb_mutex_lock(&usb_lock, "usb sdb_usb_close");
-        remove_node(&handle_list, handle->node, NULL);
-        sdb_mutex_unlock(&usb_lock, "usb sdb_usb_close");
-    }
-    D("-sdb_usb_close: %p\n", handle);
-    return 0;
-}
-
-void do_lsusb() {
-    usb_find_devices(TIZEN_CLASSID);
-}
diff --git a/deps/libusb/winusb.h b/deps/libusb/winusb.h
deleted file mode 100755 (executable)
index 8e5cf8a..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __WINUSB_H
-#define __WINUSB_H
-
-#include "ddk/usb100.h"
-#include "ddk/usbioctl.h"
-
-// Windows API default is uppercase - ugh!
-#if !defined(bool)
-#define bool BOOLEAN
-#endif
-#if !defined(true)
-#define true TRUE
-#endif
-#if !defined(false)
-#define false FALSE
-#endif
-
-
-/*
- * Some of the EX stuff is not yet in MinGW => define it
- */
-#ifndef USB_GET_NODE_CONNECTION_INFORMATION_EX
-#define USB_GET_NODE_CONNECTION_INFORMATION_EX 274
-#endif
-
-#ifndef IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX
-#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX \
-        CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION_EX, \
-        METHOD_BUFFERED, FILE_ANY_ACCESS)
-#endif
-
-#ifndef USB_NODE_CONNECTION_INFORMATION_EX
-typedef struct _USB_NODE_CONNECTION_INFORMATION_EX {
-        ULONG ConnectionIndex;
-        USB_DEVICE_DESCRIPTOR DeviceDescriptor;
-        UCHAR CurrentConfigurationValue;
-        UCHAR Speed;
-        BOOLEAN DeviceIsHub;
-        USHORT DeviceAddress;
-        ULONG NumberOfOpenPipes;
-        USB_CONNECTION_STATUS ConnectionStatus;
-        USB_PIPE_INFO PipeList[0];
-} USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX;
-#endif
-
-#ifndef USB_HUB_CAP_FLAGS
-typedef union _USB_HUB_CAP_FLAGS {
-        ULONG ul;
-        struct {
-                ULONG HubIsHighSpeedCapable:1;
-                ULONG HubIsHighSpeed:1;
-                ULONG HubIsMultiTtCapable:1;
-                ULONG HubIsMultiTt:1;
-                ULONG HubIsRoot:1;
-                ULONG HubIsArmedWakeOnConnect:1;
-                ULONG ReservedMBZ:26;
-        };
-} USB_HUB_CAP_FLAGS, *PUSB_HUB_CAP_FLAGS;
-#endif
-
-#ifndef USB_HUB_CAPABILITIES_EX
-typedef struct _USB_HUB_CAPABILITIES_EX {
-        USB_HUB_CAP_FLAGS CapabilityFlags;
-} USB_HUB_CAPABILITIES_EX, *PUSB_HUB_CAPABILITIES_EX;
-#endif
-
-#ifndef USB_GET_HUB_CAPABILITIES_EX
-#define USB_GET_HUB_CAPABILITIES_EX 276
-#endif
-
-#ifndef IOCTL_USB_GET_HUB_CAPABILITIES_EX
-#define IOCTL_USB_GET_HUB_CAPABILITIES_EX \
-        CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, \
-        METHOD_BUFFERED, FILE_ANY_ACCESS )
-#endif
-
-/*
- * WinUSB macros - from libusb-win32 1.x
- */
-
-#define DLL_DECLARE(api, ret, name, args) \
-   typedef ret (api * __dll_##name##_t)args; \
-   static __dll_##name##_t name
-
-#define DLL_LOAD(dll, name)                                   \
-  do {                                                        \
-  HMODULE h = GetModuleHandle(#dll);                          \
-  if(!h)                                                      \
-    h = LoadLibrary(#dll);                                    \
-  if(!h)                                                      \
-    break;                                                    \
-  if((name = (__dll_##name##_t)GetProcAddress(h, #name)))     \
-    break;                                                    \
-  if((name = (__dll_##name##_t)GetProcAddress(h, #name "A"))) \
-    break;                                                    \
-  if((name = (__dll_##name##_t)GetProcAddress(h, #name "W"))) \
-    break;                                                    \
-  } while(0)
-
-
-/* winusb.dll interface */
-
-#define SHORT_PACKET_TERMINATE  0x01
-#define AUTO_CLEAR_STALL        0x02
-#define PIPE_TRANSFER_TIMEOUT   0x03
-#define IGNORE_SHORT_PACKETS    0x04
-#define ALLOW_PARTIAL_READS     0x05
-#define AUTO_FLUSH              0x06
-#define RAW_IO                  0x07
-#define MAXIMUM_TRANSFER_SIZE   0x08
-#define AUTO_SUSPEND            0x81
-#define SUSPEND_DELAY           0x83
-#define DEVICE_SPEED            0x01
-#define LowSpeed                0x01
-#define FullSpeed               0x02
-#define HighSpeed               0x03
-
-typedef enum _USBD_PIPE_TYPE {
-        UsbdPipeTypeControl,
-        UsbdPipeTypeIsochronous,
-        UsbdPipeTypeBulk,
-        UsbdPipeTypeInterrupt
-} USBD_PIPE_TYPE;
-
-typedef struct {
-  USBD_PIPE_TYPE PipeType;
-  UCHAR          PipeId;
-  USHORT         MaximumPacketSize;
-  UCHAR          Interval;
-} WINUSB_PIPE_INFORMATION, *PWINUSB_PIPE_INFORMATION;
-
-#pragma pack(1)
-typedef struct {
-  UCHAR  RequestType;
-  UCHAR  Request;
-  USHORT Value;
-  USHORT Index;
-  USHORT Length;
-} WINUSB_SETUP_PACKET, *PWINUSB_SETUP_PACKET;
-#pragma pack()
-
-typedef void *WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
-
-#endif // __WINUSB_H
index 164ccd9453bf44cee082404bbf30ba8c7cf349c1..99569b0ba1af207c0f85e70e66e252e9da17f24c 100644 (file)
@@ -1,3 +1,6 @@
+* 2.2.21
+- sync source from dev branch
+== yoonki.park <yoonki.park@samsung.com> 2013-10-22 24:00
 * 2.2.20
 - fix offline bug
 == ho.namkoong <ho.namkoong@samsung.com> 2013-09-16 21:35
index edea43b34477d40b9a8b8b99a9b9c72a12254f7a..bc2cfe12c7e7b1e271e14b05098a6bf458f77430 100644 (file)
@@ -1,4 +1,4 @@
-Version:2.2.20
+Version:2.2.21
 Source:sdb
 Maintainer:Kangho Kim <kh5325.kim@samsung.com>, Yoonki Park<yoonki.park@samsung.com>, Hyunsik Noh<hyunsik.noh@samsung.com>, Gun Kim<gune.kim@samsung.com>, Ho Namkoong<ho.namkoong@samsung.com>, Taeyoung Son<taeyoung2.son@samsung.com>
 
index f17051619b5ea00421b4ad478d24a492b9507622..51815eff7cff28e69a2e9f1b9e4fc80fbeb7b838 100644 (file)
@@ -420,7 +420,7 @@ int version(int argc, char ** argv, void** extargv) {
         send_shellcommand(VERSION_QUERY, extargv);
     } else {
         fprintf(stdout, "Smart Development Bridge version %d.%d.%d\n",
-             SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_SERVER_VERSION);
+             SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_VERSION_PATCH);
     }
     return 0;
 }
index a761805c4228be6425d570d7f28c182af610d18d..46b8e1b168d017a3afd90f0b526746c2803b5700 100755 (executable)
@@ -506,7 +506,7 @@ int process_cmdline(int argc, char** argv) {
 static void print_help(LIST_NODE* optlist, LIST_NODE* cmdlist) {
 
     fprintf(stderr, "Smart Development Bridge version %d.%d.%d\n",
-         SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_SERVER_VERSION);
+         SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_VERSION_PATCH);
     fprintf(stderr, "\n Usage : sdb [option] <command> [parameters]\n\n");
     fprintf(stderr, " options:\n");
 
index 260cb4f3ba4d82bd4eaa8b869ce143b7cc157070..231e17fcc3b8ee1f24435fc275681ecac053bd27 100644 (file)
 #define DEFAULT_SDB_PORT 26099
 
 #define A_VERSION 0x0100000
-
-#define SDB_VERSION_MAJOR 2
-#define SDB_VERSION_MINOR 2
-
-#define SDB_SERVER_VERSION    6
+#define SDB_VERSION_MAJOR   2       // increments upon significant architectural changes or the achievement of important milestones
+#define SDB_VERSION_MINOR   2       // progress is made within a major version
+#define SDB_VERSION_PATCH   15      // increments for small sets of changes
+#define SDB_VERSION_MAX_LENGTH  128
 
 extern MAP hex_map;
 
index dcd199a34d6a59989b20404f5702737b0d0a75ae..d37ed7ff2060de69379156e22bdb5353ce4b9ecf 100644 (file)
@@ -52,7 +52,7 @@ static __inline__ void finalize(int srcfd, int dstfd, FILE_FUNC* srcF, FILE_FUNC
 static int file_copy(int src_fd, int dst_fd, char* srcp, char* dstp, FILE_FUNC* srcF, FILE_FUNC* dstF, unsigned* total_bytes, struct stat* src_stat, char* copy_flag) {
     D("file is copied from 'fd:%d' '%s' to 'fd:%d' '%s'\n", src_fd, srcp, dst_fd, dstp);
 
-    unsigned file_byte = src_stat->st_size;
+    //unsigned file_byte = src_stat->st_size;
     unsigned written_byte = 0;
 
     src_fd = srcF->readopen(src_fd, srcp, src_stat);
index 9471e56082dd967ec1d73fc60562d9fe3cf1926f..e17c34f0f270cdca321a928ce87561cc9f82228c 100755 (executable)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -136,17 +136,9 @@ int sdb_main(int is_daemon, int server_port)
     char local_name[30];
     build_local_name(local_name, sizeof(local_name), server_port);
     if(install_listener(local_name, "*smartsocket*", NULL)) {
-        exit(1);
+        _exit(1);
     }
-    if (is_daemon)
-    {
-        // inform our parent that we are up and running.
-#ifdef OS_WINDOWS
-        DWORD  count;
-        WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), "OK\n", 3, &count, NULL );
-#else
-        fprintf(stderr, "OK\n");
-#endif
+    if (is_daemon) {
         start_logging();
     }
     LOG_INFO("Event loop starting\n");
index 1aa4910f39440a6ddaa93fce3f8dbdcf94d5be16..2037d8a3caae4be231a5e08ef1bb9840e6884cd4 100644 (file)
@@ -25,6 +25,7 @@
 #include "fdevent.h"
 #include "sdb_constants.h"
 #include "utils.h"
+#include "strutils.h"
 
 #define  TRACE_TAG  TRACE_SDB
 #include "sdb_client.h"
@@ -326,6 +327,10 @@ int _sdb_connect(const char *service, void** ext_args)
 
     D("_sdb_connect: %s\n", service);
 
+    if (!strcmp(service, "host:start-server")) {
+        return 0;
+    }
+
     int server_port = *(int*)ext_args[2];
 
     fd = sdb_host_connect("127.0.0.1", server_port, SOCK_STREAM);
@@ -387,65 +392,83 @@ static int __inline__ write_msg_size(int fd, int size, int host_fd) {
  */
 int sdb_connect(const char *service, void** ext_args)
 {
-    // first query the sdb server's version
+    // check version before sending a sdb command
     int fd = _sdb_connect("host:version", ext_args);
     int server_port = *(int*)ext_args[2];
 
     D("sdb_connect: service %s\n", service);
-    if(fd == -2) {
-        fprintf(stdout,"* daemon not running. starting it now on port %d *\n",
-                server_port);
-    start_server:
-        if(launch_server(server_port)) {
-            fprintf(stderr,"* failed to start daemon *\n");
+
+    if (fd >= 0) {
+        int len = read_msg_size(fd);
+        char buf[SDB_VERSION_MAX_LENGTH] = {0,};
+        int restarting = 0;
+        if (len < 0) {
+            sdb_close(fd);
             return -1;
-        } else {
-            fprintf(stdout,"* daemon started successfully *\n");
         }
-        /* give the server some time to start properly and detect devices */
-        sdb_sleep_ms(3000);
-        // fall through to _sdb_connect
-    } else {
-        // if server was running, check its version to make sure it is not out of date
-        int version = SDB_SERVER_VERSION - 1;
-
-        // if we have a file descriptor, then parse version result
-        if(fd >= 0) {
-            int n = read_msg_size(fd);
-            char buf[100];
-            if(n < 0 || readx(fd, buf, n) || sscanf(buf, "%04x", &version) != 1) {
-                goto error;
-            }
+        if (readx(fd, buf, len) != 0 ){
             sdb_close(fd);
+            return -1;
+        }
+        char *tokens[3];
+        size_t cnt = tokenize(buf, ".", tokens, 3);
+
+        if (cnt == 3) { // since tizen2.2.1 rc 15
+            int major = strtoul(tokens[0], 0, 10);
+            int minor = strtoul(tokens[1], 0, 10);
+            int patch = strtoul(tokens[2], 0, 10);
+            if (major != SDB_VERSION_MAJOR || minor != SDB_VERSION_MINOR || patch != SDB_VERSION_PATCH ) {
+                fprintf(stdout,
+                        "* sdb (%s) already running, and restarting sdb(%d.%d.%d) again *\n",
+                        buf, SDB_VERSION_MAJOR, SDB_VERSION_MINOR,
+                        SDB_VERSION_PATCH);
+                restarting = 1;
+            }
         } else {
-                return fd;
+            int ver = 0;
+            if (sscanf(buf, "%04x", &ver) != 1) {
+                LOG_ERROR("version format is wrong:%s\n", buf);
+                // restart anyway!
+                restarting = 1;
+            } else {
+                if (ver != SDB_VERSION_PATCH) {
+                    fprintf(stdout,
+                            "* another version of sdb already running, and restarting sdb(%d.%d.%d) again *\n",
+                            SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_VERSION_PATCH);
+                    restarting = 1;
+                }
+            }
         }
-
-        if(version != SDB_SERVER_VERSION) {
-            printf("client version: %d, server version: %d\nsdb server is out of date.  killing...\n", version, SDB_SERVER_VERSION);
-            fd = _sdb_connect("host:kill", ext_args);
+        if (restarting) {
+            if (cnt) {
+                free_strings(tokens, cnt);
+            }
             sdb_close(fd);
-
-            /* XXX can we better detect its death? */
+            int fd2 = _sdb_connect("host:kill", ext_args);
+            sdb_close(fd2);
             sdb_sleep_ms(2000);
-            goto start_server;
+            goto launch_server;
         }
     }
 
-    // if the command is start-server, we are done.
-    if (!strcmp(service, "host:start-server"))
-        return 0;
+    if(fd == -2) {
+        fprintf(stdout,"* daemon not running. starting it now on port %d *\n", server_port);
+launch_server:
+        if(launch_server()) {
+            fprintf(stderr,"* failed to start daemon *\n");
+            return -1;
+        } else {
+            fprintf(stdout,"* daemon started successfully *\n");
+        }
+    }
 
     fd = _sdb_connect(service, ext_args);
     if(fd == -2) {
-        fprintf(stderr,"** daemon still not running");
+        fprintf(stderr,"** daemon still not running\n");
     }
-    D("sdb_connect: return fd %d\n", fd);
 
+    D("sdb_connect: return fd %d\n", fd);
     return fd;
-error:
-    sdb_close(fd);
-    return -1;
 }
 
 
index 4a02c6a6a9a3838633d91f336852b727373bf761..66c6e3f4289b9cf48253b6a543c40404e5e50ad1 100755 (executable)
@@ -650,7 +650,7 @@ static int handle_request_with_t(SDB_SOCKET* socket, char* service, TRANSPORT* t
                 return 0;
             }
             else {
-                LOG_INFO("LS(%X) T(%s) fail to install listener\n", socket->fd, t->device_name);
+                LOG_INFO("LS(%X) T(%s) fail to install listener\n", socket->fd, t->serial);
                 forward_err = "cannot install listener";
             }
         } else {
@@ -658,7 +658,7 @@ static int handle_request_with_t(SDB_SOCKET* socket, char* service, TRANSPORT* t
                 writex(socket->fd, "OKAYOKAY", 8);
                 return 0;
             } else {
-                LOG_INFO("LS(%X) T(%s) fail to remove listener\n", socket->fd, t->device_name);
+                LOG_INFO("LS(%X) T(%s) fail to remove listener\n", socket->fd, t->serial);
                 forward_err = "cannot remove listener";
             }
         }
@@ -916,10 +916,14 @@ success:
         return 0;
     }
 
-    // returns our value for SDB_SERVER_VERSION
+    // returns our value for SDB_VERSION_PATCH
     if (!strcmp(service, "version")) {
-        snprintf(cmd_buf, cbuf_size, "%04x", SDB_SERVER_VERSION);
-        sendokmsg(socket->fd, cmd_buf);
+        char ver[SDB_VERSION_MAX_LENGTH-8] = {0,};
+        char buf[SDB_VERSION_MAX_LENGTH] = {0,};
+
+        snprintf(ver, sizeof(ver), "%d.%d.%d", SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_VERSION_PATCH);
+        snprintf(buf, sizeof(buf), "OKAY%04x%s", strlen(ver), ver);
+        writex(socket->fd, buf, strlen(buf));
         return 0;
     }
 
@@ -1002,7 +1006,7 @@ static int smart_socket_enqueue(SDB_SOCKET *s, PACKET *p)
         if (t && t->connection_state != CS_OFFLINE) {
             s->transport = t;
             sdb_write(s->fd, "OKAY", 4);
-            D("LS(%X) get transport T(%s)", s->local_id, t->device_name);
+            D("LS(%X) get transport T(%s)", s->local_id, t->serial);
         } else {
             if(t != NULL) {
                 err_str = (char*)TRANSPORT_ERR_TARGET_OFFLINE;
index a0c0cacac88a28fe0c728e4f8a973abfe69edaba..177a5c2c71a61fadc8ad0654c08193189c3f8221 100755 (executable)
@@ -435,7 +435,7 @@ void register_transport(TRANSPORT *t)
 //lock is done by transport_unref
 static void remove_transport(TRANSPORT *t)
 {
-    D("transport removed. serial: %s, device name: %s\n", t->serial, t->device_name);
+    D("transport removed. T(%s), device name: %s\n", t->serial, t->device_name);
 
     remove_node(&transport_list, t->node, no_free);
 
index 80fc6690656f11fc5354a5fbbf7da29b3589eb79..823768130e605f2a44ef35f8951d9bb9974eef57 100755 (executable)
@@ -199,7 +199,7 @@ static void remote_kick(TRANSPORT *t)
 static void remote_close(TRANSPORT *t)
 {
     //nothing to close
-    D("close remote socket. serial: '%s', device name: '%s'\n", t->serial, t->device_name);
+    D("close remote socket. T(%s), device name: '%s'\n", t->serial, t->device_name);
 }
 
 static void init_socket_transport(TRANSPORT *t, int s, int sdb_port)
diff --git a/src/usb_windows.c b/src/usb_windows.c
new file mode 100644 (file)
index 0000000..c35a80b
--- /dev/null
@@ -0,0 +1,598 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <windows.h>
+#include <setupapi.h>
+#include <winerror.h>
+#include <limits.h>
+#include <stdio.h>
+#include <errno.h>
+#include "fdevent.h"
+#include "utils.h"
+#include "strutils.h"
+#include "linkedlist.h"
+
+#define   TRACE_TAG  TRACE_USB
+#include "sdb.h"
+#include "sdb_usb.h"
+#include "ddk/usb100.h"
+#include "ddk/usbioctl.h"
+
+#define DLL_SYMBOL_DECLARE(api, ret, name, args) \
+   typedef ret (api * __dll_##name##_t)args; \
+   static __dll_##name##_t name
+
+#define LOAD_FUNCPTR(name)                                    \
+  do {                                                        \
+  HMODULE h = GetModuleHandle("winusb.dll");                  \
+  if(h == NULL)                                               \
+    h = LoadLibrary("winusb.dll");                            \
+  if(h == NULL)                                               \
+    break;                                                    \
+  if((name = (__dll_##name##_t)GetProcAddress(h, #name)))     \
+    break;                                                    \
+  if((name = (__dll_##name##_t)GetProcAddress(h, #name "A"))) \
+    break;                                                    \
+  if((name = (__dll_##name##_t)GetProcAddress(h, #name "W"))) \
+    break;                                                    \
+  } while(0)
+
+// The USBD_PIPE_TYPE enumerator indicates the type of pipe.
+typedef enum _USBD_PIPE_TYPE { 
+  UsbdPipeTypeControl      = 0, //Indicates that the pipe is a control pipe.
+  UsbdPipeTypeIsochronous  = 1, //Indicates that the pipe is an isochronous transfer pipe.
+  UsbdPipeTypeBulk         = 2, //Indicates that the pipe is a bulk transfer pipe.
+  UsbdPipeTypeInterrupt    = 3  //Indicates that the pipe is a interrupt pipe.
+} USBD_PIPE_TYPE;
+
+// from Winusbio.h
+typedef struct _WINUSB_PIPE_INFORMATION {
+  USBD_PIPE_TYPE PipeType;          //A USBD_PIPE_TYPE-type enumeration value that specifies the pipe type.
+  UCHAR          PipeId;            //The pipe identifier (ID).
+  USHORT         MaximumPacketSize; //The maximum size, in bytes, of the packets that are transmitted on the pipe.
+  UCHAR          Interval;          //The pipe interval.
+} WINUSB_PIPE_INFORMATION, *PWINUSB_PIPE_INFORMATION;
+
+// from Winusb.h
+#pragma pack(1)
+typedef struct _WINUSB_SETUP_PACKET {
+  UCHAR  RequestType;   //The request type. The values that are assigned to this member are defined in Table 9.2 of section 9.3 of the Universal Serial Bus (USB) specification (www.usb.org).
+  UCHAR  Request;       //The device request. The values that are assigned to this member are defined in Table 9.3 of section 9.4 of the Universal Serial Bus (USB) specification.
+  USHORT Value;         //The meaning of this member varies according to the request. For an explanation of this member, see the Universal Serial Bus (USB) specification.
+  USHORT Index;         //The meaning of this member varies according to the request. For an explanation of this member, see the Universal Serial Bus (USB) specification.
+  USHORT Length;        //The number of bytes to transfer.
+} WINUSB_SETUP_PACKET, *PWINUSB_SETUP_PACKET;
+#pragma pack()
+
+typedef void *WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
+
+#define PIPE_TRANSFER_TIMEOUT   0x03 // Waits for a time-out interval before canceling the request
+struct usb_handle {
+    LIST_NODE* node;
+
+    HANDLE hnd;
+    WINUSB_INTERFACE_HANDLE fd;
+    char unique_node_path[PATH_MAX+1]; //MAX_DEVICE_ID_LEN <device-ID>\<instance-specific-ID>
+    UCHAR end_point[2];
+    unsigned int zero_mask;
+};
+usb_handle *usb_open(const char *device_path);
+int win_usb_close(usb_handle *dev);
+int usb_get_string_simple(usb_handle *dev, int index, char *buf, size_t buflen);
+void *device_poll_thread(void* unused);
+int usb_bulk_transfer(usb_handle* handle, BOOL is_read, const void *data, unsigned long length, unsigned long *actual_length, unsigned long timeout);
+void do_lsusb(void);
+
+// Class ID assigned to the device by aNdrOiduSb.sys
+static const GUID TIZEN_CLASSID = {0x9ca29f37, 0xdd62, 0x4aad, {0x82, 0x65, 0xcf, 0xf7, 0x88, 0xc8, 0xba, 0x89}};
+
+static LIST_NODE* handle_list = NULL;
+
+SDB_MUTEX_DEFINE( usb_lock );
+
+// winusb.dll entrypoints
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_Initialize, (HANDLE, PWINUSB_INTERFACE_HANDLE));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_Free, (WINUSB_INTERFACE_HANDLE));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_GetDescriptor, (WINUSB_INTERFACE_HANDLE, UCHAR, UCHAR, USHORT, PUCHAR, ULONG, PULONG));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_QueryInterfaceSettings, (WINUSB_INTERFACE_HANDLE, UCHAR, PUSB_INTERFACE_DESCRIPTOR));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_SetCurrentAlternateSetting, (WINUSB_INTERFACE_HANDLE, UCHAR));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_GetCurrentAlternateSetting, (WINUSB_INTERFACE_HANDLE, PUCHAR));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_QueryPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, UCHAR, PWINUSB_PIPE_INFORMATION));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_SetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, ULONG, ULONG, PVOID));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_GetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, ULONG, PULONG, PVOID));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_ReadPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_WritePipe, (WINUSB_INTERFACE_HANDLE, UCHAR, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_ControlTransfer, (WINUSB_INTERFACE_HANDLE, WINUSB_SETUP_PACKET, PUCHAR, ULONG, PULONG, LPOVERLAPPED));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_ResetPipe, (WINUSB_INTERFACE_HANDLE, UCHAR));
+DLL_SYMBOL_DECLARE(WINAPI, BOOL, WinUsb_GetOverlappedResult, (WINUSB_INTERFACE_HANDLE, LPOVERLAPPED, LPDWORD, BOOL));
+
+void win_usb_init(void) {
+    // Initialize DLL functions
+    if (!WinUsb_Initialize) {
+        LOAD_FUNCPTR(WinUsb_Initialize);
+        LOAD_FUNCPTR(WinUsb_Free);
+        LOAD_FUNCPTR(WinUsb_GetDescriptor);
+        LOAD_FUNCPTR(WinUsb_QueryInterfaceSettings);
+        LOAD_FUNCPTR(WinUsb_SetCurrentAlternateSetting);
+        LOAD_FUNCPTR(WinUsb_GetCurrentAlternateSetting);
+        LOAD_FUNCPTR(WinUsb_QueryPipe);
+        LOAD_FUNCPTR(WinUsb_SetPipePolicy);
+        LOAD_FUNCPTR(WinUsb_GetPipePolicy);
+        LOAD_FUNCPTR(WinUsb_ReadPipe);
+        LOAD_FUNCPTR(WinUsb_WritePipe);
+        LOAD_FUNCPTR(WinUsb_ControlTransfer);
+        LOAD_FUNCPTR(WinUsb_ResetPipe);
+        LOAD_FUNCPTR(WinUsb_GetOverlappedResult);
+    }
+}
+
+int is_device_registered(const char *node_path)
+{
+    int r = 0;
+    sdb_mutex_lock(&usb_lock, "usb is_device_registered");
+
+    LIST_NODE* cur_ptr = handle_list;
+    while(cur_ptr != NULL) {
+       usb_handle* usb = cur_ptr->data;
+       cur_ptr = cur_ptr->next_ptr;
+
+       if(!strcmp(usb->unique_node_path, node_path)) {
+               r = 1;
+               break;
+       }
+    }
+    sdb_mutex_unlock(&usb_lock, "usb is_device_registered");
+    return r;
+}
+
+usb_handle *usb_open(const char *device_path) {
+    // Allocate storage for handles
+    usb_handle* usb = calloc(1, sizeof(usb_handle));
+    s_strncpy(usb->unique_node_path, device_path, sizeof(usb->unique_node_path));
+
+    // Open generic handle to device
+    HANDLE hnd = CreateFile(device_path, GENERIC_WRITE | GENERIC_READ,
+            FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
+            FILE_FLAG_OVERLAPPED, NULL);
+
+    if (INVALID_HANDLE_VALUE == hnd) {
+        D("fail to create device file: %s due to: %d\n", device_path, GetLastError());
+       return NULL;
+    }
+
+    // Initialize WinUSB for this device and get a WinUSB handle for it
+    WINUSB_INTERFACE_HANDLE fd;
+    if (!WinUsb_Initialize(hnd, &fd)) {
+        return NULL;
+    }
+
+    // fetch USB device descriptor
+    USB_DEVICE_DESCRIPTOR         usb_device_descriptor;
+    unsigned long bytes_written;
+
+    if (!WinUsb_GetDescriptor(fd, USB_DEVICE_DESCRIPTOR_TYPE, 0, 0,
+            (PUCHAR)&usb_device_descriptor, sizeof(usb_device_descriptor), &bytes_written)) {
+        return NULL;
+    }
+
+    USB_INTERFACE_DESCRIPTOR      usb_interface_descriptor;
+
+    // fetch usb interface descriptor
+    UCHAR interface_number;
+    if (!WinUsb_GetCurrentAlternateSetting(fd, &interface_number)) {
+        return NULL;
+    }
+
+    if (!WinUsb_QueryInterfaceSettings(fd, interface_number, &usb_interface_descriptor)) {
+        return NULL;
+    }
+
+    if (2 != usb_interface_descriptor.bNumEndpoints) {
+        D("the number of endpoint should be two\n");
+        return NULL;
+    }
+
+    if (!is_sdb_interface(usb_device_descriptor.idVendor, usb_interface_descriptor.bInterfaceClass, usb_interface_descriptor.bInterfaceSubClass,
+            usb_interface_descriptor.bInterfaceProtocol)) {
+        return NULL;
+    }
+    UCHAR endpoint_index = 0;
+
+    for (endpoint_index = 0; endpoint_index < usb_interface_descriptor.bNumEndpoints; endpoint_index++) {
+        // fetch endpoint information
+        WINUSB_PIPE_INFORMATION pipe_info;
+        if (!WinUsb_QueryPipe(fd, interface_number, endpoint_index, &pipe_info)) {
+            return NULL;
+        }
+
+        if(usb_interface_descriptor.bInterfaceProtocol == 0x01) {
+            if (endpoint_index == 0) {
+                usb->zero_mask = pipe_info.MaximumPacketSize - 1;
+            }
+        }
+        // only interested in bulk type
+        if (UsbdPipeTypeBulk == pipe_info.PipeType) {
+            if (USB_ENDPOINT_DIRECTION_IN(pipe_info.PipeId)) {
+                D("builk in endpoint index: %d, id: %04x\n", endpoint_index, pipe_info.PipeId);
+                usb->end_point[0] = pipe_info.PipeId;
+            }
+
+            if (USB_ENDPOINT_DIRECTION_OUT(pipe_info.PipeId)) {
+                D("builk out endpoint index: %d, id: %04x\n", endpoint_index, pipe_info.PipeId);
+                usb->end_point[1] = pipe_info.PipeId;
+            }
+
+        }
+    }
+    usb->hnd = hnd;
+    usb->fd = fd;
+
+    return usb;
+}
+
+int register_device(usb_handle *hnd) {
+    if (is_device_registered(hnd->unique_node_path)) {
+        return 0;
+    }
+
+    sdb_mutex_lock(&usb_lock, "usb register_device");
+
+    hnd->node = prepend(&handle_list, hnd);
+
+    sdb_mutex_unlock(&usb_lock, "usb register_device");
+
+    return 1;
+}
+
+int usb_get_string_simple(usb_handle *dev, int index, char *buf, size_t buflen) {
+    unsigned char temp[MAXIMUM_USB_STRING_LENGTH];
+
+    ULONG actlen = 0;
+    //0x0409 for English (US)
+    if (!WinUsb_GetDescriptor(dev->fd, USB_STRING_DESCRIPTOR_TYPE, index, 0x0409, temp, sizeof(temp), &actlen)) {
+        return -GetLastError();
+    }
+    // Skip first two bytes of result (descriptor id and length), then take
+    // every other byte as a cheap way to convert Unicode to ASCII
+    unsigned int i, j;
+    for (i = 2, j = 0; i < actlen && j < (buflen - 1); i += 2, ++j)
+        buf[j] = temp[i];
+    buf[j] = '\0';
+
+    return strlen(buf);
+}
+
+static int get_serial_number(usb_handle *dev, char *buf, int buflen) {
+    USB_DEVICE_DESCRIPTOR         usb_device_descriptor;
+    ULONG actlen = 0;
+
+    if (!WinUsb_GetDescriptor(dev->fd, USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, (unsigned char*) &usb_device_descriptor,
+            sizeof(usb_device_descriptor), &actlen)) {
+        return 0;
+    }
+
+    return usb_get_string_simple(dev, usb_device_descriptor.iSerialNumber, buf, buflen);
+}
+
+int usb_find_devices(GUID deviceClassID) {
+    SP_DEVINFO_DATA deviceInfoData;
+    char devicePath[PATH_MAX + 1];
+    BOOL bResult = TRUE;
+    PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
+    int index = 0;
+
+    // from http://msdn.microsoft.com/en-us/library/windows/hardware/ff540174(v=vs.85).aspx
+    // Get information about all the installed devices for the specified device interface class.
+    HDEVINFO hDeviceInfo = SetupDiGetClassDevs(&deviceClassID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
+    if (hDeviceInfo == INVALID_HANDLE_VALUE) {
+        D("fail to find any device: %d\n", GetLastError());
+        return 0;
+    }
+
+    //Enumerate all the device interfaces in the device information set.
+    deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+
+    for (index = 0; ; index++) {
+
+        //Get information about the device interface.
+        SP_DEVICE_INTERFACE_DATA interfaceData;
+        interfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
+
+        bResult = SetupDiEnumDeviceInterfaces(hDeviceInfo, NULL, &deviceClassID, index, &interfaceData);
+        // Check if last item
+        if (GetLastError() == ERROR_NO_MORE_ITEMS) {
+            break;
+        }
+
+        //Check for some other error
+        if (!bResult)
+        {
+            D("Error SetupDiEnumDeviceInterfaces: %d.\n", GetLastError());
+            break;
+        }
+
+        // Determine required size for interface detail data
+        ULONG requiredLength = 0;
+
+        //Interface data is returned in SP_DEVICE_INTERFACE_DETAIL_DATA
+        //which we need to allocate, so we have to call this function twice.
+        //First to get the size so that we know how much to allocate
+        //Second, the actual call with the allocated buffer
+        bResult = SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &interfaceData, NULL, 0, &requiredLength, NULL);
+
+        //Check for some other error
+        if (!bResult) {
+            if ((ERROR_INSUFFICIENT_BUFFER == GetLastError()) && (requiredLength > 0)) {
+                // Allocate storage for interface detail data
+                detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(requiredLength);
+
+                if (detailData == NULL) {
+                    D("fail to allocate memory\n");
+                    break;
+                }
+            } else {
+                D("Error SetupDiEnumDeviceInterfaces: %d.\n", GetLastError());
+                break;
+            }
+        }
+
+        // Finally, do fetch interface detail data
+        detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
+        //Now call it with the correct size and allocated buffer
+        bResult = SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &interfaceData, detailData, requiredLength, NULL,
+                &deviceInfoData);
+
+        //Check for some other error
+        if (!bResult) {
+            D("fail to setdup get device interface detail: %d\n", GetLastError());
+            if (detailData != NULL) {
+                free(detailData);
+            }
+            break;
+        }
+
+        //copy device path
+        s_strncpy(devicePath, detailData->DevicePath, sizeof(devicePath));
+
+        if (detailData != NULL) {
+            free(detailData);
+        }
+
+        if (!is_device_registered(devicePath)) {
+            struct usb_handle *hnd = usb_open(devicePath);
+            if (hnd != NULL) {
+                char serial[256];
+                if (get_serial_number(hnd, serial, sizeof(serial)) > 0) {
+                    D("register usb for: %s\n", serial);
+                    if (register_device(hnd)) {
+                        register_usb_transport(hnd, serial);
+                    } else {
+                        D("fail to register usb\n");
+                        win_usb_close(hnd);
+                        free(hnd);
+                    }
+                } else {
+                    D("fail to get usb serial name: kick? close?\n");
+                    win_usb_close(hnd);
+                    free(hnd);
+                }
+            }
+        }
+    }
+    //  Cleanup
+    bResult = SetupDiDestroyDeviceInfoList(hDeviceInfo);
+
+    return bResult;
+}
+
+void* device_poll_thread(void* sleep_msec) {
+    D("Created device thread\n");
+
+    int  mseconds = (int) sleep_msec;
+    while (1) {
+        do_lsusb();
+        sdb_sleep_ms(mseconds);
+    }
+
+    return NULL;
+}
+
+void sdb_usb_init() {
+    sdb_thread_t tid;
+
+    win_usb_init();
+    if (sdb_thread_create(&tid, device_poll_thread, (void*)3000)) {
+        LOG_FATAL("cannot create input thread\n");
+    }
+}
+
+void sdb_usb_cleanup() {
+    D("TODO: not imple yet\n");
+}
+
+int usb_bulk_transfer(usb_handle* handle, BOOL is_read, const void *data, unsigned long length, unsigned long *actual_length, unsigned long timeout) {
+    ULONG tmp = timeout;
+    UCHAR endpoint;
+
+    if (is_read) {
+        endpoint = handle->end_point[0];
+    } else {
+        endpoint = handle->end_point[1];
+    }
+    if (handle->fd == NULL) {
+        D("invalid handle\n");
+        return 0;
+    }
+
+    // do not complete within the specified time-out interval
+    if (!WinUsb_SetPipePolicy(handle->fd, endpoint, PIPE_TRANSFER_TIMEOUT, sizeof(tmp), &tmp)) {
+        D("fail to set timeout\n");
+        SetLastError(ERROR_SEM_TIMEOUT);
+        return 0;
+    }
+
+    // manual reset must be true (second param) as the reset occurs in read
+
+    OVERLAPPED overlapped;
+    ZeroMemory(&overlapped, sizeof(overlapped));
+    overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+
+    BOOL ret = TRUE;
+    ULONG transferred = 0;
+
+    if (is_read) {
+        ret = WinUsb_ReadPipe(handle->fd, endpoint, (UCHAR*) data, length, &transferred, &overlapped);
+    } else {
+        ret = WinUsb_WritePipe(handle->fd, endpoint, (UCHAR*) data, length, &transferred, &overlapped);
+    }
+
+    if (!ret && (ERROR_IO_PENDING != GetLastError())) {
+        if (NULL != overlapped.hEvent){
+            CloseHandle(overlapped.hEvent);
+        }
+        D("pipe error: (%ld/ld) error:%d\n", length, transferred, GetLastError());
+        return 0;
+    }
+
+    // wait for the operation to be IO completed
+    ret = WinUsb_GetOverlappedResult(handle->fd, &overlapped, &transferred, TRUE);
+
+    if (ret && (NULL != actual_length)) {
+        *actual_length = transferred;
+    }
+
+    if (NULL != overlapped.hEvent) {
+        CloseHandle(overlapped.hEvent);
+    }
+
+    return ret ? 1 : 0;
+}
+
+int sdb_usb_write(usb_handle* handle, const void* data, int len) {
+    unsigned long time_out = 5000;//5000;
+    unsigned long written = 0;
+    int ret;
+
+    D("+sdb_usb_write %d\n", len);
+
+    if (NULL != handle) {
+        ret = usb_bulk_transfer(handle, FALSE, (void*)data, (unsigned long)len, &written, time_out);
+        int saved_errno = GetLastError();
+        D("sdb_usb_write got(ret:%d): %ld, expected: %d, errno: %d\n",ret, written, len, saved_errno);
+
+        if (ret) {
+            if (written == (unsigned long) len) {
+                if (handle->zero_mask && (len & handle->zero_mask) == 0) {
+                    // Send a zero length packet
+                    usb_bulk_transfer(handle, FALSE, (void*)data, 0, &written, time_out);
+                }
+                return 0;
+            }
+        } else {
+            // assume ERROR_INVALID_HANDLE indicates we are disconnected
+            if (saved_errno == ERROR_INVALID_HANDLE) {
+                sdb_usb_kick(handle);
+            }
+        }
+        errno = saved_errno;
+    } else {
+        D("usb_write NULL handle\n");
+        SetLastError(ERROR_INVALID_HANDLE);
+    }
+
+    D("-sdb_usb_write failed: %d\n", errno);
+
+    return -1;
+}
+
+int sdb_usb_read(usb_handle *handle, void* data, int len) {
+    unsigned long n = 0;
+    int ret;
+
+    D("+sdb_usb_read %d\n", len);
+    if (NULL != handle) {
+        while (len > 0) {
+            int xfer = (len > 4096) ? 4096 : len;
+            ret = usb_bulk_transfer(handle, TRUE, (void*)data, (unsigned long)xfer, &n, (unsigned long)0);
+            int saved_errno = GetLastError();
+            D("sdb_usb_read got(ret:%d): %ld, expected: %d, errno: %d\n", ret, n, xfer, saved_errno);
+
+            if (ret) {
+                data += n;
+                len -= n;
+
+                if (len == 0)
+                    return 0;
+            } else {
+                // assume ERROR_INVALID_HANDLE indicates we are disconnected
+                if (saved_errno == ERROR_INVALID_HANDLE) {
+                    sdb_usb_kick(handle);
+                }
+                break;
+            }
+            errno = saved_errno;
+        }
+    } else {
+        D("sdb_usb_read NULL handle\n");
+        SetLastError(ERROR_INVALID_HANDLE);
+    }
+
+    D("-sdb_usb_read failed: %d\n", errno);
+
+    return -1;
+}
+
+int win_usb_close(usb_handle *handle) {
+    D("+usb win_usb_close\n");
+    if (NULL != handle) {
+        if (NULL != handle->fd) {
+            WinUsb_Free(handle->fd);
+            handle->fd = NULL;
+        }
+        if (NULL != handle->hnd) {
+            CloseHandle(handle->hnd);
+            handle->hnd = NULL;
+        }
+        handle = NULL;
+    }
+    D("-usb win_usb_close\n");
+    return 0;
+}
+
+void sdb_usb_kick(usb_handle* handle) {
+    D("+sdb_usb_kick: %p\n", handle);
+    // called from transport remote kick if already registered
+    // so only clean for win usb handle resources
+    sdb_mutex_lock(&usb_lock, "usb sdb_usb_kick");
+    win_usb_close(handle);
+    sdb_mutex_unlock(&usb_lock , "usb sdb_usb_kick");
+    D("-sdb_usb_kick: %p\n", handle);
+}
+
+int sdb_usb_close(usb_handle* handle) {
+    D("+sdb_usb_close: %p\n", handle);
+    if (NULL != handle) {
+        sdb_mutex_lock(&usb_lock, "usb sdb_usb_close");
+        remove_node(&handle_list, handle->node, NULL);
+        sdb_mutex_unlock(&usb_lock, "usb sdb_usb_close");
+    }
+    D("-sdb_usb_close: %p\n", handle);
+    return 0;
+}
+
+void do_lsusb() {
+    usb_find_devices(TIZEN_CLASSID);
+}
index 16e1fecfcd221d0b3782bc3a4e7baa63bfd7a56b..67593149678d91f169ce8c76c3b9d9aac3bf2bad 100755 (executable)
@@ -176,8 +176,8 @@ void dup_quote(char* result_string, const char *source, int max_len)
 /**************************************************/
 /***           OS dependent helpers             ***/
 /**************************************************/
-int launch_server(int server_port) {
-    return utils_backend->launch_server(server_port);
+int launch_server(void) {
+    return utils_backend->launch_server();
 }
 
 void start_logging(void) {
index a31af3411405aa556aea682aab84e44acb495978..8ff8e0644774549f50e34a9d77b32a0b9f9883c3 100644 (file)
@@ -106,7 +106,7 @@ SDB_MUTEX(wakeup_select_lock)
 SDB_MUTEX(usb_lock)
 SDB_MUTEX(D_lock)
 
-int launch_server(int server_port);
+int launch_server();
 void start_logging(void);
 char* ansi_to_utf8(const char *str);
 int sdb_open(const char* path, int options);
index f8feb7ad3499a9f11a72ded84d1cff059cd713a9..4adea5e761c327f2011e156f814f05138d3f1a94 100755 (executable)
@@ -56,7 +56,7 @@ struct utils_os_backend {
     // human-readable name
     const char *name;
 
-    int (*launch_server)(int server_port);
+    int (*launch_server)(void);
     void (*start_logging)(void);
     char* (*ansi_to_utf8)(const char *str);
     int (*sdb_open)(const char* path, int options);
index 5f29b68cca145fa3fdc6b5cd29df10d7f0466f77..bd055bf56d0b2b52e16d1b963c1e9ef599d3de85 100755 (executable)
 #include "utils_backend.h"
 #include "log.h"
 
-#if defined(OS_DARWIN)
-
-void _get_sdb_path(char *s, size_t max_len)
+static int _launch_server(void)
 {
-    ProcessSerialNumber psn;
-    GetCurrentProcess(&psn);
-    CFDictionaryRef dict;
-    dict = ProcessInformationCopyDictionary(&psn, 0xffffffff);
-    CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict, CFSTR("CFBundleExecutable"));
-    CFStringGetCString(value, s, max_len, kCFStringEncodingUTF8);
-}
+    pid_t   pid;
 
-#elif defined(OS_LINUX)
+    switch (pid = fork()) {
+        case -1:
+            fprintf(stderr, "Couldn't fork: %s\n", strerror(errno));
+            return -1;
+            // never reached!
+        case 0: {
+            char path[128] = {0,};
 
-static void _get_sdb_path(char *exe, size_t max_len)
-{
-    char proc[64];
-    snprintf(proc, sizeof proc, "/proc/%d/exe", getpid());
-    int err = readlink(proc, exe, max_len - 1);
-    if(err > 0) {
-        exe[err] = '\0';
-    } else {
-        exe[0] = '\0';
-    }
-}
-#endif
+#if defined(OS_DARWIN)
+            ProcessSerialNumber psn;
+            GetCurrentProcess(&psn);
+            CFDictionaryRef dict;
+            dict = ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask); //0xffffffff
+            CFStringRef buf = (CFStringRef)CFDictionaryGetValue(dict, CFSTR("CFBundleExecutable"));
+            CFStringGetCString(buf, path, sizeof(path), kCFStringEncodingUTF8);
 
-static int _launch_server(int server_port)
-{
-    char    path[PATH_MAX];
-    int     fd[2];
+#elif defined(OS_LINUX)
+            ssize_t len = 0;
+            char buf[128] = {0,};
+            snprintf(buf, sizeof(buf), "/proc/%d/exe", getpid());
+            if ((len = readlink(buf, path, sizeof(path) - 1)) != -1) {
+                path[len] = '\0';
+            }
+#endif
+            // before fork exec, be session leader.
+            setsid();
 
-    // set up a pipe so the child can tell us when it is ready.
-    // fd[0] will be parent's end, and fd[1] will get mapped to stderr in the child.
-    if (pipe(fd)) {
-        fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
-        return -1;
-    }
-    _get_sdb_path(path, PATH_MAX);
-    pid_t pid = fork();
-    if(pid < 0) return -1;
-
-    if (pid == 0) {
-        // child side of the fork
-
-        // redirect stderr to the pipe
-        // we use stderr instead of stdout due to stdout's buffering behavior.
-        sdb_close(fd[0]);
-        dup2(fd[1], STDERR_FILENO);
-        sdb_close(fd[1]);
-
-        sdb_close(STDOUT_FILENO);
-
-        // child process
-        int result = execl(path, "sdb", "fork-server", "server", NULL);
-        // this should not return
-        fprintf(stderr, "OOPS! execl returned %d, errno: %d\n", result, errno);
-    } else  {
-        // parent side of the fork
-
-        char  temp[3];
-
-        temp[0] = 'A'; temp[1] = 'B'; temp[2] = 'C';
-        // wait for the "OK\n" message
-        sdb_close(fd[1]);
-        int ret = sdb_read(fd[0], temp, 3);
-        int saved_errno = errno;
-        sdb_close(fd[0]);
-
-        if (ret < 0) {
-            fprintf(stderr, "could not read ok from SDB Server, errno = %d\n", saved_errno);
-            return -1;
-        }
-        if (ret != 3 || temp[0] != 'O' || temp[1] != 'K' || temp[2] != '\n') {
-            fprintf(stderr, "SDB server didn't ACK\n" );
-            return -1;
+            execl(path, "sdb", "fork-server", "server", NULL);
+            fprintf(stderr, "Couldn't exec: '%s'\n", strerror(errno));
+            _exit(-1);
         }
-
-        setsid();
+        default:
+            // wait for sec due to for booting up sdb server
+            sdb_sleep_ms(3000);
+            break;
     }
+
     return 0;
 }
 
index 33edf5a13b686c29d37674b8376086f9e6185c18..05347a823dec7e9338a3ccb756b4ff04906b06dd 100755 (executable)
@@ -119,7 +119,7 @@ int getBaseErrno(DWORD dwLastErrorCode)
 /*
  * from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
  */
-static int _launch_server(int server_port) {
+static int _launch_server(void) {
     HANDLE g_hChildStd_OUT_Rd = NULL;
     HANDLE g_hChildStd_OUT_Wr = NULL;
     SECURITY_ATTRIBUTES saAttr;
@@ -190,22 +190,8 @@ static int _launch_server(int server_port) {
 
             CloseHandle(piProcInfo.hProcess);
             CloseHandle(piProcInfo.hThread);
-
-            //Read "OK\n" stdout message from sdb server
-            DWORD dwRead;
-            char chBuf[3];
-
-            bSuccess = ReadFile(g_hChildStd_OUT_Rd, chBuf, sizeof(chBuf), &dwRead, NULL);
-            CloseHandle(g_hChildStd_OUT_Rd);
-
-            if( ! bSuccess || dwRead == 0 ) {
-                fprintf(stderr, "fail to read ok message from sdb server: %ld\n", GetLastError());
-                return -1;
-            }
-            if (dwRead != 3 || chBuf[0] != 'O' || chBuf[1] != 'K' || chBuf[2] != '\n') {
-                fprintf(stderr, "fail to get OK\\n from sdb server: [%s]\n", chBuf);
-                return -1;
-            }
+            // wait for sec due to for booting up sdb server
+            sdb_sleep_ms(3000);
         }
     }
     return 0;