Ejemplo n.º 1
0
/** Reads and processes an attached device's Device Descriptor, to determine compatibility
 *
 *  This routine checks to ensure that the attached device's VID and PID matches Google's for Android devices.
 *
 *  \return An error code from the \ref AndroidHost_GetDeviceDescriptorDataCodes_t enum.
 */
uint8_t ProcessDeviceDescriptor(void)
{
	USB_Descriptor_Device_t DeviceDescriptor;

	/* Send the request to retrieve the device descriptor */
	if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
	  return DevControlError;

	/* Validate returned data - ensure the returned data is a device descriptor */
	if (DeviceDescriptor.Header.Type != DTYPE_Device)
	  return InvalidDeviceDataReturned;

	/* Validate returned device Vendor ID against the Android ADK spec values */
/*
 * EA: Second time XOOM is connected it announces itself with VID=MOTOROLA (0x22b8)
 *     and not VID=GOOGLE (0x18D1).
 *     If IncorrectAndroidDevice is returned below it will always fail
 *     the second time XOOM is connected without a restart.
 */
	if (DeviceDescriptor.VendorID != ANDROID_VENDOR_ID)
	{
	  //return IncorrectAndroidDevice;
	  return NonAccessoryModeAndroidDevice;
	}


	/* Check the product ID to determine if the Android device is in accessory mode */
	if ((DeviceDescriptor.ProductID != ANDROID_ACCESSORY_PRODUCT_ID) &&
	    (DeviceDescriptor.ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID))
	{
		return NonAccessoryModeAndroidDevice;
	}

	return AccessoryModeAndroidDevice;
}
/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
 *  enumerated by the host and is now ready to be used by the application.
 */
void EVENT_USB_Host_DeviceEnumerationComplete(void)
{
	LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);

	USB_Descriptor_Device_t DeviceDescriptor;

	if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
	{
		puts_P(PSTR("Error Retrieving Device Descriptor.\r\n"));
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		return;
	}

	bool NeedModeSwitch;
	if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch)))
	{
		puts_P(PSTR("Not an Android device.\r\n"));
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		return;
	}

	if (NeedModeSwitch)
	{
		puts_P(PSTR("Not in Accessory mode, switching...\r\n"));
		AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface);
		return;
	}

	uint16_t ConfigDescriptorSize;
	uint8_t  ConfigDescriptorData[512];

	if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
	                                       sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
	{
		puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		return;
	}

	if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface,
	                            ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError)
	{
		puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n"));
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		return;
	}

	if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
	{
		puts_P(PSTR("Error Setting Device Configuration.\r\n"));
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		return;
	}

	puts_P(PSTR("Android Device Enumerated.\r\n"));
	LEDs_SetAllLEDs(LEDMASK_USB_READY);
}
/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
 *  enumerated by the host and is now ready to be used by the application.
 */
void EVENT_USB_Host_DeviceEnumerationComplete(void)
{
	USB_Descriptor_Device_t DeviceDescriptor;
	uint16_t ConfigDescriptorSize;
	uint8_t  ConfigDescriptorData[512];

	printf(PSTR("\r\n* Configuring *"));

	if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
	{
		printf(PSTR("\r\nERR: Dev Desc"));
		//RGB_SetColour(RGB_ALIAS_Error);
		//return;
	}

	if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
	                                       sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
	{
		printf(PSTR("\r\nERR: Config Desc"));
	//	RGB_SetColour(RGB_ALIAS_Error);
	//	return;
	}

	BluetoothAdapter_ConfigurePipes(&DeviceDescriptor, ConfigDescriptorSize, ConfigDescriptorData);
	

	if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
	{
		printf(PSTR("\r\nERR: Set Config"));
//		RGB_SetColour(RGB_ALIAS_Error);
		return;
	}
	
	if (!(BluetoothAdapter_PostConfiguration()))
	{
		printf(PSTR("\r\nERR: Post Config"));
//		RGB_SetColour(RGB_ALIAS_Error);
		return;
	}
	
	printf(PSTR("\r\n* System Ready *\n"));
	
	
//	RGB_SetColour(RGB_ALIAS_Ready);
}
Ejemplo n.º 4
0
/** Reads and processes an attached device's Device Descriptor, to determine compatibility
 *
 *  This routine checks to ensure that the attached device's VID and PID matches Google's for Android devices.
 *
 *  \return An error code from the \ref AndroidHost_GetDeviceDescriptorDataCodes_t enum.
 */
uint8_t ProcessDeviceDescriptor(void)
{
	USB_Descriptor_Device_t DeviceDescriptor;

	/* Send the request to retrieve the device descriptor */
	if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
	  return DevControlError;

	/* Validate returned data - ensure the returned data is a device descriptor */
	if (DeviceDescriptor.Header.Type != DTYPE_Device)
	  return InvalidDeviceDataReturned;

	/* Check the product ID to determine if the Android device is in accessory mode */
	if ((DeviceDescriptor.ProductID != ANDROID_ACCESSORY_PRODUCT_ID) &&
	    (DeviceDescriptor.ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID))
	{
		return NonAccessoryModeAndroidDevice;
	}

	return AccessoryModeAndroidDevice;
}
Ejemplo n.º 5
0
uint8_t ProcessDeviceDescriptor(void)
{
	USB_Descriptor_Device_t DeviceDescriptor;

	/* Send the request to retrieve the device descriptor */
	if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
	  return ControlErrorDuringDeviceRead;
	  
	/* Validate returned data - ensure the returned data is a device descriptor */
	if (DeviceDescriptor.Header.Type != DTYPE_Device)
	  return InvalidDeviceDataReturned;
	
	/* Validate returned device Class, SubClass and Protocol values against the Bluetooth spec values */
	if ((DeviceDescriptor.Class    != BLUETOOTH_DEVICE_CLASS)    ||
	    (DeviceDescriptor.SubClass != BLUETOOTH_DEVICE_SUBCLASS) ||
	    (DeviceDescriptor.Protocol != BLUETOOTH_DEVICE_PROTOCOL))
	{
		return IncorrectDevice;
	}
	
	return SuccessfulDeviceRead;
}
Ejemplo n.º 6
0
/** Reads and processes an attached device's Device Descriptor, to determine compatibility
 *
 *  This routine checks to ensure that the attached device's VID and PID matches Google's for Android devices.
 *
 *  \return An error code from the \ref BluetoothHost_GetDeviceDescriptorDataCodes_t enum.
 */
uint8_t ProcessDeviceDescriptor(void)
{
	USB_Descriptor_Device_t DeviceDescriptor;

	/* Send the request to retrieve the device descriptor */
	if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
	  return DevControlError;

	/* Validate returned data - ensure the returned data is a device descriptor */
	if (DeviceDescriptor.Header.Type != DTYPE_Device)
	  return InvalidDeviceDataReturned;

	/* Validate returned device Class, SubClass and Protocol values against the Bluetooth spec values */
	if (DeviceDescriptor.VendorID != ANDROID_VENDOR_ID)
		return IncorrectAndroidDevice;

	if ((DeviceDescriptor.ProductID != ANDROID_ACCESSORY_PRODUCT_ID) ||
	    (DeviceDescriptor.ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID))
	{
		return NonAccessoryModeAndroidDevice;
	}

	return AccessoryModeAndroidDevice;
}