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/14 23:42:32 UTC

[1/3] incubator-mynewt-core git commit: add an untested socket interface for the ocf stack

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 3204c603b -> 1cb7f3577


add an untested socket interface for the ocf stack


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/1cb7f357
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1cb7f357
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1cb7f357

Branch: refs/heads/develop
Commit: 1cb7f35772158a7376d9ab1236c16809939eb817
Parents: 23b0a5a
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Wed Sep 14 16:42:04 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Wed Sep 14 16:42:22 2016 -0700

----------------------------------------------------------------------
 libs/iotivity/pkg.yml                       |   2 +
 libs/iotivity/src/port/mynewt/ip_adaptor.c  | 323 ++++++++++++++++++++++-
 sys/log/include/log/log.h                   |   2 +
 sys/mn_socket/include/mn_socket/mn_socket.h |   2 +
 4 files changed, 319 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1cb7f357/libs/iotivity/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/iotivity/pkg.yml b/libs/iotivity/pkg.yml
index f8f9f03..c4bf8b2 100644
--- a/libs/iotivity/pkg.yml
+++ b/libs/iotivity/pkg.yml
@@ -26,6 +26,8 @@ pkg.keywords:
 pkg.deps:
     - "@apache-mynewt-core/libs/tinycbor"
     - "@apache-mynewt-core/libs/os"
+    - "@apache-mynewt-core/sys/mn_socket"
+    - "@apache-mynewt-core/sys/log"
 
 pkg.cflags: -DDEBUG=1
         -DSECURE=0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1cb7f357/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 b32fc39..11a7981 100644
--- a/libs/iotivity/src/port/mynewt/ip_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ip_adaptor.c
@@ -17,40 +17,343 @@
  * under the License.
  */
 
+#include <assert.h>
+#include <os/os.h>
+#include <os/endian.h>
+#include <string.h>
+#include <log/log.h>
+#include <mn_socket/mn_socket.h>
+
 #include "../oc_network_events_mutex.h"
 #include "../oc_connectivity.h"
+#include "oc_buffer.h"
+
+#ifdef OC_SECURITY
+#error This implementation does not yet support security
+#endif
+
+#define COAP_PORT_UNSECURED (5683)
+#define ALL_COAP_NODES_V6 "FF02::FD"
+
+/* TODO these should be defined elsewhere but they are here as stubs */
+#define MN_SOL_SOCKET (0)
+#define MN_SO_REUSEPORT (1)
+#define MN_SO_REUSEADDR (2)
+
+/* need a task to process OCF messages */
+#define OC_NET_TASK_STACK_SIZE          OS_STACK_ALIGN(300)
+#define OC_NET_TASK_PRIORITY            (4)
+struct os_task oc_task;
+os_stack_t *oc_stack;
+
+/* sockets to use for coap unicast and multicast */
+struct mn_socket *mcast;
+struct mn_socket *ucast;
+
+/* to wake our task when stuff is ready */
+struct os_sem oc_read_sem;
+struct os_sem oc_write_sem;
 
-void oc_network_event_handler_mutex_init(void)
+/* logging data for this module. TODO, the application should
+ * define the logging strategy for this module */
+#define MAX_CBMEM_BUF   (600)
+static uint32_t *cbmem_buf;
+static struct cbmem cbmem;
+static struct log oc_log;
+
+/* not sure if these semaphores are necessary yet.  If we are running
+ * all of this from one task, we may not need these */
+static struct os_mutex oc_net_mutex;
+
+void
+oc_network_event_handler_mutex_init(void)
 {
+    os_error_t rc;
+    rc = os_mutex_init(&oc_net_mutex);
+    assert(rc == 0);
 }
 
-void oc_network_event_handler_mutex_lock(void)
+void
+oc_network_event_handler_mutex_lock(void)
 {
+    os_mutex_pend(&oc_net_mutex, OS_TIMEOUT_NEVER);
 }
 
-void oc_network_event_handler_mutex_unlock(void)
+void
+oc_network_event_handler_mutex_unlock(void)
 {
+    os_mutex_release(&oc_net_mutex);
 }
 
-void oc_send_buffer(oc_message_t *message)
+void
+oc_send_buffer(oc_message_t *message)
 {
+    struct mn_sockaddr_in6 to;
+    struct mn_socket * send_sock;
+    struct os_mbuf m;
+    int rc;
+
+    while (1) {
+        LOG_INFO(&oc_log, LOG_MODULE_DEFAULT,
+                 "attempt send buffer %u\n", message->length);
+
+        to.msin6_len = sizeof(to);
+        to.msin6_family = MN_AF_INET6;
+        to.msin6_port = htons(message->endpoint.ipv6_addr.port);
+        memcpy(to.msin6_addr, message->endpoint.ipv6_addr.address,
+               sizeof(to.msin6_addr));
+        send_sock = ucast;
+
+        /* put on an mbuf header to make the socket happy */
+        memset(&m,0, sizeof(m));
+        m.om_data = message->data;
+        m.om_len = message->length;
+
+        rc = mn_sendto(send_sock, &m, (struct mn_sockaddr *) &to);
+        /* TODO what to do if this fails, we can't keep the buffer */
+        if (rc != 0) {
+            LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                      "Failed sending buffer %u\n", message->length);
+        } else {
+            break;
+        }
+        /* if we failed to write, wait around until we can */
+        os_sem_pend(&oc_write_sem, OS_TIMEOUT_NEVER);
+    }
 }
 
-#ifdef OC_SECURITY
-uint16_t oc_connectivity_get_dtls_port(void)
+oc_message_t *
+oc_attempt_rx(struct mn_socket * rxsock) {
+    int rc;
+    struct os_mbuf *m;
+    struct os_mbuf_pkthdr *pkt;
+    oc_message_t *message;
+    struct mn_sockaddr_in6 from;
+
+    LOG_DEBUG(&oc_log, LOG_MODULE_DEFAULT, "attempt rx from %u\n", rxsock);
+
+    rc= mn_recvfrom(rxsock, &m, (struct mn_sockaddr *) &from);
+
+    if ( rc != 0) {
+        return NULL;
+    }
+
+    if(!OS_MBUF_IS_PKTHDR(m)) {
+        return NULL;
+    }
+
+    pkt = OS_MBUF_PKTHDR(m);
+
+    message = oc_allocate_message();
+    if (NULL != message) {
+        /* TODO log an error that we dropped a frame */
+        return NULL;
+    }
+
+    if (pkt->omp_len > message->length) {
+        /* TODO what do we do with this */
+        free(message);
+        return NULL;
+    }
+    /* 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;
+    }
+
+    message->endpoint.flags = IP;
+    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.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;
+}
+
+static void oc_socks_readable(void *cb_arg, int err);
+static void oc_socks_writable(void *cb_arg, int err);
+
+union mn_socket_cb oc_sock_cbs = {
+    .socket.readable = oc_socks_readable,
+    .socket.writable = oc_socks_writable
+};
+
+void
+oc_socks_readable(void *cb_arg, int err)
+{
+    os_sem_release(&oc_read_sem);
+}
+
+void
+oc_socks_writable(void *cb_arg, int err)
 {
+    os_sem_release(&oc_write_sem);
+}
+
+
+void
+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);
+        if (pmsg) {
+            oc_network_event(pmsg);
+        }
+
+        pmsg = oc_attempt_rx(mcast);
+        if (pmsg) {
+            oc_network_event(pmsg);
+        }
+    }
+}
+
+static int
+oc_init_net_task(void) {
+    int rc;
+
+    /* start this thing running to check right away */
+    rc = os_sem_init(&oc_read_sem, 1);
+    if (0 != rc) {
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                  "Could not initialize oc read sem\n");
+        return rc;
+    }
+
+    rc = os_sem_init(&oc_write_sem, 1);
+    if (0 != rc) {
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                  "Could not initialize oc write sem\n");
+        return rc;
+    }
+
+    oc_stack = (os_stack_t*) malloc(sizeof(os_stack_t)*OC_NET_TASK_STACK_SIZE);
+    if (NULL == oc_stack) {
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                  "Could not malloc oc stack\n");
+        return -1;
+    }
+
+    rc = os_task_init(&oc_task, "oc", oc_task_handler, NULL,
+            OC_NET_TASK_PRIORITY, OS_WAIT_FOREVER,
+            oc_stack, OC_NET_TASK_STACK_SIZE);
+
+    if (rc != 0) {
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT, "Could not start oc task\n");
+        free(oc_stack);
+    }
+
+    return rc;
 }
-#endif /* OC_SECURITY */
 
-int oc_connectivity_init(void)
+void
+oc_connectivity_shutdown(void)
 {
-    return -1;
+    LOG_INFO(&oc_log, LOG_MODULE_DEFAULT, "OC shutdown");
+
+    if (ucast) {
+        mn_close(ucast);
+    }
+
+    if (mcast) {
+        mn_close(mcast);
+    }
 }
 
