Coder Social home page Coder Social logo

gt's Introduction

gt

Gadget-tool - Linux command line tool for setting USB gadget using configFS

gt's People

Contributors

andrzejtp avatar astraluma avatar gbrikis avatar kopasiak avatar lmctl avatar nekocwd avatar pabs3 avatar pszewczyk avatar snikulov avatar stachw avatar tintou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gt's Issues

I want to assign address as .bEndpointAddress = 6 | USB_DIR_IN in ep2 ffs

Dear Kopasiak,

I facing issue when I cam configuring as
.bEndpointAddress = 6 | USB_DIR_IN in ep2.

Getting write error in the gadget side.

Ans Host side descriptor also showing it wrong.
expectation is it should detect endpoint 6 but it is showing as endpoint 1.

Can you tell me is it possible to assign any address to any endpoint ?

Regards,
Subham

Silent failure if no configuration file found

I cloned and compiled gt, and installed it using make install.

When I tried to run "gt", it appeared to succeed, but nothing happened. Eventually, running it under strace revealed that it was existing because it could not find any configuration files.

stat64("~/.gt.conf", 0xbecf8a28)        = -1 ENOENT (No such file or directory)
open("/etc/gt//gt.conf", O_RDONLY)      = -1 ENOENT (No such file or directory)
exit_group(-1)                          = ?
+++ exited with 255 +++

Creating /etc/gt/gt.conf as an empty file allowed it to continue.

segfault if function modules are not loaded

if the function module is not loaded you get a segfault when running

# gt func create cyberkey mass_storage usb0
(when usb_f_mass_storage) is not loaded, likewise with hid

Service running?

Ok, so I'm reading https://www.collabora.com/news-and-blog/blog/2019/03/27/modern-usb-gadget-on-linux-and-how-to-integrate-it-with-systemd-part-2/ and i'm like.... this is nuts. (I have an uneasy truce with systemd on the best of days.)

Could gt learn to start a service, the process being:

  1. load the scheme
  2. mount the ffs
  3. start the service
  4. enable the gadget
  5. Wait on the service (with signal forwarding?)
  6. Unmount the ffs
  7. remove the scheme
  8. return the return code of the service

It doesn't need to do full daemon management, just wrap another program to do the necessary usb init/etc.

For the record, I'm using gt with https://github.com/viveris/uMTP-Responder/ because I wrote my own script to do all this and having an actual declarative file is much nicer.

Problem when emulating a keyboard

Hi, I am using this tool to emulate a keyboard device, this is my scheme file:

attrs :
{
    bcdUSB = 0x200;
    bDeviceClass = 0xEF;
    bDeviceSubClass = 0x02;
    bDeviceProtocol = 0x01;
    bMaxPacketSize0 = 0x40;
    idVendor = 0x1d6b; 
    idProduct = 0x0437; 
    bcdDevice = 0x100;
};
strings = (
        {
                lang = 0x409;
                manufacturer = "Test_manu";
                product = "Test_pro";
                serialnumber = "deadbeef1337";
        }
);
functions :
{
    hid_keyboard :
    {
        instance = "keyboard";
        type = "hid";
        protocol = "1";
        subclass= "1";
        report_length = "8";
        report_desc = "\x05\x01\t\x06\xa1\x01\x05\x07\x19\xe0)\xe7\x15\x00%\x01u\x01\x95\x08\x81\x02\x95\x01u\x08\x81\x03\x95\x05u\x01\x05\x08\x19\x01)\x05\x91\x02\x95\x01u\x03\x91\x03\x95\x06u\x08\x15\x00%e\x05\x07\x19\x00)e\x81\x00\xc0";
    };
};
configs = (
    {
        id = 1;
        name = "c";
        attrs :
        {
            bmAttributes = 0x80;
            bMaxPower = 250;
        };
        functions = (
            {
                name = "hid.keyboard";
                function = "hid_keyboard";
            } );
    } );

The emulation is successful but the host cannot detect this keyboard. I checked those files in /sys/kernel/config/usb_gadget/keyboard/functions/hid.keyboard/, the files(protocal, subclass, report_length, report_desc) are not set as I expected. Is there anything wrong with my scheme file?
Thanks!

set mass_storage function parameters in sheme

Is there a way to set mass_storage function parameters in scheme ?
I have tried this syntax based on the examples i found on the repo :

