#include <string.h>
#include <stdlib.h>
#include <sys/queue.h>
+#include <system_info.h>
#include "usb_host.h"
#include "uref.h"
#include "usb_host_internal.h"
+static int usb_host_feature_enabled(void)
+{
+ int ret;
+ bool val;
+ static int enabled = -1;
+
+ if (enabled >= 0)
+ return enabled;
+
+ ret = system_info_get_platform_bool("http://tizen.org/feature/usb.host", &val);
+ if (ret == SYSTEM_INFO_ERROR_NONE && val)
+ enabled = 1;
+ else {
+ _E("USB Host API is not supported");
+ enabled = 0;
+ }
+
+ return enabled;
+}
+
static inline struct usb_host_device_s *to_usb_host_device(struct uref *_uref)
{
return container_of(_uref, struct usb_host_device_s, ref);
int count = 10;
struct usb_host_context_s *_ctx;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ctx) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_destroy(usb_host_context_h context)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!context) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
{
int ret = USB_HOST_ERROR_OUT_OF_MEMORY;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_close(usb_host_device_h dev)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
libusb_device_handle *ldev_handle;
libusb_device *ldev;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ctx || !device_handle) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_bus_number(usb_host_device_h dev, int *bus_number)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !bus_number) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_address(usb_host_device_h dev, int *device_address)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
if (!dev || !device_address) {
_E("Invalid parameter was passed");
int ret = 0;
int i;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (port_numbers_len <= 0) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
struct usb_host_device_s *rdevice;
struct usb_host_device_s **list;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!context || !devs || !length) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_ref_device(usb_host_device_h dev)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_unref_device(usb_host_device_h dev)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int i = 0;
int ret;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!devs) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
struct libusb_config_descriptor *lcfg_desc;
struct usb_host_config_s *cfg;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !config) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int ret;
struct usb_host_device_s *dev;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!configuration) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int interface_number;
struct libusb_device_handle *lusb_dev_handle;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface) {
_E("Invalid parameter");
return USB_HOST_ERROR_INVALID_PARAMETER;
int interface_number;
struct libusb_device_handle *lusb_dev_handle;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_bcd_usb(usb_host_device_h dev, int *bcd_usb)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !bcd_usb) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_class(usb_host_device_h dev, int *device_class)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !device_class) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_sub_class(usb_host_device_h dev, int *subclass)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !subclass) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_protocol(usb_host_device_h dev, int *protocol)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !protocol) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_max_packet_size_0(usb_host_device_h dev, int *max_packet_size)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !max_packet_size) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_id_vendor(usb_host_device_h dev, int *vendor_id)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !vendor_id) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_id_product(usb_host_device_h dev, int *product_id)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !product_id) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_bcd_device(usb_host_device_h dev, int *device_bcd)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !device_bcd) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_num_configurations(usb_host_device_h dev, int *num_configurations)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !num_configurations) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_is_device_opened(usb_host_device_h dev, bool *is_opened)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !is_opened) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_manufacturer_str(usb_host_device_h dev, int *length, unsigned char *data)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !data) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_product_str(usb_host_device_h dev, int *length, unsigned char *data)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !data) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_serial_number_str(usb_host_device_h dev, int *length, unsigned char *data)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !data) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_config_get_num_interfaces(usb_host_config_h config, int *num_interfaces)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!config || !num_interfaces) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_config_is_self_powered(usb_host_config_h config, bool *self_powered)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!config || !self_powered) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_config_support_remote_wakeup(usb_host_config_h config, bool *remote_wakeup)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!config || !remote_wakeup) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
{
int speed;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!config || !max_power) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_config_str(usb_host_config_h config, int *length, unsigned char *data)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!config || !data) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_interface_get_number(usb_host_interface_h interface, int *number)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface || !number) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_interface_get_num_endpoints(usb_host_interface_h interface, int *num_endpoints)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface || !num_endpoints) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_interface_get_str(usb_host_interface_h interface, int *length,
unsigned char *data)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface || !data) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_number(usb_host_endpoint_h ep, int *number)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !number) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_direction(usb_host_endpoint_h ep, int* direction)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !direction) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_transfer_type(usb_host_endpoint_h ep, int *transfer_type)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !transfer_type) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_synch_type(usb_host_endpoint_h ep, int *synch_type)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !synch_type) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_usage_type(usb_host_endpoint_h ep, int *usage_type)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !usage_type) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_max_packet_size(usb_host_endpoint_h ep, int *max_packet_size)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !max_packet_size) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_endpoint_get_interval(usb_host_endpoint_h ep, int *interval)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep || !interval) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
{
int i;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!config) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_interface_get_endpoint(usb_host_interface_h interface, int ep_index,
usb_host_endpoint_h *ep)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
if (!interface || !ep || ep_index >= interface->altsettings[interface->altsetting].num_endpoints) {
_E("Invalid parameter was passed");
int usb_host_interface_set_altsetting(usb_host_interface_h interface, int altsetting)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface || altsetting < 0 || altsetting >= interface->num_altsettings) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_config_get_interface(usb_host_config_h config, int interface_index, usb_host_interface_h *interface)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!interface || !config || interface_index < 0 || interface_index >= config->num_interfaces) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
int usb_host_device_get_config(usb_host_device_h dev, int config_index, usb_host_config_h *config)
{
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !config) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
{
int ret;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !data || !length) {
_E("Invalid parameter was passed");
return USB_HOST_ERROR_INVALID_PARAMETER;
{
int ret;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!dev || !data || !transfered) {
_E("Invalid parameter");
return USB_HOST_ERROR_INVALID_PARAMETER;
{
int type;
+ if (!usb_host_feature_enabled())
+ return USB_HOST_ERROR_NOT_SUPPORTED;
+
if (!ep) {
_E("Inavlid parameter");
return USB_HOST_ERROR_INVALID_PARAMETER;