You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by pa...@apache.org on 2016/09/16 20:42:29 UTC
incubator-mynewt-core git commit: basic test app working with the
iotivity client that builds with their constrained github repo
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop b359382d5 -> d27f1f309
basic test app working with the iotivity client that builds with their constrained github repo
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d27f1f30
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d27f1f30
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d27f1f30
Branch: refs/heads/develop
Commit: d27f1f3095f34bb1b9261ea425db4e87c0e548af
Parents: b359382
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Fri Sep 16 10:36:53 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Fri Sep 16 13:41:36 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/pkg.yml | 36 ++++
apps/ocf_sample/src/main.c | 198 +++++++++++++++++++
libs/iotivity/include/iotivity/oc_api.h | 6 +-
libs/iotivity/include/iotivity/oc_buffer.h | 4 +-
.../iotivity/include/iotivity/oc_client_state.h | 2 +-
libs/iotivity/include/iotivity/oc_helpers.h | 4 +-
.../include/iotivity/oc_network_events.h | 4 +-
libs/iotivity/include/iotivity/oc_rep.h | 2 +-
libs/iotivity/include/iotivity/oc_ri.h | 6 +-
libs/iotivity/src/messaging/coap/coap.h | 10 +-
libs/iotivity/src/messaging/coap/conf.h | 2 +-
libs/iotivity/src/messaging/coap/observe.h | 4 +-
libs/iotivity/src/messaging/coap/oc_coap.h | 2 +-
libs/iotivity/src/messaging/coap/separate.h | 2 +-
libs/iotivity/src/messaging/coap/transactions.h | 2 +-
libs/iotivity/src/port/mynewt/ip_adaptor.c | 87 +++++---
libs/iotivity/src/port/oc_assert.h | 2 +-
libs/iotivity/src/port/oc_clock.h | 2 +-
libs/iotivity/src/port/oc_connectivity.h | 8 +-
libs/iotivity/src/util/oc_process.h | 2 +-
libs/iotivity/src/util/oc_timer.h | 2 +-
21 files changed, 329 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/apps/ocf_sample/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/pkg.yml b/apps/ocf_sample/pkg.yml
new file mode 100644
index 0000000..32c96f2
--- /dev/null
+++ b/apps/ocf_sample/pkg.yml
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+pkg.name: apps/ocf_sample
+pkg.type: app
+pkg.description: Example application which uses OCF iotivity.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - libs/console/full
+ - libs/os
+ - libs/shell
+ - libs/util
+ - sys/log
+ - libs/iotivity
+
+# this tells the library that you intend to suppor the server functionality
+pkg.cflags: -DOC_SERVER
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
new file mode 100644
index 0000000..4d90495
--- /dev/null
+++ b/apps/ocf_sample/src/main.c
@@ -0,0 +1,198 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 <assert.h>
+#include <os/os.h>
+#include <bsp/bsp.h>
+#include <console/console.h>
+#include <shell/shell.h>
+#include <log/log.h>
+
+#include <iotivity/oc_api.h>
+#include "mn_socket/mn_socket.h"
+#include "mn_socket/arch/sim/native_sock.h"
+
+/* Shell */
+#define SHELL_TASK_PRIO (8)
+#define SHELL_MAX_INPUT_LEN (256)
+#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
+static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
+
+#define OCF_TASK_PRIO (8)
+#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
+static os_stack_t ocf_stack[OCF_TASK_STACK_SIZE];
+struct os_task ocf_task;
+
+static bool light_state = false;
+
+#define DEFAULT_MBUF_MPOOL_BUF_LEN (256)
+#define DEFAULT_MBUF_MPOOL_NBUFS (10)
+
+static uint8_t default_mbuf_mpool_data[DEFAULT_MBUF_MPOOL_BUF_LEN *
+ DEFAULT_MBUF_MPOOL_NBUFS];
+
+static struct os_mbuf_pool default_mbuf_pool;
+static struct os_mempool default_mbuf_mpool;
+
+static void
+get_light(oc_request_t *request, oc_interface_mask_t interface)
+{
+ PRINT("GET_light:\n");
+ oc_rep_start_root_object();
+ switch (interface) {
+ 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
+put_light(oc_request_t *request, oc_interface_mask_t interface)
+{
+ PRINT("PUT_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 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
+app_init(void)
+{
+ oc_init_platform("Mynewt", NULL, NULL);
+ oc_add_device("/oic/d", "oic.d.light", "MynewtLED", "1.0", "1.0", NULL, NULL);
+}
+
+static void
+register_resources(void)
+{
+ oc_resource_t *res = oc_new_resource("/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);
+
+#ifdef OC_SECURITY
+ oc_resource_make_secure(res);
+#endif
+
+ oc_resource_set_discoverable(res);
+ oc_resource_set_periodic_observable(res, 1);
+ oc_resource_set_request_handler(res, OC_GET, get_light);
+ oc_resource_set_request_handler(res, OC_PUT, put_light);
+ oc_add_resource(res);
+}
+
+struct os_sem ocf_main_loop_sem;
+
+
+ oc_handler_t ocf_handler = {.init = app_init,
+ .register_resources = register_resources };
+
+ void
+oc_signal_main_loop(void) {
+ os_sem_release(&ocf_main_loop_sem);
+}
+
+void ocf_task_handler(void *arg) {
+ /* TODO */
+ oc_main_init(&ocf_handler);
+
+ os_sem_init(&ocf_main_loop_sem, 1);
+
+ while (1) {
+ uint32_t ticks;
+ oc_clock_time_t next_event;
+ next_event = oc_main_poll();
+ ticks = oc_clock_time();
+ if (next_event == 0) {
+ ticks = OS_TIMEOUT_NEVER;
+ } else {
+ ticks = next_event - ticks;
+ }
+ os_sem_pend(&ocf_main_loop_sem, ticks);
+ }
+ oc_main_shutdown();
+}
+
+void
+ocf_task_init(void) {
+
+ int rc;
+ rc = os_task_init(&ocf_task, "ocf", ocf_task_handler, NULL,
+ OCF_TASK_PRIO, OS_WAIT_FOREVER, ocf_stack, OCF_TASK_STACK_SIZE);
+ assert(rc == 0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int rc;
+
+ /* Initialize OS */
+ os_init();
+
+ rc = os_mempool_init(&default_mbuf_mpool, DEFAULT_MBUF_MPOOL_NBUFS,
+ DEFAULT_MBUF_MPOOL_BUF_LEN, default_mbuf_mpool_data,
+ "default_mbuf_data");
+ assert(rc == 0);
+
+ rc = os_mbuf_pool_init(&default_mbuf_pool, &default_mbuf_mpool,
+ DEFAULT_MBUF_MPOOL_BUF_LEN, DEFAULT_MBUF_MPOOL_NBUFS);
+ assert(rc == 0);
+
+ rc = os_msys_register(&default_mbuf_pool);
+ assert(rc == 0);
+
+ /* Init tasks */
+ rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
+ SHELL_MAX_INPUT_LEN);
+ assert(rc == 0);
+
+ rc = native_sock_init();
+ assert(rc == 0);
+
+ ocf_task_init();
+
+ /* Start the OS */
+ os_start();
+
+ /* os start should never return. If it does, this should be an error */
+ assert(0);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_api.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_api.h b/libs/iotivity/include/iotivity/oc_api.h
index e607668..ce83b64 100644
--- a/libs/iotivity/include/iotivity/oc_api.h
+++ b/libs/iotivity/include/iotivity/oc_api.h
@@ -17,10 +17,10 @@
#ifndef OC_API_H
#define OC_API_H
-#include "messaging/coap/oc_coap.h"
+#include "../src/messaging/coap/oc_coap.h"
#include "oc_ri.h"
-#include "port/oc_signal_main_loop.h"
-#include "port/oc_storage.h"
+#include "../src/port/oc_signal_main_loop.h"
+#include "../src/port/oc_storage.h"
typedef struct
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_buffer.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_buffer.h b/libs/iotivity/include/iotivity/oc_buffer.h
index 55373e6..4204a9d 100644
--- a/libs/iotivity/include/iotivity/oc_buffer.h
+++ b/libs/iotivity/include/iotivity/oc_buffer.h
@@ -17,8 +17,8 @@
#ifndef OC_BUFFER_H
#define OC_BUFFER_H
-#include "port/oc_connectivity.h"
-#include "util/oc_process.h"
+#include "../../src/port/oc_connectivity.h"
+#include "../../src/util/oc_process.h"
#include <stdbool.h>
OC_PROCESS_NAME(message_buffer_handler);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_client_state.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_client_state.h b/libs/iotivity/include/iotivity/oc_client_state.h
index 7049c32..eb04857 100644
--- a/libs/iotivity/include/iotivity/oc_client_state.h
+++ b/libs/iotivity/include/iotivity/oc_client_state.h
@@ -17,7 +17,7 @@
#ifndef OC_CLIENT_STATE_H
#define OC_CLIENT_STATE_H
-#include "messaging/coap/constants.h"
+#include "../../src/messaging/coap/constants.h"
#include "oc_ri.h"
#include <stdbool.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_helpers.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_helpers.h b/libs/iotivity/include/iotivity/oc_helpers.h
index 4a8cd1e..0f730bb 100644
--- a/libs/iotivity/include/iotivity/oc_helpers.h
+++ b/libs/iotivity/include/iotivity/oc_helpers.h
@@ -17,8 +17,8 @@
#ifndef OC_HELPERS_H
#define OC_HELPERS_H
-#include "util/oc_list.h"
-#include "util/oc_mmem.h"
+#include "../../src/util/oc_list.h"
+#include "../../src/util/oc_mmem.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_network_events.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_network_events.h b/libs/iotivity/include/iotivity/oc_network_events.h
index a678666..f8b98ca 100644
--- a/libs/iotivity/include/iotivity/oc_network_events.h
+++ b/libs/iotivity/include/iotivity/oc_network_events.h
@@ -17,8 +17,8 @@
#ifndef OC_NETWORK_EVENTS_H
#define OC_NETWORK_EVENTS_H
-#include "port/oc_network_events_mutex.h"
-#include "util/oc_process.h"
+#include "../../src/port/oc_network_events_mutex.h"
+#include "../../src/util/oc_process.h"
OC_PROCESS_NAME(oc_network_events);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_rep.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_rep.h b/libs/iotivity/include/iotivity/oc_rep.h
index b7a88be..713abb5 100644
--- a/libs/iotivity/include/iotivity/oc_rep.h
+++ b/libs/iotivity/include/iotivity/oc_rep.h
@@ -20,7 +20,7 @@
#include <tinycbor/cbor.h>
#include "oc_constants.h"
#include "oc_helpers.h"
-#include <config.h>
+#include "../src/port/mynewt/config.h"
#include <stdbool.h>
#include <stdint.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/include/iotivity/oc_ri.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_ri.h b/libs/iotivity/include/iotivity/oc_ri.h
index 5e96656..b836f70 100644
--- a/libs/iotivity/include/iotivity/oc_ri.h
+++ b/libs/iotivity/include/iotivity/oc_ri.h
@@ -17,11 +17,11 @@
#ifndef OC_RI_H
#define OC_RI_H
-#include "config.h"
+#include "../src/port/mynewt/config.h"
#include "oc_rep.h"
#include "oc_uuid.h"
-#include "port/oc_connectivity.h"
-#include "util/oc_etimer.h"
+#include "../../src/port/oc_connectivity.h"
+#include "../../src/util/oc_etimer.h"
typedef enum { OC_GET = 1, OC_POST, OC_PUT, OC_DELETE } oc_method_t;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/coap.h b/libs/iotivity/src/messaging/coap/coap.h
index b61b759..2d946fa 100644
--- a/libs/iotivity/src/messaging/coap/coap.h
+++ b/libs/iotivity/src/messaging/coap/coap.h
@@ -40,11 +40,11 @@
#include <stdint.h>
/* OIC stack headers */
-#include "config.h"
-#include "oc_buffer.h"
-#include "port/oc_connectivity.h"
-#include "port/oc_log.h"
-#include "port/oc_random.h"
+#include "../src/port/mynewt/config.h"
+#include "../../../include/iotivity/oc_buffer.h"
+#include "../src/port/oc_connectivity.h"
+#include "../src/port/oc_log.h"
+#include "../src/port/oc_random.h"
#ifndef MAX
#define MAX(n, m) (((n) < (m)) ? (m) : (n))
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/messaging/coap/conf.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/conf.h b/libs/iotivity/src/messaging/coap/conf.h
index 4e2c878..ebac670 100644
--- a/libs/iotivity/src/messaging/coap/conf.h
+++ b/libs/iotivity/src/messaging/coap/conf.h
@@ -34,7 +34,7 @@
#ifndef CONF_H
#define CONF_H
-#include "config.h"
+#include "../../port/mynewt/config.h"
/* Features that can be disabled to achieve smaller memory footprint */
#define COAP_LINK_FORMAT_FILTERING 0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/messaging/coap/observe.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/observe.h b/libs/iotivity/src/messaging/coap/observe.h
index 3f2cfb6..6d73c27 100644
--- a/libs/iotivity/src/messaging/coap/observe.h
+++ b/libs/iotivity/src/messaging/coap/observe.h
@@ -36,10 +36,10 @@
#include "coap.h"
#include "transactions.h"
-#include "util/oc_list.h"
+#include "../../util/oc_list.h"
/* OIC stack headers */
-#include "oc_ri.h"
+#include "../../../include/iotivity/oc_ri.h"
#define COAP_OBSERVER_URL_LEN 20
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/messaging/coap/oc_coap.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/oc_coap.h b/libs/iotivity/src/messaging/coap/oc_coap.h
index b393048..ccd14c8 100644
--- a/libs/iotivity/src/messaging/coap/oc_coap.h
+++ b/libs/iotivity/src/messaging/coap/oc_coap.h
@@ -18,7 +18,7 @@
#define OC_COAP_H
#include "separate.h"
-#include "util/oc_list.h"
+#include "../../util/oc_list.h"
typedef struct oc_separate_response_s
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/messaging/coap/separate.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/separate.h b/libs/iotivity/src/messaging/coap/separate.h
index 8a64de2..c91a6ea 100644
--- a/libs/iotivity/src/messaging/coap/separate.h
+++ b/libs/iotivity/src/messaging/coap/separate.h
@@ -39,7 +39,7 @@
/* OIC stack headers */
#include "oc_coap.h"
-#include "oc_ri.h"
+#include "../../../include/iotivity/oc_ri.h"
typedef struct coap_separate
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/messaging/coap/transactions.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/transactions.h b/libs/iotivity/src/messaging/coap/transactions.h
index 0b6fd9e..8807363 100644
--- a/libs/iotivity/src/messaging/coap/transactions.h
+++ b/libs/iotivity/src/messaging/coap/transactions.h
@@ -35,7 +35,7 @@
#define TRANSACTIONS_H
#include "coap.h"
-#include "util/oc_etimer.h"
+#include "../../util/oc_etimer.h"
/*
* Modulo mask (thus +1) for a random number to get the tick number for the
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ip_adaptor.c b/libs/iotivity/src/port/mynewt/ip_adaptor.c
index 11a7981..494ae82 100644
--- a/libs/iotivity/src/port/mynewt/ip_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ip_adaptor.c
@@ -33,7 +33,10 @@
#endif
#define COAP_PORT_UNSECURED (5683)
-#define ALL_COAP_NODES_V6 "FF02::FD"
+const struct mn_in6_addr coap_all_nodes_v6 = {
+ .s_addr = {0xFF,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFD}
+};
/* TODO these should be defined elsewhere but they are here as stubs */
#define MN_SOL_SOCKET (0)
@@ -99,8 +102,9 @@ oc_send_buffer(oc_message_t *message)
to.msin6_len = sizeof(to);
to.msin6_family = MN_AF_INET6;
+ to.msin6_scope_id = message->endpoint.ipv6_addr.scope;
to.msin6_port = htons(message->endpoint.ipv6_addr.port);
- memcpy(to.msin6_addr, message->endpoint.ipv6_addr.address,
+ memcpy(&to.msin6_addr, message->endpoint.ipv6_addr.address,
sizeof(to.msin6_addr));
send_sock = ucast;
@@ -125,7 +129,7 @@ oc_send_buffer(oc_message_t *message)
oc_message_t *
oc_attempt_rx(struct mn_socket * rxsock) {
int rc;
- struct os_mbuf *m;
+ struct os_mbuf *m = NULL;
struct os_mbuf_pkthdr *pkt;
oc_message_t *message;
struct mn_sockaddr_in6 from;
@@ -139,41 +143,66 @@ oc_attempt_rx(struct mn_socket * rxsock) {
}
if(!OS_MBUF_IS_PKTHDR(m)) {
- return NULL;
+ goto rx_attempt_err;
}
pkt = OS_MBUF_PKTHDR(m);
+ LOG_DEBUG(&oc_log, LOG_MODULE_DEFAULT,
+ "rx from %u %p-%u\n", rxsock, pkt, pkt->omp_len);
+
message = oc_allocate_message();
- if (NULL != message) {
+ if (NULL == message) {
/* TODO log an error that we dropped a frame */
- return NULL;
+ goto rx_attempt_err;
}
- if (pkt->omp_len > message->length) {
+ if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
/* TODO what do we do with this */
- free(message);
- return NULL;
+ goto rx_attempt_err;
}
/* copy to message from mbuf chain */
rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
if (rc != 0) {
/* TODO what do we do with this */
- free(message);
- return NULL;
+ goto rx_attempt_err;
}
+ os_mbuf_free_chain(m);
+
message->endpoint.flags = IP;
- memcpy(message->endpoint.ipv6_addr.address, from.msin6_addr,
+ message->length = pkt->omp_len;
+ memcpy(&message->endpoint.ipv6_addr.address, &from.msin6_addr,
sizeof(message->endpoint.ipv6_addr.address));
- message->endpoint.ipv6_addr.scope = 0; /* TODO what is scope */
+ message->endpoint.ipv6_addr.scope = from.msin6_scope_id;
message->endpoint.ipv6_addr.port = ntohs(from.msin6_port);
LOG_INFO(&oc_log, LOG_MODULE_DEFAULT, "rx from %u len %u\n",
rxsock, message->length);
- /* add the addr info to the message */
return message;
+
+ /* add the addr info to the message */
+rx_attempt_err:
+ if(m) {
+ os_mbuf_free_chain(m);
+ }
+
+ if (message) {
+ oc_message_unref(message);
+ }
+
+ return NULL;
+}
+
+oc_message_t *
+oc_attempt_rx_mcast(void) {
+ return oc_attempt_rx(mcast);
+}
+
+oc_message_t *
+oc_attempt_rx_ucast(void) {
+ return oc_attempt_rx(ucast);
}
static void oc_socks_readable(void *cb_arg, int err);
@@ -202,12 +231,12 @@ oc_task_handler(void *arg) {
while(1) {
oc_message_t *pmsg;
os_sem_pend(&oc_read_sem, OS_TIMEOUT_NEVER);
- pmsg = oc_attempt_rx(ucast);
+ pmsg = oc_attempt_rx_ucast();
if (pmsg) {
oc_network_event(pmsg);
}
- pmsg = oc_attempt_rx(mcast);
+ pmsg = oc_attempt_rx_mcast();
if (pmsg) {
oc_network_event(pmsg);
}
@@ -272,7 +301,6 @@ oc_connectivity_init(void)
{
int rc;
struct mn_sockaddr_in6 sin;
- uint32_t mcast_addr[4];
log_init();
@@ -287,13 +315,13 @@ oc_connectivity_init(void)
LOG_INFO(&oc_log, LOG_MODULE_DEFAULT, "OC Init");
rc = mn_socket(&ucast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
- if( !ucast || !rc) {
+ if ( rc != 0 || !ucast ) {
LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
"Could not create oc unicast socket\n");
return rc;
}
rc = mn_socket(&mcast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
- if( !mcast || !rc) {
+ if ( rc != 0 || !mcast ) {
mn_close(ucast);
LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
"Could not create oc multicast socket\n");
@@ -306,7 +334,7 @@ oc_connectivity_init(void)
sin.msin6_family = MN_AF_INET6;
sin.msin6_port = 0;
sin.msin6_flowinfo = 0;
- memcpy(sin.msin6_addr,nm_in6addr_any, sizeof(sin.msin6_addr));
+ memcpy(&sin.msin6_addr, nm_in6addr_any, sizeof(sin.msin6_addr));
rc = mn_bind(ucast, (struct mn_sockaddr *)&sin);
if (rc != 0) {
@@ -315,13 +343,21 @@ oc_connectivity_init(void)
goto oc_connectivity_init_err;
}
- rc = mn_inet_pton(MN_AF_INET6, ALL_COAP_NODES_V6, mcast_addr);
- if (rc != 0) {
- goto oc_connectivity_init_err;
- }
+ /* Set socket option to join multicast group */
+ {
+ struct mn_mreq join;
- /* TODO --set socket option to join multicast group */
+ join.mm_addr.v6 = coap_all_nodes_v6;
+ join.mm_idx = 1;
+ join.mm_family = MN_AF_INET6;
+ rc = mn_setsockopt(mcast, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &join);
+ if (rc != 0) {
+ goto oc_connectivity_init_err;
+ }
+ }
+
+#if 0
int reuse = 1;
rc = mn_setsockopt(mcast, MN_SOL_SOCKET, MN_SO_REUSEADDR, &reuse);
if (rc != 0) {
@@ -332,6 +368,7 @@ oc_connectivity_init(void)
if (rc != 0) {
goto oc_connectivity_init_err;
}
+#endif
sin.msin6_port = htons(COAP_PORT_UNSECURED);
rc = mn_bind(mcast, (struct mn_sockaddr *)&sin);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/port/oc_assert.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/oc_assert.h b/libs/iotivity/src/port/oc_assert.h
index a3323cf..069866b 100644
--- a/libs/iotivity/src/port/oc_assert.h
+++ b/libs/iotivity/src/port/oc_assert.h
@@ -17,7 +17,7 @@
#ifndef OC_ASSERT_H
#define OC_ASSERT_H
-#include "port/oc_log.h"
+#include "oc_log.h"
#ifdef __linux__
#include <stdlib.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/port/oc_clock.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/oc_clock.h b/libs/iotivity/src/port/oc_clock.h
index e012bb5..8c958a9 100644
--- a/libs/iotivity/src/port/oc_clock.h
+++ b/libs/iotivity/src/port/oc_clock.h
@@ -50,7 +50,7 @@
#ifndef OC_CLOCK_H
#define OC_CLOCK_H
-#include "config.h"
+#include "mynewt/config.h"
#include <stdint.h>
/**
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/oc_connectivity.h b/libs/iotivity/src/port/oc_connectivity.h
index 1c36171..b004cea 100644
--- a/libs/iotivity/src/port/oc_connectivity.h
+++ b/libs/iotivity/src/port/oc_connectivity.h
@@ -17,10 +17,10 @@
#ifndef OC_CONNECTIVITY_H
#define OC_CONNECTIVITY_H
-#include "config.h"
-#include "oc_network_events.h"
-#include "port/oc_log.h"
-#include "util/oc_process.h"
+#include "mynewt/config.h"
+#include "../../include/iotivity/oc_network_events.h"
+#include "oc_log.h"
+#include "../util/oc_process.h"
#include <stdint.h>
typedef struct
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/util/oc_process.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/util/oc_process.h b/libs/iotivity/src/util/oc_process.h
index a4944b3..27179d7 100644
--- a/libs/iotivity/src/util/oc_process.h
+++ b/libs/iotivity/src/util/oc_process.h
@@ -42,7 +42,7 @@
#ifndef OC_PROCESS_H
#define OC_PROCESS_H
-#include "util/pt/pt.h"
+#include "pt/pt.h"
#ifndef NULL
#define NULL 0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d27f1f30/libs/iotivity/src/util/oc_timer.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/util/oc_timer.h b/libs/iotivity/src/util/oc_timer.h
index 9769dc8..bff0a49 100644
--- a/libs/iotivity/src/util/oc_timer.h
+++ b/libs/iotivity/src/util/oc_timer.h
@@ -63,7 +63,7 @@
#ifndef OC_TIMER_H
#define OC_TIMER_H
-#include "port/oc_clock.h"
+#include "../port/oc_clock.h"
/**
* A timer.