...
 
Commits (17)
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff is collapsed.
......@@ -100,6 +100,7 @@ oc_new_link(oc_resource_t *resource)
oc_new_string_array(&link->rel, 3);
oc_string_array_add_item(link->rel, "hosts");
link->resource = resource;
link->interfaces = resource->interfaces;
resource->num_links++;
link->next = 0;
link->ins = (int64_t)oc_random_value();
......@@ -122,7 +123,8 @@ oc_delete_link(oc_link_t *link)
oc_memb_free(&oc_params_s, p);
p = (oc_link_params_t *)oc_list_pop(link->params);
}
if (link->resource) {
if (oc_ri_is_app_resource_valid(link->resource) ||
oc_check_if_collection(link->resource)) {
link->resource->num_links--;
}
oc_free_string_array(&(link->rel));
......@@ -202,6 +204,12 @@ oc_link_add_link_param(oc_link_t *link, const char *key, const char *value)
}
}
void
oc_link_set_interfaces(oc_link_t *link, oc_interface_mask_t new_interfaces)
{
link->interfaces = new_interfaces;
}
oc_collection_t *
oc_get_collection_by_uri(const char *uri_path, size_t uri_path_len,
size_t device)
......@@ -600,7 +608,7 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
oc_rep_set_text_string(links, href, oc_string(link->resource->uri));
oc_rep_set_string_array(links, rt, link->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links),
link->resource->interfaces);
link->interfaces);
oc_rep_set_string_array(links, rel, link->rel);
oc_rep_set_int(links, ins, link->ins);
oc_link_params_t *p = (oc_link_params_t *)oc_list_head(link->params);
......@@ -701,8 +709,7 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
oc_rep_object_array_start_item(links);
oc_rep_set_text_string(links, href, oc_string(link->resource->uri));
oc_rep_set_string_array(links, rt, link->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links),
link->resource->interfaces);
oc_core_encode_interfaces_mask(oc_rep_object(links), link->interfaces);
oc_rep_set_string_array(links, rel, link->rel);
oc_rep_set_int(links, ins, link->ins);
oc_link_params_t *p = (oc_link_params_t *)oc_list_head(link->params);
......
......@@ -46,6 +46,7 @@ static oc_device_info_t oc_device_info[OC_MAX_NUM_DEVICES];
static oc_platform_info_t oc_platform_info;
static bool announce_con_res = false;
static int res_latency = 0;
static size_t device_count = 0;
/* Although used several times in the OCF spec, "/oic/con" is not
......@@ -272,6 +273,18 @@ oc_get_con_res_announced(void)
return announce_con_res;
}
void
oc_core_set_latency(int latency)
{
res_latency = latency;
}
int
oc_core_get_latency(void)
{
return res_latency;
}
void
oc_set_con_res_announced(bool announce)
{
......@@ -610,6 +623,10 @@ oc_core_get_resource_by_uri(const char *uri, size_t device)
type = OCF_SEC_ROLES;
}
#endif /* OC_PKI */
else if ((strlen(uri) - skip) == 11 &&
memcmp(uri + skip, "oic/sec/sdi", 11) == 0) {
type = OCF_SEC_SDI;
}
#endif /* OC_SECURITY */
#ifdef OC_SOFTWARE_UPDATE
else if ((strlen(uri) - skip) == 2 && memcmp(uri + skip, "sw", 2) == 0) {
......
......@@ -36,6 +36,10 @@
#include "oc_core_res.h"
#include "oc_endpoint.h"
#ifdef OC_SECURITY
#include "security/oc_sdi.h"
#endif
static bool
filter_resource(oc_resource_t *resource, oc_request_t *request,
const char *anchor, CborEncoder *links, size_t device_index)
......@@ -111,6 +115,8 @@ filter_resource(oc_resource_t *resource, oc_request_t *request,
oc_rep_set_text_string(eps, ep, oc_string(ep));
oc_free_string(&ep);
}
if (oc_core_get_latency() > 0)
oc_rep_set_uint(eps, lat, oc_core_get_latency());
oc_rep_object_array_end_item(eps);
next_eps:
eps = eps->next;
......@@ -228,6 +234,11 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
oc_string(anchor), links, device_index))
matches++;
#endif /* OC_PKI */
if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_SDI, device_index),
request, oc_string(anchor), links, device_index))
matches++;
#endif /* OC_SECURITY */
#if defined(OC_CLIENT) && defined(OC_SERVER) && defined(OC_CLOUD)
......@@ -675,6 +686,15 @@ oc_core_discovery_handler(oc_request_t *request, oc_interface_mask_t iface_mask,
memcpy(&root_map, &props_map, sizeof(CborEncoder));
oc_process_baseline_interface(
oc_core_get_resource_by_index(OCF_RES, device));
#ifdef OC_SECURITY
oc_sec_sdi_t *s = oc_sec_get_sdi(device);
if (!s->priv) {
char uuid[37];
oc_uuid_to_str(&s->uuid, uuid, OC_UUID_LEN);
oc_rep_set_text_string(root, sduuid, uuid);
oc_rep_set_text_string(root, sdname, oc_string(s->name));
}
#endif
oc_rep_set_array(root, links);
matches += process_device_resources(oc_rep_array(links), request, device);
oc_rep_close_array(root, links);
......
......@@ -48,6 +48,7 @@
#ifdef OC_PKI
#include "security/oc_keypair.h"
#endif /* OC_PKI */
#include "security/oc_sdi.h"
#endif /* OC_SECURITY */
#ifdef OC_CLOUD
......@@ -251,6 +252,8 @@ oc_main_init(const oc_handler_t *handler)
OC_DBG("oc_main_init(): loading ECDSA keypair");
oc_sec_load_ecdsa_keypair(device);
#endif /* OC_PKI */
OC_DBG("oc_main_init(): loading sdi");
oc_sec_load_sdi(device);
}
#endif
......@@ -308,6 +311,7 @@ oc_main_shutdown(void)
#ifdef OC_PKI
oc_free_ecdsa_keypairs();
#endif /* OC_PKI */
oc_sec_sdi_free();
oc_tls_shutdown();
#endif /* OC_SECURITY */
......
......@@ -145,6 +145,19 @@ oc_ri_get_app_resources(void)
{
return oc_list_head(app_resources);
}
bool
oc_ri_is_app_resource_valid(oc_resource_t *resource)
{
oc_resource_t *res = oc_ri_get_app_resources();
while (res) {
if (res == resource) {
return true;
}
res = res->next;
}
return false;
}
#endif
int
......
......@@ -65,7 +65,7 @@ static int
app_init(void)
{
int ret = oc_init_platform("OCF", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.wk.d", "OCFTestClient", "ocf.2.1.1",
ret |= oc_add_device("/oic/d", "oic.wk.d", "OCFTestClient", "ocf.2.2.0",
"ocf.res.1.3.0,ocf.sh.1.3.0", NULL, NULL);
#if defined(OC_IDD_API)
......@@ -126,10 +126,10 @@ display_menu(void)
PRINT("[8] Start OBSERVE resource TCP\n");
PRINT("[9] Stop OBSERVE resource TCP\n");
PRINT("-----------------------------------------------\n");
#ifdef OC_CLOUD
#ifdef OC_TCP
PRINT("[20] Send ping message\n");
PRINT("-----------------------------------------------\n");
#endif /* OC_CLOUD */
#endif /* OC_TCP */
PRINT("[99] Exit\n");
PRINT("################################################\n");
PRINT("\nSelect option: \n");
......@@ -276,7 +276,7 @@ GET_handler(oc_client_response_t *data)
display_menu();
}
#ifdef OC_CLOUD
#ifdef OC_TCP
static void
ping_handler(oc_client_response_t *data)
{
......@@ -310,7 +310,7 @@ cloud_send_ping(void)
pthread_mutex_unlock(&app_sync_lock);
signal_event_loop();
}
#endif /* OC_CLOUD */
#endif /* OC_TCP */
static void
get_resource(bool tcp, bool observe)
......@@ -688,11 +688,11 @@ main(void)
case 9:
stop_observe_resource(true);
break;
#ifdef OC_CLOUD
#ifdef OC_TCP
case 20:
cloud_send_ping();
break;
#endif /* OC_CLOUD */
#endif /* OC_TCP */
case 99:
handle_signal(0);
break;
......
......@@ -7,6 +7,48 @@
"application/json"
],
"paths":{
"/oc/con": {
"get": {
"description": "Resource that allows for Device specific information to be configured.\n",
"parameters": [
{
"$ref": "#/parameters/interface-all"
}
],
"responses": {
"200": {
"description" : "",
"schema": {
"$ref": "#/definitions/Configuration"
}
}
}
},
"post": {
"description": "Update the information about the Device\n",
"parameters": [
{
"$ref": "#/parameters/interface-rw"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
}
}
},
"/oic/p":{
"get":{
"responses":{
......@@ -324,6 +366,57 @@
}
},
"type":"object"
},
"Configuration": {
"properties": {
"rt": {
"description": "Resource Type of the Resource",
"items": {
"enum": ["oic.wk.con"],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array",
"default": ["oic.wk.con"]
},
"n": {
"type": "string",
"readOnly": true,
"maxLength": 64,
"description": ""
},
"if" : {
"description": "The OCF Interfaces supported by this Resource",
"items": {
"enum": [
"oic.if.baseline",
"oic.if.rw"
],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array"
}
},
"type" : "object",
"required": ["n"]
},
"ConfigurationUpdate" : {
"properties": {
"n": {
"description": "The human friendly name to be set on the Resource, this is also reflected in the same Property in oic.wk.d",
"maxLength": 64,
"type": "string"
}
},
"required": ["n"],
"type" : "object"
}
},
"info":{
......
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
static bool got_discovery_response = false;
static int
app_init(void)
{
int ret = oc_init_platform("Apple", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.phone", "Kishen's IPhone", "1.0", "1.0",
NULL, NULL);
return ret;
}
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_endpoint_t *light_server;
static bool light_state = false;
static oc_event_callback_retval_t
stop_observe(void *data)
{
(void)data;
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, light_server);
return OC_EVENT_DONE;
}
static void
post_light(oc_client_response_t *data)
{
PRINT("POST_light:\n");
if (data->code == OC_STATUS_CHANGED)
PRINT("POST response OK\n");
else
PRINT("POST response code %d\n", data->code);
}
static void
observe_light(oc_client_response_t *data)
{
PRINT("OBSERVE_light:\n");
oc_rep_t *rep = data->payload;
while (rep != NULL) {
PRINT("key %s, value ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
PRINT("%d\n", rep->value.boolean);
light_state = rep->value.boolean;
break;
default:
break;
}
rep = rep->next;
}
if (oc_init_post(light_1, light_server, NULL, &post_light, LOW_QOS, NULL)) {
oc_rep_start_root_object();
oc_rep_set_boolean(root, state, !light_state);
oc_rep_end_root_object();
if (oc_do_post())
PRINT("Sent POST request\n");
else
PRINT("Could not send POST\n");
} else
PRINT("Could not init POST\n");
}
static oc_discovery_flags_t
discovery(const char *anchor, const char *uri, oc_string_array_t types,
oc_interface_mask_t iface_mask, oc_endpoint_t *endpoint,
oc_resource_properties_t bm, void *user_data)
{
(void)anchor;
(void)iface_mask;
(void)user_data;
(void)bm;
int i;
int uri_len = strlen(uri);
uri_len = (uri_len >= MAX_URI_LENGTH) ? MAX_URI_LENGTH - 1 : uri_len;
for (i = 0; i < oc_string_array_get_allocated_size(types); i++) {
char *t = oc_string_array_get_item(types, i);
if (strlen(t) == 11 && strncmp(t, "oic.r.light", 11) == 0) {
light_server = endpoint;
strncpy(light_1, uri, uri_len);
light_1[uri_len] = '\0';
oc_do_observe(light_1, light_server, NULL, &observe_light, LOW_QOS, NULL);
oc_set_delayed_callback(NULL, &stop_observe, 30);
got_discovery_response = true;
return OC_STOP_DISCOVERY;
}
}
return OC_CONTINUE_DISCOVERY;
}
static oc_event_callback_retval_t
do_discovery(void *data)
{
(void)data;
if (got_discovery_response) {
return OC_EVENT_DONE;
}
oc_do_ip_discovery("oic.r.light", &discovery, NULL);
return OC_EVENT_CONTINUE;
}
static void
issue_requests(void)
{
oc_set_delayed_callback(NULL, &do_discovery, 10);
}
#include "contiki.h"
PROCESS(sample_client_process, "OCF client sample");
AUTOSTART_PROCESSES(&sample_client_process);
static void
signal_event_loop(void)
{
process_post(&sample_client_process, PROCESS_EVENT_TIMER, NULL);
}
PROCESS_THREAD(sample_client_process, ev, data)
{
static struct etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
static oc_clock_time_t next_event;
PROCESS_BEGIN();
int init = oc_main_init(&handler);
if (init < 0)
return init;
while (ev != PROCESS_EVENT_EXIT) {
next_event = oc_main_poll();
if (next_event != 0) {
next_event -= oc_clock_time();
etimer_set(&et, next_event);
}
PROCESS_YIELD();
}
PROCESS_END();
}
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
#include "pthread_cond.h"
#include "thread.h"
static int quit;
static mutex_t mutex;
static pthread_cond_t cv;
static struct timespec ts;
static bool got_discovery_response = false;
static void
set_device_custom_property(void *data)
{
(void)data;
oc_set_custom_device_property(purpose, "operate lamp");
}
static int
app_init(void)
{
int ret = oc_init_platform("Apple", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.phone", "Kishen's IPhone", "1.0", "1.0",
set_device_custom_property, NULL);
return ret;
}
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_endpoint_t *light_server;
static bool light_state = false;
static oc_event_callback_retval_t
stop_observe(void *data)
{
(void)data;
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, light_server);
return OC_EVENT_DONE;
}
static void
post_light(oc_client_response_t *data)
{
PRINT("POST_light:\n");
if (data->code == OC_STATUS_CHANGED)
PRINT("POST response OK\n");
else
PRINT("POST response code %d\n", data->code);
}
static void
observe_light(oc_client_response_t *data)
{
PRINT("OBSERVE_light:\n");
oc_rep_t *rep = data->payload;
while (rep != NULL) {
PRINT("key %s, value ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
PRINT("%d\n", rep->value.boolean);
light_state = rep->value.boolean;
break;
default:
break;
}
rep = rep->next;
}
if (oc_init_post(light_1, light_server, NULL, &post_light, LOW_QOS, NULL)) {
oc_rep_start_root_object();
oc_rep_set_boolean(root, state, !light_state);
oc_rep_end_root_object();
if (oc_do_post())
PRINT("Sent POST request\n");
else
PRINT("Could not send POST\n");
} else
PRINT("Could not init POST\n");
}
static oc_discovery_flags_t
discovery(const char *anchor, const char *uri, oc_string_array_t types,
oc_interface_mask_t iface_mask, oc_endpoint_t *endpoint,
oc_resource_properties_t bm, void *user_data)
{
(void)anchor;
(void)iface_mask;
(void)user_data;
(void)bm;
int i;
int uri_len = strlen(uri);
uri_len = (uri_len >= MAX_URI_LENGTH) ? MAX_URI_LENGTH - 1 : uri_len;
for (i = 0; i < (int)oc_string_array_get_allocated_size(types); i++) {
char *t = oc_string_array_get_item(types, i);
if (strlen(t) == 11 && strncmp(t, "oic.r.light", 11) == 0) {
light_server = endpoint;
strncpy(light_1, uri, uri_len);
light_1[uri_len] = '\0';
oc_do_observe(light_1, light_server, NULL, &observe_light, LOW_QOS, NULL);
oc_set_delayed_callback(NULL, &stop_observe, 30);
got_discovery_response = true;
return OC_STOP_DISCOVERY;
}
}
return OC_CONTINUE_DISCOVERY;
}
static oc_event_callback_retval_t
do_discovery(void *data)
{
(void)data;
if (got_discovery_response) {
return OC_EVENT_DONE;
}
oc_do_ip_discovery("oic.r.light", &discovery, NULL);
return OC_EVENT_CONTINUE;
}
static void
issue_requests(void)
{
oc_set_delayed_callback(NULL, &do_discovery, 10);
}
static void
signal_event_loop(void)
{
mutex_lock(&mutex);
pthread_cond_signal(&cv);
mutex_unlock(&mutex);
}
static char _oc_main_stack[THREAD_STACKSIZE_MAIN];
void *
oc_main_thread(void *arg)
{
(void)arg;
pthread_cond_init(&cv, NULL);
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
if (oc_main_init(&handler) < 0) {
PRINT("client_riot: failed to initialize stack\n");
return NULL;
}
oc_clock_time_t next_event;
while (quit == 0) {
next_event = oc_main_poll();
mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else if (oc_clock_time() < next_event) {
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);
}
mutex_unlock(&mutex);
}
oc_main_shutdown();
return NULL;
}
int
main(void)
{
thread_create(_oc_main_stack, sizeof(_oc_main_stack), 2, 0, oc_main_thread,
NULL, "OCF event thread");
fgetc(stdin);
quit = 1;
signal_event_loop();
return 0;
}
......@@ -28,7 +28,7 @@
#include <stdio.h>
// define application specific values.
static const char *spec_version = "ocf.2.1.1";
static const char *spec_version = "ocf.2.2.0";
static const char *data_model_version = "ocf.res.1.3.0,ocf.sh.1.3.0";
static const char *device_rt = "oic.d.switch";
......
......@@ -31,7 +31,7 @@
static const size_t DEVICE = 0;
// define application specific values.
static const char *spec_version = "ocf.2.1.1";
static const char *spec_version = "ocf.2.2.0";
static const char *data_model_version = "ocf.res.1.3.0,ocf.sh.1.3.0";
static const char *deivce_uri = "/oic/d";
......@@ -899,6 +899,8 @@ register_resources(void)
oc_resource_set_periodic_observable(temp_resource, 1);
oc_resource_set_request_handler(temp_resource, OC_GET, get_temp, NULL);
oc_resource_set_request_handler(temp_resource, OC_POST, post_temp, NULL);
oc_resource_tag_func_desc(temp_resource, OC_ENUM_HEATING);
oc_resource_tag_pos_desc(temp_resource, OC_POS_CENTRE);
oc_add_resource(temp_resource);
PRINT("\tTemperature resource added.\n");
bswitch = oc_new_resource(NULL, "/switch", 1, 0);
......@@ -909,6 +911,9 @@ register_resources(void)
oc_resource_set_discoverable(bswitch, true);
oc_resource_set_request_handler(bswitch, OC_GET, get_switch, NULL);
oc_resource_set_request_handler(bswitch, OC_POST, post_switch, NULL);
oc_resource_tag_func_desc(bswitch, OC_ENUM_SMART);
oc_resource_tag_pos_rel(bswitch, 0.34, 0.5, 0.8);
oc_resource_tag_pos_desc(bswitch, OC_POS_TOP);
oc_add_resource(bswitch);
PRINT("\tSwitch resource added.\n");
#ifdef OC_COLLECTIONS
......
......@@ -7,6 +7,48 @@
"application/json"
],
"paths":{
"/oc/con": {
"get": {
"description": "",
"parameters": [
{
"$ref": "#/parameters/interface-rw"
}
],
"responses": {
"200": {
"description" : "",
"schema": {
"$ref": "#/definitions/Configuration"
}
}
}
},
"post": {
"description": "",
"parameters": [
{
"$ref": "#/parameters/interface-rw"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
}
}
},
"/platform?if=oic.if.ll":{
"get":{
"responses":{
......@@ -142,7 +184,7 @@
},
"parameters":[
{
"$ref":"#/parameters/interface-update"
"$ref":"#/parameters/interface-all40"
},
{
"schema":{
......@@ -232,7 +274,7 @@
},
"parameters":[
{
"$ref":"#/parameters/interface-all"
"$ref":"#/parameters/interface-rw"
}
],
"description":""
......@@ -250,7 +292,7 @@
},
"parameters":[
{
"$ref":"#/parameters/interface-update"
"$ref":"#/parameters/interface-all40"
},
{
"schema":{
......@@ -350,7 +392,7 @@
"description":""
},
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -378,7 +420,7 @@
"tag-pos-rel":{
"type":"array",
"readOnly":true,
"description":"Relative position; against a known [0,0,0] point.",
"description":"",
"minItems":3,
"maxItems":3,
"items":{
......@@ -430,7 +472,7 @@
"items":{
"properties":{
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -690,7 +732,7 @@
"description":""
},
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -869,7 +911,7 @@
"items":{
"properties":{
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -1195,7 +1237,7 @@
"oic.oic-link":{
"properties":{
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -1335,7 +1377,7 @@
"description":""
},
"di":{
"type":"string",
"type":"string",
"pattern":"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
"description":""
},
......@@ -1350,16 +1392,67 @@
"if"
],
"type":"object"
}
},
"Configuration": {
"properties": {
"rt": {
"description": "",
"items": {
"enum": ["oic.wk.con"],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array",
"default": ["oic.wk.con"]
},
"n": {
"type": "string",
"readOnly": true,
"maxLength": 64,
"description": ""
},
"if" : {
"description": "",
"items": {
"enum": [
"oic.if.baseline",
"oic.if.rw"
],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array"
}
},
"type" : "object",
"required": ["n"]
},
"ConfigurationUpdate" : {
"properties": {
"n": {
"description": "",
"maxLength": 64,
"type": "string"
}
},
"required": ["n"],
"type" : "object"
}
},
"info":{
"version":"20190215",
"title":"serverlite24521",
"termsOfService":"https://openconnectivityfoundation.github.io/core/DISCLAIMER.md",
"title":"serverlite",
"termsOfService":"",
"license":{
"x-copyright":"copyright 2016-2017, 2019 Open Connectivity Foundation, Inc. All rights reserved.",
"url":"https://github.com/openconnectivityfoundation/core/blob/e28a9e0a92e17042ba3e83661e4c0fbce8bdc4ba/LICENSE.md",
"name":"OCF Data Model License"
"x-copyright":"",
"url":"",
"name":""
}
},
"parameters":{
......@@ -1371,7 +1464,6 @@
],
"in":"query",
"name":"units",
"x-queryexample":"/TemperatureResURI?units=C",
"description":"",
"type":"string"
},
......@@ -1384,17 +1476,6 @@
"in":"query",
"name":"if"
},
"interface-update":{
"enum":[
"oic.if.ll",
"oic.if.create",
"oic.if.b",
"oic.if.baseline"
],
"type":"string",
"in":"query",
"name":"if"
},
"interface30":{
"enum":[
"oic.if.r",
......@@ -1425,7 +1506,7 @@
},
"interface-all40":{
"enum":[
"oic.if.ll",
"oic.if.ll",
"oic.if.create",
"oic.if.b",
"oic.if.baseline"
......@@ -1434,15 +1515,6 @@
"in":"query",
"name":"if"
},
"interface-all":{
"enum":[
"oic.if.rw",
"oic.if.baseline"
],
"type":"string",
"in":"query",
"name":"if"
},
"platforminterface-all":{
"enum":[
"oic.if.baseline"
......
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
static bool light_state = false;
static int
app_init(void)
{
int ret = oc_init_platform("Intel", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.light", "Kishen's light", "1.0", "1.0",
NULL, NULL);
return ret;
}
static void
get_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)user_data;
PRINT("GET_light:\n");
oc_rep_start_root_object();
switch (iface_mask) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
case OC_IF_RW:
oc_rep_set_boolean(root, state, light_state);
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
PRINT("Light state %d\n", light_state);
}
static void
post_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)iface_mask;
(void)user_data;
PRINT("POST_light:\n");
bool state = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
PRINT("key: %s ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
state = rep->value.boolean;
PRINT("value: %d\n", state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
break;
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
light_state = state;
}
static void
put_light(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
post_light(request, iface_mask, user_data);
}
static void
register_resources(void)
{
oc_resource_t *res = oc_new_resource("lightbulb", "/light/1", 1, 0);
oc_resource_bind_resource_type(res, "oic.r.light");
oc_resource_bind_resource_interface(res, OC_IF_RW);
oc_resource_set_default_interface(res, OC_IF_RW);
oc_resource_set_discoverable(res, true);
oc_resource_set_periodic_observable(res, 1);
oc_resource_set_request_handler(res, OC_GET, get_light, NULL);
oc_resource_set_request_handler(res, OC_POST, post_light, NULL);
oc_resource_set_request_handler(res, OC_PUT, put_light, NULL);
oc_add_resource(res);
}
#include "contiki.h"
PROCESS(sample_server_process, "OCF server sample");
AUTOSTART_PROCESSES(&sample_server_process);
static void
signal_event_loop(void)
{
process_post(&sample_server_process, PROCESS_EVENT_TIMER, NULL);
}
PROCESS_THREAD(sample_server_process, ev, data)
{
static struct etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
static oc_clock_time_t next_event;
PROCESS_BEGIN();
int init = oc_main_init(&handler);
if (init < 0)
return init;
while (ev != PROCESS_EVENT_EXIT) {
next_event = oc_main_poll();
if (next_event != 0) {
next_event -= oc_clock_time();
etimer_set(&et, next_event);
}
PROCESS_YIELD();
}
PROCESS_END();
}
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
static bool light_state = false;
static int
app_init(void)
{
int ret = oc_init_platform("Intel", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.light", "Kishen's light", "1.0", "1.0",
NULL, NULL);
return ret;
}
static void
get_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)user_data;
PRINT("GET_light:\n");
oc_rep_start_root_object();
switch (iface_mask) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
case OC_IF_RW:
oc_rep_set_boolean(root, state, light_state);
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
PRINT("Light state %d\n", light_state);
}
static void
post_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)iface_mask;
(void)user_data;
PRINT("POST_light:\n");
bool state = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
PRINT("key: %s ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
state = rep->value.boolean;
PRINT("value: %d\n", state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
break;
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
light_state = state;
}
static void
put_light(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
post_light(request, iface_mask, user_data);
}
static void
register_resources(void)
{
oc_resource_t *res = oc_new_resource("lightbulb", "/light/1", 1, 0);
oc_resource_bind_resource_type(res, "oic.r.light");
oc_resource_bind_resource_interface(res, OC_IF_RW);
oc_resource_set_default_interface(res, OC_IF_RW);
oc_resource_set_discoverable(res, true);
oc_resource_set_periodic_observable(res, 1);
oc_resource_set_request_handler(res, OC_GET, get_light, NULL);
oc_resource_set_request_handler(res, OC_POST, post_light, NULL);
oc_resource_set_request_handler(res, OC_PUT, put_light, NULL);
oc_add_resource(res);
}
#include "pthread_cond.h"
#include "thread.h"
static int quit;
static mutex_t mutex;
static pthread_cond_t cv;
static struct timespec ts;
static void
signal_event_loop(void)
{
mutex_lock(&mutex);
pthread_cond_signal(&cv);
mutex_unlock(&mutex);
}
static char _oc_main_stack[THREAD_STACKSIZE_MAIN];
void *
oc_main_thread(void *arg)
{
(void)arg;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
if (oc_main_init(&handler) < 0) {
PRINT("server_riot: failed to initialize stack\n");
return NULL;
}
oc_clock_time_t next_event;
while (!quit) {
next_event = oc_main_poll();
mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else {
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);
}
mutex_unlock(&mutex);
}
oc_main_shutdown();
return NULL;
}
int
main(void)
{
thread_create(_oc_main_stack, sizeof(_oc_main_stack), 2, 0, oc_main_thread,
NULL, "OCF event thread");
fgetc(stdin);
quit = 1;
signal_event_loop();
return 0;
}
This diff is collapsed.
......@@ -142,12 +142,17 @@ main(void)
int init;
/* set the latency to 240 seconds*/
/* if no latency is needed then remove the next line */
oc_core_set_latency(240);
signal(SIGINT, handle_signal);
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources = register_resources,
.requests_entry = 0 };
static const oc_handler_t handler = { .init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources,
.requests_entry = 0 };
oc_clock_time_t next_event;
......@@ -166,8 +171,8 @@ main(void)
} else {
oc_clock_time_t now = oc_clock_time();
if (now < next_event) {
SleepConditionVariableCS(&cv, &cs,
(DWORD)((next_event-now) * 1000 / OC_CLOCK_SECOND));
SleepConditionVariableCS(
&cv, &cs, (DWORD)((next_event - now) * 1000 / OC_CLOCK_SECOND));
}
}
}
......
......@@ -70,7 +70,7 @@ app_init(void)
oc_activate_interrupt_handler(toggle_switch);
int err = oc_init_platform("Intel", NULL, NULL);
err |= oc_add_device("/oic/d", "oic.d.switch", "Temp_sensor", "ocf.2.1.1",
err |= oc_add_device("/oic/d", "oic.d.switch", "Temp_sensor", "ocf.2.2.0",
"ocf.res.1.3.0,ocf.sh.1.3.0", NULL, NULL);
PRINT("\tSwitch device added.\n");
#if defined(OC_IDD_API)
......@@ -741,6 +741,13 @@ main(void)
// max app data size set to 13k large enough to hold full IDD
oc_set_max_app_data_size(13312);
/* set the latency to 240 seconds*/
/* if no latency is needed then remove the next line */
oc_core_set_latency(240);
/* set the MTU size to the (minimum IPv6 MTU - size of UDP/IP headers) */
/* DTLS handshake messages would be fragmented to fit within this size */
/* This enables certificate-based DTLS handshakes over Thread */
oc_set_mtu_size(1232);
#ifdef OC_STORAGE
oc_storage_config("./smart_home_server_linux_creds");
#endif /* OC_STORAGE */
......
......@@ -85,7 +85,7 @@ app_init(void)
{
int err = oc_init_platform("Intel", NULL, NULL);
err |= oc_add_device("/oic/d", "oic.d.switch", "binary_switch", "ocf.2.1.1",
err |= oc_add_device("/oic/d", "oic.d.switch", "binary_switch", "ocf.2.2.0",
"ocf.res.1.3.0,ocf.sh.1.3.0", NULL, NULL);
return err;
}
......
......@@ -23,8 +23,7 @@
#include "util/oc_list.h"
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
typedef struct oc_link_params_t
......@@ -38,6 +37,7 @@ struct oc_link_s
{
struct oc_link_s *next;
oc_resource_t *resource;
oc_interface_mask_t interfaces;
int64_t ins;
oc_string_array_t rel;
OC_LIST_STRUCT(params);
......@@ -75,6 +75,9 @@ struct oc_collection_s
OC_LIST_STRUCT(links);
};
void oc_link_set_interfaces(oc_link_t *link,
oc_interface_mask_t new_interfaces);
bool oc_handle_collection_request(oc_method_t method, oc_request_t *request,
oc_interface_mask_t iface_mask,
oc_resource_t *notify_resource);
......
......@@ -92,6 +92,24 @@ bool oc_filter_resource_by_rt(oc_resource_t *resource, oc_request_t *request);
bool oc_core_is_DCR(oc_resource_t *resource, size_t device);
/**
* set the latency (lat) property in eps of oic.wk.res resource.
* The latency is implemented globally e.g. for all the resource instances.
* The default behaviour is that if nothing is set (e.g. value is 0) the lat
* property will not be framed in the eps property. Setting the value on 0 will
* cause that the lat property will not be framed in the eps property.
* @param[in] latency the latency in seconds
*/
void oc_core_set_latency(int latency);
/**
* retrieves the latency (lat) property in eps of the oic.wk.res resource.
* the lat value is implemented globally for the stack
* @return
* - the latency in seconds
*/
int oc_core_get_latency(void);
#ifdef __cplusplus
}
#endif
......
......@@ -30,8 +30,7 @@
#include "oc_uuid.h"
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
/**
......@@ -708,8 +707,8 @@ int oc_obt_provision_role_certificate(oc_role_t *roles, oc_uuid_t *uuid,
* Build a linked list of roles to provision a role certificate.
*
* This function will add a single role (role name and authroity) to a list of
* rules. If the provided list of roles is empty, it will create a new list with the
* added role.
* rules. If the provided list of roles is empty, it will create a new list with
* the added role.
*
* Example:
* ```
......@@ -942,7 +941,8 @@ void oc_obt_free_ace(oc_sec_ace_t *ace);
/**
* Provision a role ACE for the wildcard "*" resource with RW permissions.
*
* This is a helper function to quickly provision a role ACE for wildcard access.
* This is a helper function to quickly provision a role ACE for wildcard
* access.
*
* @param[in] subject the uuid or the device being provisioned
* @param[in] role the role for the ACE
......@@ -1134,7 +1134,7 @@ void oc_obt_free_acl(oc_sec_acl_t *acl);
*/
int oc_obt_delete_ace_by_aceid(oc_uuid_t *uuid, int aceid,
oc_obt_status_cb_t cb, void *data);
void oc_obt_set_sd_info(char *name, bool priv);
#ifdef __cplusplus
}
#endif
......
......@@ -138,6 +138,7 @@ typedef enum {
OCF_SEC_ACL,
OCF_SEC_AEL,
OCF_SEC_CRED,
OCF_SEC_SDI,
OCF_SEC_SP,
#ifdef OC_PKI
OCF_SEC_CSR,
......@@ -274,6 +275,8 @@ int oc_ri_get_query_value(const char *query, size_t query_len, const char *key,
oc_interface_mask_t oc_ri_get_interface_mask(char *iface, size_t if_len);
bool oc_ri_is_app_resource_valid(oc_resource_t *resource);
#ifdef __cplusplus
}
#endif
......
......@@ -703,7 +703,7 @@ coap_receive(oc_message_t *msg)
message->token, message->token_len);
}
}
if (response_buffer) {
if (!error_response && response_buffer) {