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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>