-void oc_connectivity_shutdown(void)
+
+int
+oc_connectivity_init(void)
 {
+    int rc;
+    struct mn_sockaddr_in6 sin;
+    uint32_t mcast_addr[4];
+
+    log_init();
+
+    cbmem_buf = malloc(sizeof(uint32_t) * MAX_CBMEM_BUF);
+    if(cbmem_buf == NULL) {
+        return -1;
+    }
+
+    cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
+    log_register("iot", &oc_log, &log_cbmem_handler, &cbmem);
+
+    LOG_INFO(&oc_log, LOG_MODULE_DEFAULT, "OC Init");
+
+    rc = mn_socket(&ucast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    if( !ucast || !rc) {
+        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) {
+        mn_close(ucast);
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                  "Could not create oc multicast socket\n");
+        return rc;
+    }
+    mn_socket_set_cbs(ucast, ucast, &oc_sock_cbs);
+    mn_socket_set_cbs(mcast, mcast, &oc_sock_cbs);
+
+    sin.msin6_len = sizeof(sin);
+    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));
+
+    rc = mn_bind(ucast, (struct mn_sockaddr *)&sin);
+    if (rc != 0) {
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                  "Could not bind oc unicast socket\n");
+        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;
+    }
+
+    /* TODO --set socket option to join multicast group */
+
+    int reuse = 1;
+    rc = mn_setsockopt(mcast, MN_SOL_SOCKET, MN_SO_REUSEADDR, &reuse);
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+
+    rc = mn_setsockopt(mcast, MN_SOL_SOCKET, MN_SO_REUSEPORT, &reuse);
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+
+    sin.msin6_port = htons(COAP_PORT_UNSECURED);
+    rc = mn_bind(mcast, (struct mn_sockaddr *)&sin);
+    if (rc != 0) {
+        LOG_ERROR(&oc_log, LOG_MODULE_DEFAULT,
+                  "Could not bind oc multicast socket\n");
+        goto oc_connectivity_init_err;
+    }
+
+    rc = oc_init_net_task();
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+
+    return 0;
+
+oc_connectivity_init_err:
+    oc_connectivity_shutdown();
+    return rc;
 }
 
 void oc_send_multicast_message(oc_message_t *message)
 {
+    oc_send_buffer(message);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1cb7f357/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index a27ad6c..48c3aed 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -97,6 +97,7 @@ struct log_entry_hdr {
 #define LOG_MODULE_NIMBLE_HOST      (4)
 #define LOG_MODULE_NFFS             (5)
 #define LOG_MODULE_REBOOT           (6)
+#define LOG_MODULE_IOTIVITY         (7)
 #define LOG_MODULE_PERUSER          (64)
 #define LOG_MODULE_MAX              (255)
 
@@ -108,6 +109,7 @@ struct log_entry_hdr {
     (LOG_MODULE_NIMBLE_HOST == module ? "NIMBLE_HOST" :\
     (LOG_MODULE_NFFS        == module ? "NFFS"        :\
     (LOG_MODULE_REBOOT      == module ? "REBOOT"      :\
+    (LOG_MODULE_IOTIVITY    == module ? "IOTIVITY"    :\
      "UNKNOWN")))))))
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1cb7f357/sys/mn_socket/include/mn_socket/mn_socket.h
----------------------------------------------------------------------
diff --git a/sys/mn_socket/include/mn_socket/mn_socket.h b/sys/mn_socket/include/mn_socket/mn_socket.h
index a852dcb..ff4839f 100644
--- a/sys/mn_socket/include/mn_socket/mn_socket.h
+++ b/sys/mn_socket/include/mn_socket/mn_socket.h
@@ -106,6 +106,8 @@ struct mn_sockaddr_in6 {
     uint32_t msin6_addr[4];
 };
 
