Exemplo n.º 1
0
static DBusHandlerResult devicelock_unlocked_cb(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
  DBusHandlerResult   result    = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  const char         *interface = dbus_message_get_interface(msg);
  const char         *member    = dbus_message_get_member(msg);
  const char         *object    = dbus_message_get_path(msg);
  int                 type      = dbus_message_get_type(msg);
  int ret=0, ret1 = 0;

  (void) user_data;

  // sanity checks
  if( !interface || !member || !object ) goto cleanup;
  if( type != DBUS_MESSAGE_TYPE_SIGNAL ) goto cleanup;
  if( strcmp(interface, DEVICELOCK_REQUEST_IF) ) goto cleanup;
  if( strcmp(object, DEVICELOCK_REQUEST_PATH) )  goto cleanup;

  // handle known signals
  else if( !strcmp(member, "stateChanged") )
  {
        dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &ret1, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
  	log_debug("Devicelock state changed. New state = %d\n", ret);
  	if(ret == 0 && get_usb_connection_state() == 1 )
  	{	
         	if(!strcmp(get_usb_mode(), MODE_UNDEFINED) || !strcmp(get_usb_mode(), MODE_CHARGING))
			set_usb_connected_state();
  	}
  }
  result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

cleanup:
  return result;
}
Exemplo n.º 2
0
/*
 *if otg cable is connected , id state =0
 *as host turn on vbus, in this case shouldn't call this handler
 */
