├── .gitignore ├── .gitmodules ├── .gitreview ├── IoTivityConstrained-Arch.png ├── LICENSE.md ├── README.rst ├── api ├── c-timestamp │ ├── .travis.yml │ ├── Makefile │ ├── README.md │ ├── t │ │ ├── compare.c │ │ ├── format.c │ │ ├── parse_malformed.c │ │ ├── parse_wellformed.c │ │ ├── tap.c │ │ ├── tap.h │ │ ├── tm.c │ │ └── valid.c │ ├── timestamp.h │ ├── timestamp_compare.c │ ├── timestamp_format.c │ ├── timestamp_parse.c │ ├── timestamp_tm.c │ └── timestamp_valid.c ├── oc_base64.c ├── oc_blockwise.c ├── oc_buffer.c ├── oc_client_api.c ├── oc_clock.c ├── oc_collection.c ├── oc_core_res.c ├── oc_discovery.c ├── oc_endpoint.c ├── oc_events.h ├── oc_helpers.c ├── oc_introspection.c ├── oc_main.c ├── oc_network_events.c ├── oc_rep.c ├── oc_ri.c ├── oc_server_api.c ├── oc_session_events.c ├── oc_uuid.c └── unittest │ ├── RITest.cpp │ ├── base64test.cpp │ ├── coreresourcetest.cpp │ ├── ocapitest.cpp │ ├── reptest.cpp │ └── uuidtest.cpp ├── apps ├── SmartLock.json ├── client_block_linux.c ├── client_collections_linux.c ├── client_contiki.c ├── client_linux.c ├── client_multithread_linux.c ├── client_openthread.c ├── client_riot.c ├── client_zephyr.c ├── multi_device_client_linux.c ├── multi_device_server_linux.c ├── sensor_interrupt_server_zephyr.c ├── server_block_linux.c ├── server_collections_linux.c ├── server_contiki.c ├── server_linux.c ├── server_multithread_linux.c ├── server_openthread.c ├── server_riot.c ├── server_zephyr.c ├── simpleclient.c ├── simpleclient_windows.c ├── simpleserver.c ├── simpleserver_pki.c ├── simpleserver_windows.c ├── smart_home_server_linux.c ├── smart_lock_linux.c └── temp_sensor_client_linux.c ├── include ├── oc_api.h ├── oc_base64.h ├── oc_blockwise.h ├── oc_buffer.h ├── oc_buffer_settings.h ├── oc_client_state.h ├── oc_clock_util.h ├── oc_collection.h ├── oc_core_res.h ├── oc_discovery.h ├── oc_endpoint.h ├── oc_helpers.h ├── oc_introspection.h ├── oc_network_events.h ├── oc_network_monitor.h ├── oc_obt.h ├── oc_pki.h ├── oc_rep.h ├── oc_ri.h ├── oc_session_events.h ├── oc_signal_event_loop.h ├── oc_uuid.h └── server_introspection.dat.h ├── messaging └── coap │ ├── coap.c │ ├── coap.h │ ├── coap_signal.c │ ├── coap_signal.h │ ├── conf.h │ ├── constants.h │ ├── engine.c │ ├── engine.h │ ├── observe.c │ ├── observe.h │ ├── oc_coap.h │ ├── separate.c │ ├── separate.h │ ├── transactions.c │ ├── transactions.h │ └── unittest │ └── coapsignaltest.cpp ├── onboarding_tool └── obtmain.c ├── patches ├── 01_mbedtls_dynamic-content-length_p1.patch ├── 02_mbedtls_dynamic-content-length_p2.patch ├── 03_mbedtls_dynamic-content-length_p3.patch ├── 04_mbedtls_dynamic-content-length_p4.patch ├── 05_mbedtls_ocf-samsung.patch ├── 06_mbedtls_ocf-microsoft.patch ├── 07_mbedtls_constrained.patch ├── 08_mbedtls_content_len.patch └── 09_mbedtls_C99.patch ├── port ├── android │ ├── Makefile │ ├── abort.c │ ├── clock.c │ ├── ifaddrs-android.c │ ├── ifaddrs-android.h │ ├── ipadapter.c │ ├── ipcontext.h │ ├── oc_config.h │ ├── random.c │ └── storage.c ├── contiki │ ├── Makefile │ ├── README │ ├── abort.c │ ├── ipadapter.c │ ├── oc_clock.c │ ├── oc_config.h │ ├── oc_random.c │ └── storage.c ├── freertos │ ├── Makefile │ ├── abort.c │ ├── clock.c │ ├── ipadapter.c │ ├── ipcontext.h │ ├── oc_config.h │ ├── random.c │ ├── storage.c │ ├── tcpadapter.c │ └── tcpadapter.h ├── linux │ ├── Makefile │ ├── abort.c │ ├── clock.c │ ├── iotivity-constrained-client-server.pc.in │ ├── iotivity-constrained-client.pc.in │ ├── iotivity-constrained-server.pc.in │ ├── ipadapter.c │ ├── ipcontext.h │ ├── oc_config.h │ ├── random.c │ ├── storage.c │ ├── tcpadapter.c │ └── tcpadapter.h ├── oc_assert.h ├── oc_clock.h ├── oc_connectivity.h ├── oc_log.h ├── oc_network_events_mutex.h ├── oc_random.h ├── oc_storage.h ├── openthread │ ├── Makefile │ ├── Makefile-efr32 │ ├── Makefile-posix │ ├── Makefile-samr21 │ ├── README │ ├── abort.c │ ├── clock.c │ ├── ipadapter.c │ ├── ocInstance.cpp │ ├── ocInstance.hpp │ ├── oc_config.h │ ├── oc_instance.h │ ├── random.c │ ├── storage.c │ └── uart.c ├── riot │ ├── Makefile │ ├── README │ ├── abort.c │ ├── clock.c │ ├── ipadapter.c │ ├── oc_config.h │ ├── random.c │ └── storage.c ├── tizenrt │ ├── Makefile │ ├── abort.c │ ├── clock.c │ ├── ipadapter.c │ ├── ipcontext.h │ ├── oc_config.h │ ├── random.c │ ├── storage.c │ ├── tcpadapter.c │ └── tcpadapter.h ├── unittest │ ├── clocktest.cpp │ ├── connectivitytest.cpp │ └── storagetest.cpp ├── windows │ ├── abort.c │ ├── clock.c │ ├── ipadapter.c │ ├── oc_config.h │ ├── patch-mbedtls.bat │ ├── random.c │ ├── storage.c │ └── vs2015 │ │ ├── IoTivity-Constrained.sln │ │ ├── IoTivity-Constrained.vcxproj │ │ ├── IoTivity-Constrained.vcxproj.filters │ │ ├── SimpleClient.vcxproj │ │ ├── SimpleClient.vcxproj.user │ │ ├── SimpleServer.vcxproj │ │ └── SimpleServer.vcxproj.user └── zephyr │ ├── Makefile │ ├── prj.conf │ ├── prj_bt.conf │ ├── prj_secure.conf │ └── src │ ├── Makefile │ ├── abort.c │ ├── assert.h │ ├── clock.c │ ├── ipadapter.c │ ├── oc_config.h │ ├── random.c │ └── storage.c ├── security ├── oc_acl.c ├── oc_acl.h ├── oc_certs.c ├── oc_certs.h ├── oc_cred.c ├── oc_cred.h ├── oc_csr.c ├── oc_csr.h ├── oc_doxm.c ├── oc_doxm.h ├── oc_keypair.c ├── oc_keypair.h ├── oc_obt.c ├── oc_pki.c ├── oc_pstat.c ├── oc_pstat.h ├── oc_roles.c ├── oc_roles.h ├── oc_sp.c ├── oc_sp.h ├── oc_store.c ├── oc_store.h ├── oc_svr.c ├── oc_svr.h ├── oc_tls.c ├── oc_tls.h └── unittest │ └── tlstest.cpp ├── tests ├── Makefile ├── auto_build.py ├── auto_build.sh ├── client_get_linux.c ├── client_init_linux.c ├── itc │ └── ri │ │ ├── Makefile │ │ ├── helper │ │ └── RIHelper.cpp │ │ ├── include │ │ └── RIHelper.h │ │ └── src │ │ └── RIGeneralIntegrationTest.cpp ├── port │ ├── freertos │ │ └── Makefile │ ├── linux │ │ └── coverage_report.sh │ └── tizenrt │ │ ├── Makefile │ │ ├── iotivity-constrained.Kconfig │ │ └── iotivity-constrained.mk ├── server_init_linux.c └── test.h ├── tools ├── README ├── _clang-format ├── check-style ├── check.py ├── doxygen.ini └── pre-commit └── util ├── oc_etimer.c ├── oc_etimer.h ├── oc_list.c ├── oc_list.h ├── oc_mem_trace.c ├── oc_mem_trace.h ├── oc_memb.c ├── oc_memb.h ├── oc_mmem.c ├── oc_mmem.h ├── oc_process.c ├── oc_process.h ├── oc_timer.c ├── oc_timer.h └── pt ├── lc-addrlabels.h ├── lc-switch.h ├── lc.h ├── pt-sem.h └── pt.h /.gitignore: -------------------------------------------------------------------------------- 1 | port/linux/client 2 | port/linux/server 3 | port/linux/temp_sensor 4 | port/linux/simpleclient 5 | port/linux/simpleserver 6 | port/linux/server_collections_linux 7 | port/linux/client_collections_linux 8 | port/linux/client_block_linux 9 | port/linux/server_block_linux 10 | port/linux/smart_home_server_linux 11 | port/linux/multi_device_client 12 | port/linux/multi_device_server 13 | port/linux/onboarding_tool 14 | port/linux/server_multithread_linux 15 | port/linux/client_multithread_linux 16 | port/linux/libiotivity-constrained-client.* 17 | port/linux/libiotivity-constrained-server.* 18 | port/linux/libiotivity-constrained-client-server.* 19 | port/linux/iotivity-constrained-server.pc 20 | port/linux/iotivity-constrained-client.pc 21 | port/linux/iotivity-constrained-client-server.pc 22 | port/linux/tests/* 23 | port/linux/obj/ 24 | port/linux/onboarding_tool_creds/ 25 | port/linux/smart_lock 26 | port/windows/vs2015/.vs/ 27 | port/windows/vs2015/Debug/ 28 | port/windows/vs2015/Release/ 29 | port/windows/vs2015/simpleserver_creds/ 30 | port/windows/vs2015/*.VC.opendb 31 | port/windows/vs2015/*.VC.db 32 | port/windows/vs2015/*.vcxproj.user 33 | port/zephyr/outdir/ 34 | port/contiki/*.a 35 | port/contiki/*.map 36 | port/contiki/obj_native/ 37 | port/contiki/*.native 38 | port/contiki/symbols.* 39 | port/openthread/output 40 | *.o 41 | *.cmd 42 | *.tmp 43 | .clang-format 44 | _clang-format 45 | port/linux/platformtest 46 | port/linux/storage_test 47 | 48 | #creds files 49 | port/linux/client_creds 50 | port/linux/server_creds 51 | port/linux/temp_sensor_creds 52 | port/linux/simpleclient_creds 53 | port/linux/simpleserver_creds 54 | port/linux/server_collections_linux_creds 55 | port/linux/client_collections_linux_creds 56 | port/linux/smart_home_server_linux_creds 57 | port/linux/multi_device_client_creds 58 | port/linux/multi_device_server_creds 59 | port/linux/server_multithread_linux_creds 60 | port/linux/client_multithread_linux_creds 61 | 62 | #vscode setting files 63 | .vscode 64 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/tinycbor"] 2 | path = deps/tinycbor 3 | url = https://github.com/intel/tinycbor.git 4 | [submodule "deps/mbedtls"] 5 | path = deps/mbedtls 6 | url = https://github.com/ARMmbed/mbedtls.git 7 | [submodule "deps/gtest"] 8 | path = deps/gtest 9 | url = https://github.com/google/googletest.git 10 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=gerrit.iotivity.org 3 | port=29418 4 | project=iotivity-constrained 5 | -------------------------------------------------------------------------------- /IoTivityConstrained-Arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotivity/iotivity-constrained/b5641b089eb2e8076fe4b6cb3d237263e6980b99/IoTivityConstrained-Arch.png -------------------------------------------------------------------------------- /api/c-timestamp/.travis.yml: -------------------------------------------------------------------------------- 1 | language: perl 2 | install: "perl -V" 3 | before_script: 4 | - "cpanm -n Test::Harness" 5 | - sudo pip install cpp-coveralls --use-mirrors 6 | script: "make test" 7 | after_success: 8 | - "make clean" 9 | - "make gcov" 10 | - coveralls --exclude t 11 | notifications: 12 | recipients: 13 | - chansen@cpan.org 14 | email: 15 | on_success: change 16 | on_failure: always 17 | -------------------------------------------------------------------------------- /api/c-timestamp/Makefile: -------------------------------------------------------------------------------- 1 | CC = cc 2 | GCOV = gcov 3 | CFLAGS = $(DCFLAGS) -Wall -I. -I.. 4 | LDFLAGS += -lc $(DLDFLAGS) 5 | 6 | SOURCES = \ 7 | timestamp_compare.c \ 8 | timestamp_format.c \ 9 | timestamp_parse.c \ 10 | timestamp_valid.c \ 11 | timestamp_tm.c 12 | 13 | OBJECTS = \ 14 | timestamp_compare.o \ 15 | timestamp_format.o \ 16 | timestamp_parse.o \ 17 | timestamp_valid.o \ 18 | timestamp_tm.o 19 | 20 | HARNESS_OBJS = \ 21 | t/valid.o \ 22 | t/compare.o \ 23 | t/format.o \ 24 | t/parse_wellformed.o \ 25 | t/parse_malformed.o \ 26 | t/tm.o 27 | 28 | HARNESS_EXES = \ 29 | t/valid.t \ 30 | t/compare.t \ 31 | t/format.t \ 32 | t/parse_wellformed.t \ 33 | t/parse_malformed.t \ 34 | t/tm.t 35 | 36 | HARNESS_DEPS = \ 37 | $(OBJECTS) \ 38 | t/tap.o 39 | 40 | .SUFFIXES: 41 | .SUFFIXES: .o .c .t 42 | 43 | .PHONY: check-asan test gcov cover clean 44 | 45 | .o.t: 46 | $(CC) $(LDFLAGS) $< $(HARNESS_DEPS) -o $@ 47 | 48 | t/valid.o: \ 49 | $(HARNESS_DEPS) t/valid.c 50 | 51 | t/compare.o: \ 52 | $(HARNESS_DEPS) t/compare.c 53 | 54 | t/format.o: \ 55 | $(HARNESS_DEPS) t/format.c 56 | 57 | t/parse_wellformed.o: \ 58 | $(HARNESS_DEPS) t/parse_wellformed.c 59 | 60 | t/parse_malformed.o: \ 61 | $(HARNESS_DEPS) t/parse_malformed.c 62 | 63 | t/tm.o: \ 64 | $(HARNESS_DEPS) t/tm.c 65 | 66 | test: $(HARNESS_EXES) 67 | @prove $(HARNESS_EXES) 68 | 69 | check-asan: 70 | @$(MAKE) DCFLAGS="-O1 -g -fsanitize=address -fno-omit-frame-pointer" \ 71 | DLDFLAGS="-g -fsanitize=address" test 72 | 73 | gcov: 74 | @$(MAKE) DCFLAGS="-O0 -g -coverage" DLDFLAGS="-coverage" test 75 | @$(GCOV) $(SOURCES) 76 | 77 | cover: 78 | @$(MAKE) DCFLAGS="-O0 -g --coverage" DLDFLAGS="-coverage" test 79 | @$(GCOV) -abc $(SOURCES) 80 | @gcov2perl *.gcov 81 | @cover --no-gcov 82 | 83 | clean: 84 | rm -f $(HARNESS_DEPS) $(HARNESS_OBJS) $(HARNESS_EXES) *.gc{ov,da,no} t/*.gc{ov,da,no} 85 | 86 | -------------------------------------------------------------------------------- /api/c-timestamp/README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/chansen/c-timestamp.png?branch=master)](https://travis-ci.org/chansen/c-timestamp) [![Coverage Status](https://coveralls.io/repos/chansen/c-timestamp/badge.png)](https://coveralls.io/r/chansen/c-timestamp) 2 | 3 | timestamp 4 | ========= 5 | 6 | 7 | ```c 8 | 9 | typedef struct { 10 | int64_t sec; /* Number of seconds since the epoch of 1970-01-01T00:00:00Z */ 11 | int32_t nsec; /* Nanoseconds [0, 999999999] */ 12 | int16_t offset; /* Offset from UTC in minutes [-1439, 1439] */ 13 | } timestamp_t; 14 | 15 | int timestamp_parse (const char *str, size_t len, timestamp_t *tsp); 16 | size_t timestamp_format (char *dst, size_t len, const timestamp_t *tsp); 17 | size_t timestamp_format_precision (char *dst, size_t len, const timestamp_t *tsp, int precision); 18 | int timestamp_compare (const timestamp_t *tsp1, const timestamp_t *tsp2); 19 | bool timestamp_valid (const timestamp_t *tsp); 20 | struct tm * timestamp_to_tm_utc (const timestamp_t *tsp, struct tm *tmp); 21 | struct tm * timestamp_to_tm_local (const timestamp_t *tsp, struct tm *tmp); 22 | 23 | 24 | ``` 25 | 26 | -------------------------------------------------------------------------------- /api/c-timestamp/t/compare.c: -------------------------------------------------------------------------------- 1 | #include "tap.h" 2 | #include "timestamp.h" 3 | #include 4 | 5 | int 6 | main() 7 | { 8 | timestamp_t t1, t2; 9 | 10 | t1.sec = t2.sec = 0; 11 | t1.nsec = t2.nsec = 0; 12 | t1.offset = t2.offset = 0; 13 | cmp_ok(timestamp_compare(&t1, &t2), "==", 0, "t1 == t2"); 14 | 15 | t1.sec = 1; 16 | cmp_ok(timestamp_compare(&t1, &t2), ">", 0, "t1 > t2"); 17 | cmp_ok(timestamp_compare(&t2, &t1), "<", 0, "t1 < t2"); 18 | 19 | t1.sec = 0; 20 | t1.nsec = 1; 21 | cmp_ok(timestamp_compare(&t1, &t2), ">", 0, "t1 > t2"); 22 | cmp_ok(timestamp_compare(&t2, &t1), "<", 0, "t2 < t1"); 23 | 24 | done_testing(); 25 | } 26 | -------------------------------------------------------------------------------- /api/c-timestamp/t/tm.c: -------------------------------------------------------------------------------- 1 | #include "tap.h" 2 | #include "timestamp.h" 3 | #include 4 | 5 | int 6 | main() 7 | { 8 | timestamp_t ts; 9 | struct tm tm; 10 | 11 | { /* 0001-01-01T12:30:45Z */ 12 | ts.sec = INT64_C(-62135551755); 13 | ts.nsec = 0; 14 | ts.offset = 0; 15 | 16 | memset(&tm, 0, sizeof(tm)); 17 | ok(timestamp_to_tm_utc(&ts, &tm) != NULL); 18 | cmp_ok(tm.tm_year, "==", -1899, "tm_year"); 19 | cmp_ok(tm.tm_mon, "==", 0, "tm_mon"); 20 | cmp_ok(tm.tm_mday, "==", 1, "tm_mday"); 21 | cmp_ok(tm.tm_yday, "==", 0, "tm_yday"); 22 | cmp_ok(tm.tm_wday, "==", 1, "tm_wday"); 23 | cmp_ok(tm.tm_hour, "==", 12, "tm_hour"); 24 | cmp_ok(tm.tm_min, "==", 30, "tm_min"); 25 | cmp_ok(tm.tm_sec, "==", 45, "tm_sec"); 26 | } 27 | 28 | { /* 0001-01-01T12:30:45+02:00 */ 29 | ts.sec = INT64_C(-62135558955); 30 | ts.nsec = 0; 31 | ts.offset = 120; 32 | 33 | memset(&tm, 0, sizeof(tm)); 34 | ok(timestamp_to_tm_local(&ts, &tm) != NULL); 35 | cmp_ok(tm.tm_year, "==", -1899, "tm_year"); 36 | cmp_ok(tm.tm_mon, "==", 0, "tm_mon"); 37 | cmp_ok(tm.tm_mday, "==", 1, "tm_mday"); 38 | cmp_ok(tm.tm_yday, "==", 0, "tm_yday"); 39 | cmp_ok(tm.tm_wday, "==", 1, "tm_wday"); 40 | cmp_ok(tm.tm_hour, "==", 12, "tm_hour"); 41 | cmp_ok(tm.tm_min, "==", 30, "tm_min"); 42 | cmp_ok(tm.tm_sec, "==", 45, "tm_sec"); 43 | } 44 | 45 | { /* 1970-12-31T23:59:59Z */ 46 | ts.sec = INT64_C(31535999); 47 | ts.nsec = 0; 48 | ts.offset = 0; 49 | 50 | memset(&tm, 0, sizeof(tm)); 51 | ok(timestamp_to_tm_utc(&ts, &tm) != NULL); 52 | cmp_ok(tm.tm_year, "==", 70, "tm_year"); 53 | cmp_ok(tm.tm_mon, "==", 11, "tm_mon"); 54 | cmp_ok(tm.tm_mday, "==", 31, "tm_mday"); 55 | cmp_ok(tm.tm_yday, "==", 364, "tm_yday"); 56 | cmp_ok(tm.tm_wday, "==", 4, "tm_wday"); 57 | cmp_ok(tm.tm_hour, "==", 23, "tm_hour"); 58 | cmp_ok(tm.tm_min, "==", 59, "tm_min"); 59 | cmp_ok(tm.tm_sec, "==", 59, "tm_sec"); 60 | } 61 | 62 | done_testing(); 63 | } 64 | -------------------------------------------------------------------------------- /api/c-timestamp/t/valid.c: -------------------------------------------------------------------------------- 1 | #include "tap.h" 2 | #include "timestamp.h" 3 | #include 4 | 5 | int 6 | main() 7 | { 8 | timestamp_t ts; 9 | 10 | ts.sec = 0; 11 | ts.offset = 0; 12 | ts.nsec = -1; 13 | ok(!timestamp_valid(&ts), "nsec out of range"); 14 | 15 | ts.nsec = 1000000000; 16 | ok(!timestamp_valid(&ts), "nsec out of range"); 17 | 18 | ts.nsec = 0; 19 | ts.offset = -23 * 60 - 60; 20 | ok(!timestamp_valid(&ts), "offset out of range"); 21 | 22 | ts.offset = +23 * 60 + 60; 23 | ok(!timestamp_valid(&ts), "offset out of range"); 24 | 25 | ts.offset = 0; 26 | ts.sec = INT64_C(-62135596801); /* 0000-12-31T23:59:59Z */ 27 | ok(!timestamp_valid(&ts), "sec out of range"); 28 | ts.sec = INT64_C(253402387140); /* 10000-01-01T23:59:00Z */ 29 | ok(!timestamp_valid(&ts), "sec out of range"); 30 | 31 | done_testing(); 32 | } 33 | -------------------------------------------------------------------------------- /api/c-timestamp/timestamp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Christian Hansen 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this 11 | * list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef __TIMESTAMP_H__ 31 | #define __TIMESTAMP_H__ 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | typedef struct 42 | { 43 | int64_t sec; /* Number of seconds since the epoch of 1970-01-01T00:00:00Z */ 44 | int32_t nsec; /* Nanoseconds [0, 999999999] */ 45 | int16_t offset; /* Offset from UTC in minutes [-1439, 1439] */ 46 | } timestamp_t; 47 | 48 | int timestamp_parse(const char *str, size_t len, timestamp_t *tsp); 49 | size_t timestamp_format(char *dst, size_t len, const timestamp_t *tsp); 50 | size_t timestamp_format_precision(char *dst, size_t len, const timestamp_t *tsp, 51 | int precision); 52 | int timestamp_compare(const timestamp_t *tsp1, const timestamp_t *tsp2); 53 | bool timestamp_valid(const timestamp_t *tsp); 54 | struct tm *timestamp_to_tm_utc(const timestamp_t *tsp, struct tm *tmp); 55 | struct tm *timestamp_to_tm_local(const timestamp_t *tsp, struct tm *tmp); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | #endif 61 | -------------------------------------------------------------------------------- /api/c-timestamp/timestamp_compare.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Christian Hansen 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this 11 | * list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #include "timestamp.h" 31 | 32 | int 33 | timestamp_compare(const timestamp_t *t1, const timestamp_t *t2) 34 | { 35 | if (t1->sec < t2->sec) 36 | return -1; 37 | if (t1->sec > t2->sec) 38 | return 1; 39 | if (t1->nsec < t2->nsec) 40 | return -1; 41 | if (t1->nsec > t2->nsec) 42 | return 1; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /api/c-timestamp/timestamp_valid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Christian Hansen 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this 11 | * list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | * FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #include "timestamp.h" 31 | 32 | #define MIN_SEC INT64_C(-62135596800) /* 0001-01-01T00:00:00 */ 33 | #define MAX_SEC INT64_C(253402300799) /* 9999-12-31T23:59:59 */ 34 | 35 | bool 36 | timestamp_valid(const timestamp_t *tsp) 37 | { 38 | const int64_t sec = tsp->sec + tsp->offset * 60; 39 | if (sec < MIN_SEC || sec > MAX_SEC || tsp->nsec < 0 || 40 | tsp->nsec > 999999999 || tsp->offset < -1439 || tsp->offset > 1439) 41 | return false; 42 | return true; 43 | } 44 | -------------------------------------------------------------------------------- /api/oc_clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2019 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_clock.h" 18 | #include "c-timestamp/timestamp.h" 19 | #include "port/oc_log.h" 20 | 21 | size_t 22 | oc_clock_time_rfc3339(char *out_buf, size_t out_buf_len) 23 | { 24 | return oc_clock_encode_time_rfc3339(oc_clock_time(), out_buf, out_buf_len); 25 | } 26 | 27 | size_t 28 | oc_clock_encode_time_rfc3339(oc_clock_time_t time, char *out_buf, 29 | size_t out_buf_len) 30 | { 31 | timestamp_t now_t = { 0 }; 32 | 33 | now_t.sec = (int64_t)(time / OC_CLOCK_SECOND); 34 | now_t.nsec = (int32_t)((time % OC_CLOCK_SECOND) * (1.e09 / OC_CLOCK_SECOND)); 35 | 36 | return timestamp_format(out_buf, out_buf_len, &now_t); 37 | } 38 | 39 | oc_clock_time_t 40 | oc_clock_parse_time_rfc3339(const char *in_buf, size_t in_buf_len) 41 | { 42 | timestamp_t in_time = { 0 }; 43 | 44 | int ret = timestamp_parse(in_buf, in_buf_len, &in_time); 45 | 46 | if (ret != 0) { 47 | OC_ERR("error parsing time in RFC3339 formatted string"); 48 | return 0; 49 | } 50 | 51 | oc_clock_time_t t = 52 | ((in_time.sec * 1.e09) + in_time.nsec) * OC_CLOCK_SECOND / 1.e09; 53 | 54 | return t; 55 | } 56 | -------------------------------------------------------------------------------- /api/oc_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_EVENTS_H 18 | #define OC_EVENTS_H 19 | 20 | #include "util/oc_process.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | typedef enum { 28 | INBOUND_NETWORK_EVENT, 29 | UDP_TO_TLS_EVENT, 30 | INIT_TLS_CONN_EVENT, 31 | RI_TO_TLS_EVENT, 32 | INBOUND_RI_EVENT, 33 | OUTBOUND_NETWORK_EVENT, 34 | TLS_READ_DECRYPTED_DATA, 35 | TLS_WRITE_APPLICATION_DATA, 36 | INTERFACE_DOWN, 37 | INTERFACE_UP, 38 | __NUM_OC_EVENT_TYPES__ 39 | } oc_events_t; 40 | 41 | extern oc_process_event_t oc_events[]; 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* OC_EVENTS_H */ 48 | -------------------------------------------------------------------------------- /api/unittest/coreresourcetest.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * 3 | * Copyright 2018 GRANITE RIVER LABS All Rights Reserved. 4 | * 5 | * 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "oc_core_res.h" 27 | #include "oc_api.h" 28 | #include "oc_helpers.h" 29 | 30 | #define DEVICE_URI "/oic/d" 31 | #define DEVICE_TYPE "oic.d.light" 32 | #define MANUFACTURER_NAME "Samsung" 33 | #define DEVICE_NAME "Table Lamp" 34 | #define OCF_SPEC_VERSION "ocf.1.0.0" 35 | #define OCF_DATA_MODEL_VERSION "ocf.res.1.0.0" 36 | 37 | class TestCoreResource: public testing::Test 38 | { 39 | protected: 40 | virtual void SetUp() 41 | { 42 | oc_core_init(); 43 | #ifndef OC_SECURITY 44 | oc_random_init(); 45 | #endif /* !OC_SECURITY */ 46 | } 47 | virtual void TearDown() 48 | { 49 | oc_core_shutdown(); 50 | #ifndef OC_SECURITY 51 | oc_random_destroy(); 52 | #endif /* !OC_SECURITY */ 53 | } 54 | }; 55 | 56 | TEST_F(TestCoreResource, InitPlatform_P) 57 | { 58 | int oc_platform_info; 59 | 60 | oc_platform_info = oc_init_platform(MANUFACTURER_NAME, NULL, NULL); 61 | EXPECT_EQ(0, oc_platform_info); 62 | } 63 | 64 | TEST_F(TestCoreResource, CoreInitPlatform_P) 65 | { 66 | oc_platform_info_t *oc_platform_info; 67 | 68 | oc_platform_info = oc_core_init_platform(MANUFACTURER_NAME, NULL, NULL); 69 | EXPECT_EQ(strlen(MANUFACTURER_NAME), oc_string_len(oc_platform_info->mfg_name)); 70 | } 71 | 72 | TEST_F(TestCoreResource, CoreDevice_P) 73 | { 74 | int numcoredevice; 75 | oc_device_info_t *addcoredevice; 76 | 77 | addcoredevice = oc_core_add_new_device(DEVICE_URI, DEVICE_TYPE, DEVICE_NAME, 78 | OCF_SPEC_VERSION, OCF_DATA_MODEL_VERSION, NULL, NULL); 79 | ASSERT_NE(addcoredevice, NULL); 80 | numcoredevice = oc_core_get_num_devices(); 81 | EXPECT_EQ(1, numcoredevice); 82 | oc_connectivity_shutdown(0); 83 | } 84 | 85 | TEST_F(TestCoreResource, CoreGetResource_P) 86 | { 87 | oc_core_init_platform(MANUFACTURER_NAME, NULL, NULL); 88 | 89 | char uri[] = "/oic/p"; 90 | oc_resource_t *res = oc_core_get_resource_by_uri(uri, 0); 91 | 92 | ASSERT_NE(res, NULL); 93 | EXPECT_EQ(strlen(uri), oc_string_len(res->uri)); 94 | } 95 | -------------------------------------------------------------------------------- /api/unittest/uuidtest.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************/ 20 | 21 | #include 22 | #include "gtest/gtest.h" 23 | 24 | #include "oc_uuid.h" 25 | 26 | #define UUID "12345678123412341234123456789012" 27 | 28 | TEST(UUIDGeneration, StrToUUIDTest_P) 29 | { 30 | oc_uuid_t uuid; 31 | memset(&uuid, 0, sizeof(oc_uuid_t)); 32 | oc_uuid_t uuidTemp = uuid; 33 | oc_str_to_uuid(UUID, &uuid); 34 | EXPECT_NE(uuid.id, uuidTemp.id); 35 | } 36 | -------------------------------------------------------------------------------- /apps/SmartLock.json: -------------------------------------------------------------------------------- 1 | { 2 | "device": "SmartLock", 3 | "company": "Intel Corporation", 4 | "role": "Client", 5 | "supportedVerticalProfile": [ 6 | "Smart Home" 7 | ], 8 | "supportedDeviceTypes": [ 9 | "oic.d.smartlock" 10 | ], 11 | "icv": "ocf.1.0.0", 12 | "dmv": "ocf.res.1.3.0", 13 | "acceptVersion": [ 14 | "1.0.0" 15 | ], 16 | "resources": [], 17 | "OTM": [ 18 | "oic.sec.doxm.jw" 19 | ], 20 | "contentFormatVersion": [ 21 | "1.0.0" 22 | ], 23 | "multiValueQuerySupport": false, 24 | "sct": 1, 25 | "observableOICRES": false, 26 | "persistentDeviceuuid": false 27 | } -------------------------------------------------------------------------------- /include/oc_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_BUFFER_H 18 | #define OC_BUFFER_H 19 | 20 | #include "port/oc_connectivity.h" 21 | #include "util/oc_memb.h" 22 | #include "util/oc_process.h" 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | OC_PROCESS_NAME(message_buffer_handler); 31 | oc_message_t *oc_allocate_message(void); 32 | void oc_set_buffers_avail_cb(oc_memb_buffers_avail_callback_t cb); 33 | 34 | oc_message_t *oc_allocate_message_from_pool(struct oc_memb *pool); 35 | 36 | oc_message_t *oc_internal_allocate_outgoing_message(void); 37 | 38 | void oc_message_add_ref(oc_message_t *message); 39 | void oc_message_unref(oc_message_t *message); 40 | 41 | void oc_recv_message(oc_message_t *message); 42 | void oc_send_message(oc_message_t *message); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* OC_BUFFER_H */ 49 | -------------------------------------------------------------------------------- /include/oc_buffer_settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_BUFFER_SETTINGS_H 18 | #define OC_BUFFER_SETTINGS_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | int oc_set_mtu_size(size_t mtu_size); 26 | long oc_get_mtu_size(void); 27 | void oc_set_max_app_data_size(size_t size); 28 | long oc_get_max_app_data_size(void); 29 | long oc_get_block_size(void); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* OC_BUFFER_SETTINGS_H */ 36 | -------------------------------------------------------------------------------- /include/oc_clock_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2019 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_CLOCK_UTIL_H 18 | #define OC_CLOCK_UTIL_H 19 | 20 | #include "oc_config.h" 21 | #include 22 | 23 | size_t oc_clock_time_rfc3339(char *out_buf, size_t out_buf_len); 24 | 25 | size_t oc_clock_encode_time_rfc3339(oc_clock_time_t time, char *out_buf, 26 | size_t out_buf_len); 27 | 28 | oc_clock_time_t oc_clock_parse_time_rfc3339(const char *in_buf, 29 | size_t in_buf_len); 30 | 31 | #endif /* OC_CLOCK_UTIL_H */ 32 | -------------------------------------------------------------------------------- /include/oc_collection.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_COLLECTION_H 18 | #define OC_COLLECTION_H 19 | 20 | #include "oc_ri.h" 21 | #include "util/oc_list.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | struct oc_link_s 29 | { 30 | struct oc_link_s *next; 31 | oc_resource_t *resource; 32 | oc_string_t ins; 33 | oc_string_array_t rel; 34 | }; 35 | 36 | struct oc_collection_s 37 | { 38 | struct oc_collection_s *next; 39 | size_t device; 40 | oc_string_t name; 41 | oc_string_t uri; 42 | oc_string_array_t types; 43 | oc_interface_mask_t interfaces; 44 | oc_interface_mask_t default_interface; 45 | oc_resource_properties_t properties; 46 | oc_request_handler_t get_handler; 47 | oc_request_handler_t put_handler; 48 | oc_request_handler_t post_handler; 49 | oc_request_handler_t delete_handler; 50 | uint8_t num_observers; 51 | uint8_t num_links; 52 | oc_string_array_t supported_rts; 53 | oc_string_array_t mandatory_rts; 54 | OC_LIST_STRUCT(links); 55 | }; 56 | 57 | bool oc_handle_collection_request(oc_method_t method, oc_request_t *request, 58 | oc_interface_mask_t iface_mask, 59 | oc_resource_t *notify_resource); 60 | oc_collection_t *oc_collection_alloc(uint8_t num_supported_rts, 61 | uint8_t num_mandatory_rts); 62 | void oc_collection_free(oc_collection_t *collection); 63 | 64 | oc_collection_t *oc_get_next_collection_with_link(oc_resource_t *resource, 65 | oc_collection_t *start); 66 | oc_collection_t *oc_get_collection_by_uri(const char *uri_path, 67 | size_t uri_path_len, size_t device); 68 | oc_collection_t *oc_collection_get_all(void); 69 | oc_link_t *oc_get_link_by_uri(oc_collection_t *collection, const char *uri_path, int uri_path_len); 70 | 71 | bool oc_check_if_collection(oc_resource_t *resource); 72 | void oc_collection_add(oc_collection_t *collection); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* OC_COLLECTION_H */ 79 | -------------------------------------------------------------------------------- /include/oc_discovery.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_DISCOVERY_H 18 | #define OC_DISCOVERY_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | void oc_create_discovery_resource(int resource_idx, size_t device); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* OC_DISCOVERY_H */ 32 | -------------------------------------------------------------------------------- /include/oc_introspection.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_INTROSPECTION_H 18 | #define OC_INTROSPECTION_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | /** 26 | * @brief functions for introspection . 27 | * The introspection mechanism is implemented by 2 different mechanisms 28 | * 29 | * The first mechanism is reading the IDD file from a location. 30 | * The file is read with standard c library (fopen, fread, ..) 31 | * The IDD information is served up as encoded CBOR contents (e.g. read as is). 32 | * The file is read and passed to the requesting client on each call. 33 | * if the file size is to big for the buffer, then an internal error is given back. 34 | * note that this option can serve up more than 1 introspection file, if multiple devices are implemented. 35 | * This feature is enabled when the compile switch OC_IDD_FILE is used. 36 | * 37 | * The second option is to use an include file that contains the IDD information. 38 | * This is the default mechanism. 39 | * The include file is called "server_introspection.dat.h" and should contain 40 | * introspection_data_size : size of the array introspection_data 41 | * uint8_t introspection_data[] : hex data representing the IDD. 42 | * one should place this file in a folder that gets included in the build 43 | * for example the include directory. 44 | */ 45 | 46 | 47 | /** 48 | @brief sets the filename of the introspection resource. 49 | if not set the file is "server_introspection.dat" is read from the location where the executable resides 50 | 51 | @param device index of the device to which the resource is to be created 52 | @param filename filename of the IDD file in cbor. 53 | */ 54 | void oc_set_introspection_file(size_t device, const char* filename); 55 | 56 | 57 | /** 58 | @brief Creation of the oic.wk.introspection resource. 59 | 60 | @param device index of the device to which the resource is to be created 61 | */ 62 | void oc_create_introspection_resource(size_t device); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* OC_INTROSPECTION_H */ 69 | -------------------------------------------------------------------------------- /include/oc_network_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_NETWORK_EVENTS_H 18 | #define OC_NETWORK_EVENTS_H 19 | 20 | #include "port/oc_network_events_mutex.h" 21 | #include "util/oc_process.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | typedef enum { 29 | NETWORK_INTERFACE_DOWN, 30 | NETWORK_INTERFACE_UP 31 | } oc_interface_event_t; 32 | 33 | /** 34 | @brief Callback function to pass the network interface up/down infomation 35 | to App. 36 | @param event enum values in oc_interface_event_t. 37 | */ 38 | typedef void (*interface_event_handler_t)(oc_interface_event_t event); 39 | 40 | /** 41 | * Structure to manage network interface handler list. 42 | */ 43 | typedef struct oc_network_interface_cb 44 | { 45 | struct oc_network_interface_cb *next; 46 | interface_event_handler_t handler; 47 | } oc_network_interface_cb_t; 48 | 49 | OC_PROCESS_NAME(oc_network_events); 50 | 51 | typedef struct oc_message_s oc_message_t; 52 | 53 | void oc_network_event(oc_message_t *message); 54 | 55 | void oc_network_interface_event(oc_interface_event_t event); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* OC_NETWORK_EVENTS_H */ 62 | -------------------------------------------------------------------------------- /include/oc_network_monitor.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | #ifndef OC_NETWORK_HELPERS_H 20 | #define OC_NETWORK_HELPERS_H 21 | 22 | #include "oc_network_events.h" 23 | #include "oc_session_events.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | /** 31 | @brief Add the callback to receive change notifications for 32 | Network interface event. 33 | @param cb The callback to be added. Must not be NULL. 34 | @return 0 if success. -1 return if error occur. 35 | */ 36 | int oc_add_network_interface_event_callback(interface_event_handler_t cb); 37 | 38 | /** 39 | @brief Remove the callback to receive change notifications for 40 | Network interface event. 41 | @param cb The callback to be removed. Must not be NULL. 42 | @return 0 if success. -1 return if error occur. 43 | */ 44 | int oc_remove_network_interface_event_callback(interface_event_handler_t cb); 45 | 46 | /** 47 | @brief Add the callback to receive change notifications for 48 | Network interface event. 49 | @param cb The callback to be added. Must not be NULL. 50 | @return 0 if success. -1 return if error occur. 51 | */ 52 | int oc_add_session_event_callback(session_event_handler_t cb); 53 | 54 | /** 55 | @brief Remove the callback to receive change notifications for 56 | Network interface event. 57 | @param cb The callback to be removed. Must not be NULL. 58 | @return 0 if success. -1 return if error occur. 59 | */ 60 | int oc_remove_session_event_callback(session_event_handler_t cb); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* OC_NETWORK_HELPERS_H */ 67 | -------------------------------------------------------------------------------- /include/oc_obt.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_OBT_H 18 | #define OC_OBT_H 19 | 20 | #include "oc_api.h" 21 | #include "oc_uuid.h" 22 | #include "security/oc_acl.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif 28 | 29 | typedef void (*oc_obt_discovery_cb_t)(oc_uuid_t *, oc_endpoint_t *, void *); 30 | typedef void (*oc_obt_device_status_cb_t)(oc_uuid_t *, int, void *); 31 | typedef void (*oc_obt_status_cb_t)(int, void *); 32 | 33 | /* Call once at startup for OBT initialization */ 34 | void oc_obt_init(void); 35 | 36 | /* Device discovery */ 37 | int oc_obt_discover_unowned_devices(oc_obt_discovery_cb_t cb, void *data); 38 | int oc_obt_discover_owned_devices(oc_obt_discovery_cb_t cb, void *data); 39 | 40 | /* Perform ownership transfer */ 41 | int oc_obt_perform_just_works_otm(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb, 42 | void *data); 43 | 44 | /* RESET device state */ 45 | int oc_obt_device_hard_reset(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb, 46 | void *data); 47 | 48 | /* Provision pair-wise 128-bit shared keys */ 49 | int oc_obt_provision_pairwise_credentials(oc_uuid_t *uuid1, oc_uuid_t *uuid2, 50 | oc_obt_status_cb_t cb, void *data); 51 | 52 | /* Provision access-control entries (ace2) */ 53 | oc_sec_ace_t *oc_obt_new_ace_for_subject(oc_uuid_t *uuid); 54 | oc_sec_ace_t *oc_obt_new_ace_for_connection(oc_ace_connection_type_t conn); 55 | 56 | oc_ace_res_t *oc_obt_ace_new_resource(oc_sec_ace_t *ace); 57 | void oc_obt_ace_resource_set_href(oc_ace_res_t *resource, const char *href); 58 | void oc_obt_ace_resource_set_num_rt(oc_ace_res_t *resource, int num_resources); 59 | void oc_obt_ace_resource_bind_rt(oc_ace_res_t *resource, const char *rt); 60 | void oc_obt_ace_resource_bind_if(oc_ace_res_t *resource, 61 | oc_interface_mask_t iface_mask); 62 | void oc_obt_ace_resource_set_wc(oc_ace_res_t *resource, oc_ace_wildcard_t wc); 63 | void oc_obt_ace_add_permission(oc_sec_ace_t *ace, 64 | oc_ace_permissions_t permission); 65 | 66 | int oc_obt_provision_ace(oc_uuid_t *subject, oc_sec_ace_t *ace, 67 | oc_obt_device_status_cb_t cb, void *data); 68 | void oc_obt_free_ace(oc_sec_ace_t *ace); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* OC_OBT_H */ 75 | -------------------------------------------------------------------------------- /include/oc_pki.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_PKI_H 18 | #define OC_PKI_H 19 | 20 | #include "security/oc_sp.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | int oc_pki_add_mfg_cert(size_t device, const unsigned char *cert, 27 | size_t cert_size, const unsigned char *key, 28 | size_t key_size); 29 | 30 | int oc_pki_add_mfg_intermediate_cert(size_t device, int credid, 31 | const unsigned char *cert, 32 | size_t cert_size); 33 | 34 | int oc_pki_add_mfg_trust_anchor(size_t device, const unsigned char *cert, 35 | size_t cert_size); 36 | 37 | int oc_pki_add_trust_anchor(size_t device, const unsigned char *cert, 38 | size_t cert_size); 39 | 40 | void oc_pki_set_security_profile(size_t device, 41 | oc_sp_types_t supported_profiles, 42 | oc_sp_types_t current_profile, int mfg_credid); 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif /* OC_PKI_H */ 47 | -------------------------------------------------------------------------------- /include/oc_session_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_SESSION_EVENTS_H 18 | #define OC_SESSION_EVENTS_H 19 | 20 | #include "oc_endpoint.h" 21 | #include "port/oc_network_events_mutex.h" 22 | #include "util/oc_process.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif 28 | 29 | typedef enum { 30 | OC_SESSION_CONNECTED, 31 | OC_SESSION_DISCONNECTED 32 | } oc_session_state_t; 33 | 34 | /** 35 | @brief Callback function to pass the session event infomation to App. 36 | @param endpoint endpoint info which the session event is happened. 37 | @param state enum values in oc_session_state_t. 38 | */ 39 | typedef void (*session_event_handler_t)(const oc_endpoint_t *endpoint, 40 | oc_session_state_t state); 41 | 42 | /** 43 | * Structure to manage session event handler list. 44 | */ 45 | typedef struct oc_session_event_cb 46 | { 47 | struct oc_session_event_cb *next; 48 | session_event_handler_t handler; 49 | } oc_session_event_cb_t; 50 | 51 | OC_PROCESS_NAME(oc_session_events); 52 | 53 | void oc_session_start_event(oc_endpoint_t *endpoint); 54 | void oc_session_end_event(oc_endpoint_t *endpoint); 55 | void oc_handle_session(oc_endpoint_t *endpoint, oc_session_state_t state); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* OC_SESSION_EVENTS_H */ 62 | -------------------------------------------------------------------------------- /include/oc_signal_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_SIGNAL_EVENT_LOOP_H 18 | #define OC_SIGNAL_EVENT_LOOP_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | void _oc_signal_event_loop(void); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* OC_SIGNAL_EVENT_LOOP_H */ 32 | -------------------------------------------------------------------------------- /include/oc_uuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_UUID_H 18 | #define OC_UUID_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | #define OC_UUID_LEN (37) 28 | 29 | typedef struct 30 | { 31 | uint8_t id[16]; 32 | } oc_uuid_t; 33 | 34 | void oc_str_to_uuid(const char *str, oc_uuid_t *uuid); 35 | void oc_uuid_to_str(const oc_uuid_t *uuid, char *buffer, int buflen); 36 | void oc_gen_uuid(oc_uuid_t *uuid); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* OC_UUID_H */ 43 | -------------------------------------------------------------------------------- /messaging/coap/engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | /* 17 | * 18 | * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich 19 | * All rights reserved. 20 | * 21 | * Redistribution and use in source and binary forms, with or without 22 | * modification, are permitted provided that the following conditions 23 | * are met: 24 | * 1. Redistributions of source code must retain the above copyright 25 | * notice, this list of conditions and the following disclaimer. 26 | * 2. Redistributions in binary form must reproduce the above copyright 27 | * notice, this list of conditions and the following disclaimer in the 28 | * documentation and/or other materials provided with the distribution. 29 | * 3. Neither the name of the Institute nor the names of its contributors 30 | * may be used to endorse or promote products derived from this software 31 | * without specific prior written permission. 32 | * 33 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 34 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 35 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 36 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 37 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 38 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 39 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 40 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 42 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 43 | * SUCH DAMAGE. 44 | * 45 | * This file is part of the Contiki operating system. 46 | */ 47 | 48 | #ifndef ENGINE_H 49 | #define ENGINE_H 50 | 51 | #include "coap.h" 52 | #include "observe.h" 53 | #include "separate.h" 54 | #include "transactions.h" 55 | 56 | #ifdef __cplusplus 57 | extern "C" 58 | { 59 | #endif 60 | 61 | OC_PROCESS_NAME(coap_engine); 62 | 63 | void coap_init_engine(void); 64 | /*---------------------------------------------------------------------------*/ 65 | int coap_receive(oc_message_t *message); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* ENGINE_H */ 72 | -------------------------------------------------------------------------------- /messaging/coap/oc_coap.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_COAP_H 18 | #define OC_COAP_H 19 | 20 | #include "separate.h" 21 | #include "util/oc_list.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | struct oc_separate_response_s 29 | { 30 | OC_LIST_STRUCT(requests); 31 | int active; 32 | #ifdef OC_DYNAMIC_ALLOCATION 33 | uint8_t *buffer; 34 | #else /* OC_DYNAMIC_ALLOCATION */ 35 | uint8_t buffer[OC_MAX_APP_DATA_SIZE]; 36 | #endif /* !OC_DYNAMIC_ALLOCATION */ 37 | }; 38 | 39 | struct oc_response_buffer_s 40 | { 41 | uint8_t *buffer; 42 | uint16_t buffer_size; 43 | uint16_t response_length; 44 | int code; 45 | }; 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* OC_COAP_H */ 52 | -------------------------------------------------------------------------------- /patches/08_mbedtls_content_len.patch: -------------------------------------------------------------------------------- 1 | diff --git a/library/ssl_tls.c b/library/ssl_tls.c 2 | index d51230dfa..dee3c4093 100644 3 | --- a/library/ssl_tls.c 4 | +++ b/library/ssl_tls.c 5 | @@ -2290,7 +2290,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) 6 | } 7 | 8 | ret = mbedtls_ssl_confirm_content_len( ssl, &ssl->in, nb_want + 9 | - (size_t)( ssl->in.hdr - ssl->in.buf ) + 1024 ); 10 | + (size_t)( ssl->in.hdr - ssl->in.buf ) + 2048 ); 11 | if( ret ) 12 | return( ret ); 13 | 14 | -------------------------------------------------------------------------------- /port/android/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_assert.h" 18 | #include 19 | 20 | void 21 | abort_impl(void) 22 | { 23 | abort(); 24 | } 25 | 26 | void 27 | exit_impl(int status) 28 | { 29 | exit(status); 30 | } 31 | -------------------------------------------------------------------------------- /port/android/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_clock.h" 18 | #include "port/oc_log.h" 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | oc_clock_init(void) 25 | {} 26 | 27 | oc_clock_time_t 28 | oc_clock_time(void) 29 | { 30 | oc_clock_time_t time = 0; 31 | struct timespec t; 32 | if (clock_gettime(CLOCK_REALTIME, &t) != -1) { 33 | time = (oc_clock_time_t)t.tv_sec * OC_CLOCK_SECOND + 34 | (oc_clock_time_t)ceil(t.tv_nsec / (1.e09 / OC_CLOCK_SECOND)); 35 | } 36 | return time; 37 | } 38 | 39 | unsigned long 40 | oc_clock_seconds(void) 41 | { 42 | struct timespec t; 43 | if (clock_gettime(CLOCK_REALTIME, &t) != -1) { 44 | return t.tv_sec; 45 | } 46 | return 0; 47 | } 48 | 49 | void 50 | oc_clock_wait(oc_clock_time_t t) 51 | { 52 | usleep(t * 1.e03); 53 | } 54 | -------------------------------------------------------------------------------- /port/android/ifaddrs-android.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, The WebRTC project authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of Google nor the names of its contributors may 17 | be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef WEBRTC_BASE_IFADDRS_ANDROID_H_ 34 | #define WEBRTC_BASE_IFADDRS_ANDROID_H_ 35 | 36 | #include 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" 41 | { 42 | #endif 43 | 44 | /* Implementation of getifaddrs for Android. 45 | * Fills out a list of ifaddr structs (see below) which contain information 46 | * about every network interface available on the host. 47 | * See 'man getifaddrs' on Linux or OS X (nb: it is not a POSIX function). */ 48 | struct ifaddrs 49 | { 50 | struct ifaddrs *ifa_next; 51 | char *ifa_name; 52 | unsigned int ifa_flags; 53 | struct sockaddr *ifa_addr; 54 | struct sockaddr *ifa_netmask; 55 | /* Real ifaddrs has broadcast, point to point and data members. 56 | * We don't need them (yet?). */ 57 | }; 58 | 59 | int android_getifaddrs(struct ifaddrs **result); 60 | void android_freeifaddrs(struct ifaddrs *addrs); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* WEBRTC_BASE_IFADDRS_ANDROID_H_ */ 67 | -------------------------------------------------------------------------------- /port/android/ipcontext.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | #ifndef IPCONTEXT_H 20 | #define IPCONTEXT_H 21 | 22 | #include "oc_endpoint.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" 30 | { 31 | #endif 32 | 33 | #ifdef OC_TCP 34 | typedef struct tcp_context_t { 35 | struct sockaddr_storage server; 36 | int server_sock; 37 | uint16_t port; 38 | #ifdef OC_SECURITY 39 | struct sockaddr_storage secure; 40 | int secure_sock; 41 | uint16_t tls_port; 42 | #endif /* OC_SECURITY */ 43 | #ifdef OC_IPV4 44 | struct sockaddr_storage server4; 45 | int server4_sock; 46 | uint16_t port4; 47 | #ifdef OC_SECURITY 48 | struct sockaddr_storage secure4; 49 | int secure4_sock; 50 | uint16_t tls4_port; 51 | #endif /* OC_SECURITY */ 52 | #endif /* OC_IPV4 */ 53 | int connect_pipe[2]; 54 | pthread_mutex_t mutex; 55 | } tcp_context_t; 56 | #endif 57 | 58 | typedef struct ip_context_t { 59 | struct ip_context_t *next; 60 | OC_LIST_STRUCT(eps); 61 | struct sockaddr_storage mcast; 62 | struct sockaddr_storage server; 63 | int mcast_sock; 64 | int server_sock; 65 | uint16_t port; 66 | #ifdef OC_SECURITY 67 | struct sockaddr_storage secure; 68 | int secure_sock; 69 | uint16_t dtls_port; 70 | #endif /* OC_SECURITY */ 71 | #ifdef OC_IPV4 72 | struct sockaddr_storage mcast4; 73 | struct sockaddr_storage server4; 74 | int mcast4_sock; 75 | int server4_sock; 76 | uint16_t port4; 77 | #ifdef OC_SECURITY 78 | struct sockaddr_storage secure4; 79 | int secure4_sock; 80 | uint16_t dtls4_port; 81 | #endif /* OC_SECURITY */ 82 | #endif /* OC_IPV4 */ 83 | #ifdef OC_TCP 84 | tcp_context_t tcp; 85 | #endif 86 | pthread_t event_thread; 87 | int terminate; 88 | size_t device; 89 | fd_set rfds; 90 | int shutdown_pipe[2]; 91 | } ip_context_t; 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* IPCONTEXT_H */ 98 | -------------------------------------------------------------------------------- /port/android/oc_config.h: -------------------------------------------------------------------------------- 1 | #ifndef OC_CONFIG_H 2 | #define OC_CONFIG_H 3 | 4 | /* Time resolution */ 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef uint64_t oc_clock_time_t; 13 | #define OC_CLOCK_CONF_TICKS_PER_SECOND CLOCKS_PER_SEC 14 | 15 | /* Security Layer */ 16 | /* Max inactivity timeout before tearing down DTLS connection */ 17 | #define OC_DTLS_INACTIVITY_TIMEOUT (600) 18 | 19 | /* Add support for passing network up/down events to the app */ 20 | #define OC_NETWORK_MONITOR 21 | /* Add support for passing TCP/TLS/DTLS session connection events to the app */ 22 | #define OC_SESSION_EVENTS 23 | 24 | /* Add support for dns lookup to the endpoint */ 25 | #define OC_DNS_LOOKUP 26 | #define OC_DNS_LOOKUP_IPV6 27 | 28 | /* If we selected support for dynamic memory allocation */ 29 | #ifdef OC_DYNAMIC_ALLOCATION 30 | #define OC_COLLECTIONS 31 | #define OC_BLOCK_WISE 32 | 33 | #else /* OC_DYNAMIC_ALLOCATION */ 34 | /* List of constraints below for a build that does not employ dynamic 35 | memory allocation 36 | */ 37 | /* Memory pool sizes */ 38 | #define OC_BYTES_POOL_SIZE (1800) 39 | #define OC_INTS_POOL_SIZE (100) 40 | #define OC_DOUBLES_POOL_SIZE (4) 41 | 42 | /* Server-side parameters */ 43 | /* Maximum number of server resources */ 44 | #define OC_MAX_APP_RESOURCES (4) 45 | 46 | #define OC_MAX_NUM_COLLECTIONS (1) 47 | 48 | /* Common paramters */ 49 | /* Prescriptive lower layers MTU size, enable block-wise transfers */ 50 | #define OC_BLOCK_WISE_SET_MTU (700) 51 | 52 | /* Maximum size of request/response payloads */ 53 | #define OC_MAX_APP_DATA_SIZE (2048) 54 | 55 | /* Maximum number of concurrent requests */ 56 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (3) 57 | 58 | /* Maximum number of nodes in a payload tree structure */ 59 | #define OC_MAX_NUM_REP_OBJECTS (150) 60 | 61 | /* Number of devices on the OCF platform */ 62 | #define OC_MAX_NUM_DEVICES (2) 63 | 64 | /* Maximum number of endpoints */ 65 | #define OC_MAX_NUM_ENDPOINTS (20) 66 | 67 | /* Security layer */ 68 | /* Maximum number of authorized clients */ 69 | #define OC_MAX_NUM_SUBJECTS (2) 70 | 71 | /* Maximum number of concurrent (D)TLS sessions */ 72 | #define OC_MAX_TLS_PEERS (1) 73 | 74 | /* Maximum number of peer for TCP channel */ 75 | #define OC_MAX_TCP_PEERS (2) 76 | 77 | /* Maximum number of interfaces for IP adapter */ 78 | /* Warning: Android has often over 10 interfaces. */ 79 | #define OC_MAX_IP_INTERFACES (20) 80 | 81 | /* Maximum number of callbacks for Network interface event monitoring */ 82 | #define OC_MAX_NETWORK_INTERFACE_CBS (2) 83 | 84 | /* Maximum number of callbacks for connection of session */ 85 | #define OC_MAX_SESSION_EVENT_CBS (2) 86 | 87 | #endif /* !OC_DYNAMIC_ALLOCATION */ 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /* OC_CONFIG_H */ 94 | -------------------------------------------------------------------------------- /port/android/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_random.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static int urandom_fd; 26 | 27 | void 28 | oc_random_init(void) 29 | { 30 | urandom_fd = open("/dev/urandom", O_RDONLY); 31 | } 32 | 33 | unsigned int 34 | oc_random_value(void) 35 | { 36 | unsigned int rand = 0; 37 | int ret = read(urandom_fd, &rand, sizeof(rand)); 38 | assert(ret != -1); 39 | #ifndef DEBUG 40 | (void)ret; 41 | #endif 42 | return rand; 43 | } 44 | 45 | void 46 | oc_random_destroy(void) 47 | { 48 | close(urandom_fd); 49 | } 50 | -------------------------------------------------------------------------------- /port/android/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_storage.h" 18 | 19 | #ifdef OC_SECURITY 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define STORE_PATH_SIZE 64 26 | 27 | static char store_path[STORE_PATH_SIZE]; 28 | static int store_path_len; 29 | static bool path_set = false; 30 | 31 | int 32 | oc_storage_config(const char *store) 33 | { 34 | store_path_len = strlen(store); 35 | if (store_path_len >= STORE_PATH_SIZE) 36 | return -ENOENT; 37 | 38 | strncpy(store_path, store, store_path_len); 39 | path_set = true; 40 | 41 | return 0; 42 | } 43 | 44 | long 45 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 46 | { 47 | FILE *fp = 0; 48 | size_t store_len = strlen(store); 49 | 50 | if (!path_set || (1 + store_len + store_path_len >= STORE_PATH_SIZE)) 51 | return -ENOENT; 52 | 53 | store_path[store_path_len] = '/'; 54 | strncpy(store_path + store_path_len + 1, store, store_len); 55 | store_path[1 + store_path_len + store_len] = '\0'; 56 | fp = fopen(store_path, "rb"); 57 | if (!fp) 58 | return -EINVAL; 59 | 60 | size = fread(buf, 1, size, fp); 61 | fclose(fp); 62 | return size; 63 | } 64 | 65 | long 66 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 67 | { 68 | FILE *fp; 69 | size_t store_len = strlen(store); 70 | 71 | if (!path_set || (store_len + store_path_len >= STORE_PATH_SIZE)) 72 | return -ENOENT; 73 | 74 | store_path[store_path_len] = '/'; 75 | strncpy(store_path + store_path_len + 1, store, store_len); 76 | store_path[1 + store_path_len + store_len] = '\0'; 77 | fp = fopen(store_path, "wb"); 78 | if (!fp) 79 | return -EINVAL; 80 | 81 | size = fwrite(buf, 1, size, fp); 82 | fclose(fp); 83 | return size; 84 | } 85 | #endif /* OC_SECURITY */ 86 | -------------------------------------------------------------------------------- /port/contiki/Makefile: -------------------------------------------------------------------------------- 1 | #Set CONTIKI appropriately below to point to the root of your Contiki source. 2 | CONTIKI = ${HOME}/contiki 3 | 4 | ifeq ($(CLIENT),1) 5 | CONTIKI_PROJECT = client_contiki 6 | else 7 | CONTIKI_PROJECT = server_contiki 8 | SERVER=1 9 | endif 10 | 11 | all: $(CONTIKI_PROJECT) 12 | 13 | PROJECTDIRS += ./ ../../include ../../ ../../api ../../messaging/coap ../../apps ../../deps/tinycbor/src ../../util 14 | 15 | PROJECT_SOURCEFILES += oc_buffer.c oc_discovery.c oc_main.c oc_ri.c oc_client_api.c oc_network_events.c oc_server_api.c oc_core_res.c oc_helpers.c oc_rep.c oc_uuid.c cborencoder.c cborencoder_close_container_checked.c cborparser.c oc_etimer.c oc_memb.c oc_process.c oc_list.c oc_mmem.c oc_timer.c coap.c separate.c engine.c transactions.c observe.c ipadapter.c oc_clock.c oc_random.c abort.c storage.c oc_blockwise.c oc_base64.c oc_endpoint.c oc_introspection.c 16 | 17 | CONTIKI_WITH_RPL = 1 18 | CONTIKI_WITH_IPV6 = 1 19 | 20 | include $(CONTIKI)/Makefile.include 21 | 22 | CFLAGS += -std=gnu99 -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-reorder-functions -fno-defer-pop -fno-strict-overflow -Wl,--gc-sections 23 | 24 | ifeq ($(CLIENT),1) 25 | CFLAGS += -DOC_CLIENT 26 | endif 27 | 28 | ifeq ($(SERVER),1) 29 | CFLAGS += -DOC_SERVER 30 | endif 31 | 32 | ifeq ($(DEBUG),1) 33 | CFLAGS += -DOC_DEBUG -g 34 | endif 35 | -------------------------------------------------------------------------------- /port/contiki/README: -------------------------------------------------------------------------------- 1 | 1) Set CONTIKI path in the Makefile. 2 | 3 | 2) Perform the build: 4 | make SERVER=1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* Time resolution */ 27 | #include 28 | typedef uint64_t oc_clock_time_t; 29 | #define OC_CLOCK_CONF_TICKS_PER_SECOND CLOCK_CONF_SECOND 30 | 31 | #define OC_BYTES_POOL_SIZE (900) 32 | #define OC_INTS_POOL_SIZE (4) 33 | #define OC_DOUBLES_POOL_SIZE (4) 34 | 35 | /* Server-side parameters */ 36 | /* Maximum number of server resources */ 37 | #define OC_MAX_APP_RESOURCES (1) 38 | 39 | /* Common paramters */ 40 | /* Maximum size of request/response PDUs */ 41 | #define OC_MAX_APP_DATA_SIZE (600) 42 | 43 | /* Maximum number of concurrent requests */ 44 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (2) 45 | 46 | /* Maximum number of nodes in a payload tree structure */ 47 | #define OC_MAX_NUM_REP_OBJECTS (70) 48 | 49 | /* Number of devices on the OCF platform */ 50 | #define OC_MAX_NUM_DEVICES (1) 51 | 52 | #define OC_MAX_NUM_ENDPOINTS (4) 53 | 54 | /* Security layer */ 55 | /* Maximum number of authorized clients */ 56 | #define OC_MAX_NUM_SUBJECTS (1) 57 | 58 | /* Maximum number of concurrent DTLS sessions */ 59 | #define OC_MAX_DTLS_PEERS (1) 60 | 61 | /* Max inactivity timeout before tearing down DTLS connection */ 62 | #define OC_DTLS_INACTIVITY_TIMEOUT (10) 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* OC_CONFIG_H */ 69 | -------------------------------------------------------------------------------- /port/contiki/oc_random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_random.h" 18 | #include "random.h" 19 | 20 | // FIXME: Employ an appropriate seeding strategy here for the PRNG. 21 | void 22 | oc_random_init(void) 23 | { 24 | random_init(0); 25 | } 26 | 27 | unsigned int 28 | oc_random_value(void) 29 | { 30 | return random_rand(); 31 | } 32 | 33 | void 34 | oc_random_destroy(void) 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /port/contiki/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifdef OC_SECURITY 18 | 19 | #include "port/oc_storage.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #define STORE_PATH_SIZE 64 28 | 29 | static char store_path[STORE_PATH_SIZE]; 30 | static int store_path_len; 31 | static bool path_set = false; 32 | 33 | int 34 | oc_storage_config(const char *store) 35 | { 36 | store_path_len = strlen(store); 37 | if (store_path_len >= STORE_PATH_SIZE) 38 | return -ENOENT; 39 | 40 | strncpy(store_path, store, store_path_len); 41 | path_set = true; 42 | 43 | return 0; 44 | } 45 | 46 | long 47 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 48 | { 49 | int fd; 50 | size_t store_len = strlen(store); 51 | 52 | if (!path_set || (store_len + store_path_len >= STORE_PATH_SIZE)) 53 | return -ENOENT; 54 | 55 | strncpy(store_path + store_path_len, store, store_len); 56 | store_path[store_path_len + store_len] = '\0'; 57 | fd = cfs_open(store_path, CFS_READ); 58 | if (!fd) 59 | return -EINVAL; 60 | 61 | size = cfs_read(fd, buf, size); 62 | cfs_close(fd); 63 | return size; 64 | } 65 | 66 | long 67 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 68 | { 69 | int fd; 70 | size_t store_len = strlen(store); 71 | 72 | if (!path_set || (store_len + store_path_len >= STORE_PATH_SIZE)) 73 | return -ENOENT; 74 | 75 | strncpy(store_path + store_path_len, store, store_len); 76 | store_path[store_path_len + store_len] = '\0'; 77 | fd = cfs_open(store_path, CFS_WRITE); 78 | if (!fd) 79 | return -EINVAL; 80 | 81 | size = cfs_write(fd, buf, size); 82 | cfs_close(fd); 83 | return size; 84 | } 85 | 86 | #endif /* OC_SECURITY */ 87 | -------------------------------------------------------------------------------- /port/freertos/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2017 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_assert.h" 19 | #include 20 | 21 | void 22 | abort_impl(void) 23 | { 24 | exit(1); 25 | } 26 | 27 | void 28 | exit_impl(int status) 29 | { 30 | exit(status); 31 | } 32 | -------------------------------------------------------------------------------- /port/freertos/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_clock.h" 19 | #include "port/oc_assert.h" 20 | 21 | void 22 | oc_clock_init(void) 23 | { 24 | abort_impl(); 25 | } 26 | 27 | oc_clock_time_t 28 | oc_clock_time(void) 29 | { 30 | oc_clock_time_t time = 0; 31 | oc_abort(__func__); 32 | return time; 33 | } 34 | 35 | unsigned long 36 | oc_clock_seconds(void) 37 | { 38 | oc_abort(__func__); 39 | return 0; 40 | } 41 | 42 | void 43 | oc_clock_wait(oc_clock_time_t t) 44 | { 45 | (void) t; 46 | oc_abort(__func__); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /port/freertos/ipcontext.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | #ifndef IPCONTEXT_H 20 | #define IPCONTEXT_H 21 | 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | #ifdef OC_TCP 31 | typedef struct tcp_context_t { 32 | void* server; 33 | int server_sock; 34 | uint16_t port; 35 | #ifdef OC_SECURITY 36 | void* secure; 37 | int secure_sock; 38 | uint16_t tls_port; 39 | #endif /* OC_SECURITY */ 40 | #ifdef OC_IPV4 41 | void* server4; 42 | int server4_sock; 43 | uint16_t port4; 44 | #ifdef OC_SECURITY 45 | void* secure4; 46 | int secure4_sock; 47 | uint16_t tls4_port; 48 | #endif /* OC_SECURITY */ 49 | #endif /* OC_IPV4 */ 50 | int connect_pipe[2]; 51 | } tcp_context_t; 52 | #endif 53 | 54 | typedef struct ip_context_t { 55 | struct ip_context_t *next; 56 | int mcast_sock; 57 | int server_sock; 58 | uint16_t port; 59 | #ifdef OC_SECURITY 60 | void* secure; 61 | int secure_sock; 62 | uint16_t dtls_port; 63 | #endif /* OC_SECURITY */ 64 | #ifdef OC_IPV4 65 | void* mcast4; 66 | void* server4; 67 | int mcast4_sock; 68 | int server4_sock; 69 | uint16_t port4; 70 | #ifdef OC_SECURITY 71 | void* secure4; 72 | int secure4_sock; 73 | uint16_t dtls4_port; 74 | #endif /* OC_SECURITY */ 75 | #endif /* OC_IPV4 */ 76 | #ifdef OC_TCP 77 | tcp_context_t tcp; 78 | #endif 79 | int terminate; 80 | size_t device; 81 | int shutdown_pipe[2]; 82 | } ip_context_t; 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* IPCONTEXT_H */ 89 | -------------------------------------------------------------------------------- /port/freertos/oc_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #ifndef OC_CONFIG_H 19 | #define OC_CONFIG_H 20 | 21 | /* Time resolution */ 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef uint64_t oc_clock_time_t; 29 | #define OC_CLOCK_CONF_TICKS_PER_SECOND 1 30 | 31 | /* Security Layer */ 32 | /* Max inactivity timeout before tearing down DTLS connection */ 33 | #define OC_DTLS_INACTIVITY_TIMEOUT (600) 34 | 35 | /* Maximum wait time for select function */ 36 | #define SELECT_TIMEOUT_SEC (1) 37 | 38 | /* Add support for dns lookup to the endpoint */ 39 | #define OC_DNS_LOOKUP 40 | 41 | /* If we selected support for dynamic memory allocation */ 42 | #ifdef OC_DYNAMIC_ALLOCATION 43 | #define OC_COLLECTIONS 44 | #define OC_BLOCK_WISE 45 | 46 | #else /* OC_DYNAMIC_ALLOCATION */ 47 | /* List of constraints below for a build that does not employ dynamic 48 | memory allocation 49 | */ 50 | /* Memory pool sizes */ 51 | #define OC_BYTES_POOL_SIZE (1800) 52 | #define OC_INTS_POOL_SIZE (100) 53 | #define OC_DOUBLES_POOL_SIZE (4) 54 | 55 | /* Server-side parameters */ 56 | /* Maximum number of server resources */ 57 | #define OC_MAX_APP_RESOURCES (4) 58 | 59 | #define OC_MAX_NUM_COLLECTIONS (1) 60 | 61 | /* Common paramters */ 62 | /* Prescriptive lower layers MTU size, enable block-wise transfers */ 63 | #define OC_BLOCK_WISE_SET_MTU (700) 64 | 65 | /* Maximum size of request/response payloads */ 66 | #define OC_MAX_APP_DATA_SIZE (2048) 67 | 68 | /* Maximum number of concurrent requests */ 69 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (3) 70 | 71 | /* Maximum number of nodes in a payload tree structure */ 72 | #define OC_MAX_NUM_REP_OBJECTS (150) 73 | 74 | /* Number of devices on the OCF platform */ 75 | #define OC_MAX_NUM_DEVICES (2) 76 | 77 | /* Maximum number of endpoints */ 78 | #define OC_MAX_NUM_ENDPOINTS (20) 79 | 80 | /* Security layer */ 81 | /* Maximum number of authorized clients */ 82 | #define OC_MAX_NUM_SUBJECTS (2) 83 | 84 | /* Maximum number of concurrent DTLS sessions */ 85 | #define OC_MAX_DTLS_PEERS (1) 86 | 87 | /* Maximum number of peer for TCP channel */ 88 | #define OC_MAX_TCP_PEERS (2) 89 | 90 | #endif /* !OC_DYNAMIC_ALLOCATION */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* OC_CONFIG_H */ 97 | -------------------------------------------------------------------------------- /port/freertos/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_random.h" 19 | #include "port/oc_assert.h" 20 | 21 | 22 | void 23 | oc_random_init(void) 24 | { 25 | oc_abort(__func__); 26 | } 27 | 28 | unsigned int 29 | oc_random_value(void) 30 | { 31 | unsigned int rand = 0; 32 | oc_abort(__func__); 33 | return rand; 34 | } 35 | 36 | void 37 | oc_random_destroy(void) 38 | { 39 | oc_abort(__func__); 40 | } 41 | -------------------------------------------------------------------------------- /port/freertos/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_storage.h" 19 | #include "port/oc_assert.h" 20 | 21 | #ifdef OC_SECURITY 22 | 23 | int 24 | oc_storage_config(const char *store) 25 | { 26 | (void) store; 27 | oc_abort(__func__); 28 | return 0; 29 | } 30 | 31 | long 32 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 33 | { 34 | (void) store; 35 | (void) buf; 36 | oc_abort(__func__); 37 | return size; 38 | } 39 | 40 | long 41 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 42 | { 43 | (void) store; 44 | (void) buf; 45 | oc_abort(__func__); 46 | return size; 47 | } 48 | #endif /* OC_SECURITY */ 49 | -------------------------------------------------------------------------------- /port/freertos/tcpadapter.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | 20 | #ifndef TCP_ADAPTER_H 21 | #define TCP_ADAPTER_H 22 | 23 | #include "ipcontext.h" 24 | #include "port/oc_connectivity.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" 28 | { 29 | #endif 30 | 31 | typedef enum { 32 | TCP_STATUS_NONE = 0, 33 | TCP_STATUS_ACCEPT, 34 | TCP_STATUS_RECEIVE, 35 | TCP_STATUS_ERROR 36 | } tcp_receive_state_t; 37 | 38 | int oc_tcp_connectivity_init(ip_context_t *dev); 39 | 40 | void oc_tcp_connectivity_shutdown(ip_context_t *dev); 41 | 42 | int oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message, 43 | const void *receiver); 44 | 45 | void oc_tcp_add_socks_to_fd_set(ip_context_t *dev); 46 | 47 | void oc_tcp_set_session_fds(void *fds); 48 | 49 | tcp_receive_state_t oc_tcp_receive_message(ip_context_t *dev, void *fds, 50 | oc_message_t *message); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* TCP_ADAPTER_H */ 57 | -------------------------------------------------------------------------------- /port/linux/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_assert.h" 18 | #include 19 | 20 | void 21 | abort_impl(void) 22 | { 23 | abort(); 24 | } 25 | 26 | void 27 | exit_impl(int status) 28 | { 29 | exit(status); 30 | } 31 | -------------------------------------------------------------------------------- /port/linux/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_clock.h" 18 | #include "port/oc_log.h" 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | oc_clock_init(void) 25 | { 26 | } 27 | 28 | oc_clock_time_t 29 | oc_clock_time(void) 30 | { 31 | oc_clock_time_t time = 0; 32 | struct timespec t; 33 | if (clock_gettime(CLOCK_REALTIME, &t) != -1) { 34 | time = (oc_clock_time_t)t.tv_sec * OC_CLOCK_SECOND + 35 | (oc_clock_time_t)ceil(t.tv_nsec / (1.e09 / OC_CLOCK_SECOND)); 36 | } 37 | return time; 38 | } 39 | 40 | unsigned long 41 | oc_clock_seconds(void) 42 | { 43 | struct timespec t; 44 | if (clock_gettime(CLOCK_REALTIME, &t) != -1) { 45 | return t.tv_sec; 46 | } 47 | return 0; 48 | } 49 | 50 | void 51 | oc_clock_wait(oc_clock_time_t t) 52 | { 53 | usleep(t * 1.e03); 54 | } 55 | -------------------------------------------------------------------------------- /port/linux/iotivity-constrained-client-server.pc.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | prefix=@prefix@ 16 | exec_prefix=@exec_prefix@ 17 | libdir=@libdir@ 18 | includedir=@includedir@ 19 | 20 | Name: iotivity-constrained-client-server 21 | Description: Iotivity constrained client and server library 22 | Version: @version@ 23 | Libs.private: -lm -pthread 24 | Cflags: -I${includedir}/iotivity-constrained -DOC_CLIENT -DOC_SERVER @extra_cflags@ 25 | Libs: -L${libdir} -liotivity-constrained-client-server 26 | -------------------------------------------------------------------------------- /port/linux/iotivity-constrained-client.pc.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | prefix=@prefix@ 16 | exec_prefix=@exec_prefix@ 17 | libdir=@libdir@ 18 | includedir=@includedir@ 19 | 20 | Name: iotivity-constrained-client 21 | Description: Iotivity constrained client library 22 | Version: @version@ 23 | Libs.private: -lm -pthread 24 | Cflags: -I${includedir}/iotivity-constrained -DOC_CLIENT @extra_cflags@ 25 | Libs: -L${libdir} -liotivity-constrained-client 26 | -------------------------------------------------------------------------------- /port/linux/iotivity-constrained-server.pc.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | prefix=@prefix@ 16 | exec_prefix=@exec_prefix@ 17 | libdir=@libdir@ 18 | includedir=@includedir@ 19 | 20 | Name: iotivity-constrained-server 21 | Description: Iotivity constrained server library 22 | Version: @version@ 23 | Libs.private: -lm -pthread 24 | Cflags: -I${includedir}/iotivity-constrained -DOC_SERVER @extra_cflags@ 25 | Libs: -L${libdir} -liotivity-constrained-server 26 | -------------------------------------------------------------------------------- /port/linux/ipcontext.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | #ifndef IPCONTEXT_H 20 | #define IPCONTEXT_H 21 | 22 | #include "oc_endpoint.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" 30 | { 31 | #endif 32 | 33 | typedef enum { 34 | ADAPTER_STATUS_NONE = 0, /* Nothing happens */ 35 | ADAPTER_STATUS_ACCEPT, /* Receiving no meaningful data */ 36 | ADAPTER_STATUS_RECEIVE, /* Receiving meaningful data */ 37 | ADAPTER_STATUS_ERROR /* Error */ 38 | } adapter_receive_state_t; 39 | 40 | #ifdef OC_TCP 41 | typedef struct tcp_context_t 42 | { 43 | struct sockaddr_storage server; 44 | int server_sock; 45 | uint16_t port; 46 | #ifdef OC_SECURITY 47 | struct sockaddr_storage secure; 48 | int secure_sock; 49 | uint16_t tls_port; 50 | #endif /* OC_SECURITY */ 51 | #ifdef OC_IPV4 52 | struct sockaddr_storage server4; 53 | int server4_sock; 54 | uint16_t port4; 55 | #ifdef OC_SECURITY 56 | struct sockaddr_storage secure4; 57 | int secure4_sock; 58 | uint16_t tls4_port; 59 | #endif /* OC_SECURITY */ 60 | #endif /* OC_IPV4 */ 61 | int connect_pipe[2]; 62 | pthread_mutex_t mutex; 63 | } tcp_context_t; 64 | #endif 65 | 66 | typedef struct ip_context_t { 67 | struct ip_context_t *next; 68 | OC_LIST_STRUCT(eps); 69 | struct sockaddr_storage mcast; 70 | struct sockaddr_storage server; 71 | int mcast_sock; 72 | int server_sock; 73 | uint16_t port; 74 | #ifdef OC_SECURITY 75 | struct sockaddr_storage secure; 76 | int secure_sock; 77 | uint16_t dtls_port; 78 | #endif /* OC_SECURITY */ 79 | #ifdef OC_IPV4 80 | struct sockaddr_storage mcast4; 81 | struct sockaddr_storage server4; 82 | int mcast4_sock; 83 | int server4_sock; 84 | uint16_t port4; 85 | #ifdef OC_SECURITY 86 | struct sockaddr_storage secure4; 87 | int secure4_sock; 88 | uint16_t dtls4_port; 89 | #endif /* OC_SECURITY */ 90 | #endif /* OC_IPV4 */ 91 | #ifdef OC_TCP 92 | tcp_context_t tcp; 93 | #endif 94 | pthread_t event_thread; 95 | int terminate; 96 | size_t device; 97 | fd_set rfds; 98 | int shutdown_pipe[2]; 99 | } ip_context_t; 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* IPCONTEXT_H */ 106 | -------------------------------------------------------------------------------- /port/linux/oc_config.h: -------------------------------------------------------------------------------- 1 | #ifndef OC_CONFIG_H 2 | #define OC_CONFIG_H 3 | 4 | /* Time resolution */ 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef uint64_t oc_clock_time_t; 13 | #define OC_CLOCK_CONF_TICKS_PER_SECOND CLOCKS_PER_SEC 14 | 15 | /* Security Layer */ 16 | /* Max inactivity timeout before tearing down DTLS connection */ 17 | #define OC_DTLS_INACTIVITY_TIMEOUT (600) 18 | 19 | /* Maximum wait time for select function */ 20 | #define SELECT_TIMEOUT_SEC (1) 21 | 22 | /* Add support for passing network up/down events to the app */ 23 | #define OC_NETWORK_MONITOR 24 | /* Add support for passing TCP/TLS/DTLS session connection events to the app */ 25 | #define OC_SESSION_EVENTS 26 | 27 | /* Add support for dns lookup to the endpoint */ 28 | #define OC_DNS_LOOKUP 29 | #define OC_DNS_LOOKUP_IPV6 30 | 31 | /* If we selected support for dynamic memory allocation */ 32 | #ifdef OC_DYNAMIC_ALLOCATION 33 | #define OC_COLLECTIONS 34 | #define OC_BLOCK_WISE 35 | 36 | #else /* OC_DYNAMIC_ALLOCATION */ 37 | /* List of constraints below for a build that does not employ dynamic 38 | memory allocation 39 | */ 40 | /* Memory pool sizes */ 41 | #define OC_BYTES_POOL_SIZE (1800) 42 | #define OC_INTS_POOL_SIZE (100) 43 | #define OC_DOUBLES_POOL_SIZE (4) 44 | 45 | /* Server-side parameters */ 46 | /* Maximum number of server resources */ 47 | #define OC_MAX_APP_RESOURCES (4) 48 | 49 | #define OC_MAX_NUM_COLLECTIONS (1) 50 | 51 | /* Common paramters */ 52 | /* Prescriptive lower layers MTU size, enable block-wise transfers */ 53 | #define OC_BLOCK_WISE_SET_MTU (700) 54 | 55 | /* Maximum size of request/response payloads */ 56 | #define OC_MAX_APP_DATA_SIZE (2048) 57 | 58 | /* Maximum number of concurrent requests */ 59 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (3) 60 | 61 | /* Maximum number of nodes in a payload tree structure */ 62 | #define OC_MAX_NUM_REP_OBJECTS (150) 63 | 64 | /* Number of devices on the OCF platform */ 65 | #define OC_MAX_NUM_DEVICES (2) 66 | 67 | /* Maximum number of endpoints */ 68 | #define OC_MAX_NUM_ENDPOINTS (20) 69 | 70 | /* Security layer */ 71 | /* Maximum number of authorized clients */ 72 | #define OC_MAX_NUM_SUBJECTS (2) 73 | 74 | /* Maximum number of concurrent (D)TLS sessions */ 75 | #define OC_MAX_TLS_PEERS (1) 76 | 77 | /* Maximum number of peer for TCP channel */ 78 | #define OC_MAX_TCP_PEERS (2) 79 | 80 | /* Maximum number of interfaces for IP adapter */ 81 | #define OC_MAX_IP_INTERFACES (2) 82 | 83 | /* Maximum number of callbacks for Network interface event monitoring */ 84 | #define OC_MAX_NETWORK_INTERFACE_CBS (2) 85 | 86 | /* Maximum number of callbacks for connection of session */ 87 | #define OC_MAX_SESSION_EVENT_CBS (2) 88 | 89 | #endif /* !OC_DYNAMIC_ALLOCATION */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /* OC_CONFIG_H */ 96 | -------------------------------------------------------------------------------- /port/linux/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_random.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static int urandom_fd; 26 | 27 | void 28 | oc_random_init(void) 29 | { 30 | urandom_fd = open("/dev/urandom", O_RDONLY); 31 | } 32 | 33 | unsigned int 34 | oc_random_value(void) 35 | { 36 | unsigned int rand = 0; 37 | int ret = read(urandom_fd, &rand, sizeof(rand)); 38 | assert(ret != -1); 39 | #ifndef DEBUG 40 | (void)ret; 41 | #endif 42 | return rand; 43 | } 44 | 45 | void 46 | oc_random_destroy(void) 47 | { 48 | close(urandom_fd); 49 | } 50 | -------------------------------------------------------------------------------- /port/linux/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_storage.h" 18 | 19 | #ifdef OC_SECURITY 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define STORE_PATH_SIZE 64 26 | 27 | static char store_path[STORE_PATH_SIZE]; 28 | static int store_path_len; 29 | static bool path_set = false; 30 | 31 | int 32 | oc_storage_config(const char *store) 33 | { 34 | store_path_len = strlen(store); 35 | if (store_path_len >= STORE_PATH_SIZE) 36 | return -ENOENT; 37 | 38 | strncpy(store_path, store, store_path_len); 39 | store_path[store_path_len] = '\0'; 40 | path_set = true; 41 | 42 | return 0; 43 | } 44 | 45 | long 46 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 47 | { 48 | FILE *fp = 0; 49 | size_t store_len = strlen(store); 50 | 51 | if (!path_set || (1 + store_len + store_path_len >= STORE_PATH_SIZE)) 52 | return -ENOENT; 53 | 54 | store_path[store_path_len] = '/'; 55 | strncpy(store_path + store_path_len + 1, store, store_len); 56 | store_path[1 + store_path_len + store_len] = '\0'; 57 | fp = fopen(store_path, "rb"); 58 | if (!fp) 59 | return -EINVAL; 60 | 61 | size = fread(buf, 1, size, fp); 62 | fclose(fp); 63 | return size; 64 | } 65 | 66 | long 67 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 68 | { 69 | FILE *fp; 70 | size_t store_len = strlen(store); 71 | 72 | if (!path_set || (store_len + store_path_len >= STORE_PATH_SIZE)) 73 | return -ENOENT; 74 | 75 | store_path[store_path_len] = '/'; 76 | strncpy(store_path + store_path_len + 1, store, store_len); 77 | store_path[1 + store_path_len + store_len] = '\0'; 78 | fp = fopen(store_path, "wb"); 79 | if (!fp) 80 | return -EINVAL; 81 | 82 | size = fwrite(buf, 1, size, fp); 83 | fclose(fp); 84 | return size; 85 | } 86 | #endif /* OC_SECURITY */ 87 | -------------------------------------------------------------------------------- /port/linux/tcpadapter.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | 20 | #ifndef TCP_ADAPTER_H 21 | #define TCP_ADAPTER_H 22 | 23 | #include "ipcontext.h" 24 | #include "port/oc_connectivity.h" 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" 29 | { 30 | #endif 31 | 32 | int oc_tcp_connectivity_init(ip_context_t *dev); 33 | 34 | void oc_tcp_connectivity_shutdown(ip_context_t *dev); 35 | 36 | int oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message, 37 | const struct sockaddr_storage *receiver); 38 | 39 | void oc_tcp_add_socks_to_fd_set(ip_context_t *dev); 40 | 41 | void oc_tcp_set_session_fds(fd_set *fds); 42 | 43 | adapter_receive_state_t oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, 44 | oc_message_t *message); 45 | 46 | void oc_tcp_end_session(ip_context_t *dev, oc_endpoint_t *endpoint); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* TCP_ADAPTER_H */ 53 | -------------------------------------------------------------------------------- /port/oc_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_ASSERT_H 18 | #define OC_ASSERT_H 19 | 20 | #include "port/oc_log.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | void abort_impl(void); 28 | void exit_impl(int status); 29 | 30 | static inline void 31 | oc_abort(const char *msg) 32 | { 33 | PRINT("\n%s\nAbort.\n", msg); 34 | abort_impl(); 35 | } 36 | 37 | #define oc_assert(cond) \ 38 | do { \ 39 | if (!(cond)) { \ 40 | oc_abort("Assertion (" #cond ") failed."); \ 41 | } \ 42 | } while (0) 43 | 44 | static inline void 45 | oc_exit(int status) 46 | { 47 | exit_impl(status); 48 | } 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* OC_ASSERT_H */ 55 | -------------------------------------------------------------------------------- /port/oc_network_events_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_NETWORK_EVENTS_MUTEX_H 18 | #define OC_NETWORK_EVENTS_MUTEX_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | void oc_network_event_handler_mutex_init(void); 26 | 27 | void oc_network_event_handler_mutex_lock(void); 28 | 29 | void oc_network_event_handler_mutex_unlock(void); 30 | 31 | void oc_network_event_handler_mutex_destroy(void); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* OC_NETWORK_EVENTS_MUTEX_H */ 38 | -------------------------------------------------------------------------------- /port/oc_random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Intel Corporation 3 | * 4 | * Copyright (c) 2005, Swedish Institute of Computer Science 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the Institute nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * This file is part of the Contiki operating system. 32 | * 33 | */ 34 | #ifndef OC_RANDOM_H 35 | #define OC_RANDOM_H 36 | 37 | #ifdef __cplusplus 38 | extern "C" 39 | { 40 | #endif 41 | 42 | /* 43 | * Initialize the pseudo-random generator. 44 | * 45 | */ 46 | void oc_random_init(void); 47 | 48 | /* 49 | * Calculate a pseudo random number. 50 | * 51 | * \return A pseudo-random number. 52 | */ 53 | unsigned int oc_random_value(void); 54 | 55 | void oc_random_destroy(void); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* OC_RANDOM_H */ 62 | -------------------------------------------------------------------------------- /port/oc_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_STORAGE_H 18 | #define OC_STORAGE_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | int oc_storage_config(const char *store); 29 | long oc_storage_read(const char *store, uint8_t *buf, size_t size); 30 | long oc_storage_write(const char *store, uint8_t *buf, size_t size); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* OC_STORAGE_H */ 37 | -------------------------------------------------------------------------------- /port/openthread/Makefile: -------------------------------------------------------------------------------- 1 | OPENTHREAD_PATH = ../../../openthread 2 | OPENTHREAD_BOARD = posix 3 | OPENTHREAD_LIB_PATH = ${OPENTHREAD_PATH}/output/${OPENTHREAD_BOARD}/lib 4 | 5 | include Makefile-${OPENTHREAD_BOARD} 6 | 7 | PATH_OBJ = output/${OPENTHREAD_BOARD}/obj 8 | PATH_BIN = output/${OPENTHREAD_BOARD}/bin 9 | 10 | CBOR = \ 11 | ../../deps/tinycbor/src/cborencoder.c \ 12 | ../../deps/tinycbor/src/cborencoder_close_container_checked.c \ 13 | ../../deps/tinycbor/src/cborparser.c 14 | # ../../deps/tinycbor/src/cbortojson.c 15 | # ../../deps/tinycbor/src/cborpretty.c 16 | # ../../deps/tinycbor/src/cborparser_dup_string.c 17 | 18 | SRC_COMMON = $(wildcard ../../util/*.c) ${CBOR} 19 | SRC_COMMON += $(wildcard ../../messaging/coap/*.c ../../api/*.c ../../port/openthread/*.c*) 20 | 21 | SRC_CLIENT = $(SRC_COMMON) ../../apps/client_openthread.c 22 | SRC_SERVER = $(SRC_COMMON) ../../apps/server_openthread.c 23 | 24 | OBJ_CLIENT = $(addprefix ${PATH_OBJ}/client/, $(addsuffix .o, $(basename $(notdir $(SRC_CLIENT))))) 25 | OBJ_SERVER = $(addprefix ${PATH_OBJ}/server/, $(addsuffix .o, $(basename $(notdir $(SRC_SERVER))))) 26 | 27 | CFLAGS += -Wall -Wextra 28 | CFLAGS += -I./ -I../../include/ -I../../ -I../ 29 | CFLAGS += -I${OPENTHREAD_PATH} -I${OPENTHREAD_PATH}/output/include -I${OPENTHREAD_PATH}/src/core 30 | CFLAGS += -I${OPENTHREAD_PATH}/third_party/mbedtls/repo.patched/include 31 | CFLAGS += -DOPENTHREAD_FTD 32 | 33 | VPATH=../../messaging/coap/:../../util/:../../api/:../../deps/tinycbor/src/:../../apps: 34 | 35 | LIBS = -L${OPENTHREAD_LIB_PATH} -lopenthread-ftd -lmbedcrypto \ 36 | -lopenthread-${OPENTHREAD_BOARD} -lopenthread-diag ${BOARD_LIBS} 37 | 38 | ifeq ($(RETARGET),1) 39 | CFLAGS += -DOC_RETARGET 40 | endif 41 | 42 | ifeq ($(DEBUG),1) 43 | CFLAGS += -DOC_DEBUG -g -O0 44 | else 45 | CFLAGS += -g -O0 46 | endif 47 | 48 | ifeq ($(SECURE),1) 49 | SRC_COMMON += oc_acl.c oc_cred.c oc_doxm.c oc_pstat.c oc_dtls.c oc_svr.c oc_store.c 50 | SRC_COMMON += memory_buffer_alloc.c 51 | CFLAGS += -DOC_SECURITY 52 | endif 53 | 54 | CXXFLAGS := ${CFLAGS} 55 | 56 | CFLAGS += -std=c99 57 | 58 | SAMPLES = ${PATH_BIN}/server ${PATH_BIN}/client 59 | 60 | all: $(SAMPLES) 61 | 62 | .PHONY: clean cleanall 63 | 64 | -include ${PATH_OBJ}/*.d 65 | -include ${PATH_OBJ}/client/*.d 66 | -include ${PATH_OBJ}/server/*.d 67 | 68 | ${PATH_OBJ}/server/%.o: %.c 69 | @mkdir -p ${@D} 70 | ${CC} -c -o $@ ${CFLAGS} -DOC_SERVER -MMD $< 71 | 72 | ${PATH_OBJ}/server/%.o: %.cpp 73 | @mkdir -p ${@D} 74 | ${CC} -c -o $@ ${CXXFLAGS} -DOC_SERVER -MMD $< 75 | 76 | ${PATH_OBJ}/client/%.o: %.c 77 | @mkdir -p ${@D} 78 | ${CC} -c -o $@ ${CFLAGS} -DOC_CLIENT -MMD $< 79 | 80 | ${PATH_OBJ}/client/%.o: %.cpp 81 | @mkdir -p ${@D} 82 | ${CC} -c -o $@ ${CXXFLAGS} -DOC_CLIENT -MMD $< 83 | 84 | ${PATH_BIN}/server: ${OBJ_SERVER} 85 | @mkdir -p ${@D} 86 | ${CC} -o $@ $(OBJ_SERVER) ${CFLAGS} ${LDFLAGS} ${LIBS} 87 | 88 | ${PATH_BIN}/client: ${OBJ_CLIENT} 89 | @mkdir -p ${@D} 90 | ${CC} -o $@ $(OBJ_CLIENT) ${CFLAGS} ${LDFLAGS} ${LIBS} 91 | 92 | clean: 93 | rm -rf ${PATH_OBJ} 94 | 95 | cleanall: clean 96 | rm -rf ${PATH_BIN} 97 | 98 | -------------------------------------------------------------------------------- /port/openthread/Makefile-efr32: -------------------------------------------------------------------------------- 1 | CC = arm-none-eabi-gcc 2 | 3 | RETARGET = 1 4 | 5 | CFLAGS = -mcpu=cortex-m4 -mfloat-abi=soft -mthumb 6 | CFLAGS += -fdata-sections -ffunction-sections 7 | 8 | LDFLAGS = -nostartfiles -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections 9 | LDFLAGS += -T ${OPENTHREAD_PATH}/third_party/silabs/gecko_sdk_suite/v2.0/platform/Device/SiliconLabs/EFR32MG12P/Source/GCC/efr32mg12p.ld 10 | 11 | BOARD_LIBS = -L${OPENTHREAD_PATH}/third_party/silabs/gecko_sdk_suite/v2.0/platform/radio/rail_lib/autogen/librail_release/ \ 12 | -lrail_efr32xg12_gcc_release -lopenthread-efr32 -------------------------------------------------------------------------------- /port/openthread/Makefile-posix: -------------------------------------------------------------------------------- 1 | TARGET_TUPLE = ${shell ${OPENTHREAD_PATH}/third_party/nlbuild-autotools/repo/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g'} 2 | LDFLAGS = -L ${OPENTHREAD_PATH}/output/${TARGET_TUPLE}/lib 3 | BOARD_LIBS = -lstdc++ -------------------------------------------------------------------------------- /port/openthread/Makefile-samr21: -------------------------------------------------------------------------------- 1 | CC = arm-none-eabi-gcc 2 | 3 | RETARGET = 1 4 | 5 | CFLAGS = -mcpu=cortex-m0plus -mfloat-abi=soft -mthumb 6 | CFLAGS += -fdata-sections -ffunction-sections 7 | 8 | LDFLAGS = -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections -Wl,--entry=Reset_Handler 9 | LDFLAGS += -T ${OPENTHREAD_PATH}/third_party/microchip/include/samr21x18a.ld -------------------------------------------------------------------------------- /port/openthread/README: -------------------------------------------------------------------------------- 1 | 1) Download and build openthread https://openthread.io/guides/building/ 2 | 3 | 2) Set following variables in Makefile: 4 | * OPENTHREAD_PATH - path to openthread sources 5 | * OPENTHREAD_LIB_PATH - path to openthread libraries 6 | ($(OPENTHREAD_PATH)/output/{platform}/lib}) 7 | * OPENTHREAD_BOARD - openthread platform 8 | * CC - gcc compiler (for cross compilation) 9 | * other compiler flags related to your platform (for cross compilation) 10 | 11 | 3) Perform the build: 12 | make 13 | Add DEBUG=1 to include debug output from IoTivity-Constrained. 14 | 15 | 4) Launch the demo: 16 | ./server 1 17 | ./client 2 18 | -------------------------------------------------------------------------------- /port/openthread/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_assert.h" 18 | 19 | void abort_impl() 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /port/openthread/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "oc_clock.h" 18 | #include "oc_api.h" 19 | 20 | #include 21 | 22 | static uint32_t prev_time = 0; 23 | static uint32_t high_time = 0; 24 | 25 | void 26 | oc_clock_init(void) 27 | { 28 | } 29 | 30 | oc_clock_time_t 31 | oc_clock_time(void) 32 | { 33 | uint32_t time = otPlatAlarmMilliGetNow(); 34 | 35 | if (time < prev_time) { 36 | high_time++; 37 | } 38 | 39 | prev_time = time; 40 | 41 | return (uint64_t)high_time << 32 | time; 42 | } 43 | 44 | unsigned long 45 | oc_clock_seconds(void) 46 | { 47 | unsigned long time = oc_clock_time() / OC_CLOCK_SECOND; 48 | 49 | return time; 50 | } 51 | 52 | void 53 | oc_clock_wait(oc_clock_time_t t) 54 | { 55 | (void)t; 56 | } 57 | -------------------------------------------------------------------------------- /port/openthread/ocInstance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "ocInstance.hpp" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | extern "C" { 24 | #include "oc_api.h" 25 | #include "oc_assert.h" 26 | } 27 | 28 | static otDEFINE_ALIGNED_VAR(sOcInstanceRaw, sizeof(ocInstance), uint64_t); 29 | 30 | extern "C" { 31 | void 32 | ocInstanceInit(const oc_handler_t *handler) 33 | { 34 | ocInstance *instance = NULL; 35 | 36 | instance = new(&sOcInstanceRaw) ocInstance(); 37 | 38 | oc_assert(instance); 39 | 40 | oc_assert(oc_main_init(handler) == 0); 41 | } 42 | 43 | void 44 | ocInstanceSignal() 45 | { 46 | ocInstance::GetInstance()->PollRequest(); 47 | } 48 | } 49 | 50 | ocInstance *ocInstance::sInstance = NULL; 51 | 52 | ocInstance * 53 | ocInstance::GetInstance() 54 | { 55 | return sInstance; 56 | } 57 | 58 | ocInstance::ocInstance() : 59 | mPollRequest(ot::Instance::Get(), &ocInstance::HandlePollRequest, this), 60 | mPollTimer(ot::Instance::Get(), &ocInstance::HandlePollTimer, this) 61 | { 62 | sInstance = this; 63 | 64 | mPollRequest.Post(); 65 | } 66 | 67 | void 68 | ocInstance::PollRequest() 69 | { 70 | mPollRequest.Post(); 71 | } 72 | 73 | void 74 | ocInstance::HandlePollRequest(ot::Tasklet &tasklet) 75 | { 76 | (void)tasklet; 77 | 78 | ocInstance::GetInstance()->onPollRequest(); 79 | } 80 | 81 | void 82 | ocInstance::HandlePollTimer(ot::Timer &timer) 83 | { 84 | (void)timer; 85 | 86 | ocInstance::GetInstance()->onPollTimer(); 87 | } 88 | 89 | void 90 | ocInstance::onPollRequest() 91 | { 92 | oc_clock_time_t time = oc_main_poll(); 93 | 94 | OC_DBG("Poll %lu", time); 95 | 96 | if (time){ 97 | mPollTimer.StartAt(time, 0); 98 | } else { 99 | mPollTimer.Stop(); 100 | } 101 | } 102 | 103 | void 104 | ocInstance::onPollTimer() 105 | { 106 | onPollRequest(); 107 | } 108 | 109 | -------------------------------------------------------------------------------- /port/openthread/ocInstance.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OCINSTANCE_HPP_ 18 | #define OCINSTANCE_HPP_ 19 | 20 | #include 21 | #include 22 | 23 | class ocInstance 24 | { 25 | public: 26 | ocInstance(); 27 | 28 | static ocInstance *GetInstance(); 29 | 30 | void PollRequest(); 31 | 32 | private: 33 | ot::Tasklet mPollRequest; 34 | ot::TimerMilli mPollTimer; 35 | static ocInstance *sInstance; 36 | 37 | static void HandlePollRequest(ot::Tasklet &aTasklet); 38 | static void HandlePollTimer(ot::Timer &aTimer); 39 | 40 | void onPollRequest(); 41 | void onPollTimer(); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /port/openthread/oc_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_CONFIG_H 18 | #define OC_CONFIG_H 19 | 20 | /* Time resolution */ 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef uint64_t oc_clock_time_t; 28 | /* 1 clock tick = 1ms */ 29 | #define OC_CLOCK_CONF_TICKS_PER_SECOND (1000) 30 | 31 | #define OC_BYTES_POOL_SIZE (900) 32 | #define OC_INTS_POOL_SIZE (4) 33 | #define OC_DOUBLES_POOL_SIZE (4) 34 | 35 | /* Server-side parameters */ 36 | /* Maximum number of server resources */ 37 | #define OC_MAX_APP_RESOURCES (1) 38 | 39 | /* Common paramters */ 40 | /* Maximum size of request/response PDUs */ 41 | #define OC_MAX_APP_DATA_SIZE (600) 42 | 43 | /* Maximum number of concurrent requests */ 44 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (2) 45 | 46 | /* Maximum number of nodes in a payload tree structure */ 47 | #define OC_MAX_NUM_REP_OBJECTS (70) 48 | 49 | /* Number of devices on the OCF platform */ 50 | #define OC_MAX_NUM_DEVICES (1) 51 | 52 | #define OC_MAX_NUM_ENDPOINTS (4) 53 | 54 | /* Security layer */ 55 | /* Maximum number of authorized clients */ 56 | #define OC_MAX_NUM_SUBJECTS (1) 57 | 58 | /* Maximum number of concurrent DTLS sessions */ 59 | #define OC_MAX_DTLS_PEERS (1) 60 | 61 | /* Max inactivity timeout before tearing down DTLS connection */ 62 | #define OC_DTLS_INACTIVITY_TIMEOUT (10) 63 | 64 | #ifdef __cplusplus 65 | } // extern "C" 66 | #endif 67 | 68 | #endif /* OC_CONFIG_H */ 69 | -------------------------------------------------------------------------------- /port/openthread/oc_instance.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_INSTANCE_H_ 18 | #define OC_INSTANCE_H_ 19 | 20 | #include "oc_api.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | void ocInstanceInit(const oc_handler_t *handler); 27 | 28 | void ocInstanceSignal(); 29 | 30 | #ifdef __cplusplus 31 | } // extern "C" 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /port/openthread/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "oc_random.h" 18 | #include "oc_log.h" 19 | 20 | #include 21 | 22 | void 23 | oc_random_init(void) 24 | { 25 | } 26 | 27 | unsigned int 28 | oc_random_value(void) 29 | { 30 | return otPlatRandomGet(); 31 | } 32 | 33 | void 34 | oc_random_destroy(void) 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /port/openthread/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_storage.h" 18 | 19 | #ifdef OC_SECURITY 20 | 21 | #endif /* OC_SECURITY */ 22 | -------------------------------------------------------------------------------- /port/openthread/uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright 2018 Oleksandr Grytsov 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #ifdef OC_RETARGET 20 | 21 | #define TX_BUFFER_SIZE 1024 22 | 23 | static uint16_t tx_head = 0; 24 | static uint16_t tx_tail = 0; 25 | static uint16_t tx_size = 0; 26 | static char tx_buffer[TX_BUFFER_SIZE]; 27 | 28 | static void 29 | send(void) 30 | { 31 | if (tx_tail > tx_head) { 32 | tx_size = TX_BUFFER_SIZE - tx_tail; 33 | } else { 34 | tx_size = tx_head - tx_tail; 35 | } 36 | 37 | if (tx_size) { 38 | otPlatUartSend((uint8_t *)&tx_buffer[tx_tail], tx_size); 39 | } 40 | } 41 | 42 | static bool 43 | put_char(char c) 44 | { 45 | uint16_t next_head = tx_head + 1; 46 | 47 | if (next_head == TX_BUFFER_SIZE) { 48 | next_head = 0; 49 | } 50 | 51 | if (next_head == tx_tail) { 52 | return false; 53 | } 54 | 55 | tx_buffer[tx_head] = c; 56 | tx_head = next_head; 57 | 58 | return true; 59 | } 60 | 61 | int 62 | _write(int file, const char *ptr, int len) 63 | { 64 | (void)file; 65 | 66 | int i; 67 | 68 | for(i = 0; i < len; i++) { 69 | 70 | if (*ptr == '\n') { 71 | if (!put_char('\r')) { 72 | break; 73 | } 74 | } 75 | 76 | if (!put_char(*ptr)) { 77 | break; 78 | } 79 | 80 | ptr++; 81 | } 82 | 83 | if (tx_size == 0) { 84 | send(); 85 | } 86 | 87 | return i; 88 | } 89 | 90 | #endif 91 | 92 | void 93 | otPlatUartSendDone(void) 94 | { 95 | #ifdef OC_RETARGET 96 | tx_tail += tx_size; 97 | 98 | if (tx_tail == TX_BUFFER_SIZE) { 99 | tx_tail = 0; 100 | } 101 | 102 | tx_size = 0; 103 | 104 | send(); 105 | #endif 106 | } 107 | 108 | void 109 | otPlatUartReceived(const uint8_t *buf, uint16_t len) 110 | { 111 | (void)buf; 112 | (void)len; 113 | } 114 | -------------------------------------------------------------------------------- /port/riot/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(CLIENT),1) 2 | APP_SRC = ../../apps/client_riot.c 3 | else 4 | APP_SRC = ../../apps/server_riot.c 5 | SERVER=1 6 | endif 7 | 8 | APPLICATION = ocf_app 9 | 10 | #Set RIOTBASE appropriately below. 11 | RIOTBASE ?= ${HOME}/RIOT/ 12 | BOARD ?= native 13 | 14 | BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ 15 | nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \ 16 | stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ 17 | yunjia-nrf51822 z1 nucleo-f072 18 | 19 | USEMODULE += gnrc_netdev_default 20 | USEMODULE += auto_init_gnrc_netif 21 | USEMODULE += gnrc_ipv6 22 | USEMODULE += gnrc_conn_udp 23 | USEMODULE += pthread 24 | USEMODULE += gnrc_ndp_router 25 | USEMODULE += gnrc_icmpv6_echo 26 | USEMODULE += gnrc_ipv6_router_default 27 | #USEMODULE += gnrc_rpl 28 | #USEMODULE += auto_init_gnrc_rpl 29 | 30 | CFLAGS = -std=gnu99 -I./ -I../../include/ -I../../ #-fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-reorder-functions -fno-defer-pop -fno-strict-overflow 31 | 32 | CBOR = ../../deps/tinycbor/src/cborencoder.c ../../deps/tinycbor/src/cborencoder_close_container_checked.c ../../deps/tinycbor/src/cborparser.c 33 | 34 | DTLS=../../deps/tinydtls/ccm.c ../../deps/tinydtls/hmac.c ../../deps/tinydtls/netq.c ../../deps/tinydtls/peer.c ../../deps/tinydtls/dtls_time.c ../../deps/tinydtls/session.c ../../deps/tinydtls/sha2/sha2.c ../../deps/tinydtls/ecc/ecc.c ../../deps/tinydtls/aes/rijndael.c ../../deps/tinydtls/crypto.c ../../deps/tinydtls/dtls.c 35 | 36 | DTLSFLAGS=-DDTLSV12 -DWITH_SHA256 -DDTLS_CHECK_CONTENTTYPE -DWITH_OCF -I../../deps/tinydtls -DNDEBUG 37 | 38 | SRC_COMMON = $(wildcard ../../util/*.c) ${CBOR} 39 | SRC = $(wildcard ../../messaging/coap/*.c ../../api/*.c) 40 | VPATH=../../messaging/coap/:../../util/:../../api/:../../deps/tinycbor/src/: 41 | 42 | ifeq ($(CLIENT),1) 43 | CFLAGS += -DOC_CLIENT 44 | endif 45 | 46 | ifeq ($(SERVER),1) 47 | CFLAGS += -DOC_SERVER 48 | endif 49 | 50 | ifeq ($(SECURE),1) 51 | SRC += $(wildcard ../../security/*.c) 52 | SRC_COMMON += ${DTLS} 53 | CFLAGS += ${DTLSFLAGS} -DOC_SECURITY 54 | VPATH += ../../security/:../../deps/tinydtls/:../../deps/tinydtls/aes/:../../deps/tinydtls/sha2/:../../deps/tinydtls/ecc/: 55 | endif 56 | 57 | ifeq ($(DEBUG),1) 58 | CFLAGS += -DOC_DEBUG -g 59 | endif 60 | 61 | APP_OBJ = $(APP_SRC:.c=.o) 62 | OBJ_COMMON = $(SRC_COMMON:.c=.o) 63 | OBJ_FRAMEWORK = $(SRC:.c=.o) 64 | APPDEPS += ${OBJ_COMMON} ${OBJ_FRAMEWORK} ${APP_OBJ} 65 | 66 | include $(RIOTBASE)/Makefile.include 67 | 68 | ${APP_OBJ}: ${APP_SRC} 69 | ${CC} -c -o $@ $< ${CFLAGS} ${INCLUDES} 70 | 71 | %.o: %.c 72 | ${CC} -c -o $@ $< ${CFLAGS} 73 | 74 | clean: clean_iotivity_constrained 75 | 76 | clean_iotivity_constrained: 77 | rm -rf ${OBJ_COMMON} ${OBJ_FRAMEWORK} ${APP_OBJ} 78 | 79 | # Change this to 0 show compiler invocation lines by default: 80 | QUIET ?= 0 81 | 82 | -------------------------------------------------------------------------------- /port/riot/README: -------------------------------------------------------------------------------- 1 | 1) Set RIOTBASE path in port/riot/Makefile. 2 | 3 | 2) Perform the build: 4 | Run export BOARD=native && make CLIENT=1 (or make SERVER=1) 5 | CLIENT=1/SERVER=1 selects the client_riot/server_riot sample. 6 | Add DEBUG=1 to include debug output from IoTivity-Constrained. 7 | 8 | 3) Setup a tap interface: 9 | sudo ip tuntap add tap0 mode tap user ${USER} 10 | sudo ip link set tap0 up 11 | 12 | 4) Run the application: 13 | bin/native/ocf_app.elf tap0 14 | 15 | client_riot/server_riot may be tested against the server_linux and 16 | client_linux samples. 17 | -------------------------------------------------------------------------------- /port/riot/abort.c: -------------------------------------------------------------------------------- 1 | #include "port/oc_assert.h" 2 | 3 | // TODO: 4 | void abort_impl(void) {} 5 | -------------------------------------------------------------------------------- /port/riot/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_clock.h" 18 | #include "xtimer.h" 19 | 20 | void 21 | oc_clock_init(void) 22 | { 23 | xtimer_init(); 24 | } 25 | 26 | oc_clock_time_t 27 | oc_clock_time(void) 28 | { 29 | return (oc_clock_time_t)((xtimer_now64().ticks64 + 999) / 1000); 30 | } 31 | 32 | unsigned long 33 | oc_clock_seconds(void) 34 | { 35 | return (oc_clock_time() + OC_CLOCK_SECOND - 1) / OC_CLOCK_SECOND; 36 | } 37 | 38 | void 39 | oc_clock_wait(oc_clock_time_t t) 40 | { 41 | xtimer_usleep(t * 1000); 42 | } 43 | -------------------------------------------------------------------------------- /port/riot/oc_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_CONFIG_H 18 | #define OC_CONFIG_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* Time resolution */ 25 | #include 26 | typedef uint64_t oc_clock_time_t; 27 | /* 1 clock tick = 1ms */ 28 | #define OC_CLOCK_CONF_TICKS_PER_SECOND (1000) 29 | 30 | #define OC_BYTES_POOL_SIZE (900) 31 | #define OC_INTS_POOL_SIZE (4) 32 | #define OC_DOUBLES_POOL_SIZE (4) 33 | 34 | /* Server-side parameters */ 35 | /* Maximum number of server resources */ 36 | #define OC_MAX_APP_RESOURCES (1) 37 | 38 | /* Common paramters */ 39 | /* Maximum size of request/response PDUs */ 40 | #define OC_MAX_APP_DATA_SIZE (600) 41 | 42 | /* Maximum number of concurrent requests */ 43 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (2) 44 | 45 | /* Maximum number of nodes in a payload tree structure */ 46 | #define OC_MAX_NUM_REP_OBJECTS (70) 47 | 48 | /* Number of devices on the OCF platform */ 49 | #define OC_MAX_NUM_DEVICES (1) 50 | 51 | #define OC_MAX_NUM_ENDPOINTS (4) 52 | 53 | /* Security layer */ 54 | /* Maximum number of authorized clients */ 55 | #define OC_MAX_NUM_SUBJECTS (1) 56 | 57 | /* Maximum number of concurrent DTLS sessions */ 58 | #define OC_MAX_DTLS_PEERS (1) 59 | 60 | /* Max inactivity timeout before tearing down DTLS connection */ 61 | #define OC_DTLS_INACTIVITY_TIMEOUT (10) 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* OC_CONFIG_H */ 68 | -------------------------------------------------------------------------------- /port/riot/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "random.h" 18 | #include "port/oc_random.h" 19 | 20 | // FIXME: Employ an appropriate seeding strategy here for the PRNG. 21 | void 22 | oc_random_init(void) 23 | { 24 | random_init(0); 25 | } 26 | 27 | unsigned int 28 | oc_random_value(void) 29 | { 30 | return random_uint32(); 31 | } 32 | 33 | void 34 | oc_random_destroy(void) 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /port/riot/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_storage.h" 18 | #ifdef OC_SECURITY 19 | // TODO: 20 | 21 | int 22 | oc_storage_config(const char *store) 23 | { 24 | (void)store; 25 | return 0; 26 | } 27 | 28 | long 29 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 30 | { 31 | (void)store; 32 | (void)buf; 33 | (void)size; 34 | return size; 35 | } 36 | 37 | long 38 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 39 | { 40 | (void)store; 41 | (void)buf; 42 | (void)size; 43 | return size; 44 | } 45 | #endif /* OC_SECURITY */ 46 | -------------------------------------------------------------------------------- /port/tizenrt/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2017 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_assert.h" 19 | #include 20 | 21 | void 22 | abort_impl(void) 23 | { 24 | abort(); 25 | } 26 | 27 | void 28 | exit_impl(int status) 29 | { 30 | exit(status); 31 | } 32 | -------------------------------------------------------------------------------- /port/tizenrt/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_clock.h" 19 | #include "port/oc_assert.h" 20 | 21 | void 22 | oc_clock_init(void) 23 | { 24 | oc_abort(__func__); 25 | } 26 | 27 | oc_clock_time_t 28 | oc_clock_time(void) 29 | { 30 | oc_clock_time_t time = 0; 31 | oc_abort(__func__); 32 | return time; 33 | } 34 | 35 | unsigned long 36 | oc_clock_seconds(void) 37 | { 38 | oc_abort(__func__); 39 | return 0; 40 | } 41 | 42 | void 43 | oc_clock_wait(oc_clock_time_t t) 44 | { 45 | (void) t; 46 | oc_abort(__func__); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /port/tizenrt/ipcontext.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | #ifndef IPCONTEXT_H 20 | #define IPCONTEXT_H 21 | 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef OC_TCP 30 | typedef struct tcp_context_t { 31 | void* server; 32 | int server_sock; 33 | uint16_t port; 34 | #ifdef OC_SECURITY 35 | void* secure; 36 | int secure_sock; 37 | uint16_t tls_port; 38 | #endif /* OC_SECURITY */ 39 | #ifdef OC_IPV4 40 | void* server4; 41 | int server4_sock; 42 | uint16_t port4; 43 | #ifdef OC_SECURITY 44 | void* secure4; 45 | int secure4_sock; 46 | uint16_t tls4_port; 47 | #endif /* OC_SECURITY */ 48 | #endif /* OC_IPV4 */ 49 | int connect_pipe[2]; 50 | } tcp_context_t; 51 | #endif 52 | 53 | typedef struct ip_context_t { 54 | struct ip_context_t *next; 55 | int mcast_sock; 56 | int server_sock; 57 | uint16_t port; 58 | #ifdef OC_SECURITY 59 | void* secure; 60 | int secure_sock; 61 | uint16_t dtls_port; 62 | #endif /* OC_SECURITY */ 63 | #ifdef OC_IPV4 64 | void* mcast4; 65 | void* server4; 66 | int mcast4_sock; 67 | int server4_sock; 68 | uint16_t port4; 69 | #ifdef OC_SECURITY 70 | void* secure4; 71 | int secure4_sock; 72 | uint16_t dtls4_port; 73 | #endif /* OC_SECURITY */ 74 | #endif /* OC_IPV4 */ 75 | #ifdef OC_TCP 76 | tcp_context_t tcp; 77 | #endif 78 | int terminate; 79 | size_t device; 80 | int shutdown_pipe[2]; 81 | } ip_context_t; 82 | 83 | #ifdef __cplusplus 84 | } // extern "C" 85 | #endif 86 | 87 | #endif /* IPCONTEXT_H */ 88 | -------------------------------------------------------------------------------- /port/tizenrt/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_random.h" 19 | #include "port/oc_assert.h" 20 | 21 | 22 | void 23 | oc_random_init(void) 24 | { 25 | oc_abort(__func__); 26 | } 27 | 28 | unsigned int 29 | oc_random_value(void) 30 | { 31 | unsigned int rand = 0; 32 | oc_abort(__func__); 33 | return rand; 34 | } 35 | 36 | void 37 | oc_random_destroy(void) 38 | { 39 | oc_abort(__func__); 40 | } 41 | -------------------------------------------------------------------------------- /port/tizenrt/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Samsung Electronics France SAS 3 | // Copyright (c) 2016 Intel Corporation 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | */ 17 | 18 | #include "port/oc_storage.h" 19 | #include "port/oc_assert.h" 20 | 21 | #ifdef OC_SECURITY 22 | 23 | int 24 | oc_storage_config(const char *store) 25 | { 26 | (void) store; 27 | oc_abort(__func__); 28 | return 0; 29 | } 30 | 31 | long 32 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 33 | { 34 | (void) store; 35 | (void) buf; 36 | oc_abort(__func__); 37 | return size; 38 | } 39 | 40 | long 41 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 42 | { 43 | (void) store; 44 | (void) buf; 45 | oc_abort(__func__); 46 | return size; 47 | } 48 | #endif /* OC_SECURITY */ 49 | -------------------------------------------------------------------------------- /port/tizenrt/tcpadapter.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | 20 | #ifndef TCP_ADAPTER_H 21 | #define TCP_ADAPTER_H 22 | 23 | #include "ipcontext.h" 24 | #include "port/oc_connectivity.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef enum { 31 | TCP_STATUS_NONE = 0, 32 | TCP_STATUS_ACCEPT, 33 | TCP_STATUS_RECEIVE, 34 | TCP_STATUS_ERROR 35 | } tcp_receive_state_t; 36 | 37 | int oc_tcp_connectivity_init(ip_context_t *dev); 38 | 39 | void oc_tcp_connectivity_shutdown(ip_context_t *dev); 40 | 41 | int oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message, 42 | const void *receiver); 43 | 44 | void oc_tcp_add_socks_to_fd_set(ip_context_t *dev); 45 | 46 | void oc_tcp_set_session_fds(void *fds); 47 | 48 | tcp_receive_state_t oc_tcp_receive_message(ip_context_t *dev, void *fds, 49 | oc_message_t *message); 50 | 51 | #ifdef __cplusplus 52 | } // extern "C" 53 | #endif 54 | 55 | #endif /* TCP_ADAPTER_H */ 56 | -------------------------------------------------------------------------------- /port/unittest/clocktest.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | extern "C" { 26 | #include "port/oc_clock.h" 27 | } 28 | 29 | class TestClock: public testing::Test 30 | { 31 | protected: 32 | virtual void SetUp() 33 | { 34 | } 35 | 36 | virtual void TearDown() 37 | { 38 | } 39 | }; 40 | 41 | TEST_F(TestClock, oc_clock_time) 42 | { 43 | oc_clock_time_t timestamp = oc_clock_time(); 44 | EXPECT_NE(0, timestamp); 45 | } 46 | 47 | TEST_F(TestClock, oc_clock_seconds) 48 | { 49 | long time_seconds = oc_clock_seconds(); 50 | EXPECT_NE(0, time_seconds); 51 | } 52 | 53 | TEST_F(TestClock, oc_clock_wait) 54 | { 55 | oc_clock_time_t wait_time = 1 * (OC_CLOCK_SECOND / 1000); 56 | oc_clock_time_t prev_stamp = oc_clock_time(); 57 | oc_clock_wait(wait_time); 58 | oc_clock_time_t cur_stamp = oc_clock_time(); 59 | 60 | int seconds = (cur_stamp - prev_stamp) / OC_CLOCK_SECOND; 61 | EXPECT_EQ(1, seconds); 62 | } 63 | -------------------------------------------------------------------------------- /port/unittest/storagetest.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | extern "C" { 26 | #include "port/oc_storage.h" 27 | } 28 | 29 | #ifdef OC_SECURITY 30 | static const char *path = "./storage_test"; 31 | static const char *file_name = "storage_store"; 32 | static uint8_t buf[100]; 33 | #endif /* OC_SECURITY */ 34 | 35 | class TestStorage: public testing::Test 36 | { 37 | protected: 38 | virtual void SetUp() 39 | { 40 | } 41 | 42 | virtual void TearDown() 43 | { 44 | } 45 | }; 46 | 47 | #ifdef OC_SECURITY 48 | TEST_F(TestStorage, oc_storage_config_fail_with_length_over) 49 | { 50 | int ret = oc_storage_config("./storage_test_long_size_fail_storage_test_long_size_fail_storage_test_long_size_fail"); 51 | EXPECT_NE(0, ret); 52 | } 53 | 54 | TEST_F(TestStorage, oc_storage_read_fail) 55 | { 56 | int ret = oc_storage_read(file_name, buf, 100); 57 | EXPECT_NE(0, ret); 58 | } 59 | 60 | TEST_F(TestStorage, oc_storage_write_fail) 61 | { 62 | int ret = oc_storage_write(file_name, buf, 100); 63 | EXPECT_NE(0, ret); 64 | } 65 | 66 | TEST_F(TestStorage, oc_storage_config) 67 | { 68 | int ret = oc_storage_config(path); 69 | EXPECT_EQ(0, ret); 70 | } 71 | 72 | TEST_F(TestStorage, oc_storage_write) 73 | { 74 | uint8_t str[100] = "storage"; 75 | int ret = oc_storage_write(file_name, str, strlen((char *)str)); 76 | EXPECT_LE(0, ret); 77 | ret = oc_storage_read(file_name, buf, 100); 78 | EXPECT_LE(0, ret); 79 | EXPECT_STREQ(str, buf); 80 | } 81 | #endif /* OC_SECURITY */ -------------------------------------------------------------------------------- /port/windows/abort.c: -------------------------------------------------------------------------------- 1 | #include "port/oc_assert.h" 2 | #include 3 | 4 | void 5 | abort_impl(void) 6 | { 7 | exit(1); 8 | } 9 | 10 | void 11 | exit_impl(int status) 12 | { 13 | exit(status); 14 | } 15 | -------------------------------------------------------------------------------- /port/windows/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Lynx Technology 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_clock.h" 18 | 19 | #include 20 | #define WIN32_LEAN_AND_MEAN 21 | #include 22 | 23 | static LARGE_INTEGER frequency = { 0 }; 24 | void 25 | oc_clock_init(void) 26 | { 27 | QueryPerformanceFrequency(&frequency); 28 | } 29 | 30 | oc_clock_time_t 31 | oc_clock_time(void) 32 | { 33 | LARGE_INTEGER count = { 0 }; 34 | if (frequency.QuadPart && QueryPerformanceCounter(&count)) { 35 | oc_clock_time_t t = 36 | 1000 * count.QuadPart / frequency.QuadPart; // milliseconds 37 | return t; 38 | } 39 | // fall back if no QueryPerformanceCounter available 40 | return GetTickCount64(); 41 | } 42 | 43 | unsigned long 44 | oc_clock_seconds(void) 45 | { 46 | return (unsigned long)time(0); 47 | } 48 | 49 | void 50 | oc_clock_wait(oc_clock_time_t t) 51 | { 52 | Sleep((DWORD)(t * 1000)); 53 | } 54 | -------------------------------------------------------------------------------- /port/windows/oc_config.h: -------------------------------------------------------------------------------- 1 | #ifndef OC_CONFIG_H 2 | #define OC_CONFIG_H 3 | 4 | /* Time resolution */ 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef uint64_t oc_clock_time_t; 12 | #define strncasecmp _strnicmp 13 | /* Sets one clock tick to 1 ms */ 14 | #define OC_CLOCK_CONF_TICKS_PER_SECOND (1000) 15 | 16 | /* Security Layer */ 17 | /* Max inactivity timeout before tearing down DTLS connection */ 18 | #define OC_DTLS_INACTIVITY_TIMEOUT (300) 19 | 20 | #if !defined(OC_DYNAMIC_ALLOCATION) 21 | #error "Set preprocessor definition OC_DYNAMIC_ALLOCATION in your build" 22 | #endif /* OC_DYNAMIC_ALLOCATION */ 23 | #if !defined(OC_COLLECTIONS) 24 | #define OC_COLLECTIONS 25 | #endif /* OC_COLLECTIONS */ 26 | #if !defined(OC_BLOCK_WISE) 27 | #define OC_BLOCK_WISE 28 | #endif /* OC_BLOCK_WISE */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* OC_CONFIG_H */ 35 | -------------------------------------------------------------------------------- /port/windows/patch-mbedtls.bat: -------------------------------------------------------------------------------- 1 | @rem This batch file uses Git to apply the mbedTLS patches 2 | @rem on Windows. Please adapt GIT_CMD below as required. 3 | @rem Also adapt PATCH_CMD with the location of the patch 4 | @rem utility, if automatic resolution does not work. 5 | 6 | @rem If git.exe is not in PATH, then set the full path. 7 | set GIT_CMD=git 8 | 9 | @rem Get location of Git. ~p drops the executable name and keeps 10 | @rem drive letter and path only. The output path has a trailing \. 11 | for /f "tokens=*" %%i in ('where %GIT_CMD%') do set GIT_INSTALL_DIR=%%~dpi 12 | 13 | @rem Now iterate up to find the Git top-level directory. 14 | :redo 15 | @rem Drop the trailing slash 16 | set GIT_INSTALL_DIR=%GIT_INSTALL_DIR:~0,-1% 17 | @rem Get parent directory 18 | for /f "tokens=*" %%i in ("%GIT_INSTALL_DIR%") do set GIT_INSTALL_DIR=%%~dpi 19 | @rem Get the directory name (last folder) 20 | for /f "tokens=*" %%i in ("%GIT_INSTALL_DIR:~0,-1%") do set LAST_DIR=%%~ni 21 | if "%LAST_DIR%" == "" goto error 22 | if NOT %LAST_DIR% == Git goto redo 23 | 24 | @rem Now search for the patch tool starting from the Git top-level directory 25 | for /f "tokens=*" %%i in ('where /R "%GIT_INSTALL_DIR:~0,-1%" patch.exe') do set PATCH_CMD=%%~fi 26 | 27 | @rem current working directory for recovery 28 | set OLD_CWD=%CD% 29 | 30 | if exist "%~dp0..\..\deps\mbedtls\" ( 31 | cd "%~dp0..\..\deps\mbedtls" || goto error 32 | "%GIT_CMD%" clean -xdf . || goto error 33 | "%GIT_CMD%" reset --hard || goto error 34 | cd "%OLD_CWD%" || goto error 35 | ) 36 | 37 | "%GIT_CMD%" submodule update --init 38 | 39 | cd %~dp0..\..\deps\mbedtls || goto error 40 | @rem git apply cannot deal with "/dev/null" as input to create a new 41 | @rem file. Hence, we are using its patch utility directly. 42 | @rem -r -: do not create reject files if applying hunks fail 43 | @rem -s : work silently 44 | @rem -N : do not reverse the patch if already applied 45 | @rem -p1 : remove first path component from paths in the patches 46 | for /r ..\..\patches %%F IN (*.patch) DO ( 47 | "%PATCH_CMD%" -r - -s -N -p1 < %%F || goto error 48 | ) 49 | @rem VS project can check existence of the file whether to invoke 50 | @rem this batch file or not. 51 | echo patches applied > patched.txt 52 | cd "%OLD_CWD%" 53 | exit /b 0 54 | 55 | :error 56 | cd "%OLD_CWD%" 57 | exit /b 1 58 | -------------------------------------------------------------------------------- /port/windows/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Lynx Technology 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_random.h" 18 | 19 | #define _CRT_RAND_S 20 | #include 21 | #define WIN32_LEAN_AND_MEAN 22 | #include 23 | 24 | void 25 | oc_random_init(void) 26 | { 27 | srand((unsigned)GetTickCount()); 28 | } 29 | 30 | unsigned int 31 | oc_random_value(void) 32 | { 33 | unsigned int val = 0; 34 | rand_s(&val); 35 | return val; 36 | } 37 | 38 | void 39 | oc_random_destroy() 40 | { 41 | } 42 | -------------------------------------------------------------------------------- /port/windows/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_storage.h" 18 | 19 | #ifdef OC_SECURITY 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define STORE_PATH_SIZE 64 26 | 27 | static char store_path[STORE_PATH_SIZE]; 28 | static size_t store_path_len; 29 | static bool path_set = false; 30 | 31 | int 32 | oc_storage_config(const char *store) 33 | { 34 | if (!store || !*store) 35 | return -EINVAL; 36 | store_path_len = strlen(store); 37 | if (store_path_len >= STORE_PATH_SIZE) 38 | return -ENOENT; 39 | 40 | strncpy(store_path, store, store_path_len); 41 | if (store_path[store_path_len - 1] != '/' && 42 | store_path[store_path_len - 1] != '\\') { 43 | ++store_path_len; 44 | if (store_path_len >= STORE_PATH_SIZE) 45 | return -ENOENT; 46 | store_path[store_path_len - 1] = '\\'; 47 | } 48 | path_set = true; 49 | 50 | return 0; 51 | } 52 | 53 | long 54 | oc_storage_read(const char *store, uint8_t *buf, size_t size) 55 | { 56 | FILE *fp = 0; 57 | size_t store_len = strlen(store); 58 | 59 | if (!path_set || (store_len + store_path_len >= STORE_PATH_SIZE)) 60 | return -ENOENT; 61 | 62 | strncpy(store_path + store_path_len, store, store_len); 63 | store_path[store_path_len + store_len] = '\0'; 64 | fp = fopen(store_path, "rb"); 65 | if (!fp) 66 | return -EINVAL; 67 | 68 | size = fread(buf, 1, size, fp); 69 | fclose(fp); 70 | return (long)size; 71 | } 72 | 73 | long 74 | oc_storage_write(const char *store, uint8_t *buf, size_t size) 75 | { 76 | FILE *fp; 77 | size_t store_len = strlen(store); 78 | 79 | if (!path_set || (store_len + store_path_len >= STORE_PATH_SIZE)) 80 | return -ENOENT; 81 | 82 | strncpy(store_path + store_path_len, store, store_len); 83 | store_path[store_path_len + store_len] = '\0'; 84 | fp = fopen(store_path, "wb"); 85 | if (!fp) 86 | return -EINVAL; 87 | 88 | size = fwrite(buf, 1, size, fp); 89 | fclose(fp); 90 | return (long)size; 91 | } 92 | #endif /* OC_SECURITY */ 93 | -------------------------------------------------------------------------------- /port/windows/vs2015/IoTivity-Constrained.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IoTivity-Constrained", "IoTivity-Constrained.vcxproj", "{1866D7A4-FC11-46CA-9377-3BAA69D4BF58}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleClient", "SimpleClient.vcxproj", "{5E14206D-1D40-4AEB-85EE-E085F013ABA8}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleServer", "SimpleServer.vcxproj", "{49A279BB-F431-4310-BEA2-CEDAC797D9E1}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Debug|x64.ActiveCfg = Debug|x64 21 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Debug|x64.Build.0 = Debug|x64 22 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Debug|x64.Deploy.0 = Debug|x64 23 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Debug|x86.ActiveCfg = Debug|Win32 24 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Debug|x86.Build.0 = Debug|Win32 25 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Release|x64.ActiveCfg = Release|x64 26 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Release|x64.Build.0 = Release|x64 27 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Release|x86.ActiveCfg = Release|Win32 28 | {1866D7A4-FC11-46CA-9377-3BAA69D4BF58}.Release|x86.Build.0 = Release|Win32 29 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Debug|x64.ActiveCfg = Debug|x64 30 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Debug|x64.Build.0 = Debug|x64 31 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Debug|x86.ActiveCfg = Debug|Win32 32 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Debug|x86.Build.0 = Debug|Win32 33 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Release|x64.ActiveCfg = Release|x64 34 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Release|x64.Build.0 = Release|x64 35 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Release|x86.ActiveCfg = Release|Win32 36 | {5E14206D-1D40-4AEB-85EE-E085F013ABA8}.Release|x86.Build.0 = Release|Win32 37 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Debug|x64.ActiveCfg = Debug|x64 38 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Debug|x64.Build.0 = Debug|x64 39 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Debug|x86.ActiveCfg = Debug|Win32 40 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Debug|x86.Build.0 = Debug|Win32 41 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Release|x64.ActiveCfg = Release|x64 42 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Release|x64.Build.0 = Release|x64 43 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Release|x86.ActiveCfg = Release|Win32 44 | {49A279BB-F431-4310-BEA2-CEDAC797D9E1}.Release|x86.Build.0 = Release|Win32 45 | EndGlobalSection 46 | GlobalSection(SolutionProperties) = preSolution 47 | HideSolutionNode = FALSE 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /port/windows/vs2015/SimpleClient.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(ProjectDir)\$(Platform)\$(Configuration)\ 5 | WindowsLocalDebugger 6 | 7 | 8 | $(ProjectDir)\$(Platform)\$(Configuration)\ 9 | WindowsLocalDebugger 10 | 11 | 12 | $(ProjectDir)\$(Platform)\$(Configuration)\ 13 | WindowsLocalDebugger 14 | 15 | 16 | $(ProjectDir)\$(Platform)\$(Configuration)\ 17 | WindowsLocalDebugger 18 | 19 | -------------------------------------------------------------------------------- /port/windows/vs2015/SimpleServer.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(ProjectDir)\$(Platform)\$(Configuration)\ 5 | WindowsLocalDebugger 6 | 7 | 8 | $(ProjectDir)\$(Platform)\$(Configuration)\ 9 | WindowsLocalDebugger 10 | 11 | 12 | $(ProjectDir)\$(Platform)\$(Configuration)\ 13 | WindowsLocalDebugger 14 | 15 | 16 | $(ProjectDir)\$(Platform)\$(Configuration)\ 17 | WindowsLocalDebugger 18 | 19 | -------------------------------------------------------------------------------- /port/zephyr/Makefile: -------------------------------------------------------------------------------- 1 | BOARD ?= qemu_x86 2 | 3 | ifeq ($(SECURE),1) 4 | CONF_FILE = prj_secure.conf 5 | else 6 | CONF_FILE = prj.conf 7 | endif 8 | 9 | include ${ZEPHYR_BASE}/Makefile.inc 10 | include $(ZEPHYR_BASE)/samples/net/common/Makefile.ipstack 11 | -------------------------------------------------------------------------------- /port/zephyr/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_NETWORKING=y 2 | CONFIG_NET_UDP=y 3 | CONFIG_NET_IPV6=y 4 | #CONFIG_NET_IPV4=y 5 | #CONFIG_NET_DHCPV4=y 6 | 7 | CONFIG_RANDOM_GENERATOR=y 8 | CONFIG_TEST_RANDOM_GENERATOR=y 9 | CONFIG_INIT_STACKS=y 10 | 11 | #CONFIG_NEWLIB_LIBC=y 12 | #CONFIG_CONSOLE_HANDLER=y 13 | #CONFIG_EARLY_CONSOLE=y 14 | #CONFIG_STDOUT_CONSOLE=y 15 | 16 | #CONFIG_NET_LOG=y 17 | #CONFIG_SYS_LOG_NET_LEVEL=4 18 | #CONFIG_SYS_LOG_SHOW_COLOR=y 19 | #CONFIG_NET_STATISTICS=y 20 | #CONFIG_PRINTK=y 21 | 22 | CONFIG_NET_SLIP_TAP=y 23 | 24 | CONFIG_NET_PKT_RX_COUNT=10 25 | CONFIG_NET_PKT_TX_COUNT=10 26 | CONFIG_NET_BUF_RX_COUNT=20 27 | CONFIG_NET_BUF_TX_COUNT=20 28 | CONFIG_NET_CONTEXT_NET_PKT_POOL=y 29 | 30 | CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 31 | CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4 32 | CONFIG_NET_MAX_CONTEXTS=10 33 | 34 | #CONFIG_NET_SHELL=y 35 | 36 | CONFIG_NET_APP_SETTINGS=y 37 | CONFIG_NET_APP_NEED_IPV6=y 38 | #CONFIG_NET_APP_NEED_IPV4=y 39 | #CONFIG_NET_APP_SERVER=y 40 | #CONFIG_NET_DEBUG_APP=y 41 | CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1" 42 | CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2" 43 | #CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1" 44 | #CONFIG_NET_APP_PEER_IPV4_ADDR="192.0.2.2" 45 | 46 | #CONFIG_NET_DEBUG_CONTEXT=n 47 | 48 | CONFIG_MAIN_STACK_SIZE=4096 49 | -------------------------------------------------------------------------------- /port/zephyr/prj_bt.conf: -------------------------------------------------------------------------------- 1 | CONFIG_NETWORKING=y 2 | CONFIG_NET_IPV6=y 3 | CONFIG_NET_UDP=y 4 | 5 | CONFIG_TEST_RANDOM_GENERATOR=y 6 | CONFIG_INIT_STACKS=y 7 | 8 | CONFIG_NEWLIB_LIBC=y 9 | CONFIG_STDOUT_CONSOLE=y 10 | 11 | CONFIG_NET_PKT_RX_COUNT=10 12 | CONFIG_NET_PKT_TX_COUNT=10 13 | CONFIG_NET_BUF_RX_COUNT=20 14 | CONFIG_NET_BUF_TX_COUNT=20 15 | CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 16 | CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 17 | CONFIG_NET_MAX_CONTEXTS=6 18 | 19 | CONFIG_BT=y 20 | CONFIG_BT_SMP=y 21 | CONFIG_BT_PERIPHERAL=y 22 | CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y 23 | CONFIG_NET_L2_BT_ZEP1656=y 24 | CONFIG_NET_L2_BT=y 25 | CONFIG_BT_DEVICE_NAME="OCF_BLE_NODE" 26 | 27 | CONFIG_NET_APP_SETTINGS=y 28 | CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1" 29 | CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2" 30 | CONFIG_NET_APP_AUTO_INIT=n 31 | 32 | CONFIG_MAIN_STACK_SIZE=4096 33 | -------------------------------------------------------------------------------- /port/zephyr/prj_secure.conf: -------------------------------------------------------------------------------- 1 | CONFIG_NETWORKING=y 2 | CONFIG_NET_IPV6=y 3 | CONFIG_NET_UDP=y 4 | CONFIG_NANO_TIMEOUTS=y 5 | CONFIG_TEST_RANDOM_GENERATOR=y 6 | CONFIG_NET_LOG=y 7 | 8 | CONFIG_NET_SLIP=y 9 | CONFIG_NET_SLIP_TAP=y 10 | 11 | CONFIG_INIT_STACKS=y 12 | CONFIG_PRINTK=n 13 | CONFIG_STDOUT_CONSOLE=y 14 | 15 | CONFIG_NET_NBUF_RX_COUNT=14 16 | CONFIG_NET_NBUF_TX_COUNT=14 17 | CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=2 18 | CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=1 19 | CONFIG_NET_MAX_CONTEXTS=4 20 | 21 | CONFIG_MAIN_STACK_SIZE=2048 22 | 23 | CONFIG_FLASH=y 24 | CONFIG_SPI=y 25 | CONFIG_GPIO=y 26 | CONFIG_SPI_CS_GPIO=y 27 | CONFIG_SPI_0_CS_GPIO_PIN=24 28 | 29 | CONFIG_NET_APP_SETTINGS=y 30 | CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1" 31 | CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2" 32 | -------------------------------------------------------------------------------- /port/zephyr/src/abort.c: -------------------------------------------------------------------------------- 1 | #include "port/oc_assert.h" 2 | 3 | // TODO: 4 | void 5 | abort_impl() 6 | { 7 | } 8 | 9 | void 10 | exit_impl(int status) 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /port/zephyr/src/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef ASSERT_H 18 | #define ASSERT_H 19 | 20 | #include "port/oc_assert.h" 21 | 22 | #define assert oc_assert 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /port/zephyr/src/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_clock.h" 18 | 19 | void 20 | oc_clock_init(void) 21 | { 22 | } 23 | 24 | oc_clock_time_t 25 | oc_clock_time(void) 26 | { 27 | return k_uptime_get(); 28 | } 29 | 30 | unsigned long 31 | oc_clock_seconds(void) 32 | { 33 | return (oc_clock_time() + OC_CLOCK_SECOND - 1) / OC_CLOCK_SECOND; 34 | } 35 | 36 | void 37 | oc_clock_wait(oc_clock_time_t t) 38 | { 39 | k_sleep(t); 40 | } 41 | -------------------------------------------------------------------------------- /port/zephyr/src/oc_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_CONFIG_H 18 | #define OC_CONFIG_H 19 | 20 | /* Time resolution */ 21 | #include 22 | typedef uint64_t oc_clock_time_t; 23 | #include 24 | #define OC_CLOCK_CONF_TICKS_PER_SECOND (1000) 25 | 26 | #define OC_BYTES_POOL_SIZE (1024) 27 | #define OC_INTS_POOL_SIZE (16) 28 | #define OC_DOUBLES_POOL_SIZE (16) 29 | 30 | /* Server-side parameters */ 31 | /* Maximum number of server resources */ 32 | #define OC_MAX_APP_RESOURCES (1) 33 | 34 | /* Common paramters */ 35 | //#define OC_BLOCK_WISE_SET_MTU (80) 36 | 37 | /* Maximum size of request/response PDUs */ 38 | #define OC_MAX_APP_DATA_SIZE (600) 39 | 40 | /* Maximum number of concurrent requests */ 41 | #define OC_MAX_NUM_CONCURRENT_REQUESTS (2) 42 | 43 | /* Maximum number of nodes in a payload tree structure */ 44 | #define OC_MAX_NUM_REP_OBJECTS (70) 45 | 46 | /* Number of devices on the OCF platform */ 47 | #define OC_MAX_NUM_DEVICES (1) 48 | 49 | #define OC_MAX_NUM_ENDPOINTS (4) 50 | 51 | /* Security layer */ 52 | /* Maximum number of authorized clients */ 53 | #define OC_MAX_NUM_SUBJECTS (1) 54 | 55 | /* Maximum number of concurrent DTLS sessions */ 56 | #define OC_MAX_DTLS_PEERS (1) 57 | 58 | /* Max inactivity timeout before tearing down DTLS connection */ 59 | #define OC_DTLS_INACTIVITY_TIMEOUT (10) 60 | 61 | #endif /* OC_CONFIG_H */ 62 | -------------------------------------------------------------------------------- /port/zephyr/src/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include "port/oc_random.h" 18 | #include 19 | 20 | void 21 | oc_random_init(void) 22 | { 23 | } 24 | 25 | // FIXME: Update below to interface with desired PRNG implementation 26 | unsigned int 27 | oc_random_value(void) 28 | { 29 | return (unsigned int)sys_rand32_get(); 30 | } 31 | 32 | void 33 | oc_random_destroy(void) 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /security/oc_certs.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_CERTS_H 18 | #define OC_CERTS_H 19 | 20 | #ifdef OC_SECURITY 21 | #include "mbedtls/x509_crt.h" 22 | #include "security/oc_cred.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | int oc_certs_parse_CN_for_UUID(const mbedtls_x509_crt *cert, 29 | oc_string_t *subjectuuid); 30 | 31 | int oc_certs_serialize_chain_to_pem(const mbedtls_x509_crt *cert_chain, 32 | char *output_buffer, 33 | size_t output_buffer_len); 34 | 35 | int oc_certs_extract_public_key(const mbedtls_x509_crt *cert, 36 | uint8_t *public_key); 37 | 38 | int oc_certs_validate_root_cert(const mbedtls_x509_crt *root_cert); 39 | 40 | int oc_certs_validate_intermediate_cert(const mbedtls_x509_crt *int_cert); 41 | 42 | int oc_certs_validate_end_entity_cert(const mbedtls_x509_crt *ee_cert); 43 | 44 | int oc_certs_validate_role_cert(const mbedtls_x509_crt *role_cert); 45 | 46 | int oc_certs_is_subject_the_issuer(mbedtls_x509_crt *issuer, 47 | mbedtls_x509_crt *child); 48 | 49 | int oc_certs_generate_csr(size_t device, unsigned char *csr, size_t csr_len); 50 | 51 | int oc_certs_parse_public_key(const unsigned char *cert, size_t cert_size, 52 | uint8_t *public_key); 53 | 54 | int oc_certs_parse_role_certificate(const unsigned char *role_certificate, 55 | size_t cert_size, oc_sec_cred_t *role_cred); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | #endif /* OC_SECURITY */ 61 | #endif /* OC_CERTS_H */ 62 | -------------------------------------------------------------------------------- /security/oc_csr.c: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifdef OC_SECURITY 18 | #ifdef OC_PKI 19 | 20 | #include "oc_csr.h" 21 | #include "oc_api.h" 22 | #include "oc_certs.h" 23 | #include "oc_core_res.h" 24 | 25 | void 26 | get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data) 27 | { 28 | (void)iface_mask; 29 | (void)data; 30 | 31 | size_t device = request->resource->device; 32 | 33 | #ifdef OC_DYNAMIC_ALLOCATION 34 | unsigned char *csr = 35 | (unsigned char *)calloc(OC_PDU_SIZE, sizeof(unsigned char)); 36 | if (!csr) { 37 | oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR); 38 | return; 39 | } 40 | #else /* OC_DYNAMIC_ALLOCATION */ 41 | unsigned char csr[OC_PDU_SIZE]; 42 | #endif /* !OC_DYNAMIC_ALLOCATION */ 43 | 44 | int csr_len = oc_certs_generate_csr(device, csr, OC_PDU_SIZE); 45 | if (csr_len < 0) { 46 | oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR); 47 | #ifdef OC_DYNAMIC_ALLOCATION 48 | free(csr); 49 | #endif /* OC_DYNAMIC_ALLOCATION */ 50 | return; 51 | } 52 | 53 | oc_rep_start_root_object(); 54 | oc_process_baseline_interface( 55 | oc_core_get_resource_by_index(OCF_SEC_CRED, device)); 56 | oc_rep_set_byte_string(root, csr, csr, csr_len); 57 | oc_rep_set_text_string(root, encoding, "oic.sec.encoding.der"); 58 | oc_rep_end_root_object(); 59 | 60 | oc_send_response(request, OC_STATUS_OK); 61 | 62 | #ifdef OC_DYNAMIC_ALLOCATION 63 | free(csr); 64 | #endif /* OC_DYNAMIC_ALLOCATION */ 65 | } 66 | 67 | #else /* OC_PKI */ 68 | typedef int dummy_declaration; 69 | #endif /* !OC_PKI */ 70 | #endif /* OC_SECURITY */ 71 | -------------------------------------------------------------------------------- /security/oc_csr.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_CSR_H 18 | #define OC_CSR_H 19 | 20 | #include "oc_ri.h" 21 | #include "oc_uuid.h" 22 | #include 23 | 24 | #include "oc_cred.h" 25 | #include "oc_ri.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | void get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* OC_CSR_H */ 38 | -------------------------------------------------------------------------------- /security/oc_doxm.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_DOXM_H 18 | #define OC_DOXM_H 19 | 20 | #include "oc_uuid.h" 21 | #include "port/oc_log.h" 22 | #include "util/oc_list.h" 23 | #include "util/oc_memb.h" 24 | 25 | #include "oc_ri.h" 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" 30 | { 31 | #endif 32 | 33 | typedef enum oc_sec_doxmtype_t { 34 | OC_OXMTYPE_JW = 0, 35 | OC_OXMTYPE_RDP = 1, 36 | OC_OXMTYPE_MFG_CERT = 2 37 | } oc_sec_oxmtype_t; 38 | 39 | typedef struct 40 | { 41 | int oxmsel; 42 | int sct; 43 | bool owned; 44 | oc_uuid_t deviceuuid; 45 | oc_uuid_t devowneruuid; 46 | oc_uuid_t rowneruuid; 47 | } oc_sec_doxm_t; 48 | 49 | void oc_sec_doxm_init(void); 50 | void oc_sec_doxm_free(void); 51 | bool oc_sec_decode_doxm(oc_rep_t *rep, bool from_storage, size_t device); 52 | void oc_sec_encode_doxm(size_t device); 53 | oc_sec_doxm_t *oc_sec_get_doxm(size_t device); 54 | void oc_sec_doxm_default(size_t device); 55 | void get_doxm(oc_request_t *request, oc_interface_mask_t iface_mask, void *data); 56 | void post_doxm(oc_request_t *request, oc_interface_mask_t iface_mask, 57 | void *data); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* OC_DOXM_H */ 64 | -------------------------------------------------------------------------------- /security/oc_keypair.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_KEYPAIR_H 18 | #define OC_KEYPAIR_H 19 | 20 | #include "oc_rep.h" 21 | #include 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define OC_KEYPAIR_PUBKEY_SIZE (91) 29 | #define OC_KEYPAIR_PRIVKEY_SIZE (200) 30 | 31 | typedef struct oc_ecdsa_keypair_t 32 | { 33 | struct oc_ecdsa_keypair_t *next; 34 | size_t device; 35 | uint8_t public_key[OC_KEYPAIR_PUBKEY_SIZE]; 36 | uint8_t private_key[OC_KEYPAIR_PRIVKEY_SIZE]; 37 | uint8_t private_key_size; 38 | } oc_ecdsa_keypair_t; 39 | 40 | bool oc_sec_decode_ecdsa_keypair(oc_rep_t *rep, size_t device); 41 | bool oc_sec_encode_ecdsa_keypair(size_t device); 42 | int oc_generate_ecdsa_keypair(size_t device); 43 | oc_ecdsa_keypair_t *oc_sec_get_ecdsa_keypair(size_t device); 44 | void oc_free_ecdsa_keypairs(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* OC_KEYPAIR_H */ 51 | -------------------------------------------------------------------------------- /security/oc_pstat.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_PSTAT_H 18 | #define OC_PSTAT_H 19 | 20 | #include "oc_ri.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | typedef enum { 28 | OC_DOS_RESET = 0, 29 | OC_DOS_RFOTM, 30 | OC_DOS_RFPRO, 31 | OC_DOS_RFNOP, 32 | OC_DOS_SRESET 33 | } oc_dostype_t; 34 | 35 | typedef struct 36 | { 37 | oc_dostype_t s; 38 | bool p; 39 | bool isop; 40 | int cm; 41 | int tm; 42 | int om; 43 | int sm; 44 | oc_uuid_t rowneruuid; 45 | } oc_sec_pstat_t; 46 | 47 | void oc_sec_pstat_init(void); 48 | void oc_sec_pstat_free(void); 49 | bool oc_sec_is_operational(size_t device); 50 | bool oc_sec_decode_pstat(oc_rep_t *rep, bool from_storage, size_t device); 51 | void oc_sec_encode_pstat(size_t device); 52 | oc_sec_pstat_t *oc_sec_get_pstat(size_t device); 53 | void oc_sec_pstat_default(size_t device); 54 | void get_pstat(oc_request_t *request, oc_interface_mask_t iface_mask, 55 | void *data); 56 | void post_pstat(oc_request_t *request, oc_interface_mask_t iface_mask, 57 | void *data); 58 | void oc_sec_reset(); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* OC_PSTAT_H */ 65 | -------------------------------------------------------------------------------- /security/oc_roles.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_ROLES_H 18 | #define OC_ROLES_H 19 | 20 | #include "oc_api.h" 21 | #include "oc_cred.h" 22 | #include "security/oc_tls.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Used on the server-side for handling role assertions via /oic/sec/roles */ 29 | oc_sec_cred_t *oc_sec_allocate_role(oc_tls_peer_t *client, size_t device); 30 | void oc_sec_free_role(oc_sec_cred_t *role, oc_tls_peer_t *client); 31 | oc_sec_cred_t *oc_sec_get_roles(oc_tls_peer_t *client); 32 | void oc_sec_free_roles(oc_tls_peer_t *client); 33 | void oc_sec_free_roles_for_device(size_t device); 34 | int oc_sec_free_role_by_credid(int credid, oc_tls_peer_t *client); 35 | 36 | /* Used on the client-side for asserting roles that had been provisioned to 37 | * /oic/sec/cred. 38 | */ 39 | void oc_sec_remove_role_cred(const char *role, const char *authority); 40 | oc_role_t *oc_sec_add_role_cred(const char *role, const char *authority); 41 | oc_role_t *oc_sec_get_role_creds(void); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* OC_ROLES_H */ 48 | -------------------------------------------------------------------------------- /security/oc_sp.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_SP_H 18 | #define OC_SP_H 19 | 20 | #include "oc_ri.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef enum { 27 | OC_SP_BASELINE = 1 << 1, 28 | OC_SP_BLACK = 1 << 2, 29 | OC_SP_BLUE = 1 << 3, 30 | OC_SP_PURPLE = 1 << 4 31 | } oc_sp_types_t; 32 | 33 | typedef struct 34 | { 35 | oc_sp_types_t supported_profiles; 36 | oc_sp_types_t current_profile; 37 | int credid; 38 | } oc_sec_sp_t; 39 | 40 | void oc_sec_sp_init(void); 41 | void oc_sec_sp_free(void); 42 | bool oc_sec_decode_sp(oc_rep_t *rep, size_t device); 43 | void oc_sec_encode_sp(size_t device); 44 | oc_sec_sp_t *oc_sec_get_sp(size_t device); 45 | void oc_sec_sp_default(size_t device); 46 | void get_sp(oc_request_t *request, oc_interface_mask_t iface_mask, void *data); 47 | void post_sp(oc_request_t *request, oc_interface_mask_t iface_mask, void *data); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* OC_SP_H */ 54 | -------------------------------------------------------------------------------- /security/oc_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_STORE_H 18 | #define OC_STORE_H 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | void oc_sec_load_pstat(size_t device); 27 | void oc_sec_load_doxm(size_t device); 28 | void oc_sec_load_cred(size_t device); 29 | void oc_sec_load_acl(size_t device); 30 | void oc_sec_dump_pstat(size_t device); 31 | void oc_sec_dump_cred(size_t device); 32 | void oc_sec_dump_doxm(size_t device); 33 | void oc_sec_dump_acl(size_t device); 34 | void oc_sec_dump_unique_ids(size_t device); 35 | void oc_sec_load_unique_ids(size_t device); 36 | void oc_sec_load_sp(size_t device); 37 | void oc_sec_dump_sp(size_t device); 38 | void oc_sec_load_ecdsa_keypair(size_t device); 39 | void oc_sec_dump_ecdsa_keypair(size_t device); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* OC_STORE_H */ 46 | -------------------------------------------------------------------------------- /security/oc_svr.h: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #ifndef OC_SVR_H 18 | #define OC_SVR_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | void oc_sec_create_svr(void); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* OC_SVR_H */ 32 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | #! /usr/bin/make -f 2 | 3 | topdir?=${CURDIR}/.. 4 | port?=linux 5 | 6 | default: ${port}/all 7 | sync 8 | 9 | DYNAMIC?=0 10 | export DYNAMIC 11 | 12 | SECURE?=0 13 | export SECURE 14 | 15 | TCP?=0 16 | export TCP 17 | 18 | prep_files+=${topdir}/deps/tinycbor/LICENSE 19 | prep_files+=${topdir}/deps/mbedtls/LICENSE 20 | prep_files+=${topdir}/deps/gtest/LICENSE 21 | 22 | linux/%: ${CURDIR}/../port/${port} ${prep_files} 23 | ${MAKE} -C $< ${@F} 24 | 25 | ${port}/%: ${CURDIR}/port/${port} ${prep_files} 26 | ${MAKE} -C $< ${@F} 27 | 28 | help: ${topdir}/README.rst 29 | cat $< 30 | @echo "# Usage: " 31 | @echo "# make all : to build port=${port}" 32 | 33 | ${prep_files}: .git-submodule.done.tmp 34 | 35 | .git-submodule.done.tmp: ${topdir}/.gitmodules 36 | git submodule init 37 | git submodule sync 38 | git submodule update 39 | touch $@ 40 | 41 | prep: ${prep_files} 42 | ls $< 43 | 44 | test: ${port}/test 45 | 46 | .PHONY: default help 47 | -------------------------------------------------------------------------------- /tests/auto_build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | python auto_build.py "$@" 3 | -------------------------------------------------------------------------------- /tests/client_init_linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "test.h" 18 | 19 | #include "oc_api.h" 20 | #include "port/oc_clock.h" 21 | 22 | #include 23 | 24 | static int 25 | app_init(void) 26 | { 27 | int ret; 28 | 29 | ret = oc_init_platform("Intel", NULL, NULL); 30 | ASSERT(ret == 0); 31 | 32 | ret = oc_add_device("/oic/d", "oic.d.test-client-init", "Client init test", "1.0", "1.0", 33 | NULL, NULL); 34 | return ret; 35 | } 36 | 37 | static void 38 | issue_requests(void) 39 | { 40 | } 41 | 42 | static void 43 | signal_event_loop(void) 44 | { 45 | } 46 | 47 | int 48 | main(void) 49 | { 50 | int init; 51 | 52 | oc_handler_t handler = { 53 | .init = app_init, 54 | .signal_event_loop = signal_event_loop, 55 | .requests_entry = issue_requests 56 | }; 57 | 58 | init = oc_main_init(&handler); 59 | ASSERT(init == 0); 60 | oc_main_shutdown(); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /tests/itc/ri/Makefile: -------------------------------------------------------------------------------- 1 | SED = sed 2 | INSTALL = install 3 | OS = linux 4 | IOTIVITY_ROOT_DIR = ../../.. 5 | OUT_DIR = $(IOTIVITY_ROOT_DIR)/port/$(OS) 6 | MODULE = ri 7 | #CHECK_SCRIPT = ../../tools/check.py 8 | 9 | 10 | GTEST_DIR = $(IOTIVITY_ROOT_DIR)/deps/gtest 11 | GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ 12 | $(GTEST_DIR)/include/gtest/internal/*.h 13 | GTEST = gtest_build 14 | TEST_CPPFLAGS += -isystem $(GTEST_DIR)/include 15 | TEST_CXXFLAGS += -g -Wall -Wextra -pthread -std=c++0x -fpermissive -DOC_CLIENT -DOC_SERVER -fprofile-arcs -ftest-coverage 16 | IOTIVITY_HEADER_DIR = $(IOTIVITY_ROOT_DIR)/include 17 | 18 | API_TEST_DIR = $(IOTIVITY_ROOT_DIR)/tests/itc/$(MODULE) 19 | API_TEST_OBJ_DIR = $(API_TEST_DIR)/src/obj 20 | API_TEST_HELPER_OBJ_DIR = $(API_TEST_DIR)/helper/obj 21 | 22 | API_TEST_HELPER_FILES := $(wildcard $(API_TEST_DIR)/helper/*.cpp) 23 | API_TEST_HEADER_DIR = $(API_TEST_DIR)/include/ 24 | API_TEST_SRC_FILES := $(wildcard $(API_TEST_DIR)/src/*.cpp) 25 | 26 | API_TEST_OBJ_FILES := $(patsubst $(API_TEST_DIR)/src/%.cpp,$(API_TEST_OBJ_DIR)/%.o,$(API_TEST_SRC_FILES)) 27 | API_TEST_HELPER_OBJ_FILES := $(patsubst $(API_TEST_DIR)/helper/%.cpp,$(API_TEST_HELPER_OBJ_DIR)/%.o,$(API_TEST_HELPER_FILES)) 28 | INT_TESTS = integration_test 29 | 30 | 31 | CONSTRAINED_LIBS = libiotivity-constrained-server.a libiotivity-constrained-client.a \ 32 | libiotivity-constrained-server.so libiotivity-constrained-client.so \ 33 | libiotivity-constrained-client-server.so libiotivity-constrained-client-server.a 34 | PC = iotivity-constrained-client.pc iotivity-constrained-server.pc \ 35 | iotivity-constrained-client-server.pc 36 | 37 | test: $(INT_TESTS) 38 | all: test 39 | 40 | .PHONY: $(GTEST) clean 41 | 42 | $(GTEST): $(GTEST_DIR) 43 | $(MAKE) --directory=$ 23 | 24 | static int 25 | app_init(void) 26 | { 27 | int ret; 28 | 29 | ret = oc_init_platform("Intel", NULL, NULL); 30 | ASSERT(ret == 0); 31 | 32 | ret = oc_add_device("/oic/d", "oic.d.test-server-init", "Server init test", "1.0", "1.0", 33 | NULL, NULL); 34 | return ret; 35 | } 36 | 37 | static void 38 | signal_event_loop(void) 39 | { 40 | } 41 | 42 | static void 43 | register_resources(void) 44 | { 45 | } 46 | 47 | int 48 | main(void) 49 | { 50 | int init; 51 | const oc_handler_t handler = { 52 | .init = app_init, 53 | .signal_event_loop = signal_event_loop, 54 | .register_resources = register_resources, 55 | }; 56 | 57 | init = oc_main_init(&handler); 58 | ASSERT(init == 0); 59 | oc_main_shutdown(); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /tests/test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef TEST_H 18 | #define TEST_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define ASSERT(expr) \ 25 | do { \ 26 | if ((!(expr))) { \ 27 | fprintf(stderr, "%s:%d: %s: Assertion: `" # expr "' failed.\n", \ 28 | __FILE__, __LINE__, __func__); \ 29 | exit(1); \ 30 | } \ 31 | } while (0) 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /tools/README: -------------------------------------------------------------------------------- 1 | Both tools, pre-commit and check-style, use clang-format to fix the code style. 2 | 3 | In order to use the tools one should copy the file "_clang-format" to the 4 | project's root dir. This file contains the description of the iotivity-constrained code 5 | style and will be used by clang-format. 6 | 7 | The check-style tool can fix the code style of the project's file or only print 8 | the changes. If no parameter is given the files are automatically fixed, to only 9 | print the changes the option "-p" should be given. 10 | 11 | The pre-commit tool is a git hook that fix the code style of the commmit 12 | automatically. To use this tool one have to copy this file to 13 | /.git/hooks/ 14 | 15 | Invoke doxygen doygen.ini to create the Doxygen API documentation. 16 | Afterwards you find the start page by loading html/index.html. 17 | -------------------------------------------------------------------------------- /tools/_clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Mozilla 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlinesLeft: false 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: false 12 | AllowShortBlocksOnASingleLine: false 13 | AllowShortCaseLabelsOnASingleLine: false 14 | AllowShortFunctionsOnASingleLine: Inline 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterDefinitionReturnType: TopLevel 18 | AlwaysBreakAfterReturnType: TopLevelDefinitions 19 | AlwaysBreakBeforeMultilineStrings: false 20 | AlwaysBreakTemplateDeclarations: true 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | BreakBeforeBinaryOperators: None 24 | BreakBeforeTernaryOperators: true 25 | BreakConstructorInitializersBeforeComma: true 26 | ColumnLimit: 80 27 | ContinuationIndentWidth: 2 28 | DerivePointerAlignment: false 29 | DisableFormat: false 30 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 31 | IndentCaseLabels: false 32 | IndentWidth: 2 33 | IndentWrappedFunctionNames: false 34 | KeepEmptyLinesAtTheStartOfBlocks: true 35 | MaxEmptyLinesToKeep: 1 36 | NamespaceIndentation: None 37 | PenaltyBreakBeforeFirstCallParameter: 19 38 | PenaltyBreakComment: 300 39 | PenaltyBreakFirstLessLess: 120 40 | PenaltyBreakString: 1000 41 | PenaltyExcessCharacter: 1000000 42 | PenaltyReturnTypeOnItsOwnLine: 200 43 | PointerAlignment: Right 44 | ReflowComments: true 45 | SortIncludes: true 46 | SpaceAfterCStyleCast: false 47 | SpaceBeforeAssignmentOperators: true 48 | SpaceBeforeParens: ControlStatements 49 | SpaceInEmptyParentheses: false 50 | SpacesBeforeTrailingComments: 1 51 | SpacesInAngles: false 52 | SpacesInContainerLiterals: true 53 | SpacesInCStyleCastParentheses: false 54 | SpacesInParentheses: false 55 | SpacesInSquareBrackets: false 56 | Standard: Cpp11 57 | TabWidth: 2 58 | UseTab: Never 59 | ... 60 | 61 | -------------------------------------------------------------------------------- /tools/check-style: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | 3 | # Copyright(c) 2016 Intel Corporation 4 | # 5 | # Licensed under the Apache License, Version 2.0(the "License") 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import argparse 18 | import difflib 19 | import os 20 | import re 21 | import string 22 | import subprocess 23 | import sys 24 | 25 | 26 | def get_root_dir(): 27 | cmd = ['git', 'rev-parse', '--show-toplevel'] 28 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 29 | stderr=None, stdin=subprocess.PIPE) 30 | stdout, stderr = process.communicate() 31 | if process.returncode != 0: 32 | return None 33 | return stdout.splitlines()[0] 34 | 35 | def get_files(): 36 | files = None 37 | cmd = ['git', 'ls-files'] 38 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 39 | stderr=None, stdin=subprocess.PIPE) 40 | stdout, stderr = process.communicate() 41 | if process.returncode != 0: 42 | return None 43 | return list(filter(lambda x: x.endswith(b".c") or x.endswith(b".h"), stdout.splitlines())) 44 | 45 | def print_diff(filename, clang_output): 46 | with open(filename) as f: 47 | print "\n".join(difflib.unified_diff(map(lambda x: x[:-1], f.readlines()), 48 | clang_output.splitlines(), fromfile=filename, tofile=filename)) 49 | 50 | def check_style(files, only_print): 51 | cmd = ['clang-format', '-style=file'] 52 | 53 | if not only_print: 54 | cmd.append("-i") 55 | 56 | for f in files: 57 | cmd.append(f) 58 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 59 | stderr=None, stdin=subprocess.PIPE) 60 | stdout, stderr = process.communicate() 61 | if process.returncode != 0: 62 | sys.exit(process.returncode) 63 | 64 | if only_print: 65 | print_diff(f, stdout) 66 | cmd.pop() 67 | 68 | if __name__ == '__main__': 69 | parser = argparse.ArgumentParser(description= 70 | 'Format the files in the repository according ' 71 | 'with iotivity constrained code style.') 72 | parser.add_argument('-p', action='store_true', default=False, 73 | help='Only print the changes') 74 | 75 | args = parser.parse_args() 76 | current_dir = os.getcwd() 77 | root_dir = get_root_dir() 78 | 79 | os.chdir(root_dir) 80 | check_style(get_files(), args.p) 81 | os.chdir(current_dir) 82 | -------------------------------------------------------------------------------- /tools/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright(c) 2016 Intel Corporation 4 | # 5 | # Licensed under the Apache License, Version 2.0(the "License") 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import re 18 | import string 19 | import subprocess 20 | import sys 21 | 22 | 23 | def format(diff): 24 | filename = None 25 | changes = {} 26 | 27 | for line in diff.splitlines(): 28 | m = re.search(b'^\+\+\+\ (.*?/)(\S*)', line) 29 | if m: 30 | filename = m.group(2) 31 | if not filename: 32 | continue 33 | 34 | if not re.match(b'^.*\.(c|h)$', filename): 35 | continue 36 | 37 | if not filename in changes: 38 | changes[filename] = [] 39 | 40 | m = re.search(b'^@@.*\+(\d+),(\d+)?', line) 41 | if m: 42 | start = int(m.group(1)) 43 | end = start + int(m.group(2)) 44 | changes[filename].extend(['-lines', str(start) + ':' + str(end)]) 45 | 46 | for filename, lines in changes.items(): 47 | cmd = ['clang-format', filename, '-i', '-style', 'file'] 48 | cmd.extend(lines) 49 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 50 | stderr=None, stdin=subprocess.PIPE) 51 | stdout, stderr = process.communicate() 52 | if process.returncode != 0: 53 | return process.returncode 54 | process = subprocess.Popen(['git', 'add', filename], stdout=subprocess.PIPE, 55 | stderr=None, stdin=subprocess.PIPE) 56 | stdout, stderr = process.communicate() 57 | if process.returncode != 0: 58 | return process.returncode 59 | 60 | return 0 61 | 62 | if __name__ == '__main__': 63 | cmd = ['git', 'diff', '-U1', '--cached', 'HEAD'] 64 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 65 | stderr=None, stdin=subprocess.PIPE) 66 | out, err = process.communicate() 67 | if process.returncode != 0: 68 | sys.exit(process.returncode) 69 | sys.exit(format(out)) 70 | -------------------------------------------------------------------------------- /util/oc_mem_trace.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright 2018 Samsung Electronics All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific 15 | * language governing permissions and limitations under the License. 16 | * 17 | ****************************************************************************/ 18 | 19 | #ifndef OC_MEM_TRACE_H 20 | #define OC_MEM_TRACE_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | #define MEM_TRACE_ALLOC (1) // it would be combination when BYTE, INT, DOUBLE 28 | #define MEM_TRACE_FREE (0) 29 | 30 | void oc_mem_trace_init(void); 31 | void oc_mem_trace_add_pace(const char *func, int size, int type, void *address); 32 | void oc_mem_trace_shutdown(void); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* OC_MEM_TRACE_H */ 39 | -------------------------------------------------------------------------------- /util/oc_mmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Intel Corporation 3 | * 4 | * Copyright (c) 2005, Swedish Institute of Computer Science 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the Institute nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * This file is part of the Contiki operating system. 32 | * 33 | */ 34 | 35 | #ifndef OC_MMEM_H 36 | #define OC_MMEM_H 37 | 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" 42 | { 43 | #endif 44 | 45 | #define OC_MMEM_PTR(m) (struct oc_mmem *)(m)->ptr 46 | 47 | struct oc_mmem 48 | { 49 | struct oc_mmem *next; 50 | size_t size; 51 | void *ptr; 52 | }; 53 | 54 | typedef enum { BYTE_POOL, INT_POOL, DOUBLE_POOL } pool; 55 | 56 | void oc_mmem_init(void); 57 | 58 | #ifdef OC_MEMORY_TRACE 59 | 60 | #define oc_mmem_alloc(m, size, pool_type) \ 61 | _oc_mmem_alloc(__func__, m, size, pool_type) 62 | #define oc_mmem_free(m, pool_type) _oc_mmem_free(__func__, m, pool_type) 63 | 64 | #else /* OC_MEMORY_TRACE */ 65 | 66 | #define oc_mmem_alloc(m, size, pool_type) \ 67 | _oc_mmem_alloc(m, size, pool_type) 68 | #define oc_mmem_free(m, pool_type) _oc_mmem_free(m, pool_type) 69 | 70 | #endif /* !OC_MEMORY_TRACE */ 71 | 72 | size_t _oc_mmem_alloc( 73 | #ifdef OC_MEMORY_TRACE 74 | const char *func, 75 | #endif 76 | struct oc_mmem *m, size_t size, pool pool_type); 77 | 78 | void _oc_mmem_free( 79 | #ifdef OC_MEMORY_TRACE 80 | const char *func, 81 | #endif 82 | struct oc_mmem *m, pool pool_type); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* OC_MMEM_H */ 89 | --------------------------------------------------------------------------------