Add protocol to get the platform type of target.
authorshingil.kang <shingil.kang@samsung.com>
Thu, 2 Jun 2016 06:44:03 +0000 (15:44 +0900)
committershingil.kang <shingil.kang@samsung.com>
Thu, 2 Jun 2016 06:44:03 +0000 (15:44 +0900)
Change-Id: I65fb32665fb93be05d40ba9a2284202fbdb989b2
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
src/common_modules.h
src/sdb_usb.h
src/sockets.c
src/transport.c
src/transport.h
src/transport_local.c
src/transport_usb.c
src/usb_darwin.c
src/usb_linux.c
src/usb_windows.c

index c22b33aa8f2d70b99de48ea783b8e70253a30e44..b3e1c837a4ad033e8a3466e3086895ce8b650bb9 100644 (file)
@@ -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;
 };
 
 
index db62e725760f93cde5055978599a65d09e107ab4..cb02e652b73761c8605a6f7339886222fb5d0283 100755 (executable)
@@ -4,6 +4,7 @@
 
 
 #include <limits.h>
+#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();
index 90265d43583a0030c9fe2fce30d02385e5603356..983ef18e9693a2446c98ecae3f32048aae5196b1 100755 (executable)
@@ -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;
 }
 
index 0224f912cbefd041652c6224b55e80903e2213f2..e408eaa9fabb4fbdf65440a99e2ed4adcff0e1d7 100755 (executable)
@@ -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));
index af3c11987bbf08455ff959b70109a529ce004f59..b29b920693765c9459a61d9b9ea04e02e263d957 100755 (executable)
@@ -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();
index 5e4502c0eea4f830eefa4eea1b3efc1f65440804..2100533b65ffd90b7d5fba8eacbcdc66266a2e40 100755 (executable)
@@ -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;
 
index 5491421f64104ec38433223052cbd0eb6c04bf0b..a89ed052b32960e3224433b5209b3ec97e005e4b 100755 (executable)
@@ -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()
index 20456acd61604e29e1dcff8044b7a00159e3bb90..6dcef3822762601ebc735d20a87e877573859ee5 100755 (executable)
@@ -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
index f6ea2172bf980ba2523941bb4bdbffe742d476ef..5324c0652b690a736d64c477fd894b24100a55b9 100644 (file)
@@ -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;
index b6731657ec11bc031d7aa1627d0398185d0ab4f2..abff3c0effb1009b1ed61ec0ba06f75d376aff9a 100644 (file)
@@ -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);