diff --git a/README.md b/README.md index b58c8d4..8a9a005 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ git checkout swig ``` git apply /extlibs/patchs/remove_cred_by_credid.patch git apply /extlibs/patchs/fix_config.patch +git apply /extlibs/patchs/bwt_fix.patch +git apply /extlibs/patchs/timeout_fix.patch ``` 3. Go to the linux directory. ``` diff --git a/build/debian/otgc_native.sh b/build/debian/otgc_native.sh index 277c6f2..8a993d9 100755 --- a/build/debian/otgc_native.sh +++ b/build/debian/otgc_native.sh @@ -11,7 +11,7 @@ # Constants PROJECT_NAME="otgc" -VERSION="2.6.0" +VERSION="2.7.0" program=$0 @@ -117,7 +117,7 @@ else echo "cd /usr/share/$PROJECT_NAME" >> "$(pwd)/out/$PROJECT_NAME.sh" echo "mkdir logs"$'\n' >> "$(pwd)/out/$PROJECT_NAME.sh" echo "DATE=\$(date +\"%Y%m%d%H%M\")"$'\n' >> "$(pwd)/out/$PROJECT_NAME.sh" - echo "java -jar /usr/lib/$PROJECT_NAME/$PROJECT_NAME-$VERSION-jfx.jar > logs/otgc_\$DATE.log"$'\n' >> "$(pwd)/out/$PROJECT_NAME.sh" + echo "java -Dprism.order=sw -jar /usr/lib/$PROJECT_NAME/$PROJECT_NAME-$VERSION-jfx.jar > logs/otgc_\$DATE.log"$'\n' >> "$(pwd)/out/$PROJECT_NAME.sh" chmod 755 "$(pwd)/out/$PROJECT_NAME.sh" cp "$(pwd)/out/$PROJECT_NAME.sh" $(pwd)/out/$PROJECT_NAME-$VERSION/usr/bin rm $(pwd)/out/$PROJECT_NAME.sh diff --git a/extlibs/patchs/bwt_fix.patch b/extlibs/patchs/bwt_fix.patch new file mode 100644 index 0000000..b7d3113 --- /dev/null +++ b/extlibs/patchs/bwt_fix.patch @@ -0,0 +1,126 @@ +diff --git a/api/oc_server_api.c b/api/oc_server_api.c +index 198fef46..e94cbcb3 100644 +--- a/api/oc_server_api.c ++++ b/api/oc_server_api.c +@@ -395,7 +395,13 @@ oc_send_separate_response(oc_separate_response_t *handle, + oc_string(cur->uri), oc_string_len(cur->uri), &cur->endpoint, + cur->method, NULL, 0, OC_BLOCKWISE_SERVER); + if (response_state) { +- goto next_separate_request; ++ if (response_state->payload_size == ++ response_state->next_block_offset) { ++ oc_blockwise_free_response_buffer(response_state); ++ response_state = NULL; ++ } else { ++ continue; ++ } + } + response_state = oc_blockwise_alloc_response_buffer( + oc_string(cur->uri), oc_string_len(cur->uri), &cur->endpoint, +diff --git a/messaging/coap/engine.c b/messaging/coap/engine.c +index f7bcfce3..b7c1b91a 100644 +--- a/messaging/coap/engine.c ++++ b/messaging/coap/engine.c +@@ -274,6 +274,15 @@ coap_receive(oc_message_t *msg) + href, href_len, &msg->endpoint, message->code, message->uri_query, + message->uri_query_len, OC_BLOCKWISE_SERVER); + ++ if (request_buffer && request_buffer->payload_size == ++ request_buffer->next_block_offset) { ++ if ((request_buffer->next_block_offset - incoming_block_len) != ++ block1_offset) { ++ oc_blockwise_free_request_buffer(request_buffer); ++ request_buffer = NULL; ++ } ++ } ++ + if (!request_buffer && block1_num == 0) { + OC_DBG("creating new block-wise request buffer"); + request_buffer = oc_blockwise_alloc_request_buffer( +@@ -307,7 +316,6 @@ coap_receive(oc_message_t *msg) + block1_size); + request_buffer->payload_size = + request_buffer->next_block_offset; +- request_buffer->ref_count = 0; + goto request_handler; + } + } +@@ -325,6 +333,13 @@ coap_receive(oc_message_t *msg) + response_buffer = oc_blockwise_find_response_buffer( + href, href_len, &msg->endpoint, message->code, message->uri_query, + message->uri_query_len, OC_BLOCKWISE_SERVER); ++ ++ if (response_buffer && (response_buffer->next_block_offset - ++ block2_offset) > block2_size) { ++ oc_blockwise_free_response_buffer(response_buffer); ++ response_buffer = NULL; ++ } ++ + if (response_buffer) { + OC_DBG("continuing ongoing block-wise transfer"); + uint32_t payload_size = 0; +@@ -342,7 +357,6 @@ coap_receive(oc_message_t *msg) + (oc_blockwise_response_state_t *)response_buffer; + coap_set_header_etag(response, response_state->etag, + COAP_ETAG_LEN); +- response_buffer->ref_count = more; + goto send_message; + } else { + OC_ERR("could not dispatch block"); +@@ -410,6 +424,13 @@ coap_receive(oc_message_t *msg) + request_buffer->payload_size = incoming_block_len; + request_buffer->ref_count = 0; + } ++ response_buffer = oc_blockwise_find_response_buffer( ++ href, href_len, &msg->endpoint, message->code, message->uri_query, ++ message->uri_query_len, OC_BLOCKWISE_SERVER); ++ if (response_buffer) { ++ oc_blockwise_free_response_buffer(response_buffer); ++ response_buffer = NULL; ++ } + goto request_handler; + } else { + OC_ERR("incoming payload size exceeds block size"); +diff --git a/messaging/coap/observe.c b/messaging/coap/observe.c +index 62192fa5..2847d526 100644 +--- a/messaging/coap/observe.c ++++ b/messaging/coap/observe.c +@@ -313,7 +313,12 @@ coap_notify_collection_observers(oc_resource_t *resource, + oc_string_len(obs->resource->uri) - 1, &obs->endpoint, OC_GET, NULL, 0, + OC_BLOCKWISE_SERVER); + if (response_state) { +- continue; ++ if (response_state->payload_size == response_state->next_block_offset) { ++ oc_blockwise_free_response_buffer(response_state); ++ response_state = NULL; ++ } else { ++ continue; ++ } + } + response_state = oc_blockwise_alloc_response_buffer( + oc_string(obs->resource->uri) + 1, +@@ -480,8 +485,7 @@ coap_remove_observers_on_dos_change(size_t device, bool reset) + coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list); + while (obs != NULL) { + if (obs->endpoint.device == device && +- (reset || +- !oc_sec_check_acl(OC_GET, obs->resource, &obs->endpoint))) { ++ (reset || !oc_sec_check_acl(OC_GET, obs->resource, &obs->endpoint))) { + coap_observer_t *o = obs; + coap_packet_t notification[1]; + #ifdef OC_TCP +@@ -638,7 +642,13 @@ coap_notify_observers(oc_resource_t *resource, + oc_string_len(obs->resource->uri) - 1, &obs->endpoint, OC_GET, + NULL, 0, OC_BLOCKWISE_SERVER); + if (response_state) { +- continue; ++ if (response_state->payload_size == ++ response_state->next_block_offset) { ++ oc_blockwise_free_response_buffer(response_state); ++ response_state = NULL; ++ } else { ++ continue; ++ } + } + response_state = oc_blockwise_alloc_response_buffer( + oc_string(obs->resource->uri) + 1, diff --git a/extlibs/patchs/timeout_fix.patch b/extlibs/patchs/timeout_fix.patch new file mode 100644 index 0000000..9a84a77 --- /dev/null +++ b/extlibs/patchs/timeout_fix.patch @@ -0,0 +1,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; diff --git a/pom.xml b/pom.xml index ff71312..6f9b58f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ otgc otgc - 2.6.0 + 2.7.0 UTF-8