functions : {
    mass_storage_usb0 : {
        instance = "usb0";
        type = "mass_storage";
        lun.0 = ({
                file = "/gadget-imgs/usbdisk.img";
        });
    };
};

but i get a syntax error.

am I typing it wrong or Is there some thing to implement to mage it work ?

Gadget Busy Error

Whenever I attempt to load my scheme file (a usb gadget that’s implementing a ffs.mtp) I get a BUSY code back & a “gadget enabled” error message. But to the best of my knowledge no attempt to load the .scheme file has happened yet.

(Although this isn’t strictly gt related but might be worth bearing in mind: even when I used direct calls to configfs; mkdir function/ffs.mtp for example, I get a device or resource busy error.)

The unit I’m working with is able to load & enable other gadgets ok, just not ffs ones.

Thanks for your time!

How to link configuration to os_descs?

Is there a way to link a configuration to os_desc?

Normally I'd issue ln -s configs/c.1/ os_desc in the gadget configfs folder, but I'd like to do this with a gadget-tool schema if possible.

I've tried specifying the os_descs multiple ways, but gt never seems to link the config.

Failed to configure mass storage function attrs using scheme

I set attrs in my scheme like so:

functions :
{
  cdrom0 :
  {
    instance = "0";
    type = "mass_storage";
    attrs :
    {
      stall = false;
      luns = (
        {
          ro = true;
          removable = true;
          cdrom = true;
        },
        {
          ro = false;
          removable = true;
          cdrom = false;
        }
      );
    };
  };
};

But actually the default values is used.
After I save scheme (i.e. via gt save --file gadget.scheme gadget) I have the following:

    mass_storage_0 :
    {
        instance = "0";
        type = "mass_storage";
        attrs :
        {
            stall = false;
            luns = (
                {
                    cdrom = false; # <-- expedted to be `true`
                    ro = false; # <-- expected to be `true` too
                    nofua = false;
                    removable = true;
                    file = "";
                },
                {
                    cdrom = false;
                    ro = false;
                    nofua = false;
                    removable = true;
                    file = "";
                } );
        };
        os_descs = ( );
    };

Manually read values is same:

$ cat /sys/kernel/config/usb_gadget/gadget/functions/mass_storage.0/lun.0/cdrom
0

$ cat /sys/kernel/config/usb_gadget/gadget/functions/mass_storage.0/lun.0/ro
0

How to set "iInterface" from gt/configfs?

I've been trying to set "iInterface" to a specific string, but I simply can't find a way to make gt/configfs accept this. I presume I'm missing something obvious but I simply can't find it:

When I set my gadget up on my Beaglebone Black I get:

iInterface 5 HID Interface

But I want it to be:
iInterface 4 LPC-LINK2 CMSIS-DAP V5.224

How do I do this?

(If you want to know my issue: This is the first step toward replacing an old custom obsolete programmer with something that can be used on modern hardware.)

Thanks.

# lsusb -vvvvvvv -d 1fc9:

Bus 001 Device 021: ID 1fc9:0090 NXP Semiconductors
Device Descriptor:
   bLength                18
   bDescriptorType         1
   bcdUSB               2.00
   bDeviceClass            0 (Defined at Interface level)
   bDeviceSubClass         0
   bDeviceProtocol         0
   bMaxPacketSize0        64
   idVendor           0x1fc9 NXP Semiconductors
   idProduct          0x0090
   bcdDevice            1.00
   iManufacturer           1 NXP Semiconductors
   iProduct                2 LPC-LINK2 CMSIS-DAP V5.224
   iSerial                 3 I3FSFVKZ
   bNumConfigurations      1
OTG Descriptor:
   bLength                 3
   bDescriptorType         9
   bmAttributes         0x03
     SRP (Session Request Protocol)
     HNP (Host Negotiation Protocol)
   Configuration Descriptor:
     bLength                 9
     bDescriptorType         2
     wTotalLength           44
     bNumInterfaces          1
     bConfigurationValue     1
     iConfiguration          4
     bmAttributes         0x80
       (Bus Powered)
     MaxPower              500mA
     Interface Descriptor:
       bLength                 9
       bDescriptorType         4
       bInterfaceNumber        0
       bAlternateSetting       0
       bNumEndpoints           2
       bInterfaceClass         3 Human Interface Device
       bInterfaceSubClass      0 No Subclass
       bInterfaceProtocol      0 None
       iInterface              5 HID Interface
         HID Device Descriptor:
           bLength                 9
           bDescriptorType        33
           bcdHID               1.01
           bCountryCode            0 Not supported
           bNumDescriptors         1
           bDescriptorType        34 Report
           wDescriptorLength      25
          Report Descriptors:
            ** UNAVAILABLE **
       Endpoint Descriptor:
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x81  EP 1 IN
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0040  1x 64 bytes
         bInterval               4
       Endpoint Descriptor:
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x01  EP 1 OUT
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0040  1x 64 bytes
         bInterval               4
