#include <usbg/function/net.h>
#include <libsyscommon/dbus-systemd.h>
+#include <hw/usb_gadget.h>
#include <hw/usb_client.h>
#define CONFIGFS_PATH "/sys/kernel/config"
/* Based on values in slp-gadget kernel module */
struct usbg_gadget_attrs default_g_attrs = {
- .bcdUSB = 0x0200,
- .idVendor = 0x04e8,
- .idProduct = 0x6860,
- .bcdDevice = 0x0100,
+ .idVendor = DEFAULT_VID,
+ .idProduct = DEFAULT_PID,
+ .bcdDevice = DEFAULT_BCD_DEVICE,
};
struct usbg_gadget_strs default_g_strs = {
- .manufacturer = "Samsung",
- .product = "TIZEN",
- .serial = "01234TEST",
+ .manufacturer = DEFAULT_MANUFACTURER,
+ .product = DEFAULT_PRODUCT,
+ .serial = DEFAULT_SERIAL,
};
static struct usb_function *cfs_find_usb_function(usbg_function *function)
static int cfs_set_gadget_strs(struct cfs_client *cfs_client,
struct usb_gadget_strings *strs)
{
- int ret = 0;
+ int ret;
- /*
- * TODO
- * Here is a good place to ensure that serial is immutable
- */
#define SET_STR(FIELD, STR_ID) \
if (strs->FIELD) { \
ret = usbg_set_gadget_str(cfs_client->gadget, \
SET_STR(product, USBG_STR_PRODUCT);
SET_STR(serial, USBG_STR_SERIAL_NUMBER);
#undef SET_STR
- return ret;
+
+ return 0;
}
static int cfs_ensure_dir(char *path)
return 0;
}
-static int cfs_reconfigure_gadget(struct usb_client *usb,
- struct usb_gadget *gadget)
+static int cfs_reconfigure_gadget(struct usb_client *usb, struct usb_gadget *gadget)
{
int i;
int ret;
#include <libsyscommon/dbus-systemd.h>
#include <hw/shared.h>
+#include <hw/usb_gadget.h>
#include <hw/usb_client.h>
#define MAX_GADGET_STR_LEN 256
if (!gadget || !gadget->configs || !gadget->funcs)
return false;
- /*
- * TODO
- * Here is a good place to ensure that serial is immutable
- */
if (gadget->strs) {
/* only strings in US_en are allowed */
- if (gadget->strs[0].lang_code != 0x409 ||
- gadget->strs[1].lang_code)
+ if (gadget->strs[0].lang_code != DEFAULT_LANG || gadget->strs[1].lang_code)
return false;
}
{
int ret = 0;
- /*
- * TODO
- * Here is a good place to ensure that serial is immutable
- */
+ /* SLP gadget's kernel driver writes serial number directly */
if (strs->manufacturer) {
ret = sys_set_str(LEGACY_IMANUFACTURER_PATH, strs->manufacturer);
#include <hw/common.h>
-/**
- * The id of this device
- */
+/* The id of this device */
#define USB_GADGET_DEVICE_ID "usb_gadget"
-/**
- * The version of this device
- */
+/*The version of this device */
#define USB_GADGET_DEVICE_VERSION MAKE_VERSION(0,1)
+/*The default USB configuration */
+#define DEFAULT_VID 0x04e8
+#define DEFAULT_PID 0x6860
+#define DEFAULT_BCD_DEVICE 0x0100
+
+#define DEFAULT_LANG 0x409 /* US_en */
+#define DEFAULT_MANUFACTURER "Samsung"
+#define DEFAULT_PRODUCT "TIZEN"
+#define DEFAULT_SERIAL "01234TEST"
+
+#define DEFAULT_BMATTRIBUTES ((1 << 7) | (1 << 6))
+#define DEFAULT_MAX_POWER 500
+
typedef enum {
USB_FUNCTION_IDX_MTP = 0,
USB_FUNCTION_IDX_ACM = 1,
#include <hw/board.h>
#include <hw/usb_gadget.h>
-#define zalloc(amount) calloc(1, amount)
-
-/* Based on slp-gadget and initial version of USB HAL by Taeyoung Kim */
-#define DEFAULT_VID 0x04e8
-#define DEFAULT_PID 0x6860
-#define DEFAULT_BCD_DEVICE 0x0100
-
-#define DEFAULT_LANG 0x409 /* US_en */
-#define DEFAULT_MANUFACTURER "Samsung"
-#define DEFAULT_PRODUCT "TIZEN"
-#define DEFAULT_SERIAL "01234TEST"
-
-#define DEFAULT_BMATTRIBUTES ((1 << 7) | (1 << 6))
-#define DEFAULT_MAX_POWER 500
-
#ifndef EXPORT
#define EXPORT __attribute__ ((visibility("default")))
#endif
{
struct usb_configuration *config;
- config = zalloc(sizeof(*config));
+ config = calloc(1, sizeof(*config));
if (!config)
goto out;
struct usb_gadget *gadget;
struct usb_gadget_strings *strs;
struct usb_configuration **configs;
- int ret;
- gadget = zalloc(sizeof(*gadget));
+ gadget = calloc(1, sizeof(*gadget));
if (!gadget)
goto out;
if (!strs)
goto free_gadget;
- strs[0].lang_code = 0x409;
+ strs[0].lang_code = DEFAULT_LANG;
strs[0].manufacturer = strdup(DEFAULT_MANUFACTURER);
strs[0].product = strdup(DEFAULT_PRODUCT);
- ret = get_device_serial(&strs[0].serial);
- if (ret < 0)
+ if (get_device_serial(&strs[0].serial) < 0)
strs[0].serial = strdup(DEFAULT_SERIAL);
if (!strs[0].manufacturer || !strs[0].product || !strs[0].serial)
if (!info || !common)
return -EINVAL;
- simple_translator = zalloc(sizeof(*simple_translator));
+ simple_translator = calloc(1, sizeof(*simple_translator));
if (!simple_translator)
return -ENOMEM;