+const uint32_t nm_in6addr_any[4] = {0,0,0,0};
+
 /*
  * Socket calls.
  *


[3/3] incubator-mynewt-core git commit: add stubs for mynewt implememtations for iotivity

Posted by pa...@apache.org.
add stubs for mynewt implememtations for iotivity

abort,clock, random are complete but untested
storage -- stub that we probably won't need until we turn on security
oc_loop, ip_adator -- need to fill these out with mynewt content


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/aa0f2596
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/aa0f2596
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/aa0f2596

Branch: refs/heads/develop
Commit: aa0f2596fb9d9cd959fe27abbc0af3d984228d55
Parents: 3204c60
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Wed Sep 14 13:58:36 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Wed Sep 14 16:42:22 2016 -0700

----------------------------------------------------------------------
 libs/iotivity/src/messaging/coap/transactions.c | 4 ++--
 libs/iotivity/src/port/mynewt/config.h          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aa0f2596/libs/iotivity/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/transactions.c b/libs/iotivity/src/messaging/coap/transactions.c
index facd95f..e52362a 100644
--- a/libs/iotivity/src/messaging/coap/transactions.c
+++ b/libs/iotivity/src/messaging/coap/transactions.c
@@ -112,10 +112,10 @@ coap_send_transaction(coap_transaction_t *t)
           COAP_RESPONSE_TIMEOUT_TICKS +
           (oc_random_rand() %
            (oc_clock_time_t)COAP_RESPONSE_TIMEOUT_BACKOFF_MASK);
-        LOG("Initial interval %llu\n", t->retrans_timer.timer.interval);
+        LOG("Initial interval %lu\n", t->retrans_timer.timer.interval);
       } else {
         t->retrans_timer.timer.interval <<= 1; /* double */
-        LOG("Doubled %llu\n", t->retrans_timer.timer.interval);
+        LOG("Doubled %lu\n", t->retrans_timer.timer.interval);
       }
 
       OC_PROCESS_CONTEXT_BEGIN(transaction_handler_process);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aa0f2596/libs/iotivity/src/port/mynewt/config.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/config.h b/libs/iotivity/src/port/mynewt/config.h
index 803a99d..673ec1c 100644
--- a/libs/iotivity/src/port/mynewt/config.h
+++ b/libs/iotivity/src/port/mynewt/config.h
@@ -6,7 +6,7 @@
 #include <stdint.h>
 #include <os/os.h>
 
-typedef uint64_t oc_clock_time_t;
+typedef os_time_t oc_clock_time_t;
 #define OC_CLOCK_CONF_TICKS_PER_SECOND (OS_TICKS_PER_SEC)
 
 /* Memory pool sizes */


[2/3] incubator-mynewt-core git commit: add stubs for mynewt

Posted by pa...@apache.org.
add stubs for mynewt

abort, clock, random are implemented but untested
storage -- we will probbably not need until we do security
loop, ip are still TBD


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/23b0a5ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/23b0a5ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/23b0a5ac

Branch: refs/heads/develop
Commit: 23b0a5ac4d5632cecdb77b9e08edae6a10e69e6c
Parents: aa0f259
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Wed Sep 14 14:04:07 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Wed Sep 14 16:42:22 2016 -0700

----------------------------------------------------------------------
 libs/iotivity/src/messaging/coap/transactions.c |  4 +-
 libs/iotivity/src/port/mynewt/abort.c           | 25 +++++++++
 libs/iotivity/src/port/mynewt/clock.c           | 41 ++++++++++++++
 libs/iotivity/src/port/mynewt/config.h          |  5 ++
 libs/iotivity/src/port/mynewt/ip_adaptor.c      | 56 ++++++++++++++++++++
 libs/iotivity/src/port/mynewt/oc_loop.c         | 26 +++++++++
 libs/iotivity/src/port/mynewt/random.c          | 31 +++++++++++
 libs/iotivity/src/port/mynewt/storage.c         | 38 +++++++++++++
 8 files changed, 224 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/messaging/coap/transactions.c b/libs/iotivity/src/messaging/coap/transactions.c
index e52362a..8feaa7c 100644
--- a/libs/iotivity/src/messaging/coap/transactions.c
+++ b/libs/iotivity/src/messaging/coap/transactions.c
@@ -112,10 +112,10 @@ coap_send_transaction(coap_transaction_t *t)
           COAP_RESPONSE_TIMEOUT_TICKS +
           (oc_random_rand() %
            (oc_clock_time_t)COAP_RESPONSE_TIMEOUT_BACKOFF_MASK);
-        LOG("Initial interval %lu\n", t->retrans_timer.timer.interval);
+        LOG("Initial interval " OC_CLK_FMT "\n", t->retrans_timer.timer.interval);
       } else {
         t->retrans_timer.timer.interval <<= 1; /* double */
-        LOG("Doubled %lu\n", t->retrans_timer.timer.interval);
+        LOG("Doubled " OC_CLK_FMT "\n", t->retrans_timer.timer.interval);
       }
 
       OC_PROCESS_CONTEXT_BEGIN(transaction_handler_process);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/port/mynewt/abort.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/abort.c b/libs/iotivity/src/port/mynewt/abort.c
