timeout_fix.patch 8.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
diff --git a/onboarding_tool/obtmain.c b/onboarding_tool/obtmain.c
index 65bf47fa..a4b066ad 100644
--- a/onboarding_tool/obtmain.c
+++ b/onboarding_tool/obtmain.c
@@ -301,7 +301,7 @@ unowned_device_cb(oc_uuid_t *uuid, oc_endpoint_t *eps, void *data)
     eps = eps->next;
   }
 
-  oc_do_get("/oic/d", ep, NULL, &get_device, LOW_QOS, unowned_devices);
+  oc_do_get("/oic/d", ep, NULL, &get_device, HIGH_QOS, unowned_devices);
 }
 
 static void
@@ -319,7 +319,7 @@ owned_device_cb(oc_uuid_t *uuid, oc_endpoint_t *eps, void *data)
     eps = eps->next;
   }
 
-  oc_do_get("/oic/d", ep, NULL, &get_device, LOW_QOS, owned_devices);
+  oc_do_get("/oic/d", ep, NULL, &get_device, HIGH_QOS, owned_devices);
 }
 
 static void
@@ -1270,9 +1270,9 @@ main(void)
 
   int init;
 
-  static const oc_handler_t handler = {.init = app_init,
-                                       .signal_event_loop = signal_event_loop,
-                                       .requests_entry = issue_requests };
+  static const oc_handler_t handler = { .init = app_init,
+                                        .signal_event_loop = signal_event_loop,
+                                        .requests_entry = issue_requests };
 
   oc_storage_config("./onboarding_tool_creds");
   oc_set_factory_presets_cb(factory_presets_cb, NULL);
diff --git a/security/oc_obt.c b/security/oc_obt.c
index b6c28499..ebcc8320 100644
--- a/security/oc_obt.c
+++ b/security/oc_obt.c
@@ -358,17 +358,9 @@ free_otm_state(oc_otm_ctx_t *o, int status, oc_obt_otm_t otm)
   oc_memb_free(&oc_otm_ctx_m, o);
 }
 
-oc_event_callback_retval_t
-oc_obt_otm_request_timeout_cb(void *data)
-{
-  free_otm_state(data, -1, 0);
-  return OC_EVENT_DONE;
-}
-
 void
 oc_obt_free_otm_ctx(oc_otm_ctx_t *ctx, int status, oc_obt_otm_t otm)
 {
-  oc_remove_delayed_callback(ctx, oc_obt_otm_request_timeout_cb);
   free_otm_state(ctx, status, otm);
 }
 
@@ -772,13 +764,6 @@ free_hard_reset_ctx(oc_hard_reset_ctx_t *ctx, int status)
   oc_memb_free(&oc_hard_reset_ctx_m, ctx);
 }
 
-static oc_event_callback_retval_t
-hard_reset_timeout_cb(void *data)
-{
-  free_hard_reset_ctx(data, -1);
-  return OC_EVENT_DONE;
-}
-
 static void
 hard_reset_cb(int status, void *data)
 {
@@ -787,7 +772,6 @@ hard_reset_cb(int status, void *data)
     return;
   }
   d->switch_dos = NULL;
-  oc_remove_delayed_callback(data, hard_reset_timeout_cb);
   free_hard_reset_ctx(data, status);
 }
 
@@ -821,7 +805,6 @@ oc_obt_device_hard_reset(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
   }
 
   oc_list_add(oc_hard_reset_ctx_l, d);
-  oc_set_delayed_callback(d, hard_reset_timeout_cb, OBT_CB_TIMEOUT);
 
   return 0;
 }
@@ -855,17 +838,9 @@ free_credprov_state(oc_credprov_ctx_t *p, int status)
   oc_memb_free(&oc_credprov_ctx_m, p);
 }
 
-static oc_event_callback_retval_t
-credprov_request_timeout_cb(void *data)
-{
-  free_credprov_state(data, -1);
-  return OC_EVENT_DONE;
-}
-
 static void
 free_credprov_ctx(oc_credprov_ctx_t *ctx, int status)
 {
-  oc_remove_delayed_callback(ctx, credprov_request_timeout_cb);
   free_credprov_state(ctx, status);
 }
 
@@ -1382,7 +1357,6 @@ oc_obt_provision_role_certificate(oc_role_t *roles, oc_uuid_t *uuid,
   }
 
   oc_list_add(oc_credprov_ctx_l, p);
-  oc_set_delayed_callback(p, credprov_request_timeout_cb, OBT_CB_TIMEOUT);
 
   return 0;
 }
@@ -1431,7 +1405,6 @@ oc_obt_provision_identity_certificate(oc_uuid_t *uuid, oc_obt_status_cb_t cb,
   }
 
   oc_list_add(oc_credprov_ctx_l, p);
-  oc_set_delayed_callback(p, credprov_request_timeout_cb, OBT_CB_TIMEOUT);
 
   return 0;
 }
@@ -1479,7 +1452,6 @@ oc_obt_provision_pairwise_credentials(oc_uuid_t *uuid1, oc_uuid_t *uuid2,
   }
 
   oc_list_add(oc_credprov_ctx_l, p);
-  oc_set_delayed_callback(p, credprov_request_timeout_cb, OBT_CB_TIMEOUT);
 
   return 0;
 }
@@ -1683,17 +1655,9 @@ free_acl2prov_state(oc_acl2prov_ctx_t *request, int status)
   oc_memb_free(&oc_acl2prov_m, request);
 }
 
-static oc_event_callback_retval_t
-acl2prov_timeout_cb(void *data)
-{
-  free_acl2prov_state(data, -1);
-  return OC_EVENT_DONE;
-}
-
 static void
 free_acl2prov_ctx(oc_acl2prov_ctx_t *r, int status)
 {
-  oc_remove_delayed_callback(r, acl2prov_timeout_cb);
   free_acl2prov_state(r, status);
 }
 
