1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-26 04:05:06 +03:00
Commit graph

230 commits

Author SHA1 Message Date
Krzysztof Opasiak
8c9547cca5 libusbgx: Fix compilation warnings
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Pawel Szewczyk
b7c63c3dd2 libusbgx: Fix gadget attributes reading order
To be more consistent we read and write gadget attributes in the same order
specified by usbg_gadget_attr enum. It can make difference in testing, where
order often does matter and allows to write tests more efficient when
using wrapped filesystem operations. Also, consistency is always a good
thing.

Change-Id: Ieb3c7f81a8c0a135c47ebd358e5a87fe04766f2a
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
0396c9760a libusbgx: Fix usbg_get_configfs_path()
Store configfs path in configfs_path attribute
and return it in usbg_get_configfs_path()
instead of returning path to usbg_gadget subsys.

Based on patch "libusbg: Fix configfs path" created by:
Pawel Szewczyk <p.szewczyk@samsung.com>

Change-Id: I49e606c9f8c5eb478ac48fc453840b9a3efdd117
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
88c5d4a5a0 libusbgx: add --disable-gadget-schemes to configure
This commit adds --disable-gadget-schemes option to configure.
It allows to build libusbgx without libconfig.
This change does not change the API - we add instead empty functions.
The default solution is to use libconfig.

