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

230 commits

Author SHA1 Message Date
Krzysztof Opasiak
0565d795b3 libusbgx: Refactor the core code to be more readable
Let's use more kernel-like convention to make gadget
code more readable.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
5637edd558 libusbgx: Switch to a new function API
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
76214e391a libusbgx: ms: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
5fff0aefae libusbgx: net: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
b5288f38de libusbgx: midi: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
114951d5ec libusbgx: loopback: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
70c13a532a libusbgx: serial: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
38fe104315 libusbgx: phonet: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
e722c6395f libusbgx: ffs: Add implementation of function specific API
Implement all function-specific functions from header file

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
5ea221a027 libusbgx: common: Add alloc_inst() and free_inst() callbacks
Those callback can be used by specific function type to allocate
and then free more memory than in raw usbg_function structure.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
8c5f9cde66 libusbgx: common: Add helper for getting and setting bool values
Add helper functions which allows to get and set bool values
from both configfs and libconfig files.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
9e6d1e7ee5 libusbgx: common: Add helper for getting and setting ether addr
Add helper functions which allows to get and set ether addr
from both configfs and libconfig files.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
f029af5061 libusbgx: common: Add helper for getting and setting string values
Add helper functions which allows to get and set string values
from both configfs and libconfig files.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
66533cd7e1 libusbgx: common: Add helper for getting and setting dec values
Add helper functions which allows to get and set int values
from both configfs and libconfig files.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
1868c4e91c libusbgx: common: Add functions for reading string with limited length
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:03 +01:00
Krzysztof Opasiak
013b9cc990 libusbgx: Add internal API for defining function types
Adding support for a new function type was quite complicated.
Moreover the main library source fail was growing realy fast.

As a solution introduce internal OO API for defining function.
Thanks to this support for each function may be placed in
a separate file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:02 +01:00
Krzysztof Opasiak
639a329af5 libusbgx: Move some common functions to a separate file
Main library file is definitely too big so let's move
some common functions into a separate file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:02 +01:00
Krzysztof Opasiak
43b2e6b11e libusbgx: Move error-ralted functions to a separate file
Main library file is definitely too big so let's move
some error-related functions into a separate file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-23 00:49:02 +01:00
Krzysztof Opasiak
bd24a4b60b libusbgx: Fix memory leak in usbg_set_function_ms_attrs()
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:37 +01:00
Krzysztof Opasiak
ef6cb691c8 libusbgx: Add support for importing/exporting loopback function
Now it is also possible to use loopback function in gadget
schemes.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:37 +01:00
Krzysztof Opasiak
5298d83e01 libusbgx: Add support for loopback function.
Now it is also possible to create and manage loopback
function using libusbgx library.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:37 +01:00
Pawel Szewczyk
42ac731c0e libusbgx: Add enum for gadget strings
This commit provides functionality for gadget strings similar to
existing gadget attributes api. It allows to iterate over gadget
strings and to write cleaner and more flexible code.

Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:37 +01:00
Pawel Szewczyk
943835a0e7 libusbgx: Add USBG_ERROR_NOT_EMPTY error code
ENOTEMPTY error is common when removing configfs objects. This commit
adds proper error message and internal usbg error code for this
situation.

Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:37 +01:00
Pawel Szewczyk
76911389a4 libusbgx: schemes: Allow to import midi function
Add support for importing midi function from gadget scheme.

Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Pawel Szewczyk
00035f6638 libusbgx: schemes: Allow to export midi function
Add support for exporting midi function to gadget scheme.

Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Krzysztof Opasiak
782cd0a928 libusbgx: Allow to pass NULL as name to usbg_add_config_function()
Somtimes we would like to add function to configuration
without any extraordinary name. In that case we can simply
use type.instance as symlink name.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Dominic Sacré
191ba95604 libusbgx: Add support for MIDI function
Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>

Fix usbg_parse_function_midi_attrs() to store qlen value
in qlen member of attrs struct instead of in buflen

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Dominic Sacré
52e41b29fc libusbgx: Mark char pointers in usbg_*_attrs as const
These attributes are const as far as a library user is concerned.
This change allows attributes to be cleanly initialized from string
literals.

Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Dominic Sacré
af4cb66925 libusbgx: Fix warnings when compiling with -Wall
Remove unused variables and duplicate const specifiers.
This makes libusbgx compile cleanly using -Wall with both gcc and clang.

Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Dominic Sacré
e2bd9bb192 libusbgx: Format switch statements more consistently
Insert blank lines between all cases in switch statements that branch
on attribute types.

Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Dominic Sacré
b0a27a01f6 libusbgx: Fix several typos
Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Pawel Szewczyk
c43977889d libusbgx: Fix mapping function type into attributes type
Type of ffs function's attribute is not PHONET, but FFS.

Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Stefan Agner
c769d06c3c libusbgx: print leading zero for MAC address bytes
The ethernet gadget driver requires the hex formatted MAC address
bytes with leading zero, in other words each byte needs to be two
characters in length (see get_ether_addr in u_ether.c). The libc
implementation ether_ntoa does not print leading zeros. Hence use
our own implementation which provides the format expected by the
kernel.

