Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #65 has a regression for ether devices. #101

Open
einarjon opened this issue Oct 21, 2024 · 2 comments
Open

Issue #65 has a regression for ether devices. #101

einarjon opened this issue Oct 21, 2024 · 2 comments

Comments

@einarjon
Copy link

einarjon commented Oct 21, 2024

Renaming the class variable has a side-effect:
https://github.com/linux-usb-gadgets/libusbgx/blob/master/src/function/ether.c#L70

Now the library will want to write to the file "class_" instead of "class", and that breaks
usbg_create_function() if f_attrs != NULL.

One way to fix that:

diff --git a/src/function/ether.c b/src/function/ether.c
index a1d20f1..fd29312 100644
--- a/src/function/ether.c
+++ b/src/function/ether.c
@@ -23,9 +23,9 @@ struct usbg_f_net {
        struct usbg_function func;
 };
 
-#define NET_DEC_ATTR(_name)                                            \
+#define NET_DEC_ATTR2(_name,_filename)                                 \
        {                                                               \
-               .name = #_name,                                         \
+               .name = #_filename,                                     \
                .ro = false,                                            \
                .offset = offsetof(struct usbg_f_net_attrs, _name),     \
                .get = usbg_get_dec,                                    \
@@ -34,6 +34,8 @@ struct usbg_f_net {
                .export = usbg_set_config_node_int,                     \
        }
 
+#define NET_DEC_ATTR(_name) NET_DEC_ATTR2(_name, _name)
+
 #define NET_RO_STRING_ATTR(_name)                                      \
        {                                                               \
                .name = #_name,                                         \
@@ -67,7 +69,7 @@ static struct {
        [USBG_F_NET_HOST_ADDR] = NET_ETHER_ADDR_ATTR(host_addr),
        [USBG_F_NET_IFNAME] = NET_RO_STRING_ATTR(ifname),
        [USBG_F_NET_QMULT] = NET_DEC_ATTR(qmult),
-       [USBG_F_NET_CLASS] = NET_DEC_ATTR(class_),
+       [USBG_F_NET_CLASS] = NET_DEC_ATTR2(class_,class),
        [USBG_F_NET_SUBCLASS] = NET_DEC_ATTR(subclass),
        [USBG_F_NET_PROTOCOL] = NET_DEC_ATTR(protocol)
 };

Confirmed broken for NCM and RNDIS in master, but only if usbg_create_function() is called with f_attrs != NULL.
The error is in usbg_f_net_set_attrs(): Setting attr USBG_F_NET_CLASS returns USBG_ERROR_NO_ACCESS

@einarjon
Copy link
Author

Relates to Issue #65

@einarjon
Copy link
Author

einarjon commented Oct 24, 2024

This is actually worse than described:
The class/subclass/protocol parameters only exist for rndis, so trying to set those values breaks ncm/ecm devices

# ls /config/usb_gadget/g1/functions/rndis.usb0/
class  dev_addr  host_addr  ifname  os_desc  protocol  qmult  subclass
# ls /config/usb_gadget/g1/functions/ecm.usb0/
dev_addr  host_addr  ifname  qmult

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant