From: shingil.kang Date: Thu, 2 Jun 2016 06:44:03 +0000 (+0900) Subject: Add protocol to get the platform type of target. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad69a055bb6b19bfdae2e5aa9f9203c1fe72c45f;p=sdk%2Ftools%2Fsdb.git Add protocol to get the platform type of target. Change-Id: I65fb32665fb93be05d40ba9a2284202fbdb989b2 Signed-off-by: shingil.kang --- diff --git a/src/common_modules.h b/src/common_modules.h index c22b33a..b3e1c83 100644 --- a/src/common_modules.h +++ b/src/common_modules.h @@ -29,7 +29,6 @@ #include "linkedlist.h" #include "fdevent.h" -#include "sdb_usb.h" #include "fdevent.h" #define MAX_PAYLOAD_V1 (4*1024) @@ -105,6 +104,15 @@ typedef enum transport_type { //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; @@ -202,6 +210,8 @@ struct atransport int suspended; char host[20]; char *device_name; + + platform_type platform; }; diff --git a/src/sdb_usb.h b/src/sdb_usb.h index db62e72..cb02e65 100755 --- a/src/sdb_usb.h +++ b/src/sdb_usb.h @@ -4,6 +4,7 @@ #include +#include "common_modules.h" extern int g_only_detect_tizen_device; // should bo implements for each os type @@ -19,7 +20,7 @@ int sdb_usb_read(usb_handle *h, void *data, int len); int sdb_usb_close(usb_handle *h); void sdb_usb_kick(usb_handle *h); -int is_sdb_interface(int vendor_id, int usb_class, int usb_subclass, int usb_protocol); +platform_type get_platform_type(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(); diff --git a/src/sockets.c b/src/sockets.c index 90265d4..983ef18 100755 --- a/src/sockets.c +++ b/src/sockets.c @@ -831,6 +831,12 @@ sendfail: 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', }; @@ -1176,7 +1182,6 @@ static int handle_host_request(char *service, SDB_SOCKET* socket) sdb_write(socket->fd, "OKAY", 4); exit(0); } - return -1; } diff --git a/src/transport.c b/src/transport.c index 0224f91..e408eaa 100755 --- a/src/transport.c +++ b/src/transport.c @@ -1019,6 +1019,21 @@ const char *connection_state_name(TRANSPORT *t) 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)); diff --git a/src/transport.h b/src/transport.h index af3c119..b29b920 100755 --- a/src/transport.h +++ b/src/transport.h @@ -61,7 +61,7 @@ const char *connection_state_name(TRANSPORT *t); 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); +void register_usb_transport(usb_handle *usb, const char *serial, platform_type platform); 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(); diff --git a/src/transport_local.c b/src/transport_local.c index 5e4502c..2100533 100755 --- a/src/transport_local.c +++ b/src/transport_local.c @@ -254,6 +254,7 @@ void register_socket_transport(int s, const char *serial, char* host, int port, t->sdb_port = port; t->suspended = 0; t->type = ttype; + t->platform = PLATFORM_TIZEN; //TODO REMOTE_DEVICE_CONNECT // t->remote_cnxn_socket = NULL; diff --git a/src/transport_usb.c b/src/transport_usb.c index 5491421..a89ed05 100755 --- a/src/transport_usb.c +++ b/src/transport_usb.c @@ -23,6 +23,7 @@ #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) @@ -98,7 +99,7 @@ static int get_connected_device_count(transport_type type) return cnt; } -void register_usb_transport(usb_handle *usb, const char *serial) +void register_usb_transport(usb_handle *usb, const char *serial, platform_type platform) { TRANSPORT *t = calloc(1, sizeof(TRANSPORT)); char device_name[256]; @@ -118,6 +119,7 @@ void register_usb_transport(usb_handle *usb, const char *serial) t->req = 0; t->res = 0; t->suspended = 0; + t->platform = platform; if(serial) { t->serial = strdup(serial); @@ -131,29 +133,27 @@ void register_usb_transport(usb_handle *usb, const char *serial) t->device_name = strdup(device_name); } -// 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) +/* 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) { /** * 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 1; + return PLATFORM_TIZEN; if (g_only_detect_tizen_device) { D("only detect tizen device !\n"); - return 0; + return PLATFORM_UNKNOWN; } else { if (usb_subclass == ADB_INTERFACE_SUBCLASS && usb_protocol == ADB_INTERFACE_PROTOCOL) - return 2; + return PLATFORM_ANDROID; } } - return 0; + return PLATFORM_UNKNOWN; } void close_usb_devices() diff --git a/src/usb_darwin.c b/src/usb_darwin.c index 20456ac..6dcef38 100755 --- a/src/usb_darwin.c +++ b/src/usb_darwin.c @@ -132,7 +132,7 @@ kern_return_t getUSBSerial(IOUSBDeviceInterface182 **dev, UInt8 string_id, char return kr; } -void register_usb(IOUSBDeviceInterface182 **dev, usb_handle *handle) { +void register_usb(IOUSBDeviceInterface182 **dev, usb_handle *handle, platform_type platform) { IOReturn ior; kern_return_t kr; UInt8 serialIndex; @@ -150,7 +150,7 @@ void register_usb(IOUSBDeviceInterface182 **dev, usb_handle *handle) { LOG_ERROR("couldn't get usb serial\n"); } - register_usb_transport(handle, serial); + register_usb_transport(handle, serial, platform); // Register for an interest notification of this device being removed. // Pass the reference to our private data as the refCon for the notification. @@ -173,12 +173,13 @@ UInt8 find_sdb_interface_by_looping_configuration(IOUSBDeviceInterface182 **dev, kern_return_t kr; UInt8 totalConfigNum = 0; UInt8 configNum; + platform_type platform; // find SDB interface in current configuration - ior = FindSDBInterface(dev, handle); + ior = FindSDBInterface(dev, handle, &platform); if (!ior) { LOG_DEBUG("found tizen device and register usb transport.........\n"); - register_usb(dev, handle); + register_usb(dev, handle, platform); return 0; } @@ -223,11 +224,11 @@ UInt8 find_sdb_interface_by_looping_configuration(IOUSBDeviceInterface182 **dev, } else { LOG_DEBUG("set configuration to %d\n", sdb_configuration); // find SDB interface in configuration - if (FindSDBInterface(dev, handle) != 0) + if (FindSDBInterface(dev, handle, &platform) != 0) continue; else { LOG_DEBUG("found SDB interface in configuration: %d\n", sdb_configuration); - register_usb(dev, handle); + register_usb(dev, handle, platform); kr = (*dev)->USBDeviceClose(dev); return 0; } @@ -239,7 +240,7 @@ UInt8 find_sdb_interface_by_looping_configuration(IOUSBDeviceInterface182 **dev, } IOReturn FindSDBInterface(IOUSBDeviceInterface **device, - usb_handle* handle) { + usb_handle* handle, platform_type* platform_type_ptr) { IOReturn kr = -1; IOUSBFindInterfaceRequest request; io_iterator_t iterator; @@ -307,10 +308,13 @@ IOReturn FindSDBInterface(IOUSBDeviceInterface **device, interfaceClass, interfaceSubClass, intfProtocol); //Check if interface is sdb interface - if (!is_sdb_interface(VENDOR_ID_SAMSUNG, interfaceClass, interfaceSubClass, intfProtocol)) { + platform_type platform_type_temp = get_platform_type(VENDOR_ID_SAMSUNG, interfaceClass, interfaceSubClass, intfProtocol); + if (platform_type_temp == PLATFORM_UNKNOWN) { LOG_DEBUG("it is not sdb interface\n"); (*interface)->Release(interface); continue; + } else { + *platform_type_ptr = platform_type_temp; } // get number of end points diff --git a/src/usb_linux.c b/src/usb_linux.c index f6ea217..5324c06 100644 --- a/src/usb_linux.c +++ b/src/usb_linux.c @@ -185,11 +185,11 @@ int register_device(const char* node, const char* serial) { struct usb_interface_descriptor* usb_interface = (struct usb_interface_descriptor *) desc_current_ptr; - int device_type; - if ((device_type = is_sdb_interface(usb_dev->idVendor, - usb_interface->bInterfaceClass, - usb_interface->bInterfaceSubClass, - usb_interface->bInterfaceProtocol)) + platform_type platform= get_platform_type(usb_dev->idVendor, + usb_interface->bInterfaceClass, + usb_interface->bInterfaceSubClass, + usb_interface->bInterfaceProtocol); + if ((platform != PLATFORM_UNKNOWN) && (USB_DT_INTERFACE_SIZE == bLength && USB_DT_INTERFACE == bType && 2 == usb_interface->bNumEndpoints)) { @@ -205,7 +205,7 @@ int register_device(const char* node, const char* serial) { unsigned char endpoint_out; unsigned char interface = usb_interface->bInterfaceNumber; - if(device_type == 2) { + if(platform == PLATFORM_ANDROID) { int bConfigurationValue = 2; int n = ioctl(fd, USBDEVFS_SETCONFIGURATION, &bConfigurationValue); @@ -276,7 +276,7 @@ int register_device(const char* node, const char* serial) { 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); + register_usb_transport(usb, usb_serial, platform); sdb_mutex_unlock(&usb_lock, "usb register unlocked"); } desc_current_ptr += endpoint2->bLength; diff --git a/src/usb_windows.c b/src/usb_windows.c index b673165..abff3c0 100644 --- a/src/usb_windows.c +++ b/src/usb_windows.c @@ -71,7 +71,7 @@ struct usb_handle { UCHAR end_point[2]; unsigned int zero_mask; }; -usb_handle *usb_open(const char *device_path); +usb_handle *usb_open(const char *device_path, platform_type *platform); 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); @@ -161,7 +161,7 @@ int is_device_registered(const char *node_path) return r; } -usb_handle *usb_open(const char *device_path) { +usb_handle *usb_open(const char *device_path, platform_type *platform_type_ptr) { // 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)); @@ -208,9 +208,11 @@ usb_handle *usb_open(const char *device_path) { return NULL; } - if (!is_sdb_interface(usb_device_descriptor.idVendor, usb_interface_descriptor.bInterfaceClass, usb_interface_descriptor.bInterfaceSubClass, - usb_interface_descriptor.bInterfaceProtocol)) { + 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) { return NULL; + } else { + *platform_type_ptr = platform_type_temp; } UCHAR endpoint_index = 0; @@ -371,13 +373,14 @@ int usb_find_devices(GUID deviceClassID) { SAFE_FREE(detailData); if (!is_device_registered(devicePath)) { - struct usb_handle *hnd = usb_open(devicePath); + platform_type platform; + struct usb_handle *hnd = usb_open(devicePath, &platform); 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); + register_usb_transport(hnd, serial, platform); } else { LOG_DEBUG("fail to register usb\n"); win_usb_close(hnd);