case VCONFKEY_SYSMAN_USB_DISCONNECTED:
str = EVT_VAL_USB_DISCONNECTED;
break;
+
case VCONFKEY_SYSMAN_USB_CONNECTED:
str = EVT_VAL_USB_CONNECTED;
break;
+
case VCONFKEY_SYSMAN_USB_AVAILABLE:
str = EVT_VAL_USB_AVAILABLE;
break;
+
default:
return;
}
}
ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, mode_v);
- if (ret < 0)
+ if (ret != VCONF_OK)
_E("Failed to set vconf value for usb selected mode: %d", vconf_get_ext_errno());
return ret;
usb_connection = conn;
}
-
-#if 0
-char *usb_state_get_mode_str(unsigned int mode, char *str, size_t len)
-{
- int i;
- int ret;
- int flag = 0;
-
- if (mode == USB_FUNCTION_NONE) {
- snprintf(str, len, "%s", "");
- } else {
- for (i = 0; i < ARRAY_SIZE(_available_funcs); ++i) {
- if (mode & _available_funcs[i]->id) {
- ret = snprintf(str, len, "%s,",
- _available_funcs[i]->name);
- if (ret >= len)
- return str;
- str += ret;
- len -= ret;
- flag = 1;
- }
- }
- if (flag == 1) {
- /* eliminate trailing comma */
- *(str - 1) = '\0';
- }
- }
-
- return str;
-}
-#endif
-
static void media_noti_cb(GVariant *var, void *user_data, GError *err)
{
int id = 0;
static void send_usb_state_changed_event(extcon_usb_state_e state, unsigned int mode)
{
- int ret;
int status;
static int old_status = -1;
usb_state_send_system_event(status);
- ret = vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, status);
- if (ret < 0)
+ if (vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, status) != VCONF_OK)
_E("Failed to set vconf value for usb status: %d", vconf_get_ext_errno());
broadcast_usb_state_changed();
static int usb_tethering_mode_changed(void *data)
{
bool on;
- unsigned mode;
int ret = 0;
+ unsigned mode;
on = (bool)data;
void add_usb_tethering_handler(void)
{
- if (vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE,
- usb_tethering_changed, NULL) != 0)
+ if (vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, usb_tethering_changed, NULL) != VCONF_OK)
_E("Failed to add usb tethering handler.");
- register_notifier(DEVICE_NOTIFIER_USB_TETHERING_MODE,
- usb_tethering_mode_changed);
+ register_notifier(DEVICE_NOTIFIER_USB_TETHERING_MODE, usb_tethering_mode_changed);
}
void remove_usb_tethering_handler(void)
{
- vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE,
- usb_tethering_changed);
+ vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, usb_tethering_changed);
- unregister_notifier(DEVICE_NOTIFIER_USB_TETHERING_MODE,
- usb_tethering_mode_changed);
+ unregister_notifier(DEVICE_NOTIFIER_USB_TETHERING_MODE, usb_tethering_mode_changed);
}
static int usb_config_init(void)
{
int ret;
- struct usb_gadget_id gadget_id;
struct usb_gadget *gadget;
+ struct usb_gadget_id gadget_id;
if (!gadget_translator || !usb_client)
goto no_hal;
_E("Unable to configure gadget: %d", ret);
return ret;
+
no_hal:
/* TODO. Maybe some default action here? */
return -ENODEV;
usb_client->disable(usb_client);
return;
+
no_hal:
/* TODO. Maybe some default action here? */
return;
usb_client->disable(usb_client);
return 0;
+
no_hal:
/* TODO. Maybe some default action here? */
return -ENODEV;
static int usb_change_gadget(unsigned mode)
{
- struct usb_gadget_id gadget_id;
- struct usb_gadget *gadget;
int ret;
+ struct usb_gadget *gadget;
+ struct usb_gadget_id gadget_id;
if (!gadget_translator || !usb_client)
goto no_hal;
gadget_translator->cleanup_gadget(gadget);
if (ret) {
_E("Unable to configure gadget: %d", ret);
- goto out;
+ return ret;
}
_I("USB gadget changed to %d.", mode);
-out:
return ret;
+
no_hal:
/* TODO. Maybe some default action here? */
return -ENODEV;
return 0;
}
+static int usb_connected(void)
+{
+ int ret;
+ unsigned int mode = usb_state_get_selected_mode();
+
+ usb_state_update_state(USB_CONNECTED, USB_FUNCTION_NONE);
+
+ ret = usb_enable(mode);
+ if (ret < 0) {
+ _E("Failed to enable usb gadget(%d): %d", mode, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int usb_disconnected(void)
+{
+ usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE);
+
+ return usb_disable();
+}
+
+/* Called by dbus signal and vconf change(tethering, debug mode) */
int usb_change_mode(unsigned mode)
{
int ret;
return 0;
}
-static int usb_connected(void)
-{
- int ret;
- unsigned int mode = usb_state_get_selected_mode();
-
- usb_state_update_state(USB_CONNECTED, USB_FUNCTION_NONE);
-
- ret = usb_enable(mode);
- if (ret < 0) {
- _E("Failed to enable usb gadget(%d): %d", mode, ret);
- return ret;
- }
-
- return 0;
-}
-
-static int usb_disconnected(void)
-{
- usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE);
-
- return usb_disable();
-}
-
-static int usb_state_changed(int status)
+/* Called by extcon udev event */
+static int usb_state_changed(int new_status)
{
- static int old = -1; /* to update at the first time */
- int ret;
+ int ret = -1;
+ static int old_status = -1;
/* For debugging. Do not move the location. */
- _I("USB state is changed from (%d) to (%d).", old, status);
+ _I("USB state is changed from (%d) to (%d).", old_status, new_status);
- if (old == status)
+ if (old_status == new_status)
return 0;
- switch (status) {
+ switch (new_status) {
case USB_CONNECTED:
ret = usb_connected();
break;
+
case USB_DISCONNECTED:
ret = usb_disconnected();
break;
+
default:
- _E("Invalid USB state(%d).", status);
+ _E("Invalid USB state(%d).", new_status);
return -EINVAL;
}
- if (ret < 0)
+ if (ret < 0) {
_E("Failed to operate usb connection: %d", ret);
- else
- old = status;
+ return ret;
+ }
+
+ old_status = new_status;
return ret;
}