1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-24 22:15:07 +03:00
Commit graph

361 commits

Author SHA1 Message Date
Federico Fuga
b5ad66eb1e Fix #39 Compilation fails on gcc v8 2020-01-30 17:28:41 +01:00
Ahmad Fatoum
283879d017 libusbgx: fix --without-libconfig build against glibc-2.28
Commit 45c14ef4d5 ("libusbgx: fix build with glibc-2.28 since
<sys/sysmacros.h> is no more included by <sys/types.h>")
fixed this issue for the (default) --with-libconfig configuration,
but building --without-libconfig still throws a linker error
because makedev was assumed to be an external symbol in
usbg_common.c.

Include <sys/sysmacros.h> there to address this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2019-04-25 20:47:56 +02:00
Gwenhael Goavec-Merou
45c14ef4d5 libusbgx: fix build with glibc-2.28 since <sys/sysmacros.h> is no more included by <sys/types.h>
Signed-off-by: Sid Spry R030t1@gmail.com
Signed-off-by: Gwenhael Goavec-Merou gwenhael.goavec-merou@trabucayre.com
[Copy sign-offs from pull requst to commit msg]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-09-12 15:10:33 +02:00
Krzysztof Opasiak
6ffbb21559 libusbgx: Fix doc build with new doxygen version
Doc build may fail with newest doxygen with error:
error: the type 'dirs' is not supported for the entry tag within a navindex! Check your layout file!

Fix this by simply remove the line that caused the error.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-08-22 18:34:50 +02:00
ing. Federico Fuga
dccb4f19a6 libusbgx: Fix out of tree compilation
With the current 0.2.0 (999a6e5) the library can't be compiled
out ofthe tree:

libtool: compile:  gcc -DPACKAGE_NAME=\"libusbgx\" -DPACKAGE_TARNAME=\"libusbgx\" -DPACKAGE_VERSION=\"0.2.0\" "-DPACKAGE_STRING=\"libusbgx 0.2.0\"" -DPACKAGE_BUGREPORT=\"k.opasiak@samsung.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"libusbgx\" -DVERSION=\"0.2.0\" "-D_GNU_SOURCE=/**/" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I../../src -I../../include/ -g -O2 -MT function/libusbgx_la-midi.lo -MD -MP -MF function/.deps/libusbgx_la-midi.Tpo -c ../../src/function/midi.c  -fPIC -DPIC -o function/.libs/libusbgx_la-midi.o
In file included from ../../src/usbg_common.c:13:0:
../../include/usbg/usbg.h:33:26: fatal error: usbg_version.h: File o directory non esistente
compilation terminated.

It compiled correctly on 904b04c.

To fix this issue let's add usbg subdirectory to include path.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-08-22 12:59:05 +02:00
Krzysztof Opasiak
999a6e5ee9 libusbgx: Release libusbgx version 0.2.0
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-03-02 22:06:33 +01:00
Krzysztof Opasiak
91538d5486 libusbgx: Add build dependencies info to doc
Suggested-by: Robert Bielik <robert.bielik@dirac.se>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-03-02 22:06:33 +01:00
Krzysztof Opasiak
4595736442 libusbgx: tests: Add a C++ compilation checker
Recently we faced some C++ compilation issues because
we used in our header a gcc extension that is not supported
by g++. Even through this problem has been fix let's try to
avoid such problems in a future. To do so, let's add a C++
compilation check for all our public headers as part of our
test suit.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:57:06 +01:00
Krzysztof Opasiak
77c456b77d libusbgx: uac2: Use dedicated macro for casting to union
Casting to union is gcc extension that is not supported
by g++. As we are using it in header in causes compilation
issues. Let's fix this by using our own macro for type-safe
casting to union.

Initially we used *(union a)&var construction but it does
not provide any type safety so let's replace it with our
macro.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:37:11 +01:00
Krzysztof Opasiak
9444caa614 libusbgx: net: Fix C++ compilation issues
Casting to union is gcc extension that is not supported
by g++. As we are using it in header in causes compilation
issues. Let's fix this by using our own macro for type-safe
casting to union.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:35:15 +01:00
Krzysztof Opasiak
3c2da958d6 libusbgx: ms: Fix C++ compilation issues
Casting to union is gcc extension that is not supported
by g++. As we are using it in header in causes compilation
issues. Let's fix this by using our own macro for type-safe
casting to union.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:35:04 +01:00
Krzysztof Opasiak
3cb9f66d12 libusbgx: midi: Fix C++ compilation issues
Casting to union is gcc extension that is not supported
by g++. As we are using it in header in causes compilation
issues. Let's fix this by using our own macro for type-safe
casting to union.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:34:50 +01:00
Krzysztof Opasiak
09574fb990 libusbgx: hid: Fix C++ compilation issues
Casting to union is gcc extension that is not supported
by g++. As we are using it in header in causes compilation
issues. Let's fix this by using our own macro for type-safe
casting to union.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:34:31 +01:00
Krzysztof Opasiak
e5394faf2d libusbgx: Introduce helper macro for casting to union
Casting some variable to union is a gcc extension that is not
available in g++. As we are using this feature in our headers
this causes compilation issues in C++ code.

First attempt to fix this took place when we were merging UAC2
support. But used solution is far away from being perfect as
it does not provide any type safety so is basically equivalent
of casting to void *.

To fix this let's introduce a macro that will cast any variable
to union using {} initialization which is supported by both gcc
and g++ and additionally provides us type safety.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:32:23 +01:00
Krzysztof Opasiak
f02d36d163 libusbgx: tests: Remove redefinition of _GNU_SOURCE
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-22 17:27:22 +01:00
Krzysztof Opasiak
b1d0b906f8 libusbgx: Fix access when memory allocation failed
Don't access the memory when allocation failed.
Reported by SVACE.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-21 18:03:36 +01:00
John Keeping
7c51fe5c2d libusbgx: add USBG_VERSION preprocessor symbol
The libusbgx API has changed over time (for example struct
usbg_gadget_strs as changed from fixed-size fields to pointers to char)
which requires that client programs also change.

Sometimes it is not possible to keep applications and libusbgx versions
in lock step and it is desirable to support multiple libusbgx API
versions from a single client code base.

Add a version number which can be used for conditional code in client
applications by doing:

	#if USBG_VERSION < USBG_MAKE_VERSION(0, 2, 0)

Signed-off-by: John Keeping <john@metanate.com>
[Add macro for generating API version]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-02-06 16:52:56 +01:00
Krzysztof Opasiak
9e71df567e libusbgx: packaging: Add missing uac2 header to devel package
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-01-24 13:55:33 +01:00
Krzysztof Opasiak
0ab9f2f128 libusbgx: examples: Make show-gadgets aware of uac2 function
Allow user to show values of uac2 attributes instead of dummy
"UNKNOWN" string.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-01-17 16:13:58 +01:00
John Keeping
88cff3cbf7 libusbgx: examples: Add UAC2 function example
Show how to create a USB Audio Class 2 gadget.

Signed-off-by: John Keeping <john@metanate.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2018-01-17 16:12:56 +01:00
John Keeping
5740ca8a5e libusbgx: Add support for UAC2 function
This is the USB Audio Class 2 function that creates an ALSA audio device
exposed as a USB gadget function.

Signed-off-by: John Keeping <john@metanate.com>
[Set import/export callbacks to correct values,
 adjust convention of set_attr(),
 fix union cast in c++]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com
2018-01-17 14:38:58 +00:00
Krzysztof Opasiak
1c3f1b4660 libusbgx: fix: Disallow creating function with empty instance name
USB function should have both type and instance name.
Mistakenly it was possible to create function with empty instance
name. This may lead to situations like FunctionFS device name
identified by "" or some misleading debug messages from TCM like:

tcm: Activating

Additionaly trying to execute usbg_init() after creating such
a function fails with -3 USBG_ERROR_INVALID_PARAM because it checks
if instance name is not empty.

To avoid this let's add a check in usbg_create_function() that
instance name should have at least one character.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:52:50 +01:00
Krzysztof Opasiak
904b04c4b4 libusbgx: tests: fix: Make our tests os_desc aware
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:52:50 +01:00
Krzysztof Opasiak
bfa2c29daa libusbgx: examples: Add rndis with OS descriptors support example
Add a program which shows how to use OS descriptors support
based on RNDIS example.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Krzysztof Opasiak
1809b5ae60 libusbgx: fix: Correct typo in usbg_rm_file() funciton name
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Krzysztof Opasiak
e4d9cbf6cc libusbgx: Make usbg_rm_config() aware of OS descriptors
Since we added support for OS descriptors we allowed user
to create a link in gadget's os_desc directory to choose
one of available configurations. This link prevents config
from being removed. This makes our rm funcitons stop working
with the recursive option. To fix this, let's make them
OS desc aware and remove this link before trying to remove
configuration if recurse option is set.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
952f19c7ce libusbgx: Add support for OS Descriptor configuration bindings
OS Descriptors require an association to a single configuration. This
allows to use a specific configuration for hosts supporting  OS
Descriptors.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Allow to also remove os desc binding]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
db490f1ca5 libusbgx: Add config support for function OS Descriptors
This adds support for OS Descriptors available on function level,
called "Feature Descriptors".

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Use a little bit different convention]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
0bc519f2f2 libusbgx: Add function level OS Descriptor support
This adds support for OS Descriptors available on function level,
called "Feature Descriptors".

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Fix mem leak in error path, allow multiple ifaces per funciton]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
abf422bffc libusbgx: Add interface name for Feature Descriptors
This adds interface name required for "Feature Descriptors". If
specified, we can assume that a Feature Descriptor with the
interface name of the specified string is understood by the
kernel (e.g. interface.rndis).

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Allow multiple os_desc ifaces per funciton]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
47526ac2a6 libusbgx: Add libconfig support for OS Descriptors
Add configuration support for OS Descriptors.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Move import to the right place, don't strdup() during import]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
996c322af1 libusbgx: Add OS Descriptors support
This adds OS Descriptors support on Gadget level. It allows to
enable OS Descriptors support as well as to define the OS String
proper.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Remove unused variable]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-12 14:06:36 +01:00
Stefan Agner
ad44340734 libusbgx: Do not write null terminator when using usbg_write_string()
The helper usbg_write_string() adds one to the length of the provided
string. This leads to usbg_write_buf() writting also a null terminator
to the kernel which is not necessary/wrong. Provide usbg_write_buf
the real string length.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
[Add missing () to function names in commit msg]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-12-11 22:40:26 +01:00
Stefan Agner
4c6124d68f libusbgx: fix usbg_free_gadget_strs when passing NULL
Do not dereference g_strs if we pass NULL to usbg_free_gadget_strs.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-11-24 10:22:46 +01:00
Krzysztof Opasiak
9498bfe5e5 libusbgx: fix: Install mising hid function header
Reported-by: Matthias Wieloch vel Saiberion (guthub.com)
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-11-20 19:16:36 +01:00
Krzysztof Opasiak
5837aedfcc libusbgx: fix: Check fclose() return code
According to man fclose:

"The fclose() function may also fail and set errno for any of the
 errors specified for the routines close(2), write(2) or fflush(3)."

So if libc decides to cache our write till closing fd we may
miss the error if we ignore value returned from fclose().

This fixes issue #12 (github).

Reported-by: Noralf Trønnes <noralf@tronnes.org>
Suggested-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-11-20 12:52:55 +01:00
Krzysztof Opasiak
b8941d1cf5 libusbgx: fix: remove unused variable
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-04-19 18:10:16 +02:00
Krzysztof Opasiak
5d0962ed41 libusbgx: Fix meaning of HAS_LIBCONFIG and HAS_GADGET_SCHEMES
We have two configure options related to libconfig:
1) --disable-gadget-schemes
2) --without-libconfig

Option #1 means that libusbgx itself should be compiled without gadget
schemes support. Option #2 means that everything what requires
libconfig should be turned off. So option #2 is wider than #1 as
libconfig us used also in our testing program.

To fix this meaning let's use HAS_GADGET_SCHEMES inside library source
code to determine if we should use libconfig or not and HAS_LIBCONFIG
inside our tests source code.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 17:48:44 +01:00
Krzysztof Opasiak
651177558b libusbgx: Fix compilation without libconfig
After refactorization we lost ability to build libusbgx
without libconfig. Let's restore this.