Device Qualifier (for other device speed):
   bLength                10
   bDescriptorType         6
   bcdUSB               2.00
   bDeviceClass            0 (Defined at Interface level)
   bDeviceSubClass         0
   bDeviceProtocol         0
   bMaxPacketSize0        64
   bNumConfigurations      1
Device Status:     0x0000
   (Bus Powered)


Patch for compilation with libusbgx 0.2.0

Checked out repo today, didn't compile. This fixes compilation, sorry for not making a PR, but I find that a hassle usually.

From f0916276fd8f40e49144d2638f8f994c63a69315 Mon Sep 17 00:00:00 2001
From: Merlijn Wajer <[email protected]>
Date: Sat, 3 Mar 2018 12:32:45 +0100
Subject: [PATCH] Update to libusbgx 0.2.0

---
 source/config/src/configuration_libusbg.c |  4 ++--
 source/function/src/function_libusbg.c    | 26 +++++++++++++-------------
 source/gadget/src/gadget.c                | 16 ++++++++--------
 source/gadget/src/gadget_libusbg.c        | 22 +++++++++++-----------
 4 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/source/config/src/configuration_libusbg.c b/source/config/src/configuration_l
ibusbg.c
index ccbbbaa..dcd0a84 100644
--- a/source/config/src/configuration_libusbg.c
+++ b/source/config/src/configuration_libusbg.c
@@ -165,8 +165,8 @@ int gt_print_config_libusbg(usbg_config *c, int opts)
        usbg_function *f;
        const char *label, *instance, *bname;
        usbg_function_type type;
-       usbg_config_attrs c_attrs;
-       usbg_config_strs c_strs;
+       struct usbg_config_attrs c_attrs;
+       struct usbg_config_strs c_strs;
        int usbg_ret, id;

        label = usbg_get_config_label(c);
