* limitations under the License.
*/
+#include <stdlib.h>
+#include <string.h>
#include <hal/hal-common.h>
#include "common.h"
+#include "hal-board.h"
#include "hal-usb_gadget-interface.h"
hal_backend_usb_gadget_funcs *g_usb_gadget_funcs;
-static int usb_gadget_is_valid(void)
+static int usb_gadget_is_valid(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
{
- if(g_usb_gadget_funcs &&
- g_usb_gadget_funcs->id_to_gadget &&
- g_usb_gadget_funcs->cleanup_gadget &&
- g_usb_gadget_funcs->enable &&
- g_usb_gadget_funcs->disable &&
- g_usb_gadget_funcs->reconfigure_gadget)
+ if(usb_gadget_funcs &&
+ usb_gadget_funcs->board_serial &&
+ usb_gadget_funcs->id_to_gadget &&
+ usb_gadget_funcs->cleanup_gadget &&
+ usb_gadget_funcs->enable &&
+ usb_gadget_funcs->disable &&
+ usb_gadget_funcs->reconfigure_gadget)
return 1;
return 0;
}
+static int get_board_serial(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
+{
+ char *board_serial = NULL;
+
+ if (!usb_gadget_funcs)
+ return -EINVAL;
+
+ if (hal_device_board_get_backend()) {
+ _E("Failed to get board backend for USB");
+ goto no_board;
+ }
+
+ if (hal_device_board_get_device_serial(&board_serial)) {
+ _E("Failed to get board serial for USB");
+ goto no_serial;
+ }
+
+no_serial:
+ /* hal_device_board_put_backend(); // Hack. continue to use board hal */
+
+no_board:
+ if (!board_serial)
+ board_serial = strdup(DEFAULT_SERIAL);
+
+ usb_gadget_funcs->board_serial = board_serial;
+ if (!usb_gadget_funcs->board_serial)
+ return -ENOMEM;
+
+ return 0;
+}
+
int hal_device_usb_gadget_get_backend(void)
{
int ret;
return -EINVAL;
}
- if(!usb_gadget_is_valid()) {
+ (void) get_board_serial(g_usb_gadget_funcs);
+
+ if(!usb_gadget_is_valid(g_usb_gadget_funcs)) {
_E("USB gadget backend is not valid");
hal_common_put_backend(HAL_MODULE_DEVICE_USB_GADGET, (void *)g_usb_gadget_funcs);
return -ENODEV;
if (!g_usb_gadget_funcs)
return 0;
- if(!usb_gadget_is_valid())
+ if(!usb_gadget_is_valid(g_usb_gadget_funcs))
return -ENODEV;
hal_common_put_backend(HAL_MODULE_DEVICE_USB_GADGET, (void *)g_usb_gadget_funcs);
+
+ free(g_usb_gadget_funcs->board_serial);
g_usb_gadget_funcs = NULL;
return 0;
int hal_device_usb_gadget_enable(void)
{
- if(!usb_gadget_is_valid())
+ if(!usb_gadget_is_valid(g_usb_gadget_funcs))
return -ENODEV;
return g_usb_gadget_funcs->enable();
int hal_device_usb_gadget_disable(void)
{
- if(!usb_gadget_is_valid())
+ if(!usb_gadget_is_valid(g_usb_gadget_funcs))
return -ENODEV;
return g_usb_gadget_funcs->disable();
struct usb_gadget *gadget;
struct usb_gadget_id gadget_id;
- if(!usb_gadget_is_valid())
+ if(!usb_gadget_is_valid(g_usb_gadget_funcs))
return -ENODEV;
memset(&gadget_id, 0, sizeof(gadget_id));
gadget_id.function_mask = mode;
- ret = g_usb_gadget_funcs->id_to_gadget(&gadget_id, &gadget);
+ ret = g_usb_gadget_funcs->id_to_gadget(&gadget_id, g_usb_gadget_funcs->board_serial, &gadget);
if (ret) {
_E("Unable to translate USB mode id into gadget: %d", ret);
return ret;