summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2014-02-27 19:00:12 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2014-03-11 09:25:12 +0100
commit7310bf251a8b83ee71c912a88d0e7b9a64ea1a78 (patch)
tree7d9a8c7dd520ffb7ee1c611d82d1e0acbb35e7a5
parent427d5ab2a777937ab4775eed525ed273f185c2ad (diff)
downloadlibusbg-7310bf251a8b83ee71c912a88d0e7b9a64ea1a78.tar.gz
libusbg-7310bf251a8b83ee71c912a88d0e7b9a64ea1a78.tar.bz2
libusbg-7310bf251a8b83ee71c912a88d0e7b9a64ea1a78.zip
libusbg: Add return value to usbg_set_gadget_*() functions.
Setting each of attribute may fail due to a lot of reasons so those functions should report this failure to a user. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--include/usbg/usbg.h33
-rw-r--r--src/usbg.c85
2 files changed, 77 insertions, 41 deletions
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index f6f7a2e..17084bb 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -314,62 +314,70 @@ extern int usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len);
* @brief Set the USB gadget vendor id
* @param g Pointer to gadget
* @param idVendor USB device vendor id
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
+extern int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
/**
* @brief Set the USB gadget product id
* @param g Pointer to gadget
* @param idProduct USB device product id
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
+extern int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
/**
* @brief Set the USB gadget device class code
* @param g Pointer to gadget
* @param bDeviceClass USB device class code
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_device_class(usbg_gadget *g,
+extern int usbg_set_gadget_device_class(usbg_gadget *g,
uint8_t bDeviceClass);
/**
* @brief Set the USB gadget protocol code
* @param g Pointer to gadget
* @param bDeviceProtocol USB protocol code
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_device_protocol(usbg_gadget *g,
+extern int usbg_set_gadget_device_protocol(usbg_gadget *g,
uint8_t bDeviceProtocol);
/**
* @brief Set the USB gadget device subclass code
* @param g Pointer to gadget
* @param bDeviceSubClass USB device subclass code
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_device_subclass(usbg_gadget *g,
+extern int usbg_set_gadget_device_subclass(usbg_gadget *g,
uint8_t bDeviceSubClass);
/**
* @brief Set the maximum packet size for a gadget
* @param g Pointer to gadget
* @param bMaxPacketSize0 Maximum packet size
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_device_max_packet(usbg_gadget *g,
+extern int usbg_set_gadget_device_max_packet(usbg_gadget *g,
uint8_t bMaxPacketSize0);
/**
* @brief Set the gadget device BCD release number
* @param g Pointer to gadget
* @param bcdDevice BCD release number
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_device_bcd_device(usbg_gadget *g,
+extern int usbg_set_gadget_device_bcd_device(usbg_gadget *g,
uint16_t bcdDevice);
/**
* @brief Set the gadget device BCD USB version
* @param g Pointer to gadget
* @param bcdUSB BCD USB version
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
+extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
/**
* @brief Get the USB gadget strings
@@ -397,24 +405,27 @@ extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
* @param g Pointer to gadget
* @param lang USB language ID
* @param ser Serial number
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser);
+extern int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser);
/**
* @brief Set the manufacturer name for a gadget
* @param g Pointer to gadget
* @param lang USB language ID
* @param mnf Manufacturer
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf);
+extern int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf);
/**
* @brief Set the product name for a gadget
* @param g Pointer to gadget
* @param lang USB language ID
* @param prd Product
+ * @return 0 on success usbg_error if error occurred
*/
-extern void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
+extern int usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
/* USB function allocation and configuration */
diff --git a/src/usbg.c b/src/usbg.c
index ed8070d..5a4202c 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1012,44 +1012,52 @@ out:
return ret;
}
-void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
+int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
{
- usbg_write_hex16(g->path, g->name, "idVendor", idVendor);
+ return g ? usbg_write_hex16(g->path, g->name, "idVendor", idVendor)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
+int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
{
- usbg_write_hex16(g->path, g->name, "idProduct", idProduct);
+ return g ? usbg_write_hex16(g->path, g->name, "idProduct", idProduct)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
+int usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
{
- usbg_write_hex8(g->path, g->name, "bDeviceClass", bDeviceClass);
+ return g ? usbg_write_hex8(g->path, g->name, "bDeviceClass", bDeviceClass)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
+int usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
{
- usbg_write_hex8(g->path, g->name, "bDeviceProtocol", bDeviceProtocol);
+ return g ? usbg_write_hex8(g->path, g->name, "bDeviceProtocol", bDeviceProtocol)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
+int usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
{
- usbg_write_hex8(g->path, g->name, "bDeviceSubClass", bDeviceSubClass);
+ return g ? usbg_write_hex8(g->path, g->name, "bDeviceSubClass", bDeviceSubClass)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0)
+int usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0)
{
- usbg_write_hex8(g->path, g->name, "bMaxPacketSize0", bMaxPacketSize0);
+ return g ? usbg_write_hex8(g->path, g->name, "bMaxPacketSize0", bMaxPacketSize0)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
+int usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
{
- usbg_write_hex16(g->path, g->name, "bcdDevice", bcdDevice);
+ return g ? usbg_write_hex16(g->path, g->name, "bcdDevice", bcdDevice)
+ : USBG_ERROR_INVALID_PARAM;
}
-void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
+int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
{
- usbg_write_hex16(g->path, g->name, "bcdUSB", bcdUSB);
+ return g ? usbg_write_hex16(g->path, g->name, "bcdUSB", bcdUSB)
+ : USBG_ERROR_INVALID_PARAM;
}
usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
@@ -1082,8 +1090,10 @@ int usbg_set_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs)
{
char path[USBG_MAX_PATH_LENGTH];
- DIR *dir;
- int ret = USBG_SUCCESS;
+ int ret = USBG_ERROR_INVALID_PARAM;
+
+ if (!g || !g_strs)
+ goto out;
sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
@@ -1104,37 +1114,52 @@ out:
return ret;
}
-void usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *serno)
+int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *serno)
{
char path[USBG_MAX_PATH_LENGTH];
+ int ret = USBG_ERROR_INVALID_PARAM;
- sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
+ if (g && serno) {
+ sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
- mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
+ ret = usbg_check_dir(path);
+ if (ret == USBG_SUCCESS)
+ ret = usbg_write_string(path, "", "serialnumber", serno);
+ }
- usbg_write_string(path, "", "serialnumber", serno);
+ return ret;
}
-void usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf)
+int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf)
{
char path[USBG_MAX_PATH_LENGTH];
+ int ret = USBG_ERROR_INVALID_PARAM;
- sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
+ if (g && mnf) {
+ sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
- mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
+ ret = usbg_check_dir(path);
+ if (ret == USBG_SUCCESS)
+ ret = usbg_write_string(path, "", "manufacturer", mnf);
+ }
- usbg_write_string(path, "", "manufacturer", mnf);
+ return ret;
}
-void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd)
+int usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd)
{
char path[USBG_MAX_PATH_LENGTH];
+ int ret = USBG_ERROR_INVALID_PARAM;
- sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
+ if (g && prd) {
+ sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
- mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
+ ret = usbg_check_dir(path);
+ if (ret == USBG_SUCCESS)
+ ret = usbg_write_string(path, "", "product", prd);
+ }
- usbg_write_string(path, "", "product", prd);
+ return ret;
}
usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type type,