@@ -1861,7 +1825,6 @@ oc_obt_provision_ace(oc_uuid_t *uuid, oc_sec_ace_t *ace,
   }
 
   oc_list_add(oc_acl2prov_l, r);
-  oc_set_delayed_callback(r, acl2prov_timeout_cb, OBT_CB_TIMEOUT);
 
   return 0;
 }
diff --git a/security/oc_obt_internal.h b/security/oc_obt_internal.h
index d2f0dd3d..9d4d7f71 100644
--- a/security/oc_obt_internal.h
+++ b/security/oc_obt_internal.h
@@ -28,9 +28,7 @@ extern "C"
 {
 #endif
 
-#define DISCOVERY_CB_PERIOD (5)
-/* Worst case timeout for all onboarding/provisioning sequences */
-#define OBT_CB_TIMEOUT (15)
+#define DISCOVERY_CB_PERIOD (60)
 
 /* Used for tracking owned/unowned devices in oc_obt's internal caches */
 typedef struct oc_device_t
diff --git a/security/oc_obt_otm_cert.c b/security/oc_obt_otm_cert.c
index 062b38cb..0f511a64 100644
--- a/security/oc_obt_otm_cert.c
+++ b/security/oc_obt_otm_cert.c
@@ -396,7 +396,7 @@ obt_cert_7(oc_client_response_t *data)
   }
 
   /**  7) post acl rowneruuid
-  */
+   */
   oc_device_t *device = o->device;
   oc_endpoint_t *ep = oc_obt_get_secure_endpoint(device->endpoint);
 
@@ -648,7 +648,6 @@ oc_obt_perform_cert_otm(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
    */
   oc_endpoint_t *ep = oc_obt_get_unsecure_endpoint(device->endpoint);
   if (oc_do_get("/oic/d", ep, NULL, &obt_cert_2, HIGH_QOS, o)) {
-    oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT);
     return 0;
   }
 
diff --git a/security/oc_obt_otm_justworks.c b/security/oc_obt_otm_justworks.c
index c1ea607e..f4ffeaab 100644
--- a/security/oc_obt_otm_justworks.c
+++ b/security/oc_obt_otm_justworks.c
@@ -395,7 +395,7 @@ obt_jw_7(oc_client_response_t *data)
   }
 
   /**  7) post acl rowneruuid
-  */
+   */
   oc_device_t *device = o->device;
   oc_endpoint_t *ep = oc_obt_get_secure_endpoint(device->endpoint);
 
@@ -647,7 +647,6 @@ oc_obt_perform_just_works_otm(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
    */
   oc_endpoint_t *ep = oc_obt_get_unsecure_endpoint(device->endpoint);
   if (oc_do_get("/oic/d", ep, NULL, &obt_jw_2, HIGH_QOS, o)) {
-    oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT);
     return 0;
   }
 
diff --git a/security/oc_obt_otm_randompin.c b/security/oc_obt_otm_randompin.c
index 98fb7b1e..b1d03198 100644
--- a/security/oc_obt_otm_randompin.c
+++ b/security/oc_obt_otm_randompin.c
@@ -396,7 +396,7 @@ obt_rdp_6(oc_client_response_t *data)
   }
 
   /**  6) post acl rowneruuid
-  */
+   */
   oc_device_t *device = o->device;
   oc_endpoint_t *ep = oc_obt_get_secure_endpoint(device->endpoint);
 
@@ -645,7 +645,6 @@ oc_obt_perform_random_pin_otm(oc_uuid_t *uuid, const unsigned char *pin,
   oc_tls_close_connection(ep);
   oc_tls_select_psk_ciphersuite();
   if (oc_do_get("/oic/d", ep, NULL, &obt_rdp_2, HIGH_QOS, o)) {
-    oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT);
     return 0;
   }
 
@@ -718,7 +717,6 @@ oc_obt_request_random_pin(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
     oc_rep_set_int(root, oxmsel, 1);
     oc_rep_end_root_object();
     if (oc_do_post()) {
-      oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT);
       return 0;
     }
   }
diff --git a/security/oc_tls.c b/security/oc_tls.c
index ba25168f..983ecbe2 100644
--- a/security/oc_tls.c
+++ b/security/oc_tls.c
@@ -338,6 +338,7 @@ oc_tls_inactive(void *data)
       return OC_EVENT_CONTINUE;
     }
     mbedtls_ssl_close_notify(&peer->ssl_ctx);
+    mbedtls_ssl_close_notify(&peer->ssl_ctx);
     oc_tls_free_peer(peer, true);
   }
   OC_DBG("oc_tls: Terminating DTLS inactivity callback");
@@ -1292,6 +1293,7 @@ oc_tls_close_connection(oc_endpoint_t *endpoint)
 {
   oc_tls_peer_t *peer = oc_tls_get_peer(endpoint);
   if (peer) {
+    mbedtls_ssl_close_notify(&peer->ssl_ctx);
     mbedtls_ssl_close_notify(&peer->ssl_ctx);
     oc_tls_free_peer(peer, false);
   }
@@ -1687,6 +1689,7 @@ read_application_data(oc_tls_peer_t *peer)
         if (peer->role == MBEDTLS_SSL_IS_SERVER &&
             (peer->endpoint.flags & TCP) == 0) {
           mbedtls_ssl_close_notify(&peer->ssl_ctx);
+          mbedtls_ssl_close_notify(&peer->ssl_ctx);
         }
         oc_tls_free_peer(peer, false);
         return;