http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_clock.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_clock.h b/libs/iotivity/src/port/oc_clock.h deleted file mode 100644 index 16b0b7a..0000000 --- a/libs/iotivity/src/port/oc_clock.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * Copyright (c) 2004, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels <a...@sics.se> - * - */ - -/** - * \defgroup clock Clock library - * - * The clock library is the interface between Contiki and the platform - * specific clock functionality. The clock library defines a macro, - * CLOCK_SECOND, to convert seconds into the tick resolution of the platform. - * Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512. - * A 16 bit counter would thus overflow every 1-10 minutes. - * Platforms use the tick interrupt to maintain a long term count - * of seconds since startup. - * - */ - -#ifndef OC_CLOCK_H -#define OC_CLOCK_H - -#include "mynewt/config.h" -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * A second, measured in system clock time. - * - * \hideinitializer - */ -#ifndef OC_CLOCK_CONF_TICKS_PER_SECOND -#error "Please define OC_CLOCK_CONF_TICKS_PER_SECOND in config.h" -#else -#define OC_CLOCK_SECOND OC_CLOCK_CONF_TICKS_PER_SECOND -#endif - -/** - * Initialize the clock library. - * - * This function initializes the clock library and should be called - * from the main() function of the system. - * - */ -void oc_clock_init(void); - -/** - * Get the current clock time. - * - * This function returns the current system clock time. - * - * \return The current clock time, measured in system ticks. - */ -oc_clock_time_t oc_clock_time(void); - -/** - * Get the current value of the platform seconds. - * - * This could be the number of seconds since startup, or - * since a standard epoch. - * - * \return The value. - */ -unsigned long oc_clock_seconds(void); - -/** - * Wait for a given number of ticks. - * \param t How many ticks. - * - */ -void oc_clock_wait(oc_clock_time_t t); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_CLOCK_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_connectivity.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_connectivity.h b/libs/iotivity/src/port/oc_connectivity.h deleted file mode 100644 index 203f2b0..0000000 --- a/libs/iotivity/src/port/oc_connectivity.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_CONNECTIVITY_H -#define OC_CONNECTIVITY_H - -#include "mynewt/config.h" -#include "../../include/iotivity/oc_network_events.h" -#include "oc_log.h" -#include "../util/oc_process.h" -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - uint16_t port; - uint8_t address[16]; - uint8_t scope; -} oc_ipv6_addr_t; - -typedef struct -{ - uint8_t type; - uint8_t address[6]; - uint16_t conn_handle; -} oc_le_addr_t; - -typedef struct -{ - enum transport_flags - { - IP = 1 << 0, - GATT = 1 << 1, - IPSP = 1 << 2, - MULTICAST = 1 << 3, - SECURED = 1 << 4, - SERIAL = 1 <<5, - } flags; - - union - { - oc_ipv6_addr_t ipv6_addr; - oc_le_addr_t bt_addr; - }; -} oc_endpoint_t; - -#define oc_make_ip_endpoint(__name__, __flags__, __port__, ...) \ - oc_endpoint_t __name__ = {.flags = __flags__, \ - .ipv6_addr = {.port = __port__, \ - .address = { __VA_ARGS__ } } } - -typedef struct oc_message_s -{ - struct oc_message_s *next; - oc_endpoint_t endpoint; - size_t length; - uint8_t ref_count; - uint8_t data[MAX_PAYLOAD_SIZE]; -} oc_message_t; - -void oc_send_buffer(oc_message_t *message); - -#ifdef OC_SECURITY -uint16_t oc_connectivity_get_dtls_port(void); -#endif /* OC_SECURITY */ - -int oc_connectivity_init(void); - -void oc_connectivity_shutdown(void); - -void oc_send_multicast_message(oc_message_t *message); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_CONNECTIVITY_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_log.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_log.h b/libs/iotivity/src/port/oc_log.h deleted file mode 100644 index e77575b..0000000 --- a/libs/iotivity/src/port/oc_log.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_LOG_H -#define OC_LOG_H - -#include <stdio.h> -#include "mynewt/config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PRINT(...) printf(__VA_ARGS__) - -#define PRINTipaddr(endpoint) \ - PRINT( \ - "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \ - "02x]:%d", \ - ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1], \ - ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3], \ - ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5], \ - ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7], \ - ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9], \ - ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11], \ - ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13], \ - ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15], \ - (endpoint).ipv6_addr.port) - -#define LogMynewtipaddr(endpoint) \ -{\ - char tmp_buf[16*3+6]; /* 16 octets plus port */ \ - sprintf(tmp_buf, \ - "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \ - "02x]:%d", \ - ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1], \ - ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3], \ - ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5], \ - ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7], \ - ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9], \ - ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11], \ - ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13], \ - ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15], \ - (endpoint).ipv6_addr.port); \ - LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "%s", tmp_buf); \ -} - -#if defined(ARCH_sim) -#define LOG(...) PRINT(__VA_ARGS__) -#define ERROR(...) LOG(__VA_ARGS__) -#define LOGipaddr(endpoint) PRINTipaddr(endpoint) -#define oc_log_init() 0 -#elif defined(DEBUG) -int oc_log_init(void); -#define LOG(...) LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__) -#define ERROR(...) LOG_ERROR(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__) -#define LOGipaddr(endpoint) LogMynewtipaddr(endpoint) -#else -#define LOG(...) -#define ERROR(...) -#define LOGipaddr(endpoint) -#define oc_log_init() 0 -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* OC_LOG_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_network_events_mutex.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_network_events_mutex.h b/libs/iotivity/src/port/oc_network_events_mutex.h deleted file mode 100644 index 715be7f..0000000 --- a/libs/iotivity/src/port/oc_network_events_mutex.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_NETWORK_EVENTS_MUTEX_H -#define OC_NETWORK_EVENTS_MUTEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -void oc_network_event_handler_mutex_init(void); - -void oc_network_event_handler_mutex_lock(void); - -void oc_network_event_handler_mutex_unlock(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_NETWORK_EVENTS_MUTEX_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_random.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_random.h b/libs/iotivity/src/port/oc_random.h deleted file mode 100644 index 4e377a5..0000000 --- a/libs/iotivity/src/port/oc_random.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * Copyright (c) 2005, Swedish Institute of Computer Science - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - */ -#ifndef OC_RANDOM_H -#define OC_RANDOM_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Initialize the pseudo-random generator. - * - */ -void oc_random_init(unsigned short seed); - -/* - * Calculate a pseudo random number between 0 and 65535. - * - * \return A pseudo-random number between 0 and 65535. - */ -unsigned short oc_random_rand(void); - -/* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX */ -/* Since random_rand casts to unsigned short, we'll use this maxmimum */ -#define RANDOM_RAND_MAX 65535U - -void oc_random_destroy(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_RANDOM_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_signal_main_loop.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_signal_main_loop.h b/libs/iotivity/src/port/oc_signal_main_loop.h deleted file mode 100644 index 8a3251b..0000000 --- a/libs/iotivity/src/port/oc_signal_main_loop.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_SIGNAL_MAIN_LOOP_H -#define OC_SIGNAL_MAIN_LOOP_H - -#ifdef __cplusplus -extern "C" { -#endif - -void oc_signal_main_loop(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_SIGNAL_MAIN_LOOP_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/port/oc_storage.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/oc_storage.h b/libs/iotivity/src/port/oc_storage.h deleted file mode 100644 index e8127fa..0000000 --- a/libs/iotivity/src/port/oc_storage.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_STORAGE_H -#define OC_STORAGE_H - -#include <stddef.h> -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -int oc_storage_config(const char *store); -long oc_storage_read(const char *store, uint8_t *buf, size_t size); -long oc_storage_write(const char *store, uint8_t *buf, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_STORAGE_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_acl.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_acl.c b/libs/iotivity/src/security/oc_acl.c deleted file mode 100644 index 173873b..0000000 --- a/libs/iotivity/src/security/oc_acl.c +++ /dev/null @@ -1,412 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY - -#include "oc_acl.h" -#include "config.h" -#include "oc_api.h" -#include "oc_core_res.h" -#include "oc_dtls.h" -#include "oc_rep.h" -#include <stddef.h> -#include <strings.h> - -#define MAX_NUM_RES_PERM_PAIRS \ - (NUM_OC_CORE_RESOURCES + (MAX_NUM_SUBJECTS + 1) * (MAX_APP_RESOURCES)) -OC_MEMB(ace_l, oc_sec_ace_t, MAX_NUM_SUBJECTS + 1); -OC_MEMB(res_l, oc_sec_acl_res_t, MAX_NUM_RES_PERM_PAIRS); -static oc_uuid_t WILDCARD = {.id = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0 } }; -static oc_sec_acl_t ac_list = { 0 }; - -static void -get_sub_perm_groups(oc_sec_ace_t *ace, uint16_t *groups, int *n) -{ - int i = 0, j; - oc_sec_acl_res_t *res = oc_list_head(ace->resources); - while (res != NULL) { - groups[i++] = res->permissions; - res = res->next; - } - for (i = 0; i < (*n - 1); i++) { - for (j = (i + 1); j < *n; j++) { - if (groups[i] > groups[j]) { - uint16_t t = groups[i]; - groups[i] = groups[j]; - groups[j] = t; - } - } - } - j = 0; - for (i = 1; i < *n; i++) { - if (groups[j] != groups[i]) - groups[++j] = groups[i]; - } - *n = j + 1; -} - -void -oc_sec_encode_acl(void) -{ - int i, n; - char uuid[37]; - oc_rep_start_root_object(); - oc_process_baseline_interface(oc_core_get_resource_by_index(OCF_SEC_ACL)); - oc_rep_set_object(root, aclist); - oc_rep_set_array(aclist, aces); - oc_sec_ace_t *sub = oc_list_head(ac_list.subjects); - while (sub != NULL) { - if (strncmp(sub->subjectuuid.id, WILDCARD.id, 16) == 0) { - uuid[0] = '*'; - uuid[1] = '\0'; - } else { - oc_uuid_to_str(&sub->subjectuuid, uuid, 37); - } - LOG("oc_sec_acl_encode: subject %s\n", uuid); - n = oc_list_length(sub->resources); - uint16_t groups[n]; - get_sub_perm_groups(sub, groups, &n); - for (i = 0; i < n; i++) { - oc_rep_object_array_start_item(aces); - oc_rep_set_text_string(aces, subjectuuid, uuid); - oc_rep_set_uint(aces, permission, groups[i]); - oc_rep_set_array(aces, resources); - oc_sec_acl_res_t *res = oc_list_head(sub->resources); - while (res != NULL) { - if (res->permissions == groups[i]) { - LOG("oc_sec_acl_encode: adding resource %s\n", - oc_string(res->resource->uri)); - oc_rep_object_array_start_item(resources); - oc_rep_set_text_string(resources, href, - oc_string(res->resource->uri)); - oc_rep_set_text_string(resources, rel, ""); - oc_rep_set_text_string(resources, rt, ""); - oc_rep_set_text_string(resources, if, ""); - oc_rep_object_array_end_item(resources); - } - res = res->next; - } - oc_rep_close_array(aces, resources); - oc_rep_object_array_end_item(aces); - } - sub = sub->next; - } - oc_rep_close_array(aclist, aces); - oc_rep_close_object(root, aclist); - oc_uuid_to_str(&ac_list.rowneruuid, uuid, 37); - oc_rep_set_text_string(root, rowneruuid, uuid); - oc_rep_end_root_object(); -} - -static oc_sec_acl_res_t * -oc_sec_acl_get_ace(oc_uuid_t *subjectuuid, oc_resource_t *resource, bool create) -{ - oc_sec_ace_t *ace = (oc_sec_ace_t *)oc_list_head(ac_list.subjects); - oc_sec_acl_res_t *res = NULL; - -#ifdef DEBUG - char uuid[37]; - oc_uuid_to_str(subjectuuid, uuid, 37); -#endif - - while (ace != NULL) { - if (strncmp(ace->subjectuuid.id, subjectuuid->id, 16) == 0) - goto got_ace; - ace = oc_list_item_next(ace); - } - - if (create) - goto new_ace; - - LOG("Could not find ACE for subject %s\n", uuid); - - goto done; - -got_ace: - LOG("Found ACE for subject %s\n", uuid); - res = (oc_sec_acl_res_t *)oc_list_head(ace->resources); - - while (res != NULL) { - if (res->resource == resource) { - LOG("Found permissions mask for resource %s in ACE\n", - oc_string(res->resource->uri)); - goto done; - } - res = oc_list_item_next(res); - } - - if (create) - goto new_res; - - goto done; - -new_ace: - ace = oc_memb_alloc(&ace_l); - - if (!ace) - goto done; - - LOG("Created new ACE for subject %s\n", uuid); - - OC_LIST_STRUCT_INIT(ace, resources); - strncpy(ace->subjectuuid.id, subjectuuid->id, 16); - oc_list_add(ac_list.subjects, ace); - -new_res: - res = oc_memb_alloc(&res_l); - if (res) { - res->resource = resource; - LOG("Adding new resource %s to ACE\n", oc_string(res->resource->uri)); - oc_list_add(ace->resources, res); - } - -done: - return res; -} - -static bool -oc_sec_update_acl(oc_uuid_t *subjectuuid, oc_resource_t *resource, - uint16_t permissions) -{ - oc_sec_acl_res_t *res = oc_sec_acl_get_ace(subjectuuid, resource, true); - - if (!res) - return false; - - res->permissions = permissions; - - LOG("Added resource with permissions: %d\n", res->permissions); - - return true; -} - -void -oc_sec_acl_init(void) -{ - OC_LIST_STRUCT_INIT(&ac_list, subjects); -} - -void -oc_sec_acl_default(void) -{ - bool success = true; - int i; - oc_resource_t *resource; - for (i = 0; i < NUM_OC_CORE_RESOURCES; i++) { - resource = oc_core_get_resource_by_index(i); - if (i < OCF_SEC_DOXM || i > OCF_SEC_CRED) - success &= oc_sec_update_acl(&WILDCARD, resource, 2); - else - success &= oc_sec_update_acl(&WILDCARD, resource, 6); - } - LOG("ACL for core resources initialized %d\n", success); - oc_uuid_t *device = oc_core_get_device_id(0); - memcpy(&ac_list.rowneruuid, device, sizeof(oc_uuid_t)); -} - -bool -oc_sec_check_acl(oc_method_t method, oc_resource_t *resource, - oc_endpoint_t *endpoint) -{ - bool granted = false; - oc_sec_acl_res_t *res = NULL; - oc_uuid_t *identity = (oc_uuid_t *)oc_sec_dtls_get_peer_uuid(endpoint); - - if (identity) { - res = oc_sec_acl_get_ace(identity, resource, false); - } - - if (!res) { // Try Anonymous - res = oc_sec_acl_get_ace(&WILDCARD, resource, false); - } - - if (!res) - return granted; - - LOG("Got permissions mask %d\n", res->permissions); - - if (res->permissions & OC_PERM_CREATE || res->permissions & OC_PERM_UPDATE) { - switch (method) { - case OC_PUT: - case OC_POST: - granted = true; - break; - default: - break; - } - } - - if (res->permissions & OC_PERM_RETRIEVE || - res->permissions & OC_PERM_NOTIFY) { - switch (method) { - case OC_GET: - granted = true; - break; - default: - break; - } - } - - if (res->permissions & OC_PERM_DELETE) { - switch (method) { - case OC_DELETE: - granted = true; - break; - default: - break; - } - } - - return granted; -} - -bool -oc_sec_decode_acl(oc_rep_t *rep) -{ - uint16_t permissions = 0; - oc_uuid_t subjectuuid; - oc_rep_t *resources = 0; - int len = 0; - while (rep != NULL) { - len = oc_string_len(rep->name); - switch (rep->type) { - case STRING: - if (len == 10 && strncmp(oc_string(rep->name), "rowneruuid", 10) == 0) { - oc_str_to_uuid(oc_string(rep->value_string), &ac_list.rowneruuid); - } - break; - case OBJECT: { - oc_rep_t *aclist = rep->value_object; - while (aclist != NULL) { - switch (aclist->type) { - case OBJECT_ARRAY: { - oc_rep_t *aces = aclist->value_object_array; - while (aces != NULL) { - oc_rep_t *ace = aces->value_object; - while (ace != NULL) { - len = oc_string_len(ace->name); - switch (ace->type) { - case STRING: - if (len == 11 && - strncmp(oc_string(ace->name), "subjectuuid", 11) == 0) { - if (strncmp(oc_string(ace->value_string), "*", 1) == 0) - strncpy(subjectuuid.id, WILDCARD.id, 16); - else - oc_str_to_uuid(oc_string(ace->value_string), &subjectuuid); - } - break; - case INT: - if (len == 10 && - strncmp(oc_string(ace->name), "permission", 10) == 0) - permissions = ace->value_int; - break; - case OBJECT_ARRAY: - if (len == 9 && - strncmp(oc_string(ace->name), "resources", 9) == 0) - resources = ace->value_object_array; - break; - default: - break; - } - ace = ace->next; - } - - while (resources != NULL) { - oc_rep_t *resource = resources->value_object; - while (resource != NULL) { - switch (resource->type) { - case STRING: - if (oc_string_len(resource->name) == 4 && - strncasecmp(oc_string(resource->name), "href", 4) == 0) { - oc_resource_t *res = oc_core_get_resource_by_uri( - oc_string(resource->value_string)); - -#ifdef OC_SERVER - if (!res) - res = oc_ri_get_app_resource_by_uri( - oc_string(resource->value_string)); -#endif /* OC_SERVER */ - - if (!res) { - LOG( - "\n\noc_sec_acl_decode: could not find resource %s\n\n", - oc_string(resource->value_string)); - return false; - } - - if (!oc_sec_update_acl(&subjectuuid, res, permissions)) { - LOG("\n\noc_sec_acl_decode: could not update ACE with " - "resource %s permissions\n\n", - oc_string(res->uri)); - return false; - } - } - break; - default: - break; - } - resource = resource->next; - } - resources = resources->next; - } - aces = aces->next; - } - } break; - default: - break; - } - aclist = aclist->next; - } - } break; - default: - break; - } - rep = rep->next; - } - return true; -} - -/* - { - "aclist": - { - "aces": - [ - { - "subjectuuid": "61646d69-6e44-6576-6963-655575696430", - "resources": - [ - {"href": "/led/1", "rel": "", "rt": "", "if": ""}, - {"href": "/switch/1", "rel": "", "rt": "", "if": ""} - ], - "permission": 31 - } - ] - }, - "rowneruuid": "5cdf40b1-c12e-432b-67a2-aa79a3f08c59" - } -*/ -void -post_acl(oc_request_t *request, oc_interface_mask_t interface) -{ - if (oc_sec_decode_acl(request->request_payload)) - oc_send_response(request, OC_STATUS_CREATED); - else - oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR); -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_acl.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_acl.h b/libs/iotivity/src/security/oc_acl.h deleted file mode 100644 index 17f5560..0000000 --- a/libs/iotivity/src/security/oc_acl.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_ACL_H_ -#define OC_ACL_H_ - -#include "oc_ri.h" -#include "oc_uuid.h" -#include "port/oc_log.h" -#include "util/oc_list.h" -#include "util/oc_memb.h" -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - OC_PERM_CREATE = (1 << 0), - OC_PERM_RETRIEVE = (1 << 1), - OC_PERM_UPDATE = (1 << 2), - OC_PERM_DELETE = (1 << 3), - OC_PERM_NOTIFY = (1 << 4) -} oc_sec_acl_permissions_mask_t; - -typedef struct -{ - OC_LIST_STRUCT(subjects); - oc_uuid_t rowneruuid; -} oc_sec_acl_t; - -typedef struct oc_sec_acl_res_s -{ - struct oc_sec_acl_res_s *next; - oc_resource_t *resource; - uint16_t permissions; -} oc_sec_acl_res_t; - -typedef struct oc_sec_ace_s -{ - struct oc_sec_ace_s *next; - OC_LIST_STRUCT(resources); - oc_uuid_t subjectuuid; -} oc_sec_ace_t; - -void oc_sec_acl_default(void); -void oc_sec_encode_acl(void); -bool oc_sec_decode_acl(oc_rep_t *rep); -void oc_sec_acl_init(void); -void post_acl(oc_request_t *request, oc_interface_mask_t interface); -bool oc_sec_check_acl(oc_method_t method, oc_resource_t *resource, - oc_endpoint_t *endpoint); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_ACL_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_cred.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_cred.c b/libs/iotivity/src/security/oc_cred.c deleted file mode 100644 index 2cccf71..0000000 --- a/libs/iotivity/src/security/oc_cred.c +++ /dev/null @@ -1,200 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY - -#include "oc_cred.h" -#include "config.h" -#include "oc_api.h" -#include "oc_core_res.h" -#include "oc_doxm.h" -#include "oc_dtls.h" -#include "port/oc_log.h" -#include "util/oc_list.h" -#include "util/oc_memb.h" - -OC_LIST(creds_l); -OC_MEMB(creds, oc_sec_cred_t, MAX_NUM_SUBJECTS + 1); -#define OXM_JUST_WORKS "oic.sec.doxm.jw" - -oc_sec_cred_t * -oc_sec_find_cred(oc_uuid_t *subjectuuid) -{ - oc_sec_cred_t *cred = oc_list_head(creds_l); - while (cred != NULL) { - if (strncmp(cred->subjectuuid.id, subjectuuid->id, 16) == 0) { - return cred; - } - cred = cred->next; - } - return NULL; -} - -oc_sec_cred_t * -oc_sec_get_cred(oc_uuid_t *subjectuuid) -{ - oc_sec_cred_t *cred = oc_sec_find_cred(subjectuuid); - if (cred == NULL) { - cred = oc_memb_alloc(&creds); - strncpy(cred->subjectuuid.id, subjectuuid->id, 16); - oc_list_add(creds_l, cred); - } - return cred; -} - -void -oc_sec_encode_cred(void) -{ - oc_sec_cred_t *creds = oc_list_head(creds_l); - char uuid[37]; - oc_rep_start_root_object(); - oc_process_baseline_interface(oc_core_get_resource_by_index(OCF_SEC_CRED)); - oc_rep_set_array(root, creds); - if (creds == NULL) { - oc_rep_object_array_start_item(creds); - oc_rep_object_array_end_item(creds); - } - while (creds != NULL) { - oc_rep_object_array_start_item(creds); - oc_rep_set_int(creds, credid, creds->credid); - oc_rep_set_int(creds, credtype, creds->credtype); - oc_uuid_to_str(&creds->subjectuuid, uuid, 37); - oc_rep_set_text_string(creds, subjectuuid, uuid); - oc_rep_set_object(creds, privatedata); - oc_rep_set_byte_string(privatedata, data, creds->key); - oc_rep_set_text_string(privatedata, encoding, "oic.sec.encoding.raw"); - oc_rep_close_object(creds, privatedata); - oc_rep_object_array_end_item(creds); - creds = creds->next; - } - oc_rep_close_array(root, creds); - oc_rep_end_root_object(); -} - -bool -oc_sec_decode_cred(oc_rep_t *rep, oc_sec_cred_t **owner) -{ - oc_sec_doxm_t *doxm = oc_sec_get_doxm(); - int credid = 0, credtype = 0; - char subjectuuid[37] = { 0 }; - oc_uuid_t subject; - oc_sec_cred_t *credobj; - bool got_key = false; - int len = 0; - uint8_t key[16]; - while (rep != NULL) { - len = oc_string_len(rep->name); - switch (rep->type) { - case STRING: - if (len == 10 && strncmp(oc_string(rep->name), "rowneruuid", 10) == 0) { - oc_str_to_uuid(oc_string(rep->value_string), &doxm->rowneruuid); - } - break; - case OBJECT_ARRAY: { - oc_rep_t *creds_array = rep->value_object_array; - while (creds_array != NULL) { - oc_rep_t *cred = creds_array->value_object; - bool valid_cred = false; - while (cred != NULL) { - len = oc_string_len(cred->name); - valid_cred = true; - switch (cred->type) { - case INT: - if (len == 6 && strncmp(oc_string(cred->name), "credid", 6) == 0) - credid = cred->value_int; - else if (len == 8 && - strncmp(oc_string(cred->name), "credtype", 8) == 0) - credtype = cred->value_int; - break; - case STRING: - if (len == 11 && - strncmp(oc_string(cred->name), "subjectuuid", 11) == 0) { - strncpy(subjectuuid, oc_string(cred->value_string), - oc_string_len(cred->value_string) + 1); - } - break; - case OBJECT: { - oc_rep_t *data = cred->value_object; - while (data != NULL) { - switch (data->type) { - case BYTE_STRING: { - got_key = true; - int psk = 0; - uint8_t *p = oc_cast(data->value_string, uint8_t); - size_t size = oc_string_len(data->value_string); - if (size != 16) { - return false; - } - while (psk < size) { - key[psk] = p[psk]; - psk++; - } - } break; - default: - break; - } - data = data->next; - } - } break; - default: - break; - } - cred = cred->next; - } - if (valid_cred) { - oc_str_to_uuid(subjectuuid, &subject); - credobj = oc_sec_get_cred(&subject); - credobj->credid = credid; - credobj->credtype = credtype; - - if (got_key) { - memcpy(credobj->key, key, 16); - } else { - if (owner) - *owner = credobj; - } - } - creds_array = creds_array->next; - } - } break; - default: - break; - } - rep = rep->next; - } - return true; -} - -void -post_cred(oc_request_t *request, oc_interface_mask_t interface) -{ - oc_sec_doxm_t *doxm = oc_sec_get_doxm(); - oc_sec_cred_t *owner = NULL; - bool success = oc_sec_decode_cred(request->request_payload, &owner); - if (owner && strncmp(owner->subjectuuid.id, doxm->rowneruuid.id, 16) == 0) { - oc_uuid_t *dev = oc_core_get_device_id(0); - oc_sec_derive_owner_psk(request->origin, OXM_JUST_WORKS, - strlen(OXM_JUST_WORKS), owner->subjectuuid.id, 16, - dev->id, 16, owner->key, 16); - } - if (!success) { - oc_send_response(request, OC_STATUS_BAD_REQUEST); - } else { - oc_send_response(request, OC_STATUS_CHANGED); - } -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_cred.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_cred.h b/libs/iotivity/src/security/oc_cred.h deleted file mode 100644 index 106f18a..0000000 --- a/libs/iotivity/src/security/oc_cred.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_CRED_H_ -#define OC_CRED_H_ - -#include "oc_ri.h" -#include "oc_uuid.h" -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct oc_sec_cred_s -{ - struct oc_sec_cred_s *next; - int credid; - int credtype; - oc_uuid_t subjectuuid; - uint8_t key[16]; // Supports only 128-bit keys -} oc_sec_cred_t; - -void oc_sec_encode_cred(void); -bool oc_sec_decode_cred(oc_rep_t *rep, oc_sec_cred_t **owner); -oc_sec_cred_t *oc_sec_find_cred(oc_uuid_t *subjectuuid); -oc_sec_cred_t *oc_sec_get_cred(oc_uuid_t *subjectuuid); -void put_cred(oc_request_t *request, oc_interface_mask_t interface); -void post_cred(oc_request_t *request, oc_interface_mask_t interface); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_CRED_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_doxm.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_doxm.c b/libs/iotivity/src/security/oc_doxm.c deleted file mode 100644 index ceb6045..0000000 --- a/libs/iotivity/src/security/oc_doxm.c +++ /dev/null @@ -1,128 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY - -#include "oc_doxm.h" -#include "oc_api.h" -#include "oc_core_res.h" -#include <stddef.h> -#include <strings.h> - -static oc_sec_doxm_t doxm; - -// Fix.. multiple devices.. how many doxms, when we retrieve -// credentials, how do we correlate between creds and devices? -void -oc_sec_doxm_default(void) -{ - doxm.oxmsel = 0; - doxm.sct = 1; - doxm.owned = false; - doxm.dpc = false; - oc_uuid_t *deviceuuid = oc_core_get_device_id(0); - oc_gen_uuid(deviceuuid); - memcpy(&doxm.deviceuuid, deviceuuid, sizeof(oc_uuid_t)); - memset(doxm.devowneruuid.id, 0, 16); - memset(doxm.rowneruuid.id, 0, 16); -} - -void -oc_sec_encode_doxm(void) -{ - int oxms[1] = { 0 }; - char uuid[37]; - oc_rep_start_root_object(); - oc_process_baseline_interface(oc_core_get_resource_by_index(OCF_SEC_DOXM)); - oc_rep_set_int_array(root, oxms, oxms, 1); - oc_rep_set_int(root, oxmsel, doxm.oxmsel); - oc_rep_set_int(root, sct, doxm.sct); - oc_rep_set_boolean(root, owned, doxm.owned); - oc_uuid_to_str(&doxm.deviceuuid, uuid, 37); - oc_rep_set_text_string(root, deviceuuid, uuid); - oc_uuid_to_str(&doxm.devowneruuid, uuid, 37); - oc_rep_set_text_string(root, devowneruuid, uuid); - oc_uuid_to_str(&doxm.rowneruuid, uuid, 37); - oc_rep_set_text_string(root, rowneruuid, uuid); - oc_rep_end_root_object(); -} - -oc_sec_doxm_t * -oc_sec_get_doxm(void) -{ - return &doxm; -} - -void -get_doxm(oc_request_t *request, oc_interface_mask_t interface) -{ - switch (interface) { - case OC_IF_BASELINE: { - char *q; - int ql = oc_get_query_value(request, "owned", &q); - if (ql && ((doxm.owned == 1 && strncasecmp(q, "false", 5) == 0) || - (doxm.owned == 0 && strncasecmp(q, "true", 4) == 0))) { - oc_ignore_request(request); - } else { - oc_sec_encode_doxm(); - oc_send_response(request, OC_STATUS_OK); - } - } break; - default: - break; - } -} - -void -oc_sec_decode_doxm(oc_rep_t *rep) -{ - while (rep != NULL) { - switch (rep->type) { - case BOOL: - if (strncmp(oc_string(rep->name), "owned", 5) == 0) - doxm.owned = rep->value_boolean; - else if (strncmp(oc_string(rep->name), "dpc", 3) == 0) - doxm.dpc = rep->value_boolean; - break; - case INT: - if (strncmp(oc_string(rep->name), "oxmsel", 6) == 0) - doxm.oxmsel = rep->value_int; - else if (strncmp(oc_string(rep->name), "sct", 3) == 0) - doxm.sct = rep->value_int; - break; - case STRING: - if (strncmp(oc_string(rep->name), "deviceuuid", 10) == 0) - oc_str_to_uuid(oc_string(rep->value_string), &doxm.deviceuuid); - else if (strncmp(oc_string(rep->name), "devowneruuid", 12) == 0) - oc_str_to_uuid(oc_string(rep->value_string), &doxm.devowneruuid); - else if (strncmp(oc_string(rep->name), "rowneruuid", 10) == 0) - oc_str_to_uuid(oc_string(rep->value_string), &doxm.rowneruuid); - break; - default: - break; - } - rep = rep->next; - } -} - -void -post_doxm(oc_request_t *request, oc_interface_mask_t interface) -{ - oc_sec_decode_doxm(request->request_payload); - oc_send_response(request, OC_STATUS_CHANGED); -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_doxm.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_doxm.h b/libs/iotivity/src/security/oc_doxm.h deleted file mode 100644 index 7c7586d..0000000 --- a/libs/iotivity/src/security/oc_doxm.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_DOXM_H_ -#define OC_DOXM_H_ - -#include "oc_uuid.h" -#include "port/oc_log.h" -#include "util/oc_list.h" -#include "util/oc_memb.h" - -#include "oc_ri.h" -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - int oxmsel; - int sct; - bool owned; - bool dpc; - oc_uuid_t deviceuuid; - oc_uuid_t devowneruuid; - oc_uuid_t rowneruuid; -} oc_sec_doxm_t; - -void oc_sec_decode_doxm(oc_rep_t *rep); -void oc_sec_encode_doxm(void); -oc_sec_doxm_t *oc_sec_get_doxm(void); -void oc_sec_doxm_default(void); -void get_doxm(oc_request_t *request, oc_interface_mask_t interface); -void post_doxm(oc_request_t *request, oc_interface_mask_t interface); -#ifdef __cplusplus -} -#endif - -#endif /* OC_DOXM_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_dtls.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_dtls.c b/libs/iotivity/src/security/oc_dtls.c deleted file mode 100644 index fdd0249..0000000 --- a/libs/iotivity/src/security/oc_dtls.c +++ /dev/null @@ -1,372 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY - -#include "oc_dtls.h" -#include "api/oc_events.h" -#include "config.h" -#include "oc_acl.h" -#include "oc_buffer.h" -#include "oc_core_res.h" -#include "oc_cred.h" -#include "oc_pstat.h" -#include "oc_svr.h" - -OC_PROCESS(oc_dtls_handler, "DTLS Process"); -OC_MEMB(dtls_peers_s, oc_sec_dtls_peer_t, MAX_DTLS_PEERS); -OC_LIST(dtls_peers); - -static dtls_context_t *ocf_dtls_context; - -oc_sec_dtls_peer_t * -oc_sec_dtls_get_peer(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *peer = oc_list_head(dtls_peers); - while (peer != NULL) { - if (memcmp(&peer->session.addr, endpoint, sizeof(oc_endpoint_t)) == 0) - break; - peer = oc_list_item_next(peer); - } - return peer; -} - -void -oc_sec_dtls_remove_peer(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(endpoint); - if (peer) { - LOG("\n\noc_sec_dtls: removed peer\n\n"); - oc_list_remove(dtls_peers, peer); - oc_memb_free(&dtls_peers_s, peer); - } -} - -oc_event_callback_retval_t -oc_sec_dtls_inactive(void *data) -{ - LOG("\n\noc_sec_dtls: DTLS inactivity callback\n\n"); - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(data); - if (peer) { - oc_clock_time_t time = oc_clock_time(); - time -= peer->timestamp; - if (time < DTLS_INACTIVITY_TIMEOUT * OC_CLOCK_SECOND) { - LOG("\n\noc_sec_dtls: Resetting DTLS inactivity callback\n\n"); - return CONTINUE; - } else if (time < 2 * DTLS_INACTIVITY_TIMEOUT * OC_CLOCK_SECOND) { - LOG("\n\noc_sec_dtls: Initiating connection close\n\n"); - oc_sec_dtls_close_init(data); - return CONTINUE; - } else { - LOG("\n\noc_sec_dtls: Completing connection close\n\n"); - oc_sec_dtls_close_finish(data); - } - } else { - LOG("\n\noc_sec_dtls: Could not find peer\n\n"); - LOG("oc_sec_dtls: Num active peers %d\n", oc_list_length(dtls_peers)); - } - LOG("\n\noc_sec_dtls: Terminating DTLS inactivity callback\n\n"); - return DONE; -} - -oc_sec_dtls_peer_t * -oc_sec_dtls_add_peer(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(endpoint); - if (!peer) { - peer = oc_memb_alloc(&dtls_peers_s); - if (peer) { - LOG("\n\noc_sec_dtls: Allocating new DTLS peer\n\n"); - memcpy(&peer->session.addr, endpoint, sizeof(oc_endpoint_t)); - peer->session.size = sizeof(oc_endpoint_t); - OC_LIST_STRUCT_INIT(peer, send_queue); - peer->connected = false; - oc_list_add(dtls_peers, peer); - - oc_ri_add_timed_event_callback_seconds( - &peer->session.addr, oc_sec_dtls_inactive, DTLS_INACTIVITY_TIMEOUT); - } - } - return peer; -} - -bool -oc_sec_dtls_connected(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(endpoint); - if (peer) - return peer->connected; - return false; -} - -oc_uuid_t * -oc_sec_dtls_get_peer_uuid(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(endpoint); - if (peer) { - return &peer->uuid; - } - return NULL; -} - -/* - Called back from DTLS state machine following decryption so - application can read incoming message. - Following function packages up incoming data into a messaage - to forward up to CoAP -*/ -static int -oc_sec_dtls_get_decrypted_message(struct dtls_context_t *ctx, - session_t *session, uint8_t *buf, size_t len) -{ - oc_message_t *message = oc_allocate_message(); - if (message) { - memcpy(&message->endpoint, &session->addr, sizeof(oc_endpoint_t)); - memcpy(message->data, buf, len); - message->length = len; - oc_recv_message(message); - } - return 0; -} - -void -oc_sec_dtls_init_connection(oc_message_t *message) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_add_peer(&message->endpoint); - if (peer) { - LOG("\n\noc_dtls: Initializing DTLS connection\n\n"); - dtls_connect(ocf_dtls_context, &peer->session); - oc_list_add(peer->send_queue, message); - } else - oc_message_unref(message); -} - -/* - Called from app layer via buffer.c to post OCF responses... - Message routed to this function on spoting SECURE flag in - endpoint structure. This would've already been set on receipt - of the request (to which this the current message is the response) - We call dtls_write(...) to feed response data through the - DTLS state machine leading up to the encrypted send callback below. - - Message sent here may have been flagged to get freed OR - may have been stored for retransmissions. -*/ -int -oc_sec_dtls_send_message(oc_message_t *message) -{ - int ret = 0; - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(&message->endpoint); - if (peer) { - ret = dtls_write(ocf_dtls_context, &peer->session, message->data, - message->length); - } - oc_message_unref(message); - return ret; -} - -/* - Called back from DTLS state machine when it is ready to send - an encrypted response to the remote endpoint. - Construct a new oc_message for this purpose and call oc_send_buffer - to send this message over the wire. -*/ -static int -oc_sec_dtls_send_encrypted_message(struct dtls_context_t *ctx, - session_t *session, uint8_t *buf, size_t len) -{ - oc_message_t message; - memcpy(&message.endpoint, &session->addr, sizeof(oc_endpoint_t)); - memcpy(message.data, buf, len); - message.length = len; - oc_send_buffer(&message); - return len; -} - -/* - This is called once during the handshake process over normal - operation. - OwnerPSK woud've been generated previously during provisioning. -*/ -static int -oc_sec_dtls_get_owner_psk(struct dtls_context_t *ctx, const session_t *session, - dtls_credentials_type_t type, - const unsigned char *desc, size_t desc_len, - unsigned char *result, size_t result_length) -{ - switch (type) { - case DTLS_PSK_IDENTITY: - case DTLS_PSK_HINT: { - LOG("Identity\n"); - oc_uuid_t *uuid = oc_core_get_device_id(0); - memcpy(result, uuid->id, 16); - return 16; - } break; - case DTLS_PSK_KEY: { - LOG("key\n"); - oc_sec_cred_t *cred = oc_sec_find_cred((oc_uuid_t *)desc); - oc_sec_dtls_peer_t *peer = - oc_sec_dtls_get_peer((oc_endpoint_t *)&session->addr); - if (cred != NULL && peer != NULL) { - memcpy(&peer->uuid, (oc_uuid_t *)desc, 16); - memcpy(result, cred->key, 16); - return 16; - } - return 0; - } break; - default: - break; - } - return 0; -} - -int -oc_sec_dtls_events(struct dtls_context_t *ctx, session_t *session, - dtls_alert_level_t level, unsigned short code) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(&session->addr); - if (peer && level == 0 && code == DTLS_EVENT_CONNECTED) { - peer->connected = true; - oc_message_t *m = oc_list_pop(peer->send_queue); - while (m != NULL) { - oc_sec_dtls_send_message(m); - m = oc_list_pop(peer->send_queue); - } - } else if (level == 2) { - oc_sec_dtls_close_finish(&session->addr); - } - return 0; -} - -static dtls_handler_t dtls_cb = {.write = oc_sec_dtls_send_encrypted_message, - .read = oc_sec_dtls_get_decrypted_message, - .event = oc_sec_dtls_events, - .get_psk_info = oc_sec_dtls_get_owner_psk }; - -void -oc_sec_derive_owner_psk(oc_endpoint_t *endpoint, const char *oxm, - const size_t oxm_len, const char *server_uuid, - const size_t server_uuid_len, const char *obt_uuid, - const size_t obt_uuid_len, uint8_t *key, - const size_t key_len) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_get_peer(endpoint); - if (peer) { - dtls_prf_with_current_keyblock( - ocf_dtls_context, &peer->session, oxm, oxm_len, server_uuid, - server_uuid_len, obt_uuid, obt_uuid_len, (uint8_t *)key, key_len); - } -} - -/* - Message received from the wire, routed here via buffer.c - based on examination of the 1st byte proving it is DTLS. - Data sent to dtls_handle_message(...) for decryption. -*/ -static void -oc_sec_dtls_recv_message(oc_message_t *message) -{ - oc_sec_dtls_peer_t *peer = oc_sec_dtls_add_peer(&message->endpoint); - if (peer) { - int ret = dtls_handle_message(ocf_dtls_context, &peer->session, - message->data, message->length); - if (ret != 0) { - oc_sec_dtls_close_finish(&message->endpoint); - } else { - peer->timestamp = oc_clock_time(); - } - } - oc_message_unref(message); -} - -/* If not owned, select anon_ECDH cipher and enter ready for OTM state */ -/* If owned, enter ready for normal operation state */ -/* Fetch persisted SVR from app by this time */ - -void -oc_sec_dtls_init_context(void) -{ - dtls_init(); - ocf_dtls_context = dtls_new_context(NULL); - - if (oc_sec_provisioned()) { - LOG("\n\noc_sec_dtls: Device in normal operation state\n\n"); - dtls_select_cipher(ocf_dtls_context, TLS_PSK_WITH_AES_128_CCM_8); - } else { - LOG("\n\noc_sec_dtls: Device in ready for OTM state\n\n"); - dtls_enables_anon_ecdh(ocf_dtls_context, DTLS_CIPHER_ENABLE); - } - dtls_set_handler(ocf_dtls_context, &dtls_cb); -} - -void -oc_sec_dtls_close_init(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *p = oc_sec_dtls_get_peer(endpoint); - if (p) { - dtls_peer_t *peer = dtls_get_peer(ocf_dtls_context, &p->session); - if (peer) { - dtls_close(ocf_dtls_context, &p->session); - oc_message_t *m = oc_list_pop(p->send_queue); - while (m != NULL) { - LOG("\n\noc_sec_dtls: Freeing DTLS Peer send queue\n\n"); - oc_message_unref(m); - m = oc_list_pop(p->send_queue); - } - } - } -} - -void -oc_sec_dtls_close_finish(oc_endpoint_t *endpoint) -{ - oc_sec_dtls_peer_t *p = oc_sec_dtls_get_peer(endpoint); - if (p) { - dtls_peer_t *peer = dtls_get_peer(ocf_dtls_context, &p->session); - if (peer) { - oc_list_remove(ocf_dtls_context->peers, peer); - dtls_free_peer(peer); - } - oc_message_t *m = oc_list_pop(p->send_queue); - while (m != NULL) { - LOG("\n\noc_sec_dtls: Freeing DTLS Peer send queue\n\n"); - oc_message_unref(m); - m = oc_list_pop(p->send_queue); - } - oc_sec_dtls_remove_peer(endpoint); - } -} - -OC_PROCESS_THREAD(oc_dtls_handler, ev, data) -{ - OC_PROCESS_BEGIN(); - - while (1) { - OC_PROCESS_YIELD(); - - if (ev == oc_events[UDP_TO_DTLS_EVENT]) { - oc_sec_dtls_recv_message(data); - } else if (ev == oc_events[INIT_DTLS_CONN_EVENT]) { - oc_sec_dtls_init_connection(data); - } else if (ev == oc_events[RI_TO_DTLS_EVENT]) { - oc_sec_dtls_send_message(data); - } - } - - OC_PROCESS_END(); -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_dtls.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_dtls.h b/libs/iotivity/src/security/oc_dtls.h deleted file mode 100644 index 21885c0..0000000 --- a/libs/iotivity/src/security/oc_dtls.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_DTLS_H_ -#define OC_DTLS_H_ - -#include "deps/tinydtls/dtls.h" -#include "oc_uuid.h" -#include "port/oc_connectivity.h" -#include "util/oc_process.h" -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -OC_PROCESS_NAME(oc_dtls_handler); - -void oc_sec_dtls_close_init(oc_endpoint_t *endpoint); -void oc_sec_dtls_close_finish(oc_endpoint_t *endpoint); -void oc_sec_derive_owner_psk(oc_endpoint_t *endpoint, const char *oxm, - const size_t oxm_len, const char *server_uuid, - const size_t server_uuid_len, const char *obt_uuid, - const size_t obt_uuid_len, uint8_t *key, - const size_t key_len); -void oc_sec_dtls_init_context(void); -int oc_sec_dtls_send_message(oc_message_t *message); -oc_uuid_t *oc_sec_dtls_get_peer_uuid(oc_endpoint_t *endpoint); -bool oc_sec_dtls_connected(oc_endpoint_t *endpoint); - -typedef struct oc_sec_dtls_peer_s -{ - struct oc_sec_dtls_peer_s *next; - OC_LIST_STRUCT(send_queue); - session_t session; - oc_uuid_t uuid; - bool connected; - oc_clock_time_t timestamp; -} oc_sec_dtls_peer_t; - -#ifdef __cplusplus -} -#endif - -#endif /* OC_DTLS_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_pstat.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_pstat.c b/libs/iotivity/src/security/oc_pstat.c deleted file mode 100644 index 7e8a86d..0000000 --- a/libs/iotivity/src/security/oc_pstat.c +++ /dev/null @@ -1,119 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY - -#include "oc_pstat.h" -#include "oc_api.h" -#include "oc_core_res.h" -#include "oc_doxm.h" - -static oc_sec_pstat_t pstat; - -oc_sec_pstat_t * -oc_sec_get_pstat(void) -{ - return &pstat; -} - -bool -oc_sec_provisioned(void) -{ - return pstat.isop; -} - -void -oc_sec_pstat_default(void) -{ - pstat.isop = false; - pstat.cm = 2; - pstat.tm = 0; - pstat.om = 3; - pstat.sm = 3; -} - -void -oc_sec_encode_pstat(void) -{ - char uuid[37]; - oc_sec_doxm_t *doxm = oc_sec_get_doxm(); - oc_rep_start_root_object(); - oc_process_baseline_interface(oc_core_get_resource_by_index(OCF_SEC_PSTAT)); - oc_rep_set_uint(root, cm, pstat.cm); - oc_rep_set_uint(root, tm, pstat.tm); - oc_rep_set_int(root, om, pstat.om); - oc_rep_set_int(root, sm, pstat.sm); - oc_rep_set_boolean(root, isop, pstat.isop); - oc_uuid_to_str(&doxm->deviceuuid, uuid, 37); - oc_rep_set_text_string(root, deviceuuid, uuid); - oc_uuid_to_str(&doxm->rowneruuid, uuid, 37); - oc_rep_set_text_string(root, rowneruuid, uuid); - oc_rep_end_root_object(); -} - -void -oc_sec_decode_pstat(oc_rep_t *rep) -{ - oc_sec_doxm_t *doxm = oc_sec_get_doxm(); - while (rep != NULL) { - switch (rep->type) { - case BOOL: - pstat.isop = rep->value_boolean; - break; - case INT: - if (strncmp(oc_string(rep->name), "cm", 2) == 0) - pstat.cm = rep->value_int; - else if (strncmp(oc_string(rep->name), "tm", 2) == 0) - pstat.tm = rep->value_int; - else if (strncmp(oc_string(rep->name), "om", 2) == 0) - pstat.om = rep->value_int; - else if (strncmp(oc_string(rep->name), "sm", 2) == 0) - pstat.sm = rep->value_int; - break; - case STRING: - if (strncmp(oc_string(rep->name), "deviceuuid", 10) == 0) - oc_str_to_uuid(oc_string(rep->value_string), &doxm->deviceuuid); - else if (strncmp(oc_string(rep->name), "rowneruuid", 10) == 0) - oc_str_to_uuid(oc_string(rep->value_string), &doxm->rowneruuid); - break; - default: - break; - } - rep = rep->next; - } -} - -void -get_pstat(oc_request_t *request, oc_interface_mask_t interface) -{ - switch (interface) { - case OC_IF_BASELINE: { - oc_sec_encode_pstat(); - oc_send_response(request, OC_STATUS_OK); - } break; - default: - break; - } -} - -void -post_pstat(oc_request_t *request, oc_interface_mask_t interface) -{ - oc_sec_decode_pstat(request->request_payload); - oc_send_response(request, OC_STATUS_CHANGED); -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_pstat.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_pstat.h b/libs/iotivity/src/security/oc_pstat.h deleted file mode 100644 index 7189d52..0000000 --- a/libs/iotivity/src/security/oc_pstat.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_PSTAT_H_ -#define OC_PSTAT_H_ - -#include "oc_ri.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - bool isop; - int cm; - int tm; - int om; - int sm; -} oc_sec_pstat_t; - -bool oc_sec_provisioned(void); -void oc_sec_decode_pstat(oc_rep_t *rep); -void oc_sec_encode_pstat(void); -oc_sec_pstat_t *oc_sec_get_pstat(void); -void oc_sec_pstat_default(void); -void get_pstat(oc_request_t *request, oc_interface_mask_t interface); -void post_pstat(oc_request_t *request, oc_interface_mask_t interface); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_PSTAT_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_store.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_store.c b/libs/iotivity/src/security/oc_store.c deleted file mode 100644 index 15f8cca..0000000 --- a/libs/iotivity/src/security/oc_store.c +++ /dev/null @@ -1,158 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY -#include "oc_store.h" -#include "oc_acl.h" -#include "oc_core_res.h" -#include "oc_cred.h" -#include "oc_doxm.h" -#include "oc_pstat.h" -#include "port/oc_storage.h" - -void -oc_sec_load_doxm(void) -{ - long ret = 0; - size_t size = 512; - uint8_t buf[size]; - oc_rep_t *rep; - - if (oc_sec_provisioned()) { - ret = oc_storage_read("/doxm", buf, size); - if (ret > 0) { - oc_parse_rep(buf, ret, &rep); - oc_sec_decode_doxm(rep); - oc_free_rep(rep); - } - } - - if (ret <= 0) { - oc_sec_doxm_default(); - } - - oc_uuid_t *deviceuuid = oc_core_get_device_id(0); - oc_sec_doxm_t *doxm = oc_sec_get_doxm(); - memcpy(deviceuuid, &doxm->deviceuuid, sizeof(oc_uuid_t)); -} - -void -oc_sec_load_pstat(void) -{ - long ret = 0; - size_t size = 512; - uint8_t buf[size]; - oc_rep_t *rep; - - ret = oc_storage_read("/pstat", buf, size); - if (ret > 0) { - oc_parse_rep(buf, ret, &rep); - oc_sec_decode_pstat(rep); - oc_free_rep(rep); - } - - if (ret <= 0) { - oc_sec_pstat_default(); - } -} - -void -oc_sec_load_cred(void) -{ - long ret = 0; - size_t size = 1024; - uint8_t buf[size]; - oc_rep_t *rep; - - if (oc_sec_provisioned()) { - ret = oc_storage_read("/cred", buf, size); - - if (ret <= 0) - return; - - oc_parse_rep(buf, ret, &rep); - oc_sec_decode_cred(rep, NULL); - oc_free_rep(rep); - } -} - -void -oc_sec_load_acl(void) -{ - size_t size = 1024; - long ret = 0; - uint8_t buf[size]; - oc_rep_t *rep; - - oc_sec_acl_init(); - - if (oc_sec_provisioned()) { - ret = oc_storage_read("/acl", buf, size); - if (ret > 0) { - oc_parse_rep(buf, ret, &rep); - oc_sec_decode_acl(rep); - oc_free_rep(rep); - } - } - - if (ret <= 0) { - oc_sec_acl_default(); - } -} - -void -oc_sec_dump_state(void) -{ - uint8_t buf[1024]; - - /* pstat */ - oc_rep_new(buf, 1024); - oc_sec_encode_pstat(); - int size = oc_rep_finalize(); - if (size > 0) { - LOG("oc_store: encoded pstat size %d\n", size); - oc_storage_write("/pstat", buf, size); - } - - /* cred */ - oc_rep_new(buf, 1024); - oc_sec_encode_cred(); - size = oc_rep_finalize(); - if (size > 0) { - LOG("oc_store: encoded cred size %d\n", size); - oc_storage_write("/cred", buf, size); - } - - /* doxm */ - oc_rep_new(buf, 1024); - oc_sec_encode_doxm(); - size = oc_rep_finalize(); - if (size > 0) { - LOG("oc_store: encoded doxm size %d\n", size); - oc_storage_write("/doxm", buf, size); - } - - /* acl */ - oc_rep_new(buf, 1024); - oc_sec_encode_acl(); - size = oc_rep_finalize(); - if (size > 0) { - LOG("oc_store: encoded ACL size %d\n", size); - oc_storage_write("/acl", buf, size); - } -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_store.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_store.h b/libs/iotivity/src/security/oc_store.h deleted file mode 100644 index 077290d..0000000 --- a/libs/iotivity/src/security/oc_store.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_STORE_H_ -#define OC_STORE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void oc_sec_load_pstat(void); -void oc_sec_load_doxm(void); -void oc_sec_load_cred(void); -void oc_sec_load_acl(void); -void oc_sec_dump_state(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_STORE_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_svr.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_svr.c b/libs/iotivity/src/security/oc_svr.c deleted file mode 100644 index 8e44425..0000000 --- a/libs/iotivity/src/security/oc_svr.c +++ /dev/null @@ -1,51 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifdef OC_SECURITY - -#include "oc_svr.h" -#include "oc_acl.h" -#include "oc_api.h" -#include "oc_core_res.h" -#include "oc_cred.h" -#include "oc_doxm.h" -#include "oc_pstat.h" -#include "oc_ri.h" -#include "port/oc_log.h" - -// Multiple devices? -// What methods do sec resources support - -/* check resource properties */ -void -oc_sec_create_svr(void) -{ - oc_core_populate_resource(OCF_SEC_DOXM, "/oic/sec/doxm", "oic.sec.doxm", - OC_IF_BASELINE, OC_IF_BASELINE, - OC_ACTIVE | OC_SECURE | OC_DISCOVERABLE, get_doxm, - 0, post_doxm, 0, 0); - oc_core_populate_resource( - OCF_SEC_PSTAT, "/oic/sec/pstat", "oic.sec.pstat", OC_IF_BASELINE, - OC_IF_BASELINE, OC_ACTIVE | OC_SECURE, get_pstat, 0, post_pstat, 0, 0); - oc_core_populate_resource(OCF_SEC_ACL, "/oic/sec/acl", "oic.sec.acl", - OC_IF_BASELINE, OC_IF_BASELINE, - OC_ACTIVE | OC_SECURE, 0, 0, post_acl, 0, 0); - oc_core_populate_resource(OCF_SEC_CRED, "/oic/sec/cred", "oic.sec.cred", - OC_IF_BASELINE, OC_IF_BASELINE, - OC_ACTIVE | OC_SECURE, 0, 0, post_cred, 0, 0); -} - -#endif /* OC_SECURITY */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/security/oc_svr.h ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/security/oc_svr.h b/libs/iotivity/src/security/oc_svr.h deleted file mode 100644 index 70164ec..0000000 --- a/libs/iotivity/src/security/oc_svr.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -// Copyright (c) 2016 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ - -#ifndef OC_SVR_H -#define OC_SVR_H - -#ifdef __cplusplus -extern "C" { -#endif - -void oc_sec_create_svr(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_SVR_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/libs/iotivity/src/util/oc_etimer.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/util/oc_etimer.c b/libs/iotivity/src/util/oc_etimer.c deleted file mode 100644 index bf56f49..0000000 --- a/libs/iotivity/src/util/oc_etimer.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * Copyright (c) 2004, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels <a...@sics.se> - * - */ - -#include "oc_etimer.h" -#include "oc_process.h" - -static struct oc_etimer *timerlist; -static oc_clock_time_t next_expiration; - -OC_PROCESS(oc_etimer_process, "Event timer"); -/*---------------------------------------------------------------------------*/ -static void -update_time(void) -{ - oc_clock_time_t tdist; - oc_clock_time_t now; - struct oc_etimer *t; - - if (timerlist == NULL) { - next_expiration = 0; - } else { - now = oc_clock_time(); - t = timerlist; - /* Must calculate distance to next time into account due to wraps */ - tdist = t->timer.start + t->timer.interval - now; - for (t = t->next; t != NULL; t = t->next) { - if (t->timer.start + t->timer.interval - now < tdist) { - tdist = t->timer.start + t->timer.interval - now; - } - } - next_expiration = now + tdist; - } -} -/*---------------------------------------------------------------------------*/ -OC_PROCESS_THREAD(oc_etimer_process, ev, data) -{ - struct oc_etimer *t, *u; - - OC_PROCESS_BEGIN(); - - timerlist = NULL; - - while (1) { - OC_PROCESS_YIELD(); - - if (ev == OC_PROCESS_EVENT_EXITED) { - struct oc_process *p = data; - - while (timerlist != NULL && timerlist->p == p) { - timerlist = timerlist->next; - } - - if (timerlist != NULL) { - t = timerlist; - while (t->next != NULL) { - if (t->next->p == p) { - t->next = t->next->next; - } else - t = t->next; - } - } - continue; - } else if (ev != OC_PROCESS_EVENT_POLL) { - continue; - } - - again: - - u = NULL; - - for (t = timerlist; t != NULL; t = t->next) { - if (oc_timer_expired(&t->timer)) { - if (oc_process_post(t->p, OC_PROCESS_EVENT_TIMER, t) == - OC_PROCESS_ERR_OK) { - - /* Reset the process ID of the event timer, to signal that the - etimer has expired. This is later checked in the - oc_etimer_expired() function. */ - t->p = OC_PROCESS_NONE; - if (u != NULL) { - u->next = t->next; - } else { - timerlist = t->next; - } - t->next = NULL; - update_time(); - goto again; - } else { - oc_etimer_request_poll(); - } - } - u = t; - } - } - - OC_PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -oc_clock_time_t -oc_etimer_request_poll(void) -{ - oc_process_poll(&oc_etimer_process); - return oc_etimer_next_expiration_time(); -} -/*---------------------------------------------------------------------------*/ -static void -add_timer(struct oc_etimer *timer) -{ - struct oc_etimer *t; - - oc_etimer_request_poll(); - - if (timer->p != OC_PROCESS_NONE) { - for (t = timerlist; t != NULL; t = t->next) { - if (t == timer) { - /* Timer already on list, bail out. */ - timer->p = OC_PROCESS_CURRENT(); - update_time(); - return; - } - } - } - - /* Timer not on list. */ - timer->p = OC_PROCESS_CURRENT(); - timer->next = timerlist; - timerlist = timer; - - update_time(); -} -/*---------------------------------------------------------------------------*/ -void -oc_etimer_set(struct oc_etimer *et, oc_clock_time_t interval) -{ - oc_timer_set(&et->timer, interval); - add_timer(et); -} -/*---------------------------------------------------------------------------*/ -void -oc_etimer_reset_with_new_interval(struct oc_etimer *et, - oc_clock_time_t interval) -{ - oc_timer_reset(&et->timer); - et->timer.interval = interval; - add_timer(et); -} -/*---------------------------------------------------------------------------*/ -void -oc_etimer_reset(struct oc_etimer *et) -{ - oc_timer_reset(&et->timer); - add_timer(et); -} -/*---------------------------------------------------------------------------*/ -void -oc_etimer_restart(struct oc_etimer *et) -{ - oc_timer_restart(&et->timer); - add_timer(et); -} -/*---------------------------------------------------------------------------*/ -void -oc_etimer_adjust(struct oc_etimer *et, int timediff) -{ - et->timer.start += timediff; - update_time(); -} -/*---------------------------------------------------------------------------*/ -int -oc_etimer_expired(struct oc_etimer *et) -{ - return et->p == OC_PROCESS_NONE; -} -/*---------------------------------------------------------------------------*/ -oc_clock_time_t -oc_etimer_expiration_time(struct oc_etimer *et) -{ - return et->timer.start + et->timer.interval; -} -/*---------------------------------------------------------------------------*/ -oc_clock_time_t -oc_etimer_start_time(struct oc_etimer *et) -{ - return et->timer.start; -} -/*---------------------------------------------------------------------------*/ -int -oc_etimer_pending(void) -{ - return timerlist != NULL; -} -/*---------------------------------------------------------------------------*/ -oc_clock_time_t -oc_etimer_next_expiration_time(void) -{ - return oc_etimer_pending() ? next_expiration : 0; -} -/*---------------------------------------------------------------------------*/ -void -oc_etimer_stop(struct oc_etimer *et) -{ - struct oc_etimer *t; - - /* First check if et is the first event timer on the list. */ - if (et == timerlist) { - timerlist = timerlist->next; - update_time(); - } else { - /* Else walk through the list and try to find the item before the - et timer. */ - for (t = timerlist; t != NULL && t->next != et; t = t->next) - ; - - if (t != NULL) { - /* We've found the item before the event timer that we are about - to remove. We point the items next pointer to the event after - the removed item. */ - t->next = et->next; - - update_time(); - } - } - - /* Remove the next pointer from the item to be removed. */ - et->next = NULL; - /* Set the timer as expired */ - et->p = OC_PROCESS_NONE; -} -/*---------------------------------------------------------------------------*/ -/** @} */