diff --git a/source/function/src/function_libusbg.c b/source/function/src/function_libusbg
.c
index 74dba21..dc3e674 100644
--- a/source/function/src/function_libusbg.c
+++ b/source/function/src/function_libusbg.c
@@ -126,18 +126,18 @@ int gt_print_function_libusbg(usbg_function *f, int opts)
                return 0;

        switch (type) {
-       case F_ACM:
-       case F_OBEX:
-       case F_SERIAL:
+       case USBG_F_ACM:
+       case USBG_F_OBEX:
+       case USBG_F_SERIAL:
                fprintf(stdout, "    port_num\t\t%d\n",
                        f_attrs.serial_port_num);
                break;

-       case F_ECM:
-       case F_SUBSET:
-       case F_NCM:
-       case F_EEM:
-       case F_RNDIS:
+       case USBG_F_ECM:
+       case USBG_F_SUBSET:
+       case USBG_F_NCM:
+       case USBG_F_EEM:
+       case USBG_F_RNDIS:
                fprintf(stdout, "    dev_addr\t\t%s\n",
                        ether_ntoa(&f_attrs.net.dev_addr));
                fprintf(stdout, "    host_addr\t\t%s\n",
@@ -146,15 +146,15 @@ int gt_print_function_libusbg(usbg_function *f, int opts)
                fprintf(stdout, "    qmult\t\t%d\n", f_attrs.net.qmult);
                break;

-       case F_PHONET:
+       case USBG_F_PHONET:
                fprintf(stdout, "    ifname\t\t%s\n", f_attrs.phonet_ifname);
                break;

-       case F_FFS:
+       case USBG_F_FFS:
                fprintf(stdout, "    dev_name\t\t%s\n", f_attrs.ffs_dev_name);
                break;

-       case F_MASS_STORAGE:
+       case USBG_F_MASS_STORAGE:
        {
                struct usbg_f_ms_attrs *attrs = &f_attrs.ms;
                int i;
@@ -172,7 +172,7 @@ int gt_print_function_libusbg(usbg_function *f, int opts)
                break;
        }

-       case F_MIDI:
+       case USBG_F_MIDI:
        {
                struct usbg_f_midi_attrs *attrs = &f_attrs.midi;

@@ -185,7 +185,7 @@ int gt_print_function_libusbg(usbg_function *f, int opts)
                break;
        }

-       case F_LOOPBACK:
+       case USBG_F_LOOPBACK:
        {
                struct usbg_f_loopback_attrs *attrs = &f_attrs.loopback;

diff --git a/source/gadget/src/gadget.c b/source/gadget/src/gadget.c
index 1fedb83..2d853ed 100644
--- a/source/gadget/src/gadget.c
+++ b/source/gadget/src/gadget.c
@@ -55,16 +55,16 @@ static void gt_gadget_create_destructor(void *data)
 char *attr_type_get(usbg_gadget_attr a)
 {
        switch (a) {
-       case B_DEVICE_CLASS:
-       case B_DEVICE_SUB_CLASS:
-       case B_DEVICE_PROTOCOL:
-       case B_MAX_PACKET_SIZE_0:
+       case USBG_B_DEVICE_CLASS:
+       case USBG_B_DEVICE_SUB_CLASS:
+       case USBG_B_DEVICE_PROTOCOL:
+       case USBG_B_MAX_PACKET_SIZE_0:
                return "y";

-       case BCD_USB:
-       case ID_VENDOR:
-       case ID_PRODUCT:
-       case BCD_DEVICE:
+       case USBG_BCD_USB:
+       case USBG_ID_VENDOR:
+       case USBG_ID_PRODUCT:
+       case USBG_BCD_DEVICE:
                return "q";

        default:
diff --git a/source/gadget/src/gadget_libusbg.c b/source/gadget/src/gadget_libusbg.c
index 7fb1ebd..8bdecfb 100644
--- a/source/gadget/src/gadget_libusbg.c
+++ b/source/gadget/src/gadget_libusbg.c
@@ -234,25 +234,25 @@ static int disable_func(void *data)
        return 0;
 }

-static void print_gadget_attrs(usbg_gadget_attrs *g_attrs, int *mask) {
-       if (!mask || mask[BCD_USB])
+static void print_gadget_attrs(struct usbg_gadget_attrs *g_attrs, int *mask) {
+       if (!mask || mask[USBG_BCD_USB])
                printf("  bcdUSB\t\t%x.%02x\n",
                        g_attrs->bcdUSB >> 8,
                        g_attrs->bcdUSB & 0x00ff);

-       if (!mask || mask[B_DEVICE_CLASS])
+       if (!mask || mask[USBG_B_DEVICE_CLASS])
                printf("  bDeviceClass\t\t0x%02x\n", g_attrs->bDeviceClass);
-       if (!mask || mask[B_DEVICE_SUB_CLASS])
+       if (!mask || mask[USBG_B_DEVICE_SUB_CLASS])
                printf("  bDeviceSubClass\t0x%02x\n", g_attrs->bDeviceSubClass);
-       if (!mask || mask[B_DEVICE_PROTOCOL])
+       if (!mask || mask[USBG_B_DEVICE_PROTOCOL])
                printf("  bDeviceProtocol\t0x%02x\n", g_attrs->bDeviceProtocol);
-       if (!mask || mask[B_MAX_PACKET_SIZE_0])
+       if (!mask || mask[USBG_B_MAX_PACKET_SIZE_0])
                printf("  bMaxPacketSize0\t%d\n", g_attrs->bMaxPacketSize0);
-       if (!mask || mask[ID_VENDOR])
+       if (!mask || mask[USBG_ID_VENDOR])
                printf("  idVendor\t\t0x%04x\n", g_attrs->idVendor);
-       if (!mask || mask[ID_PRODUCT])
+       if (!mask || mask[USBG_ID_PRODUCT])
                printf("  idProduct\t\t0x%04x\n", g_attrs->idProduct);
-       if (!mask || mask[BCD_DEVICE])
+       if (!mask || mask[USBG_BCD_DEVICE])
                printf("  bcdDevice\t\t%x.%02x\n",
                        g_attrs->bcdDevice >> 8,
                        g_attrs->bcdDevice & 0x00ff);
@@ -263,7 +263,7 @@ static int get_func(void *data)
        struct gt_gadget_get_data *dt;

        usbg_gadget *g;
-       usbg_gadget_attrs g_attrs;
+       struct usbg_gadget_attrs g_attrs;
        int usbg_ret;

        dt = (struct gt_gadget_get_data *)data;
@@ -288,7 +288,7 @@ static int get_func(void *data)

 static int print_gadget(usbg_gadget *g, int opts)
 {
-       usbg_gadget_attrs g_attrs;
+       struct usbg_gadget_attrs g_attrs;
        usbg_udc *u;
        usbg_function *f;
        usbg_config *c;
--
2.16.2

Man page install directory

It seems by default the CMake build system installs the manpage into /usr/share/man/gt.1.gz but it should be in the man1 subdirectory, so /usr/share/man/man1/gt.1.gz

It's possible to overwrite/set the directory at build time with -DCMAKE_INSTALL_MANDIR=/usr/share/man/man1 but the default should also put it into the correct place so no override is necessary

error when invoking gt

Hi,

first I have to admit I'm a real newbie concerning the use of manually built libraries and commands. Nevertheless I suceeded in building gt without errors on my raspberry but now when I want to invoke gt it ends up either with "Error reading configuration /etc/gt//gt.conf". Probably some mismatch with my folders?

And one more question: my background for trying gt is that I'd like to use my raspberry simultaneously as an usb audio gadget (g_audio) and as a serial device (g_serial). Do you think this should work when I'm using gt?

Thanks and best regards,
Johannes

error on compile

Scanning dependencies of target config
[ 20%] Building C object config/CMakeFiles/config.dir/src/configuration.c.o
[ 23%] Building C object config/CMakeFiles/config.dir/src/configuration_gadgetd.c.o
[ 26%] Building C object config/CMakeFiles/config.dir/src/configuration_libusbg.c.o
/root/gt-master/source/config/src/configuration_libusbg.c: In function ‘gt_print_config_libusbg’:
/root/gt-master/source/config/src/configuration_libusbg.c:168:2: error: unknown type name ‘usbg_config_attrs’
  usbg_config_attrs c_attrs;
  ^~~~~~~~~~~~~~~~~
/root/gt-master/source/config/src/configuration_libusbg.c:168:2: note: use ‘struct’ keyword to refer to the type
/root/gt-master/source/config/src/configuration_libusbg.c:169:2: error: unknown type name ‘usbg_config_strs’
  usbg_config_strs c_strs;
  ^~~~~~~~~~~~~~~~
/root/gt-master/source/config/src/configuration_libusbg.c:169:2: note: use ‘struct’ keyword to refer to the type
/root/gt-master/source/config/src/configuration_libusbg.c:188:39: warning: passing argument 2 of ‘usbg_get_config_attrs’ from incompatible pointer type [-Wincompatible-pointer-types]
   usbg_ret = usbg_get_config_attrs(c, &c_attrs);
                                       ^
In file included from /root/gt-master/source/config/src/configuration_libusbg.c:20:0:
/usr/local/include/usbg/usbg.h:790:12: note: expected ‘struct usbg_config_attrs *’ but argument is of type ‘int *’
 extern int usbg_get_config_attrs(usbg_config *c,
            ^~~~~~~~~~~~~~~~~~~~~
/root/gt-master/source/config/src/configuration_libusbg.c:195:41: error: request for member ‘bMaxPower’ in something not a structure or union
   printf("    MaxPower\t\t%d\n", c_attrs.bMaxPower);
                                         ^
/root/gt-master/source/config/src/configuration_libusbg.c:196:47: error: request for member ‘bmAttributes’ in something not a structure or union
   printf("    bmAttributes\t0x%02x\n", c_attrs.bmAttributes);
                                               ^

Is this a vaild serial/uac2 scheme?

Hi,

my scheme file seems to work in general but I'm not sure, whether I'm using the right placement for the attributs for my uac2 gadget:

attrs :
{
idVendor = 0x1D6B;
idProduct = 0x104;
};
strings = (
{
lang = 0x409;
manufacturer = "MyLocalTest";
product = "MyTestPI";
}
);
functions :
{
uac2_usb0 :
{
instance = "usb0";
type = "uac2";
attrs :
{
c_chmask = 3;
c_srate = 48000;
c_ssize = 3;
p_chmask = 3;
p_srate = 48000;
p_ssize = 3;
};
},
acm_usb0 :
{
instance = "usb0";
type = "acm";
};
};
configs = (
{
id = 1;
name = "c";
functions = (
{
name = "uac2.usb0";
function = "uac2_usb0";
},
{
name = "acm.usb0";
function = "acm_usb0";
} );
} );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.