int usb_get_id_state(void)
{
#if defined(CONFIG_MACH_SPX35EA)
	/**EA board H/W doesn't support OTG**/
	return 1;
#else
#ifdef CONFIG_USB_EXTERNAL_DETECT
	int value, mode;
	mode = get_usb_mode();
	if (mode == NOTIFY_HOST_MODE)
		value = 0;
	else
		value = 1;
#else
#ifdef CONFIG_MFD_SM5504
	int value = 0;
	value = !sm5504_get_otg_status();
	return value;
#else
	int value;
	value = gpio_get_value(gpio_id);
#endif
#endif
	return !!value;
#endif
}
Exemplo n.º 3
0
static void _wake_up_enable(struct fsl_usb2_platform_data *pdata, bool enable)
{
	if (get_usb_mode(pdata) == FSL_USB_DR_DEVICE) {
		if (enable) {
			USBCTRL |= (UCTRL_OWIE | UCTRL_VBUS_WKUP_EN);
			USB_PHY_CTR_FUNC |= USB_UTMI_PHYCTRL_CONF2;
		} else {
			USBCTRL &= ~UCTRL_OWIE;
			USBCTRL &= ~UCTRL_VBUS_WKUP_EN;
			USB_PHY_CTR_FUNC &= ~USB_UTMI_PHYCTRL_CONF2;
		}
	}
}
Exemplo n.º 4
0
static void _wake_up_enable(struct fsl_usb2_platform_data *pdata, bool enable)
{
	if (get_usb_mode(pdata) == FSL_USB_DR_DEVICE) {
		if (enable) {
			USBCTRL |= UCTRL_OWIE;
			USBCTRL_HOST2 |= UCTRL_H2OVBWK_EN;
			USB_PHY_CTR_FUNC |= USB_UTMI_PHYCTRL_CONF2;
		} else {
			USBCTRL &= ~UCTRL_OWIE;
			USBCTRL_HOST2 &= ~UCTRL_H2OVBWK_EN;
			USB_PHY_CTR_FUNC &= ~USB_UTMI_PHYCTRL_CONF2;
		}
	} else {
		if (enable) {
			USBCTRL |= UCTRL_OWIE;
			USBCTRL_HOST2 |= (1 << 5);
		} else {
			USBCTRL &= ~UCTRL_OWIE;
			USBCTRL_HOST2 &= ~(1 << 5);
		}
	}
}
Exemplo n.º 5
0
static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
  DBusHandlerResult   status    = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  DBusMessage        *reply     = 0;
  const char         *interface = dbus_message_get_interface(msg);
  const char         *member    = dbus_message_get_member(msg);
  const char         *object    = dbus_message_get_path(msg);
  int                 type      = dbus_message_get_type(msg);
  const char *xml = 	"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" "
    		    	"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
    		    	"<node name=\"/com/meego/usb_moded\">\n"
    		    	"  <interface name=\"com.meego.usb_moded\">\n"
    		    	"    <method name=\"mode_request\">\n"
    	            	"      <arg name=\"mode\" type=\"s\" direction=\"out\"/>\n"
    	            	"    </method>\n"
    	            	"    <method name=\"set_mode\">\n"
    		    	"      <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"
    		    	"    </method>\n"
    		    	"    <signal name=\"sig_usb_state_ind\">\n"
    			"      <arg name=\"mode\" type=\"s\"/>\n"
    			"    </signal>\n"
    			"  </interface>\n"
    			"	</node>\n";

  (void)user_data;

  if(!interface || !member || !object) goto EXIT;

  if( type == DBUS_MESSAGE_TYPE_METHOD_CALL && !strcmp(interface, USB_MODE_INTERFACE) && !strcmp(object, USB_MODE_OBJECT))
  {
  	status = DBUS_HANDLER_RESULT_HANDLED;
  	
    	if(!strcmp(member, USB_MODE_STATE_REQUEST))
    	{
		const char *mode = get_usb_mode();

      		if((reply = dbus_message_new_method_return(msg)))
        		dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
    	}
    	else if(!strcmp(member, USB_MODE_STATE_SET))
    	{
      		char *use = 0;
      		DBusError   err = DBUS_ERROR_INIT;

      		if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID))
        		reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
		else
		{
				/* check if usb is connected, since it makes no sense to change mode if it isn't */
				if(!get_usb_connection_state())
				{
					log_warning("USB not connected, not changing mode!\n");
					goto error_reply;
				}
				/* check if the mode exists */
				if(valid_mode(use))
					goto error_reply;
				/* do not change mode if the mode requested is the one already set */
				if(strcmp(use, get_usb_mode()) != 0)
					set_usb_mode(use);
      				if((reply = dbus_message_new_method_return(msg)))
			        	dbus_message_append_args (reply, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID);
				else
error_reply:
       					reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
		}
		dbus_error_free(&err);
        }
	else if(!strcmp(member, USB_MODE_CONFIG_SET))
	{
	  	char *config = 0;
      		DBusError   err = DBUS_ERROR_INIT;

      		if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
        		reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
		else
		{
			/* error checking is done when setting configuration */
			if(!set_mode_setting(config))
			{
 				if((reply = dbus_message_new_method_return(msg)))
			       	dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
			}
			else
       				reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
		}
		dbus_error_free(&err);	
	}
	else if(!strcmp(member, USB_MODE_NETWORK_SET))
	{
	  	char *config = 0, *setting = 0;
      		DBusError   err = DBUS_ERROR_INIT;

      		if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID))
        		reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
		else
		{
			/* error checking is done when setting configuration */
			if(!set_network_setting(config, setting))
			{
 				if((reply = dbus_message_new_method_return(msg)))
			       	dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID);
				usb_network_update();
			}
			else
       				reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
		}
		dbus_error_free(&err);	
	}
	else if(!strcmp(member, USB_MODE_NETWORK_GET))
	{
		char *config = 0;
		const char *setting = 0;
		DBusError   err = DBUS_ERROR_INIT;

		if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
		{
			reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
		}
		else
		{
			setting = get_network_setting(config);
			if(setting)
			{
				if((reply = dbus_message_new_method_return(msg)))
				dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID);
				free((void *)setting);
			}
			else
				reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
		}
	}
	else if(!strcmp(member, USB_MODE_CONFIG_GET))
	{
		const char *config = get_mode_setting();
		
      		if((reply = dbus_message_new_method_return(msg)))
        		dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
		free((void *)config);
	}
	else if(!strcmp(member, USB_MODE_LIST))
	{
		 gchar *mode_list = get_mode_list();

                if((reply = dbus_message_new_method_return(msg)))
                        dbus_message_append_args (reply, DBUS_TYPE_STRING, (const char *) &mode_list, DBUS_TYPE_INVALID);
		g_free(mode_list);
	}
	else if(!strcmp(member, USB_MODE_RESCUE_OFF))
	{
		rescue_mode = FALSE;
		log_debug("Rescue mode off\n ");
		reply = dbus_message_new_method_return(msg);
	}
  	else
    	{ 
        	/*unknown methods are handled here */
      		reply = dbus_message_new_error(msg, DBUS_ERROR_UNKNOWN_METHOD, member);
    	}

    	if( !reply )
    	{
      		reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, member);
    	}
  }
  else if( type == DBUS_MESSAGE_TYPE_METHOD_CALL && !strcmp(interface, "org.freedesktop.DBus.Introspectable") &&
           !strcmp(object, USB_MODE_OBJECT) && !strcmp(member, "Introspect"))
  {
  	status = DBUS_HANDLER_RESULT_HANDLED;

      	if((reply = dbus_message_new_method_return(msg)))
               dbus_message_append_args (reply, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID);
  }


EXIT:

  if(reply)
  {
  	if( !dbus_message_get_no_reply(msg) )
    	{	
      		if( !dbus_connection_send(connection, reply, 0) )
        		log_debug("Failed sending reply. Out Of Memory!\n");
      	}
    	dbus_message_unref(reply);
  }

  return status;
}