Change-Id: Ia8581fdb6368fb1877e97ee56d91d29e5128611e
Signed-off-by: Przemyslaw Kedzierski <p.kedzierski@samsung.com>
[Rebase and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
75094d0afa libusbgx: Add empty definitions of gadget schemes functions
In some cases user may want to not use gadget schemes
functionality so he should be able to remove libconfig
dependency. To be able to do this without API break
add empty definitions of gadget schemes functions which
only returns USBG_ERROR_NOT_SUPPORTED.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
0927f81ee3 libusbgx: Move gadget schemes functionality to separate file
Having wholle code in one file hurts code readability.
It would be more convenient to split this large file
into a few smaller. This commits move whole functinality
related to gadget schemes to separate file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
c2f0e17639 libusbgx: Extract internal header file
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
3c785ec649 libusbgx: Add max and min values to enums
In some cases user of library would like to iterate over
all enum values. Depending on enum values order is not
a good idea so provide suitable min and max values to alow
doing something like:

int i;
for(i = USBG_GADGET_ATTR_MIN; i < USBG_GADGET_ATTR_MAX; ++i)
	do_something_useful(i);

Moreover, ensure that function_names and gadget_attr_names
arrays has allways the same size as number of meaningful
values in related enums.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
4e2cc9700f libusbgx: Allow to get gadget enabled on given UDC
Add usbg_get_udc_gadget() which allows user to learn
which gadget is attached to selected UDC.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
081c49e44f libusbgx: Refresh gadget UDC while each usbg_get_gadget_udc()
Kernel may decide to detach our gadget in some cases.
A good example is when FFS daemon received a SIGSEGV
and all descriptors has been closed.

To avoid returning false informations to user we have
to refresh UDC attribute before returning cached pointer
to usbg_udc.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
0cd967b99b libusbgx: Rework API to use usbg_udc structure
Using string as udc identifier provides a lot
of troubles. To be more consistent with rest of
API rework it to start using usbg_udc structure
instead of using char *.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
8d5550172c libusbgx: Replace usbg_get_udcs() with loop
Library allows to iterate over each gadget using loop.
To be consistent with this convention add similar loop
for UDCs.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:57 +01:00
Krzysztof Opasiak
e8338aa327 libusbgx: Add udc structure
Add structure to store informations about available udcs
instead of using their names as a string.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:41:51 +01:00
Krzysztof Opasiak
80393f53cb libusbgx: Don't print errno when it has not been directly set
Replace ERRORNO() macro with ERROR(). Difference betwen
them is that ERRORNO() prints also standard error string
based on errno value. This variable should not be accessed
when called function doesn't directly set it.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:53 +01:00
Krzysztof Opasiak
eb3de1983a libusbgx: Make usbg_lookup_function_type() publicly available
Users of library may often receive function type as a string.
Instead of implementing parsing of such string in each program
it would be more convenient to provide such support in library.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:46 +01:00
Krzysztof Opasiak
22ad8219e6 libusbgx: Return suitable error codes instead of -1
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:42 +01:00
Krzysztof Opasiak
7e30d9d040 libusbgx: Allow to set all gadget attrs using one function.
Having specialized functions for each attribute may be
sometime inconvenient to use. Provide also function
whihc allows to set attribute selected by parameter.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:37 +01:00
Krzysztof Opasiak
d3f3ca6081 libusbgx: Simplify getting names form library structures
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>

Changes since v1:
Fix show-gadgets example: get attributes before dereferencing them

Reported-by: Philippe De Swert <philippe.deswert@jollamobile.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:29 +01:00
Krzysztof Opasiak
1aba4b0dc2 libusbgx: Always add '\0' at end of string
strncpy() may not append trailing '\0' so let's append
it always at end of string to avoid getting into troubles.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:24 +01:00
Krzysztof Opasiak
cc29cb7cbf libusbgx: fix: Remove unused variables
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:20 +01:00
Krzysztof Opasiak
0bd79c47cb libusbgx: Fix off-by-one error.
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:05:14 +01:00
Tony Lindgren
d805a6f2d9 libusbgx: Fix usbg_disable_gadget to actually clear the UDC
Currently usbg_disable_gadget() does not actually write anything
to UDC to clear it and the configured UDC name stays there.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:48:21 +01:00
Krzysztof Opasiak
3428a366e2 libusbgx: fix: reverse comparsion to fix error
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:48:20 +01:00
Philippe De Swert
3077b578f3 libusbgx: Return USBG_ERROR_PATH_TOO_LONG error when it happens
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
Acked-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:47:57 +01:00
Krzysztof Opasiak
67a56d406c libusbgx: Fix out-of-tree builds
The include flag should point to the source directory, not the build
directory.

Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>

Rebased onto kopasiak/master.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:46:03 +01:00
Krzysztof Opasiak
fa0acfd45b libusbgx: examples: Add gadget-import sample app
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:45:13 +01:00
Krzysztof Opasiak
8cadbec5ce libusbgx: Add functions to get import error text and line
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:45:02 +01:00
Krzysztof Opasiak
1988e7afb4 libusbgx: Add import gadget functionality
Whole gadget can be exported to file using usbg_export_gadget().
This commit adds complementary API function usbg_import_gadget()
which allows to import whole gadget (including attrs, strings,
configs, functions and bindings) from file to configfs.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:56 +01:00
Krzysztof Opasiak
72e3e4bc6d libusbgx: Allow to store error information in usbg_state
If error occurred during parsing user should have
an opportunity to get details about place and type
of error.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:50 +01:00
Krzysztof Opasiak
954c82ea5d libusbgx: Add import config functionality
Configurations can be exported to file using usbg_export_config().
This commit adds complementary API function usbg_import_config()
which allows to import configuration (with attrs, strings and
bindings) from file to chosen gadget.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:43 +01:00
Krzysztof Opasiak
c478fc8d7c libusbgx: Add import function functionality
Functions can be exported to file using usbg_export_function().
This commit adds complementary API function usbg_import_function()
which allows to import function from file to configfs.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:37 +01:00
Krzysztof Opasiak
001658b576 libusbgx: Allow to store error information in usbg_gadget
If error occurred during parsing user should have
an oportunity to get details about place and type
of error.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:28 +01:00
Krzysztof Opasiak
c2908012ac libusbgx: Add errors which may happen during parsing
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:18 +01:00
Krzysztof Opasiak
2aa8f8ae62 libusbgx: Add export gadget functionality
Whole gadget setting process take a lot of simple
commands (or lines of code). Those shell commands
may take a while or require dedicated script and
hard-coding gadget configuration. To avoid such
situation add to library ability to export a whole
gadget into file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:44:01 +01:00
Krzysztof Opasiak
fb3aa1133c libusbgx: Add export config functionality
Configuration may have several functions if we add
strings and some attributes it gives a few shell commands
to set it up. To avoid this add export cofiguration
which allows to store usb configuration in a file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:43:55 +01:00
Krzysztof Opasiak
2199fbdd69 libusbgx: Add export function functionality
Function settings may be complicated and their configuration
may take a long while. To save time it would be convenient
to allow for storing function settings in a file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:43:48 +01:00
Krzysztof Opasiak
ea42b108db libusbgx: Add label field to usbg_function structure
Add some field where additional label for function can be stored.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:43:38 +01:00
Krzysztof Opasiak
c306a23ddc libusbgx: Add dependency to libconfig
This library is used to import and export
gadget/function/config to and from file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:42:30 +01:00
Krzysztof Opasiak
a61c465d47 libusbgx: Use reentrant functions to avoid static buffers usage
ether_aton() and ether_ntoa() use static buffers which are
overwritten by next call of this function so those functions
should not be used in multithread environment.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:40:53 +01:00
Krzysztof Opasiak
d55899cb25 libusbgx: Add missing const qualifiers
Const qualifers should be placed in all functions which
don't need to modify provided buffers to allow caller to
pass literals or pointers to non-modifable space.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:40:46 +01:00
Krzysztof Opasiak
177ab1fe5b libusbgx: Don't try to set read only attribute
Some of function attributes are read only on configfs, so library
should not try to set them and accept only empty values in functions
which set multiple attributes at single call.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:40:38 +01:00
Krzysztof Opasiak
54bf28f8c8 libusbgx: Add support for functionFS.
Recent kernel versions supports creation of functionFS based
functions using configFS, so this library also should support this.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:40:19 +01:00
Krzysztof Opasiak
bd8d5769fc libusbgx: Fix potential memory leak in usbg_init()
Memory allocated with asprintf() for variable path
could be not free() in some cases. Fix this issue by
doing some small refactoring.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:40:11 +01:00
Krzysztof Opasiak
f105a847c4 libusbgx: Add remove gadget functionality.
Add function which allow to remove USB gadget.
This functions also remove gadget from internal
library structures what means that after this
operation all pointers to removed gadget are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:58 +01:00
Krzysztof Opasiak
ec4b771d97 libusbgx: Add remove function functionality.
Add function which allow to remove USB function.
This functions also remove function from internal
library structures what means that after this
operation all pointers to removed function are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:51 +01:00
Krzysztof Opasiak
f338ca35a5 libusbgx: Add remove configuration functionality.
Add function which allow to remove configuration.
This functions also remove binding from internal
library structures what means that after this
operation all pointers to removed config are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:43 +01:00
Krzysztof Opasiak
4517fe3c48 libusbgx: Add remove gadget/config strings functionality.
Add functions which allow to remove strings in gadget
and configuration.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:37 +01:00
Krzysztof Opasiak
a7ae6221cc libusbgx: Add remove binding functionality.
Add function which allow to remove binding between function
and configuration. This functions also remove binding from
internal library structures wht means that after this
operation all pointers to removed binding are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:30 +01:00
Philippe De Swert
8d2e47a48a libusbgx: Do not dereference usb config attributes when they are NULL. CID#56126
We probably need to check if we get valid attributes passed. Otherwise we will
try to dereference a NULL-pointer as the usb_config_attr will not be valid.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:23 +01:00
Philippe De Swert
6f4e2b6d25 libusbgx: Do not try to dereference func when it is NULL. CID#56127
We check if func is NULL, so if the allocation function failed we should
not dereference or handle it anymore, so we jump straight to the end.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 20:39:15 +01:00