Basic concept is that the whole code related to libconfig usage
should be under #ifdef or compiled only if libconfig support
is enabled.

To prevent future problems of that kind, let's create a header
which is included when compiling without libconfig. Inside it we
like:
	struct s {
	       .import = usbg_get_config_node_int,
	       .export = usbg_set_config_node_int,
	};

are still valid, but all tries to call this functions directly end up
in compilation error. This helps us identify all pieces of code
which should be placed under suitable #ifdef.

Based on initial pull request "Compilation fixes. #4" by:
Bent Bisballe Nyeng (github: aasimon) <deva@aasimon.org>

Reported-by: Bent Bisballe Nyeng (github: aasimon) <deva@aasimon.org>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 17:48:44 +01:00
Krzysztof Opasiak
a91dd9d037 libusbgx: examples: Add example how to create gadget with HID function
Let's add some simple example how to create a gadget which includes
HID function.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:05:37 +01:00
Krzysztof Opasiak
e323f6c0f9 libusbgx: examples: Allow show-gadgets to print HID function attrs
As libusbgx now supports also HID function so we may print its
attributes in our show-gadgets example. This may also be used
as example of getting HID attributes using generic functions.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:04:08 +01:00
Krzysztof Opasiak
b656ce0845 libusbgx: Add support for HID function
HID function has been ported to ConfigFS interface quite long
time ago so let's add support for it also in libusbgx.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
784e693fe5 libusbgx: common: Allow to export int attribute in hex format
Add a helper to export int attributes in hex format.
Now each function may decide which format should be used
(decimal or hex).

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
71f93716df libsubgx: common: Allow to export dev_t attribute using libconfig
Add a helper to export dev_t attributes to gadget schemes using
libconfig syntax.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
7b0ef8b934 libusbgx: common: Add function for reading dev_t from ConfigFS
As some of kernel functions expose details about device node
which is assigned to this instance in form:
      <major>:<minor>
Let's add a convenient helper which will read those values
form file and convert them to dev_t.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
6bdf0a3b93 libusbgx: common: Use fread() instead of fgets()
Reading binary data using fgets() may not be a good idea due
to \0 byte in the middle of data. Let's fix this by using fread()
instead of fgets().

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
b42b7b0c2f libusbgx: common: Use fwrite() instead of fputs()
Using fputs() for writing binary data is not a good idea as \0
byte can be in the middle of our data. Let's just use fwrite()
instead.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
e8e16af025 libusbgx: examples: Print strings in all available languages
Instead of printing strings only in US_EN let's make a use of
our new function and print all available strings.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
a996f168f7 libusbgx: Simplify strings handling in libconfig schemes
Make use of usbg_get_gadget_strs_langs() and
usbg_get_config_strs_langs() in libconfig schemes instead of
direct listing content of directory using scandir().

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:27 +01:00
Krzysztof Opasiak
49879b8fc0 libusbgx: Add usbg_get_config_str_langs()
Add a function which allows to get the list of languages
in which config strings are currently available.

Thanks to this function now we may iterate through all strings
languages available in particular config and print their values.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2017-03-03 14:02:26 +01:00