usb_gadget: apply next HAL architecture #3 57/252457/1 accepted/tizen/unified/20210201.130306 submit/tizen/20210201.022214
authorINSUN PYO <insun.pyo@samsung.com>
Thu, 28 Jan 2021 11:08:25 +0000 (20:08 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Thu, 28 Jan 2021 11:08:52 +0000 (20:08 +0900)
- support usb serial for sdb devices
   ---------------------------------------------------
    $ sdb devices
      List of devices attached
      530MWC2R10400764          device          artik
   ---------------------------------------------------

- remove temporary "BuildRequires:  pkgconfig(dlog)" dependency

Change-Id: Iae4944b6848efda105396d718ad7fb73a994cd4a

packaging/hal-backend-device-common.spec
src/usb_gadget/usb_gadget_common.c

index 6e38281..17db5ef 100644 (file)
@@ -9,12 +9,8 @@ Source1:    %{name}.manifest
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(libusbgx)
 BuildRequires:  pkgconfig(hal-api-device)
-
 BuildRequires:  pkgconfig(libsyscommon)
 
-# TODO remove later. It's temporary patch
-BuildRequires:  pkgconfig(dlog)
-
 %description
 Library for HAL backend device modules
 
index 734f933..0628744 100644 (file)
@@ -21,7 +21,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-//include <hw/board.h> TODO move to common
 #include <libsyscommon/dbus-systemd.h>
 #include <hal/device/hal-usb_gadget-interface.h>
 
@@ -87,29 +86,7 @@ static int alloc_default_config(struct usb_configuration **_config)
        return 0;
 }
 
-static int get_device_serial(char **out)
-{
-#if 0 // TODO fix build error
-       struct hw_info *info;
-       struct hw_common *common;
-       struct hw_board *board;
-       int ret;
-
-       if (hw_get_info(BOARD_HARDWARE_DEVICE_ID, (const struct hw_info **)&info))
-               return -ENOENT;
-
-       ret = info->open(info, NULL, &common);
-       if (ret < 0)
-               return ret;
-
-       board = container_of(common, struct hw_board, common);
-       return board->get_device_serial(out);
-#else
-       return -1;
-#endif
-}
-
-static int alloc_default_gadget(struct usb_gadget **_gadget)
+static int alloc_default_gadget(char *serial, struct usb_gadget **_gadget)
 {
        struct usb_gadget *gadget;
        struct usb_configuration **configs;
@@ -125,8 +102,7 @@ static int alloc_default_gadget(struct usb_gadget **_gadget)
        gadget->strs.lang_code = DEFAULT_LANG;
        gadget->strs.manufacturer = strdup(DEFAULT_MANUFACTURER);
        gadget->strs.product = strdup(DEFAULT_PRODUCT);
-       if (get_device_serial(&gadget->strs.serial) < 0)
-               gadget->strs.serial = strdup(DEFAULT_SERIAL);
+       gadget->strs.serial = strdup(serial);
 
        if (!gadget->strs.manufacturer || !gadget->strs.product || !gadget->strs.serial)
                goto free_strs;
@@ -150,7 +126,7 @@ out:
        return -ENOMEM;
 }
 
-static int id_to_gadget(struct usb_gadget_id *gadget_id, struct usb_gadget **_gadget)
+static int id_to_gadget(struct usb_gadget_id *gadget_id, char *serial, struct usb_gadget **_gadget)
 {
        int ret;
        int i, j;
@@ -158,10 +134,10 @@ static int id_to_gadget(struct usb_gadget_id *gadget_id, struct usb_gadget **_ga
        struct usb_gadget *gadget;
        int functions[2][sizeof(gadget_id->function_mask)*8]; /* zero terminates */
 
-       if (!gadget_id || !_gadget)
+       if (!gadget_id || !serial || !_gadget)
                return -EINVAL;
 
-       ret = alloc_default_gadget(&gadget);
+       ret = alloc_default_gadget(serial, &gadget);
        if (ret)
                goto out;