mirror of https://github.com/GOSTSec/sgminer
Con Kolivas
11 years ago
57 changed files with 2194 additions and 3435 deletions
@ -0,0 +1,554 @@
@@ -0,0 +1,554 @@
|
||||
Version 2.5 |
||||
=========== |
||||
|
||||
Released 2013-09-19 |
||||
|
||||
* New features: |
||||
|
||||
- `json_pack()` and friends: Add format specifiers ``s#``, ``+`` and |
||||
``+#``. |
||||
|
||||
- Add ``JSON_DECODE_INT_AS_REAL`` decoding flag to treat all numbers |
||||
as real in the decoder (#123). |
||||
|
||||
- Add `json_array_foreach()`, paralleling `json_object_foreach()` |
||||
(#118). |
||||
|
||||
* Bug fixes: |
||||
|
||||
- `json_dumps()` and friends: Don't crash if json is *NULL* and |
||||
``JSON_ENCODE_ANY`` is set. |
||||
|
||||
- Fix a theoretical integer overflow in `jsonp_strdup()`. |
||||
|
||||
- Fix `l_isxdigit()` macro (#97). |
||||
|
||||
- Fix an off-by-one error in `json_array_remove()`. |
||||
|
||||
* Build: |
||||
|
||||
- Support CMake in addition to GNU Autotools (#106, #107, #112, |
||||
#115, #120, #127). |
||||
|
||||
- Support building for Android (#109). |
||||
|
||||
- Don't use ``-Werror`` by default. |
||||
|
||||
- Support building and testing with VPATH (#93). |
||||
|
||||
- Fix compilation when ``NDEBUG`` is defined (#128) |
||||
|
||||
* Tests: |
||||
|
||||
- Fix a refleak in ``test/bin/json_process.c``. |
||||
|
||||
* Documentation: |
||||
|
||||
- Clarify the return value of `json_load_callback_t`. |
||||
|
||||
- Document how to circumvent problems with separate heaps on Windows. |
||||
|
||||
- Fix memory leaks and warnings in ``github_commits.c``. |
||||
|
||||
- Use `json_decref()` properly in tutorial. |
||||
|
||||
* Other: |
||||
|
||||
- Make it possible to forward declare ``struct json_t``. |
||||
|
||||
|
||||
Version 2.4 |
||||
=========== |
||||
|
||||
Released 2012-09-23 |
||||
|
||||
* New features: |
||||
|
||||
- Add `json_boolean()` macro that returns the JSON true or false |
||||
value based on its argument (#86). |
||||
|
||||
- Add `json_load_callback()` that calls a callback function |
||||
repeatedly to read the JSON input (#57). |
||||
|
||||
- Add JSON_ESCAPE_SLASH encoding flag to escape all occurences of |
||||
``/`` with ``\/``. |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Check for and reject NaN and Inf values for reals. Encoding these |
||||
values resulted in invalid JSON. |
||||
|
||||
- Fix `json_real_set()` to return -1 on error. |
||||
|
||||
* Build: |
||||
|
||||
- Jansson now builds on Windows with Visual Studio 2010, and |
||||
includes solution and project files in ``win32/vs2010/`` |
||||
directory. |
||||
|
||||
- Fix build warnings (#77, #78). |
||||
|
||||
- Add ``-no-undefined`` to LDFLAGS (#90). |
||||
|
||||
* Tests: |
||||
|
||||
- Fix the symbol exports test on Linux/PPC64 (#88). |
||||
|
||||
* Documentation: |
||||
|
||||
- Fix typos (#73, #84). |
||||
|
||||
|
||||
Version 2.3.1 |
||||
============= |
||||
|
||||
Released 2012-04-20 |
||||
|
||||
* Build issues: |
||||
|
||||
- Only use ``long long`` if ``strtoll()`` is also available. |
||||
|
||||
* Documentation: |
||||
|
||||
- Fix the names of library version constants in documentation. (#52) |
||||
|
||||
- Change the tutorial to use GitHub API v3. (#65) |
||||
|
||||
* Tests: |
||||
|
||||
- Make some tests locale independent. (#51) |
||||
|
||||
- Distribute the library exports test in the tarball. |
||||
|
||||
- Make test run on shells that don't support the ``export FOO=bar`` |
||||
syntax. |
||||
|
||||
|
||||
Version 2.3 |
||||
=========== |
||||
|
||||
Released 2012-01-27 |
||||
|
||||
* New features: |
||||
|
||||
- `json_unpack()` and friends: Add support for optional object keys |
||||
with the ``{s?o}`` syntax. |
||||
|
||||
- Add `json_object_update_existing()` and |
||||
`json_object_update_missing()`, for updating only existing keys or |
||||
only adding missing keys to an object. (#37) |
||||
|
||||
- Add `json_object_foreach()` for more convenient iteration over |
||||
objects. (#45, #46) |
||||
|
||||
- When decoding JSON, write the number of bytes that were read from |
||||
input to ``error.position`` also on success. This is handy with |
||||
``JSON_DISABLE_EOF_CHECK``. |
||||
|
||||
- Add support for decoding any JSON value, not just arrays or |
||||
objects. The support is enabled with the new ``JSON_DECODE_ANY`` |
||||
flag. Patch by Andrea Marchesini. (#4) |
||||
|
||||
* Bug fixes |
||||
|
||||
- Avoid problems with object's serial number growing too big. (#40, |
||||
#41) |
||||
|
||||
- Decoding functions now return NULL if the first argument is NULL. |
||||
Patch by Andrea Marchesini. |
||||
|
||||
- Include ``jansson_config.h.win32`` in the distribution tarball. |
||||
|
||||
- Remove ``+`` and leading zeros from exponents in the encoder. |
||||
(#39) |
||||
|
||||
- Make Jansson build and work on MinGW. (#39, #38) |
||||
|
||||
* Documentation |
||||
|
||||
- Note that the same JSON values must not be encoded in parallel by |
||||
separate threads. (#42) |
||||
|
||||
- Document MinGW support. |
||||
|
||||
|
||||
Version 2.2.1 |
||||
============= |
||||
|
||||
Released 2011-10-06 |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Fix real number encoding and decoding under non-C locales. (#32) |
||||
|
||||
- Fix identifier decoding under non-UTF-8 locales. (#35) |
||||
|
||||
- `json_load_file()`: Open the input file in binary mode for maximum |
||||
compatiblity. |
||||
|
||||
* Documentation: |
||||
|
||||
- Clarify the lifecycle of the result of the ``s`` fromat of |
||||
`json_unpack()`. (#31) |
||||
|
||||
- Add some portability info. (#36) |
||||
|
||||
- Little clarifications here and there. |
||||
|
||||
* Other: |
||||
|
||||
- Some style fixes, issues detected by static analyzers. |
||||
|
||||
|
||||
Version 2.2 |
||||
=========== |
||||
|
||||
Released 2011-09-03 |
||||
|
||||
* New features: |
||||
|
||||
- `json_dump_callback()`: Pass the encoder output to a callback |
||||
function in chunks. |
||||
|
||||
* Bug fixes: |
||||
|
||||
- `json_string_set()`: Check that target is a string and value is |
||||
not NULL. |
||||
|
||||
* Other: |
||||
|
||||
- Documentation typo fixes and clarifications. |
||||
|
||||
|
||||
Version 2.1 |
||||
=========== |
||||
|
||||
Released 2011-06-10 |
||||
|
||||
* New features: |
||||
|
||||
- `json_loadb()`: Decode a string with a given size, useful if the |
||||
string is not null terminated. |
||||
|
||||
- Add ``JSON_ENCODE_ANY`` encoding flag to allow encoding any JSON |
||||
value. By default, only arrays and objects can be encoded. (#19) |
||||
|
||||
- Add ``JSON_REJECT_DUPLICATES`` decoding flag to issue a decoding |
||||
error if any JSON object in the input contins duplicate keys. (#3) |
||||
|
||||
- Add ``JSON_DISABLE_EOF_CHECK`` decoding flag to stop decoding after a |
||||
valid JSON input. This allows other data after the JSON data. |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Fix an additional memory leak when memory allocation fails in |
||||
`json_object_set()` and friends. |
||||
|
||||
- Clear errno before calling `strtod()` for better portability. (#27) |
||||
|
||||
* Building: |
||||
|
||||
- Avoid set-but-not-used warning/error in a test. (#20) |
||||
|
||||
* Other: |
||||
|
||||
- Minor clarifications to documentation. |
||||
|
||||
|
||||
Version 2.0.1 |
||||
============= |
||||
|
||||
Released 2011-03-31 |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Replace a few `malloc()` and `free()` calls with their |
||||
counterparts that support custom memory management. |
||||
|
||||
- Fix object key hashing in json_unpack() strict checking mode. |
||||
|
||||
- Fix the parentheses in ``JANSSON_VERSION_HEX`` macro. |
||||
|
||||
- Fix `json_object_size()` return value. |
||||
|
||||
- Fix a few compilation issues. |
||||
|
||||
* Portability: |
||||
|
||||
- Enhance portability of `va_copy()`. |
||||
|
||||
- Test framework portability enhancements. |
||||
|
||||
* Documentation: |
||||
|
||||
- Distribute ``doc/upgrading.rst`` with the source tarball. |
||||
|
||||
- Build documentation in strict mode in ``make distcheck``. |
||||
|
||||
|
||||
Version 2.0 |
||||
=========== |
||||
|
||||
Released 2011-02-28 |
||||
|
||||
This release is backwards incompatible with the 1.x release series. |
||||
See the chapter "Upgrading from older versions" in documentation for |
||||
details. |
||||
|
||||
* Backwards incompatible changes: |
||||
|
||||
- Unify unsigned integer usage in the API: All occurences of |
||||
unsigned int and unsigned long have been replaced with size_t. |
||||
|
||||
- Change JSON integer's underlying type to the widest signed integer |
||||
type available, i.e. long long if it's supported, otherwise long. |
||||
Add a typedef json_int_t that defines the type. |
||||
|
||||
- Change the maximum indentation depth to 31 spaces in encoder. This |
||||
frees up bits from the flags parameter of encoding functions |
||||
`json_dumpf()`, `json_dumps()` and `json_dump_file()`. |
||||
|
||||
- For future needs, add a flags parameter to all decoding functions |
||||
`json_loadf()`, `json_loads()` and `json_load_file()`. |
||||
|
||||
* New features |
||||
|
||||
- `json_pack()`, `json_pack_ex()`, `json_vpack_ex()`: Create JSON |
||||
values based on a format string. |
||||
|
||||
- `json_unpack()`, `json_unpack_ex()`, `json_vunpack_ex()`: Simple |
||||
value extraction and validation functionality based on a format |
||||
string. |
||||
|
||||
- Add column, position and source fields to the ``json_error_t`` |
||||
struct. |
||||
|
||||
- Enhance error reporting in the decoder. |
||||
|
||||
- ``JANSSON_VERSION`` et al.: Preprocessor constants that define the |
||||
library version. |
||||
|
||||
- `json_set_alloc_funcs()`: Set custom memory allocation functions. |
||||
|
||||
* Fix many portability issues, especially on Windows. |
||||
|
||||
* Configuration |
||||
|
||||
- Add file ``jansson_config.h`` that contains site specific |
||||
configuration. It's created automatically by the configure script, |
||||
or can be created by hand if the configure script cannot be used. |
||||
The file ``jansson_config.h.win32`` can be used without |
||||
modifications on Windows systems. |
||||
|
||||
- Add a section to documentation describing how to build Jansson on |
||||
Windows. |
||||
|
||||
- Documentation now requires Sphinx 1.0 or newer. |
||||
|
||||
|
||||
Version 1.3 |
||||
=========== |
||||
|
||||
Released 2010-06-13 |
||||
|
||||
* New functions: |
||||
|
||||
- `json_object_iter_set()`, `json_object_iter_set_new()`: Change |
||||
object contents while iterating over it. |
||||
|
||||
- `json_object_iter_at()`: Return an iterator that points to a |
||||
specific object item. |
||||
|
||||
* New encoding flags: |
||||
|
||||
- ``JSON_PRESERVE_ORDER``: Preserve the insertion order of object |
||||
keys. |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Fix an error that occured when an array or object was first |
||||
encoded as empty, then populated with some data, and then |
||||
re-encoded |
||||
|
||||
- Fix the situation like above, but when the first encoding resulted |
||||
in an error |
||||
|
||||
* Documentation: |
||||
|
||||
- Clarify the documentation on reference stealing, providing an |
||||
example usage pattern |
||||
|
||||
|
||||
Version 1.2.1 |
||||
============= |
||||
|
||||
Released 2010-04-03 |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Fix reference counting on ``true``, ``false`` and ``null`` |
||||
- Estimate real number underflows in decoder with 0.0 instead of |
||||
issuing an error |
||||
|
||||
* Portability: |
||||
|
||||
- Make ``int32_t`` available on all systems |
||||
- Support compilers that don't have the ``inline`` keyword |
||||
- Require Autoconf 2.60 (for ``int32_t``) |
||||
|
||||
* Tests: |
||||
|
||||
- Print test names correctly when ``VERBOSE=1`` |
||||
- ``test/suites/api``: Fail when a test fails |
||||
- Enhance tests for iterators |
||||
- Enhance tests for decoding texts that contain null bytes |
||||
|
||||
* Documentation: |
||||
|
||||
- Don't remove ``changes.rst`` in ``make clean`` |
||||
- Add a chapter on RFC conformance |
||||
|
||||
|
||||
Version 1.2 |
||||
=========== |
||||
|
||||
Released 2010-01-21 |
||||
|
||||
* New functions: |
||||
|
||||
- `json_equal()`: Test whether two JSON values are equal |
||||
- `json_copy()` and `json_deep_copy()`: Make shallow and deep copies |
||||
of JSON values |
||||
- Add a version of all functions taking a string argument that |
||||
doesn't check for valid UTF-8: `json_string_nocheck()`, |
||||
`json_string_set_nocheck()`, `json_object_set_nocheck()`, |
||||
`json_object_set_new_nocheck()` |
||||
|
||||
* New encoding flags: |
||||
|
||||
- ``JSON_SORT_KEYS``: Sort objects by key |
||||
- ``JSON_ENSURE_ASCII``: Escape all non-ASCII Unicode characters |
||||
- ``JSON_COMPACT``: Use a compact representation with all unneeded |
||||
whitespace stripped |
||||
|
||||
* Bug fixes: |
||||
|
||||
- Revise and unify whitespace usage in encoder: Add spaces between |
||||
array and object items, never append newline to output. |
||||
- Remove const qualifier from the ``json_t`` parameter in |
||||
`json_string_set()`, `json_integer_set()` and `json_real_set`. |
||||
- Use ``int32_t`` internally for representing Unicode code points |
||||
(int is not enough on all platforms) |
||||
|
||||
* Other changes: |
||||
|
||||
- Convert ``CHANGES`` (this file) to reStructured text and add it to |
||||
HTML documentation |
||||
- The test system has been refactored. Python is no longer required |
||||
to run the tests. |
||||
- Documentation can now be built by invoking ``make html`` |
||||
- Support for pkg-config |
||||
|
||||
|
||||
Version 1.1.3 |
||||
============= |
||||
|
||||
Released 2009-12-18 |
||||
|
||||
* Encode reals correctly, so that first encoding and then decoding a |
||||
real always produces the same value |
||||
* Don't export private symbols in ``libjansson.so`` |
||||
|
||||
|
||||
Version 1.1.2 |
||||
============= |
||||
|
||||
Released 2009-11-08 |
||||
|
||||
* Fix a bug where an error message was not produced if the input file |
||||
could not be opened in `json_load_file()` |
||||
* Fix an assertion failure in decoder caused by a minus sign without a |
||||
digit after it |
||||
* Remove an unneeded include of ``stdint.h`` in ``jansson.h`` |
||||
|
||||
|
||||
Version 1.1.1 |
||||
============= |
||||
|
||||
Released 2009-10-26 |
||||
|
||||
* All documentation files were not distributed with v1.1; build |
||||
documentation in make distcheck to prevent this in the future |
||||
* Fix v1.1 release date in ``CHANGES`` |
||||
|
||||
|
||||
Version 1.1 |
||||
=========== |
||||
|
||||
Released 2009-10-20 |
||||
|
||||
* API additions and improvements: |
||||
|
||||
- Extend array and object APIs |
||||
- Add functions to modify integer, real and string values |
||||
- Improve argument validation |
||||
- Use unsigned int instead of ``uint32_t`` for encoding flags |
||||
|
||||
* Enhance documentation |
||||
|
||||
- Add getting started guide and tutorial |
||||
- Fix some typos |
||||
- General clarifications and cleanup |
||||
|
||||
* Check for integer and real overflows and underflows in decoder |
||||
* Make singleton values thread-safe (``true``, ``false`` and ``null``) |
||||
* Enhance circular reference handling |
||||
* Don't define ``-std=c99`` in ``AM_CFLAGS`` |
||||
* Add C++ guards to ``jansson.h`` |
||||
* Minor performance and portability improvements |
||||
* Expand test coverage |
||||
|
||||
|
||||
Version 1.0.4 |
||||
============= |
||||
|
||||
Released 2009-10-11 |
||||
|
||||
* Relax Autoconf version requirement to 2.59 |
||||
* Make Jansson compile on platforms where plain ``char`` is unsigned |
||||
* Fix API tests for object |
||||
|
||||
|
||||
Version 1.0.3 |
||||
============= |
||||
|
||||
Released 2009-09-14 |
||||
|
||||
* Check for integer and real overflows and underflows in decoder |
||||
* Use the Python json module for tests, or simplejson if the json |
||||
module is not found |
||||
* Distribute changelog (this file) |
||||
|
||||
|
||||
Version 1.0.2 |
||||
============= |
||||
|
||||
Released 2009-09-08 |
||||
|
||||
* Handle EOF correctly in decoder |
||||
|
||||
|
||||
Version 1.0.1 |
||||
============= |
||||
|
||||
Released 2009-09-04 |
||||
|
||||
* Fixed broken `json_is_boolean()` |
||||
|
||||
|
||||
Version 1.0 |
||||
=========== |
||||
|
||||
Released 2009-08-25 |
||||
|
||||
* Initial release |
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org> |
||||
Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
ACLOCAL_AMFLAGS = -I m4 |
||||
|
||||
EXTRA_DIST = CHANGES LICENSE README.rst |
||||
SUBDIRS = src |
||||
|
||||
# "make distcheck" builds the dvi target, so use it to check that the
|
||||
# documentation is built correctly.
|
||||
dvi: |
||||
$(MAKE) SPHINXOPTS_EXTRA=-W html |
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig |
||||
pkgconfig_DATA = jansson.pc |
||||
|
||||
if GCC |
||||
# These flags are gcc specific
|
||||
export AM_CFLAGS = -Wall -Wextra -Wdeclaration-after-statement |
||||
endif |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
Jansson README |
||||
============== |
||||
|
||||
.. image:: https://travis-ci.org/akheron/jansson.png |
||||
:alt: Build status |
||||
:target: https://travis-ci.org/akheron/jansson |
||||
|
||||
Jansson_ is a C library for encoding, decoding and manipulating JSON |
||||
data. Its main features and design principles are: |
||||
|
||||
- Simple and intuitive API and data model |
||||
|
||||
- Comprehensive documentation |
||||
|
||||
- No dependencies on other libraries |
||||
|
||||
- Full Unicode support (UTF-8) |
||||
|
||||
- Extensive test suite |
||||
|
||||
Jansson is licensed under the `MIT license`_; see LICENSE in the |
||||
source distribution for details. |
||||
|
||||
|
||||
Compilation and Installation |
||||
---------------------------- |
||||
|
||||
If you obtained a source tarball, just use the standard autotools |
||||
commands:: |
||||
|
||||
$ ./configure |
||||
$ make |
||||
$ make install |
||||
|
||||
To run the test suite, invoke:: |
||||
|
||||
$ make check |
||||
|
||||
If the source has been checked out from a Git repository, the |
||||
./configure script has to be generated first. The easiest way is to |
||||
use autoreconf:: |
||||
|
||||
$ autoreconf -i |
||||
|
||||
|
||||
Documentation |
||||
------------- |
||||
|
||||
Prebuilt HTML documentation is available at |
||||
http://www.digip.org/jansson/doc/. |
||||
|
||||
The documentation source is in the ``doc/`` subdirectory. To generate |
||||
HTML documentation, invoke:: |
||||
|
||||
$ make html |
||||
|
||||
Then, point your browser to ``doc/_build/html/index.html``. Sphinx_ |
||||
1.0 or newer is required to generate the documentation. |
||||
|
||||
|
||||
.. _Jansson: http://www.digip.org/jansson/ |
||||
.. _`MIT license`: http://www.opensource.org/licenses/mit-license.php |
||||
.. _Sphinx: http://sphinx.pocoo.org/ |
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
AC_PREREQ([2.60]) |
||||
AC_INIT([jansson], [2.5], [petri@digip.org]) |
||||
|
||||
AC_CONFIG_MACRO_DIR([m4]) |
||||
|
||||
AM_INIT_AUTOMAKE([1.10 foreign]) |
||||
|
||||
AC_CONFIG_SRCDIR([src/value.c]) |
||||
AC_CONFIG_HEADERS([config.h]) |
||||
|
||||
# Checks for programs. |
||||
AC_PROG_CC |
||||
AC_PROG_LIBTOOL |
||||
AM_CONDITIONAL([GCC], [test x$GCC = xyes]) |
||||
|
||||
# Checks for libraries. |
||||
|
||||
# Checks for header files. |
||||
AC_CHECK_HEADERS([locale.h]) |
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics. |
||||
AC_TYPE_INT32_T |
||||
AC_TYPE_LONG_LONG_INT |
||||
|
||||
AC_C_INLINE |
||||
case $ac_cv_c_inline in |
||||
yes) json_inline=inline;; |
||||
no) json_inline=;; |
||||
*) json_inline=$ac_cv_c_inline;; |
||||
esac |
||||
AC_SUBST([json_inline]) |
||||
|
||||
# Checks for library functions. |
||||
AC_CHECK_FUNCS([strtoll localeconv]) |
||||
|
||||
case "$ac_cv_type_long_long_int$ac_cv_func_strtoll" in |
||||
yesyes) json_have_long_long=1;; |
||||
*) json_have_long_long=0;; |
||||
esac |
||||
AC_SUBST([json_have_long_long]) |
||||
|
||||
case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in |
||||
yesyes) json_have_localeconv=1;; |
||||
*) json_have_localeconv=0;; |
||||
esac |
||||
AC_SUBST([json_have_localeconv]) |
||||
|
||||
AC_CONFIG_FILES([ |
||||
jansson.pc |
||||
Makefile |
||||
src/Makefile |
||||
src/jansson_config.h |
||||
]) |
||||
AC_OUTPUT |
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
prefix=@prefix@ |
||||
exec_prefix=@exec_prefix@ |
||||
libdir=@libdir@ |
||||
includedir=${prefix}/include |
||||
|
||||
Name: Jansson |
||||
Description: Library for encoding, decoding and manipulating JSON data |
||||
Version: @VERSION@ |
||||
Libs: -L${libdir} -ljansson |
||||
Cflags: -I${includedir} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
EXTRA_DIST = jansson.def |
||||
|
||||
include_HEADERS = jansson.h jansson_config.h |
||||
|
||||
lib_LTLIBRARIES = libjansson.la |
||||
libjansson_la_SOURCES = \
|
||||
dump.c \
|
||||
error.c \
|
||||
hashtable.c \
|
||||
hashtable.h \
|
||||
jansson_private.h \
|
||||
load.c \
|
||||
memory.c \
|
||||
pack_unpack.c \
|
||||
strbuffer.c \
|
||||
strbuffer.h \
|
||||
strconv.c \
|
||||
utf.c \
|
||||
utf.h \
|
||||
value.c |
||||
libjansson_la_LDFLAGS = \
|
||||
-no-undefined \
|
||||
-export-symbols-regex '^json_' \
|
||||
-version-info 9:0:5 |
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 Petri Lehtinen <petri@digip.org> |
||||
* Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org> |
||||
* |
||||
* This library is free software; you can redistribute it and/or modify |
||||
* it under the terms of the MIT license. See LICENSE for details. |
@ -1,5 +1,3 @@
@@ -1,5 +1,3 @@
|
||||
LIBRARY "jansson" |
||||
|
||||
EXPORTS |
||||
json_delete |
||||
json_true |
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 Petri Lehtinen <petri@digip.org> |
||||
* Copyright (c) 2010-2013 Petri Lehtinen <petri@digip.org> |
||||
* |
||||
* Jansson is free software; you can redistribute it and/or modify |
||||
* it under the terms of the MIT license. See LICENSE for details. |
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 Petri Lehtinen <petri@digip.org> |
||||
* Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org> |
||||
* |
||||
* Jansson is free software; you can redistribute it and/or modify |
||||
* it under the terms of the MIT license. See LICENSE for details. |
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 Petri Lehtinen <petri@digip.org> |
||||
* Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org> |
||||
* |
||||
* Jansson is free software; you can redistribute it and/or modify |
||||
* it under the terms of the MIT license. See LICENSE for details. |
@ -1,21 +0,0 @@
@@ -1,21 +0,0 @@
|
||||
EXTRA_DIST = jansson.def |
||||
|
||||
include_HEADERS = jansson.h jansson_config.h |
||||
|
||||
noinst_LIBRARIES = libjansson.a |
||||
|
||||
libjansson_a_SOURCES = \
|
||||
dump.c \
|
||||
error.c \
|
||||
hashtable.c \
|
||||
hashtable.h \
|
||||
jansson_private.h \
|
||||
load.c \
|
||||
memory.c \
|
||||
pack_unpack.c \
|
||||
strbuffer.c \
|
||||
strbuffer.h \
|
||||
strconv.c \
|
||||
utf.c \
|
||||
utf.h \
|
||||
value.c |
@ -1,39 +0,0 @@
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 Petri Lehtinen <petri@digip.org> |
||||
* |
||||
* Jansson is free software; you can redistribute it and/or modify |
||||
* it under the terms of the MIT license. See LICENSE for details. |
||||
* |
||||
* |
||||
* This file specifies a part of the site-specific configuration for |
||||
* Jansson, namely those things that affect the public API in |
||||
* jansson.h. |
||||
* |
||||
* The configure script copies this file to jansson_config.h and |
||||
* replaces @var@ substitutions by values that fit your system. If you |
||||
* cannot run the configure script, you can do the value substitution |
||||
* by hand. |
||||
*/ |
||||
|
||||
#ifndef JANSSON_CONFIG_H |
||||
#define JANSSON_CONFIG_H |
||||
|
||||
/* If your compiler supports the inline keyword in C, JSON_INLINE is
|
||||
defined to `inline', otherwise empty. In C++, the inline is always |
||||
supported. */ |
||||
#ifdef __cplusplus |
||||
#define JSON_INLINE inline |
||||
#else |
||||
#define JSON_INLINE inline |
||||
#endif |
||||
|
||||
/* If your compiler supports the `long long` type and the strtoll()
|
||||
library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, |
||||
otherwise to 0. */ |
||||
#define JSON_INTEGER_IS_LONG_LONG 1 |
||||
|
||||
/* If locale.h and localeconv() are available, define to 1,
|
||||
otherwise to 0. */ |
||||
#define JSON_HAVE_LOCALECONV 1 |
||||
|
||||
#endif |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org> |
||||
* |
||||
* Jansson is free software; you can redistribute it and/or modify |
||||
* it under the terms of the MIT license. See LICENSE for details. |
||||
*/ |
||||
|
||||
#ifndef UTIL_H |
||||
#define UTIL_H |
||||
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b)) |
||||
|
||||
#endif |
@ -1,10 +0,0 @@
@@ -1,10 +0,0 @@
|
||||
EXTRA_DIST = doxygen.cfg.in |
||||
|
||||
docs: doxygen.cfg |
||||
doxygen $^ |
||||
|
||||
docs-upload: docs |
||||
ln -s html api-1.0 |
||||
rsync -av api-1.0/ web.sourceforge.net:htdocs/api-1.0/ |
||||
rm -f api-1.0 |
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,15 +0,0 @@
@@ -1,15 +0,0 @@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/libusb |
||||
LDADD = ../libusb/libusb-1.0.la |
||||
noinst_PROGRAMS = listdevs hotplugtest testlibusb1 |
||||
|
||||
if HAVE_SIGACTION |
||||
noinst_PROGRAMS += dpfp |
||||
|
||||
if THREADS_POSIX |
||||
dpfp_threaded_CFLAGS = $(AM_CFLAGS) |
||||
noinst_PROGRAMS += dpfp_threaded |
||||
endif |
||||
|
||||
sam3u_benchmark_SOURCES = sam3u_benchmark.c |
||||
noinst_PROGRAMS += sam3u_benchmark |
||||
endif |
@ -1,507 +0,0 @@
@@ -1,507 +0,0 @@
|
||||
/*
|
||||
* libusb example program to manipulate U.are.U 4000B fingerprint scanner. |
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org> |
||||
* |
||||
* Basic image capture program only, does not consider the powerup quirks or |
||||
* the fact that image encryption may be enabled. Not expected to work |
||||
* flawlessly all of the time. |
||||
* |
||||
* 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 |
||||
*/ |
||||
|
||||
#include <errno.h> |
||||
#include <signal.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
|
||||
#include <libusb.h> |
||||
|
||||
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN) |
||||
#define EP_DATA (2 | LIBUSB_ENDPOINT_IN) |
||||
#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN) |
||||
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT) |
||||
#define USB_RQ 0x04 |
||||
#define INTR_LENGTH 64 |
||||
|
||||
enum { |
||||
MODE_INIT = 0x00, |
||||
MODE_AWAIT_FINGER_ON = 0x10, |
||||
MODE_AWAIT_FINGER_OFF = 0x12, |
||||
MODE_CAPTURE = 0x20, |
||||
MODE_SHUT_UP = 0x30, |
||||
MODE_READY = 0x80, |
||||
}; |
||||
|
||||
static int next_state(void); |
||||
|
||||
enum { |
||||
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1, |
||||
STATE_AWAIT_IRQ_FINGER_DETECTED, |
||||
STATE_AWAIT_MODE_CHANGE_CAPTURE, |
||||
STATE_AWAIT_IMAGE, |
||||
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF, |
||||
STATE_AWAIT_IRQ_FINGER_REMOVED, |
||||
}; |
||||
|
||||
static int state = 0; |
||||
static struct libusb_device_handle *devh = NULL; |
||||
static unsigned char imgbuf[0x1b340]; |
||||
static unsigned char irqbuf[INTR_LENGTH]; |
||||
static struct libusb_transfer *img_transfer = NULL; |
||||
static struct libusb_transfer *irq_transfer = NULL; |
||||
static int img_idx = 0; |
||||
static int do_exit = 0; |
||||
|
||||
static int find_dpfp_device(void) |
||||
{ |
||||
devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a); |
||||
return devh ? 0 : -EIO; |
||||
} |
||||
|
||||
static int print_f0_data(void) |
||||
{ |
||||
unsigned char data[0x10]; |
||||
int r; |
||||
unsigned int i; |
||||
|
||||
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data, |
||||
sizeof(data), 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "F0 error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < sizeof(data)) { |
||||
fprintf(stderr, "short read (%d)\n", r); |
||||
return -1; |
||||
} |
||||
|
||||
printf("F0 data:"); |
||||
for (i = 0; i < sizeof(data); i++) |
||||
printf("%02x ", data[i]); |
||||
printf("\n"); |
||||
return 0; |
||||
} |
||||
|
||||
static int get_hwstat(unsigned char *status) |
||||
{ |
||||
int r; |
||||
|
||||
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0x07, 0, status, 1, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "read hwstat error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < 1) { |
||||
fprintf(stderr, "short read (%d)\n", r); |
||||
return -1; |
||||
} |
||||
|
||||
printf("hwstat reads %02x\n", *status); |
||||
return 0; |
||||
} |
||||
|
||||
static int set_hwstat(unsigned char data) |
||||
{ |
||||
int r; |
||||
|
||||
printf("set hwstat to %02x\n", data); |
||||
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x07, 0, &data, 1, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "set hwstat error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < 1) { |
||||
fprintf(stderr, "short write (%d)", r); |
||||
return -1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int set_mode(unsigned char data) |
||||
{ |
||||
int r; |
||||
printf("set mode %02x\n", data); |
||||
|
||||
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "set mode error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < 1) { |
||||
fprintf(stderr, "short write (%d)", r); |
||||
return -1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer) |
||||
{ |
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "mode change transfer not completed!\n"); |
||||
do_exit = 2; |
||||
} |
||||
|
||||
printf("async cb_mode_changed length=%d actual_length=%d\n", |
||||
transfer->length, transfer->actual_length); |
||||
if (next_state() < 0) |
||||
do_exit = 2; |
||||
} |
||||
|
||||
static int set_mode_async(unsigned char data) |
||||
{ |
||||
unsigned char *buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); |
||||
struct libusb_transfer *transfer; |
||||
|
||||
if (!buf) |
||||
return -ENOMEM; |
||||
|
||||
transfer = libusb_alloc_transfer(0); |
||||
if (!transfer) { |
||||
free(buf); |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
printf("async set mode %02x\n", data); |
||||
libusb_fill_control_setup(buf, CTRL_OUT, USB_RQ, 0x4e, 0, 1); |
||||
buf[LIBUSB_CONTROL_SETUP_SIZE] = data; |
||||
libusb_fill_control_transfer(transfer, devh, buf, cb_mode_changed, NULL, |
||||
1000); |
||||
|
||||
transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK |
||||
| LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER; |
||||
return libusb_submit_transfer(transfer); |
||||
} |
||||
|
||||
static int do_sync_intr(unsigned char *data) |
||||
{ |
||||
int r; |
||||
int transferred; |
||||
|
||||
r = libusb_interrupt_transfer(devh, EP_INTR, data, INTR_LENGTH, |
||||
&transferred, 1000); |
||||
if (r < 0) { |
||||
fprintf(stderr, "intr error %d\n", r); |
||||
return r; |
||||
} |
||||
if (transferred < INTR_LENGTH) { |
||||
fprintf(stderr, "short read (%d)\n", r); |
||||
return -1; |
||||
} |
||||
|
||||
printf("recv interrupt %04x\n", *((uint16_t *) data)); |
||||
return 0; |
||||
} |
||||
|
||||
static int sync_intr(unsigned char type) |
||||
{ |
||||
int r; |
||||
unsigned char data[INTR_LENGTH]; |
||||
|
||||
while (1) { |
||||
r = do_sync_intr(data); |
||||
if (r < 0) |
||||
return r; |
||||
if (data[0] == type) |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
static int save_to_file(unsigned char *data) |
||||
{ |
||||
FILE *fd; |
||||
char filename[64]; |
||||
|
||||
snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++); |
||||
fd = fopen(filename, "w"); |
||||
if (!fd) |
||||
return -1; |
||||
|
||||
fputs("P5 384 289 255 ", fd); |
||||
(void) fwrite(data + 64, 1, 384*289, fd); |
||||
fclose(fd); |
||||
printf("saved image to %s\n", filename); |
||||
return 0; |
||||
} |
||||
|
||||
static int next_state(void) |
||||
{ |
||||
int r = 0; |
||||
printf("old state: %d\n", state); |
||||
switch (state) { |
||||
case STATE_AWAIT_IRQ_FINGER_REMOVED: |
||||
state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON; |
||||
r = set_mode_async(MODE_AWAIT_FINGER_ON); |
||||
break; |
||||
case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON: |
||||
state = STATE_AWAIT_IRQ_FINGER_DETECTED; |
||||
break; |
||||
case STATE_AWAIT_IRQ_FINGER_DETECTED: |
||||
state = STATE_AWAIT_MODE_CHANGE_CAPTURE; |
||||
r = set_mode_async(MODE_CAPTURE); |
||||
break; |
||||
case STATE_AWAIT_MODE_CHANGE_CAPTURE: |
||||
state = STATE_AWAIT_IMAGE; |
||||
break; |
||||
case STATE_AWAIT_IMAGE: |
||||
state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF; |
||||
r = set_mode_async(MODE_AWAIT_FINGER_OFF); |
||||
break; |
||||
case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF: |
||||
state = STATE_AWAIT_IRQ_FINGER_REMOVED; |
||||
break; |
||||
default: |
||||
printf("unrecognised state %d\n", state); |
||||
} |
||||
if (r < 0) { |
||||
fprintf(stderr, "error detected changing state\n"); |
||||
return r; |
||||
} |
||||
|
||||
printf("new state: %d\n", state); |
||||
return 0; |
||||
} |
||||
|
||||
static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer) |
||||
{ |
||||
unsigned char irqtype = transfer->buffer[0]; |
||||
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "irq transfer status %d?\n", transfer->status); |
||||
do_exit = 2; |
||||
libusb_free_transfer(transfer); |
||||
irq_transfer = NULL; |
||||
return; |
||||
} |
||||
|
||||
printf("IRQ callback %02x\n", irqtype); |
||||
switch (state) { |
||||
case STATE_AWAIT_IRQ_FINGER_DETECTED: |
||||
if (irqtype == 0x01) { |
||||
if (next_state() < 0) { |
||||
do_exit = 2; |
||||
return; |
||||
} |
||||
} else { |
||||
printf("finger-on-sensor detected in wrong state!\n"); |
||||
} |
||||
break; |
||||
case STATE_AWAIT_IRQ_FINGER_REMOVED: |
||||
if (irqtype == 0x02) { |
||||
if (next_state() < 0) { |
||||
do_exit = 2; |
||||
return; |
||||
} |
||||
} else { |
||||
printf("finger-on-sensor detected in wrong state!\n"); |
||||
} |
||||
break; |
||||
} |
||||
if (libusb_submit_transfer(irq_transfer) < 0) |
||||
do_exit = 2; |
||||
} |
||||
|
||||
static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer) |
||||
{ |
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "img transfer status %d?\n", transfer->status); |
||||
do_exit = 2; |
||||
libusb_free_transfer(transfer); |
||||
img_transfer = NULL; |
||||
return; |
||||
} |
||||
|
||||
printf("Image callback\n"); |
||||
save_to_file(imgbuf); |
||||
if (next_state() < 0) { |
||||
do_exit = 2; |
||||
return; |
||||
} |
||||
if (libusb_submit_transfer(img_transfer) < 0) |
||||
do_exit = 2; |
||||
} |
||||
|
||||
static int init_capture(void) |
||||
{ |
||||
int r; |
||||
|
||||
r = libusb_submit_transfer(irq_transfer); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
r = libusb_submit_transfer(img_transfer); |
||||
if (r < 0) { |
||||
libusb_cancel_transfer(irq_transfer); |
||||
while (irq_transfer) |
||||
if (libusb_handle_events(NULL) < 0) |
||||
break; |
||||
return r; |
||||
} |
||||
|
||||
/* start state machine */ |
||||
state = STATE_AWAIT_IRQ_FINGER_REMOVED; |
||||
return next_state(); |
||||
} |
||||
|
||||
static int do_init(void) |
||||
{ |
||||
unsigned char status; |
||||
int r; |
||||
|
||||
r = get_hwstat(&status); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
if (!(status & 0x80)) { |
||||
r = set_hwstat(status | 0x80); |
||||
if (r < 0) |
||||
return r; |
||||
r = get_hwstat(&status); |
||||
if (r < 0) |
||||
return r; |
||||
} |
||||
|
||||
status &= ~0x80; |
||||
r = set_hwstat(status); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
r = get_hwstat(&status); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
r = sync_intr(0x56); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int alloc_transfers(void) |
||||
{ |
||||
img_transfer = libusb_alloc_transfer(0); |
||||
if (!img_transfer) |
||||
return -ENOMEM; |
||||
|
||||
irq_transfer = libusb_alloc_transfer(0); |
||||
if (!irq_transfer) |
||||
return -ENOMEM; |
||||
|
||||
libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf, |
||||
sizeof(imgbuf), cb_img, NULL, 0); |
||||
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR, irqbuf, |
||||
sizeof(irqbuf), cb_irq, NULL, 0); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void sighandler(int signum) |
||||
{ |
||||
do_exit = 1; |
||||
} |
||||
|
||||
int main(void) |
||||
{ |
||||
struct sigaction sigact; |
||||
int r = 1; |
||||
|
||||
r = libusb_init(NULL); |
||||
if (r < 0) { |
||||
fprintf(stderr, "failed to initialise libusb\n"); |
||||
exit(1); |
||||
} |
||||
|
||||
r = find_dpfp_device(); |
||||
if (r < 0) { |
||||
fprintf(stderr, "Could not find/open device\n"); |
||||
goto out; |
||||
} |
||||
|
||||
r = libusb_claim_interface(devh, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "usb_claim_interface error %d\n", r); |
||||
goto out; |
||||
} |
||||
printf("claimed interface\n"); |
||||
|
||||
r = print_f0_data(); |
||||
if (r < 0) |
||||
goto out_release; |
||||
|
||||
r = do_init(); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
|
||||
/* async from here onwards */ |
||||
|
||||
r = alloc_transfers(); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
|
||||
r = init_capture(); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
|
||||
sigact.sa_handler = sighandler; |
||||
sigemptyset(&sigact.sa_mask); |
||||
sigact.sa_flags = 0; |
||||
sigaction(SIGINT, &sigact, NULL); |
||||
sigaction(SIGTERM, &sigact, NULL); |
||||
sigaction(SIGQUIT, &sigact, NULL); |
||||
|
||||
while (!do_exit) { |
||||
r = libusb_handle_events(NULL); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
} |
||||
|
||||
printf("shutting down...\n"); |
||||
|
||||
if (irq_transfer) { |
||||
r = libusb_cancel_transfer(irq_transfer); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
} |
||||
|
||||
if (img_transfer) { |
||||
r = libusb_cancel_transfer(img_transfer); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
} |
||||
|
||||
while (irq_transfer || img_transfer) |
||||
if (libusb_handle_events(NULL) < 0) |
||||
break; |
||||
|
||||
if (do_exit == 1) |
||||
r = 0; |
||||
else |
||||
r = 1; |
||||
|
||||
out_deinit: |
||||
libusb_free_transfer(img_transfer); |
||||
libusb_free_transfer(irq_transfer); |
||||
set_mode(0); |
||||
set_hwstat(0x80); |
||||
out_release: |
||||
libusb_release_interface(devh, 0); |
||||
out: |
||||
libusb_close(devh); |
||||
libusb_exit(NULL); |
||||
return r >= 0 ? r : -r; |
||||
} |
||||
|
@ -1,545 +0,0 @@
@@ -1,545 +0,0 @@
|
||||
/*
|
||||
* libusb example program to manipulate U.are.U 4000B fingerprint scanner. |
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org> |
||||
* |
||||
* Basic image capture program only, does not consider the powerup quirks or |
||||
* the fact that image encryption may be enabled. Not expected to work |
||||
* flawlessly all of the time. |
||||
* |
||||
* 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 |
||||
*/ |
||||
|
||||
#include <errno.h> |
||||
#include <pthread.h> |
||||
#include <signal.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
|
||||
#include <libusb.h> |
||||
|
||||
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN) |
||||
#define EP_DATA (2 | LIBUSB_ENDPOINT_IN) |
||||
#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN) |
||||
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT) |
||||
#define USB_RQ 0x04 |
||||
#define INTR_LENGTH 64 |
||||
|
||||
enum { |
||||
MODE_INIT = 0x00, |
||||
MODE_AWAIT_FINGER_ON = 0x10, |
||||
MODE_AWAIT_FINGER_OFF = 0x12, |
||||
MODE_CAPTURE = 0x20, |
||||
MODE_SHUT_UP = 0x30, |
||||
MODE_READY = 0x80, |
||||
}; |
||||
|
||||
static int next_state(void); |
||||
|
||||
enum { |
||||
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1, |
||||
STATE_AWAIT_IRQ_FINGER_DETECTED, |
||||
STATE_AWAIT_MODE_CHANGE_CAPTURE, |
||||
STATE_AWAIT_IMAGE, |
||||
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF, |
||||
STATE_AWAIT_IRQ_FINGER_REMOVED, |
||||
}; |
||||
|
||||
static int state = 0; |
||||
static struct libusb_device_handle *devh = NULL; |
||||
static unsigned char imgbuf[0x1b340]; |
||||
static unsigned char irqbuf[INTR_LENGTH]; |
||||
static struct libusb_transfer *img_transfer = NULL; |
||||
static struct libusb_transfer *irq_transfer = NULL; |
||||
static int img_idx = 0; |
||||
static int do_exit = 0; |
||||
|
||||
static pthread_t poll_thread; |
||||
static pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER; |
||||
static pthread_mutex_t exit_cond_lock = PTHREAD_MUTEX_INITIALIZER; |
||||
|
||||
static void request_exit(int code) |
||||
{ |
||||
do_exit = code; |
||||
pthread_cond_signal(&exit_cond); |
||||
} |
||||
|
||||
static void *poll_thread_main(void *arg) |
||||
{ |
||||
int r = 0; |
||||
printf("poll thread running\n"); |
||||
|
||||
while (!do_exit) { |
||||
struct timeval tv = { 1, 0 }; |
||||
r = libusb_handle_events_timeout(NULL, &tv); |
||||
if (r < 0) { |
||||
request_exit(2); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
printf("poll thread shutting down\n"); |
||||
return NULL; |
||||
} |
||||
|
||||
static int find_dpfp_device(void) |
||||
{ |
||||
devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a); |
||||
return devh ? 0 : -EIO; |
||||
} |
||||
|
||||
static int print_f0_data(void) |
||||
{ |
||||
unsigned char data[0x10]; |
||||
int r; |
||||
unsigned int i; |
||||
|
||||
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data, |
||||
sizeof(data), 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "F0 error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < sizeof(data)) { |
||||
fprintf(stderr, "short read (%d)\n", r); |
||||
return -1; |
||||
} |
||||
|
||||
printf("F0 data:"); |
||||
for (i = 0; i < sizeof(data); i++) |
||||
printf("%02x ", data[i]); |
||||
printf("\n"); |
||||
return 0; |
||||
} |
||||
|
||||
static int get_hwstat(unsigned char *status) |
||||
{ |
||||
int r; |
||||
|
||||
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0x07, 0, status, 1, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "read hwstat error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < 1) { |
||||
fprintf(stderr, "short read (%d)\n", r); |
||||
return -1; |
||||
} |
||||
|
||||
printf("hwstat reads %02x\n", *status); |
||||
return 0; |
||||
} |
||||
|
||||
static int set_hwstat(unsigned char data) |
||||
{ |
||||
int r; |
||||
|
||||
printf("set hwstat to %02x\n", data); |
||||
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x07, 0, &data, 1, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "set hwstat error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < 1) { |
||||
fprintf(stderr, "short write (%d)", r); |
||||
return -1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int set_mode(unsigned char data) |
||||
{ |
||||
int r; |
||||
printf("set mode %02x\n", data); |
||||
|
||||
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "set mode error %d\n", r); |
||||
return r; |
||||
} |
||||
if ((unsigned int) r < 1) { |
||||
fprintf(stderr, "short write (%d)", r); |
||||
return -1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer) |
||||
{ |
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "mode change transfer not completed!\n"); |
||||
request_exit(2); |
||||
} |
||||
|
||||
printf("async cb_mode_changed length=%d actual_length=%d\n", |
||||
transfer->length, transfer->actual_length); |
||||
if (next_state() < 0) |
||||
request_exit(2); |
||||
} |
||||
|
||||
static int set_mode_async(unsigned char data) |
||||
{ |
||||
unsigned char *buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); |
||||
struct libusb_transfer *transfer; |
||||
|
||||
if (!buf) |
||||
return -ENOMEM; |
||||
|
||||
transfer = libusb_alloc_transfer(0); |
||||
if (!transfer) { |
||||
free(buf); |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
printf("async set mode %02x\n", data); |
||||
libusb_fill_control_setup(buf, CTRL_OUT, USB_RQ, 0x4e, 0, 1); |
||||
buf[LIBUSB_CONTROL_SETUP_SIZE] = data; |
||||
libusb_fill_control_transfer(transfer, devh, buf, cb_mode_changed, NULL, |
||||
1000); |
||||
|
||||
transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK |
||||
| LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER; |
||||
return libusb_submit_transfer(transfer); |
||||
} |
||||
|
||||
static int do_sync_intr(unsigned char *data) |
||||
{ |
||||
int r; |
||||
int transferred; |
||||
|
||||
r = libusb_interrupt_transfer(devh, EP_INTR, data, INTR_LENGTH, |
||||
&transferred, 1000); |
||||
if (r < 0) { |
||||
fprintf(stderr, "intr error %d\n", r); |
||||
return r; |
||||
} |
||||
if (transferred < INTR_LENGTH) { |
||||
fprintf(stderr, "short read (%d)\n", r); |
||||
return -1; |
||||
} |
||||
|
||||
printf("recv interrupt %04x\n", *((uint16_t *) data)); |
||||
return 0; |
||||
} |
||||
|
||||
static int sync_intr(unsigned char type) |
||||
{ |
||||
int r; |
||||
unsigned char data[INTR_LENGTH]; |
||||
|
||||
while (1) { |
||||
r = do_sync_intr(data); |
||||
if (r < 0) |
||||
return r; |
||||
if (data[0] == type) |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
static int save_to_file(unsigned char *data) |
||||
{ |
||||
FILE *fd; |
||||
char filename[64]; |
||||
|
||||
snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++); |
||||
fd = fopen(filename, "w"); |
||||
if (!fd) |
||||
return -1; |
||||
|
||||
fputs("P5 384 289 255 ", fd); |
||||
(void) fwrite(data + 64, 1, 384*289, fd); |
||||
fclose(fd); |
||||
printf("saved image to %s\n", filename); |
||||
return 0; |
||||
} |
||||
|
||||
static int next_state(void) |
||||
{ |
||||
int r = 0; |
||||
printf("old state: %d\n", state); |
||||
switch (state) { |
||||
case STATE_AWAIT_IRQ_FINGER_REMOVED: |
||||
state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON; |
||||
r = set_mode_async(MODE_AWAIT_FINGER_ON); |
||||
break; |
||||
case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON: |
||||
state = STATE_AWAIT_IRQ_FINGER_DETECTED; |
||||
break; |
||||
case STATE_AWAIT_IRQ_FINGER_DETECTED: |
||||
state = STATE_AWAIT_MODE_CHANGE_CAPTURE; |
||||
r = set_mode_async(MODE_CAPTURE); |
||||
break; |
||||
case STATE_AWAIT_MODE_CHANGE_CAPTURE: |
||||
state = STATE_AWAIT_IMAGE; |
||||
break; |
||||
case STATE_AWAIT_IMAGE: |
||||
state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF; |
||||
r = set_mode_async(MODE_AWAIT_FINGER_OFF); |
||||
break; |
||||
case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF: |
||||
state = STATE_AWAIT_IRQ_FINGER_REMOVED; |
||||
break; |
||||
default: |
||||
printf("unrecognised state %d\n", state); |
||||
} |
||||
if (r < 0) { |
||||
fprintf(stderr, "error detected changing state\n"); |
||||
return r; |
||||
} |
||||
|
||||
printf("new state: %d\n", state); |
||||
return 0; |
||||
} |
||||
|
||||
static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer) |
||||
{ |
||||
unsigned char irqtype = transfer->buffer[0]; |
||||
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "irq transfer status %d?\n", transfer->status); |
||||
irq_transfer = NULL; |
||||
request_exit(2); |
||||
return; |
||||
} |
||||
|
||||
printf("IRQ callback %02x\n", irqtype); |
||||
switch (state) { |
||||
case STATE_AWAIT_IRQ_FINGER_DETECTED: |
||||
if (irqtype == 0x01) { |
||||
if (next_state() < 0) { |
||||
request_exit(2); |
||||
return; |
||||
} |
||||
} else { |
||||
printf("finger-on-sensor detected in wrong state!\n"); |
||||
} |
||||
break; |
||||
case STATE_AWAIT_IRQ_FINGER_REMOVED: |
||||
if (irqtype == 0x02) { |
||||
if (next_state() < 0) { |
||||
request_exit(2); |
||||
return; |
||||
} |
||||
} else { |
||||
printf("finger-on-sensor detected in wrong state!\n"); |
||||
} |
||||
break; |
||||
} |
||||
if (libusb_submit_transfer(irq_transfer) < 0) |
||||
request_exit(2); |
||||
} |
||||
|
||||
static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer) |
||||
{ |
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "img transfer status %d?\n", transfer->status); |
||||
img_transfer = NULL; |
||||
request_exit(2); |
||||
return; |
||||
} |
||||
|
||||
printf("Image callback\n"); |
||||
save_to_file(imgbuf); |
||||
if (next_state() < 0) { |
||||
request_exit(2); |
||||
return; |
||||
} |
||||
if (libusb_submit_transfer(img_transfer) < 0) |
||||
request_exit(2); |
||||
} |
||||
|
||||
static int init_capture(void) |
||||
{ |
||||
int r; |
||||
|
||||
r = libusb_submit_transfer(irq_transfer); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
r = libusb_submit_transfer(img_transfer); |
||||
if (r < 0) { |
||||
libusb_cancel_transfer(irq_transfer); |
||||
while (irq_transfer) |
||||
if (libusb_handle_events(NULL) < 0) |
||||
break; |
||||
return r; |
||||
} |
||||
|
||||
/* start state machine */ |
||||
state = STATE_AWAIT_IRQ_FINGER_REMOVED; |
||||
return next_state(); |
||||
} |
||||
|
||||
static int do_init(void) |
||||
{ |
||||
unsigned char status; |
||||
int r; |
||||
|
||||
r = get_hwstat(&status); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
if (!(status & 0x80)) { |
||||
r = set_hwstat(status | 0x80); |
||||
if (r < 0) |
||||
return r; |
||||
r = get_hwstat(&status); |
||||
if (r < 0) |
||||
return r; |
||||
} |
||||
|
||||
status &= ~0x80; |
||||
r = set_hwstat(status); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
r = get_hwstat(&status); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
r = sync_intr(0x56); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int alloc_transfers(void) |
||||
{ |
||||
img_transfer = libusb_alloc_transfer(0); |
||||
if (!img_transfer) |
||||
return -ENOMEM; |
||||
|
||||
irq_transfer = libusb_alloc_transfer(0); |
||||
if (!irq_transfer) |
||||
return -ENOMEM; |
||||
|
||||
libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf, |
||||
sizeof(imgbuf), cb_img, NULL, 0); |
||||
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR, irqbuf, |
||||
sizeof(irqbuf), cb_irq, NULL, 0); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void sighandler(int signum) |
||||
{ |
||||
request_exit(1); |
||||
} |
||||
|
||||
int main(void) |
||||
{ |
||||
struct sigaction sigact; |
||||
int r = 1; |
||||
|
||||
r = libusb_init(NULL); |
||||
if (r < 0) { |
||||
fprintf(stderr, "failed to initialise libusb\n"); |
||||
exit(1); |
||||
} |
||||
|
||||
r = find_dpfp_device(); |
||||
if (r < 0) { |
||||
fprintf(stderr, "Could not find/open device\n"); |
||||
goto out; |
||||
} |
||||
|
||||
r = libusb_claim_interface(devh, 0); |
||||
if (r < 0) { |
||||
fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r)); |
||||
goto out; |
||||
} |
||||
printf("claimed interface\n"); |
||||
|
||||
r = print_f0_data(); |
||||
if (r < 0) |
||||
goto out_release; |
||||
|
||||
r = do_init(); |
||||
if (r < 0) |
||||
goto out_deinit; |
||||
|
||||
/* async from here onwards */ |
||||
|
||||
sigact.sa_handler = sighandler; |
||||
sigemptyset(&sigact.sa_mask); |
||||
sigact.sa_flags = 0; |
||||
sigaction(SIGINT, &sigact, NULL); |
||||
sigaction(SIGTERM, &sigact, NULL); |
||||
sigaction(SIGQUIT, &sigact, NULL); |
||||
|
||||
r = pthread_create(&poll_thread, NULL, poll_thread_main, NULL); |
||||
if (r) |
||||
goto out_deinit; |
||||
|
||||
r = alloc_transfers(); |
||||
if (r < 0) { |
||||
request_exit(1); |
||||
pthread_join(poll_thread, NULL); |
||||
goto out_deinit; |
||||
} |
||||
|
||||
r = init_capture(); |
||||
if (r < 0) { |
||||
request_exit(1); |
||||
pthread_join(poll_thread, NULL); |
||||
goto out_deinit; |
||||
} |
||||
|
||||
while (!do_exit) { |
||||
pthread_mutex_lock(&exit_cond_lock); |
||||
pthread_cond_wait(&exit_cond, &exit_cond_lock); |
||||
pthread_mutex_unlock(&exit_cond_lock); |
||||
} |
||||
|
||||
printf("shutting down...\n"); |
||||
pthread_join(poll_thread, NULL); |
||||
|
||||
r = libusb_cancel_transfer(irq_transfer); |
||||
if (r < 0) { |
||||
request_exit(1); |
||||
goto out_deinit; |
||||
} |
||||
|
||||
r = libusb_cancel_transfer(img_transfer); |
||||
if (r < 0) { |
||||
request_exit(1); |
||||
goto out_deinit; |
||||
} |
||||
|
||||
while (img_transfer || irq_transfer) |
||||
if (libusb_handle_events(NULL) < 0) |
||||
break; |
||||
|
||||
if (do_exit == 1) |
||||
r = 0; |
||||
else |
||||
r = 1; |
||||
|
||||
out_deinit: |
||||
libusb_free_transfer(img_transfer); |
||||
libusb_free_transfer(irq_transfer); |
||||
set_mode(0); |
||||
set_hwstat(0x80); |
||||
out_release: |
||||
libusb_release_interface(devh, 0); |
||||
out: |
||||
libusb_close(devh); |
||||
libusb_exit(NULL); |
||||
return r >= 0 ? r : -r; |
||||
} |
||||
|
@ -1,95 +0,0 @@
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* libusb example program for hotplug API |
||||
* Copyright (C) 2012-2013 Nathan Hjelm <hjelmn@mac.ccom> |
||||
* |
||||
* 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 |
||||
*/ |
||||
|
||||
#include <stdlib.h> |
||||
#include <stdio.h> |
||||
#include <sched.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <libusb.h> |
||||
|
||||
int done = 0; |
||||
libusb_device_handle *handle; |
||||
|
||||
static int hotplug_callback (libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) { |
||||
struct libusb_device_descriptor desc; |
||||
int rc; |
||||
|
||||
rc = libusb_get_device_descriptor(dev, &desc); |
||||
if (LIBUSB_SUCCESS != rc) { |
||||
fprintf (stderr, "Error getting device descriptor\n"); |
||||
} |
||||
|
||||
printf ("Device attach: %04x:%04x\n", desc.idVendor, desc.idProduct); |
||||
|
||||
libusb_open (dev, &handle); |
||||
|
||||
done++; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int hotplug_callback_detach (libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) { |
||||
printf ("Device detached\n"); |
||||
|
||||
libusb_close (handle); |
||||
|
||||
done++; |
||||
return 0; |
||||
} |
||||
|
||||
int main (int argc, char *argv[]) { |
||||
libusb_hotplug_callback_handle hp[2]; |
||||
int product_id, vendor_id, class_id; |
||||
int rc; |
||||
|
||||
vendor_id = (argc > 1) ? strtol (argv[1], NULL, 0) : 0x045a; |
||||
product_id = (argc > 2) ? strtol (argv[2], NULL, 0) : 0x5005; |
||||
class_id = (argc > 3) ? strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; |
||||
|
||||
libusb_init (NULL); |
||||
|
||||
if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) { |
||||
printf ("Hotplug not supported by this build of libusb\n"); |
||||
libusb_exit (NULL); |
||||
return EXIT_FAILURE; |
||||
} |
||||
|
||||
rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id, |
||||
product_id, class_id, hotplug_callback, NULL, &hp[0]); |
||||
if (LIBUSB_SUCCESS != rc) { |
||||
fprintf (stderr, "Error registering callback 0\n"); |
||||
libusb_exit (NULL); |
||||
return EXIT_FAILURE; |
||||
} |
||||
|
||||
rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id, |
||||
product_id,class_id, hotplug_callback_detach, NULL, &hp[1]); |
||||
if (LIBUSB_SUCCESS != rc) { |
||||
fprintf (stderr, "Error registering callback 1\n"); |
||||
libusb_exit (NULL); |
||||
return EXIT_FAILURE; |
||||
} |
||||
|
||||
while (done < 2) { |
||||
libusb_handle_events (NULL); |
||||
} |
||||
|
||||
libusb_exit (NULL); |
||||
} |
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* libusb example program to list devices on the bus |
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org> |
||||
* |
||||
* 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 |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <sys/types.h> |
||||
|
||||
#include <libusb.h> |
||||
|
||||
static void print_devs(libusb_device **devs) |
||||
{ |
||||
libusb_device *dev; |
||||
int i = 0; |
||||
|
||||
while ((dev = devs[i++]) != NULL) { |
||||
struct libusb_device_descriptor desc; |
||||
int r = libusb_get_device_descriptor(dev, &desc); |
||||
if (r < 0) { |
||||
fprintf(stderr, "failed to get device descriptor"); |
||||
return; |
||||
} |
||||
|
||||
printf("%04x:%04x (bus %d, device %d)\n", |
||||
desc.idVendor, desc.idProduct, |
||||
libusb_get_bus_number(dev), libusb_get_device_address(dev)); |
||||
} |
||||
} |
||||
|
||||
int main(void) |
||||
{ |
||||
libusb_device **devs; |
||||
int r; |
||||
ssize_t cnt; |
||||
|
||||
r = libusb_init(NULL); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
cnt = libusb_get_device_list(NULL, &devs); |
||||
if (cnt < 0) |
||||
return (int) cnt; |
||||
|
||||
print_devs(devs); |
||||
libusb_free_device_list(devs, 1); |
||||
|
||||
libusb_exit(NULL); |
||||
return 0; |
||||
} |
||||
|
@ -1,193 +0,0 @@
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* libusb example program to measure Atmel SAM3U isochronous performance |
||||
* Copyright (C) 2012 Harald Welte <laforge@gnumonks.org> |
||||
* |
||||
* Copied with the author's permission under LGPL-2.1 from |
||||
* http://git.gnumonks.org/cgi-bin/gitweb.cgi?p=sam3u-tests.git;a=blob;f=usb-benchmark-project/host/benchmark.c;h=74959f7ee88f1597286cd435f312a8ff52c56b7e
|
||||
* |
||||
* An Atmel SAM3U test firmware is also available in the above repository. |
||||
* |
||||
* 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 |
||||
*/ |
||||
|
||||
#include <unistd.h> |
||||
#include <stdlib.h> |
||||
#include <stdio.h> |
||||
#include <errno.h> |
||||
#include <signal.h> |
||||
|
||||
#include <libusb.h> |
||||
|
||||
|
||||
#define EP_DATA_IN 0x82 |
||||
#define EP_ISO_IN 0x86 |
||||
|
||||
static int do_exit = 0; |
||||
static struct libusb_device_handle *devh = NULL; |
||||
|
||||
static unsigned long num_bytes = 0, num_xfer = 0; |
||||
static struct timeval tv_start; |
||||
|
||||
static void cb_xfr(struct libusb_transfer *xfr) |
||||
{ |
||||
unsigned int i; |
||||
|
||||
if (xfr->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "transfer status %d\n", xfr->status); |
||||
libusb_free_transfer(xfr); |
||||
exit(3); |
||||
} |
||||
|
||||
if (xfr->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) { |
||||
for (i = 0; i < xfr->num_iso_packets; i++) { |
||||
struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i]; |
||||
|
||||
if (pack->status != LIBUSB_TRANSFER_COMPLETED) { |
||||
fprintf(stderr, "Error: pack %u status %d\n", i, pack->status); |
||||
exit(5); |
||||
} |
||||
|
||||
printf("pack%u length:%u, actual_length:%u\n", i, pack->length, pack->actual_length); |
||||
} |
||||
} |
||||
|
||||
printf("length:%u, actual_length:%u\n", xfr->length, xfr->actual_length); |
||||
for (i = 0; i < xfr->actual_length; i++) { |
||||
printf("%02x", xfr->buffer[i]); |
||||
if (i % 16) |
||||
printf("\n"); |
||||
else if (i % 8) |
||||
printf(" "); |
||||
else |
||||
printf(" "); |
||||
} |
||||
num_bytes += xfr->actual_length; |
||||
num_xfer++; |
||||
|
||||
if (libusb_submit_transfer(xfr) < 0) { |
||||
fprintf(stderr, "error re-submitting URB\n"); |
||||
exit(1); |
||||
} |
||||
} |
||||
|
||||
static int benchmark_in(uint8_t ep) |
||||
{ |
||||
static uint8_t buf[2048]; |
||||
static struct libusb_transfer *xfr; |
||||
int num_iso_pack = 0; |
||||
|
||||
if (ep == EP_ISO_IN) |
||||
num_iso_pack = 16; |
||||
|
||||
xfr = libusb_alloc_transfer(num_iso_pack); |
||||
if (!xfr) |
||||
return -ENOMEM; |
||||
|
||||
if (ep == EP_ISO_IN) { |
||||
libusb_fill_iso_transfer(xfr, devh, ep, buf, |
||||
sizeof(buf), num_iso_pack, cb_xfr, NULL, 0); |
||||
libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack); |
||||
} else |
||||
libusb_fill_bulk_transfer(xfr, devh, ep, buf, |
||||
sizeof(buf), cb_xfr, NULL, 0); |
||||
|
||||
gettimeofday(&tv_start, NULL); |
||||
|
||||
/* NOTE: To reach maximum possible performance the program must
|
||||
* submit *multiple* transfers here, not just one. |
||||
* |
||||
* When only one transfer is submitted there is a gap in the bus |
||||
* schedule from when the transfer completes until a new transfer |
||||
* is submitted by the callback. This causes some jitter for |
||||
* isochronous transfers and loss of throughput for bulk transfers. |
||||
* |
||||
* This is avoided by queueing multiple transfers in advance, so |
||||
* that the host controller is always kept busy, and will schedule |
||||
* more transfers on the bus while the callback is running for |
||||
* transfers which have completed on the bus. |
||||
*/ |
||||
|
||||
return libusb_submit_transfer(xfr); |
||||
} |
||||
|
||||
static void measure(void) |
||||
{ |
||||
struct timeval tv_stop; |
||||
unsigned int diff_msec; |
||||
|
||||
gettimeofday(&tv_stop, NULL); |
||||
|
||||
diff_msec = (tv_stop.tv_sec - tv_start.tv_sec)*1000; |
||||
diff_msec += (tv_stop.tv_usec - tv_start.tv_usec)/1000; |
||||
|
||||
printf("%lu transfers (total %lu bytes) in %u miliseconds => %lu bytes/sec\n", |
||||
num_xfer, num_bytes, diff_msec, (num_bytes*1000)/diff_msec); |
||||
} |
||||
|
||||
static void sig_hdlr(int signum) |
||||
{ |
||||
switch (signum) { |
||||
case SIGINT: |
||||
measure(); |
||||
do_exit = 1; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
int rc; |
||||
struct sigaction sigact; |
||||
|
||||
sigact.sa_handler = sig_hdlr; |
||||
sigemptyset(&sigact.sa_mask); |
||||
sigact.sa_flags = 0; |
||||
sigaction(SIGINT, &sigact, NULL); |
||||
|
||||
rc = libusb_init(NULL); |
||||
if (rc < 0) { |
||||
fprintf(stderr, "Error initializing libusb: %s\n", libusb_error_name(rc)); |
||||
exit(1); |
||||
} |
||||
|
||||
devh = libusb_open_device_with_vid_pid(NULL, 0x16c0, 0x0763); |
||||
if (!devh) { |
||||
fprintf(stderr, "Error finding USB device\n"); |
||||
goto out; |
||||
} |
||||
|
||||
rc = libusb_claim_interface(devh, 2); |
||||
if (rc < 0) { |
||||
fprintf(stderr, "Error claiming interface: %s\n", libusb_error_name(rc)); |
||||
goto out; |
||||
} |
||||
|
||||
benchmark_in(EP_ISO_IN); |
||||
|
||||
while (!do_exit) { |
||||
rc = libusb_handle_events(NULL); |
||||
if (rc != LIBUSB_SUCCESS) |
||||
break; |
||||
} |
||||
|
||||
/* Measurement has already been done by the signal handler. */ |
||||
|
||||
libusb_release_interface(devh, 0); |
||||
out: |
||||
if (devh) |
||||
libusb_close(devh); |
||||
libusb_exit(NULL); |
||||
return rc; |
||||
} |
@ -1,256 +0,0 @@
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
* Test suite program based of libusb-0.1-compat testlibusb |
||||
* Copyright (c) 2013 Nathan Hjelm <hjelmn@mac.ccom> |
||||
* |
||||
* 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 |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <libusb.h> |
||||
|
||||
int verbose = 0; |
||||
|
||||
static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp) |
||||
{ |
||||
printf(" USB 3.0 Endpoint Companion:\n"); |
||||
printf(" bMaxBurst: %d\n", ep_comp->bMaxBurst); |
||||
printf(" bmAttributes: 0x%02x\n", ep_comp->bmAttributes); |
||||
printf(" wBytesPerInterval: %d\n", ep_comp->wBytesPerInterval); |
||||
} |
||||
|
||||
static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint) |
||||
{ |
||||
int i, ret; |
||||
|
||||
printf(" Endpoint:\n"); |
||||
printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress); |
||||
printf(" bmAttributes: %02xh\n", endpoint->bmAttributes); |
||||
printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize); |
||||
printf(" bInterval: %d\n", endpoint->bInterval); |
||||
printf(" bRefresh: %d\n", endpoint->bRefresh); |
||||
printf(" bSynchAddress: %d\n", endpoint->bSynchAddress); |
||||
|
||||
for (i = 0 ; i < endpoint->extra_length ; ) { |
||||
if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i+1]) { |
||||
struct libusb_ss_endpoint_companion_descriptor *ep_comp; |
||||
|
||||
ret = libusb_parse_ss_endpoint_comp(endpoint->extra+i, endpoint->extra[0], &ep_comp); |
||||
if (LIBUSB_SUCCESS != ret) { |
||||
continue; |
||||
} |
||||
|
||||
print_endpoint_comp(ep_comp); |
||||
|
||||
libusb_free_ss_endpoint_comp(ep_comp); |
||||
} |
||||
|
||||
i += endpoint->extra[i]; |
||||
} |
||||
} |
||||
|
||||
static void print_altsetting(const struct libusb_interface_descriptor *interface) |
||||
{ |
||||
int i; |
||||
|
||||
printf(" Interface:\n"); |
||||
printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber); |
||||
printf(" bAlternateSetting: %d\n", interface->bAlternateSetting); |
||||
printf(" bNumEndpoints: %d\n", interface->bNumEndpoints); |
||||
printf(" bInterfaceClass: %d\n", interface->bInterfaceClass); |
||||
printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass); |
||||
printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol); |
||||
printf(" iInterface: %d\n", interface->iInterface); |
||||
|
||||
for (i = 0; i < interface->bNumEndpoints; i++) |
||||
print_endpoint(&interface->endpoint[i]); |
||||
} |
||||
|
||||
static void print_2_0_ext_cap(struct libusb_usb_2_0_device_capability_descriptor *usb_2_0_ext_cap) |
||||
{ |
||||
printf(" USB 2.0 Extension Capabilities:\n"); |
||||
printf(" bDevCapabilityType: %d\n", usb_2_0_ext_cap->bDevCapabilityType); |
||||
printf(" bmAttributes: 0x%x\n", usb_2_0_ext_cap->bmAttributes); |
||||
} |
||||
|
||||
static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap) |
||||
{ |
||||
printf(" USB 3.0 Capabilities:\n"); |
||||
printf(" bDevCapabilityType: %d\n", ss_usb_cap->bDevCapabilityType); |
||||
printf(" bmAttributes: 0x%x\n", ss_usb_cap->bmAttributes); |
||||
printf(" wSpeedSupported: 0x%x\n", ss_usb_cap->wSpeedSupported); |
||||
printf(" bFunctionalitySupport: %d\n", ss_usb_cap->bFunctionalitySupport); |
||||
printf(" bU1devExitLat: %d\n", ss_usb_cap->bU1DevExitLat); |
||||
printf(" bU2devExitLat: %d\n", ss_usb_cap->bU2DevExitLat); |
||||
} |
||||
|
||||
static void print_bos(libusb_device_handle *handle) |
||||
{ |
||||
unsigned char buffer[128]; |
||||
struct libusb_bos_descriptor *bos; |
||||
int ret; |
||||
|
||||
ret = libusb_get_descriptor(handle, LIBUSB_DT_BOS, 0, buffer, 128); |
||||
if (0 > ret) { |
||||
return; |
||||
} |
||||
|
||||
ret = libusb_parse_bos_descriptor(buffer, 128, &bos); |
||||
if (0 > ret) { |
||||
return; |
||||
} |
||||
|
||||
printf(" Binary Object Store (BOS):\n"); |
||||
printf(" wTotalLength: %d\n", bos->wTotalLength); |
||||
printf(" bNumDeviceCaps: %d\n", bos->bNumDeviceCaps); |
||||
if (bos->usb_2_0_ext_cap) { |
||||
print_2_0_ext_cap(bos->usb_2_0_ext_cap); |
||||
} |
||||
|
||||
if (bos->ss_usb_cap) { |
||||
print_ss_usb_cap(bos->ss_usb_cap); |
||||
} |
||||
} |
||||
|
||||
static void print_interface(const struct libusb_interface *interface) |
||||
{ |
||||
int i; |
||||
|
||||
for (i = 0; i < interface->num_altsetting; i++) |
||||
print_altsetting(&interface->altsetting[i]); |
||||
} |
||||
|
||||
static void print_configuration(struct libusb_config_descriptor *config) |
||||
{ |
||||
int i; |
||||
|
||||
printf(" Configuration:\n"); |
||||
printf(" wTotalLength: %d\n", config->wTotalLength); |
||||
printf(" bNumInterfaces: %d\n", config->bNumInterfaces); |
||||
printf(" bConfigurationValue: %d\n", config->bConfigurationValue); |
||||
printf(" iConfiguration: %d\n", config->iConfiguration); |
||||
printf(" bmAttributes: %02xh\n", config->bmAttributes); |
||||
printf(" MaxPower: %d\n", config->MaxPower); |
||||
|
||||
for (i = 0; i < config->bNumInterfaces; i++) |
||||
print_interface(&config->interface[i]); |
||||
} |
||||
|
||||
static int print_device(libusb_device *dev, int level) |
||||
{ |
||||
struct libusb_device_descriptor desc; |
||||
libusb_device_handle *handle = NULL; |
||||
char description[256]; |
||||
char string[256]; |
||||
int ret, i; |
||||
|
||||
ret = libusb_get_device_descriptor(dev, &desc); |
||||
if (ret < 0) { |
||||
fprintf(stderr, "failed to get device descriptor"); |
||||
return -1; |
||||
} |
||||
|
||||
ret = libusb_open(dev, &handle); |
||||
if (LIBUSB_SUCCESS == ret) { |
||||
if (desc.iManufacturer) { |
||||
ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string)); |
||||
if (ret > 0) |
||||
snprintf(description, sizeof(description), "%s - ", string); |
||||
else |
||||
snprintf(description, sizeof(description), "%04X - ", |
||||
desc.idVendor); |
||||
} else |
||||
snprintf(description, sizeof(description), "%04X - ", |
||||
desc.idVendor); |
||||
|
||||
if (desc.iProduct) { |
||||
ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string)); |
||||
if (ret > 0) |
||||
snprintf(description + strlen(description), sizeof(description) - |
||||
strlen(description), "%s", string); |
||||
else |
||||
snprintf(description + strlen(description), sizeof(description) - |
||||
strlen(description), "%04X", desc.idProduct); |
||||
} else |
||||
snprintf(description + strlen(description), sizeof(description) - |
||||
strlen(description), "%04X", desc.idProduct); |
||||
} else { |
||||
snprintf(description, sizeof(description), "%04X - %04X", |
||||
desc.idVendor, desc.idProduct); |
||||
} |
||||
|
||||
printf("%.*sDev (bus %d, device %d): %s\n", level * 2, " ", |
||||
libusb_get_bus_number(dev), libusb_get_device_address(dev), description); |
||||
|
||||
if (handle && verbose) { |
||||
if (desc.iSerialNumber) { |
||||
ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string)); |
||||
if (ret > 0) |
||||
printf("%.*s - Serial Number: %s\n", level * 2, |
||||
" ", string); |
||||
} |
||||
} |
||||
|
||||
if (verbose) { |
||||
for (i = 0; i < desc.bNumConfigurations; i++) { |
||||
struct libusb_config_descriptor *config; |
||||
ret = libusb_get_config_descriptor(dev, i, &config); |
||||
if (LIBUSB_SUCCESS != ret) { |
||||
printf(" Couldn't retrieve descriptors\n"); |
||||
continue; |
||||
} |
||||
|
||||
print_configuration(config); |
||||
|
||||
libusb_free_config_descriptor(config); |
||||
} |
||||
|
||||
if (handle && desc.bcdUSB >= 0x0201) { |
||||
print_bos(handle); |
||||
} |
||||
} |
||||
|
||||
if (handle) |
||||
libusb_close(handle); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
libusb_device **devs; |
||||
ssize_t cnt; |
||||
int r, i; |
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-v")) |
||||
verbose = 1; |
||||
|
||||
r = libusb_init(NULL); |
||||
if (r < 0) |
||||
return r; |
||||
|
||||
cnt = libusb_get_device_list(NULL, &devs); |
||||
if (cnt < 0) |
||||
return (int) cnt; |
||||
|
||||
for (i = 0 ; devs[i] ; ++i) { |
||||
print_device(devs[i], 0); |
||||
} |
||||
|
||||
libusb_free_device_list(devs, 1); |
||||
|
||||
libusb_exit(NULL); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue