refactor iotivity to match new sysconfig interfaces.
retested serial, IP, and gatt server.  gat client is still not working


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

Branch: refs/heads/develop
Commit: b98fe70953d6fc68d06da8c861d17d2ff720b578
Parents: 5b51d6b
Author: Paul Dietrich <paulfdietr...@yahoo.com>
Authored: Mon Sep 26 15:13:47 2016 -0700
Committer: Paul Dietrich <paulfdietr...@yahoo.com>
Committed: Mon Sep 26 15:13:47 2016 -0700

----------------------------------------------------------------------
 apps/ocf_sample/pkg.yml                        |  23 +--
 apps/ocf_sample/src/main.c                     | 163 ++++----------------
 libs/console/full/pkg.yml                      |   8 +
 libs/console/full/src/cons_tty.c               |   2 +
 libs/console/full/src/prompt.c                 |   3 +-
 libs/iotivity/include/iotivity/oc_api.h        |   1 +
 libs/iotivity/include/iotivity/oc_gatt.h       |   2 +-
 libs/iotivity/pkg.yml                          |  40 ++++-
 libs/iotivity/src/port/mynewt/adaptor.c        |  39 ++---
 libs/iotivity/src/port/mynewt/adaptor.h        |   6 +-
 libs/iotivity/src/port/mynewt/ble_adaptor.c    |  38 ++---
 libs/iotivity/src/port/mynewt/config.h         |  18 ++-
 libs/iotivity/src/port/mynewt/ip_adaptor.c     |  14 +-
 libs/iotivity/src/port/mynewt/serial_adaptor.c |   4 +-
 14 files changed, 157 insertions(+), 204 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/apps/ocf_sample/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/pkg.yml b/apps/ocf_sample/pkg.yml
index bf9b362..3abca7e 100644
--- a/apps/ocf_sample/pkg.yml
+++ b/apps/ocf_sample/pkg.yml
@@ -25,23 +25,16 @@ pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
 
 pkg.deps:
-    - libs/console/full
     - libs/os
-    - libs/shell
     - libs/util
     - sys/log
     - libs/iotivity
-    - "@apache-mynewt-core/net/nimble/host"
-    - "@apache-mynewt-core/net/nimble/controller"
-    - "@apache-mynewt-core/net/nimble/transport/ram"
-    - "@apache-mynewt-core/net/nimble/host/store/ram"
-    - "@apache-mynewt-core/net/nimble/host/services/gap"
-    - "@apache-mynewt-core/net/nimble/host/services/gatt"
-# this tells the library that you intend to suppor the server functionality
-pkg.cflags:
 
-#-DOC_SERVER -- build the server examples
-#-DOC_CLIENT -- build the client examples
-#-DOC_TRANSPORT_GATT -- to send COAP over GATT
-#-DOC_TRANSPORT_SERIAL -- to send COAP over serial
-#-DOC_TRANSPORT_IP -- to send COAP over IP ßß
\ No newline at end of file
+pkg.deps.OC_TRANSPORT_SERIAL:
+    - libs/shell
+    - libs/console/full
+
+pkg.deps.OC_TRANSPORT_GATT:
+    - net/nimble/controller
+    - net/nimble/transport/ram
+    - net/nimble/host/store/ram

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index e767dce..948408b 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -19,82 +19,40 @@
 #include <assert.h>
 #include <os/os.h>
 #include <bsp/bsp.h>
-#include <console/console.h>
-#include <console/prompt.h>
-#include <shell/shell.h>
 #include <log/log.h>
 #include <hal/hal_cputime.h>
 #include <iotivity/oc_api.h>
+
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+#include <console/console.h>
+#include <console/prompt.h>
+#include <shell/shell.h>
+#endif
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 #include "mn_socket/mn_socket.h"
 #include "mn_socket/arch/sim/native_sock.h"
+#endif
 
-#ifdef OC_TRANSPORT_GATT
-
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
 #include <iotivity/oc_gatt.h>
-
-/* BLE */
 #include "nimble/ble.h"
 #include "host/ble_hs.h"
-#include "host/ble_hs_adv.h"
-#include "host/ble_uuid.h"
-#include "host/ble_att.h"
-#include "host/ble_gap.h"
-#include "host/ble_gatt.h"
-#include "host/ble_l2cap.h"
-#include "host/ble_sm.h"
 #include "controller/ble_ll.h"
-
-/* RAM HCI transport. */
-#include "transport/ram/ble_hci_ram.h"
-
-/* RAM persistence layer. */
-#include "store/ram/ble_store_ram.h"
-
-/* Mandatory services. */
 #include "services/gap/ble_svc_gap.h"
 #include "services/gatt/ble_svc_gatt.h"
-
-uint8_t g_random_addr[6] = {6,5,4,3,2,1};
-uint8_t g_dev_addr[6] = {1,2,3,4,5,6};
-
-/** Priority of the nimble host and controller tasks. */
-#define BLE_LL_TASK_PRI             (OS_TASK_PRI_HIGHEST)
-
-#endif
-
-/* Shell */
-#ifdef OC_TRANSPORT_SERIAL
-#define SHELL_TASK_PRIO         (8)
-#define SHELL_MAX_INPUT_LEN     (512)
-#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
-static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
 #endif
 
 #define OCF_TASK_PRIO      (8)
-#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
+#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(512))
 static os_stack_t ocf_stack[OCF_TASK_STACK_SIZE];
 struct os_task ocf_task;
 
-#ifdef OC_TRANSPORT_GATT
-#define MBUF_PAYLOAD_SIZE BLE_MBUF_PAYLOAD_SIZE
-#else
-#define MBUF_PAYLOAD_SIZE 128
-#endif
-
-#define DEFAULT_MBUF_MPOOL_BUF_LEN OS_ALIGN(MBUF_PAYLOAD_SIZE, 4)
-#define DEFAULT_MBUF_MPOOL_NBUFS (12)
-
-static uint8_t default_mbuf_mpool_data[DEFAULT_MBUF_MPOOL_BUF_LEN *
-    DEFAULT_MBUF_MPOOL_NBUFS];
-
-static struct os_mbuf_pool default_mbuf_pool;
-static struct os_mempool default_mbuf_mpool;
-
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
 static void issue_requests(void);
 #endif
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
 static bool light_state = false;
 
 static void
@@ -156,7 +114,7 @@ register_resources(void)
 }
 #endif
 
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
 #define MAX_URI_LENGTH (30)
 static char light_1[MAX_URI_LENGTH];
 static oc_server_handle_t light_server;
@@ -245,29 +203,27 @@ issue_requests(void)
 {
   oc_do_ip_discovery("oic.r.light", &discovery);
 }
-
 #endif
 
 static void
 app_init(void)
 {
   oc_init_platform("Mynewt", NULL, NULL);
-#ifdef OC_CLIENT
-  oc_add_device("/oic/d", "oic.d.phone", "MynewtClient", "1.0", "1.0",
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+  oc_add_device("/oic/d", "oic.d.light", "MynewtClient", "1.0", "1.0",
                 set_device_custom_property, NULL);
 #endif
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     oc_add_device("/oic/d", "oic.d.light", "MynewtServer", "1.0", "1.0", NULL, 
NULL);
 #endif
 }
 
-
  oc_handler_t ocf_handler = {.init = app_init,
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
                           .register_resources = register_resources,
 #endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
                           .requests_entry = issue_requests,
 #endif
  };
@@ -309,14 +265,14 @@ ocf_task_init(void) {
     oc_main_init(&ocf_handler);
 }
 
+static const uint8_t addr[6] = {1,2,3,4,5,6};
+
 int
 main(int argc, char **argv)
 {
     int rc;
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
     struct os_eventq *ev;
-    struct ble_hci_ram_cfg hci_cfg;
-    struct ble_hs_cfg cfg;
 #endif
     /* Initialize OS */
     os_init();
@@ -325,86 +281,27 @@ main(int argc, char **argv)
     rc = cputime_init(1000000);
     assert(rc == 0);
 
-
-    rc = os_mempool_init(&default_mbuf_mpool, DEFAULT_MBUF_MPOOL_NBUFS,
-            DEFAULT_MBUF_MPOOL_BUF_LEN, default_mbuf_mpool_data,
-            "default_mbuf_data");
-    assert(rc == 0);
-
-    rc = os_mbuf_pool_init(&default_mbuf_pool, &default_mbuf_mpool,
-            DEFAULT_MBUF_MPOOL_BUF_LEN, DEFAULT_MBUF_MPOOL_NBUFS);
-    assert(rc == 0);
-
-    rc = os_msys_register(&default_mbuf_pool);
-    assert(rc == 0);
-
-#ifdef OC_TRANSPORT_SERIAL
-    console_echo(0);
-    console_no_prompt();
-
-    /* Init tasks */
-    rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
-                         SHELL_MAX_INPUT_LEN);
-    assert(rc == 0);
-#else
-    console_init(NULL);
-#endif
-
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
     rc = native_sock_init();
     assert(rc == 0);
 #endif
 
-#ifdef OC_TRANSPORT_GATT
-    /* Initialize the BLE LL */
-    rc = ble_ll_init(BLE_LL_TASK_PRI, DEFAULT_MBUF_MPOOL_NBUFS,
-                     DEFAULT_MBUF_MPOOL_BUF_LEN - BLE_HCI_DATA_HDR_SZ);
-    assert(rc == 0);
-
-    /* Initialize the RAM HCI transport. */
-    hci_cfg = ble_hci_ram_cfg_dflt;
-    rc = ble_hci_ram_init(&hci_cfg);
-    assert(rc == 0);
-
-    /* Initialize the BLE host. */
-    cfg = ble_hs_cfg_dflt;
-    cfg.max_hci_bufs = hci_cfg.num_evt_hi_bufs + hci_cfg.num_evt_lo_bufs;
-    cfg.max_connections = 1;
-    cfg.max_gattc_procs = 2;
-    cfg.max_l2cap_chans = 3;
-    cfg.max_l2cap_sig_procs = 1;
-    cfg.sm_bonding = 1;
-    cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
-    cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
-    cfg.sync_cb = NULL; /* TODO */
-    cfg.store_read_cb = ble_store_ram_read;
-    cfg.store_write_cb = ble_store_ram_write;
-
-    /* Populate config with the required GATT server settings. */
-    cfg.max_attrs = 0;
-    cfg.max_services = 0;
-    cfg.max_client_configs = 0;
-
-    rc = ble_svc_gap_init(&cfg);
-    assert(rc == 0);
-
-    rc = ble_svc_gatt_init(&cfg);
-    assert(rc == 0);
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+    memcpy(g_dev_addr, addr, sizeof(g_dev_addr));
 
     /* COAP Gatt server initialization */
-    rc = ble_coap_gatt_srv_init(&cfg, &ev);
+    rc = ble_coap_gatt_srv_init(&ev);
     assert(rc == 0);
 
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
     /* TODO INIT CLIENT */
 #endif
-
-    rc = ble_hs_init(ev, &cfg);
-    assert(rc == 0);
-
     /* Set the default device name. */
     rc = ble_svc_gap_device_name_set("Mynewt_OCF");
     assert(rc == 0);
+
+    /* Initialize the BLE host. */
+    ble_hs_cfg.parent_evq = ev;
 #endif
 
     ocf_task_init();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/console/full/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/console/full/pkg.yml b/libs/console/full/pkg.yml
index cf0e2d2..f7b895f 100644
--- a/libs/console/full/pkg.yml
+++ b/libs/console/full/pkg.yml
@@ -31,3 +31,11 @@ pkg.apis: console
 
 pkg.init_function: console_pkg_init
 pkg.init_stage: 0
+
+pkg.syscfg_defs:
+    CONSOLE_PROMPT:
+        description: 'Default console prompt '
+        value: '0'
+    CONSOLE_ECHO:
+        description: 'Default console echo '
+        value: '0'
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index f420c2a..0b4fab4 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -19,6 +19,7 @@
 
 #include <inttypes.h>
 #include <assert.h>
+#include "syscfg/syscfg.h"
 #include "sysinit/sysinit.h"
 #include "os/os.h"
 #include "uart/uart.h"
@@ -404,6 +405,7 @@ console_init(console_rx_cb rx_cb)
         if (!ct->ct_dev) {
             return -1;
         }
+        ct->ct_echo_off = ! MYNEWT_VAL(CONSOLE_ECHO);
     }
 
     console_print_prompt();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/console/full/src/prompt.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/prompt.c b/libs/console/full/src/prompt.c
index 3806310..33e37c0 100644
--- a/libs/console/full/src/prompt.c
+++ b/libs/console/full/src/prompt.c
@@ -20,10 +20,11 @@
 
 #include "console/console.h"
 #include "console/prompt.h"
+#include <syscfg/syscfg.h>
 
 /* console prompt, always followed by a space */
 static char console_prompt[] = " > ";
-static char do_prompt = 1;
+static char do_prompt = MYNEWT_VAL(CONSOLE_PROMPT);
 
 
 /* set the prompt character, leave the space */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/include/iotivity/oc_api.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_api.h 
b/libs/iotivity/include/iotivity/oc_api.h
index ce83b64..31eb3c2 100644
--- a/libs/iotivity/include/iotivity/oc_api.h
+++ b/libs/iotivity/include/iotivity/oc_api.h
@@ -17,6 +17,7 @@
 #ifndef OC_API_H
 #define OC_API_H
 
+#include "../src/port/mynewt/config.h"
 #include "../src/messaging/coap/oc_coap.h"
 #include "oc_ri.h"
 #include "../src/port/oc_signal_main_loop.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/include/iotivity/oc_gatt.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_gatt.h 
b/libs/iotivity/include/iotivity/oc_gatt.h
index 0cb48a8..ae6c59c 100644
--- a/libs/iotivity/include/iotivity/oc_gatt.h
+++ b/libs/iotivity/include/iotivity/oc_gatt.h
@@ -28,7 +28,7 @@ struct ble_hs_cfg;
 
 /* returns the event q for bluetooth to use */
 int
-ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out);
+ble_coap_gatt_srv_init(struct os_eventq **out);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/iotivity/pkg.yml b/libs/iotivity/pkg.yml
index abecc02..6c2480e 100644
--- a/libs/iotivity/pkg.yml
+++ b/libs/iotivity/pkg.yml
@@ -26,19 +26,51 @@ 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.deps.OC_TRANSPORT_GATT:
     - "@apache-mynewt-core/net/nimble/host"
-    - "@apache-mynewt-core/net/nimble/transport/ram"
     - "@apache-mynewt-core/net/nimble/host/services/gap"
     - "@apache-mynewt-core/net/nimble/host/services/gatt"
+
+pkg.deps.OC_TRANSPORT_IP:
+    - "@apache-mynewt-core/sys/mn_socket"
+
+pkg.deps.OC_TRANSPORT_SERIAL:
+    - "@apache-mynewt-core/libs/shell"
+
 # remove debug option to save logging
 pkg.cflags: -std=c99
-        -DDEBUG=1
         -DSECURE=0
         -I./port/mynewt
         -I../port/mynewt
         -I../../port/mynewt
         -I../include/iotivity
         -I../../include/iotivity
-        -I../../../include/iotivity
\ No newline at end of file
+        -I../../../include/iotivity
+
+pkg.syscfg_defs:
+    OC_TRANSPORT_SERIAL:
+        description: 'Enables OIC transport over nlip serial'
+        value: '0'
+    OC_TRANSPORT_GATT:
+        description: 'Enables OIC transport over BLE GATT'
+        value: '0'
+    OC_TRANSPORT_IP:
+        description: 'Enables OIC transport over IP UDP'
+        value: '0'
+    OC_CLIENT:
+        description: 'Enables OIC client support'
+        value: '0'
+    OC_SERVER:
+        description: 'Enables OIC server support'
+        value: '0'
+    OC_DEBUG:
+        description: 'Enables OIC debug logs'
+        value: '0'
+    OC_TASK_PRIORITY:
+        description: 'The task priority for an internal tasks that runs the 
OCF stack'
+        value: '4'
+    OC_TASK_STACK_SIZE:
+        description: 'The stack size of the OC task in words'
+        value: '300'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.c 
b/libs/iotivity/src/port/mynewt/adaptor.c
index 144ef9b..0367c67 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.c
+++ b/libs/iotivity/src/port/mynewt/adaptor.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include <assert.h>
+#include <syscfg/syscfg.h>
 #include <os/os.h>
 #include <os/endian.h>
 #include <string.h>
@@ -54,8 +55,8 @@ oc_network_event_handler_mutex_unlock(void)
 }
 
 /* need a task to process OCF messages */
-#define OC_NET_TASK_STACK_SIZE          OS_STACK_ALIGN(300)
-#define OC_NET_TASK_PRIORITY            (4)
+#define OC_NET_TASK_STACK_SIZE          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;
 
@@ -64,17 +65,17 @@ oc_send_buffer(oc_message_t *message) {
 
     switch (message->endpoint.flags)
     {
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
         case IP:
             oc_send_buffer_ip(message);
             break;
 #endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
         case GATT:
             oc_send_buffer_gatt(message);
             break;
 #endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
         case SERIAL:
             oc_send_buffer_serial(message);
             break;
@@ -91,17 +92,17 @@ 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  */
 
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
     oc_send_buffer_ip_mcast(message);
 #endif
 
-#ifdef OC_TRANSPORT_GATT
+#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
 
-#ifdef OC_TRANSPORT_SERIAL
+#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);
@@ -112,7 +113,7 @@ void oc_send_multicast_message(oc_message_t *message)
 void
 oc_task_handler(void *arg) {
 
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
     oc_connectivity_start_gatt();
 #endif
 
@@ -123,21 +124,21 @@ oc_task_handler(void *arg) {
         struct os_event *evt = os_eventq_get(&oc_event_q);
 
         switch(evt->ev_type) {
-#ifdef OC_TRANSPORT_IP
+#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
-#ifdef OC_TRANSPORT_SERIAL
+#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
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
             case OC_ADATOR_EVENT_GATT:
                 while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
                     oc_network_event(pmsg);
@@ -182,13 +183,13 @@ oc_init_task(void) {
 void
 oc_connectivity_shutdown(void)
 {
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
     oc_connectivity_shutdown_ip();
 #endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
     oc_connectivity_shutdown_serial();
 #endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
     oc_connectivity_shutdown_gatt();
 #endif
 }
@@ -198,25 +199,25 @@ oc_connectivity_init(void)
 {
     int rc;
 
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
     rc = oc_connectivity_init_ip();
     if (rc != 0) {
         goto oc_connectivity_init_err;
     }
 #endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+
     rc = oc_connectivity_init_serial();
     if (rc != 0) {
         goto oc_connectivity_init_err;
     }
 #endif
-#ifdef OC_TRANSPORT_GATT
+#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;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.h 
b/libs/iotivity/src/port/mynewt/adaptor.h
index ea9034e..89c2599 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.h
+++ b/libs/iotivity/src/port/mynewt/adaptor.h
@@ -31,7 +31,7 @@ extern "C" {
 extern struct os_eventq oc_event_q;
 
 
-#ifdef OC_TRANSPORT_IP
+#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);
@@ -39,7 +39,7 @@ void oc_send_buffer_ip_mcast(oc_message_t *message);
 oc_message_t *oc_attempt_rx_ip(void);
 #endif
 
-#ifdef OC_TRANSPORT_GATT
+#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);
@@ -49,7 +49,7 @@ oc_message_t *oc_attempt_rx_gatt(void);
 
 #endif
 
-#ifdef OC_TRANSPORT_SERIAL
+#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);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ble_adaptor.c 
b/libs/iotivity/src/port/mynewt/ble_adaptor.c
index f6a2925..1ae2f8e 100644
--- a/libs/iotivity/src/port/mynewt/ble_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ble_adaptor.c
@@ -16,6 +16,9 @@
  * 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>
@@ -26,7 +29,6 @@
 #include "services/gap/ble_svc_gap.h"
 #include "services/gatt/ble_svc_gatt.h"
 
-#ifdef OC_TRANSPORT_GATT
 
 /* a custom service for COAP over GATT */
 /* {e3f9f9c4-8a83-4055-b647-728b769745d6} */
@@ -47,7 +49,7 @@ struct os_mqueue ble_coap_mq;
 static int
 blecoap_gap_event(struct ble_gap_event *event, void *arg);
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
 /* ble nmgr attr handle */
 uint16_t g_ble_coap_attr_handle;
 
@@ -167,7 +169,7 @@ oc_gatt_advertise(void)
 }
 #endif
 
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
 static char *
 addr_str(const void *addr)
 {
@@ -358,7 +360,7 @@ static int
 blecoap_gap_event(struct ble_gap_event *event, void *arg)
 {
     switch (event->type) {
-#ifdef OC_CLIENT
+#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);
@@ -373,11 +375,11 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
             /* nothing to do here on the client */
         }
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     /* keep advertising for multiple connections */
     oc_gatt_advertise();
 #endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
         /* keep scanning for new connections */
         oc_gatt_scan();
 #endif
@@ -385,16 +387,16 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
 
     case BLE_GAP_EVENT_DISCONNECT:
         /* Connection terminated; resume advertising. */
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
         /* keep scanning for new connections */
         oc_gatt_scan();
 #endif
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
         /* resume advertising  */
         oc_gatt_advertise();
 #endif
         return 0;
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
     case BLE_GAP_EVENT_NOTIFY_RX:
         /* TODO queue the packet */
         return 0;
@@ -404,11 +406,11 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
 }
 
 int
-ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out)
+ble_coap_gatt_srv_init(struct os_eventq **out)
 {
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     int rc;
-    rc = ble_gatts_count_cfg(gatt_svr_svcs, cfg);
+    rc = ble_gatts_count_cfg(gatt_svr_svcs);
     if (rc != 0) {
         return rc;
     }
@@ -435,13 +437,13 @@ void oc_connectivity_start_gatt(void) {
     if (rc != 0) {
         goto err;
     }
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     rc = oc_gatt_advertise();
     if (rc != 0) {
         goto err;
     }
 #endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
     rc = oc_gatt_scan();
     if (rc != 0) {
         goto err;
@@ -475,11 +477,11 @@ void oc_send_buffer_gatt(oc_message_t *message)
         goto err;
     }
 
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
     ERROR("send not supported on client");
 #endif
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
                                 g_ble_coap_attr_handle, m);
     m = NULL;
@@ -496,9 +498,9 @@ err:
 void
 oc_send_buffer_gatt_mcast(oc_message_t *message)
 {
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
     ERROR("send not supported on client");
-#elif defined(OC_SERVER)
+#elif (MYNEWT_VAL(OC_SERVER) == 1)
     oc_message_unref(message);
     ERROR("oc_transport_gatt: no multicast support for server only system \n");
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/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 83e19de..5f8ba53 100644
--- a/libs/iotivity/src/port/mynewt/config.h
+++ b/libs/iotivity/src/port/mynewt/config.h
@@ -6,6 +6,22 @@
 #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;
@@ -54,6 +70,4 @@ typedef os_time_t oc_clock_time_t;
 /* Max inactivity timeout before tearing down DTLS connection */
 //#define DTLS_INACTIVITY_TIMEOUT (10)
 
-#define MYNEWT_OCF_SERIAL_PORT  (1)
-
 #endif /* CONFIG_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/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 8ae67e4..1bdf621 100644
--- a/libs/iotivity/src/port/mynewt/ip_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ip_adaptor.c
@@ -17,6 +17,8 @@
  * 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>
@@ -29,8 +31,6 @@
 #include "../oc_log.h"
 #include "adaptor.h"
 
-#ifdef OC_TRANSPORT_IP
-
 struct os_event oc_sock_read_event = {
     .ev_type = OC_ADATOR_EVENT_IP,
 };
@@ -51,7 +51,7 @@ const struct mn_in6_addr coap_all_nodes_v6 = {
 /* sockets to use for coap unicast and multicast */
 struct mn_socket *ucast;
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
 struct mn_socket *mcast;
 #endif
 
@@ -188,7 +188,7 @@ oc_message_t *
 oc_attempt_rx_ip(void) {
     oc_message_t *pmsg;
     pmsg = oc_attempt_rx_ip_sock(ucast);
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     if (pmsg == NULL ) {
         pmsg = oc_attempt_rx_ip_sock(mcast);
     }
@@ -218,7 +218,7 @@ oc_connectivity_shutdown_ip(void)
         mn_close(ucast);
     }
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     if (mcast) {
         mn_close(mcast);
     }
@@ -248,7 +248,7 @@ oc_connectivity_init_ip(void)
     }
     mn_socket_set_cbs(ucast, ucast, &oc_sock_cbs);
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     rc = mn_socket(&mcast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
     if ( rc != 0 || !mcast ) {
         mn_close(ucast);
@@ -270,7 +270,7 @@ oc_connectivity_init_ip(void)
         goto oc_connectivity_init_err;
     }
 
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
     /* Set socket option to join multicast group on all valid interfaces */
     while (1) {
         struct mn_mreq join;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/serial_adaptor.c 
b/libs/iotivity/src/port/mynewt/serial_adaptor.c
index 0c27b92..892db2b 100644
--- a/libs/iotivity/src/port/mynewt/serial_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/serial_adaptor.c
@@ -17,6 +17,9 @@
  * 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>
@@ -24,7 +27,6 @@
 #include "../oc_log.h"
 #include "adaptor.h"
 
-#ifdef OC_TRANSPORT_SERIAL
 
 struct os_mqueue oc_serial_mqueue;
 

Reply via email to