interface: Choose interface after thor handshake 31/223031/12
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 17 Mar 2020 04:55:56 +0000 (13:55 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 18 Mar 2020 09:31:54 +0000 (18:31 +0900)
To prevent that interface blocks other connection before host actually
start transferring, connected interface is selected after handshake is
done.

Change-Id: I6b8587898b4dae83ffeb9e4330d379fa723e98d1
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/interface.c
src/main.c
src/thor.c
src/thor.h

index 69d2084..027a3fc 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/queue.h>
 
 #include "interface.h"
+#include "thor.h"
 
 struct tfm_interface_context {
        struct tfm_interface *connected;
@@ -96,6 +97,19 @@ static void *connect_thread_main(void *ptr)
                return NULL;
        }
 
+       fprintf(stdout, "interface %s is ready.\n", intf->name);
+
+       /*
+        * Each interface can handshake at the same time, but only one
+        * interface is used for flash to prevent data corruption.
+        */
+       ret = thor_handshake(intf);
+       if (ret < 0) {
+               fprintf(stderr, "failed to handshake: %s\n", intf->name);
+               intf->ops->disconnect(intf);
+               return NULL;
+       }
+
        pthread_mutex_lock(&ictx->mutex);
        if (ictx->connected) {
                pthread_mutex_unlock(&ictx->mutex);
index 0281c30..7737e5e 100644 (file)
@@ -100,12 +100,6 @@ int _main(int argc, char *argv[])
                goto out_dfuexit;
        }
 
-       ret = thor_setup(intf);
-       if (ret < 0) {
-               ret = -1;
-               goto out_disconn;
-       }
-
        ret = thor_process(intf, dfu);
        if (ret < 0) {
                ret = -1;
index 6cb6984..ea8918e 100644 (file)
@@ -319,7 +319,7 @@ static int thor_do_request(struct thor_context *tctx)
        return ret;
 }
 
-static int thor_handshake(struct tfm_interface *intf)
+int thor_handshake(struct tfm_interface *intf)
 {
        char buf[5];
        ssize_t n;
@@ -370,13 +370,3 @@ int thor_process(struct tfm_interface *intf, struct dfu_context *dfu)
 
        return 0;
 }
-
-int thor_setup(struct tfm_interface *intf)
-{
-       if (!intf) {
-               fprintf(stderr, "Invalid connection\n");
-               return -EINVAL;
-       }
-
-       return thor_handshake(intf);
-}
index 7a88006..c24fcc5 100644 (file)
@@ -20,6 +20,6 @@
 #include "dfu.h"
 #include "interface.h"
 
-int thor_setup(struct tfm_interface *intf);
+int thor_handshake(struct tfm_interface *intf);
 int thor_process(struct tfm_interface *intf, struct dfu_context *dfu);
 #endif