handover: Add fallback code for p2p services
authorOlivier Guiter <olivier.guiter@linux.intel.com>
Tue, 11 Sep 2012 13:44:20 +0000 (15:44 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 13 Sep 2012 13:19:39 +0000 (15:19 +0200)
This code would allow non-strict implementations of p2p (e.g. Android 4
uses SNEP for handover, so first we try to connect to the Handover service,
and, if it fails, fallback to SNEP service) services.

plugins/handover.c
plugins/npp.c
plugins/p2p.c
plugins/p2p.h
plugins/snep.c

index a53a958..c8ba895 100644 (file)
@@ -468,6 +468,7 @@ static int handover_push(int client_fd,
 struct near_p2p_driver handover_driver = {
        .name = "Handover",
        .service_name = NEAR_DEVICE_SN_HANDOVER,
+       .fallback_service_name = NEAR_DEVICE_SN_SNEP,
        .read = handover_read,
        .push = handover_push,
        .close = handover_close,
index 9f40291..33136ba 100644 (file)
@@ -144,6 +144,7 @@ static near_bool_t npp_read(int client_fd,
 struct near_p2p_driver npp_driver = {
        .name = "NPP",
        .service_name = NEAR_DEVICE_SN_NPP,
+       .fallback_service_name = NULL,
        .read = npp_read,
 };
 
index 7c73bab..b4943e5 100644 (file)
@@ -332,12 +332,18 @@ static int p2p_push(uint32_t adapter_idx, uint32_t target_idx,
 
                if (strcmp(driver->service_name, service_name) != 0)
                        continue;
-
+               /*
+                * Because of Android's implementation, we have use SNEP for
+                * Handover. So, on Handover session, we try to connect to
+                * the handover service and fallback to SNEP on connect fail.
+                */
                fd = p2p_connect(adapter_idx, target_idx, ndef, cb, driver);
                if (fd < 0)
-                       return fd;
-
-               return driver->push(fd, adapter_idx, target_idx, ndef, cb);
+                       return  p2p_push(adapter_idx, target_idx, ndef,
+                               (char *) driver->fallback_service_name, cb);
+               else
+                       return driver->push(fd, adapter_idx, target_idx,
+                                       ndef, cb);
        }
 
        return -1;
index 5b74fb6..033ecd2 100644 (file)
@@ -26,6 +26,7 @@
 struct near_p2p_driver {
        const char *name;
        const char *service_name;
+       const char *fallback_service_name;
        near_bool_t (*read)(int client_fd,
                                uint32_t adapter_idx, uint32_t target_idx,
                                near_device_io_cb cb);
index 4a2367a..e181f21 100644 (file)
@@ -521,6 +521,7 @@ error:
 struct near_p2p_driver snep_driver = {
        .name = "SNEP",
        .service_name = NEAR_DEVICE_SN_SNEP,
+       .fallback_service_name = NEAR_DEVICE_SN_NPP,
        .read = snep_read,
        .push = snep_push,
        .close = snep_close,