You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/10/04 19:03:56 UTC

[04/13] incubator-mynewt-core git commit: move libs/iotivity -> net/oic.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
new file mode 100644
index 0000000..4bd1d96
--- /dev/null
+++ b/net/oic/src/messaging/coap/observe.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ */
+
+#include "config.h"
+
+#ifdef OC_SERVER
+
+#include "observe.h"
+#include "util/oc_memb.h"
+#include <stdio.h>
+#include <string.h>
+
+#include "oc_coap.h"
+#include "oc_rep.h"
+#include "oc_ri.h"
+/*-------------------*/
+uint64_t observe_counter = 3;
+/*---------------------------------------------------------------------------*/
+OC_LIST(observers_list);
+OC_MEMB(observers_memb, coap_observer_t, COAP_MAX_OBSERVERS);
+
+/*---------------------------------------------------------------------------*/
+/*- Internal API ------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+static int
+add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
+             const uint8_t *token, size_t token_len, const char *uri,
+             int uri_len)
+{
+  /* Remove existing observe relationship, if any. */
+  int dup = coap_remove_observer_by_uri(endpoint, uri);
+
+  coap_observer_t *o = oc_memb_alloc(&observers_memb);
+
+  if (o) {
+    int max = sizeof(o->url) - 1;
+    if (max > uri_len) {
+      max = uri_len;
+    }
+    memcpy(o->url, uri, max);
+    o->url[max] = 0;
+    memcpy(&o->endpoint, endpoint, sizeof(oc_endpoint_t));
+    o->token_len = token_len;
+    memcpy(o->token, token, token_len);
+    o->last_mid = 0;
+    o->obs_counter = observe_counter;
+    o->resource = resource;
+    resource->num_observers++;
+    LOG("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
+        oc_list_length(observers_list) + 1, COAP_MAX_OBSERVERS, o->url,
+        o->token[0], o->token[1]);
+    oc_list_add(observers_list, o);
+    return dup;
+  }
+  return -1;
+}
+/*---------------------------------------------------------------------------*/
+/*- Removal -----------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+void
+coap_remove_observer(coap_observer_t *o)
+{
+  LOG("Removing observer for /%s [0x%02X%02X]\n", o->url, o->token[0],
+      o->token[1]);
+  oc_memb_free(&observers_memb, o);
+  oc_list_remove(observers_list, o);
+}
+/*---------------------------------------------------------------------------*/
+int
+coap_remove_observer_by_client(oc_endpoint_t *endpoint)
+{
+  int removed = 0;
+  coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list), *next;
+
+  LOG("Unregistering observers for client at: ");
+  LOGipaddr(*endpoint);
+
+  while (obs) {
+    next = obs->next;
+    if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0) {
+      obs->resource->num_observers--;
+      coap_remove_observer(obs);
+      removed++;
+    }
+    obs = next;
+  }
+  LOG("Removed %d observers\n", removed);
+  return removed;
+}
+/*---------------------------------------------------------------------------*/
+int
+coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
+                              size_t token_len)
+{
+  int removed = 0;
+  coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list);
+  LOG("Unregistering observers for request token 0x%02X%02X\n", token[0],
+      token[1]);
+  while (obs) {
+    if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0 &&
+        obs->token_len == token_len &&
+        memcmp(obs->token, token, token_len) == 0) {
+      obs->resource->num_observers--;
+      coap_remove_observer(obs);
+      removed++;
+      break;
+    }
+    obs = obs->next;
+  }
+  LOG("Removed %d observers\n", removed);
+  return removed;
+}
+/*---------------------------------------------------------------------------*/
+int
+coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri)
+{
+  LOG("Unregistering observers for resource uri /%s", uri);
+  int removed = 0;
+  coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list), *next;
+
+  while (obs) {
+    next = obs->next;
+    if (((memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0)) &&
+        (obs->url == uri || memcmp(obs->url, uri, strlen(obs->url)) == 0)) {
+      obs->resource->num_observers--;
+      coap_remove_observer(obs);
+      removed++;
+    }
+    obs = next;
+  }
+  LOG("Removed %d observers\n", removed);
+  return removed;
+}
+/*---------------------------------------------------------------------------*/
+int
+coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
+{
+  int removed = 0;
+  coap_observer_t *obs = NULL;
+  LOG("Unregistering observers for request MID %u\n", mid);
+
+  for (obs = (coap_observer_t *)oc_list_head(observers_list); obs != NULL;
+       obs = obs->next) {
+    if (memcmp(&obs->endpoint, endpoint, sizeof(*endpoint)) == 0 &&
+        obs->last_mid == mid) {
+      obs->resource->num_observers--;
+      coap_remove_observer(obs);
+      removed++;
+      break;
+    }
+  }
+  LOG("Removed %d observers\n", removed);
+  return removed;
+}
+/*---------------------------------------------------------------------------*/
+/*- Notification ------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+int
+coap_notify_observers(oc_resource_t *resource,
+                      oc_response_buffer_t *response_buf,
+                      oc_endpoint_t *endpoint)
+{
+  int num_observers = 0;
+  if (resource) {
+    if (!resource->num_observers) {
+      LOG("coap_notify_observers: no observers; returning\n");
+      return 0;
+    }
+    num_observers = resource->num_observers;
+  }
+  uint8_t buffer[COAP_MAX_BLOCK_SIZE];
+  oc_request_t request = {};
+  oc_response_t response = {};
+  response.separate_response = 0;
+  oc_response_buffer_t response_buffer;
+  if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
+    LOG("coap_notify_observers: Issue GET request to resource\n");
+    /* performing GET on the resource */
+    response_buffer.buffer = buffer;
+    response_buffer.buffer_size = COAP_MAX_BLOCK_SIZE;
+    response_buffer.block_offset = NULL;
+    response.response_buffer = &response_buffer;
+    request.resource = resource;
+    request.response = &response;
+    request.request_payload = NULL;
+    oc_rep_new(buffer, COAP_MAX_BLOCK_SIZE);
+    resource->get_handler(&request, resource->default_interface);
+    response_buf = &response_buffer;
+    if (response_buf->code == OC_IGNORE) {
+      LOG("coap_notify_observers: Resource ignored request\n");
+      return num_observers;
+    }
+  }
+
+  coap_observer_t *obs = NULL;
+  /* iterate over observers */
+  for (obs = (coap_observer_t *)oc_list_head(observers_list);
+       obs && ((resource && obs->resource == resource) ||
+               (endpoint &&
+                memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0));
+       obs = obs->next) {
+    num_observers = obs->resource->num_observers;
+    if (response.separate_response != NULL &&
+        response_buf->code == oc_status_code(OC_STATUS_OK)) {
+      coap_packet_t req[1];
+      /*
+  req->block1_num = 0;
+  req->block1_size = 0;
+  req->block2_num = 0;
+  req->block2_size = 0;
+      */
+      coap_init_message(req, COAP_TYPE_NON, CONTENT_2_05, 0);
+      memcpy(req->token, obs->token, obs->token_len);
+      req->token_len = obs->token_len;
+      LOG("Resource is SLOW; creating separate response\n");
+      if (coap_separate_accept(req, response.separate_response, &obs->endpoint,
+                               0) == 1)
+        response.separate_response->active = 1;
+    } else {
+      LOG("coap_notify_observers: notifying observer\n");
+      coap_transaction_t *transaction = NULL;
+      if (response_buf && (transaction = coap_new_transaction(
+                             coap_get_mid(), &obs->endpoint))) {
+        memcpy(transaction->message->data + COAP_MAX_HEADER_SIZE,
+               response_buf->buffer, response_buf->response_length);
+
+        /* update last MID for RST matching */
+        obs->last_mid = transaction->mid;
+
+        /* prepare response */
+        /* build notification */
+        coap_packet_t notification
+          [1]; /* this way the packet can be treated as pointer as usual */
+        coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0);
+
+        notification->mid = transaction->mid;
+        if (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) {
+          LOG("coap_observe_notify: forcing CON notification to check for "
+              "client liveness\n");
+          notification->type = COAP_TYPE_CON;
+        }
+        coap_set_payload(notification, response_buf->buffer,
+                         response_buf->response_length);
+        coap_set_status_code(notification, response_buf->code);
+        if (notification->code < BAD_REQUEST_4_00 &&
+            obs->resource->num_observers) {
+          coap_set_header_observe(notification, (obs->obs_counter)++);
+          observe_counter++;
+        } else {
+          coap_set_header_observe(notification, 1);
+        }
+        coap_set_token(notification, obs->token, obs->token_len);
+
+        transaction->message->length =
+          coap_serialize_message(notification, transaction->message->data);
+
+        coap_send_transaction(transaction);
+      }
+    }
+  }
+  return num_observers;
+}
+/*---------------------------------------------------------------------------*/
+int
+coap_observe_handler(void *request, void *response, oc_resource_t *resource,
+                     oc_endpoint_t *endpoint)
+{
+  coap_packet_t *const coap_req = (coap_packet_t *)request;
+  coap_packet_t *const coap_res = (coap_packet_t *)response;
+  int dup = -1;
+  if (coap_req->code == COAP_GET &&
+      coap_res->code < 128) { /* GET request and response without error code */
+    if (IS_OPTION(coap_req, COAP_OPTION_OBSERVE)) {
+      if (coap_req->observe == 0) {
+        dup =
+          add_observer(resource, endpoint, coap_req->token, coap_req->token_len,
+                       coap_req->uri_path, coap_req->uri_path_len);
+      } else if (coap_req->observe == 1) {
+        /* remove client if it is currently observe */
+        dup = coap_remove_observer_by_token(endpoint, coap_req->token,
+                                            coap_req->token_len);
+      }
+    }
+  }
+  return dup;
+}
+/*---------------------------------------------------------------------------*/
+
+#endif /* OC_SERVER */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/observe.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.h b/net/oic/src/messaging/coap/observe.h
new file mode 100644
index 0000000..20c207e
--- /dev/null
+++ b/net/oic/src/messaging/coap/observe.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ */
+
+#ifndef OBSERVE_H
+#define OBSERVE_H
+
+#include "coap.h"
+#include "transactions.h"
+#include "../../util/oc_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* OIC stack headers */
+#include "oic/oc_ri.h"
+
+#define COAP_OBSERVER_URL_LEN 20
+
+typedef struct coap_observer
+{
+  struct coap_observer *next; /* for LIST */
+
+  oc_resource_t *resource;
+
+  char url[COAP_OBSERVER_URL_LEN];
+  oc_endpoint_t endpoint;
+  uint8_t token_len;
+  uint8_t token[COAP_TOKEN_LEN];
+  uint16_t last_mid;
+
+  int32_t obs_counter;
+
+  struct oc_etimer retrans_timer;
+  uint8_t retrans_counter;
+} coap_observer_t;
+
+oc_list_t coap_get_observers(void);
+void coap_remove_observer(coap_observer_t *o);
+int coap_remove_observer_by_client(oc_endpoint_t *endpoint);
+int coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
+                                  size_t token_len);
+int coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri);
+int coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid);
+
+int coap_notify_observers(oc_resource_t *resource,
+                          oc_response_buffer_t *response_buf,
+                          oc_endpoint_t *endpoint);
+// int coap_notify_observers_sub(oc_resource_t *resource, const char *subpath);
+
+int coap_observe_handler(void *request, void *response, oc_resource_t *resource,
+                         oc_endpoint_t *endpoint);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OBSERVE_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/oc_coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/oc_coap.h b/net/oic/src/messaging/coap/oc_coap.h
new file mode 100644
index 0000000..a94b926
--- /dev/null
+++ b/net/oic/src/messaging/coap/oc_coap.h
@@ -0,0 +1,47 @@
+/*
+// 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.
+*/
+
+#ifndef OC_COAP_H
+#define OC_COAP_H
+
+#include "separate.h"
+#include "../../util/oc_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct oc_separate_response_s
+{
+  OC_LIST_STRUCT(requests);
+  int active;
+  uint8_t buffer[COAP_MAX_BLOCK_SIZE];
+} oc_separate_response_t;
+
+typedef struct oc_response_buffer_s
+{
+  uint8_t *buffer;
+  uint16_t buffer_size;
+  int32_t *block_offset;
+  uint16_t response_length;
+  int code;
+} oc_response_buffer_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OC_COAP_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
new file mode 100644
index 0000000..5be01e7
--- /dev/null
+++ b/net/oic/src/messaging/coap/separate.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ */
+
+#include "config.h"
+
+#ifdef OC_SERVER
+
+#include "oc_buffer.h"
+#include "separate.h"
+#include "transactions.h"
+#include "util/oc_memb.h"
+#include <stdio.h>
+#include <string.h>
+
+OC_MEMB(separate_requests, coap_separate_t, MAX_NUM_CONCURRENT_REQUESTS);
+
+/*---------------------------------------------------------------------------*/
+/*- Separate Response API ---------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+/**
+ * \brief Initiate a separate response with an empty ACK
+ * \param request The request to accept
+ * \param separate_store A pointer to the data structure that will store the
+ *   relevant information for the response
+ *
+ * When the server does not have enough resources left to store the information
+ * for a separate response or otherwise cannot execute the resource handler,
+ * this function will respond with 5.03 Service Unavailable. The client can
+ * then retry later.
+ */
+int
+coap_separate_accept(void *request, oc_separate_response_t *separate_response,
+                     oc_endpoint_t *endpoint, int observe)
+{
+  if (separate_response->active == 0) {
+    OC_LIST_STRUCT_INIT(separate_response, requests);
+  }
+
+  coap_packet_t *const coap_req = (coap_packet_t *)request;
+
+  for (coap_separate_t *item = oc_list_head(separate_response->requests);
+       item != NULL; item = oc_list_item_next(separate_response->requests)) {
+    if (item->token_len == coap_req->token_len &&
+        memcmp(item->token, coap_req->token, item->token_len) == 0) {
+      return 0;
+    }
+  }
+
+  coap_separate_t *separate_store = oc_memb_alloc(&separate_requests);
+
+  if (!separate_store)
+    return 0;
+
+  oc_list_add(separate_response->requests, separate_store);
+
+  erbium_status_code = CLEAR_TRANSACTION;
+  /* send separate ACK for CON */
+  if (coap_req->type == COAP_TYPE_CON) {
+    LOG("Sending ACK for separate response\n");
+    coap_packet_t ack[1];
+    /* ACK with empty code (0) */
+    coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);
+    if (observe < 2) {
+      coap_set_header_observe(ack, observe);
+    }
+    coap_set_token(ack, coap_req->token, coap_req->token_len);
+    oc_message_t *message = oc_allocate_message();
+    if (message != NULL) {
+      message->endpoint.flags = IP;
+      memcpy(&message->endpoint, endpoint, sizeof(oc_endpoint_t));
+      message->length = coap_serialize_message(ack, message->data);
+      coap_send_message(message);
+    } else {
+      coap_separate_clear(separate_response, separate_store);
+      erbium_status_code = SERVICE_UNAVAILABLE_5_03;
+      return 0;
+    }
+  }
+  memcpy(&separate_store->endpoint, endpoint, sizeof(oc_endpoint_t));
+
+  /* store correct response type */
+  separate_store->type = COAP_TYPE_NON;
+
+  memcpy(separate_store->token, coap_req->token, coap_req->token_len);
+  separate_store->token_len = coap_req->token_len;
+
+  separate_store->block1_num = coap_req->block1_num;
+  separate_store->block1_size = coap_req->block1_size;
+
+  separate_store->block2_num = coap_req->block2_num;
+  separate_store->block2_size =
+    coap_req->block2_size > 0 ? MIN(COAP_MAX_BLOCK_SIZE, coap_req->block2_size)
+                              : COAP_MAX_BLOCK_SIZE;
+
+  separate_store->observe = observe;
+  return 1;
+}
+/*----------------------------------------------------------------------------*/
+void
+coap_separate_resume(void *response, coap_separate_t *separate_store,
+                     uint8_t code, uint16_t mid)
+{
+  coap_init_message(response, separate_store->type, code, mid);
+  if (separate_store->token_len) {
+    coap_set_token(response, separate_store->token, separate_store->token_len);
+  }
+  if (separate_store->block1_size) {
+    coap_set_header_block1(response, separate_store->block1_num, 0,
+                           separate_store->block1_size);
+  }
+}
+/*---------------------------------------------------------------------------*/
+void
+coap_separate_clear(oc_separate_response_t *separate_response,
+                    coap_separate_t *separate_store)
+{
+  oc_list_remove(separate_response->requests, separate_store);
+  oc_memb_free(&separate_requests, separate_store);
+}
+
+#endif /* OC_SERVER */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/separate.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.h b/net/oic/src/messaging/coap/separate.h
new file mode 100644
index 0000000..7f32da1
--- /dev/null
+++ b/net/oic/src/messaging/coap/separate.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ */
+
+#ifndef SEPARATE_H
+#define SEPARATE_H
+
+#include "coap.h"
+#include "transactions.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* OIC stack headers */
+#include "oc_coap.h"
+#include "oic/oc_ri.h"
+
+typedef struct coap_separate
+{
+  struct coap_separate *next;
+  coap_message_type_t type;
+
+  uint8_t token_len;
+  uint8_t token[COAP_TOKEN_LEN];
+
+  uint32_t block1_num;
+  uint16_t block1_size;
+
+  uint32_t block2_num;
+  uint16_t block2_size;
+
+  int32_t observe;
+
+  oc_endpoint_t endpoint;
+} coap_separate_t;
+
+int coap_separate_accept(void *request,
+                         oc_separate_response_t *separate_response,
+                         oc_endpoint_t *endpoint, int observe);
+void coap_separate_resume(void *response, coap_separate_t *separate_store,
+                          uint8_t code, uint16_t mid);
+void coap_separate_clear(oc_separate_response_t *separate_response,
+                         coap_separate_t *separate_store);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SEPARATE_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
new file mode 100644
index 0000000..8feaa7c
--- /dev/null
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ */
+
+#include "transactions.h"
+#include "observe.h"
+#include "oc_buffer.h"
+#include "util/oc_list.h"
+#include "util/oc_memb.h"
+#include <string.h>
+
+#ifdef OC_CLIENT
+#include "oc_client_state.h"
+#endif /* OC_CLIENT */
+
+#ifdef OC_SECURITY
+#include "security/oc_dtls.h"
+#endif
+
+/*---------------------------------------------------------------------------*/
+OC_MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS);
+OC_LIST(transactions_list);
+
+static struct oc_process *transaction_handler_process = NULL;
+
+/*---------------------------------------------------------------------------*/
+/*- Internal API ------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+void
+coap_register_as_transaction_handler()
+{
+  transaction_handler_process = OC_PROCESS_CURRENT();
+}
+
+coap_transaction_t *
+coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
+{
+  coap_transaction_t *t = oc_memb_alloc(&transactions_memb);
+  if (t) {
+    oc_message_t *message = oc_allocate_message();
+    if (message) {
+      LOG("Created new transaction %d %d\n", mid, (int) message->length);
+      t->mid = mid;
+      t->retrans_counter = 0;
+
+      t->message = message;
+
+      /* save client address */
+      memcpy(&t->message->endpoint, endpoint, sizeof(oc_endpoint_t));
+
+      oc_list_add(
+        transactions_list,
+        t); /* list itself makes sure same element is not added twice */
+    } else {
+      oc_memb_free(&transactions_memb, t);
+      t = NULL;
+    }
+  }
+
+  return t;
+}
+
+/*---------------------------------------------------------------------------*/
+void
+coap_send_transaction(coap_transaction_t *t)
+{
+  LOG("Sending transaction %u\n", t->mid);
+  bool confirmable = false;
+
+  confirmable =
+    (COAP_TYPE_CON == ((COAP_HEADER_TYPE_MASK & t->message->data[0]) >>
+                       COAP_HEADER_TYPE_POSITION))
+      ? true
+      : false;
+
+  if (confirmable) {
+    if (t->retrans_counter < COAP_MAX_RETRANSMIT) {
+      /* not timed out yet */
+      LOG("Keeping transaction %u\n", t->mid);
+
+      if (t->retrans_counter == 0) {
+        t->retrans_timer.timer.interval =
+          COAP_RESPONSE_TIMEOUT_TICKS +
+          (oc_random_rand() %
+           (oc_clock_time_t)COAP_RESPONSE_TIMEOUT_BACKOFF_MASK);
+        LOG("Initial interval " OC_CLK_FMT "\n", t->retrans_timer.timer.interval);
+      } else {
+        t->retrans_timer.timer.interval <<= 1; /* double */
+        LOG("Doubled " OC_CLK_FMT "\n", t->retrans_timer.timer.interval);
+      }
+
+      OC_PROCESS_CONTEXT_BEGIN(transaction_handler_process);
+      oc_etimer_restart(&t->retrans_timer); /* interval updated above */
+      OC_PROCESS_CONTEXT_END(transaction_handler_process);
+
+      coap_send_message(t->message);
+
+      oc_message_add_ref(t->message);
+
+      t = NULL;
+    } else {
+      /* timed out */
+      LOG("Timeout\n");
+
+#ifdef OC_SERVER
+      LOG("timeout.. so removing observers\n");
+      /* handle observers */
+      coap_remove_observer_by_client(&t->message->endpoint);
+#endif /* OC_SERVER */
+
+#ifdef OC_SECURITY
+      if (t->message->endpoint.flags & SECURED) {
+        oc_sec_dtls_close_init(&t->message->endpoint);
+      }
+#endif /* OC_SECURITY */
+
+#ifdef OC_CLIENT
+      oc_ri_remove_client_cb_by_mid(t->mid);
+#endif /* OC_CLIENT */
+
+      coap_clear_transaction(t);
+    }
+  } else {
+    coap_send_message(t->message);
+    oc_message_add_ref(t->message);
+
+    coap_clear_transaction(t);
+  }
+}
+/*---------------------------------------------------------------------------*/
+void
+coap_clear_transaction(coap_transaction_t *t)
+{
+  if (t) {
+    LOG("Freeing transaction %u: %p\n", t->mid, t);
+
+    oc_etimer_stop(&t->retrans_timer);
+    oc_message_unref(t->message);
+    oc_list_remove(transactions_list, t);
+    oc_memb_free(&transactions_memb, t);
+  }
+}
+coap_transaction_t *
+coap_get_transaction_by_mid(uint16_t mid)
+{
+  coap_transaction_t *t = NULL;
+
+  for (t = (coap_transaction_t *)oc_list_head(transactions_list); t;
+       t = t->next) {
+    if (t->mid == mid) {
+      LOG("Found transaction for MID %u: %p\n", t->mid, t);
+      return t;
+    }
+  }
+  return NULL;
+}
+
+/*---------------------------------------------------------------------------*/
+void
+coap_check_transactions()
+{
+  coap_transaction_t *t = NULL;
+
+  for (t = (coap_transaction_t *)oc_list_head(transactions_list); t;
+       t = t->next) {
+    if (oc_etimer_expired(&t->retrans_timer)) {
+      ++(t->retrans_counter);
+      LOG("Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
+      coap_send_transaction(t);
+    }
+  }
+}
+/*---------------------------------------------------------------------------*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/messaging/coap/transactions.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.h b/net/oic/src/messaging/coap/transactions.h
new file mode 100644
index 0000000..1bb6c33
--- /dev/null
+++ b/net/oic/src/messaging/coap/transactions.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ */
+
+#ifndef TRANSACTIONS_H
+#define TRANSACTIONS_H
+
+#include "coap.h"
+#include "../../util/oc_etimer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Modulo mask (thus +1) for a random number to get the tick number for the
+ * random
+ * retransmission time between COAP_RESPONSE_TIMEOUT and
+ * COAP_RESPONSE_TIMEOUT*COAP_RESPONSE_RANDOM_FACTOR.
+ */
+#define COAP_RESPONSE_TIMEOUT_TICKS (OC_CLOCK_SECOND * COAP_RESPONSE_TIMEOUT)
+#define COAP_RESPONSE_TIMEOUT_BACKOFF_MASK                                     \
+  (long)((OC_CLOCK_SECOND * COAP_RESPONSE_TIMEOUT *                            \
+          ((float)COAP_RESPONSE_RANDOM_FACTOR - 1.0)) +                        \
+         0.5) +                                                                \
+    1
+
+/* container for transactions with message buffer and retransmission info */
+typedef struct coap_transaction
+{
+  struct coap_transaction *next; /* for LIST */
+
+  uint16_t mid;
+  struct oc_etimer retrans_timer;
+  uint8_t retrans_counter;
+  oc_message_t *message;
+
+} coap_transaction_t;
+
+void coap_register_as_transaction_handler(void);
+
+coap_transaction_t *coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint);
+
+void coap_send_transaction(coap_transaction_t *t);
+void coap_clear_transaction(coap_transaction_t *t);
+coap_transaction_t *coap_get_transaction_by_mid(uint16_t mid);
+
+void coap_check_transactions(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TRANSACTIONS_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/abort.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/abort.c b/net/oic/src/port/mynewt/abort.c
new file mode 100644
index 0000000..0ca5329
--- /dev/null
+++ b/net/oic/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/f88168c2/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
new file mode 100644
index 0000000..9fccc88
--- /dev/null
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -0,0 +1,231 @@
+/**
+ * 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 <syscfg/syscfg.h>
+#include <os/os.h>
+#include <os/endian.h>
+#include <string.h>
+#include <log/log.h>
+#include "../oc_network_events_mutex.h"
+#include "../oc_connectivity.h"
+#include "oc_buffer.h"
+#include "../oc_log.h"
+#include "adaptor.h"
+
+struct os_eventq oc_event_q;
+
+/* 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)
+{
+    os_mutex_pend(&oc_net_mutex, OS_TIMEOUT_NEVER);
+}
+
+void
+oc_network_event_handler_mutex_unlock(void)
+{
+    os_mutex_release(&oc_net_mutex);
+}
+
+/* need a task to process OCF messages */
+#define OC_NET_TASK_STACK_SIZE  OS_STACK_ALIGN(MYNEWT_VAL(OC_TASK_STACK_SIZE))
+#define OC_NET_TASK_PRIORITY            MYNEWT_VAL(OC_TASK_PRIORITY)
+struct os_task oc_task;
+os_stack_t *oc_stack;
+
+void
+oc_send_buffer(oc_message_t *message) {
+
+    switch (message->endpoint.flags)
+    {
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+        case IP:
+            oc_send_buffer_ip(message);
+            break;
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+        case GATT:
+            oc_send_buffer_gatt(message);
+            break;
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+        case SERIAL:
+            oc_send_buffer_serial(message);
+            break;
+#endif
+        default:
+            ERROR("Unknown transport option %u\n", message->endpoint.flags);
+            oc_message_unref(message);
+    }
+}
+
+void oc_send_multicast_message(oc_message_t *message)
+{
+
+    /* send on all the transports.  Don't forget to reference the message
+     * so it doesn't get deleted  */
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+    oc_send_buffer_ip_mcast(message);
+#endif
+
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+    /* no multicast for GATT, just send unicast */
+    oc_message_add_ref(message);
+    oc_send_buffer_gatt(message);
+#endif
+
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+    /* no multi-cast for serial.  just send unicast */
+    oc_message_add_ref(message);
+    oc_send_buffer_serial(message);
+#endif
+}
+
+/* send all the entries to the OCF stack through the same task */
+void
+oc_task_handler(void *arg) {
+
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+    oc_connectivity_start_gatt();
+#endif
+
+    while (1) {
+        struct os_callout_func *cf;
+        oc_message_t *pmsg;
+        (void) pmsg;    /* to avoid unused */
+        struct os_event *evt = os_eventq_get(&oc_event_q);
+
+        switch(evt->ev_type) {
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+            case OC_ADATOR_EVENT_IP:
+                while ((pmsg = oc_attempt_rx_ip()) != NULL) {
+                    oc_network_event(pmsg);
+                }
+                break;
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+            case OC_ADATOR_EVENT_SERIAL:
+                while ((pmsg = oc_attempt_rx_serial()) != NULL) {
+                    oc_network_event(pmsg);
+                }
+                break;
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+            case OC_ADATOR_EVENT_GATT:
+                while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
+                    oc_network_event(pmsg);
+                }
+                break;
+#endif
+        case OS_EVENT_T_TIMER:
+            cf = (struct os_callout_func *)evt;
+            assert(cf->cf_func);
+            cf->cf_func(CF_ARG(cf));
+            break;
+            default:
+                ERROR("oc_task_handler: Unidentified event %d\n", evt->ev_type);
+        }
+    }
+}
+
+static int
+oc_init_task(void) {
+    int rc;
+
+    os_eventq_init(&oc_event_q);
+
+    oc_stack = (os_stack_t*) malloc(sizeof(os_stack_t)*OC_NET_TASK_STACK_SIZE);
+    if (NULL == oc_stack) {
+        ERROR("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) {
+        ERROR("Could not start oc task\n");
+        free(oc_stack);
+    }
+
+    return rc;
+}
+
+void
+oc_connectivity_shutdown(void)
+{
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+    oc_connectivity_shutdown_ip();
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+    oc_connectivity_shutdown_serial();
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+    oc_connectivity_shutdown_gatt();
+#endif
+}
+
+int
+oc_connectivity_init(void)
+{
+    int rc;
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+    rc = oc_connectivity_init_ip();
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+
+    rc = oc_connectivity_init_serial();
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+    rc = oc_connectivity_init_gatt();
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+#endif
+    rc = oc_init_task();
+    if (rc != 0) {
+        goto oc_connectivity_init_err;
+    }
+
+    return 0;
+
+oc_connectivity_init_err:
+    oc_connectivity_shutdown();
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
new file mode 100644
index 0000000..89c2599
--- /dev/null
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ */
+
+#ifndef ADAPTOR_H
+#define ADAPTOR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OC_ADATOR_EVENT_IP      (OS_EVENT_T_PERUSER + 0)
+#define OC_ADATOR_EVENT_SERIAL  (OS_EVENT_T_PERUSER + 1)
+#define OC_ADATOR_EVENT_GATT    (OS_EVENT_T_PERUSER + 2)
+
+extern struct os_eventq oc_event_q;
+
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+int oc_connectivity_init_ip(void);
+void oc_connectivity_shutdown_ip(void);
+void oc_send_buffer_ip(oc_message_t *message);
+void oc_send_buffer_ip_mcast(oc_message_t *message);
+oc_message_t *oc_attempt_rx_ip(void);
+#endif
+
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+int oc_connectivity_init_gatt(void);
+void oc_connectivity_start_gatt(void);
+void oc_connectivity_shutdown_gatt(void);
+void oc_send_buffer_gatt(oc_message_t *message);
+void oc_send_buffer_gatt_mcast(oc_message_t *message);
+oc_message_t *oc_attempt_rx_gatt(void);
+
+#endif
+
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+int oc_connectivity_init_serial(void);
+void oc_connectivity_shutdown_serial(void);
+void oc_send_buffer_serial(oc_message_t *message);
+oc_message_t *oc_attempt_rx_serial(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ADAPTOR_H */
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
new file mode 100644
index 0000000..1ae2f8e
--- /dev/null
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -0,0 +1,509 @@
+/**
+ * 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 <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+#include <assert.h>
+#include <os/os.h>
+#include <string.h>
+#include "oc_buffer.h"
+#include "../oc_log.h"
+#include "adaptor.h"
+#include "host/ble_hs.h"
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
+
+
+/* a custom service for COAP over GATT */
+/* {e3f9f9c4-8a83-4055-b647-728b769745d6} */
+const uint8_t gatt_svr_svc_coap[16] = {
+    0xd6, 0x45, 0x97, 0x76, 0x8b, 0x72, 0x47, 0xb6,
+    0x55, 0x40, 0x83, 0x8a, 0xc4, 0xf9, 0xf9, 0xe3,
+};
+
+/* {e467fee6-d6bb-4956-94df-0090350631f5} */
+const uint8_t gatt_svr_chr_coap[16] = {
+    0xf5, 0x31, 0x06, 0x35, 0x90, 0x00, 0xdf, 0x94,
+    0x56, 0x49, 0xbb, 0xd6, 0xe6, 0xfe, 0x67, 0xe4,
+};
+
+/* queue to hold mbufs until we get called from oic */
+struct os_mqueue ble_coap_mq;
+
+static int
+blecoap_gap_event(struct ble_gap_event *event, void *arg);
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+/* ble nmgr attr handle */
+uint16_t g_ble_coap_attr_handle;
+
+static int
+gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
+                         struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
+    {
+        /* Service: newtmgr */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = (void *)gatt_svr_svc_coap,
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /* Characteristic: Write No Rsp */
+            .uuid128 = (void *)gatt_svr_chr_coap,
+            .access_cb = gatt_svr_chr_access_coap,
+            .flags = BLE_GATT_CHR_F_WRITE_NO_RSP | BLE_GATT_CHR_F_NOTIFY,
+            .val_handle = &g_ble_coap_attr_handle,
+        }, {
+            0, /* No more characteristics in this service */
+        } },
+    },
+    {
+        0, /* No more services */
+    },
+};
+
+static int
+gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
+                            struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    struct os_mbuf *m;
+    int rc;
+    (void) attr_handle; /* no need to use this since we have onyl one attr
+                         * tied to this callback */
+
+    switch (ctxt->op) {
+        case BLE_GATT_ACCESS_OP_WRITE_CHR:
+            m = ctxt->om;
+            /* stick the conn handle at the end of the frame -- we will
+             * pull it out later */
+            rc = os_mbuf_append(m, &conn_handle, sizeof(conn_handle));
+            if (rc) {
+                return BLE_ATT_ERR_INSUFFICIENT_RES;
+            }
+            rc = os_mqueue_put(&ble_coap_mq, &oc_event_q, m);
+            if (rc) {
+                return BLE_ATT_ERR_PREPARE_QUEUE_FULL;
+            }
+
+            /* tell nimble we are keeping the mbuf */
+            ctxt->om = NULL;
+
+            break;
+        default:
+            assert(0);
+            return BLE_ATT_ERR_UNLIKELY;
+    }
+    return 0;
+}
+
+static int
+oc_gatt_advertise(void)
+{
+    struct ble_gap_adv_params adv_params;
+    struct ble_hs_adv_fields fields;
+    int rc;
+
+    /*
+     *  Set the advertisement data included in our advertisements:
+     *     o Flags (indicates advertisement type and other general info).
+     *     o Advertising tx power.
+     *     o 128 bit UUID
+     */
+
+    memset(&fields, 0, sizeof fields);
+
+    /* Indicate that the flags field should be included; specify a value of 0
+     * to instruct the stack to fill the value in for us.
+     */
+    fields.flags_is_present = 1;
+    fields.flags = 0;
+
+    /* Indicate that the TX power level field should be included; have the
+     * stack fill this one automatically as well.  This is done by assigning
+     * the special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
+     */
+    fields.tx_pwr_lvl_is_present = 1;
+    fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
+
+    fields.uuids128 = (void *)gatt_svr_svc_coap;
+    fields.num_uuids128 = 1;
+    fields.uuids128_is_complete = 1;
+
+    rc = ble_gap_adv_set_fields(&fields);
+    if (rc != 0) {
+        return rc;
+    }
+
+    memset(&fields, 0, sizeof fields);
+    fields.name = (uint8_t *)ble_svc_gap_device_name();
+    fields.name_len = strlen((char *)fields.name);
+    fields.name_is_complete = 1;
+
+    rc = ble_gap_adv_rsp_set_fields(&fields);
+    if (rc != 0) {
+        return rc;
+    }
+
+    /* Begin advertising. */
+    memset(&adv_params, 0, sizeof adv_params);
+    adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
+    adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
+    rc = ble_gap_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, BLE_HS_FOREVER,
+                           &adv_params, blecoap_gap_event, NULL);
+    return rc;
+}
+#endif
+
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+static char *
+addr_str(const void *addr)
+{
+    static char buf[6 * 2 + 5 + 1];
+    const uint8_t *u8p;
+
+    u8p = addr;
+    sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
+            u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
+
+    return buf;
+}
+
+
+/**
+ * Indicates whether we should tre to connect to the sender of the specified
+ * advertisement.  The function returns a positive result if the device
+ * advertises connectability and support for the Alert Notification service.
+ */
+static int
+oc_gatt_should_connect(const struct ble_gap_disc_desc *disc)
+{
+    int i;
+
+    /* The device has to be advertising connectability. */
+    if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
+        disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
+
+        return 0;
+    }
+
+    /* The device has to advertise support for the COAP service
+     */
+    for (i = 0; i < disc->fields->num_uuids128; i++) {
+        char *ptr = ((char*) disc->fields->uuids128) + 16 * i;
+        if (memcmp(ptr, gatt_svr_svc_coap, sizeof(gatt_svr_svc_coap)) == 0) {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+/**
+ * Connects to the sender of the specified advertisement of it looks
+ * interesting.  A device is "interesting" if it advertises connectability and
+ * support for the Alert Notification service.
+ */
+static void
+oc_gatt_connect_if_interesting(const struct ble_gap_disc_desc *disc)
+{
+    int rc;
+
+    /* Don't do anything if we don't care about this advertiser. */
+    if (!oc_gatt_should_connect(disc)) {
+        return;
+    }
+
+    /* Scanning must be stopped before a connection can be initiated. */
+    rc = ble_gap_disc_cancel();
+    if (rc != 0) {
+        ERROR("Failed to cancel scan; rc=%d\n", rc);
+        return;
+    }
+
+    /* Try to connect the the advertiser.  Allow 30 seconds (30000 ms) for
+     * timeout.
+     */
+    rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, disc->addr_type, disc->addr,
+                         30000, NULL, blecoap_gap_event, NULL);
+    if (rc != 0) {
+        ERROR("Error: Failed to connect to device; addr_type=%d "
+                           "addr=%s\n", disc->addr_type, addr_str(disc->addr));
+        return;
+    }
+}
+
+
+/**
+ * Initiates the GAP general discovery procedure.
+ */
+static int
+oc_gatt_scan(void)
+{
+    struct ble_gap_disc_params disc_params;
+    int rc;
+
+    /* Tell the controller to filter duplicates; we don't want to process
+     * repeated advertisements from the same device.
+     */
+    disc_params.filter_duplicates = 1;
+
+    /**
+     * Perform a passive scan.  I.e., don't send follow-up scan requests to
+     * each advertiser.
+     */
+    disc_params.passive = 1;
+
+    /* Use defaults for the rest of the parameters. */
+    disc_params.itvl = 0;
+    disc_params.window = 0;
+    disc_params.filter_policy = 0;
+    disc_params.limited = 0;
+
+    rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
+                      blecoap_gap_event, NULL);
+    if (rc != 0) {
+        ERROR("Error initiating GAP discovery procedure; rc=%d\n",
+                    rc);
+    }
+    return rc;
+}
+
+#endif
+
+oc_message_t *
+oc_attempt_rx_gatt(void) {
+    int rc;
+    struct os_mbuf *m = NULL;
+    struct os_mbuf_pkthdr *pkt;
+    uint16_t conn_handle;
+    oc_message_t *message = NULL;
+
+    LOG("oc_transport_gatt attempt rx\n");
+
+    /* get an mbuf from the queue */
+    m = os_mqueue_get(&ble_coap_mq);
+    if (NULL == m) {
+        ERROR("oc_transport_gatt: Woke for for receive but found no mbufs\n");
+        goto rx_attempt_err;
+    }
+
+    if (!OS_MBUF_IS_PKTHDR(m)) {
+        ERROR("oc_transport_gatt: received mbuf that wasn't a packet header\n");
+        goto rx_attempt_err;
+    }
+
+    pkt = OS_MBUF_PKTHDR(m);
+
+    LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
+    /* get the conn handle from the end of the message */
+    rc = os_mbuf_copydata(m, pkt->omp_len - sizeof(conn_handle),
+                            sizeof(conn_handle), &conn_handle);
+    if (rc != 0) {
+        ERROR("Failed to retrieve conn_handle from mbuf \n");
+        goto rx_attempt_err;
+    }
+
+    /* trim conn_handle from the end */
+    os_mbuf_adj(m, - sizeof(conn_handle));
+
+    message = oc_allocate_message();
+    if (NULL == message) {
+        ERROR("Could not allocate OC message buffer\n");
+        goto rx_attempt_err;
+    }
+
+    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
+        ERROR("Message to large for OC message buffer\n");
+        goto rx_attempt_err;
+    }
+    /* copy to message from mbuf chain */
+    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
+    if (rc != 0) {
+        ERROR("Failed to copy message from mbuf to OC message buffer \n");
+        goto rx_attempt_err;
+    }
+
+    os_mbuf_free_chain(m);
+    message->endpoint.flags = GATT;
+    message->endpoint.bt_addr.conn_handle = conn_handle;
+    message->length = pkt->omp_len;
+    LOG("Successfully rx length %lu\n", message->length);
+    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;
+}
+
+static int
+blecoap_gap_event(struct ble_gap_event *event, void *arg)
+{
+    switch (event->type) {
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+    case BLE_GAP_EVENT_DISC:
+        /* Try to connect to the advertiser if it looks interesting. */
+        oc_gatt_connect_if_interesting(&event->disc);
+        return 0;
+#endif
+    case BLE_GAP_EVENT_CONNECT:
+        /* A new connection was established or a connection attempt failed. */
+        if (event->connect.status == 0) {
+            /* nothing to do here on the server  */
+        }
+        if (event->connect.status != 0) {
+            /* nothing to do here on the client */
+        }
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    /* keep advertising for multiple connections */
+    oc_gatt_advertise();
+#endif
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+        /* keep scanning for new connections */
+        oc_gatt_scan();
+#endif
+        return 0;
+
+    case BLE_GAP_EVENT_DISCONNECT:
+        /* Connection terminated; resume advertising. */
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+        /* keep scanning for new connections */
+        oc_gatt_scan();
+#endif
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+        /* resume advertising  */
+        oc_gatt_advertise();
+#endif
+        return 0;
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+    case BLE_GAP_EVENT_NOTIFY_RX:
+        /* TODO queue the packet */
+        return 0;
+#endif
+    }
+    return 0;
+}
+
+int
+ble_coap_gatt_srv_init(struct os_eventq **out)
+{
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    int rc;
+    rc = ble_gatts_count_cfg(gatt_svr_svcs);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_add_svcs(gatt_svr_svcs);
+    if (rc != 0) {
+        return rc;
+    }
+#endif
+
+    *out = &oc_event_q;
+    return 0;
+}
+
+int oc_connectivity_init_gatt(void) {
+    os_mqueue_init(&ble_coap_mq, NULL);
+    ble_coap_mq.mq_ev.ev_type = OC_ADATOR_EVENT_GATT;
+    return 0;
+}
+
+void oc_connectivity_start_gatt(void) {
+    int rc;
+    rc = ble_hs_start();
+    if (rc != 0) {
+        goto err;
+    }
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    rc = oc_gatt_advertise();
+    if (rc != 0) {
+        goto err;
+    }
+#endif
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+    rc = oc_gatt_scan();
+    if (rc != 0) {
+        goto err;
+    }
+#endif
+err:
+    ERROR("error enabling advertisement; rc=%d\n", rc);
+}
+
+void oc_connectivity_shutdown_gatt(void)
+{
+    /* there is not unregister for BLE */
+}
+
+void oc_send_buffer_gatt(oc_message_t *message)
+{
+    struct os_mbuf *m = NULL;
+    int rc;
+
+    /* get a packet header */
+    m = os_msys_get_pkthdr(0, 0);
+    if (m == NULL) {
+        ERROR("oc_transport_gatt: No mbuf available\n");
+        goto err;
+    }
+
+    /* add this data to the mbuf */
+    rc = os_mbuf_append(m, message->data, message->length);
+    if (rc != 0) {
+        ERROR("oc_transport_gatt: could not append data \n");
+        goto err;
+    }
+
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+    ERROR("send not supported on client");
+#endif
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
+                                g_ble_coap_attr_handle, m);
+    m = NULL;
+#endif
+
+err:
+    if (m) {
+        os_mbuf_free_chain(m);
+    }
+    oc_message_unref(message);
+    return;
+}
+
+void
+oc_send_buffer_gatt_mcast(oc_message_t *message)
+{
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+    ERROR("send not supported on client");
+#elif (MYNEWT_VAL(OC_SERVER) == 1)
+    oc_message_unref(message);
+    ERROR("oc_transport_gatt: no multicast support for server only system \n");
+#endif
+}
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/clock.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/clock.c b/net/oic/src/port/mynewt/clock.c
new file mode 100644
index 0000000..51def9a
--- /dev/null
+++ b/net/oic/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/f88168c2/net/oic/src/port/mynewt/config.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/config.h b/net/oic/src/port/mynewt/config.h
new file mode 100644
index 0000000..1e057b3
--- /dev/null
+++ b/net/oic/src/port/mynewt/config.h
@@ -0,0 +1,81 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Time resolution */
+#include <stdint.h>
+#include <os/os.h>
+#include <log/log.h>
+#include <syscfg/syscfg.h>
+
+/* rather than change all their source files, just translate the mynewt
+ * package defines into their defines here */
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+#define OC_SERVER
+#endif
+
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+#define OC_CLIENT
+#endif
+
+#if (MYNEWT_VAL(OC_DEBUG) == 1)
+#define DEBUG 1
+#endif
+
+extern struct log oc_log;
+
+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)
+#define OC_INTS_POOL_SIZE (16)
+#define OC_DOUBLES_POOL_SIZE (16)
+
+/* Server-side parameters */
+/* Maximum number of server resources */
+#define MAX_APP_RESOURCES (8)
+
+/* Common paramters */
+/* Maximum number of concurrent requests */
+#define MAX_NUM_CONCURRENT_REQUESTS (2)
+
+/* Estimated number of nodes in payload tree structure */
+#define EST_NUM_REP_OBJECTS (100)
+
+/* Maximum size of request/response PDUs */
+#define MAX_PAYLOAD_SIZE (612)
+
+/* Number of devices on the OCF platform */
+#define MAX_NUM_DEVICES (1)
+
+/* Platform payload size */
+#define MAX_PLATFORM_PAYLOAD_SIZE (256)
+
+/* Device payload size */
+#define MAX_DEVICE_PAYLOAD_SIZE (256)
+
+/* Security layer */
+/* Maximum number of authorized clients */
+//#define MAX_NUM_SUBJECTS (2)
+
+/* Maximum number of concurrent DTLS sessions */
+//#define MAX_DTLS_PEERS (1)
+
+/* Max inactivity timeout before tearing down DTLS connection */
+//#define DTLS_INACTIVITY_TIMEOUT (10)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
new file mode 100644
index 0000000..1bdf621
--- /dev/null
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -0,0 +1,315 @@
+/**
+ * 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 <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+#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_connectivity.h"
+#include "oc_buffer.h"
+#include "../oc_log.h"
+#include "adaptor.h"
+
+struct os_event oc_sock_read_event = {
+    .ev_type = OC_ADATOR_EVENT_IP,
+};
+
+#ifdef OC_SECURITY
+#error This implementation does not yet support security
+#endif
+
+
+#define COAP_PORT_UNSECURED (5683)
+/* TODO use inet_pton when its available */
+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}
+};
+
+
+/* sockets to use for coap unicast and multicast */
+struct mn_socket *ucast;
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+struct mn_socket *mcast;
+#endif
+
+static void
+oc_send_buffer_ip_int(oc_message_t *message, int mcast)
+{
+    struct mn_sockaddr_in6 to;
+    struct os_mbuf m;
+    int rc;
+
+    LOG("oc_transport_ip attempt send buffer %lu\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));
+
+    /* 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;
+    to.msin6_scope_id = message->endpoint.ipv6_addr.scope;
+
+    if (mcast) {
+        struct mn_itf itf;
+        memset(&itf, 0, sizeof(itf));
+
+        while (1) {
+            rc = mn_itf_getnext(&itf);
+            if (rc) {
+                break;
+            }
+
+            if (0 == (itf.mif_flags & MN_ITF_F_UP)) {
+                continue;
+            }
+
+            to.msin6_scope_id = itf.mif_idx;
+
+            rc = mn_sendto(ucast, &m, (struct mn_sockaddr *) &to);
+            if (rc != 0) {
+                ERROR("Failed sending buffer %lu on itf %d\n",
+                      message->length, to.msin6_scope_id);
+            }
+        }
+    } else {
+        rc = mn_sendto(ucast, &m, (struct mn_sockaddr *) &to);
+        if (rc != 0) {
+            ERROR("Failed sending buffer %lu on itf %d\n",
+                  message->length, to.msin6_scope_id);
+        }
+    }
+    oc_message_unref(message);
+}
+
+void
+oc_send_buffer_ip(oc_message_t *message) {
+    oc_send_buffer_ip_int(message, 0);
+}
+void
+oc_send_buffer_ip_mcast(oc_message_t *message) {
+    oc_send_buffer_ip_int(message, 1);
+}
+
+oc_message_t *
+oc_attempt_rx_ip_sock(struct mn_socket * rxsock) {
+    int rc;
+    struct os_mbuf *m = NULL;
+    struct os_mbuf_pkthdr *pkt;
+    oc_message_t *message = NULL;
+    struct mn_sockaddr_in6 from;
+
+    LOG("oc_transport_ip attempt rx from %p\n", rxsock);
+
+    rc= mn_recvfrom(rxsock, &m, (struct mn_sockaddr *) &from);
+
+    if ( rc != 0) {
+        return NULL;
+    }
+
+    if (!OS_MBUF_IS_PKTHDR(m)) {
+        goto rx_attempt_err;
+    }
+
+    pkt = OS_MBUF_PKTHDR(m);
+
+    LOG("rx from %p %p-%u\n", rxsock, pkt, pkt->omp_len);
+
+    message = oc_allocate_message();
+    if (NULL == message) {
+        ERROR("Could not allocate OC message buffer\n");
+        goto rx_attempt_err;
+    }
+
+    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
+        ERROR("Message to large for OC message buffer\n");
+        goto rx_attempt_err;
+    }
+    /* copy to message from mbuf chain */
+    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
+    if (rc != 0) {
+        ERROR("Failed to copy message from mbuf to OC message buffer \n");
+        goto rx_attempt_err;
+    }
+
+    os_mbuf_free_chain(m);
+
+    message->endpoint.flags = IP;
+    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 = from.msin6_scope_id;
+    message->endpoint.ipv6_addr.port = ntohs(from.msin6_port);
+
+    LOG("Successfully rx from %p len %lu\n", rxsock, message->length);
+    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_ip(void) {
+    oc_message_t *pmsg;
+    pmsg = oc_attempt_rx_ip_sock(ucast);
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    if (pmsg == NULL ) {
+        pmsg = oc_attempt_rx_ip_sock(mcast);
+    }
+#endif
+    return pmsg;
+}
+
+static void oc_socks_readable(void *cb_arg, int err);
+
+union mn_socket_cb oc_sock_cbs = {
+    .socket.readable = oc_socks_readable,
+    .socket.writable = NULL
+};
+
+void
+oc_socks_readable(void *cb_arg, int err)
+{
+    os_eventq_put(&oc_event_q, &oc_sock_read_event);
+}
+
+void
+oc_connectivity_shutdown_ip(void)
+{
+    LOG("OC shutdown IP\n");
+
+    if (ucast) {
+        mn_close(ucast);
+    }
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    if (mcast) {
+        mn_close(mcast);
+    }
+#endif
+
+}
+
+int
+oc_connectivity_init_ip(void)
+{
+    int rc;
+    struct mn_sockaddr_in6 sin;
+    struct mn_itf itf;
+
+    LOG("OC transport init IP\n");
+    memset(&itf, 0, sizeof(itf));
+
+    rc = oc_log_init();
+    if ( rc != 0) {
+        ERROR("Could not create oc logging\n");
+        return rc;    }
+
+    rc = mn_socket(&ucast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    if ( rc != 0 || !ucast ) {
+        ERROR("Could not create oc unicast socket\n");
+        return rc;
+    }
+    mn_socket_set_cbs(ucast, ucast, &oc_sock_cbs);
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    rc = mn_socket(&mcast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    if ( rc != 0 || !mcast ) {
+        mn_close(ucast);
+        ERROR("Could not create oc multicast socket\n");
+        return rc;
+    }
+    mn_socket_set_cbs(mcast, mcast, &oc_sock_cbs);
+#endif
+
+    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) {
+        ERROR("Could not bind oc unicast socket\n");
+        goto oc_connectivity_init_err;
+    }
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    /* Set socket option to join multicast group on all valid interfaces */
+    while (1) {
+        struct mn_mreq join;
+
+        rc = mn_itf_getnext(&itf);
+        if (rc) {
+            break;
+        }
+
+        if (0 == (itf.mif_flags & MN_ITF_F_UP)) {
+            continue;
+        }
+
+        join.mm_addr.v6 = coap_all_nodes_v6;
+        join.mm_idx = itf.mif_idx;
+        join.mm_family = MN_AF_INET6;
+
+        rc = mn_setsockopt(mcast, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &join);
+        if (rc != 0) {
+            ERROR("Could not join multicast group on %s\n", itf.mif_name);
+            continue;
+        }
+
+        LOG("Joined Coap multicast grop on %s\n", itf.mif_name);
+    }
+
+    sin.msin6_port = htons(COAP_PORT_UNSECURED);
+    rc = mn_bind(mcast, (struct mn_sockaddr *)&sin);
+    if (rc != 0) {
+        ERROR("Could not bind oc multicast socket\n");
+        goto oc_connectivity_init_err;
+    }
+#endif
+
+    return 0;
+
+oc_connectivity_init_err:
+    oc_connectivity_shutdown();
+    return rc;
+}
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/log.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/log.c b/net/oic/src/port/mynewt/log.c
new file mode 100644
index 0000000..8c76fc9
--- /dev/null
+++ b/net/oic/src/port/mynewt/log.c
@@ -0,0 +1,43 @@
+/**
+ * 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 <log/log.h>
+
+/* 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;
+struct log oc_log;
+
+int
+oc_log_init(void) {
+
+    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_IOTIVITY, "OC Init");
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/oc_loop.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/oc_loop.c b/net/oic/src/port/mynewt/oc_loop.c
new file mode 100644
index 0000000..ca91812
--- /dev/null
+++ b/net/oic/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/f88168c2/net/oic/src/port/mynewt/random.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/random.c b/net/oic/src/port/mynewt/random.c
new file mode 100644
index 0000000..0fcddfb
--- /dev/null
+++ b/net/oic/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/f88168c2/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
new file mode 100644
index 0000000..892db2b
--- /dev/null
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -0,0 +1,164 @@
+/**
+ * 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 <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+
+#include <assert.h>
+#include <os/os.h>
+#include <shell/shell.h>
+#include "oc_buffer.h"
+#include "../oc_log.h"
+#include "adaptor.h"
+
+
+struct os_mqueue oc_serial_mqueue;
+
+static int
+oc_serial_in(struct os_mbuf *m, void *arg)
+{
+    return os_mqueue_put(&oc_serial_mqueue, &oc_event_q, m);
+}
+
+void
+oc_connectivity_shutdown_serial(void) {
+    shell_nlip_input_register(NULL, NULL);
+}
+
+int
+oc_connectivity_init_serial(void) {
+    int rc;
+
+    rc = shell_nlip_input_register(oc_serial_in, NULL);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = os_mqueue_init(&oc_serial_mqueue, NULL);
+    if (rc != 0) {
+        goto err;
+    }
+    /* override the eventq type */
+    oc_serial_mqueue.mq_ev.ev_type = OC_ADATOR_EVENT_SERIAL;
+    return 0;
+
+err:
+    oc_connectivity_shutdown_serial();
+    return rc;
+}
+
+
+void oc_send_buffer_serial(oc_message_t *message) {
+    int rc;
+    struct os_mbuf *m;
+
+    /* get a packet header */
+    m = os_msys_get_pkthdr(0, 0);
+    if (m == NULL) {
+        ERROR("oc_transport_serial: No mbuf available\n");
+        goto err;
+    }
+
+    /* add this data to the mbuf */
+    rc = os_mbuf_append(m, message->data, message->length);
+    if (rc != 0) {
+
+        ERROR("oc_transport_serial: could not append data \n");
+        goto err;
+    }
+
+    /* send over the shell output */
+    rc = shell_nlip_output(m);
+    if (rc != 0) {
+        ERROR("oc_transport_serial: nlip output failed \n");
+        goto err;
+    }
+
+    LOG("oc_transport_serial: send buffer %lu\n", message->length);
+
+err:
+    oc_message_unref(message);
+    return;
+
+}
+
+oc_message_t *
+oc_attempt_rx_serial(void) {
+    int rc;
+    struct os_mbuf *m = NULL;
+    struct os_mbuf_pkthdr *pkt;
+    oc_message_t *message = NULL;
+
+    LOG("oc_transport_serial attempt rx\n");
+
+    /* get an mbuf from the queue */
+    m = os_mqueue_get(&oc_serial_mqueue);
+    if (NULL == m) {
+        ERROR("oc_transport_serial: Woke for for receive but found no mbufs\n");
+        goto rx_attempt_err;
+    }
+
+    if (!OS_MBUF_IS_PKTHDR(m)) {
+        ERROR("oc_transport_serial: received mbuf that wasn't a packet header\n");
+        goto rx_attempt_err;
+    }
+
+    pkt = OS_MBUF_PKTHDR(m);
+
+    LOG("oc_transport_serial rx %p-%u\n", pkt, pkt->omp_len);
+
+    message = oc_allocate_message();
+    if (NULL == message) {
+        ERROR("Could not allocate OC message buffer\n");
+        goto rx_attempt_err;
+    }
+
+    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
+        ERROR("Message to large for OC message buffer\n");
+        goto rx_attempt_err;
+    }
+    /* copy to message from mbuf chain */
+    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
+    if (rc != 0) {
+        ERROR("Failed to copy message from mbuf to OC message buffer \n");
+        goto rx_attempt_err;
+    }
+
+    os_mbuf_free_chain(m);
+
+    message->endpoint.flags = SERIAL;
+    message->length = pkt->omp_len;
+
+    LOG("Successfully rx length %lu\n", message->length);
+    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;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/mynewt/storage.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/storage.c b/net/oic/src/port/mynewt/storage.c
new file mode 100644
index 0000000..3b77c1a
--- /dev/null
+++ b/net/oic/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;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f88168c2/net/oic/src/port/oc_assert.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_assert.h b/net/oic/src/port/oc_assert.h
new file mode 100644
index 0000000..6361c66
--- /dev/null
+++ b/net/oic/src/port/oc_assert.h
@@ -0,0 +1,50 @@
+/*
+// 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.
+*/
+
+#ifndef OC_ASSERT_H
+#define OC_ASSERT_H
+
+#include "oc_log.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __linux__
+#include <stdlib.h>
+#define abort_impl() abort()
+#else
+void abort_impl(void);
+#endif
+
+#define oc_abort(msg)                                                          \
+  do {                                                                         \
+    LOG("\n%s:%d:%s: error: %s\nAbort.\n", __FILE__, __LINE__, __func__, msg); \
+    abort_impl();                                                              \
+  } while (0)
+
+#define oc_assert(cond)                                                        \
+  do {                                                                         \
+    if (!(cond)) {                                                             \
+      oc_abort("Assertion (" #cond ") failed.");                               \
+    }                                                                          \
+  } while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OC_ASSERT_H */