From dae9ba87279bd73f0bb0b96a76503f010d09985b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20H=C3=A4nel?= <andre.haenel@knx.org> Date: Tue, 4 Feb 2025 10:20:42 +0100 Subject: [PATCH] separate scope/ interfaces for each method , part 3 --- api/oc_core_res.c | 4 +- api/oc_discovery.c | 5 +- api/oc_knx.c | 151 ++++++++++++++-------------- api/oc_knx_client.c | 7 +- api/oc_knx_client.h | 10 +- api/oc_knx_dev.c | 35 ++++--- api/oc_knx_fb.c | 2 - api/oc_knx_fp.c | 10 +- api/oc_knx_fp.h | 8 +- api/oc_knx_p.c | 1 - api/oc_knx_sec.c | 11 +-- api/oc_knx_sec.h | 2 +- api/oc_knx_sub.c | 2 +- api/oc_knx_swu.c | 23 +---- api/oc_ri.c | 18 ++-- api/oc_server_api.c | 36 ++++--- apps/knx_iot_virtual_sa.c | 16 ++- apps/knx_iot_virtual_sa.cpp | 2 +- apps/knx_iot_virtual_sa.h | 7 +- include/oc_api.h | 68 +++++++------ include/oc_core_res.h | 21 ++-- include/oc_helpers.h | 190 ++++++++++++++++++------------------ include/oc_ri.h | 16 +-- 23 files changed, 315 insertions(+), 330 deletions(-) diff --git a/api/oc_core_res.c b/api/oc_core_res.c index 96d2858b9..19aba2148 100644 --- a/api/oc_core_res.c +++ b/api/oc_core_res.c @@ -526,7 +526,7 @@ int oc_core_set_device_fid(size_t device_index, uint64_t fid) } oc_device_info_t* oc_core_add_device(const char* name, const char* version, const char* base, - char* serialnumber, + const char* serialnumber, oc_core_add_device_cb_t add_device_cb, void* data) { (void) data; @@ -881,7 +881,7 @@ bool oc_filter_resource_by_if(oc_resource_t* resource, oc_request_t* request) { more_query_params = oc_iterate_query_get_values(request, "if", &value, &value_len); - // must be minimal 'urn:knx:' + // must be at least 'urn:knx:' if (value_len > 8) { // check on wildcard if.* (everything matches) diff --git a/api/oc_discovery.c b/api/oc_discovery.c index b0b35c161..4be1fb36d 100644 --- a/api/oc_discovery.c +++ b/api/oc_discovery.c @@ -681,13 +681,12 @@ void oc_wkcore_discovery_handler(oc_request_t* request, oc_interface_mask_t ifac } OC_CORE_CREATE_CONST_RESOURCE_FINAL(well_known_core, 0, "/.well-known/core", - OC_IF_NONE, APPLICATION_LINK_FORMAT, - OC_DISCOVERABLE, + APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_wkcore_discovery_handler, OC_ACL_NONE, OC_IF_NONE, // unsecured EP 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, - NULL, OC_SIZE_MANY(1), "wk"); + NULL, OC_SIZE_MANY(1), "well-known-type"); const oc_request_handler_t wk_handler = { oc_wkcore_discovery_handler, NULL,OC_ACL_NONE, OC_IF_NONE }; diff --git a/api/oc_knx.c b/api/oc_knx.c index 6cb3c2d7f..aaafc0943 100644 --- a/api/oc_knx.c +++ b/api/oc_knx.c @@ -63,8 +63,8 @@ enum SpakeKeys static int convert_cmd(char* cmd) { -#define RESTART_DEVICE 2 -#define RESET_DEVICE 1 + #define RESTART_DEVICE 2 + #define RESET_DEVICE 1 if (strncmp(cmd, "reset", strlen("reset")) == 0) { @@ -321,18 +321,17 @@ static void oc_core_knx_post_handler(oc_request_t* request, oc_interface_mask_t } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx, knx_fp_g, 0, "/.well-known/knx", - OC_IF_LI | OC_IF_SEC | OC_IF_D, APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_knx_get_handler, OC_ACL_NONE, OC_IF_NONE, // unsecured EP 0, OC_ACL_NONE, OC_IF_NONE, - oc_core_knx_post_handler, OC_ACL_P | OC_ACL_SEC, OC_IF_P | OC_IF_SEC, + oc_core_knx_post_handler, OC_ACL_C | OC_ACL_SEC, OC_IF_C | OC_IF_SEC, 0, OC_ACL_NONE, OC_IF_NONE, NULL, OC_SIZE_ZERO()); void oc_create_knx_resource(int resource_idx, size_t device) { OC_DBG("create /knx resources"); - oc_core_populate_resource(resource_idx, device, "/.well-known/knx", + oc_core_populate_resource(resource_idx, device, "/.well-known/knx", APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_knx_get_handler, 0, oc_core_knx_post_handler, 0, 0); @@ -568,11 +567,11 @@ static void oc_core_a_lsm_post_handler(oc_request_t* request, oc_interface_mask_ oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(a_lsm, knx_spake, 0, "/a/lsm", OC_IF_C, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(a_lsm, knx_spake, 0, "/a/lsm", APPLICATION_CBOR, OC_DISCOVERABLE, - oc_core_a_lsm_get_handler, OC_ACL_P, OC_IF_P, + oc_core_a_lsm_get_handler, OC_ACL_C, OC_IF_C, 0, OC_ACL_NONE, OC_IF_NONE, - oc_core_a_lsm_post_handler, OC_ACL_SEC, OC_IF_SEC, + oc_core_a_lsm_post_handler, OC_ACL_C, OC_IF_C, 0, OC_ACL_NONE, OC_IF_NONE, NULL, OC_SIZE_ZERO()); @@ -580,7 +579,7 @@ void oc_create_a_lsm_resource(int resource_idx, size_t device) { OC_DBG("create /a/lsm resources"); - oc_core_populate_resource(resource_idx, device, "/a/lsm", + oc_core_populate_resource(resource_idx, device, "/a/lsm", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_a_lsm_get_handler, 0, oc_core_a_lsm_post_handler, 0, 0); } @@ -739,7 +738,7 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ } -#ifdef OC_IOT_ROUTER + #ifdef OC_IOT_ROUTER // gateway functionality: call back for all s-mode calls oc_gateway_t* my_gw = oc_get_gateway_cb(); if (my_gw != NULL && my_gw->cb) @@ -760,7 +759,7 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ my_gw->cb(device_index, ip_address, &g_received_notification, buffer); } } -#endif + #endif if (oc_is_device_in_runtime(device_index) == false) { @@ -769,7 +768,8 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ return; } - // get sender ip address + + // debugging ... char ip_address[100]; SNPRINTFipaddr(ip_address, 100 - 1, *request->origin); // handle the request loop over the group addresses of the /fp/r (recipient table) @@ -802,45 +802,52 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ st_read = true; } - int index = oc_core_find_first_group_object_table_index(received_notification.ga); - PRINT("k : index %d", index); - if (index == -1) + // get GO with that GA included (one out of 1...n of GO array) + int go_table_index = oc_core_find_first_group_object_table_index(received_notification.ga); + + PRINT("k : index %d", go_table_index); + if (go_table_index == -1) { // if nothing is found (initially) then ignore oc_send_response_no_format(request, OC_IGNORE); return; } - bool send_payload = false; + // default no read ... + bool is_allowed_read_request = false; - // create the dummy request + // create the dummy request, EACH application callback + // handler per GA gets an individual copy oc_request_t new_request = { 0 }; oc_response_buffer_t response_buffer = { 0 }; oc_response_t response_obj = { 0 }; - // internal callback handler, updates all to this index (=GA) assigned GOs - while (index != -1) + // internal callback handler, updates all to a GO index assigned GAs + while (go_table_index != -1) { - oc_string_t my_url = oc_core_find_group_object_table_url_from_index(index); - PRINT("k : url %s", oc_string_checked(my_url)); + // get href for the GO index + oc_string_t go_href = oc_core_get_href_from_group_object_table_index(go_table_index); + PRINT("k : url %s", oc_string_checked(go_href)); - // device EP present ? - if (oc_string_len(my_url) > 0) + // device EP present (sanity check, GO without href, product problem)? + if (oc_string_len(go_href) > 0) { - // len > 0 = no error, get the resource to do the fake post on - const oc_resource_t* my_resource = oc_ri_get_app_resource_by_uri(oc_string(my_url), oc_string_len(my_url), device_index); - if (my_resource == NULL) + // len > 0 = no error, get the application resource to do the fake post on + const oc_resource_t* my_resource = oc_ri_get_app_resource_by_uri(oc_string(go_href), oc_string_len(go_href), device_index); + if (!my_resource) { + // silently ignored on unicast ? return; } - // check if the data is allowed to write or update - oc_cflag_mask_t cflags = oc_core_group_object_table_cflag_entries(index); + // get c-flags + oc_cflag_mask_t cflags = oc_core_group_object_table_cflag_entries(go_table_index); - if (((cflags & OC_CFLAG_WRITE) > 0) && (st_write)) + if (cflags & OC_CFLAG_WRITE && st_write) { - PRINT("(case1) W-WRITE: index %d handled due to flags %d", index, cflags); + PRINT("WRITE: index %d handled due to flags %d", go_table_index, cflags); + // CASE 1: // Received from bus: -st w, any ga // @receiver : cflags = w->overwrite object value @@ -852,27 +859,33 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ if (my_resource->put_handler.cb) { oc_ri_new_request_from_request(&new_request, request, &response_buffer, &response_obj); + + // sets the pointer to 'value' from request, used to align data structure + // for /p and /k EP to be the same + // take care in application, the data pointer below is only a reference! new_request.request_payload = oc_s_mode_get_value(request); new_request.uri_path = "k"; new_request.uri_path_len = 1; my_resource->put_handler.cb(&new_request, iface_mask, my_resource->put_handler.user_data); + + // TODO wrong here if ((cflags & OC_CFLAG_TRANSMISSION) > 0) { // Case 3) part 1 // @sender : updated object value + cflags = t // Sent : -st w, sending association(1st assigned ga) PRINT("(case3) (W-WRITE) sending WRITE due to TRANSMIT flag"); - #ifdef OC_USE_MULTICAST_SCOPE_2 - oc_do_s_mode_with_scope(2, oc_string(my_url), "w"); - #endif - oc_do_s_mode_with_scope(5, oc_string(my_url), "w"); + #ifdef OC_USE_MULTICAST_SCOPE_2 + oc_do_s_mode_with_scope(2, oc_string(go_href), "w"); + #endif + oc_do_s_mode_with_scope(5, oc_string(go_href), "w"); } } } - if (((cflags & OC_CFLAG_UPDATE) > 0) && (st_rep)) + if (cflags & OC_CFLAG_UPDATE && st_rep) { - PRINT("(case2) RP-UPDATE: index %d handled due to flags %d", index, + PRINT("UPDATE: index %d handled due to flags %d", go_table_index, cflags); // Case 2) // Received from bus: -st rp , any ga @@ -894,17 +907,17 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ // Case 3) part 2 // @sender : updated object value + cflags = t // Sent : -st w, sending association(1st assigned ga) - #ifdef OC_USE_MULTICAST_SCOPE_2 - oc_do_s_mode_with_scope(2, oc_string(my_url), "w"); - #endif - oc_do_s_mode_with_scope(5, oc_string(my_url), "w"); + #ifdef OC_USE_MULTICAST_SCOPE_2 + oc_do_s_mode_with_scope(2, oc_string(go_href), "w"); + #endif + oc_do_s_mode_with_scope(5, oc_string(go_href), "w"); } } } - if (((cflags & OC_CFLAG_READ) > 0) && (st_read)) + if (cflags & OC_CFLAG_READ && st_read) { - PRINT("(case4) (R-READ) index %d handled due to flags %d", index, cflags); - send_payload = true; + PRINT("READ: index %d handled due to flags %d", go_table_index, cflags); + is_allowed_read_request = true; // Case 4) // @sender: cflags = r // Received from bus: -st r @@ -914,23 +927,24 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ if (my_resource->get_handler.cb) { - oc_ri_new_request_from_request(&new_request, request, - &response_buffer, &response_obj); - new_request.uri_path = oc_string(my_url); - new_request.uri_path_len = oc_string_len(my_url); + oc_ri_new_request_from_request(&new_request, request, &response_buffer, &response_obj); + new_request.uri_path = oc_string(go_href); + new_request.uri_path_len = oc_string_len(go_href); new_request.accept = request->accept; my_resource->get_handler.cb(&new_request, iface_mask, NULL); } - #ifdef OC_USE_MULTICAST_SCOPE_2 - oc_do_s_mode_with_scope_no_check(2, oc_string(my_url), "a"); - #endif - oc_do_s_mode_with_scope_no_check(5, oc_string(my_url), "a"); + + // send the read response + #ifdef OC_USE_MULTICAST_SCOPE_2 + oc_do_s_mode_with_scope_no_check(2, oc_string(go_href), "a"); + #endif + oc_do_s_mode_with_scope_no_check(5, oc_string(go_href), "a"); } } // get the next index in the table to get the url from, this stops when the returned index == -1 - index = oc_core_find_next_group_object_table_index(received_notification.ga, index); + go_table_index = oc_core_find_next_group_object_table_index(received_notification.ga, go_table_index); } // don't send anything back on a multicast message @@ -941,21 +955,20 @@ static void oc_core_knx_k_post_handler(oc_request_t* request, oc_interface_mask_ return; } - // send the response on unicast - if (send_payload && oc_rep_get_encoded_payload_size() > 0) + // send the response on unicast after a read 'r' request (and present callback payload) + if (is_allowed_read_request && oc_rep_get_encoded_payload_size() > 0) { - // payload > 0, ends up in CBOR + // payload > 0, ends up in CBOR = OK oc_send_cbor_response(request, OC_STATUS_OK); } else { - // payload = 0, ends up in NO FORMAT + // payload = 0, ends up in NO FORMAT = CHANGED oc_send_cbor_response(request, OC_STATUS_CHANGED); } } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_k, knx_fingerprint, 0, "/k", - OC_IF_LI | OC_IF_G | OC_IF_D, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_knx_k_get_handler, OC_ACL_G, OC_IF_G, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1010,7 +1023,6 @@ static void oc_core_knx_fingerprint_get_handler(oc_request_t* request, oc_interf } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fingerprint, knx_ia, 0, "/.well-known/knx/f", - OC_IF_C, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_knx_fingerprint_get_handler, OC_ACL_C, OC_IF_C, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1022,7 +1034,7 @@ void oc_create_knx_fingerprint_resource(int resource_idx, size_t device) { OC_DBG("create /k/f resources"); - oc_core_populate_resource(resource_idx, device, "/.well-known/knx/f", + oc_core_populate_resource(resource_idx, device, "/.well-known/knx/f", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_knx_fingerprint_get_handler, 0, 0, 0, 0); @@ -1097,7 +1109,6 @@ static void oc_core_knx_ia_post_handler(oc_request_t* request, oc_interface_mask } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_ia, knx, 0, "/.well-known/knx/ia", - OC_IF_C, APPLICATION_CBOR, OC_DISCOVERABLE, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1141,7 +1152,7 @@ static void oc_core_knx_ldevid_get_handler(oc_request_t* request, oc_interface_m } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_ldevid, knx_k, 0, "/.well-known/knx/ldevid", - OC_IF_D, APPLICATION_PKCS7_CMC_REQUEST, OC_DISCOVERABLE, + APPLICATION_PKCS7_CMC_REQUEST, OC_DISCOVERABLE, oc_core_knx_ldevid_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1186,7 +1197,6 @@ static void oc_core_knx_idevid_get_handler(oc_request_t* request, oc_interface_m } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_idevid, knx_ldevid, 0, "/.well-known/knx/idevid", - OC_IF_D, APPLICATION_PKCS7_CMC_REQUEST, OC_DISCOVERABLE, oc_core_knx_idevid_get_handler, OC_ACL_D, OC_IF_D, @@ -1281,7 +1291,7 @@ oc_core_knx_spake_post_handler(oc_request_t* request, oc_interface_mask_t iface_ return; } -#ifdef OC_SPAKE + #ifdef OC_SPAKE if (is_handshake_blocked()) { request->response->response_buffer->code = @@ -1290,7 +1300,7 @@ oc_core_knx_spake_post_handler(oc_request_t* request, oc_interface_mask_t iface_ request->response->response_buffer->max_age = failed_handshake_count * 10; return; } -#endif + #endif oc_rep_t* rep = request->request_payload; @@ -1406,7 +1416,7 @@ oc_core_knx_spake_separate_post_handler(void* req_p) if (valid_request == SPAKE_RND) { - #ifdef OC_SPAKE + #ifdef OC_SPAKE // get random numbers for rnd, salt & it (# of iterations) oc_spake_get_pbkdf_params(g_pase.rnd, g_pase.salt, &g_pase.it); OC_DBG_SPAKE("Rnd:"); @@ -1415,7 +1425,7 @@ oc_core_knx_spake_separate_post_handler(void* req_p) OC_LOGbytes_SPAKE(g_pase.salt, sizeof(g_pase.salt)); OC_DBG_SPAKE("Iterations: %d", g_pase.it); - #endif /* OC_SPAKE */ + #endif /* OC_SPAKE */ oc_rep_begin_root_object(); // id (0) // oc_rep_i_set_byte_string(root, SPAKE_ID, oc_cast(g_pase.id, uint8_t), @@ -1434,7 +1444,7 @@ oc_core_knx_spake_separate_post_handler(void* req_p) oc_send_separate_response(&spake_separate_rsp, OC_STATUS_CHANGED); return OC_EVENT_DONE; } -#ifdef OC_SPAKE + #ifdef OC_SPAKE else if (valid_request == SPAKE_PA_SHARE_P) { // return changed, frame pb (11) & cb (13) @@ -1573,7 +1583,7 @@ error: mbedtls_ecp_point_init(&spake_data.pub_y); mbedtls_mpi_init(&spake_data.w0); mbedtls_mpi_init(&spake_data.y); -#endif /* OC_SPAKE */ + #endif /* OC_SPAKE */ memset(g_pase.pa, 0, sizeof(g_pase.pa)); memset(g_pase.pb, 0, sizeof(g_pase.pb)); @@ -1583,15 +1593,14 @@ error: memset(g_pase.salt, 0, sizeof(g_pase.salt)); g_pase.it = 100000; -#ifdef OC_SPAKE + #ifdef OC_SPAKE increment_counter(); -#endif /* OC_SPAKE */ + #endif /* OC_SPAKE */ oc_send_separate_response(&spake_separate_rsp, OC_STATUS_BAD_REQUEST); return OC_EVENT_DONE; } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_spake, knx_idevid, 0, "/.well-known/knx/spake", - OC_IF_NONE, APPLICATION_CBOR, OC_DISCOVERABLE, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_knx_client.c b/api/oc_knx_client.c index c15aefe76..8be0d9016 100644 --- a/api/oc_knx_client.c +++ b/api/oc_knx_client.c @@ -442,21 +442,18 @@ int oc_knx_client_do_broker_request(const char* resource_url, const uint64_t iid // ---------------------------------------------------------------------------- -bool -oc_is_redirected_request(const oc_request_t* request) +bool oc_is_redirected_request(const oc_request_t* request) { if (request == NULL) { return false; } - // EP allows a redirect such as {4: <IA>, 5: { 6: w, 7: 1234, 1: true } } if (strncmp("k", request->uri_path, request->uri_path_len) == 0) { return true; } - // EP allows a redirect such as { href:/p/p1, value: 1 } if (strncmp("/p", request->uri_path, request->uri_path_len) == 0) { return true; @@ -790,7 +787,7 @@ static void oc_do_s_mode_with_scope_and_check(const int scope, const char* resou if (other_index != index) { oc_cflag_mask_t other_cflags = oc_core_group_object_table_cflag_entries(other_index); - oc_string_t other_url = oc_core_find_group_object_table_url_from_index(other_index); + oc_string_t other_url = oc_core_get_href_from_group_object_table_index(other_index); const char* other_url_char = oc_string(other_url); const oc_resource_t* other_resource = oc_ri_get_app_resource_by_uri(other_url_char, strlen(other_url_char), 0); if (other_resource == NULL) diff --git a/api/oc_knx_client.h b/api/oc_knx_client.h index 9b76904a7..9f6fbc59e 100644 --- a/api/oc_knx_client.h +++ b/api/oc_knx_client.h @@ -124,8 +124,14 @@ bool oc_set_s_mode_response_cb(oc_s_mode_response_cb_t my_func); oc_s_mode_response_cb_t oc_get_s_mode_response_cb(void); /** - * @brief checks if the request is a redirected request from /k or /p - * when that happened, extra information can be in the CBOR object + * @brief checks if the request is a redirected request from /k or /p + * when that happened, extra information can be in the CBOR object. + * An endpoint allows a stack 'redirect' call such as: + * - from STACK s-mode /k with { 4: <IA>, 5: { 6: w, 7: 1234, 1: true } } + * - from STACK CoAP /p/... with { 1: true } + * - from internal application, such as call handler "put_OnOff_1" + * + * @note this method allows to skip code that may ask for data that are only present on STACK call * * @param request the request to be checked * @return true diff --git a/api/oc_knx_dev.c b/api/oc_knx_dev.c index ff6f79a18..cfa183191 100644 --- a/api/oc_knx_dev.c +++ b/api/oc_knx_dev.c @@ -63,7 +63,7 @@ static void oc_core_dev_sn_get_handler(oc_request_t* request, oc_interface_mask_ oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_sn, dev_hwv, 0, "/dev/sn", OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_sn, dev_hwv, 0, "/dev/sn", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_sn_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -116,7 +116,7 @@ static void oc_core_dev_hwv_get_handler(oc_request_t* request, oc_interface_mask oc_send_response_no_format(request, OC_STATUS_INTERNAL_SERVER_ERROR); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_hwv, dev_fwv, 0, "/dev/hwv", OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_hwv, dev_fwv, 0, "/dev/hwv", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_hwv_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -167,7 +167,7 @@ static void oc_core_dev_fwv_get_handler(oc_request_t* request, oc_interface_mask oc_send_response_no_format(request, OC_STATUS_INTERNAL_SERVER_ERROR); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_fwv, dev_hwt, 0, "/dev/fwv", OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_fwv, dev_hwt, 0, "/dev/fwv", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_fwv_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -214,7 +214,7 @@ static void oc_core_dev_hwt_get_handler(oc_request_t* request, oc_interface_mask oc_send_response_no_format(request, OC_STATUS_INTERNAL_SERVER_ERROR); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_hwt, dev_model, 0, "/dev/hwt", OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_hwt, dev_model, 0, "/dev/hwt", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_hwt_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -263,7 +263,7 @@ static void oc_core_dev_model_get_handler(oc_request_t* request, oc_interface_ma } OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_model, dev_hostname, 0, "/dev/model", - OC_IF_D, APPLICATION_CBOR, OC_DISCOVERABLE, + APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_model_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -357,7 +357,7 @@ static void oc_core_dev_hostname_get_handler(oc_request_t* request, oc_interface } OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_hostname, dev_iid, 0, "/dev/hname", - OC_IF_P, APPLICATION_CBOR, OC_DISCOVERABLE, + APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_hostname_get_handler, OC_ACL_D, OC_IF_D, oc_core_dev_hostname_put_handler, OC_ACL_P, OC_IF_P, 0, OC_ACL_NONE, OC_IF_NONE, @@ -449,7 +449,7 @@ static void oc_core_dev_iid_get_handler(oc_request_t* request, oc_interface_mask oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_iid, dev_pm, 0, "/dev/iid", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_iid, dev_pm, 0, "/dev/iid", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_iid_get_handler, OC_ACL_D, OC_IF_D, oc_core_dev_iid_put_handler, OC_ACL_P, OC_IF_P, @@ -561,7 +561,7 @@ static void oc_core_dev_ipv6_get_handler(oc_request_t* request, oc_interface_mas PRINT("oc_core_dev_ipv6_get_handler - end"); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_ipv6, dev_sa, 0, "/dev/ipv6", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_ipv6, dev_sa, 0, "/dev/ipv6", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_ipv6_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -658,7 +658,7 @@ static void oc_core_dev_pm_put_handler(oc_request_t* request, oc_interface_mask_ oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_pm, dev_ipv6, 0, "/dev/pm", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_pm, dev_ipv6, 0, "/dev/pm", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_pm_get_handler, OC_ACL_D, OC_IF_D, oc_core_dev_pm_put_handler, OC_ACL_P, OC_IF_P, @@ -758,7 +758,6 @@ static void oc_core_dev_dev_get_handler(oc_request_t* request, oc_interface_mask } OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev, app, 0, "/dev", - OC_IF_LI | OC_IF_D, APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_dev_dev_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -806,7 +805,7 @@ static void oc_core_dev_sa_get_handler(oc_request_t* request, oc_interface_mask_ oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_sa, dev_da, 0, "/dev/sna", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_sa, dev_da, 0, "/dev/sna", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_sa_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -856,7 +855,7 @@ static void oc_core_dev_da_get_handler(oc_request_t* request, oc_interface_mask_ oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_da, dev_fid, 0, "/dev/da", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_da, dev_fid, 0, "/dev/da", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_da_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -935,7 +934,7 @@ static void oc_core_dev_fid_put_handler(oc_request_t* request, oc_interface_mask oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_fid, dev_port, 0, "/dev/fid", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_fid, dev_port, 0, "/dev/fid", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_fid_get_handler, OC_ACL_D, OC_IF_D, oc_core_dev_fid_put_handler, OC_ACL_P, OC_IF_P, @@ -983,7 +982,7 @@ static void oc_core_dev_port_get_handler(oc_request_t* request, oc_interface_mas } OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_port, dev_mport, 0, "/dev/port", - OC_IF_P, APPLICATION_CBOR, OC_DISCOVERABLE, + APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_port_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1033,7 +1032,7 @@ static void oc_core_dev_mport_get_handler(oc_request_t* request, oc_interface_ma OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_mport, dev_mid, 0, "/dev/mport", - OC_IF_P, APPLICATION_CBOR, OC_DISCOVERABLE, + APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_mport_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1142,7 +1141,7 @@ static void oc_core_ap_x_put_handler(oc_request_t* request, oc_interface_mask_t oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(app_x, a_lsm, 0, "/ap/pv", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(app_x, a_lsm, 0, "/ap/pv", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_ap_x_get_handler, OC_ACL_D, OC_IF_D, oc_core_ap_x_put_handler, OC_ACL_P, OC_IF_P, @@ -1240,7 +1239,7 @@ static void oc_core_ap_get_handler(oc_request_t* request, oc_interface_mask_t if PRINT("oc_core_ap_get_handler - end"); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(app, app_x, 0, "/ap", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(app, app_x, 0, "/ap", APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_ap_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1287,7 +1286,7 @@ static void oc_core_dev_mid_get_handler(oc_request_t* request, oc_interface_mask oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_mid, dev, 0, "/dev/mid", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(dev_mid, dev, 0, "/dev/mid", APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_dev_mid_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_knx_fb.c b/api/oc_knx_fb.c index 96a189e3f..747befc39 100644 --- a/api/oc_knx_fb.c +++ b/api/oc_knx_fb.c @@ -235,7 +235,6 @@ static void oc_core_fb_x_get_handler(oc_request_t* request, oc_interface_mask_t } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_f_x, knx_swu_protocol, 0, "/f/*", - OC_IF_LI | OC_IF_D, APPLICATION_LINK_FORMAT, OC_UNDISCOVERABLE, oc_core_fb_x_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -568,7 +567,6 @@ static void oc_core_fb_get_handler(oc_request_t* request, oc_interface_mask_t if } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_f, knx_f_x, 0, "/f", - OC_IF_LI | OC_IF_D, APPLICATION_LINK_FORMAT, OC_UNDISCOVERABLE, oc_core_fb_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_knx_fp.c b/api/oc_knx_fp.c index 5339587f8..9f91b2141 100644 --- a/api/oc_knx_fp.c +++ b/api/oc_knx_fp.c @@ -209,7 +209,7 @@ int oc_core_find_next_group_object_table_index(uint32_t group_address, int cur_i return -1; } -oc_string_t oc_core_find_group_object_table_url_from_index(int index) +oc_string_t oc_core_get_href_from_group_object_table_index(int index) { const oc_string_t error = { 0 }; return index < GOT_MAX_ENTRIES ? g_got[index].href : error; @@ -652,7 +652,6 @@ static void oc_core_fp_g_post_handler(oc_request_t* request, oc_interface_mask_t } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fp_g, knx_fp_g_x, 0, "/fp/g", - OC_IF_C | OC_IF_B, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_fp_g_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -756,7 +755,7 @@ static void oc_core_fp_g_x_del_handler(oc_request_t* request, oc_interface_mask_ #ifdef OC_PUBLISHER_TABLE OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fp_g_x, knx_fp_p, 0, "/fp/g/*", - OC_IF_D | OC_IF_C, APPLICATION_CBOR, OC_DISCOVERABLE, + APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_fp_g_x_get_handler, OC_ACL_P, OC_IF_P, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1136,7 +1135,6 @@ static void oc_core_fp_p_post_handler(oc_request_t* request, oc_interface_mask_t } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fp_p, knx_fp_p_x, 0, "/fp/p", - OC_IF_C | OC_IF_B, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_fp_p_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1272,7 +1270,7 @@ static void oc_core_fp_p_x_del_handler(oc_request_t* request, oc_interface_mask_ } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fp_p_x, knx_fp_r, 0, "/fp/p/*", - OC_IF_D | OC_IF_C, APPLICATION_CBOR, OC_DISCOVERABLE, + APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_fp_p_x_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1597,7 +1595,6 @@ static void oc_core_fp_r_post_handler(oc_request_t* request, oc_interface_mask_t } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fp_r, knx_fp_r_x, 0, "/fp/r", - OC_IF_C | OC_IF_B, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_fp_r_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1729,7 +1726,6 @@ static void oc_core_fp_r_x_del_handler(oc_request_t* request, oc_interface_mask_ } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_fp_r_x, knx_p, 0, "/fp/r/*", - OC_IF_D | OC_IF_C, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_fp_r_x_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_knx_fp.h b/api/oc_knx_fp.h index 30bea9262..7816ea396 100644 --- a/api/oc_knx_fp.h +++ b/api/oc_knx_fp.h @@ -322,7 +322,7 @@ extern "C" { int oc_core_find_index_in_group_object_table_from_id(int id); /** - * @brief find 'first' index in the group address table + * @brief find 'first' index in the group object table where a GA is included * * @param group_address the group address to find @@ -332,7 +332,7 @@ extern "C" { int oc_core_find_first_group_object_table_index(uint32_t group_address); /** - * @brief find 'next' index - after the provided one - in the group address table + * @brief find 'next' index - after the provided one - in the group object table where a GA is included * * @param group_address the group address to find * @param cur_index the index from which to search @@ -371,12 +371,12 @@ extern "C" { oc_cflag_mask_t oc_core_group_object_table_cflag_entries(int index); /** - * @brief find the url (of the resource) that in the group object table entry. + * @brief get the 'href' url for a resource form a specific group object table entry. * * @param index the index in the table * @return oc_string_t the url */ - oc_string_t oc_core_find_group_object_table_url_from_index(int index); + oc_string_t oc_core_get_href_from_group_object_table_index(int index); /** * @brief retrieve the number of group address entries for index diff --git a/api/oc_knx_p.c b/api/oc_knx_p.c index b01522009..c2db04f0c 100644 --- a/api/oc_knx_p.c +++ b/api/oc_knx_p.c @@ -240,7 +240,6 @@ static void oc_core_p_post_handler(oc_request_t* request, oc_interface_mask_t if } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_p, knx_f, 0, "/p", - OC_IF_LI | OC_IF_D | OC_IF_C | OC_IF_B, APPLICATION_LINK_FORMAT, OC_UNDISCOVERABLE, oc_core_p_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_knx_sec.c b/api/oc_knx_sec.c index 660d27327..ed23acbe0 100644 --- a/api/oc_knx_sec.c +++ b/api/oc_knx_sec.c @@ -134,7 +134,6 @@ static void oc_core_knx_auth_o_osndelay_put_handler(oc_request_t* request, oc_in } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth_o_osndelay, knx_auth_o, 0, "/auth/o/osndelay", - OC_IF_P, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_knx_auth_o_osndelay_get_handler, OC_ACL_P, OC_IF_P, oc_core_knx_auth_o_osndelay_put_handler, OC_ACL_SEC, OC_IF_SEC, @@ -205,7 +204,6 @@ static void oc_core_knx_auth_o_replwdo_put_handler(oc_request_t* request, oc_int } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth_o_replwdo, knx_auth_o_osndelay, 0, "/auth/o/replwdo", - OC_IF_P, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_knx_auth_o_replwdo_get_handler, OC_ACL_P, OC_IF_P, oc_core_knx_auth_o_replwdo_put_handler, OC_ACL_SEC, OC_IF_SEC, @@ -301,7 +299,6 @@ static void oc_core_knx_auth_o_get_handler(oc_request_t* request, oc_interface_m } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth_o, knx_auth_at, 0, "/auth/o", - OC_IF_LI | OC_IF_D | OC_IF_P | OC_IF_C, APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_knx_auth_o_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -383,7 +380,6 @@ static void oc_core_a_sen_post_handler(oc_request_t* request, oc_interface_mask_ } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_a_sen, knx_auth_o_replwdo, 0, "/a/sen", - OC_IF_SEC, APPLICATION_CBOR, OC_DISCOVERABLE, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, @@ -926,9 +922,8 @@ static void oc_core_auth_at_delete_handler(oc_request_t* request, oc_interface_m } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth_at, knx_auth_at_x, 0, "/auth/at", - OC_IF_LI | OC_IF_D | OC_IF_B | OC_IF_SEC, APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, - oc_core_auth_at_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, + oc_core_auth_at_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C | OC_ACL_SEC, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, oc_core_auth_at_post_handler, OC_ACL_SEC, OC_IF_SEC, oc_core_auth_at_delete_handler, OC_ACL_SEC, OC_IF_SEC, @@ -1168,7 +1163,6 @@ static void oc_core_auth_at_x_delete_handler(oc_request_t* request, oc_interface } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth_at_x, knx_auth, 0, "/auth/at/*", - OC_IF_SEC, APPLICATION_CBOR, OC_DISCOVERABLE, oc_core_auth_at_x_get_handler, OC_ACL_SEC, OC_IF_SEC, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1274,7 +1268,6 @@ OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth, knx_fp_gm, 0, "/auth", NULL, OC_SIZE_ZERO()); #else OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_auth, well_known_core, 0, "/auth", - OC_IF_LI | OC_IF_D | OC_IF_P | OC_IF_C, APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_knx_auth_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, @@ -1835,7 +1828,7 @@ oc_oscore_set_auth_shared(char* client_senderid, int client_senderid_size, oc_new_string(&spake_entry.id, client_senderid, client_senderid_size); spake_entry.ga_len = 0; spake_entry.profile = OC_PROFILE_COAP_PASE; - spake_entry.scope = OC_IF_SEC; + spake_entry.scope = OC_ACL_SEC; oc_new_byte_string(&spake_entry.osc_ms, (char*) shared_key, shared_key_size); // no context id oc_new_byte_string(&spake_entry.osc_rid, client_recipientid, diff --git a/api/oc_knx_sec.h b/api/oc_knx_sec.h index bd2099f80..ef2c5cb5e 100644 --- a/api/oc_knx_sec.h +++ b/api/oc_knx_sec.h @@ -126,7 +126,7 @@ extern "C" { * ``` * Note: maps are not stored. */ - typedef struct oc_auth_at_t + typedef struct oc_auth_at { oc_string_t id; // (0) auth / at / {id}, encoding: HEX oc_acl_mask_t scope; // (9) the acl scope diff --git a/api/oc_knx_sub.c b/api/oc_knx_sub.c index 0c48f0bd3..d0f91c433 100644 --- a/api/oc_knx_sub.c +++ b/api/oc_knx_sub.c @@ -28,7 +28,7 @@ static void oc_core_sub_delete_handler(oc_request_t* request, oc_interface_mask_ oc_send_response_no_format(request, OC_STATUS_DELETED); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(sub, knx_a_sen, 0, "/sub", OC_IF_P, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(sub, knx_a_sen, 0, "/sub", APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, 0, OC_ACL_NONE, OC_IF_NONE, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_knx_swu.c b/api/oc_knx_swu.c index 6d4001c71..b4e352adc 100644 --- a/api/oc_knx_swu.c +++ b/api/oc_knx_swu.c @@ -93,7 +93,6 @@ static void oc_knx_swu_protocol_put_handler(oc_request_t* request, oc_interface_ } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_protocol, knx_swu_maxdefer, 0, "/swu/protocol", - OC_IF_SWU | OC_IF_D, APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_protocol_get_handler, OC_ACL_D, OC_IF_D, oc_knx_swu_protocol_put_handler, OC_ACL_SWU, OC_IF_SWU, @@ -155,7 +154,6 @@ static void oc_knx_swu_max_defer_put_handler(oc_request_t* request, oc_interface } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_maxdefer, knx_swu_method, 0, "/swu/maxdefer", - OC_IF_LI | OC_IF_D, APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_max_defer_get_handler, OC_ACL_D, OC_IF_D, oc_knx_swu_max_defer_put_handler, OC_ACL_SWU, OC_IF_SWU, @@ -222,7 +220,6 @@ static void oc_knx_swu_method_put_handler(oc_request_t* request, oc_interface_ma } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_method, knx_lastupdate, 0, "/swu/method", - OC_IF_SWU | OC_IF_D, APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_method_get_handler, OC_ACL_D, OC_IF_D, oc_knx_swu_method_put_handler, OC_ACL_SWU, OC_IF_SWU, @@ -269,8 +266,7 @@ static void oc_knx_swu_last_update_get_handler(oc_request_t* request, oc_interfa oc_send_cbor_response(request, OC_STATUS_OK); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_lastupdate, knx_swu_result, 0, - "/swu/lastupdate", OC_IF_D | OC_IF_SWU, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_lastupdate, knx_swu_result, 0, "/swu/lastupdate", APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_last_update_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -310,7 +306,6 @@ static void oc_knx_swu_result_get_handler(oc_request_t* request, oc_interface_ma } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_result, knx_swu_state, 0, "/swu/result", - OC_IF_D | OC_IF_SWU, APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_result_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -348,7 +343,6 @@ static void oc_knx_swu_state_get_handler(oc_request_t* request, oc_interface_mas } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_state, knx_swu_update, 0, "/swu/state", - OC_IF_D | OC_IF_SWU, APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_state_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -391,7 +385,6 @@ static void oc_knx_swu_update_put_handler(oc_request_t* request, oc_interface_ma } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_update, knx_swu_pkgv, 0, "/swu/update", - OC_IF_D | OC_IF_SWU, APPLICATION_CBOR, OC_DISCOVERABLE, 0, OC_ACL_NONE, OC_IF_NONE, oc_knx_swu_update_put_handler, OC_ACL_SWU, OC_IF_SWU, @@ -437,7 +430,6 @@ static void oc_knx_swu_pkg_version_get_handler(oc_request_t* request, oc_interfa } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgv, knx_swu_pkgcmd, 0, "/swu/pkgv", - OC_IF_D | OC_IF_SWU, APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_pkg_version_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -550,8 +542,7 @@ static void oc_knx_swu_a_post_handler(oc_request_t* request, oc_interface_mask_t oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgcmd, knx_swu_pkgbytes, 0, - "/a/swu", OC_IF_SWU | OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgcmd, knx_swu_pkgbytes, 0, "/a/swu", APPLICATION_CBOR, OC_DISCOVERABLE, 0, OC_ACL_NONE, OC_IF_NONE, oc_knx_swu_a_put_handler, OC_ACL_P, OC_IF_P, @@ -588,8 +579,7 @@ static void oc_knx_swu_bytes_get_handler(oc_request_t* request, oc_interface_mas oc_send_cbor_response(request, OC_STATUS_OK); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgbytes, knx_swu_pkgqurl, 0, - "/swu/pkgbytes", OC_IF_SWU | OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgbytes, knx_swu_pkgqurl, 0, "/swu/pkgbytes", APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_bytes_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -649,8 +639,7 @@ static void oc_knx_swu_pkg_query_url_put_handler(oc_request_t* request, oc_inter oc_send_response_no_format(request, OC_STATUS_BAD_REQUEST); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgqurl, knx_swu_pkgnames, 0, - "/swu/pkgqurl", OC_IF_SWU | OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgqurl, knx_swu_pkgnames, 0, "/swu/pkgqurl", APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_pkg_query_url_get_handler, OC_ACL_D, OC_IF_D, oc_knx_swu_pkg_query_url_put_handler, OC_ACL_SWU, OC_IF_SWU, @@ -694,8 +683,7 @@ static void oc_knx_swu_pkg_name_get_handler(oc_request_t* request, oc_interface_ oc_send_response_no_format(request, OC_STATUS_NOT_FOUND); } -OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgnames, knx_swu, 0, - "/swu/pkgname", OC_IF_SWU | OC_IF_D, +OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu_pkgnames, knx_swu, 0, "/swu/pkgname", APPLICATION_CBOR, OC_DISCOVERABLE, oc_knx_swu_pkg_name_get_handler, OC_ACL_D, OC_IF_D, 0, OC_ACL_NONE, OC_IF_NONE, @@ -792,7 +780,6 @@ static void oc_core_knx_swu_get_handler(oc_request_t* request, oc_interface_mask } OC_CORE_CREATE_CONST_RESOURCE_LINKED(knx_swu, sub, 0, "/swu", - OC_IF_SWU | OC_IF_LI | OC_IF_D, APPLICATION_LINK_FORMAT, OC_DISCOVERABLE, oc_core_knx_swu_get_handler, OC_ACL_P | OC_ACL_D | OC_ACL_C, OC_IF_LI, 0, OC_ACL_NONE, OC_IF_NONE, diff --git a/api/oc_ri.c b/api/oc_ri.c index 3fca9005a..421bd64c4 100644 --- a/api/oc_ri.c +++ b/api/oc_ri.c @@ -183,16 +183,20 @@ void oc_ri_new_request_from_request(oc_request_t* new_request, oc_request_t* req oc_response_buffer_t* response_buffer, oc_response_t* response_obj) { - memcpy(new_request, request, sizeof(request)); // TODO why 8 bytes ? + // copy all src request content to new request content + memcpy(new_request, request, sizeof(oc_request_t)); + // init buffer response_buffer->code = 0; response_buffer->response_length = 0; response_buffer->content_format = 0; response_buffer->max_age = 0; + // init response response_obj->separate_response = NULL; response_obj->response_buffer = response_buffer; + // set new response object new_request->response = response_obj; } @@ -221,10 +225,12 @@ const oc_resource_t* oc_ri_get_app_resource_by_uri(const char* uri, size_t uri_l { if (!uri || uri_len == 0) return NULL; - int skip = 0; - if (uri[0] != '/') - skip = 1; - const oc_resource_t* res = oc_ri_get_app_resources(); + + // to distinguish /p/x or p/x; tolerate a product 'href' w/wo a "/" + const int skip = uri[0] != '/' ? 1 : 0; + + // never NULL except no application resources at all + const oc_resource_t* res = oc_ri_get_app_resources(); while (res != NULL) { if (oc_string_len(res->uri) == (uri_len + skip) && @@ -235,7 +241,7 @@ const oc_resource_t* oc_ri_get_app_resource_by_uri(const char* uri, size_t uri_l } // here res is NULL - return res; + return NULL; } static void oc_ri_delete_all_app_resources(void) diff --git a/api/oc_server_api.c b/api/oc_server_api.c index d1264c415..3e2cc06db 100644 --- a/api/oc_server_api.c +++ b/api/oc_server_api.c @@ -75,17 +75,12 @@ oc_query_values_available(oc_request_t* request) return false; } -static int response_length(void) -{ - return oc_rep_get_encoded_payload_size(); -} - void oc_send_response(oc_request_t* request, oc_status_t response_code) { if (request && request->response && request->response->response_buffer) { request->response->response_buffer->content_format = APPLICATION_CBOR; - request->response->response_buffer->response_length = response_length(); + request->response->response_buffer->response_length = oc_rep_get_encoded_payload_size(); request->response->response_buffer->code = oc_status_code(response_code); } } @@ -95,7 +90,7 @@ void oc_send_cbor_response(oc_request_t* request, oc_status_t response_code) if (request && request->response && request->response->response_buffer) { // ONLY on OK/CHANGED the payload may be > 0 - const int length = response_code == OC_STATUS_OK || response_code == OC_STATUS_CHANGED ? response_length() : 0; + const int length = response_code == OC_STATUS_OK || response_code == OC_STATUS_CHANGED ? oc_rep_get_encoded_payload_size() : 0; if (length > 0) { @@ -117,7 +112,7 @@ void oc_send_json_response(oc_request_t* request, oc_status_t response_code) if (request && request->response && request->response->response_buffer) { request->response->response_buffer->content_format = APPLICATION_JSON; - request->response->response_buffer->response_length = response_length(); + request->response->response_buffer->response_length = oc_rep_get_encoded_payload_size(); request->response->response_buffer->code = oc_status_code(response_code); } } @@ -127,7 +122,7 @@ void oc_send_linkformat_response(oc_request_t* request, oc_status_t response_cod if (request && request->response && request->response->response_buffer) { request->response->response_buffer->content_format = APPLICATION_LINK_FORMAT; - request->response->response_buffer->response_length = response_length; + request->response->response_buffer->response_length = oc_rep_get_encoded_payload_size(); request->response->response_buffer->code = oc_status_code(response_code); } } @@ -463,10 +458,10 @@ void oc_resource_set_properties_cbs(oc_resource_t* resource, void oc_resource_set_request_handler(oc_resource_t* resource, oc_method_t method, - oc_request_callback_t - callback, void* user_data, - oc_acl_mask_t scope, - oc_interface_mask_t interface) + oc_request_callback_t callback, + void* user_data, + oc_acl_mask_t scopes, + oc_interface_mask_t interfaces) { // used to create a copy of the resource pointer oc_request_handler_t* handler = NULL; @@ -504,12 +499,15 @@ void oc_resource_set_request_handler(oc_resource_t* resource, { handler->cb = callback; handler->user_data = user_data; - handler->acl_scope_mask |= scope; - handler->interface_mask |= interface; + handler->acl_scope_mask |= scopes; + handler->interface_mask |= interfaces; } } -bool oc_resource_get_acl_and_interface_mask(oc_resource_t* resource, oc_method_t method, oc_acl_mask_t* scope, oc_interface_mask_t* interface) +bool oc_resource_get_acl_and_interface_mask(oc_resource_t* resource, + oc_method_t method, + oc_acl_mask_t* scopes, + oc_interface_mask_t* interfaces) { // used to create a copy of the resource pointer oc_request_handler_t* handler = NULL; @@ -545,8 +543,8 @@ bool oc_resource_get_acl_and_interface_mask(oc_resource_t* resource, oc_method_t if (handler) { // don't set if NULL was handed over (value is not of interest) - if (scope) *scope = handler->acl_scope_mask; - if (interface) *interface = handler->interface_mask; + if (scopes) *scopes = handler->acl_scope_mask; + if (interfaces) *interfaces = handler->interface_mask; return true; } @@ -722,7 +720,7 @@ void oc_send_separate_response(oc_separate_response_t * handle, oc_status_t resp if (handle->response_state->payload_size != 0) length = handle->response_state->payload_size; else - length = response_length(); + length = oc_rep_get_encoded_payload_size(); oc_send_separate_response_with_length(handle, response_code, length); } diff --git a/apps/knx_iot_virtual_sa.c b/apps/knx_iot_virtual_sa.c index 226b32305..8c53fe5b5 100644 --- a/apps/knx_iot_virtual_sa.c +++ b/apps/knx_iot_virtual_sa.c @@ -580,18 +580,22 @@ extern "C" { PRINT("-- Begin put_OnOff_1"); - /* handle the different requests e.g. via s-mode or normal CoAP call*/ + // handle the different requests e.g. if (oc_is_redirected_request(request)) { PRINT("redirected_request %.*s", (int) request->uri_path_len, request->uri_path); } - oc_rep_t* rep = request->request_payload; + + // sets the pointer to 'value' from request + // don't change this pointer content, it points to the original request payload + const oc_rep_t* rep = request->request_payload; bool error_state = true; - // loop over all the entries in the request + // loop over all 'value' entries from request (ignore any non bool item ...) while (rep != NULL) { - /* handle the type of payload correctly. */ + // this EP accepts only a bool + // a possible faulty value construct such as (1: 2, 1: true would work ... if (rep->iname == 1 && rep->type == OC_REP_BOOL) { PRINT("put_OnOff_1 received : %d", rep->value.boolean); @@ -602,10 +606,12 @@ extern "C" { rep= rep->next; } + // if it was a bool ... if (error_state == false) { oc_send_cbor_response(request, OC_STATUS_CHANGED); - /* update the status information of InfoOnOff_1*/ + + // update the status information of InfoOnOff_1 if (g_fault_OnOff_1 == false) { PRINT("No Fault update feedback to %d'", g_OnOff_1); diff --git a/apps/knx_iot_virtual_sa.cpp b/apps/knx_iot_virtual_sa.cpp index 9b6d14e82..ec93aefc6 100644 --- a/apps/knx_iot_virtual_sa.cpp +++ b/apps/knx_iot_virtual_sa.cpp @@ -22,7 +22,7 @@ #include <wx/wxprec.h> #include <wx/cmdline.h> #ifndef WX_PRECOMP - #include <wx/wx.h> +#include <wx/wx.h> #endif #define NO_MAIN diff --git a/apps/knx_iot_virtual_sa.h b/apps/knx_iot_virtual_sa.h index af630d3a3..1bee0ca75 100644 --- a/apps/knx_iot_virtual_sa.h +++ b/apps/knx_iot_virtual_sa.h @@ -29,7 +29,7 @@ #include "oc_api.h" #include "oc_core_res.h" -#include "port/oc_clock.h" + #ifdef __cplusplus extern "C" { @@ -95,7 +95,6 @@ int app_initialize_stack(void); */ int app_set_serial_number(const char* serial_number); - /** * @brief Set a bool * @@ -104,7 +103,6 @@ int app_set_serial_number(const char* serial_number); */ void app_set_bool_variable(const char* url, bool value); - /** * @brief Set an int * @@ -128,7 +126,6 @@ bool app_retrieve_bool_variable(const char *url); * @return int variable */ int app_retrieve_int_variable(const char *url); - /** * @brief checks if the url represents a parameter @@ -163,7 +160,6 @@ char* app_get_parameter_name(int index); */ void app_set_fault_variable(const char* url, bool value); - /** * @brief retrieve the fault (boolean) variable at the url * @@ -172,7 +168,6 @@ void app_set_fault_variable(const char* url, bool value); */ bool app_retrieve_fault_variable(const char* url); - /** * @brief function to report if the (oscore) security is turn on for this instance * diff --git a/include/oc_api.h b/include/oc_api.h index de0daeb2a..7aed87aff 100644 --- a/include/oc_api.h +++ b/include/oc_api.h @@ -83,25 +83,22 @@ #ifndef OC_API_H #define OC_API_H - #include "messaging/coap/oc_coap.h" - #include "oc_knx.h" #include "oc_rep.h" #include "oc_ri.h" #include "oc_client_state.h" - #ifdef __cplusplus extern "C" { -#endif + #endif /** * @brief maximum URL length (as specified by KNX) * */ -#define OC_MAX_URL_LENGTH (30) + #define OC_MAX_URL_LENGTH (30) /** * Call back handlers that are invoked in response to oc_main_init() @@ -144,7 +141,7 @@ extern "C" { */ void (*signal_event_loop)(void); - #ifdef OC_SERVER + #ifdef OC_SERVER /** * Resource registration callback. * @@ -185,9 +182,9 @@ extern "C" { * @see oc_add_resource */ void (*register_resources)(void); - #endif /* OC_SERVER */ + #endif - #ifdef OC_CLIENT + #ifdef OC_CLIENT /** * Callback invoked when the stack is ready to issue discovery requests. * @@ -208,7 +205,7 @@ extern "C" { * @see oc_do_realm_local_ipv6_discovery */ void (*requests_entry)(void); - #endif /* OC_CLIENT */ + #endif } oc_handler_t; /** @@ -525,8 +522,8 @@ extern "C" { * @see oc_add_device_cb_t for example code using this function * @see oc_add_device */ -#define oc_set_custom_device_property(prop, value) \ - oc_rep_set_text_string(root, prop, value) + #define oc_set_custom_device_property(prop, value) \ + oc_rep_set_text_string(root, prop, value) /** * Initialize the platform. @@ -548,8 +545,7 @@ extern "C" { * @see init * @see oc_init_platform_cb_t */ - int oc_init_platform(const char* mfg_name, - oc_init_platform_cb_t init_platform_cb, void* data); + int oc_init_platform(const char* mfg_name, oc_init_platform_cb_t init_platform_cb, void* data); /** * Set custom platform property. @@ -564,8 +560,8 @@ extern "C" { * @see oc_init_platform_cb_t for example code using this function * @see oc_init_platform */ -#define oc_set_custom_platform_property(prop, value) \ - oc_rep_set_text_string(root, prop, value) + #define oc_set_custom_platform_property(prop, value) \ + oc_rep_set_text_string(root, prop, value) /* Server side */ /** @@ -668,8 +664,7 @@ extern "C" { * @param content_type the content type * @note only one type can be set at a time */ - void oc_resource_bind_content_type(oc_resource_t* resource, - oc_content_format_t content_type); + void oc_resource_bind_content_type(oc_resource_t* resource, oc_content_format_t content_type); /** * Add a Data Point Type "dpt" property to the resource. @@ -739,8 +734,7 @@ extern "C" { * @param[in] seconds the frequency in seconds that the resource will send out * an notification of is property values. */ - void oc_resource_set_periodic_observable(oc_resource_t* resource, - uint16_t seconds); + void oc_resource_set_periodic_observable(oc_resource_t* resource, uint16_t seconds); /** * Specify a request_callback for GET, PUT, POST, and DELETE methods including their scope and interfaces @@ -771,8 +765,8 @@ extern "C" { * oc_request_callback_t. The pointer must remain valid as * long as the resource exists. * - * @param[in] scope the scope of this resource for the given method (will be added, by respect other acl's) - * @param[in] interface the interface of this for the given method (will be added, by respect other if's) + * @param[in] scopes the scope of this resource for the given method (will be added, by respect other acl's) + * @param[in] interfaces the interface of this for the given method (will be added, by respect other if's) * * @see oc_new_resource to see example code using this function */ @@ -780,22 +774,25 @@ extern "C" { oc_method_t method, oc_request_callback_t callback, void* user_data, - oc_acl_mask_t scope, - oc_interface_mask_t interface); + oc_acl_mask_t scopes, + oc_interface_mask_t interfaces); /** * Get for a resource method the corresponding scope and interface * * @param[in] resource the resource * @param[in] method the requesters method for a specific resource callback - * @param[in/out] scope the method scope, if of no interest NULL - * @param[in/out] interface the method interface, if of no interest NULL + * @param[in/out] scopes the method scope, if of no interest NULL + * @param[in/out] interfaces the method interface, if of no interest NULL * * @return * - true if resource and resource method are defined (scope and interface are set accordingly) * - false otherwise (scope and interface are not touched) */ - bool oc_resource_get_acl_and_interface_mask(oc_resource_t* resource, oc_method_t method, oc_acl_mask_t* scope, oc_interface_mask_t* interface); + bool oc_resource_get_acl_and_interface_mask(oc_resource_t* resource, + oc_method_t method, + oc_acl_mask_t* scopes, + oc_interface_mask_t* interfaces); /** * @brief sets the callback properties for set properties and get properties @@ -1239,7 +1236,8 @@ extern "C" { */ int oc_notify_observers(const oc_resource_t* resource); -#ifdef __cplusplus + + #ifdef __cplusplus } #endif /** @} */ // end of doc_module_tag_server_side @@ -1274,7 +1272,7 @@ extern "C" { #ifdef __cplusplus extern "C" { -#endif + #endif /** * Discover all servers that have a resource type using the site-local scope @@ -1639,7 +1637,7 @@ extern "C" { */ void oc_close_session(oc_endpoint_t* endpoint); -#ifdef OC_TCP + #ifdef OC_TCP /** * @brief send CoAP ping over the TCP connection * @@ -1654,7 +1652,7 @@ extern "C" { bool oc_send_ping(bool custody, oc_endpoint_t* endpoint, uint16_t timeout_seconds, oc_response_handler_t handler, void* user_data); -#endif /* OC_TCP */ + #endif /* OC_TCP */ /** @} */ // end of doc_module_tag_client_state /** */ @@ -1699,18 +1697,18 @@ extern "C" { /** API for setting handlers for interrupts */ -#define oc_signal_interrupt_handler(name) \ + #define oc_signal_interrupt_handler(name) \ do { \ oc_process_poll(&(name##_interrupt_x)); \ _oc_signal_event_loop(); \ } while (0) /** activate the interrupt handler */ -#define oc_activate_interrupt_handler(name) \ + #define oc_activate_interrupt_handler(name) \ (oc_process_start(&(name##_interrupt_x), 0)) /** define the interrupt handler */ -#define oc_define_interrupt_handler(name) \ + #define oc_define_interrupt_handler(name) \ void name##_interrupt_x_handler(void); \ OC_PROCESS(name##_interrupt_x, ""); \ OC_PROCESS_THREAD(name##_interrupt_x, ev, data) \ @@ -1725,8 +1723,8 @@ extern "C" { } \ void name##_interrupt_x_handler(void) /** @} */ // end of doc_module_tag_common_operations -#ifdef __cplusplus + #ifdef __cplusplus } #endif -#endif /* OC_API_H */ +#endif diff --git a/include/oc_core_res.h b/include/oc_core_res.h index e9008d742..bda2fcea9 100644 --- a/include/oc_core_res.h +++ b/include/oc_core_res.h @@ -29,17 +29,16 @@ extern "C" { #endif - // define resource_name as extern + // define resource_name as extern by adding internal 'core_resource' name (not known in other modules) #define OC_CORE_EXTERN_CONST_RESOURCE(resource_name) extern const oc_resource_t core_resource_##resource_name; -// set the internal name of a core const resource +// set the internal name of a core const resource by adding internal 'core_resource' name (not known in other modules) #define OC_CORE_RESOURCE_NAME(name) core_resource_##name #if defined _MSC_VER && !defined __INTEL_COMPILER -#define OC_CORE_CREATE_CONST_RESOURCE_INTERNAL( \ - resource_name, next_resource, device_index, uri, iface_mask, content_format, \ - properties, \ +#define OC_CORE_CREATE_CONST_RESOURCE( \ + resource_name, next_resource, device_index, uri, content_format, properties, \ get_cb, get_scope, get_if_mask, \ put_cb, put_scope, put_if_mask, \ post_cb, post_scope, post_if_mask, \ @@ -48,7 +47,7 @@ extern "C" { _Pragma("warning(disable:4090)"); \ oc_ri_expand_call( \ oc_ri_create_const_resource, core_resource_##next_resource, \ - core_resource_##resource_name, device_index, NULL, uri, dpt, iface_mask, \ + core_resource_##resource_name, device_index, NULL, uri, dpt, \ content_format, properties, \ get_cb, get_scope, get_if_mask, \ put_cb, put_scope, put_if_mask, \ @@ -79,7 +78,7 @@ extern "C" { */ #define OC_CORE_CREATE_CONST_RESOURCE_LINKED(resource_name, next_resource, ...)\ extern const oc_resource_t core_resource_##next_resource; \ - oc_ri_expand_call(OC_CORE_CREATE_CONST_RESOURCE_INTERNAL, \ + oc_ri_expand_call(OC_CORE_CREATE_CONST_RESOURCE, \ resource_name, next_resource, __VA_ARGS__) /** @@ -98,12 +97,12 @@ extern "C" { */ #define OC_CORE_CREATE_CONST_RESOURCE_FINAL(resource_name, ...) \ oc_resource_dummy_t core_resource_##resource_name##_final = { NULL, -1 }; \ - oc_ri_expand_call(OC_CORE_CREATE_CONST_RESOURCE_INTERNAL, \ + oc_ri_expand_call(OC_CORE_CREATE_CONST_RESOURCE, \ resource_name, resource_name##_final, __VA_ARGS__) #else -#define OC_CORE_CREATE_CONST_RESOURCE_INTERNAL( \ +#define OC_CORE_CREATE_CONST_RESOURCE( \ resource_name, next_resource, device_index, uri, iface_mask, content_format, \ properties, get_cb, put_cb, post_cb, delete_cb, dpt, num_resource_types, \ ...) \ @@ -119,12 +118,12 @@ extern "C" { #define OC_CORE_CREATE_CONST_RESOURCE_LINKED(resource_name, next_resource, \ ...) \ extern const oc_resource_t core_resource_##next_resource; \ - OC_CORE_CREATE_CONST_RESOURCE_INTERNAL(resource_name, next_resource, \ + OC_CORE_CREATE_CONST_RESOURCE(resource_name, next_resource, \ __VA_ARGS__) #define OC_CORE_CREATE_CONST_RESOURCE_FINAL(resource_name, ...) \ oc_resource_dummy_t core_resource_##resource_name##_final = { NULL, -1 }; \ - OC_CORE_CREATE_CONST_RESOURCE_INTERNAL(resource_name, resource_name##_final, \ + OC_CORE_CREATE_CONST_RESOURCE(resource_name, resource_name##_final, \ __VA_ARGS__) #endif diff --git a/include/oc_helpers.h b/include/oc_helpers.h index 0ea085d91..9ae1fc941 100644 --- a/include/oc_helpers.h +++ b/include/oc_helpers.h @@ -30,7 +30,7 @@ #ifdef __cplusplus extern "C" { -#endif + #endif typedef struct oc_mmem oc_handle_t, oc_string_t, oc_array_t, oc_string_array_t, oc_byte_string_array_t; @@ -41,161 +41,161 @@ extern "C" { HEX_REPRESENTATION, }; -#define oc_cast(block, type) ((type *)(OC_MMEM_PTR(&(block)))) + #define oc_cast(block, type) ((type *)(OC_MMEM_PTR(&(block)))) /** * @brief cast oc_string to string * */ -#define oc_string(ocstring) (oc_cast(ocstring, char)) + #define oc_string(ocstring) (oc_cast(ocstring, char)) /** * @brief cast oc_string to string, replace null pointer results * with a pointer to "NULL" * */ -#define oc_string_checked(ocstring) \ + #define oc_string_checked(ocstring) \ (oc_cast(ocstring, char) ? oc_cast(ocstring, char) : "NULL") -#ifdef OC_MEMORY_TRACE -#define oc_alloc_string(ocstring, size) \ + #ifdef OC_MEMORY_TRACE + #define oc_alloc_string(ocstring, size) \ _oc_alloc_string(__func__, ocstring, size) -#define oc_new_string(ocstring, str, str_len) \ + #define oc_new_string(ocstring, str, str_len) \ _oc_new_string(__func__, ocstring, str, str_len) -#define oc_free_string(ocstring) _oc_free_string(__func__, ocstring) -#define oc_free_int_array(ocarray) (_oc_free_array(__func__, ocarray, INT_POOL)) -#define oc_free_bool_array(ocarray) \ + #define oc_free_string(ocstring) _oc_free_string(__func__, ocstring) + #define oc_free_int_array(ocarray) (_oc_free_array(__func__, ocarray, INT_POOL)) + #define oc_free_bool_array(ocarray) \ (_oc_free_array(__func__, ocarray, BYTE_POOL)) -#define oc_free_float_array(ocarray) \ + #define oc_free_float_array(ocarray) \ (_oc_free_array(__func__, ocarray, FLOAT_POOL)) -#define oc_free_double_array(ocarray) \ + #define oc_free_double_array(ocarray) \ (_oc_free_array(__func__, ocarray, DOUBLE_POOL)) -#define oc_new_int_array(ocarray, size) \ + #define oc_new_int_array(ocarray, size) \ (_oc_new_array(__func__, ocarray, size, INT_POOL)) -#define oc_new_bool_array(ocarray, size) \ + #define oc_new_bool_array(ocarray, size) \ (_oc_new_array(__func__, ocarray, size, BYTE_POOL)) -#define oc_new_float_array(ocarray, size) \ + #define oc_new_float_array(ocarray, size) \ (_oc_new_array(__func__, ocarray, size, FLOAT_POOL)) -#define oc_new_double_array(ocarray, size) \ + #define oc_new_double_array(ocarray, size) \ (_oc_new_array(__func__, ocarray, size, DOUBLE_POOL)) -#define oc_new_string_array(ocstringarray, size) \ + #define oc_new_string_array(ocstringarray, size) \ (_oc_alloc_string_array(__func__, ocstringarray, size)) -#define oc_free_string_array(ocstringarray) \ + #define oc_free_string_array(ocstringarray) \ (_oc_free_string(__func__, ocstringarray)) -#define oc_new_byte_string_array(ocstringarray, size) \ + #define oc_new_byte_string_array(ocstringarray, size) \ (_oc_alloc_string_array(__func__, ocstringarray, size)) -#define oc_free_byte_string_array(ocstringarray) \ + #define oc_free_byte_string_array(ocstringarray) \ (__func__, _oc_free_string(ocstringarray)) -#else /* OC_MEMORY_TRACE */ + #else /* OC_MEMORY_TRACE */ /** * @brief allocate oc_string * */ -#define oc_alloc_string(ocstring, size) _oc_alloc_string((ocstring), (size)) + #define oc_alloc_string(ocstring, size) _oc_alloc_string((ocstring), (size)) /** * @brief create new string from string (null terminated) * */ -#define oc_new_string(ocstring, str, str_len) \ + #define oc_new_string(ocstring, str, str_len) \ _oc_new_string(ocstring, str, str_len) /** * @brief create new (byte) string from string (not null terminated) * */ -#define oc_new_byte_string(ocstring, str, str_len) \ + #define oc_new_byte_string(ocstring, str, str_len) \ _oc_new_byte_string(ocstring, str, str_len) /** * @brief free ocstring * */ -#define oc_free_string(ocstring) _oc_free_string(ocstring) + #define oc_free_string(ocstring) _oc_free_string(ocstring) /** * @brief free array of integers * */ -#define oc_free_int_array(ocarray) (_oc_free_array(ocarray, INT_POOL)) + #define oc_free_int_array(ocarray) (_oc_free_array(ocarray, INT_POOL)) /** * @brief free array of booleans * */ -#define oc_free_bool_array(ocarray) (_oc_free_array(ocarray, BYTE_POOL)) + #define oc_free_bool_array(ocarray) (_oc_free_array(ocarray, BYTE_POOL)) /** * @brief free array of floats * */ -#define oc_free_float_array(ocarray) (_oc_free_array(ocarray, FLOAT_POOL)) + #define oc_free_float_array(ocarray) (_oc_free_array(ocarray, FLOAT_POOL)) /** * @brief free array of doubles * */ -#define oc_free_double_array(ocarray) (_oc_free_array(ocarray, DOUBLE_POOL)) + #define oc_free_double_array(ocarray) (_oc_free_array(ocarray, DOUBLE_POOL)) /** * @brief new integer array * */ -#define oc_new_int_array(ocarray, size) (_oc_new_array(ocarray, size, INT_POOL)) + #define oc_new_int_array(ocarray, size) (_oc_new_array(ocarray, size, INT_POOL)) /** * @brief new boolean array * */ -#define oc_new_bool_array(ocarray, size) \ + #define oc_new_bool_array(ocarray, size) \ (_oc_new_array(ocarray, size, BYTE_POOL)) /** * @brief new float array * */ -#define oc_new_float_array(ocarray, size) \ + #define oc_new_float_array(ocarray, size) \ (_oc_new_array(ocarray, size, FLOAT_POOL)) /** * @brief new double array * */ -#define oc_new_double_array(ocarray, size) \ + #define oc_new_double_array(ocarray, size) \ (_oc_new_array(ocarray, size, DOUBLE_POOL)) /** * @brief new oc string array * */ -#define oc_new_string_array(ocstringarray, size) \ + #define oc_new_string_array(ocstringarray, size) \ (_oc_alloc_string_array(ocstringarray, size)) /** * @brief free oc string array * */ -#define oc_free_string_array(ocstringarray) (_oc_free_string(ocstringarray)) + #define oc_free_string_array(ocstringarray) (_oc_free_string(ocstringarray)) -#define oc_new_byte_string_array(ocstringarray, size) \ + #define oc_new_byte_string_array(ocstringarray, size) \ (_oc_alloc_string_array(ocstringarray, size)) -#define oc_free_byte_string_array(ocstringarray) \ + #define oc_free_byte_string_array(ocstringarray) \ (_oc_free_string(ocstringarray)) -#endif /* !OC_MEMORY_TRACE */ -#define _MAKE_NULL(...) NULL -#define _ECHO -#define OC_SIZE_ZERO() _MAKE_NULL, 0 -#define OC_SIZE_MANY(x) _ECHO, x + #endif /* !OC_MEMORY_TRACE */ + #define _MAKE_NULL(...) NULL + #define _ECHO + #define OC_SIZE_ZERO() _MAKE_NULL, 0 + #define OC_SIZE_MANY(x) _ECHO, x /** * @brief Helper macros to create const versions of oc types * These are special and need some help to understand things correctly @@ -206,47 +206,47 @@ extern "C" { * @param count number of elements * @param ptr pointer to const data */ -#define oc_mmem_create_const(count, ptr) \ + #define oc_mmem_create_const(count, ptr) \ { \ NULL, count, ptr \ } -#define oc_string_create_const(s) oc_mmem_create_const(sizeof(s), s) + #define oc_string_create_const(s) oc_mmem_create_const(sizeof(s), s) -#define oc_string_array_create_const(f, n, ...) \ + #define oc_string_array_create_const(f, n, ...) \ oc_mmem_create_const( \ (n * STRING_ARRAY_ITEM_MAX_LEN), \ f((const char[n][STRING_ARRAY_ITEM_MAX_LEN]){ __VA_ARGS__ })) -#define oc_int_array_create_const(f, n, ...) \ + #define oc_int_array_create_const(f, n, ...) \ oc_mmem_create_const(n, f((const int64_t[n]){ __VA_ARGS__ })) -#define oc_bool_array_create_const(f, n, ...) \ + #define oc_bool_array_create_const(f, n, ...) \ oc_mmem_create_const(n, f((const bool[n]){ __VA_ARGS__ })) -#define oc_float_array_create_const(f, n, ...) \ + #define oc_float_array_create_const(f, n, ...) \ oc_mmem_create_const(n, f((const float[n]){ __VA_ARGS__ })) -#define oc_double_array_create_const(f, n, ...) \ + #define oc_double_array_create_const(f, n, ...) \ oc_mmem_create_const(n, f((const double[n]){ __VA_ARGS__ })) void oc_concat_strings(oc_string_t* concat, const char* str1, const char* str2); -#define oc_string_len(ocstring) ((ocstring).size ? (ocstring).size - 1 : 0) -#define oc_byte_string_len(ocstring) ((ocstring).size) - -#define oc_int_array_size(ocintarray) ((ocintarray).size) -#define oc_bool_array_size(ocboolarray) ((ocboolarray).size) -#define oc_float_array_size(ocfloatarray) ((ocfloatarray).size) -#define oc_double_array_size(ocdoublearray) ((ocdoublearray).size) -#define oc_string_array_size(ocstringarray) \ + #define oc_string_len(ocstring) ((ocstring).size ? (ocstring).size - 1 : 0) + #define oc_byte_string_len(ocstring) ((ocstring).size) + + #define oc_int_array_size(ocintarray) ((ocintarray).size) + #define oc_bool_array_size(ocboolarray) ((ocboolarray).size) + #define oc_float_array_size(ocfloatarray) ((ocfloatarray).size) + #define oc_double_array_size(ocdoublearray) ((ocdoublearray).size) + #define oc_string_array_size(ocstringarray) \ ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN) -#define oc_int_array(ocintarray) (oc_cast(ocintarray, int64_t)) -#define oc_bool_array(ocboolarray) (oc_cast(ocboolarray, bool)) -#define oc_float_array(ocfloatarray) (oc_cast(ocfloatarray, float)) -#define oc_double_array(ocdoublearray) (oc_cast(ocdoublearray, double)) -#define oc_string_array(ocstringarray) \ + #define oc_int_array(ocintarray) (oc_cast(ocintarray, int64_t)) + #define oc_bool_array(ocboolarray) (oc_cast(ocboolarray, bool)) + #define oc_float_array(ocfloatarray) (oc_cast(ocfloatarray, float)) + #define oc_double_array(ocdoublearray) (oc_cast(ocdoublearray, double)) + #define oc_string_array(ocstringarray) \ ((char(*)[STRING_ARRAY_ITEM_MAX_LEN])(OC_MMEM_PTR(&(ocstringarray)))) -#ifdef OC_DYNAMIC_ALLOCATION -#define STRING_ARRAY_ITEM_MAX_LEN 32 -#else -#define STRING_ARRAY_ITEM_MAX_LEN 32 -#endif + #ifdef OC_DYNAMIC_ALLOCATION + #define STRING_ARRAY_ITEM_MAX_LEN 32 + #else + #define STRING_ARRAY_ITEM_MAX_LEN 32 + #endif bool _oc_copy_string_to_array(oc_string_array_t* ocstringarray, const char str[], size_t index); @@ -262,30 +262,30 @@ extern "C" { const char str[], size_t str_len); /* Arrays of text strings */ -#define oc_string_array_add_item(ocstringarray, str) \ + #define oc_string_array_add_item(ocstringarray, str) \ (_oc_string_array_add_item(&(ocstringarray), str)) -#define oc_string_array_get_item(ocstringarray, index) \ + #define oc_string_array_get_item(ocstringarray, index) \ (oc_string(ocstringarray) + (index)*STRING_ARRAY_ITEM_MAX_LEN) -#define oc_string_array_set_item(ocstringarray, str, index) \ + #define oc_string_array_set_item(ocstringarray, str, index) \ (_oc_copy_string_to_array(&(ocstringarray), str, index)) -#define oc_string_array_get_item_size(ocstringarray, index) \ + #define oc_string_array_get_item_size(ocstringarray, index) \ (strlen((const char *)oc_string_array_get_item(ocstringarray, index))) -#define oc_string_array_get_allocated_size(ocstringarray) \ + #define oc_string_array_get_allocated_size(ocstringarray) \ ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN) /* Arrays of byte strings */ -#define oc_byte_string_array_add_item(ocstringarray, str, str_len) \ + #define oc_byte_string_array_add_item(ocstringarray, str, str_len) \ (_oc_byte_string_array_add_item(&(ocstringarray), str, str_len)) -#define oc_byte_string_array_get_item(ocstringarray, index) \ + #define oc_byte_string_array_get_item(ocstringarray, index) \ (oc_string(ocstringarray) + (index)*STRING_ARRAY_ITEM_MAX_LEN + 1) -#define oc_byte_string_array_set_item(ocstringarray, str, str_len, index) \ + #define oc_byte_string_array_set_item(ocstringarray, str, str_len, index) \ (_oc_copy_byte_string_to_array(&(ocstringarray), str, str_len, index)) -#define oc_byte_string_array_get_item_size(ocstringarray, index) \ + #define oc_byte_string_array_get_item_size(ocstringarray, index) \ (*(oc_string(ocstringarray) + (index)*STRING_ARRAY_ITEM_MAX_LEN)) -#define oc_byte_string_array_get_allocated_size(ocstringarray) \ + #define oc_byte_string_array_get_allocated_size(ocstringarray) \ ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN) /** @@ -296,9 +296,9 @@ extern "C" { * @param str_len size of the string to be copied */ void _oc_new_string( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_string_t* ocstring, const char* str, size_t str_len); /** @@ -309,9 +309,9 @@ extern "C" { * @param str_len size of the string to be copied */ void _oc_new_byte_string( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_string_t* ocstring, const char* str, size_t str_len); /** @@ -321,9 +321,9 @@ extern "C" { * @param size size to be allocated */ void _oc_alloc_string( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_string_t* ocstring, size_t size); /** @@ -332,9 +332,9 @@ extern "C" { * @param ocstring the ocstring to be freed */ void _oc_free_string( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_string_t* ocstring); /** @@ -344,9 +344,9 @@ extern "C" { * @param type pool type */ void _oc_free_array( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_array_t* ocarray, pool type); /** @@ -357,9 +357,9 @@ extern "C" { * @param type pool type */ void _oc_new_array( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_array_t* ocarray, size_t size, pool type); /** @@ -369,9 +369,9 @@ extern "C" { * @param size the size of the string array */ void _oc_alloc_string_array( - #ifdef OC_MEMORY_TRACE + #ifdef OC_MEMORY_TRACE const char* func, - #endif + #endif oc_string_array_t* ocstringarray, size_t size); /** Conversions between hex encoded strings and byte arrays */ @@ -668,7 +668,7 @@ extern "C" { int oc_url_cmp(oc_string_t string1, oc_string_t string2); /** - * @brief print a uint64_t, in either decimal or hex representation + * @brief print an uint64_t, in either decimal or hex representation * * @param number * @param rep - string representation chosen (decimal or hex) @@ -677,7 +677,7 @@ extern "C" { int oc_print_uint64_t(uint64_t number, enum StringRepresentation rep); /** - * @brief Converts a uint64_t to a decimal string representation + * @brief Converts an uint64_t to a decimal string representation * * @param[in] number number to be converted to string * @param[out] str Resulting string after conversion. IMPORTANT: Should have @@ -687,7 +687,7 @@ extern "C" { int oc_conv_uint64_to_dec_string(char* str, uint64_t number); /** - * @brief Converts a uint64_t to a hex string representation + * @brief Converts an uint64_t to a hex string representation * * @param[in] number number to be converted to hexadecimal string * @param[out] str Resulting string after conversion. IMPORTANT: Should have @@ -696,7 +696,7 @@ extern "C" { */ int oc_conv_uint64_to_hex_string(char* str, uint64_t number); -#ifdef __cplusplus + #ifdef __cplusplus } #endif diff --git a/include/oc_ri.h b/include/oc_ri.h index bc56cf647..a924517b6 100644 --- a/include/oc_ri.h +++ b/include/oc_ri.h @@ -32,6 +32,8 @@ #define oc_ri_expand_call(fn, ...) oc_ri_expand_call_expand(fn, (__VA_ARGS__)) #define oc_ri_expand_call_expand(fn, args) fn args + +// TODO not used .... #define oc_ri_create_const_resource_linked(next_resource, ...) \ extern const oc_resource_t next_resource; \ oc_ri_expand_call(oc_ri_create_const_resource, next_resource, __VA_ARGS__) @@ -42,7 +44,7 @@ resource_block_end##resource_name, resource_name, __VA_ARGS__) #define oc_ri_create_const_resource( \ - next_resource, resource_name, device_index, name, uri, dpt, iface_mask, \ + next_resource, resource_name, device_index, name, uri, dpt, \ content_format, properties, \ get_cb, get_scope, get_if_mask, \ put_cb, put_scope, put_if_mask, \ @@ -58,7 +60,6 @@ /*uri*/ oc_string_create_const(uri), \ /*types*/ oc_ri_expand_call(oc_string_array_create_const, __VA_ARGS__), \ /*dpt*/ oc_string_create_const(dpt), \ - /*interfaces*/ iface_mask, \ /*content_type*/ content_format, \ /*properties*/ properties, \ /*get_handler*/ { get_cb, cb_ctx, get_scope, get_if_mask }, \ @@ -275,7 +276,7 @@ extern "C" { OC_IF_M = 1 << 14 // if.m.x (manufacturer specific) } oc_interface_mask_t; -#define NUM_INTERFACES (14) +#define NUM_INTERFACES 14 // access control masks, derived from interfaces typedef enum oc_acl_mask @@ -292,7 +293,7 @@ extern "C" { // if.ll (is not a scope) // if.b (is not a scope) OC_ACL_SEC = OC_IF_SEC, // if.sec - OC_ACL_SWU = OC_IF_SWU, // if.swu + OC_ACL_SWU = OC_IF_SWU // if.swu // if.pm (is not a scope) // if.m.{name} (is not a scope) } oc_acl_mask_t; @@ -460,7 +461,7 @@ extern "C" { * @brief request handler type, including per handler a scope and interface * */ - typedef struct oc_request_handler_s + typedef struct oc_request_handler { oc_request_callback_t cb; void* user_data; @@ -509,9 +510,8 @@ extern "C" { size_t device; // device index oc_string_t name; // name of the resource (e.g. "n") oc_string_t uri; // uri of the resource - oc_string_array_t types; // "rt" types of the resource + oc_string_array_t types; // "rt" types of the resource (e.g. "urn:knx:dpa.0.58" -> dev/da) oc_string_t dpt; // dpt of the resource - oc_interface_mask_t interfaces; // supported interfaces oc_content_format_t content_type; // content format that the - in response included - resources supports (one at the moment) oc_resource_properties_t properties; // properties (as bit mask) oc_request_handler_t get_handler; // callback for GET @@ -625,7 +625,7 @@ extern "C" { bool oc_accept_header_is_ok(oc_request_t* request, oc_content_format_t accept); /** - * @brief retrieve the resource by uri and device index + * @brief retrieve the application resource that fits to the given uri (and device index) * * @param uri the uri of the resource * @param uri_len the length of the uri -- GitLab