Commit b0e9dac7 authored by George Nash's avatar George Nash

Add OC_STORAGE define that is set in oc_config.h

Persistant storage is currently only enabled if OC_SECURITY
is defined.  This has lead implementation problems when
implementing features like introspection, cloud, or
software-update which also require persistant storage.

This commit replaces the `#ifdef OC_SECURITY` with
`#ifdef OC_STORAGE` in oc_storage.c.

Inside config.h OC_STORAGE is defined if OC_SECURITY, OC_IDD_API
OC_SOFTWARE_UPDATE, or OC_SECURITY is defined.

Also updated samples that call oc_storage_config so they call it
if OC_STORAGE is defined instead of OC_SECURITY.

Removed the dummy storage implmentation from the
oc_cloud_storage.c since OC_STORAGE is now defined by default
when OC_CLOUD is defined.

Some preprocessor check were added to check it one of the
features that require OC_STORAGE is set but OC_STORAGE is not
set. This will cause a build error and inform developers to
check oc_config.h to make sure OC_STORAGE is set there.

Change-Id: I9a9242349e939393f190cab373fe7d0252ae656c
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent 617f48c6
Pipeline #199 passed with stage
in 50 seconds
......@@ -21,43 +21,20 @@
#include "oc_api.h"
#include "oc_cloud_internal.h"
#include "oc_rep.h"
#include "oc_config.h"
#ifdef OC_DYNAMIC_ALLOCATION
#include <stdlib.h>
#endif /* OC_DYNAMIC_ALLOCATION */
#ifndef OC_STORAGE
#error Preprocessor macro OC_CLOUD is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_CLOUD is defined.
#endif
#define CLOUD_STORE_NAME "cloud"
#define CLOUD_TAG_MAX (32)
#ifndef OC_SECURITY
// dummy storage
int
oc_storage_config(const char *store)
{
(void)store;
return 0;
}
long
oc_storage_read(const char *store, uint8_t *buf, size_t size)
{
(void)store;
(void)buf;
(void)size;
return -1;
}
long
oc_storage_write(const char *store, uint8_t *buf, size_t size)
{
(void)store;
(void)buf;
(void)size;
return -1;
}
#endif
static int cloud_store_load_internal(const char *store_name,
oc_cloud_store_t *store);
static void gen_cloud_tag(const char *name, size_t device, char *cloud_tag);
......
......@@ -22,14 +22,19 @@
#include "oc_introspection_internal.h"
#include <inttypes.h>
#include <stdio.h>
#include "oc_config.h"
#ifndef OC_IDD_API
#include "server_introspection.dat.h"
#else /* OC_IDD_API */
#if !defined(OC_STORAGE) && defined(OC_IDD_API)
#error Preprocessor macro OC_IDD_API is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_IDD_API is defined.
#endif
#define MAX_TAG_LENGTH 20
#ifdef OC_SECURITY
static void
gen_idd_tag(const char *name, size_t device_index, char *idd_tag)
{
......@@ -39,19 +44,13 @@ gen_idd_tag(const char *name, size_t device_index, char *idd_tag)
(idd_tag_len < MAX_TAG_LENGTH) ? idd_tag_len + 1 : MAX_TAG_LENGTH;
idd_tag[idd_tag_len] = '\0';
}
#endif /* OC_SECURITY */
void
oc_set_introspection_data(size_t device, uint8_t *IDD, size_t IDD_size)
{
(void) device;
(void) IDD;
(void) IDD_size;
#ifdef OC_SECURITY
char idd_tag[MAX_TAG_LENGTH];
gen_idd_tag("IDD", device, idd_tag);
oc_storage_write(idd_tag, IDD, IDD_size);
#endif /* OC_SECURITY */
}
#endif /*OC_IDD_API*/
......@@ -73,13 +72,11 @@ oc_core_introspection_data_handler(oc_request_t *request,
} else {
IDD_size = -1;
}
#else /* OC_IDD_API */
#ifdef OC_SECURITY
#else /* OC_IDD_API */
char idd_tag[MAX_TAG_LENGTH];
gen_idd_tag("IDD", request->resource->device, idd_tag);
IDD_size = oc_storage_read(
idd_tag, request->response->response_buffer->buffer, OC_MAX_APP_DATA_SIZE);
#endif /* OC_SECURITY */
#endif /* OC_IDD_API */
if (IDD_size >= 0 && IDD_size < OC_MAX_APP_DATA_SIZE) {
......
......@@ -22,6 +22,11 @@
#include "oc_swupdate_internal.h"
#include "security/oc_pstat.h"
#ifndef OC_STORAGE
#error Preprocessor macro OC_SOFTWARE_UPDATE is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_SOFTWARE_UPDATE is defined.
#endif
#ifdef OC_DYNAMIC_ALLOCATION
#include "port/oc_assert.h"
#include <stdlib.h>
......
......@@ -176,9 +176,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./client_block_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_mtu_size(300);
oc_set_max_app_data_size(2048);
......
......@@ -427,9 +427,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./client_collections_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -163,9 +163,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./client_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_con_res_announced(false);
init = oc_main_init(&handler);
......
......@@ -394,9 +394,9 @@ main(void)
.signal_event_loop =
signal_event_loop };
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./client_multithread_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n");
......
......@@ -565,7 +565,9 @@ ocf_event_thread(void *data)
.register_resources =
register_resources };
#ifdef OC_STORAGE
oc_storage_config("./cloud_tests_creds");
#endif /* OC_STORAGE */
if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n");
......
......@@ -296,7 +296,9 @@ main(void)
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
#ifdef OC_STORAGE
oc_storage_config("./cloud_server_creds/");
#endif /* OC_STORAGE */
ret = oc_main_init(&handler);
if (ret < 0)
......
......@@ -347,9 +347,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./multi_device_client_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -228,9 +228,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./multi_device_server_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -142,9 +142,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./server_block_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_mtu_size(200);
oc_set_max_app_data_size(2048);
......
......@@ -338,9 +338,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./server_collections_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -144,9 +144,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./server_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -267,9 +267,9 @@ main(void)
.register_resources =
register_resources };
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./server_multithread_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n");
......
......@@ -261,9 +261,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./simpleclient_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -260,9 +260,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./simpleclient_creds/");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -155,9 +155,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./simpleserver_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......
......@@ -391,9 +391,9 @@ main(void)
oc_set_mtu_size(16384);
oc_set_max_app_data_size(16384);
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./simpleserver_pki_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL);
......
......@@ -151,9 +151,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./simpleserver_creds/");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
init = oc_main_init(&handler);
if (init < 0)
......@@ -174,4 +174,4 @@ main(void)
oc_main_shutdown();
return 0;
}
\ No newline at end of file
}
......@@ -691,9 +691,9 @@ main(void)
oc_set_con_res_announced(false);
oc_set_max_app_data_size(16384);
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./smart_home_server_linux_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL);
#ifdef OC_SECURITY
......
......@@ -310,9 +310,9 @@ main(void)
oc_set_con_res_announced(false);
oc_set_max_app_data_size(16384);
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./smart_home_server_with_mock_swupdate_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL);
#ifdef OC_SECURITY
......
......@@ -412,10 +412,10 @@ main(void)
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./smart_lock_creds");
oc_set_random_pin_callback(random_pin_cb, NULL);
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
oc_set_con_res_announced(false);
init = oc_main_init(&handler);
......
......@@ -141,9 +141,9 @@ main(void)
oc_clock_time_t next_event;
#ifdef OC_SECURITY
#ifdef OC_STORAGE
oc_storage_config("./temp_sensor_creds");
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
int init = oc_main_init(&handler);
......
......@@ -1710,7 +1710,9 @@ main(void)
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
#ifdef OC_STORAGE
oc_storage_config("./onboarding_tool_creds");
#endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL);
oc_set_con_res_announced(false);
oc_set_max_app_data_size(16384);
......
......@@ -89,6 +89,20 @@ typedef uint64_t oc_clock_time_t;
#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
......
......@@ -14,6 +14,7 @@
// limitations under the License.
*/
#include "port/oc_random.h"
#include <assert.h>
#include <errno.h>
......
......@@ -14,9 +14,10 @@
// limitations under the License.
*/
#include "oc_config.h"
#include "port/oc_storage.h"
#ifdef OC_SECURITY
#ifdef OC_STORAGE
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
......@@ -82,4 +83,4 @@ oc_storage_write(const char *store, uint8_t *buf, size_t size)
fclose(fp);
return size;
}
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
......@@ -96,6 +96,20 @@ typedef uint64_t oc_clock_time_t;
#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
......
......@@ -14,9 +14,10 @@
// limitations under the License.
*/
#include "oc_config.h"
#include "port/oc_storage.h"
#ifdef OC_SECURITY
#ifdef OC_STORAGE
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
......@@ -83,4 +84,4 @@ oc_storage_write(const char *store, uint8_t *buf, size_t size)
fclose(fp);
return size;
}
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
......@@ -61,6 +61,20 @@ typedef uint64_t oc_clock_time_t;
/* Max inactivity timeout before tearing down DTLS connection */
#define OC_DTLS_INACTIVITY_TIMEOUT (10)
/* 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
} // extern "C"
#endif
......
......@@ -14,8 +14,9 @@
// limitations under the License.
*/
#include "oc_config.h"
#include "port/oc_storage.h"
#ifdef OC_SECURITY
#ifdef OC_STORAGE
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
......@@ -42,6 +42,20 @@ typedef uint64_t oc_clock_time_t;
/* Maximum number of callbacks for connection of session */
#define OC_MAX_SESSION_EVENT_CBS (2)
/* 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
......
......@@ -14,9 +14,10 @@
// limitations under the License.
*/
#include "oc_config.h"
#include "port/oc_storage.h"
#ifdef OC_SECURITY
#ifdef OC_STORAGE
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
......@@ -89,4 +90,4 @@ oc_storage_write(const char *store, uint8_t *buf, size_t size)
fclose(fp);
return (long)size;
}
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
......@@ -58,4 +58,18 @@ typedef uint64_t oc_clock_time_t;
/* Max inactivity timeout before tearing down DTLS connection */
#define OC_DTLS_INACTIVITY_TIMEOUT (10)
/* 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
#endif /* OC_CONFIG_H */
......@@ -14,7 +14,9 @@
// limitations under the License.
*/
#ifdef OC_SECURITY
#include "oc_config.h"
#ifdef OC_STORAGE
#include <device.h>
#include <flash.h>
......@@ -386,4 +388,4 @@ oc_storage_write(const char *store, uint8_t *buf, size_t size)
return size;
}
#endif /* OC_SECURITY */
#endif /* OC_STORAGE */
......@@ -14,11 +14,17 @@
// limitations under the License.
*/
#include "oc_config.h"
#ifdef OC_SECURITY
#ifndef OC_DYNAMIC_ALLOCATION
#error "ERROR: Please rebuild with OC_DYNAMIC_ALLOCATION"
#endif /* !OC_DYNAMIC_ALLOCATION */
#ifndef OC_STORAGE
#error Preprocessor macro OC_SECURITY is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_SECURITY is defined.
#endif
#include "oc_obt.h"
#include "oc_core_res.h"
#include "security/oc_acl_internal.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment