#include "linkedlist.h"
#include "fdevent.h"
+#include "sdb_usb.h"
#include "fdevent.h"
#define MAX_PAYLOAD_V1 (4*1024)
//kTransportRemoteDevCon
} transport_type;
-typedef enum platform_type {
- PLATFORM_UNKNOWN,
- PLATFORM_TIZEN,
- PLATFORM_ANDROID,
-} platform_type;
-
-#define PLATFORM_STR_UNKNOWN "unknown"
-#define PLATFORM_STR_TIZEN "tizen"
-#define PLATFORM_STR_ANDROID "android"
struct transport {
LIST_NODE* node;
int suspended;
char host[20];
char *device_name;
-
- platform_type platform;
};
#include <limits.h>
-#include "common_modules.h"
extern int g_only_detect_tizen_device;
// should bo implements for each os type
int sdb_usb_close(usb_handle *h);
void sdb_usb_kick(usb_handle *h);
-platform_type get_platform_type(int vendor_id, int usb_class, int usb_subclass, int usb_protocol);
+int is_sdb_interface(int vendor_id, int usb_class, int usb_subclass, int usb_protocol);
int is_device_registered(const char *node_path);
void* usb_poll_thread(void* sleep_msec);
void kick_disconnected_devices();
sendokmsg(socket->fd, state);
return 0;
}
- else if(!strncmp(service, "get-platform", strlen("get-platform"))) {
- const char *platform_type = platform_type_name(t);
- sendokmsg(socket->fd, platform_type);
- return 0;
- }
-
#ifdef MAKE_DEBUG
else if(!strncmp(service, "send-packet", strlen("send-packet"))) {
char data[MAX_PAYLOAD_V1] = {'1', };
sdb_write(socket->fd, "OKAY", 4);
exit(0);
}
+
return -1;
}
return STATE_UNKNOWN;
}
-const char *platform_type_name(TRANSPORT *t)
-{
- if(t != NULL) {
- int state = t->platform;
-
- if(state == PLATFORM_TIZEN) {
- return PLATFORM_STR_TIZEN;
- }
- if(state == PLATFORM_ANDROID) {
- return PLATFORM_STR_ANDROID;
- }
- }
- return PLATFORM_STR_UNKNOWN;
-}
-
PACKET *get_apacket(void)
{
PACKET *p = malloc(sizeof(PACKET));
PACKET *get_apacket(void);
void put_apacket(void *p);
void register_socket_transport(int s, const char *serial, char* host, int port, transport_type ttype, const char *device_name);
-void register_usb_transport(usb_handle *usb, const char *serial, platform_type platform);
+void register_usb_transport(usb_handle *usb, const char *serial);
int register_device_con_transport(int s, const char *serial);
void send_cmd(unsigned arg0, unsigned arg1, unsigned cmd, char* data, TRANSPORT* t);
void close_usb_devices();
t->sdb_port = port;
t->suspended = 0;
t->type = ttype;
- t->platform = PLATFORM_TIZEN;
//TODO REMOTE_DEVICE_CONNECT
// t->remote_cnxn_socket = NULL;
#include "utils.h"
#define TRACE_TAG TRACE_TRANSPORT
#include "sdb_usb.h"
-#include "common_modules.h"
#include "transport.h"
static int remote_read(TRANSPORT* t, void* data, int len)
return cnt;
}
-void register_usb_transport(usb_handle *usb, const char *serial, platform_type platform)
+void register_usb_transport(usb_handle *usb, const char *serial)
{
TRANSPORT *t = calloc(1, sizeof(TRANSPORT));
char device_name[256];
t->req = 0;
t->res = 0;
t->suspended = 0;
- t->platform = platform;
if(serial) {
t->serial = strdup(serial);
t->device_name = strdup(device_name);
}
-/* get the platform type of usb device.
-* returns PLATFORM_TIZEN if tizen device, PLATFORM_ANDROID if android device.
-* otherwise, returns PLATFORM_UNKNOWN.
-*/
-platform_type get_platform_type(int vendor_id, int usb_class, int usb_subclass, int usb_protocol)
+// check if device is tizen or android device.
+// return 1 if tizen device, return 2 if android device
+int is_sdb_interface(int vendor_id, int usb_class, int usb_subclass, int usb_protocol)
{
/**
* TODO: find easy way to add usb devices vendors
*/
+// if (vendor_id == VENDOR_ID_SAMSUNG && usb_class == SDB_INTERFACE_CLASS && usb_subclass == SDB_INTERFACE_SUBCLASS
+// && usb_protocol == SDB_INTERFACE_PROTOCOL) {
+// return 1;
+// }
if ( usb_class == SDB_INTERFACE_CLASS ) {
if ( usb_subclass == SDB_INTERFACE_SUBCLASS && usb_protocol == SDB_INTERFACE_PROTOCOL )
- return PLATFORM_TIZEN;
+ return 1;
if (g_only_detect_tizen_device) {
D("only detect tizen device !\n");
- return PLATFORM_UNKNOWN;
+ return 0;
} else {
if (usb_subclass == ADB_INTERFACE_SUBCLASS && usb_protocol == ADB_INTERFACE_PROTOCOL)
- return PLATFORM_ANDROID;
+ return 2;
}
}
- return PLATFORM_UNKNOWN;
+ return 0;
}
void close_usb_devices()
return kr;
}
-void register_usb(IOUSBDeviceInterface182 **dev, usb_handle *handle, platform_type platform) {
+void register_usb(IOUSBDeviceInterface182 **dev, usb_handle *handle) {
IOReturn ior;
kern_return_t kr;
UInt8 serialIndex;
LOG_ERROR("couldn't get usb serial\n");
}
- register_usb_transport(handle, serial, platform);
+ register_usb_transport(handle, serial);
// Register for an interest notification of this device being removed.
// Pass the reference to our private data as the refCon for the notification.
kern_return_t kr;
UInt8 totalConfigNum = 0;
UInt8 configNum;
- platform_type platform;
// find SDB interface in current configuration
- ior = FindSDBInterface(dev, handle, &platform);
+ ior = FindSDBInterface(dev, handle);
if (!ior) {
LOG_DEBUG("found tizen device and register usb transport.........\n");
- register_usb(dev, handle, platform);
+ register_usb(dev, handle);
return 0;
}
} else {
LOG_DEBUG("set configuration to %d\n", sdb_configuration);
// find SDB interface in configuration
- if (FindSDBInterface(dev, handle, &platform) != 0)
+ if (FindSDBInterface(dev, handle) != 0)
continue;
else {
LOG_DEBUG("found SDB interface in configuration: %d\n", sdb_configuration);
- register_usb(dev, handle, platform);
+ register_usb(dev, handle);
kr = (*dev)->USBDeviceClose(dev);
return 0;
}
}
IOReturn FindSDBInterface(IOUSBDeviceInterface **device,
- usb_handle* handle, platform_type* platform_type_ptr) {
+ usb_handle* handle) {
IOReturn kr = -1;
IOUSBFindInterfaceRequest request;
io_iterator_t iterator;
interfaceClass, interfaceSubClass, intfProtocol);
//Check if interface is sdb interface
- platform_type platform_type_temp = get_platform_type(VENDOR_ID_SAMSUNG, interfaceClass, interfaceSubClass, intfProtocol);
- if (platform_type_temp == PLATFORM_UNKNOWN) {
+ if (!is_sdb_interface(VENDOR_ID_SAMSUNG, interfaceClass, interfaceSubClass, intfProtocol)) {
LOG_DEBUG("it is not sdb interface\n");
(*interface)->Release(interface);
continue;
- } else {
- *platform_type_ptr = platform_type_temp;
}
// get number of end points
struct usb_interface_descriptor* usb_interface =
(struct usb_interface_descriptor *) desc_current_ptr;
- platform_type platform= get_platform_type(usb_dev->idVendor,
- usb_interface->bInterfaceClass,
- usb_interface->bInterfaceSubClass,
- usb_interface->bInterfaceProtocol);
- if ((platform != PLATFORM_UNKNOWN)
+ int device_type;
+ if ((device_type = is_sdb_interface(usb_dev->idVendor,
+ usb_interface->bInterfaceClass,
+ usb_interface->bInterfaceSubClass,
+ usb_interface->bInterfaceProtocol))
&& (USB_DT_INTERFACE_SIZE == bLength
&& USB_DT_INTERFACE == bType
&& 2 == usb_interface->bNumEndpoints)) {
unsigned char endpoint_out;
unsigned char interface = usb_interface->bInterfaceNumber;
- if(platform == PLATFORM_ANDROID) {
+ if(device_type == 2) {
int bConfigurationValue = 2;
int n = ioctl(fd, USBDEVFS_SETCONFIGURATION,
&bConfigurationValue);
LOG_DEBUG("-register new device (in: %04x, out: %04x) from %s\n", usb->end_point[0], usb->end_point[1], node);
is_registered = 1;
- register_usb_transport(usb, usb_serial, platform);
+ register_usb_transport(usb, usb_serial);
sdb_mutex_unlock(&usb_lock, "usb register unlocked");
}
desc_current_ptr += endpoint2->bLength;
UCHAR end_point[2];
unsigned int zero_mask;
};
-usb_handle *usb_open(const char *device_path, platform_type *platform);
+usb_handle *usb_open(const char *device_path);
int win_usb_close(usb_handle *dev);
int usb_get_string_simple(usb_handle *dev, int index, char *buf, size_t buflen);
void *device_poll_thread(void* unused);
return r;
}
-usb_handle *usb_open(const char *device_path, platform_type *platform_type_ptr) {
+usb_handle *usb_open(const char *device_path) {
// Allocate storage for handles
usb_handle* usb = calloc(1, sizeof(usb_handle));
s_strncpy(usb->unique_node_path, device_path, sizeof(usb->unique_node_path));
return NULL;
}
- platform_type platform_type_temp = get_platform_type(usb_device_descriptor.idVendor, usb_interface_descriptor.bInterfaceClass, usb_interface_descriptor.bInterfaceSubClass, usb_interface_descriptor.bInterfaceProtocol);
- if (platform_type_temp == PLATFORM_UNKNOWN) {
+ if (!is_sdb_interface(usb_device_descriptor.idVendor, usb_interface_descriptor.bInterfaceClass, usb_interface_descriptor.bInterfaceSubClass,
+ usb_interface_descriptor.bInterfaceProtocol)) {
return NULL;
- } else {
- *platform_type_ptr = platform_type_temp;
}
UCHAR endpoint_index = 0;
SAFE_FREE(detailData);
if (!is_device_registered(devicePath)) {
- platform_type platform;
- struct usb_handle *hnd = usb_open(devicePath, &platform);
+ struct usb_handle *hnd = usb_open(devicePath);
if (hnd != NULL) {
char serial[MAX_SERIAL_NAME]={0,};
if (get_serial_number(hnd, serial, sizeof(serial)) > 0) {
LOG_DEBUG("register usb for: %s\n", serial);
if (register_device(hnd)) {
- register_usb_transport(hnd, serial, platform);
+ register_usb_transport(hnd, serial);
} else {
LOG_DEBUG("fail to register usb\n");
win_usb_close(hnd);