diff --git a/device-simulator/Dockerfile b/device-simulator/Dockerfile index 96f4018dd..ff1d371e4 100644 --- a/device-simulator/Dockerfile +++ b/device-simulator/Dockerfile @@ -1,9 +1,8 @@ FROM alpine:3.12 AS build RUN apk add --no-cache curl git build-base gcc linux-headers patch -RUN git clone --recursive https://github.com/iotivity/iotivity-lite.git -COPY ./patches/devsim.diff /devsim.diff -RUN (cd /iotivity-lite && patch -p1 < /devsim.diff) +RUN git clone --recursive -b plgd.dev https://github.com/iotivity/iotivity-lite.git +COPY ./src/ /iotivity-lite/ RUN make -C /iotivity-lite/port/linux CLOUD=1 SECURE=1 DEBUG=1 MNT=1 cloud_server FROM alpine:3.12 AS service diff --git a/device-simulator/patches/devsim.diff b/device-simulator/patches/devsim.diff deleted file mode 100644 index 3168c9ac0..000000000 --- a/device-simulator/patches/devsim.diff +++ /dev/null @@ -1,119 +0,0 @@ -diff --git a/messaging/coap/engine.c b/messaging/coap/engine.c -index 627ad9d2..1a33839a 100644 ---- a/messaging/coap/engine.c -+++ b/messaging/coap/engine.c -@@ -258,7 +258,7 @@ coap_receive(oc_message_t *msg) - coap_udp_init_message(response, COAP_TYPE_ACK, CONTENT_2_05, - message->mid); - } else { -- if (check_if_duplicate(message->mid, (uint8_t)msg->endpoint.device)) { -+ if (message->type == COAP_TYPE_NON && check_if_duplicate(message->mid, (uint8_t)msg->endpoint.device)) { - return 0; - } - history[idx] = message->mid; -diff --git a/apps/cloud_server.c b/apps/cloud_server.c -index 6edd644..ceaff87 100644 ---- a/apps/cloud_server.c -+++ b/apps/cloud_server.c -@@ -19,6 +19,7 @@ - - #include "oc_api.h" - #include "oc_pki.h" -+#include "oc_core_res.h" - #include - #include - -@@ -194,6 +195,7 @@ cloud_status_handler(oc_cloud_context_t *ctx, oc_cloud_status_t status, - static int - app_init(void) - { -+ oc_set_con_res_announced(true); - int ret = oc_init_platform(manufacturer, NULL, NULL); - ret |= oc_add_device("/oic/d", device_rt, device_name, spec_version, - data_model_version, NULL, NULL); -@@ -294,6 +296,10 @@ register_resources(void) - oc_resource_set_request_handler(res2, OC_POST, post_handler, &light2); - oc_cloud_add_resource(res2); - oc_add_resource(res2); -+ -+ // publish con resource -+ oc_resource_t *con_res = oc_core_get_resource_by_index(OCF_CON, 0); -+ oc_cloud_add_resource(con_res); - } - - #if defined(OC_SECURITY) && defined(OC_PKI) -@@ -360,6 +366,65 @@ factory_presets_cb(size_t device, void *data) - #endif /* OC_SECURITY && OC_PKI */ - } - -+void -+factory_presets_cb_new(size_t device, void *data) -+{ -+ oc_device_info_t* dev = oc_core_get_device_info(device); -+ oc_free_string(&dev->name); -+ oc_new_string(&dev->name, device_name, strlen(device_name)); -+ (void)data; -+#if defined(OC_SECURITY) && defined(OC_PKI) -+ PRINT("factory_presets_cb: %d\n", (int) device); -+ -+ const char* cert = "-----BEGIN CERTIFICATE-----\n" -+"MIIB9zCCAZygAwIBAgIRAOwIWPAt19w7DswoszkVIEIwCgYIKoZIzj0EAwIwEzER\n" -+"MA8GA1UEChMIVGVzdCBPUkcwHhcNMTkwNTAyMjAwNjQ4WhcNMjkwMzEwMjAwNjQ4\n" -+"WjBHMREwDwYDVQQKEwhUZXN0IE9SRzEyMDAGA1UEAxMpdXVpZDpiNWEyYTQyZS1i\n" -+"Mjg1LTQyZjEtYTM2Yi0wMzRjOGZjOGVmZDUwWTATBgcqhkjOPQIBBggqhkjOPQMB\n" -+"BwNCAAQS4eiM0HNPROaiAknAOW08mpCKDQmpMUkywdcNKoJv1qnEedBhWne7Z0jq\n" -+"zSYQbyqyIVGujnI3K7C63NRbQOXQo4GcMIGZMA4GA1UdDwEB/wQEAwIDiDAzBgNV\n" -+"HSUELDAqBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMBBgorBgEEAYLefAEG\n" -+"MAwGA1UdEwEB/wQCMAAwRAYDVR0RBD0wO4IJbG9jYWxob3N0hwQAAAAAhwR/AAAB\n" -+"hxAAAAAAAAAAAAAAAAAAAAAAhxAAAAAAAAAAAAAAAAAAAAABMAoGCCqGSM49BAMC\n" -+"A0kAMEYCIQDuhl6zj6gl2YZbBzh7Th0uu5izdISuU/ESG+vHrEp7xwIhANCA7tSt\n" -+"aBlce+W76mTIhwMFXQfyF3awWIGjOcfTV8pU\n" -+"-----END CERTIFICATE-----\n"; -+ -+ const char* key = "-----BEGIN EC PRIVATE KEY-----\n" -+"MHcCAQEEIMPeADszZajrkEy4YvACwcbR0pSdlKG+m8ALJ6lj/ykdoAoGCCqGSM49\n" -+"AwEHoUQDQgAEEuHojNBzT0TmogJJwDltPJqQig0JqTFJMsHXDSqCb9apxHnQYVp3\n" -+"u2dI6s0mEG8qsiFRro5yNyuwutzUW0Dl0A==\n" -+"-----END EC PRIVATE KEY-----\n"; -+ -+ const char* root_ca = "-----BEGIN CERTIFICATE-----\n" -+"MIIBaTCCAQ+gAwIBAgIQR33gIB75I7Vi/QnMnmiWvzAKBggqhkjOPQQDAjATMREw\n" -+"DwYDVQQKEwhUZXN0IE9SRzAeFw0xOTA1MDIyMDA1MTVaFw0yOTAzMTAyMDA1MTVa\n" -+"MBMxETAPBgNVBAoTCFRlc3QgT1JHMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\n" -+"xbwMaS8jcuibSYJkCmuVHfeV3xfYVyUq8Iroz7YlXaTayspW3K4hVdwIsy/5U+3U\n" -+"vM/vdK5wn2+NrWy45vFAJqNFMEMwDgYDVR0PAQH/BAQDAgEGMBMGA1UdJQQMMAoG\n" -+"CCsGAQUFBwMBMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0RBAQwAoIAMAoGCCqGSM49\n" -+"BAMCA0gAMEUCIBWkxuHKgLSp6OXDJoztPP7/P5VBZiwLbfjTCVRxBvwWAiEAnzNu\n" -+"6gKPwtKmY0pBxwCo3NNmzNpA6KrEOXE56PkiQYQ=\n" -+"-----END CERTIFICATE-----\n"; -+ -+ int ee_credid = oc_pki_add_mfg_cert(0, (const unsigned char *)cert, strlen(cert), -+ (const unsigned char *)key, strlen(key)); -+ if (ee_credid < 0) { -+ PRINT("ERROR installing manufacturer EE cert\n"); -+ return; -+ } -+ -+ int rootca_credid = -+ oc_pki_add_mfg_trust_anchor(0, (const unsigned char *)root_ca, strlen(root_ca)); -+ if (rootca_credid < 0) { -+ PRINT("ERROR installing root cert\n"); -+ return; -+ } -+ -+ oc_pki_set_security_profile(0, OC_SP_BLACK, OC_SP_BLACK, ee_credid); -+#endif /* OC_SECURITY && OC_PKI */ -+} -+ - int - main(int argc, char *argv[]) - { -@@ -406,7 +471,7 @@ main(int argc, char *argv[]) - #ifdef OC_STORAGE - oc_storage_config("./cloud_server_creds/"); - #endif /* OC_STORAGE */ -- oc_set_factory_presets_cb(factory_presets_cb, NULL); -+ oc_set_factory_presets_cb(factory_presets_cb_new, NULL); - - ret = oc_main_init(&handler); - if (ret < 0) diff --git a/device-simulator/src/apps/cloud_server.c b/device-simulator/src/apps/cloud_server.c new file mode 100644 index 000000000..dd5466441 --- /dev/null +++ b/device-simulator/src/apps/cloud_server.c @@ -0,0 +1,493 @@ +/**************************************************************************** + * + * Copyright 2019 Jozef Kralik All Rights Reserved. + * Copyright 2018 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ + +#include "oc_api.h" +#include "oc_pki.h" +#include "oc_core_res.h" +#include +#include + +static int quit; + +#if defined(_WIN32) +#include + +static CONDITION_VARIABLE cv; +static CRITICAL_SECTION cs; + +static void +signal_event_loop(void) +{ + WakeConditionVariable(&cv); +} + +void +handle_signal(int signal) +{ + signal_event_loop(); + quit = 1; +} + +static int +init(void) +{ + InitializeCriticalSection(&cs); + InitializeConditionVariable(&cv); + + signal(SIGINT, handle_signal); + return 0; +} + +static void +run(void) +{ + while (quit != 1) { + oc_clock_time_t next_event = oc_main_poll(); + if (next_event == 0) { + SleepConditionVariableCS(&cv, &cs, INFINITE); + } else { + oc_clock_time_t now = oc_clock_time(); + if (now < next_event) { + SleepConditionVariableCS( + &cv, &cs, (DWORD)((next_event - now) * 1000 / OC_CLOCK_SECOND)); + } + } + } +} + +#elif defined(__linux__) || defined(__ANDROID_API__) +#include + +static pthread_mutex_t mutex; +static pthread_cond_t cv; + +static void +signal_event_loop(void) +{ + pthread_mutex_lock(&mutex); + pthread_cond_signal(&cv); + pthread_mutex_unlock(&mutex); +} + +void +handle_signal(int signal) +{ + if (signal == SIGPIPE) { + return; + } + signal_event_loop(); + quit = 1; +} + +static int +init(void) +{ + struct sigaction sa; + sigfillset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = handle_signal; + sigaction(SIGINT, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + + if (pthread_mutex_init(&mutex, NULL) < 0) { + OC_ERR("pthread_mutex_init failed!"); + return -1; + } + return 0; +} + +static void +run(void) +{ + while (quit != 1) { + oc_clock_time_t next_event = oc_main_poll(); + pthread_mutex_lock(&mutex); + if (next_event == 0) { + pthread_cond_wait(&cv, &mutex); + } else { + struct timespec ts; + ts.tv_sec = (next_event / OC_CLOCK_SECOND); + ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND; + pthread_cond_timedwait(&cv, &mutex, &ts); + } + pthread_mutex_unlock(&mutex); + } +} + +#else +#error "Unsupported OS" +#endif + +// define application specific values. +static const char *spec_version = "ocf.2.0.5"; +static const char *data_model_version = "ocf.res.1.3.0"; + +static const char *resource_rt = "core.light"; +static const char *device_rt = "oic.d.cloudDevice"; +static const char *device_name = "CloudServer"; + +static const char *manufacturer = "ocfcloud.com"; + +#ifdef OC_SECURITY +static const char *cis; +static const char *auth_code; +static const char *sid; +static const char *apn; +#else /* OC_SECURITY */ +static const char *cis = "coap+tcp://127.0.0.1:5683"; +static const char *auth_code = "test"; +static const char *sid = "00000000-0000-0000-0000-000000000001"; +static const char *apn = "test"; +#endif /* OC_SECURITY */ +oc_resource_t *res1; +oc_resource_t *res2; + +static void +cloud_status_handler(oc_cloud_context_t *ctx, oc_cloud_status_t status, + void *data) +{ + (void)data; + PRINT("\nCloud Manager Status:\n"); + if (status & OC_CLOUD_REGISTERED) { + PRINT("\t\t-Registered\n"); + } + if (status & OC_CLOUD_TOKEN_EXPIRY) { + PRINT("\t\t-Token Expiry: "); + if (ctx) { + PRINT("%d\n", oc_cloud_get_token_expiry(ctx)); + } else { + PRINT("\n"); + } + } + if (status & OC_CLOUD_FAILURE) { + PRINT("\t\t-Failure\n"); + } + if (status & OC_CLOUD_LOGGED_IN) { + PRINT("\t\t-Logged In\n"); + } + if (status & OC_CLOUD_LOGGED_OUT) { + PRINT("\t\t-Logged Out\n"); + } + if (status & OC_CLOUD_DEREGISTERED) { + PRINT("\t\t-DeRegistered\n"); + } + if (status & OC_CLOUD_REFRESHED_TOKEN) { + PRINT("\t\t-Refreshed Token\n"); + } +} + +static int +app_init(void) +{ + oc_set_con_res_announced(true); + int ret = oc_init_platform(manufacturer, NULL, NULL); + ret |= oc_add_device("/oic/d", device_rt, device_name, spec_version, + data_model_version, NULL, NULL); + return ret; +} + +struct light_t +{ + bool state; + int64_t power; +}; + +struct light_t light1 = { 0 }; +struct light_t light2 = { 0 }; + +static void +get_handler(oc_request_t *request, oc_interface_mask_t iface, void *user_data) +{ + struct light_t *light = (struct light_t *)user_data; + + PRINT("get_handler:\n"); + + oc_rep_start_root_object(); + switch (iface) { + case OC_IF_BASELINE: + oc_process_baseline_interface(request->resource); + /* fall through */ + case OC_IF_RW: + oc_rep_set_boolean(root, state, light->state); + oc_rep_set_int(root, power, light->power); + oc_rep_set_text_string(root, name, "Light"); + break; + default: + break; + } + oc_rep_end_root_object(); + oc_send_response(request, OC_STATUS_OK); +} + +static void +post_handler(oc_request_t *request, oc_interface_mask_t iface_mask, + void *user_data) +{ + struct light_t *light = (struct light_t *)user_data; + (void)iface_mask; + printf("post_handler:\n"); + oc_rep_t *rep = request->request_payload; + while (rep != NULL) { + char *key = oc_string(rep->name); + printf("key: %s ", key); + if (key && !strcmp(key, "state")) { + switch (rep->type) { + case OC_REP_BOOL: + light->state = rep->value.boolean; + PRINT("value: %d\n", light->state); + break; + default: + oc_send_response(request, OC_STATUS_BAD_REQUEST); + return; + } + } else if (key && !strcmp(key, "power")) { + switch (rep->type) { + case OC_REP_INT: + light->power = rep->value.integer; + PRINT("value: %" PRId64 "\n", light->power); + break; + default: + oc_send_response(request, OC_STATUS_BAD_REQUEST); + return; + } + } + rep = rep->next; + } + oc_send_response(request, OC_STATUS_CHANGED); +} + +static void +register_resources(void) +{ + res1 = oc_new_resource(NULL, "/light/1", 1, 0); + oc_resource_bind_resource_type(res1, resource_rt); + oc_resource_bind_resource_interface(res1, OC_IF_RW); + oc_resource_set_default_interface(res1, OC_IF_RW); + oc_resource_set_discoverable(res1, true); + oc_resource_set_observable(res1, true); + oc_resource_set_request_handler(res1, OC_GET, get_handler, &light1); + oc_resource_set_request_handler(res1, OC_POST, post_handler, &light1); + oc_cloud_add_resource(res1); + oc_add_resource(res1); + + res2 = oc_new_resource(NULL, "/light/2", 1, 0); + oc_resource_bind_resource_type(res2, resource_rt); + oc_resource_bind_resource_interface(res2, OC_IF_RW); + oc_resource_set_default_interface(res2, OC_IF_RW); + oc_resource_set_discoverable(res2, true); + oc_resource_set_observable(res2, true); + oc_resource_set_request_handler(res2, OC_GET, get_handler, &light2); + oc_resource_set_request_handler(res2, OC_POST, post_handler, &light2); + oc_cloud_add_resource(res2); + oc_add_resource(res2); + + // publish con resource + oc_resource_t *con_res = oc_core_get_resource_by_index(OCF_CON, 0); + oc_cloud_add_resource(con_res); +} + +#if defined(OC_SECURITY) && defined(OC_PKI) +static int +read_pem(const char *file_path, char *buffer, size_t *buffer_len) +{ + FILE *fp = fopen(file_path, "r"); + if (fp == NULL) { + PRINT("ERROR: unable to read PEM\n"); + return -1; + } + if (fseek(fp, 0, SEEK_END) != 0) { + PRINT("ERROR: unable to read PEM\n"); + fclose(fp); + return -1; + } + long pem_len = ftell(fp); + if (pem_len < 0) { + PRINT("ERROR: could not obtain length of file\n"); + fclose(fp); + return -1; + } + if (pem_len > (long)*buffer_len) { + PRINT("ERROR: buffer provided too small\n"); + fclose(fp); + return -1; + } + if (fseek(fp, 0, SEEK_SET) != 0) { + PRINT("ERROR: unable to read PEM\n"); + fclose(fp); + return -1; + } + if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + PRINT("ERROR: unable to read PEM\n"); + fclose(fp); + return -1; + } + fclose(fp); + buffer[pem_len] = '\0'; + *buffer_len = (size_t)pem_len; + return 0; +} + +void +factory_presets_cb_new(size_t device, void *data) +{ + oc_device_info_t* dev = oc_core_get_device_info(device); + oc_free_string(&dev->name); + oc_new_string(&dev->name, device_name, strlen(device_name)); + (void)data; +#if defined(OC_SECURITY) && defined(OC_PKI) + PRINT("factory_presets_cb: %d\n", (int) device); + + const char* cert = "-----BEGIN CERTIFICATE-----\n" +"MIIB9zCCAZygAwIBAgIRAOwIWPAt19w7DswoszkVIEIwCgYIKoZIzj0EAwIwEzER\n" +"MA8GA1UEChMIVGVzdCBPUkcwHhcNMTkwNTAyMjAwNjQ4WhcNMjkwMzEwMjAwNjQ4\n" +"WjBHMREwDwYDVQQKEwhUZXN0IE9SRzEyMDAGA1UEAxMpdXVpZDpiNWEyYTQyZS1i\n" +"Mjg1LTQyZjEtYTM2Yi0wMzRjOGZjOGVmZDUwWTATBgcqhkjOPQIBBggqhkjOPQMB\n" +"BwNCAAQS4eiM0HNPROaiAknAOW08mpCKDQmpMUkywdcNKoJv1qnEedBhWne7Z0jq\n" +"zSYQbyqyIVGujnI3K7C63NRbQOXQo4GcMIGZMA4GA1UdDwEB/wQEAwIDiDAzBgNV\n" +"HSUELDAqBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMBBgorBgEEAYLefAEG\n" +"MAwGA1UdEwEB/wQCMAAwRAYDVR0RBD0wO4IJbG9jYWxob3N0hwQAAAAAhwR/AAAB\n" +"hxAAAAAAAAAAAAAAAAAAAAAAhxAAAAAAAAAAAAAAAAAAAAABMAoGCCqGSM49BAMC\n" +"A0kAMEYCIQDuhl6zj6gl2YZbBzh7Th0uu5izdISuU/ESG+vHrEp7xwIhANCA7tSt\n" +"aBlce+W76mTIhwMFXQfyF3awWIGjOcfTV8pU\n" +"-----END CERTIFICATE-----\n"; + + const char* key = "-----BEGIN EC PRIVATE KEY-----\n" +"MHcCAQEEIMPeADszZajrkEy4YvACwcbR0pSdlKG+m8ALJ6lj/ykdoAoGCCqGSM49\n" +"AwEHoUQDQgAEEuHojNBzT0TmogJJwDltPJqQig0JqTFJMsHXDSqCb9apxHnQYVp3\n" +"u2dI6s0mEG8qsiFRro5yNyuwutzUW0Dl0A==\n" +"-----END EC PRIVATE KEY-----\n"; + + const char* root_ca = "-----BEGIN CERTIFICATE-----\n" +"MIIBaTCCAQ+gAwIBAgIQR33gIB75I7Vi/QnMnmiWvzAKBggqhkjOPQQDAjATMREw\n" +"DwYDVQQKEwhUZXN0IE9SRzAeFw0xOTA1MDIyMDA1MTVaFw0yOTAzMTAyMDA1MTVa\n" +"MBMxETAPBgNVBAoTCFRlc3QgT1JHMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\n" +"xbwMaS8jcuibSYJkCmuVHfeV3xfYVyUq8Iroz7YlXaTayspW3K4hVdwIsy/5U+3U\n" +"vM/vdK5wn2+NrWy45vFAJqNFMEMwDgYDVR0PAQH/BAQDAgEGMBMGA1UdJQQMMAoG\n" +"CCsGAQUFBwMBMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0RBAQwAoIAMAoGCCqGSM49\n" +"BAMCA0gAMEUCIBWkxuHKgLSp6OXDJoztPP7/P5VBZiwLbfjTCVRxBvwWAiEAnzNu\n" +"6gKPwtKmY0pBxwCo3NNmzNpA6KrEOXE56PkiQYQ=\n" +"-----END CERTIFICATE-----\n"; + + int ee_credid = oc_pki_add_mfg_cert(0, (const unsigned char *)cert, strlen(cert), + (const unsigned char *)key, strlen(key)); + if (ee_credid < 0) { + PRINT("ERROR installing manufacturer EE cert\n"); + return; + } + + int rootca_credid = + oc_pki_add_mfg_trust_anchor(0, (const unsigned char *)root_ca, strlen(root_ca)); + if (rootca_credid < 0) { + PRINT("ERROR installing root cert\n"); + return; + } + + oc_pki_set_security_profile(0, OC_SP_BLACK, OC_SP_BLACK, ee_credid); +#endif /* OC_SECURITY && OC_PKI */ +} +#endif /* OC_SECURITY && OC_PKI */ + +void +factory_presets_cb(size_t device, void *data) +{ + (void)device; + (void)data; +#if defined(OC_SECURITY) && defined(OC_PKI) + unsigned char cloud_ca[4096]; + size_t cert_len = 4096; + if (read_pem("pki_certs/cloudca.pem", (char *)cloud_ca, &cert_len) < 0) { + PRINT("ERROR: unable to read certificates\n"); + return; + } + + int rootca_credid = + oc_pki_add_trust_anchor(0, (const unsigned char *)cloud_ca, cert_len); + if (rootca_credid < 0) { + PRINT("ERROR installing root cert\n"); + return; + } +#endif /* OC_SECURITY && OC_PKI */ +} + +int +main(int argc, char *argv[]) +{ + if (argc == 1) { + PRINT("./cloud_server " + "\n"); +#ifndef OC_SECURITY + PRINT("Using default parameters: device_name: %s, auth_code: %s, cis: %s, " + "sid: %s, " + "apn: %s\n", + device_name, auth_code, cis, sid, apn); +#endif /* !OC_SECURITY */ + } + if (argc > 1) { + device_name = argv[1]; + PRINT("device_name: %s\n", argv[1]); + } + if (argc > 2) { + auth_code = argv[2]; + PRINT("auth_code: %s\n", argv[2]); + } + if (argc > 3) { + cis = argv[3]; + PRINT("cis : %s\n", argv[3]); + } + if (argc > 4) { + sid = argv[4]; + PRINT("sid: %s\n", argv[4]); + } + if (argc > 5) { + apn = argv[5]; + PRINT("apn: %s\n", argv[5]); + } + + int ret = init(); + if (ret < 0) { + return ret; + } + + static const oc_handler_t handler = { .init = app_init, + .signal_event_loop = signal_event_loop, + .register_resources = + register_resources }; +#ifdef OC_STORAGE + oc_storage_config("./cloud_server_creds/"); +#endif /* OC_STORAGE */ + oc_set_factory_presets_cb(factory_presets_cb_new, NULL); + + ret = oc_main_init(&handler); + if (ret < 0) + return ret; + + oc_cloud_context_t *ctx = oc_cloud_get_context(0); + if (ctx) { + oc_cloud_manager_start(ctx, cloud_status_handler, NULL); + if (cis) { + oc_cloud_provision_conf_resource(ctx, cis, auth_code, sid, apn); + } + } + + run(); + + oc_cloud_manager_stop(ctx); + oc_main_shutdown(); + return 0; +} diff --git a/device-simulator/src/port/linux/oc_config.h b/device-simulator/src/port/linux/oc_config.h new file mode 100644 index 000000000..5a3de32c6 --- /dev/null +++ b/device-simulator/src/port/linux/oc_config.h @@ -0,0 +1,120 @@ +#ifndef OC_CONFIG_H +#define OC_CONFIG_H + +/* Time resolution */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint64_t oc_clock_time_t; +#define OC_CLOCK_CONF_TICKS_PER_SECOND CLOCKS_PER_SEC +//#define OC_SPEC_VER_OIC +/* Security Layer */ +/* Max inactivity timeout before tearing down DTLS connection */ +#define OC_DTLS_INACTIVITY_TIMEOUT (600) + +/* Maximum wait time for select function */ +#define SELECT_TIMEOUT_SEC (1) + +/* Add support for passing network up/down events to the app */ +#define OC_NETWORK_MONITOR +/* Add support for passing TCP/TLS/DTLS session connection events to the app */ +#define OC_SESSION_EVENTS +/* Add request history for deduplicate UDP/DTLS messages */ +//#define OC_REQUEST_HISTORY + +/* Add support for software update */ +//#define OC_SOFTWARE_UPDATE or run "make" with SWUPDATE=1 +/* Add support for the oic.if.create interface in Collections */ +//#define OC_COLLECTIONS_IF_CREATE or run "make" with CREATE=1 +/* Add support for the maintenance resource */ +//#define OC_MNT or run "make" with MNT=1 +/* Add batch interface support to /oic/res */ +#define OC_RES_BATCH_SUPPORT +/* Add support for dns lookup to the endpoint */ +#define OC_DNS_LOOKUP +#define OC_DNS_CACHE +//#define OC_DNS_LOOKUP_IPV6 + +/* If we selected support for dynamic memory allocation */ +#ifdef OC_DYNAMIC_ALLOCATION +#define OC_COLLECTIONS +#define OC_BLOCK_WISE + +#else /* OC_DYNAMIC_ALLOCATION */ +/* List of constraints below for a build that does not employ dynamic + memory allocation +*/ +/* Memory pool sizes */ +#define OC_BYTES_POOL_SIZE (1800) +#define OC_INTS_POOL_SIZE (100) +#define OC_DOUBLES_POOL_SIZE (4) + +/* Server-side parameters */ +/* Maximum number of server resources */ +#define OC_MAX_APP_RESOURCES (4) + +#define OC_MAX_NUM_COLLECTIONS (1) + +/* Common paramters */ +/* Prescriptive lower layers MTU size, enable block-wise transfers */ +#define OC_BLOCK_WISE_SET_MTU (700) + +/* Maximum size of request/response payloads */ +#define OC_MAX_APP_DATA_SIZE (2048) + +/* Maximum number of concurrent requests */ +#define OC_MAX_NUM_CONCURRENT_REQUESTS (3) + +/* Maximum number of nodes in a payload tree structure */ +#define OC_MAX_NUM_REP_OBJECTS (150) + +/* Number of devices on the OCF platform */ +#define OC_MAX_NUM_DEVICES (2) + +/* Maximum number of endpoints */ +#define OC_MAX_NUM_ENDPOINTS (20) + +/* Security layer */ +/* Maximum number of authorized clients */ +#define OC_MAX_NUM_SUBJECTS (2) + +/* Maximum number of concurrent (D)TLS sessions */ +#define OC_MAX_TLS_PEERS (1) + +/* Maximum number of peer for TCP channel */ +#define OC_MAX_TCP_PEERS (16) + +/* Maximum number of interfaces for IP adapter */ +#define OC_MAX_IP_INTERFACES (2) + +/* Maximum number of callbacks for Network interface event monitoring */ +#define OC_MAX_NETWORK_INTERFACE_CBS (2) + +/* Maximum number of callbacks for connection of session */ +#define OC_MAX_SESSION_EVENT_CBS (2) + +#endif /* !OC_DYNAMIC_ALLOCATION */ + +/* library features that require persistent storage */ +#ifdef OC_SECURITY +#define OC_STORAGE +#endif +#ifdef OC_IDD_API +#define OC_STORAGE +#endif +#ifdef OC_CLOUD +#define OC_STORAGE +#endif +#ifdef OC_SOFTWARE_UPDATE +#define OC_STORAGE +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* OC_CONFIG_H */