new file mode 100644
index 0000000..0ca5329
--- /dev/null
+++ b/libs/iotivity/src/port/mynewt/abort.c
@@ -0,0 +1,25 @@
+/**
+ * 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 "../oc_assert.h"
+#include <assert.h>
+
+void abort_impl(void) {
+    assert(0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/port/mynewt/clock.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/clock.c b/libs/iotivity/src/port/mynewt/clock.c
new file mode 100644
index 0000000..51def9a
--- /dev/null
+++ b/libs/iotivity/src/port/mynewt/clock.c
@@ -0,0 +1,41 @@
+/**
+ * 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 <stdint.h>
+#include <os/os.h>
+#include "../oc_clock.h"
+
+void oc_clock_init(void)
+{
+    /* in mynewt clock is initialized elsewhere */
+}
+oc_clock_time_t oc_clock_time(void)
+{
+    return os_time_get();
+}
+
+unsigned long oc_clock_seconds(void)
+{
+    return os_time_get()/OS_TICKS_PER_SEC;
+}
+
+void oc_clock_wait(oc_clock_time_t t)
+{
+    os_time_delay(t);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/port/mynewt/config.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/config.h b/libs/iotivity/src/port/mynewt/config.h
index 673ec1c..1889a70 100644
--- a/libs/iotivity/src/port/mynewt/config.h
+++ b/libs/iotivity/src/port/mynewt/config.h
@@ -8,6 +8,11 @@
 
 typedef os_time_t oc_clock_time_t;
 #define OC_CLOCK_CONF_TICKS_PER_SECOND (OS_TICKS_PER_SEC)
+#ifdef ARCH_sim
+#define OC_CLK_FMT  "%u"
+#else
+#define OC_CLK_FMT  "%lu"
+#endif
 
 /* Memory pool sizes */
 #define OC_BYTES_POOL_SIZE (2048)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/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
new file mode 100644
index 0000000..b32fc39
--- /dev/null
+++ b/libs/iotivity/src/port/mynewt/ip_adaptor.c
@@ -0,0 +1,56 @@
+/**
+ * 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 "../oc_network_events_mutex.h"
+#include "../oc_connectivity.h"
+
+void oc_network_event_handler_mutex_init(void)
+{
+}
+
+void oc_network_event_handler_mutex_lock(void)
+{
+}
+
+void oc_network_event_handler_mutex_unlock(void)
+{
+}
+
+void oc_send_buffer(oc_message_t *message)
+{
+}
+
+#ifdef OC_SECURITY
+uint16_t oc_connectivity_get_dtls_port(void)
+{
+}
+#endif /* OC_SECURITY */
+
+int oc_connectivity_init(void)
+{
+    return -1;
+}
+
+void oc_connectivity_shutdown(void)
+{
+}
+
+void oc_send_multicast_message(oc_message_t *message)
+{
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/port/mynewt/oc_loop.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/oc_loop.c b/libs/iotivity/src/port/mynewt/oc_loop.c
new file mode 100644
index 0000000..ca91812
--- /dev/null
+++ b/libs/iotivity/src/port/mynewt/oc_loop.c
@@ -0,0 +1,26 @@
+/**
+ * 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 "../oc_signal_main_loop.h"
+
+
+void oc_signal_main_loop(void)
+{
+    /* TODO */
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/port/mynewt/random.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/random.c b/libs/iotivity/src/port/mynewt/random.c
new file mode 100644
index 0000000..0fcddfb
--- /dev/null
+++ b/libs/iotivity/src/port/mynewt/random.c
@@ -0,0 +1,31 @@
+/**
+ * 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 "../oc_random.h"
+#include <stdlib.h>
+
+void oc_random_init(unsigned short seed) {
+    srand(seed);
+}
+
+unsigned short oc_random_rand(void) {
+    return rand();
+}
+
+void oc_random_destroy(void) {
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23b0a5ac/libs/iotivity/src/port/mynewt/storage.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/storage.c b/libs/iotivity/src/port/mynewt/storage.c
new file mode 100644
index 0000000..3b77c1a
--- /dev/null
+++ b/libs/iotivity/src/port/mynewt/storage.c
@@ -0,0 +1,38 @@
+/**
+ * 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 <stddef.h>
+#include <stdint.h>
+
+/* we will not really use storage until after we get security working */
+int oc_storage_config(const char *store) {
+    return -1;
+}
+
+long oc_storage_read(const char *store, uint8_t *buf, size_t size)
+{
+    return -1;
+}
+
+
+long oc_storage_write(const char *store, uint8_t *buf, size_t size)
+{
+    return -1;
+}