Signed-off-by: Stefan Agner <stefan@agner.ch>
[Rebased onto current master and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:36 +01:00
Krzysztof Opasiak
8a97503aba libusbgx: schemes: Allow to import mass storage function
Allow to import mass storage function from gadget scheme
file. This make mass storage to be fully supported by
libusbgx.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:36 +01:00
Krzysztof Opasiak
cdde313025 libusbgx: schemes: Allow to export mass storage function
Add support for exporting mass storage function to
gadget scheme.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:36 +01:00
Krzysztof Opasiak
70b529d1f4 libusbgx: Add support for mass storage function
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
3483e3b735 libusbgx: Add rm callback to usbg_function
Some functions requires more complicated rm method
which will remove its sub directories. To avoid complexity
in usbg_rm_function() just add a callback which is called
there.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
40270846b3 libusbgx: Add functions for reading/writing bool values
Some of function attributes on ConfigFS may be simple
boolean values so add common functions for reading
and writing them.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
9c6e2f3420 libusbgx: Rework usbg_read_buf() to accept also empty files
Some of configfs files may be empty. In that case fgets()
returns NULL but we should accept this situation and
treat it as an empty string.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
785c326baa libusbgx: Dereference pointer before switch
In each case in usbg_cleanup_function() we have
been using f_attrs->attrs. To make this shorter
and more readable add attrs pointer which is
equal to &f_attrs->attrs.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
f9157528ec libusbgx: Allow to pass usbg_init() without access to /sys/class/udc
We may would like to use this library on machine where
is no udc support (no /sys/class/udc directory) or
where we don't have sufficient rights to read udc
directory.

This commit adds support for such situation. If we are
running on such machine we will be able to pass usbg_init()
function and manage usb gadgets but we won't be able to bind
gadget to udc as we were unable to read their names.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
6efd53d659 libusbgx: Fix export of phonet attributes
ifname is read only attribute so there is no need
to export it but we should return USBG_SUCCESS
value because this function has been succesfully
exported.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
8402c83587 libusbgx: Remove static buffers from usbg_f_ffs_attrs
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
2546b50513 libusbgx: Remove static buffers from usbg_f_phonet_attrs
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
fe3fab5328 libusbgx: Remove static buffers from usbg_f_net_attrs
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
cee215c1df libusbgx: Introduce usbg_cleanup_function_attrs() function
We would like to eliminate static buffers from function
attributes. To achieve this we should ensure that there
is some function which free the memory allocated
in usbg_get_function_attrs()

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
752e9ee578 libusbgx: Make a use of usbg_f_attrs_type
This commit adds usbg_f_attrs_header which allows
to identify which union field is currently in use.
This allows to eliminate all switch() constructions
with list of all functions types for accessing
function attributes. Now, much more readable and
shorter enum with possible attribute types is used.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
885ac4405e libusbgx: Add usbg_f_attrs_type enum
Currently user has to know which functions has
net attrs, which serial etc. There is a few places
where the same switch construction with list of all
function types is used.

This commit introduce enumeration which can be used
to determine set of function attribute instead of
rewriting the same enum once again.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Krzysztof Opasiak
604d765b40 libusbgx: Pass suitable structure to usbg_parse_function_net_attrs()
This function is desired to parse only net attrs so pass
a pointer to net attrs structure instead of generic
attrs union.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
2015-12-22 21:45:35 +01:00
Dominic Sacré
70c71bdf1b libusbgx: Make *_attrs and *_strs arguments const-correct
This makes it easier to use libusbgx in clean, idiomatic C++ code.

This patch changes the *_attrs and *_strs arguments only. It does not
make any assumptions regarding the const-ness of other structures
(usbg_gadget etc.), which is something that doesn't come up in typical
use cases.

Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
[Add libusbgx: to commit message.]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
2015-12-22 21:45:35 +01:00