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/12/02 19:43:15 UTC

[1/7] incubator-mynewt-core git commit: oic; fix typo in log message.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 9f9377088 -> 35e11e672


oic; fix typo in log message.


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

Branch: refs/heads/develop
Commit: c4a20f712028b49e4b31781c2141e03c35e8a0c2
Parents: 14a1d9a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 16:01:10 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:44 2016 -0800

----------------------------------------------------------------------
 net/oic/src/port/mynewt/ip_adaptor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c4a20f71/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
index 90edd42..fbf16ec 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -98,6 +98,7 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
                 memcpy(&itf2, &itf, sizeof(itf));
                 continue;
             }
+
             n = os_mbuf_dup(m);
             if (!n) {
                 break;
@@ -310,7 +311,7 @@ oc_connectivity_init_ip(void)
             continue;
         }
 
-        LOG("Joined Coap multicast grop on %s\n", itf.mif_name);
+        LOG("Joined Coap mcast group on %s\n", itf.mif_name);
     }
 
     sin.msin6_port = htons(COAP_PORT_UNSECURED);


[7/7] incubator-mynewt-core git commit: oic; use coap_udp_hdr for decoding coap header fields.

Posted by ma...@apache.org.
oic; use coap_udp_hdr for decoding coap header fields.


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

Branch: refs/heads/develop
Commit: 325ce5f48512abfa7c2ce442e9ccefa3f8b72bc5
Parents: c4a20f7
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 16:45:04 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:45 2016 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_server_api.c           |  1 +
 net/oic/src/messaging/coap/coap.c         | 33 ++++-----
 net/oic/src/messaging/coap/constants.h    | 19 ++++--
 net/oic/src/messaging/coap/engine.c       |  1 +
 net/oic/src/messaging/coap/observe.c      |  8 +--
 net/oic/src/messaging/coap/observe.h      |  4 +-
 net/oic/src/messaging/coap/transactions.c | 95 ++++++++++++--------------
 net/oic/src/messaging/coap/transactions.h | 17 +++--
 8 files changed, 88 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/net/oic/src/api/oc_server_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_server_api.c b/net/oic/src/api/oc_server_api.c
index 344d29f..a45cc6f 100644
--- a/net/oic/src/api/oc_server_api.c
+++ b/net/oic/src/api/oc_server_api.c
@@ -258,6 +258,7 @@ oc_send_separate_response(oc_separate_response_t *handle,
                     coap_set_payload(response, handle->buffer,
                       response_buffer.response_length);
                 }
+                t->type = response->type;
                 t->message->length = coap_serialize_message(response,
                   t->message->data);
                 coap_send_transaction(t);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 8117afb..10629f3 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -287,6 +287,7 @@ coap_init_message(coap_packet_t *coap_pkt, coap_message_type_t type,
 size_t
 coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
 {
+    struct coap_udp_hdr *cuh;
     uint8_t *option;
     unsigned int current_number = 0;
 
@@ -297,17 +298,12 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
     LOG("-Serializing MID %u to %p, ", pkt->mid, pkt->buffer);
 
     /* set header fields */
-    pkt->buffer[0] = 0x00;
-    pkt->buffer[0] |= COAP_HEADER_VERSION_MASK &
-                         (pkt->version) << COAP_HEADER_VERSION_POSITION;
-    pkt->buffer[0] |=
-      COAP_HEADER_TYPE_MASK & (pkt->type) << COAP_HEADER_TYPE_POSITION;
-    pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK &
-                         (pkt->token_len)
-                           << COAP_HEADER_TOKEN_LEN_POSITION;
-    pkt->buffer[1] = pkt->code;
-    pkt->buffer[2] = (uint8_t)((pkt->mid) >> 8);
-    pkt->buffer[3] = (uint8_t)(pkt->mid);
+    cuh = (struct coap_udp_hdr *)pkt->buffer;
+    cuh->version = pkt->version;
+    cuh->type = pkt->type;
+    cuh->token_len = pkt->token_len;
+    cuh->code = pkt->code;
+    cuh->id = htons(pkt->mid);
 
     /* empty packet, dont need to do more stuff */
     if (!pkt->code) {
@@ -411,6 +407,7 @@ coap_send_message(oc_message_t *message)
 coap_status_t
 coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
 {
+    struct coap_udp_hdr *udp;
     uint8_t *current_option;
     unsigned int option_number = 0;
     unsigned int option_delta = 0;
@@ -422,14 +419,12 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
     pkt->buffer = data;
 
     /* parse header fields */
-    pkt->version = (COAP_HEADER_VERSION_MASK & pkt->buffer[0]) >>
-                    COAP_HEADER_VERSION_POSITION;
-    pkt->type = (COAP_HEADER_TYPE_MASK & pkt->buffer[0]) >>
-                 COAP_HEADER_TYPE_POSITION;
-    pkt->token_len = (COAP_HEADER_TOKEN_LEN_MASK & pkt->buffer[0]) >>
-                      COAP_HEADER_TOKEN_LEN_POSITION;
-    pkt->code = pkt->buffer[1];
-    pkt->mid = pkt->buffer[2] << 8 | pkt->buffer[3];
+    udp = (struct coap_udp_hdr *)data;
+    pkt->version = udp->version;
+    pkt->type = udp->type;
+    pkt->token_len = udp->token_len;
+    pkt->code = udp->code;
+    pkt->mid = ntohs(udp->id);
 
     if (pkt->version != 1) {
         coap_error_message = "CoAP version must be 1";

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/net/oic/src/messaging/coap/constants.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/constants.h b/net/oic/src/messaging/coap/constants.h
index 6cb37bc..e0c0f66 100644
--- a/net/oic/src/messaging/coap/constants.h
+++ b/net/oic/src/messaging/coap/constants.h
@@ -50,12 +50,19 @@ extern "C" {
 #define COAP_TOKEN_LEN 8 /* The maximum number of bytes for the Token */
 #define COAP_ETAG_LEN 8  /* The maximum number of bytes for the ETag */
 
-#define COAP_HEADER_VERSION_MASK 0xC0
-#define COAP_HEADER_VERSION_POSITION 6
-#define COAP_HEADER_TYPE_MASK 0x30
-#define COAP_HEADER_TYPE_POSITION 4
-#define COAP_HEADER_TOKEN_LEN_MASK 0x0F
-#define COAP_HEADER_TOKEN_LEN_POSITION 0
+struct coap_udp_hdr {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+    uint8_t  version:2;         /* protocol version */
+    uint8_t  type:2;            /* type flag */
+    uint8_t  token_len:4;       /* length of token */
+#else
+    uint8_t  token_len:4;       /* length of token */
+    uint8_t  type:2;            /* type flag */
+    uint8_t  version:2;         /* protocol version */
+#endif
+    uint8_t  code;          /* request (1-10) or response (value 40-255) */
+    uint16_t id;          /* transaction id */
+};
 
 #define COAP_HEADER_OPTION_DELTA_MASK 0xF0
 #define COAP_HEADER_OPTION_SHORT_LENGTH_MASK 0x0F

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 1145447..511b71c 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -223,6 +223,7 @@ coap_receive(oc_message_t *msg)
                  response, transaction->message->data)) == 0) {
             erbium_status_code = PACKET_SERIALIZATION_ERROR;
           }
+          transaction->type = response->type;
         }
       } else {
         erbium_status_code = SERVICE_UNAVAILABLE_5_03;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/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
index 711cfff..0202bb6 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -298,6 +298,7 @@ coap_notify_observers(oc_resource_t *resource,
                 transaction->message->length =
                   coap_serialize_message(notification,
                     transaction->message->data);
+                transaction->type = notification->type;
 
                 coap_send_transaction(transaction);
             }
@@ -307,12 +308,11 @@ coap_notify_observers(oc_resource_t *resource,
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_observe_handler(void *request, void *response, oc_resource_t *resource,
-                     oc_endpoint_t *endpoint)
+coap_observe_handler(coap_packet_t *coap_req, coap_packet_t *coap_res,
+                     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)) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/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
index ae63bf1..df58cc2 100644
--- a/net/oic/src/messaging/coap/observe.h
+++ b/net/oic/src/messaging/coap/observe.h
@@ -74,8 +74,8 @@ int coap_notify_observers(oc_resource_t *resource,
                           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);
+int coap_observe_handler(coap_packet_t *request, coap_packet_t *response,
+                         oc_resource_t *resource, oc_endpoint_t *endpoint);
 
 void coap_observe_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/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
index 42ca498..708fc8a 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -76,7 +76,6 @@ coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
             LOG("Created new transaction %d %d\n", mid, (int) message->length);
             t->mid = mid;
             t->retrans_counter = 0;
-
             t->message = message;
 
             /* save client address */
@@ -99,66 +98,62 @@ coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
 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_tmo =
-          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_tmo);
-      } else {
-        t->retrans_tmo <<= 1; /* double */
-        LOG("Doubled " OC_CLK_FMT "\n", t->retrans_tmo);
-      }
-
-      os_callout_reset(&t->retrans_timer, t->retrans_tmo);
-
-      coap_send_message(t->message);
-
-      oc_message_add_ref(t->message);
-
-      t = NULL;
-    } else {
-      /* timed out */
-      LOG("Timeout\n");
+    LOG("Sending transaction %u\n", t->mid);
+    bool confirmable = false;
+
+    confirmable = (COAP_TYPE_CON == t->type) ? 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_tmo =
+                  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_tmo);
+            } else {
+                t->retrans_tmo <<= 1; /* double */
+                LOG("Doubled " OC_CLK_FMT "\n", t->retrans_tmo);
+            }
+
+            os_callout_reset(&t->retrans_timer, t->retrans_tmo);
+
+            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);
+            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);
-      }
+            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);
+            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);
+        }
+    } else {
+        coap_send_message(t->message);
+        oc_message_add_ref(t->message);
 
-    coap_clear_transaction(t);
-  }
+        coap_clear_transaction(t);
+    }
 }
 /*---------------------------------------------------------------------------*/
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/325ce5f4/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
index 794b189..8768619 100644
--- a/net/oic/src/messaging/coap/transactions.h
+++ b/net/oic/src/messaging/coap/transactions.h
@@ -54,16 +54,15 @@ extern "C" {
     1
 
 /* container for transactions with message buffer and retransmission info */
-typedef struct coap_transaction
-{
-  SLIST_ENTRY(coap_transaction) next;
-
-  uint16_t mid;
-  uint8_t retrans_counter;
-  uint32_t retrans_tmo;
-  struct os_callout retrans_timer;
-  oc_message_t *message;
+typedef struct coap_transaction {
+    SLIST_ENTRY(coap_transaction) next;
 
+    uint16_t mid;
+    uint8_t retrans_counter;
+    coap_message_type_t type;
+    uint32_t retrans_tmo;
+    struct os_callout retrans_timer;
+    oc_message_t *message;
 } coap_transaction_t;
 
 void coap_register_as_transaction_handler(void);


[2/7] incubator-mynewt-core git commit: oic; change concurrent request count back to 2. This was causing issues when acting as oic client.

Posted by ma...@apache.org.
oic; change concurrent request count back to 2. This was causing issues
when acting as oic client.


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

Branch: refs/heads/develop
Commit: 14a1d9a606ca6e59d386ba2fa7ad173f1c8d69af
Parents: ff2e998
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 15:58:17 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:44 2016 -0800

----------------------------------------------------------------------
 net/oic/syscfg.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/14a1d9a6/net/oic/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/oic/syscfg.yml b/net/oic/syscfg.yml
index a9734ab..47e9802 100644
--- a/net/oic/syscfg.yml
+++ b/net/oic/syscfg.yml
@@ -44,7 +44,7 @@ syscfg.defs:
 
     OC_CONCURRENT_REQUESTS:
         description: 'Maximum number of concurrent requests'
-        value: 1
+        value: 2
 
     OC_MAX_PAYLOAD_SIZE:
         description: 'Maximum size of request/response PDUs'


[4/7] incubator-mynewt-core git commit: oic coap; in preparation of moving to os_mbuf.

Posted by ma...@apache.org.
oic coap; in preparation of moving to os_mbuf.


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

Branch: refs/heads/develop
Commit: b93aac57241256560623e2d43c135f0307676a7b
Parents: 325ce5f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Dec 1 11:14:30 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:45 2016 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/coap.c | 284 +++++++++++++++++----------------
 1 file changed, 143 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b93aac57/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 10629f3..144e10c 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -54,102 +54,102 @@ char *coap_error_message = "";
 static uint16_t
 coap_log_2(uint16_t value)
 {
-  uint16_t result = 0;
+    uint16_t result = 0;
 
-  do {
-    value = value >> 1;
-    result++;
-  } while (value);
+    do {
+        value = value >> 1;
+        result++;
+    } while (value);
 
-  return (result - 1);
+    return (result - 1);
 }
 /*---------------------------------------------------------------------------*/
 static uint32_t
 coap_parse_int_option(uint8_t *bytes, size_t length)
 {
-  uint32_t var = 0;
-  int i = 0;
-
-  while (i < length) {
-    var <<= 8;
-    var |= bytes[i++];
-  }
-  return var;
+    uint32_t var = 0;
+    int i = 0;
+
+    while (i < length) {
+        var <<= 8;
+        var |= bytes[i++];
+    }
+    return var;
 }
 /*---------------------------------------------------------------------------*/
 static uint8_t
 coap_option_nibble(unsigned int value)
 {
-  if (value < 13) {
-    return value;
-  } else if (value <= 0xFF + 13) {
-    return 13;
-  } else {
-    return 14;
-  }
+    if (value < 13) {
+        return value;
+    } else if (value <= 0xFF + 13) {
+        return 13;
+    } else {
+        return 14;
+    }
 }
 /*---------------------------------------------------------------------------*/
 static size_t
 coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
 {
-  size_t written = 0;
+    size_t written = 0;
 
-  buffer[0] = coap_option_nibble(delta) << 4 | coap_option_nibble(length);
+    buffer[0] = coap_option_nibble(delta) << 4 | coap_option_nibble(length);
 
-  if (delta > 268) {
-    buffer[++written] = ((delta - 269) >> 8) & 0xff;
-    buffer[++written] = (delta - 269) & 0xff;
-  } else if (delta > 12) {
-    buffer[++written] = (delta - 13);
-  }
+    if (delta > 268) {
+        buffer[++written] = ((delta - 269) >> 8) & 0xff;
+        buffer[++written] = (delta - 269) & 0xff;
+    } else if (delta > 12) {
+        buffer[++written] = (delta - 13);
+    }
 
-  if (length > 268) {
-    buffer[++written] = ((length - 269) >> 8) & 0xff;
-    buffer[++written] = (length - 269) & 0xff;
-  } else if (length > 12) {
-    buffer[++written] = (length - 13);
-  }
+    if (length > 268) {
+        buffer[++written] = ((length - 269) >> 8) & 0xff;
+        buffer[++written] = (length - 269) & 0xff;
+    } else if (length > 12) {
+        buffer[++written] = (length - 13);
+    }
 
-  LOG("WRITTEN %zu B opt header\n", 1 + written);
+    LOG("WRITTEN %zu B opt header\n", 1 + written);
 
-  return ++written;
+    return ++written;
 }
 /*---------------------------------------------------------------------------*/
 static size_t
 coap_serialize_int_option(unsigned int number, unsigned int current_number,
                           uint8_t *buffer, uint32_t value)
 {
-  size_t i = 0;
-
-  if (0xFF000000 & value) {
-    ++i;
-  }
-  if (0xFFFF0000 & value) {
-    ++i;
-  }
-  if (0xFFFFFF00 & value) {
-    ++i;
-  }
-  if (0xFFFFFFFF & value) {
-    ++i;
-  }
-  LOG("OPTION %u (delta %u, len %zu)\n", number, number - current_number, i);
-
-  i = coap_set_option_header(number - current_number, i, buffer);
-
-  if (0xFF000000 & value) {
-    buffer[i++] = (uint8_t)(value >> 24);
-  }
-  if (0xFFFF0000 & value) {
-    buffer[i++] = (uint8_t)(value >> 16);
-  }
-  if (0xFFFFFF00 & value) {
-    buffer[i++] = (uint8_t)(value >> 8);
-  }
-  if (0xFFFFFFFF & value) {
-    buffer[i++] = (uint8_t)(value);
-  }
-  return i;
+    size_t i = 0;
+
+    if (0xFF000000 & value) {
+        ++i;
+    }
+    if (0xFFFF0000 & value) {
+        ++i;
+    }
+    if (0xFFFFFF00 & value) {
+        ++i;
+    }
+    if (0xFFFFFFFF & value) {
+        ++i;
+    }
+    LOG("OPTION %u (delta %u, len %zu)\n", number, number - current_number, i);
+
+    i = coap_set_option_header(number - current_number, i, buffer);
+
+    if (0xFF000000 & value) {
+        buffer[i++] = (uint8_t)(value >> 24);
+    }
+    if (0xFFFF0000 & value) {
+        buffer[i++] = (uint8_t)(value >> 16);
+    }
+    if (0xFFFFFF00 & value) {
+        buffer[i++] = (uint8_t)(value >> 8);
+    }
+    if (0xFFFFFFFF & value) {
+        buffer[i++] = (uint8_t)(value);
+    }
+    return i;
 }
 /*---------------------------------------------------------------------------*/
 static size_t
@@ -157,67 +157,68 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number,
                             uint8_t *buffer, uint8_t *array, size_t length,
                             char split_char)
 {
-  size_t i = 0;
+    size_t i = 0;
 
-  LOG("ARRAY type %u, len %zu, full [%.*s]\n", number, length, (int)length,
+    LOG("ARRAY type %u, len %zu, full [%.*s]\n", number, length, (int)length,
       array);
 
-  if (split_char != '\0') {
-    int j;
-    uint8_t *part_start = array;
-    uint8_t *part_end = NULL;
-    size_t temp_length;
-
-    for (j = 0; j <= length + 1; ++j) {
-      LOG("STEP %u/%zu (%c)\n", j, length, array[j]);
-      if (array[j] == split_char || j == length) {
-        part_end = array + j;
-        temp_length = part_end - part_start;
-
-        i += coap_set_option_header(number - current_number, temp_length,
+    if (split_char != '\0') {
+        int j;
+        uint8_t *part_start = array;
+        uint8_t *part_end = NULL;
+        size_t temp_length;
+
+        for (j = 0; j <= length + 1; ++j) {
+            LOG("STEP %u/%zu (%c)\n", j, length, array[j]);
+            if (array[j] == split_char || j == length) {
+                part_end = array + j;
+                temp_length = part_end - part_start;
+
+                i += coap_set_option_header(number - current_number,
+                                            temp_length, &buffer[i]);
+                memcpy(&buffer[i], part_start, temp_length);
+                i += temp_length;
+
+                LOG("OPTION type %u, delta %u, len %zu, part [%.*s]\n", number,
+                    number - current_number, i, (int)temp_length, part_start);
+
+                ++j; /* skip the splitter */
+                current_number = number;
+                part_start = array + j;
+            }
+        } /* for */
+    } else {
+        i += coap_set_option_header(number - current_number, length,
                                     &buffer[i]);
-        memcpy(&buffer[i], part_start, temp_length);
-        i += temp_length;
+        memcpy(&buffer[i], array, length);
+        i += length;
 
-        LOG("OPTION type %u, delta %u, len %zu, part [%.*s]\n", number,
-            number - current_number, i, (int)temp_length, part_start);
-
-        ++j; /* skip the splitter */
-        current_number = number;
-        part_start = array + j;
-      }
-    } /* for */
-  } else {
-    i += coap_set_option_header(number - current_number, length, &buffer[i]);
-    memcpy(&buffer[i], array, length);
-    i += length;
-
-    LOG("OPTION type %u, delta %u, len %zu\n", number, number - current_number,
-        length);
-  }
+        LOG("OPTION type %u, delta %u, len %zu\n", number,
+            number - current_number, length);
+    }
 
-  return i;
+    return i;
 }
 /*---------------------------------------------------------------------------*/
 static void
 coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option,
                         size_t option_len, char separator)
 {
-  /* merge multiple options */
-  if (*dst_len > 0) {
-    /* dst already contains an option: concatenate */
-    (*dst)[*dst_len] = separator;
-    *dst_len += 1;
-
-    /* memmove handles 2-byte option headers */
-    memmove((*dst) + (*dst_len), option, option_len);
-
-    *dst_len += option_len;
-  } else {
-    /* dst is empty: set to option */
-    *dst = (char *)option;
-    *dst_len = option_len;
-  }
+    /* merge multiple options */
+    if (*dst_len > 0) {
+        /* dst already contains an option: concatenate */
+        (*dst)[*dst_len] = separator;
+        *dst_len += 1;
+
+        /* memmove handles 2-byte option headers */
+        memmove((*dst) + (*dst_len), option, option_len);
+
+        *dst_len += option_len;
+    } else {
+        /* dst is empty: set to option */
+        *dst = (char *)option;
+        *dst_len = option_len;
+    }
 }
 /*---------------------------------------------------------------------------*/
 #if 0
@@ -225,35 +226,35 @@ static int
 coap_get_variable(const char *buffer, size_t length, const char *name,
 		  const char **output)
 {
-  const char *start = NULL;
-  const char *end = NULL;
-  const char *value_end = NULL;
-  size_t name_len = 0;
+    const char *start = NULL;
+    const char *end = NULL;
+    const char *value_end = NULL;
+    size_t name_len = 0;
 
-  /*initialize the output buffer first */
-  *output = 0;
+    /*initialize the output buffer first */
+    *output = 0;
 
-  name_len = strlen(name);
-  end = buffer + length;
+    name_len = strlen(name);
+    end = buffer + length;
 
-  for(start = buffer; start + name_len < end; ++start) {
-    if((start == buffer || start[-1] == '&') && start[name_len] == '='
-       && strncmp(name, start, name_len) == 0) {
+    for(start = buffer; start + name_len < end; ++start) {
+        if ((start == buffer || start[-1] == '&') && start[name_len] == '=' &&
+          strncmp(name, start, name_len) == 0) {
 
-      /* Point start to variable value */
-      start += name_len + 1;
+            /* Point start to variable value */
+            start += name_len + 1;
 
-      /* Point end to the end of the value */
-      value_end = (const char *)memchr(start, '&', end - start);
-      if(value_end == NULL) {
-	value_end = end;
-      }
-      *output = start;
+            /* Point end to the end of the value */
+            value_end = (const char *)memchr(start, '&', end - start);
+            if(value_end == NULL) {
+                value_end = end;
+            }
+            *output = start;
 
-      return value_end - start;
+            return value_end - start;
+        }
     }
-  }
-  return 0;
+    return 0;
 }
 #endif
 /*---------------------------------------------------------------------------*/
@@ -284,6 +285,7 @@ coap_init_message(coap_packet_t *coap_pkt, coap_message_type_t type,
     coap_pkt->mid = mid;
 }
 /*---------------------------------------------------------------------------*/
+
 size_t
 coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
 {
@@ -398,9 +400,9 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
 void
 coap_send_message(oc_message_t *message)
 {
-  LOG("-sending OCF message (%u)-\n", (unsigned int) message->length);
+    LOG("-sending OCF message (%u)-\n", (unsigned int) message->length);
 
-  oc_send_message(message);
+    oc_send_message(message);
 }
 
 /*---------------------------------------------------------------------------*/


[6/7] incubator-mynewt-core git commit: log_reboot; use hal_reset_cause when recording reboot reason at bootup.

Posted by ma...@apache.org.
log_reboot; use hal_reset_cause when recording reboot reason at
bootup.


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

Branch: refs/heads/develop
Commit: 35e11e67281d4f2470f8377d8145538bdcc09579
Parents: fe3c27f
Author: System Administrator <ma...@runtime.io>
Authored: Fri Dec 2 11:41:39 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:45 2016 -0800

----------------------------------------------------------------------
 apps/slinky/src/main.c                 |  2 +-
 apps/slinky_oic/src/main.c             |  2 +-
 apps/splitty/src/main.c                |  2 +-
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c  |  2 +-
 sys/reboot/include/reboot/log_reboot.h | 19 +++++++++----------
 sys/reboot/src/log_reboot.c            |  6 +++---
 6 files changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35e11e67/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index f4da51e..342a901 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -302,7 +302,7 @@ main(int argc, char **argv)
 
     conf_load();
 
-    log_reboot(HARD_REBOOT);
+    log_reboot(hal_reset_cause());
 
 #if MYNEWT_VAL(SPLIT_LOADER)
     {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35e11e67/apps/slinky_oic/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky_oic/src/main.c b/apps/slinky_oic/src/main.c
index afadd33..06c7bef 100755
--- a/apps/slinky_oic/src/main.c
+++ b/apps/slinky_oic/src/main.c
@@ -294,7 +294,7 @@ main(int argc, char **argv)
 
     conf_load();
 
-    log_reboot(HARD_REBOOT);
+    log_reboot(hal_reset_cause());
 
 #if MYNEWT_VAL(SPLIT_LOADER)
     {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35e11e67/apps/splitty/src/main.c
----------------------------------------------------------------------
diff --git a/apps/splitty/src/main.c b/apps/splitty/src/main.c
index fcb18c6..956ed1f 100755
--- a/apps/splitty/src/main.c
+++ b/apps/splitty/src/main.c
@@ -228,7 +228,7 @@ main(int argc, char **argv)
 
     conf_load();
 
-    log_reboot(HARD_REBOOT);
+    log_reboot(hal_reset_cause());
 
     init_tasks();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35e11e67/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index 1dddcc3..c645ee0 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -323,7 +323,7 @@ nmgr_reset(struct mgmt_cbuf *cb)
 {
     os_callout_init(&nmgr_reset_callout, mgmt_evq_get(), nmgr_reset_tmo, NULL);
 
-    log_reboot(SOFT_REBOOT);
+    log_reboot(HAL_RESET_SOFT);
     os_callout_reset(&nmgr_reset_callout, OS_TICKS_PER_SEC / 4);
 
     mgmt_cbuf_setoerr(cb, OS_OK);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35e11e67/sys/reboot/include/reboot/log_reboot.h
----------------------------------------------------------------------
diff --git a/sys/reboot/include/reboot/log_reboot.h b/sys/reboot/include/reboot/log_reboot.h
index eead387..396299c 100644
--- a/sys/reboot/include/reboot/log_reboot.h
+++ b/sys/reboot/include/reboot/log_reboot.h
@@ -23,18 +23,17 @@
 extern "C" {
 #endif
 
-#define  SOFT_REBOOT (0)
-#define  HARD_REBOOT (1)
-#define  GEN_CORE    (2)
-
-#define REBOOT_REASON_STR(reason) \
-    (SOFT_REBOOT  == reason ? "SOFT"     :\
-    (HARD_REBOOT  == reason ? "HARD"     :\
-    (GEN_CORE     == reason ? "GEN_CORE" :\
-     "UNKNOWN")))
+#include <hal/hal_system.h>
+#define REBOOT_REASON_STR(reason)                                       \
+    (reason == HAL_RESET_POR ? "HARD" :                                 \
+      (reason == HAL_RESET_PIN ? "RESET_PIN" :                          \
+        (reason == HAL_RESET_WATCHDOG ? "WDOG" :                        \
+          (reason == HAL_RESET_SOFT ? "SOFT" :                          \
+            (reason == HAL_RESET_BROWNOUT ? "BROWNOUT" :                \
+              "UNKNOWN")))))
 
 int reboot_init_handler(int log_store_type, uint8_t entries);
-int log_reboot(int reason);
+int log_reboot(enum hal_reset_reason);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35e11e67/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 0015157..7a02414 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -130,7 +130,7 @@ reboot_init_handler(int log_store_type, uint8_t entries)
  * @return 0 on success; non-zero on failure
  */
 int
-log_reboot(int reason)
+log_reboot(enum hal_reset_reason reason)
 {
     int rc;
     char str[12] = {0};
@@ -149,7 +149,7 @@ log_reboot(int reason)
 
     reboot_tmp_cnt = reboot_cnt;
 
-    if (reason == SOFT_REBOOT) {
+    if (reason == HAL_RESET_SOFT) {
         /*
          * Save reboot count as soft reboot cnt if the reason is
          * a soft reboot
@@ -158,7 +158,7 @@ log_reboot(int reason)
         conf_save_one("reboot/soft_reboot",
                       conf_str_from_value(CONF_INT16, &reboot_tmp_cnt,
                                           str, sizeof(str)));
-    } else if (reason == HARD_REBOOT) {
+    } else {
         conf_save_one("reboot/soft_reboot", "0");
         if (soft_reboot) {
             /* No need to log as it's not a hard reboot */


[3/7] incubator-mynewt-core git commit: oic; in preparation of moving to use os_mbuf.

Posted by ma...@apache.org.
oic; in preparation of moving to use os_mbuf.


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

Branch: refs/heads/develop
Commit: ff2e9981c6087aa9cfb5d5ec9c66e886077b82b1
Parents: 9f93770
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 15:51:09 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:44 2016 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/coap.c | 670 ++++++++++++++++-----------------
 net/oic/src/messaging/coap/coap.h |   8 +-
 2 files changed, 334 insertions(+), 344 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ff2e9981/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 6412c71..8117afb 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -285,118 +285,118 @@ coap_init_message(coap_packet_t *coap_pkt, coap_message_type_t type,
 }
 /*---------------------------------------------------------------------------*/
 size_t
-coap_serialize_message(coap_packet_t *coap_pkt, uint8_t *buffer)
+coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
 {
-  uint8_t *option;
-  unsigned int current_number = 0;
-
-  /* Initialize */
-  coap_pkt->buffer = buffer;
-  coap_pkt->version = 1;
-
-  LOG("-Serializing MID %u to %p, ", coap_pkt->mid, coap_pkt->buffer);
-
-  /* set header fields */
-  coap_pkt->buffer[0] = 0x00;
-  coap_pkt->buffer[0] |= COAP_HEADER_VERSION_MASK &
-                         (coap_pkt->version) << COAP_HEADER_VERSION_POSITION;
-  coap_pkt->buffer[0] |=
-    COAP_HEADER_TYPE_MASK & (coap_pkt->type) << COAP_HEADER_TYPE_POSITION;
-  coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK &
-                         (coap_pkt->token_len)
+    uint8_t *option;
+    unsigned int current_number = 0;
+
+    /* Initialize */
+    pkt->buffer = buffer;
+    pkt->version = 1;
+
+    LOG("-Serializing MID %u to %p, ", pkt->mid, pkt->buffer);
+
+    /* set header fields */
+    pkt->buffer[0] = 0x00;
+    pkt->buffer[0] |= COAP_HEADER_VERSION_MASK &
+                         (pkt->version) << COAP_HEADER_VERSION_POSITION;
+    pkt->buffer[0] |=
+      COAP_HEADER_TYPE_MASK & (pkt->type) << COAP_HEADER_TYPE_POSITION;
+    pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK &
+                         (pkt->token_len)
                            << COAP_HEADER_TOKEN_LEN_POSITION;
-  coap_pkt->buffer[1] = coap_pkt->code;
-  coap_pkt->buffer[2] = (uint8_t)((coap_pkt->mid) >> 8);
-  coap_pkt->buffer[3] = (uint8_t)(coap_pkt->mid);
-
-  /* empty packet, dont need to do more stuff */
-  if (!coap_pkt->code) {
-    LOG("-Done serializing empty message at %p-\n", coap_pkt->buffer);
-    return 4;
-  }
+    pkt->buffer[1] = pkt->code;
+    pkt->buffer[2] = (uint8_t)((pkt->mid) >> 8);
+    pkt->buffer[3] = (uint8_t)(pkt->mid);
+
+    /* empty packet, dont need to do more stuff */
+    if (!pkt->code) {
+        LOG("-Done serializing empty message at %p-\n", pkt->buffer);
+        return 4;
+    }
 
-  /* set Token */
-  LOG("Token (len %u)", coap_pkt->token_len);
-  option = coap_pkt->buffer + COAP_HEADER_LEN;
-  for (current_number = 0; current_number < coap_pkt->token_len;
-       ++current_number) {
-    LOG(" %02X", coap_pkt->token[current_number]);
-    *option = coap_pkt->token[current_number];
-    ++option;
-  }
-  LOG("-\n");
+    /* set Token */
+    LOG("Token (len %u)", pkt->token_len);
+    option = pkt->buffer + COAP_HEADER_LEN;
+    for (current_number = 0; current_number < pkt->token_len;
+         ++current_number) {
+        LOG(" %02X", pkt->token[current_number]);
+        *option = pkt->token[current_number];
+        ++option;
+    }
+    LOG("-\n");
 
-  /* Serialize options */
-  current_number = 0;
+    /* Serialize options */
+    current_number = 0;
 
-  LOG("-Serializing options at %p-\n", option);
+    LOG("-Serializing options at %p-\n", option);
 #if 0
-  /* The options must be serialized in the order of their number */
-  COAP_SERIALIZE_BYTE_OPTION(COAP_OPTION_IF_MATCH, if_match, "If-Match");
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_URI_HOST, uri_host, '\0',
-			       "Uri-Host");
-  COAP_SERIALIZE_BYTE_OPTION(COAP_OPTION_ETAG, etag, "ETag");
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_IF_NONE_MATCH,
-			    content_format - coap_pkt-> content_format /* hack to get a zero field */,
-			    "If-None-Match");
+    /* The options must be serialized in the order of their number */
+    COAP_SERIALIZE_BYTE_OPTION(pkt, COAP_OPTION_IF_MATCH, if_match, "If-Match");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_URI_HOST, uri_host, '\0',
+                                 "Uri-Host");
+    COAP_SERIALIZE_BYTE_OPTION(pkt, COAP_OPTION_ETAG, etag, "ETag");
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_IF_NONE_MATCH,
+        content_format - pkt-> content_format /* hack to get a zero field */,
+                              "If-None-Match");
 #endif
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_OBSERVE, observe, "Observe");
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_OBSERVE, observe, "Observe");
 #if 0
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_URI_PORT, uri_port, "Uri-Port");
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_LOCATION_PATH, location_path,
-			       '/', "Location-Path");
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_URI_PORT, uri_port, "Uri-Port");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_LOCATION_PATH, location_path,
+                                 '/', "Location-Path");
 #endif
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_URI_PATH, uri_path, '/', "Uri-Path");
-  LOG("Serialize content format: %d\n", coap_pkt->content_format);
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_CONTENT_FORMAT, content_format,
-                            "Content-Format");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_URI_PATH, uri_path, '/',
+                                 "Uri-Path");
+    LOG("Serialize content format: %d\n", pkt->content_format);
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_CONTENT_FORMAT, content_format,
+                              "Content-Format");
 #if 0
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_MAX_AGE, max_age, "Max-Age");
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_MAX_AGE, max_age, "Max-Age");
 #endif
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_URI_QUERY, uri_query, '&',
-                               "Uri-Query");
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_ACCEPT, accept, "Accept");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_URI_QUERY, uri_query, '&',
+                                 "Uri-Query");
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_ACCEPT, accept, "Accept");
 #if 0
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_LOCATION_QUERY, location_query,
-			       '&', "Location-Query");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_LOCATION_QUERY,
+                                 location_query, '&', "Location-Query");
 #endif
-  COAP_SERIALIZE_BLOCK_OPTION(COAP_OPTION_BLOCK2, block2, "Block2");
-  COAP_SERIALIZE_BLOCK_OPTION(COAP_OPTION_BLOCK1, block1, "Block1");
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_SIZE2, size2, "Size2");
+    COAP_SERIALIZE_BLOCK_OPTION(pkt, COAP_OPTION_BLOCK2, block2, "Block2");
+    COAP_SERIALIZE_BLOCK_OPTION(pkt, COAP_OPTION_BLOCK1, block1, "Block1");
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_SIZE2, size2, "Size2");
 #if 0
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_PROXY_URI, proxy_uri, '\0',
-			       "Proxy-Uri");
-  COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_PROXY_SCHEME, proxy_scheme,
-			       '\0', "Proxy-Scheme");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_PROXY_URI, proxy_uri, '\0',
+                                 "Proxy-Uri");
+    COAP_SERIALIZE_STRING_OPTION(pkt, COAP_OPTION_PROXY_SCHEME, proxy_scheme,
+                                 '\0', "Proxy-Scheme");
 #endif
-  COAP_SERIALIZE_INT_OPTION(COAP_OPTION_SIZE1, size1, "Size1");
-
-  LOG("-Done serializing at %p----\n", option);
-
-  /* Pack payload */
-  if ((option - coap_pkt->buffer) <= COAP_MAX_HEADER_SIZE) {
-    /* Payload marker */
-    if (coap_pkt->payload_len) {
-      *option = 0xFF;
-      ++option;
+    COAP_SERIALIZE_INT_OPTION(pkt, COAP_OPTION_SIZE1, size1, "Size1");
+
+    LOG("-Done serializing at %p----\n", option);
+
+    /* Pack payload */
+    if ((option - pkt->buffer) <= COAP_MAX_HEADER_SIZE) {
+        /* Payload marker */
+        if (pkt->payload_len) {
+            *option = 0xFF;
+            ++option;
+        }
+        memmove(option, pkt->payload, pkt->payload_len);
+    } else {
+        /* an error occurred: caller must check for !=0 */
+        pkt->buffer = NULL;
+        coap_error_message = "Serialized header exceeds COAP_MAX_HEADER_SIZE";
+        return 0;
     }
-    memmove(option, coap_pkt->payload, coap_pkt->payload_len);
-  } else {
-    /* an error occurred: caller must check for !=0 */
-    coap_pkt->buffer = NULL;
-    coap_error_message = "Serialized header exceeds COAP_MAX_HEADER_SIZE";
-    return 0;
-  }
 
-  LOG("-Done %u B (header len %u, payload len %u)-\n",
-      (unsigned int)(coap_pkt->payload_len + option - buffer),
-      (unsigned int)(option - buffer), (unsigned int)coap_pkt->payload_len);
+    LOG("-Done %u B (header len %u, payload len %u)-\n",
+        (unsigned int)(pkt->payload_len + option - buffer),
+        (unsigned int)(option - buffer), (unsigned int)pkt->payload_len);
 
-  LOG("Dump [0x%02X %02X %02X %02X  %02X %02X %02X %02X]\n",
-      coap_pkt->buffer[0], coap_pkt->buffer[1], coap_pkt->buffer[2],
-      coap_pkt->buffer[3], coap_pkt->buffer[4], coap_pkt->buffer[5],
-      coap_pkt->buffer[6], coap_pkt->buffer[7]);
-  return (option - buffer) + coap_pkt->payload_len; /* packet length */
+    LOG("Dump [0x%02X %02X %02X %02X  %02X %02X %02X %02X]\n",
+        pkt->buffer[0], pkt->buffer[1], pkt->buffer[2], pkt->buffer[3],
+        pkt->buffer[4], pkt->buffer[5], pkt->buffer[6], pkt->buffer[7]);
+    return (option - buffer) + pkt->payload_len; /* packet length */
 }
 /*---------------------------------------------------------------------------*/
 void
@@ -406,270 +406,260 @@ coap_send_message(oc_message_t *message)
 
   oc_send_message(message);
 }
+
 /*---------------------------------------------------------------------------*/
 coap_status_t
-coap_parse_message(coap_packet_t *coap_pkt, uint8_t *data, uint16_t data_len)
+coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
 {
-  /* initialize packet */
-  memset(coap_pkt, 0, sizeof(coap_packet_t));
-  /* pointer to packet bytes */
-  coap_pkt->buffer = data;
-  /* parse header fields */
-  coap_pkt->version = (COAP_HEADER_VERSION_MASK & coap_pkt->buffer[0]) >>
-                      COAP_HEADER_VERSION_POSITION;
-  coap_pkt->type =
-    (COAP_HEADER_TYPE_MASK & coap_pkt->buffer[0]) >> COAP_HEADER_TYPE_POSITION;
-  coap_pkt->token_len = (COAP_HEADER_TOKEN_LEN_MASK & coap_pkt->buffer[0]) >>
-                        COAP_HEADER_TOKEN_LEN_POSITION;
-  coap_pkt->code = coap_pkt->buffer[1];
-  coap_pkt->mid = coap_pkt->buffer[2] << 8 | coap_pkt->buffer[3];
-
-  if (coap_pkt->version != 1) {
-    coap_error_message = "CoAP version must be 1";
-    return BAD_REQUEST_4_00;
-  }
-
-  if (coap_pkt->token_len > COAP_TOKEN_LEN) {
-    coap_error_message = "Token Length must not be more than 8";
-    return BAD_REQUEST_4_00;
-  }
-
-  uint8_t *current_option = data + COAP_HEADER_LEN;
-
-  memcpy(coap_pkt->token, current_option, coap_pkt->token_len);
-  LOG("Token (len %u) [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
-      coap_pkt->token_len, coap_pkt->token[0], coap_pkt->token[1],
-      coap_pkt->token[2], coap_pkt->token[3], coap_pkt->token[4],
-      coap_pkt->token[5], coap_pkt->token[6],
-      coap_pkt->token[7]); /*FIXME always prints 8 bytes */
-
-  /* parse options */
-  memset(coap_pkt->options, 0, sizeof(coap_pkt->options));
-  current_option += coap_pkt->token_len;
-
-  unsigned int option_number = 0;
-  unsigned int option_delta = 0;
-  size_t option_length = 0;
-
-  while (current_option < data + data_len) {
-    /* payload marker 0xFF, currently only checking for 0xF* because rest is
-     * reserved */
-    if ((current_option[0] & 0xF0) == 0xF0) {
-      coap_pkt->payload = ++current_option;
-      coap_pkt->payload_len = data_len - (coap_pkt->payload - data);
-
-      /* also for receiving, the Erbium upper bound is MAX_PAYLOAD_SIZE */
-      if (coap_pkt->payload_len > MAX_PAYLOAD_SIZE) {
-        coap_pkt->payload_len = MAX_PAYLOAD_SIZE;
-        /* null-terminate payload */
-      }
-      coap_pkt->payload[coap_pkt->payload_len] = '\0';
-
-      break;
-    }
-
-    option_delta = current_option[0] >> 4;
-    option_length = current_option[0] & 0x0F;
-    ++current_option;
-
-    if (option_delta == 13) {
-      option_delta += current_option[0];
-      ++current_option;
-    } else if (option_delta == 14) {
-      option_delta += 255;
-      option_delta += current_option[0] << 8;
-      ++current_option;
-      option_delta += current_option[0];
-      ++current_option;
+    uint8_t *current_option;
+    unsigned int option_number = 0;
+    unsigned int option_delta = 0;
+    size_t option_length = 0;
+
+    /* initialize packet */
+    memset(pkt, 0, sizeof(coap_packet_t));
+    /* pointer to packet bytes */
+    pkt->buffer = data;
+
+    /* parse header fields */
+    pkt->version = (COAP_HEADER_VERSION_MASK & pkt->buffer[0]) >>
+                    COAP_HEADER_VERSION_POSITION;
+    pkt->type = (COAP_HEADER_TYPE_MASK & pkt->buffer[0]) >>
+                 COAP_HEADER_TYPE_POSITION;
+    pkt->token_len = (COAP_HEADER_TOKEN_LEN_MASK & pkt->buffer[0]) >>
+                      COAP_HEADER_TOKEN_LEN_POSITION;
+    pkt->code = pkt->buffer[1];
+    pkt->mid = pkt->buffer[2] << 8 | pkt->buffer[3];
+
+    if (pkt->version != 1) {
+        coap_error_message = "CoAP version must be 1";
+        return BAD_REQUEST_4_00;
     }
-
-    if (option_length == 13) {
-      option_length += current_option[0];
-      ++current_option;
-    } else if (option_length == 14) {
-      option_length += 255;
-      option_length += current_option[0] << 8;
-      ++current_option;
-      option_length += current_option[0];
-      ++current_option;
+    if (pkt->token_len > COAP_TOKEN_LEN) {
+        coap_error_message = "Token Length must not be more than 8";
+        return BAD_REQUEST_4_00;
     }
 
-    option_number += option_delta;
-
-    if (option_number < COAP_OPTION_SIZE1) {
-      LOG("OPTION %u (delta %u, len %zu): ", option_number, option_delta,
-          option_length);
-      SET_OPTION(coap_pkt, option_number);
-    }
-
-    switch (option_number) {
-    case COAP_OPTION_CONTENT_FORMAT:
-      coap_pkt->content_format =
-        coap_parse_int_option(current_option, option_length);
-      LOG("Content-Format [%u]\n", coap_pkt->content_format);
-      break;
-    case COAP_OPTION_MAX_AGE:
-      coap_pkt->max_age = coap_parse_int_option(current_option, option_length);
-      LOG("Max-Age [%lu]\n", (unsigned long)coap_pkt->max_age);
-      break;
+    current_option = data + COAP_HEADER_LEN;
+
+    memcpy(pkt->token, current_option, pkt->token_len);
+    LOG("Token (len %u) [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
+      pkt->token_len,
+      pkt->token[0], pkt->token[1], pkt->token[2], pkt->token[3], pkt->token[4],
+      pkt->token[5], pkt->token[6], pkt->token[7]); /* XXX always prints 8 */
+
+    /* parse options */
+    memset(pkt->options, 0, sizeof(pkt->options));
+    current_option += pkt->token_len;
+
+    while (current_option < data + data_len) {
+        /* payload marker 0xFF, currently only checking for 0xF* because rest is
+         * reserved */
+        if ((current_option[0] & 0xF0) == 0xF0) {
+            pkt->payload = ++current_option;
+            pkt->payload_len = data_len - (pkt->payload - data);
+
+            /* also for receiving, the Erbium upper bound is MAX_PAYLOAD_SIZE */
+            if (pkt->payload_len > MAX_PAYLOAD_SIZE) {
+                pkt->payload_len = MAX_PAYLOAD_SIZE;
+                /* null-terminate payload */
+            }
+            pkt->payload[pkt->payload_len] = '\0';
+
+            break;
+        }
+
+        option_delta = current_option[0] >> 4;
+        option_length = current_option[0] & 0x0F;
+        ++current_option;
+
+        if (option_delta == 13) {
+            option_delta += current_option[0];
+            ++current_option;
+        } else if (option_delta == 14) {
+            option_delta += 255;
+            option_delta += current_option[0] << 8;
+            ++current_option;
+            option_delta += current_option[0];
+            ++current_option;
+        }
+
+        if (option_length == 13) {
+            option_length += current_option[0];
+            ++current_option;
+        } else if (option_length == 14) {
+            option_length += 255;
+            option_length += current_option[0] << 8;
+            ++current_option;
+            option_length += current_option[0];
+            ++current_option;
+        }
+
+        option_number += option_delta;
+
+        if (option_number < COAP_OPTION_SIZE1) {
+            LOG("OPTION %u (delta %u, len %zu): ", option_number, option_delta,
+              option_length);
+            SET_OPTION(pkt, option_number);
+        }
+
+        switch (option_number) {
+        case COAP_OPTION_CONTENT_FORMAT:
+            pkt->content_format =
+              coap_parse_int_option(current_option, option_length);
+            LOG("Content-Format [%u]\n", pkt->content_format);
+            break;
+        case COAP_OPTION_MAX_AGE:
+            pkt->max_age = coap_parse_int_option(current_option, option_length);
+            LOG("Max-Age [%lu]\n", (unsigned long)pkt->max_age);
+            break;
 #if 0
-    case COAP_OPTION_ETAG:
-      coap_pkt->etag_len = MIN(COAP_ETAG_LEN,
-			       option_length);
-      memcpy(coap_pkt->etag, current_option,
-	     coap_pkt->etag_len);
-      LOG("ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
-	  coap_pkt->etag_len, coap_pkt->etag[0], coap_pkt->etag[1],
-	  coap_pkt->etag[2], coap_pkt->etag[3], coap_pkt->etag[4],
-	  coap_pkt->etag[5], coap_pkt->etag[6], coap_pkt->etag[7]
-	 ); /*FIXME always prints 8 bytes */
-      break;
+        case COAP_OPTION_ETAG:
+            pkt->etag_len = MIN(COAP_ETAG_LEN, option_length);
+            memcpy(pkt->etag, current_option, pkt->etag_len);
+            LOG("ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
+              pkt->etag_len,
+              pkt->etag[0], pkt->etag[1], pkt->etag[2], pkt->etag[3],
+              pkt->etag[4], pkt->etag[5], pkt->etag[6], pkt->etag[7]);
+            /*FIXME always prints 8 bytes */
+            break;
 #endif
-    case COAP_OPTION_ACCEPT:
-      coap_pkt->accept = coap_parse_int_option(current_option, option_length);
-      LOG("Accept [%u]\n", coap_pkt->accept);
-      break;
+        case COAP_OPTION_ACCEPT:
+            pkt->accept = coap_parse_int_option(current_option, option_length);
+            LOG("Accept [%u]\n", pkt->accept);
+            break;
 #if 0
-    case COAP_OPTION_IF_MATCH:
-      /* TODO support multiple ETags */
-      coap_pkt->if_match_len = MIN(COAP_ETAG_LEN,
-				   option_length);
-      memcpy(coap_pkt->if_match, current_option,
-	     coap_pkt->if_match_len);
-      LOG("If-Match %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
-	  coap_pkt->if_match_len, coap_pkt->if_match[0],
-	  coap_pkt->if_match[1], coap_pkt->if_match[2],
-	  coap_pkt->if_match[3], coap_pkt->if_match[4],
-	  coap_pkt->if_match[5], coap_pkt->if_match[6],
-	  coap_pkt->if_match[7]
-	 ); /* FIXME always prints 8 bytes */
-      break;
-    case COAP_OPTION_IF_NONE_MATCH:
-      coap_pkt->if_none_match = 1;
-      LOG("If-None-Match\n");
-      break;
-
-    case COAP_OPTION_PROXY_URI:
+        case COAP_OPTION_IF_MATCH:
+            /* TODO support multiple ETags */
+            pkt->if_match_len = MIN(COAP_ETAG_LEN, option_length);
+            memcpy(pkt->if_match, current_option, pkt->if_match_len);
+            LOG("If-Match %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
+              pkt->if_match_len, pkt->if_match[0], pkt->if_match[1],
+              pkt->if_match[2], pkt->if_match[3], pkt->if_match[4],
+              pkt->if_match[5], pkt->if_match[6], pkt->if_match[7]);
+            break;
+        case COAP_OPTION_IF_NONE_MATCH:
+            pkt->if_none_match = 1;
+            LOG("If-None-Match\n");
+            break;
+
+        case COAP_OPTION_PROXY_URI:
 #if COAP_PROXY_OPTION_PROCESSING
-      coap_pkt->proxy_uri = (char *)current_option;
-      coap_pkt->proxy_uri_len = option_length;
+            pkt->proxy_uri = (char *)current_option;
+            pkt->proxy_uri_len = option_length;
 #endif
-      LOG("Proxy-Uri NOT IMPLEMENTED [%.*s]\n", (int)coap_pkt->proxy_uri_len,
-	  coap_pkt->proxy_uri);
-      coap_error_message =
-	"This is a constrained server (Contiki)";
-      return PROXYING_NOT_SUPPORTED_5_05;
-      break;
-    case COAP_OPTION_PROXY_SCHEME:
+            LOG("Proxy-Uri NOT IMPLEMENTED [%.*s]\n", (int)pkt->proxy_uri_len,
+              pkt->proxy_uri);
+            coap_error_message =
+              "This is a constrained server (MyNewt)";
+            return PROXYING_NOT_SUPPORTED_5_05;
+            break;
+        case COAP_OPTION_PROXY_SCHEME:
 #if COAP_PROXY_OPTION_PROCESSING
-      coap_pkt->proxy_scheme = (char *)current_option;
-      coap_pkt->proxy_scheme_len = option_length;
+            pkt->proxy_scheme = (char *)current_option;
+            pkt->proxy_scheme_len = option_length;
 #endif
-      LOG("Proxy-Scheme NOT IMPLEMENTED [%.*s]\n",
-	  (int)coap_pkt->proxy_scheme_len, coap_pkt->proxy_scheme);
-      coap_error_message =
-	"This is a constrained server (Contiki)";
-      return PROXYING_NOT_SUPPORTED_5_05;
-      break;
-
-    case COAP_OPTION_URI_HOST:
-      coap_pkt->uri_host = (char *)current_option;
-      coap_pkt->uri_host_len = option_length;
-      LOG("Uri-Host [%.*s]\n", (int)coap_pkt->uri_host_len,
-	  coap_pkt->uri_host);
-      break;
-    case COAP_OPTION_URI_PORT:
-      coap_pkt->uri_port = coap_parse_int_option(
-	current_option, option_length);
-      LOG("Uri-Port [%u]\n", coap_pkt->uri_port);
-      break;
+            LOG("Proxy-Scheme NOT IMPLEMENTED [%.*s]\n",
+              (int)pkt->proxy_scheme_len, pkt->proxy_scheme);
+            coap_error_message =
+              "This is a constrained server (Contiki)";
+            return PROXYING_NOT_SUPPORTED_5_05;
+            break;
+
+        case COAP_OPTION_URI_HOST:
+            pkt->uri_host = (char *)current_option;
+            pkt->uri_host_len = option_length;
+            LOG("Uri-Host [%.*s]\n", (int)pkt->uri_host_len, pkt->uri_host);
+            break;
+        case COAP_OPTION_URI_PORT:
+            pkt->uri_port =
+              coap_parse_int_option(current_option, option_length);
+            LOG("Uri-Port [%u]\n", pkt->uri_port);
+            break;
 #endif
-    case COAP_OPTION_URI_PATH:
-      /* coap_merge_multi_option() operates in-place on the IPBUF, but final
-       * packet field should be const string -> cast to string */
-      coap_merge_multi_option((char **)&(coap_pkt->uri_path),
-                              &(coap_pkt->uri_path_len), current_option,
-                              option_length, '/');
-      LOG("Uri-Path [%.*s]\n", (int)coap_pkt->uri_path_len, coap_pkt->uri_path);
-      break;
-    case COAP_OPTION_URI_QUERY:
-      /* coap_merge_multi_option() operates in-place on the IPBUF, but final
-       * packet field should be const string -> cast to string */
-      coap_merge_multi_option((char **)&(coap_pkt->uri_query),
-                              &(coap_pkt->uri_query_len), current_option,
-                              option_length, '&');
-      LOG("Uri-Query [%.*s]\n", (int)coap_pkt->uri_query_len,
-          coap_pkt->uri_query);
-      break;
+        case COAP_OPTION_URI_PATH:
+            /* coap_merge_multi_option() operates in-place on the IPBUF, but
+             * final packet field should be const string -> cast to string */
+            coap_merge_multi_option((char **)&(pkt->uri_path),
+                                    &(pkt->uri_path_len), current_option,
+                                    option_length, '/');
+            LOG("Uri-Path [%.*s]\n", (int)pkt->uri_path_len, pkt->uri_path);
+            break;
+        case COAP_OPTION_URI_QUERY:
+            /* coap_merge_multi_option() operates in-place on the IPBUF, but
+             * final packet field should be const string -> cast to string */
+            coap_merge_multi_option((char **)&(pkt->uri_query),
+                                    &(pkt->uri_query_len), current_option,
+                                    option_length, '&');
+            LOG("Uri-Query [%.*s]\n", (int)pkt->uri_query_len, pkt->uri_query);
+            break;
 #if 0
-    case COAP_OPTION_LOCATION_PATH:
-      /* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
-      coap_merge_multi_option(
-	(char **)&(coap_pkt->location_path),
-	&(coap_pkt->location_path_len),
-	current_option, option_length,
-	'/');
-      LOG("Location-Path [%.*s]\n", (int)coap_pkt->location_path_len,
-	  coap_pkt->location_path);
-      break;
-    case COAP_OPTION_LOCATION_QUERY:
-      /* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
-      coap_merge_multi_option(
-	(char **)&(coap_pkt->location_query),
-	&(coap_pkt->location_query_len),
-	current_option, option_length,
-	'&');
-      LOG("Location-Query [%.*s]\n", (int)coap_pkt->location_query_len,
-	  coap_pkt->location_query);
+        case COAP_OPTION_LOCATION_PATH:
+            /* coap_merge_multi_option() operates in-place on the IPBUF, but
+             * final packet field should be const string -> cast to string */
+            coap_merge_multi_option((char **)&(pkt->location_path),
+                                    &(pkt->location_path_len),
+                                    current_option, option_length, '/');
+            LOG("Location-Path [%.*s]\n", (int)pkt->location_path_len,
+              pkt->location_path);
+            break;
+        case COAP_OPTION_LOCATION_QUERY:
+            /* coap_merge_multi_option() operates in-place on the IPBUF, but
+             * final packet field should be const string -> cast to string */
+            coap_merge_multi_option((char **)&(pkt->location_query),
+                                    &(pkt->location_query_len),
+                                    current_option, option_length, '&');
+            LOG("Location-Query [%.*s]\n", (int)pkt->location_query_len,
+                                           pkt->location_query);
       break;
 #endif
-    case COAP_OPTION_OBSERVE:
-      coap_pkt->observe = coap_parse_int_option(current_option, option_length);
-      LOG("Observe [%lu]\n", (unsigned long)coap_pkt->observe);
-      break;
-    case COAP_OPTION_BLOCK2:
-      coap_pkt->block2_num =
-        coap_parse_int_option(current_option, option_length);
-      coap_pkt->block2_more = (coap_pkt->block2_num & 0x08) >> 3;
-      coap_pkt->block2_size = 16 << (coap_pkt->block2_num & 0x07);
-      coap_pkt->block2_offset = (coap_pkt->block2_num & ~0x0000000F)
-                                << (coap_pkt->block2_num & 0x07);
-      coap_pkt->block2_num >>= 4;
-      LOG("Block2 [%lu%s (%u B/blk)]\n", (unsigned long)coap_pkt->block2_num,
-          coap_pkt->block2_more ? "+" : "", coap_pkt->block2_size);
-      break;
-    case COAP_OPTION_BLOCK1:
-      coap_pkt->block1_num =
-        coap_parse_int_option(current_option, option_length);
-      coap_pkt->block1_more = (coap_pkt->block1_num & 0x08) >> 3;
-      coap_pkt->block1_size = 16 << (coap_pkt->block1_num & 0x07);
-      coap_pkt->block1_offset = (coap_pkt->block1_num & ~0x0000000F)
-                                << (coap_pkt->block1_num & 0x07);
-      coap_pkt->block1_num >>= 4;
-      LOG("Block1 [%lu%s (%u B/blk)]\n", (unsigned long)coap_pkt->block1_num,
-          coap_pkt->block1_more ? "+" : "", coap_pkt->block1_size);
-      break;
-    case COAP_OPTION_SIZE2:
-      coap_pkt->size2 = coap_parse_int_option(current_option, option_length);
-      LOG("Size2 [%lu]\n", (unsigned long)coap_pkt->size2);
-      break;
-    case COAP_OPTION_SIZE1:
-      coap_pkt->size1 = coap_parse_int_option(current_option, option_length);
-      LOG("Size1 [%lu]\n", (unsigned long)coap_pkt->size1);
-      break;
-    default:
-      LOG("unknown (%u)\n", option_number);
-      /* check if critical (odd) */
-      if (option_number & 1) {
-        coap_error_message = "Unsupported critical option";
-        return BAD_OPTION_4_02;
-      }
-    }
-    current_option += option_length;
-  } /* for */
-  LOG("-Done parsing-------\n");
+        case COAP_OPTION_OBSERVE:
+            pkt->observe = coap_parse_int_option(current_option, option_length);
+            LOG("Observe [%lu]\n", (unsigned long)pkt->observe);
+            break;
+        case COAP_OPTION_BLOCK2:
+            pkt->block2_num =
+              coap_parse_int_option(current_option, option_length);
+            pkt->block2_more = (pkt->block2_num & 0x08) >> 3;
+            pkt->block2_size = 16 << (pkt->block2_num & 0x07);
+            pkt->block2_offset = (pkt->block2_num & ~0x0000000F) <<
+                                 (pkt->block2_num & 0x07);
+            pkt->block2_num >>= 4;
+            LOG("Block2 [%lu%s (%u B/blk)]\n", (unsigned long)pkt->block2_num,
+              pkt->block2_more ? "+" : "", pkt->block2_size);
+            break;
+        case COAP_OPTION_BLOCK1:
+            pkt->block1_num =
+              coap_parse_int_option(current_option, option_length);
+            pkt->block1_more = (pkt->block1_num & 0x08) >> 3;
+            pkt->block1_size = 16 << (pkt->block1_num & 0x07);
+            pkt->block1_offset = (pkt->block1_num & ~0x0000000F) <<
+                                 (pkt->block1_num & 0x07);
+            pkt->block1_num >>= 4;
+            LOG("Block1 [%lu%s (%u B/blk)]\n", (unsigned long)pkt->block1_num,
+              pkt->block1_more ? "+" : "", pkt->block1_size);
+            break;
+        case COAP_OPTION_SIZE2:
+            pkt->size2 = coap_parse_int_option(current_option, option_length);
+            LOG("Size2 [%lu]\n", (unsigned long)pkt->size2);
+            break;
+        case COAP_OPTION_SIZE1:
+            pkt->size1 = coap_parse_int_option(current_option, option_length);
+            LOG("Size1 [%lu]\n", (unsigned long)pkt->size1);
+            break;
+        default:
+            LOG("unknown (%u)\n", option_number);
+            /* check if critical (odd) */
+            if (option_number & 1) {
+                coap_error_message = "Unsupported critical option";
+                return BAD_OPTION_4_02;
+            }
+        }
+        current_option += option_length;
+    } /* for */
+    LOG("-Done parsing-------\n");
 
-  return NO_ERROR;
+    return NO_ERROR;
 }
 #if 0
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ff2e9981/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index 672320d..aef230f 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -152,14 +152,14 @@ typedef struct coap_packet {
 } coap_packet_t;
 
 /* option format serialization */
-#define COAP_SERIALIZE_INT_OPTION(number, field, text)                         \
+#define COAP_SERIALIZE_INT_OPTION(coap_pkt, number, field, text)               \
   if (IS_OPTION(coap_pkt, number)) {                                           \
     LOG(text " [%u]\n", (unsigned int)coap_pkt->field);                        \
     option += coap_serialize_int_option(number, current_number, option,        \
                                         coap_pkt->field);                      \
     current_number = number;                                                   \
   }
-#define COAP_SERIALIZE_BYTE_OPTION(number, field, text)                        \
+#define COAP_SERIALIZE_BYTE_OPTION(coap_pkt, number, field, text)              \
   if (IS_OPTION(coap_pkt, number)) {                                           \
     LOG(text " %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",                     \
         (unsigned int)coap_pkt->field##_len, coap_pkt->field[0],               \
@@ -171,7 +171,7 @@ typedef struct coap_packet {
                                           coap_pkt->field##_len, '\0');        \
     current_number = number;                                                   \
   }
-#define COAP_SERIALIZE_STRING_OPTION(number, field, splitter, text)            \
+#define COAP_SERIALIZE_STRING_OPTION(coap_pkt, number, field, splitter, text)  \
   if (IS_OPTION(coap_pkt, number)) {                                           \
     LOG(text " [%.*s]\n", (int)coap_pkt->field##_len, coap_pkt->field);        \
     option += coap_serialize_array_option(number, current_number, option,      \
@@ -179,7 +179,7 @@ typedef struct coap_packet {
                                           coap_pkt->field##_len, splitter);    \
     current_number = number;                                                   \
   }
-#define COAP_SERIALIZE_BLOCK_OPTION(number, field, text)                       \
+#define COAP_SERIALIZE_BLOCK_OPTION(coap_pkt, number, field, text)             \
   if (IS_OPTION(coap_pkt, number)) {                                           \
     LOG(text " [%lu%s (%u B/blk)]\n", (unsigned long)coap_pkt->field##_num,    \
         coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size);            \


[5/7] incubator-mynewt-core git commit: oic; shorten variable names.

Posted by ma...@apache.org.
oic; shorten variable names.


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

Branch: refs/heads/develop
Commit: fe3c27f605605df0738433d72e207c62ee348415
Parents: b93aac5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Dec 1 17:39:59 2016 -0800
Committer: System Administrator <ma...@runtime.io>
Committed: Fri Dec 2 11:42:45 2016 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/coap.c | 509 ++++++++++++++++-----------------
 net/oic/src/messaging/coap/coap.h | 113 ++++----
 2 files changed, 308 insertions(+), 314 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fe3c27f6/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 144e10c..5e490bd 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -200,8 +200,9 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number,
     return i;
 }
 /*---------------------------------------------------------------------------*/
+
 static void
-coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option,
+coap_merge_multi_option(char **dst, uint16_t *dst_len, uint8_t *option,
                         size_t option_len, char separator)
 {
     /* merge multiple options */
@@ -212,7 +213,6 @@ coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option,
 
         /* memmove handles 2-byte option headers */
         memmove((*dst) + (*dst_len), option, option_len);
-
         *dst_len += option_len;
     } else {
         /* dst is empty: set to option */
@@ -220,6 +220,7 @@ coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option,
         *dst_len = option_len;
     }
 }
+
 /*---------------------------------------------------------------------------*/
 #if 0
 static int
@@ -274,16 +275,17 @@ coap_get_mid(void)
 }
 /*---------------------------------------------------------------------------*/
 void
-coap_init_message(coap_packet_t *coap_pkt, coap_message_type_t type,
+coap_init_message(coap_packet_t *pkt, coap_message_type_t type,
                   uint8_t code, uint16_t mid)
 {
     /* Important thing */
-    memset(coap_pkt, 0, sizeof(coap_packet_t));
+    memset(pkt, 0, sizeof(coap_packet_t));
 
-    coap_pkt->type = type;
-    coap_pkt->code = code;
-    coap_pkt->mid = mid;
+    pkt->type = type;
+    pkt->code = code;
+    pkt->mid = mid;
 }
+
 /*---------------------------------------------------------------------------*/
 
 size_t
@@ -410,10 +412,10 @@ coap_status_t
 coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
 {
     struct coap_udp_hdr *udp;
-    uint8_t *current_option;
-    unsigned int option_number = 0;
-    unsigned int option_delta = 0;
-    size_t option_length = 0;
+    uint8_t *cur_opt;
+    unsigned int opt_num = 0;
+    unsigned int opt_delta = 0;
+    size_t opt_len = 0;
 
     /* initialize packet */
     memset(pkt, 0, sizeof(coap_packet_t));
@@ -437,9 +439,10 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
         return BAD_REQUEST_4_00;
     }
 
-    current_option = data + COAP_HEADER_LEN;
+    cur_opt = data + sizeof(*udp);
+
+    memcpy(pkt->token, cur_opt, pkt->token_len);
 
-    memcpy(pkt->token, current_option, pkt->token_len);
     LOG("Token (len %u) [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
       pkt->token_len,
       pkt->token[0], pkt->token[1], pkt->token[2], pkt->token[3], pkt->token[4],
@@ -447,13 +450,13 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
 
     /* parse options */
     memset(pkt->options, 0, sizeof(pkt->options));
-    current_option += pkt->token_len;
+    cur_opt += pkt->token_len;
 
-    while (current_option < data + data_len) {
+    while (cur_opt < data + data_len) {
         /* payload marker 0xFF, currently only checking for 0xF* because rest is
          * reserved */
-        if ((current_option[0] & 0xF0) == 0xF0) {
-            pkt->payload = ++current_option;
+        if ((cur_opt[0] & 0xF0) == 0xF0) {
+            pkt->payload = ++cur_opt;
             pkt->payload_len = data_len - (pkt->payload - data);
 
             /* also for receiving, the Erbium upper bound is MAX_PAYLOAD_SIZE */
@@ -466,54 +469,46 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
             break;
         }
 
-        option_delta = current_option[0] >> 4;
-        option_length = current_option[0] & 0x0F;
-        ++current_option;
-
-        if (option_delta == 13) {
-            option_delta += current_option[0];
-            ++current_option;
-        } else if (option_delta == 14) {
-            option_delta += 255;
-            option_delta += current_option[0] << 8;
-            ++current_option;
-            option_delta += current_option[0];
-            ++current_option;
+        opt_delta = cur_opt[0] >> 4;
+        opt_len = cur_opt[0] & 0x0F;
+        ++cur_opt;
+
+        if (opt_delta == 13) {
+            opt_delta += cur_opt[0];
+            ++cur_opt;
+        } else if (opt_delta == 14) {
+            opt_delta += (255 + (cur_opt[0] << 8) + cur_opt[1]);
+            cur_opt += 2;
         }
 
-        if (option_length == 13) {
-            option_length += current_option[0];
-            ++current_option;
-        } else if (option_length == 14) {
-            option_length += 255;
-            option_length += current_option[0] << 8;
-            ++current_option;
-            option_length += current_option[0];
-            ++current_option;
+        if (opt_len == 13) {
+            opt_len += cur_opt[0];
+            ++cur_opt;
+        } else if (opt_len == 14) {
+            opt_len += (255 + (cur_opt[0] << 8) + cur_opt[1]);
+            cur_opt += 2;
         }
 
-        option_number += option_delta;
+        opt_num += opt_delta;
 
-        if (option_number < COAP_OPTION_SIZE1) {
-            LOG("OPTION %u (delta %u, len %zu): ", option_number, option_delta,
-              option_length);
-            SET_OPTION(pkt, option_number);
+        if (opt_num < COAP_OPTION_SIZE1) {
+            LOG("OPTION %u (delta %u, len %zu): ", opt_num, opt_delta, opt_len);
+            SET_OPTION(pkt, opt_num);
         }
 
-        switch (option_number) {
+        switch (opt_num) {
         case COAP_OPTION_CONTENT_FORMAT:
-            pkt->content_format =
-              coap_parse_int_option(current_option, option_length);
+            pkt->content_format = coap_parse_int_option(cur_opt, opt_len);
             LOG("Content-Format [%u]\n", pkt->content_format);
             break;
         case COAP_OPTION_MAX_AGE:
-            pkt->max_age = coap_parse_int_option(current_option, option_length);
+            pkt->max_age = coap_parse_int_option(cur_opt, opt_len);
             LOG("Max-Age [%lu]\n", (unsigned long)pkt->max_age);
             break;
 #if 0
         case COAP_OPTION_ETAG:
-            pkt->etag_len = MIN(COAP_ETAG_LEN, option_length);
-            memcpy(pkt->etag, current_option, pkt->etag_len);
+            pkt->etag_len = MIN(COAP_ETAG_LEN, opt_len);
+            memcpy(pkt->etag, cur_opt, pkt->etag_len);
             LOG("ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
               pkt->etag_len,
               pkt->etag[0], pkt->etag[1], pkt->etag[2], pkt->etag[3],
@@ -522,18 +517,19 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
             break;
 #endif
         case COAP_OPTION_ACCEPT:
-            pkt->accept = coap_parse_int_option(current_option, option_length);
+            pkt->accept = coap_parse_int_option(cur_opt, opt_len);
             LOG("Accept [%u]\n", pkt->accept);
             break;
 #if 0
         case COAP_OPTION_IF_MATCH:
             /* TODO support multiple ETags */
-            pkt->if_match_len = MIN(COAP_ETAG_LEN, option_length);
-            memcpy(pkt->if_match, current_option, pkt->if_match_len);
+            pkt->if_match_len = MIN(COAP_ETAG_LEN, opt_len);
+            memcpy(pkt->if_match, cur_opt, pkt->if_match_len);
             LOG("If-Match %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
               pkt->if_match_len, pkt->if_match[0], pkt->if_match[1],
               pkt->if_match[2], pkt->if_match[3], pkt->if_match[4],
               pkt->if_match[5], pkt->if_match[6], pkt->if_match[7]);
+            /* FIXME always prints 8 bytes */
             break;
         case COAP_OPTION_IF_NONE_MATCH:
             pkt->if_none_match = 1;
@@ -542,117 +538,102 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
 
         case COAP_OPTION_PROXY_URI:
 #if COAP_PROXY_OPTION_PROCESSING
-            pkt->proxy_uri = (char *)current_option;
-            pkt->proxy_uri_len = option_length;
+            pkt->proxy_uri = cur_opt;
+            pkt->proxy_uri_len = opt_len;
 #endif
-            LOG("Proxy-Uri NOT IMPLEMENTED [%.*s]\n", (int)pkt->proxy_uri_len,
-              pkt->proxy_uri);
+            LOG("Proxy-Uri NOT IMPLEMENTED [%s]\n", (char *)pkt->proxy_uri);
             coap_error_message =
               "This is a constrained server (MyNewt)";
             return PROXYING_NOT_SUPPORTED_5_05;
             break;
         case COAP_OPTION_PROXY_SCHEME:
 #if COAP_PROXY_OPTION_PROCESSING
-            pkt->proxy_scheme = (char *)current_option;
-            pkt->proxy_scheme_len = option_length;
+            pkt->proxy_scheme = cur_opt;
+            pkt->proxy_scheme_len = opt_len;
 #endif
-            LOG("Proxy-Scheme NOT IMPLEMENTED [%.*s]\n",
-              (int)pkt->proxy_scheme_len, pkt->proxy_scheme);
+            LOG("Proxy-Scheme NOT IMPLEMENTED [%s]\n", pkt->proxy_scheme);
             coap_error_message =
-              "This is a constrained server (Contiki)";
+              "This is a constrained server (MyNewt)";
             return PROXYING_NOT_SUPPORTED_5_05;
             break;
 
         case COAP_OPTION_URI_HOST:
-            pkt->uri_host = (char *)current_option;
-            pkt->uri_host_len = option_length;
-            LOG("Uri-Host [%.*s]\n", (int)pkt->uri_host_len, pkt->uri_host);
+            pkt->uri_host = cur_opt;
+            pkt->uri_host_len = opt_len;
+            LOG("Uri-Host [%s]\n", (char *)pkt->uri_host);
             break;
         case COAP_OPTION_URI_PORT:
-            pkt->uri_port =
-              coap_parse_int_option(current_option, option_length);
+            pkt->uri_port = coap_parse_int_option(cur_opt, opt_len);
             LOG("Uri-Port [%u]\n", pkt->uri_port);
             break;
 #endif
         case COAP_OPTION_URI_PATH:
-            /* coap_merge_multi_option() operates in-place on the IPBUF, but
-             * final packet field should be const string -> cast to string */
-            coap_merge_multi_option((char **)&(pkt->uri_path),
-                                    &(pkt->uri_path_len), current_option,
-                                    option_length, '/');
-            LOG("Uri-Path [%.*s]\n", (int)pkt->uri_path_len, pkt->uri_path);
+            /* coap_merge_multi_option() operates in-place on the buf */
+            coap_merge_multi_option(&pkt->uri_path, &pkt->uri_path_len,
+                                    cur_opt, opt_len, '/');
+            LOG("Uri-Path [%s]\n", pkt->uri_path);
             break;
         case COAP_OPTION_URI_QUERY:
-            /* coap_merge_multi_option() operates in-place on the IPBUF, but
-             * final packet field should be const string -> cast to string */
-            coap_merge_multi_option((char **)&(pkt->uri_query),
-                                    &(pkt->uri_query_len), current_option,
-                                    option_length, '&');
-            LOG("Uri-Query [%.*s]\n", (int)pkt->uri_query_len, pkt->uri_query);
+            /* coap_merge_multi_option() operates in-place on the mbuf */
+            coap_merge_multi_option(&pkt->uri_query, &pkt->uri_query_len,
+                                    cur_opt, opt_len, '&');
+            LOG("Uri-Query [%s]\n", pkt->uri_query);
             break;
 #if 0
         case COAP_OPTION_LOCATION_PATH:
-            /* coap_merge_multi_option() operates in-place on the IPBUF, but
-             * final packet field should be const string -> cast to string */
-            coap_merge_multi_option((char **)&(pkt->location_path),
-                                    &(pkt->location_path_len),
-                                    current_option, option_length, '/');
-            LOG("Location-Path [%.*s]\n", (int)pkt->location_path_len,
-              pkt->location_path);
+            /* coap_merge_multi_option() operates in-place on the mbuf */
+            coap_merge_multi_option(&pkt->loc_path, &pkt->loc_path_len,
+                                    cur_opt, opt_len, '/');
+            LOG("Location-Path [%s]\n", pkt->loc_path);
             break;
         case COAP_OPTION_LOCATION_QUERY:
-            /* coap_merge_multi_option() operates in-place on the IPBUF, but
-             * final packet field should be const string -> cast to string */
-            coap_merge_multi_option((char **)&(pkt->location_query),
-                                    &(pkt->location_query_len),
-                                    current_option, option_length, '&');
-            LOG("Location-Query [%.*s]\n", (int)pkt->location_query_len,
-                                           pkt->location_query);
-      break;
+            /* coap_merge_multi_option() operates in-place on the mbuf */
+            coap_merge_multi_option(&pkt->loc_query, &pkt->loc_query_len,
+                                    cur_opt, opt_len, '&');
+            LOG("Location-Query [%s]\n", pkt->loc_query);
+            break;
 #endif
         case COAP_OPTION_OBSERVE:
-            pkt->observe = coap_parse_int_option(current_option, option_length);
+            pkt->observe = coap_parse_int_option(cur_opt, opt_len);
             LOG("Observe [%lu]\n", (unsigned long)pkt->observe);
             break;
         case COAP_OPTION_BLOCK2:
-            pkt->block2_num =
-              coap_parse_int_option(current_option, option_length);
+            pkt->block2_num = coap_parse_int_option(cur_opt, opt_len);
             pkt->block2_more = (pkt->block2_num & 0x08) >> 3;
             pkt->block2_size = 16 << (pkt->block2_num & 0x07);
-            pkt->block2_offset = (pkt->block2_num & ~0x0000000F) <<
-                                 (pkt->block2_num & 0x07);
+            pkt->block2_offset =
+              (pkt->block2_num & ~0x0000000F) << (pkt->block2_num & 0x07);
             pkt->block2_num >>= 4;
             LOG("Block2 [%lu%s (%u B/blk)]\n", (unsigned long)pkt->block2_num,
               pkt->block2_more ? "+" : "", pkt->block2_size);
             break;
         case COAP_OPTION_BLOCK1:
-            pkt->block1_num =
-              coap_parse_int_option(current_option, option_length);
+            pkt->block1_num = coap_parse_int_option(cur_opt, opt_len);
             pkt->block1_more = (pkt->block1_num & 0x08) >> 3;
             pkt->block1_size = 16 << (pkt->block1_num & 0x07);
-            pkt->block1_offset = (pkt->block1_num & ~0x0000000F) <<
-                                 (pkt->block1_num & 0x07);
+            pkt->block1_offset =
+              (pkt->block1_num & ~0x0000000F) << (pkt->block1_num & 0x07);
             pkt->block1_num >>= 4;
             LOG("Block1 [%lu%s (%u B/blk)]\n", (unsigned long)pkt->block1_num,
               pkt->block1_more ? "+" : "", pkt->block1_size);
             break;
         case COAP_OPTION_SIZE2:
-            pkt->size2 = coap_parse_int_option(current_option, option_length);
+            pkt->size2 = coap_parse_int_option(cur_opt, opt_len);
             LOG("Size2 [%lu]\n", (unsigned long)pkt->size2);
             break;
         case COAP_OPTION_SIZE1:
-            pkt->size1 = coap_parse_int_option(current_option, option_length);
+            pkt->size1 = coap_parse_int_option(cur_opt, opt_len);
             LOG("Size1 [%lu]\n", (unsigned long)pkt->size1);
             break;
         default:
-            LOG("unknown (%u)\n", option_number);
+            LOG("unknown (%u)\n", opt_num);
             /* check if critical (odd) */
-            if (option_number & 1) {
+            if (opt_num & 1) {
                 coap_error_message = "Unsupported critical option";
                 return BAD_OPTION_4_02;
             }
         }
-        current_option += option_length;
+        cur_opt += opt_len;
     } /* for */
     LOG("-Done parsing-------\n");
 
@@ -660,21 +641,21 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
 }
 #if 0
 int
-coap_get_query_variable(coap_packet_t *const coap_pkt, const char *name,
+coap_get_query_variable(coap_packet_t *const pkt, const char *name,
   const char **output)
 {
-    if (IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
-        return coap_get_variable(coap_pkt->uri_query, coap_pkt->uri_query_len,
+    if (IS_OPTION(pkt, COAP_OPTION_URI_QUERY)) {
+        return coap_get_variable(pkt->uri_query, pkt->uri_query_len,
                                  name, output);
     }
     return 0;
 }
 int
-coap_get_post_variable(coap_packet_t *coap_pkt, const char *name,
+coap_get_post_variable(coap_packet_t *pkt, const char *name,
                        const char **output)
 {
-    if (coap_pkt->payload_len) {
-        return coap_get_variable(coap_pkt->payload, coap_pkt->payload_len,
+    if (pkt->payload_len) {
+        return coap_get_variable(pkt->payload, pkt->payload_len,
                                  name, output);
     }
     return 0;
@@ -693,237 +674,237 @@ coap_set_status_code(coap_packet_t *const packet, unsigned int code)
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_set_token(coap_packet_t *coap_pkt, const uint8_t *token, size_t token_len)
+coap_set_token(coap_packet_t *pkt, const uint8_t *token, size_t token_len)
 {
-    coap_pkt->token_len = MIN(COAP_TOKEN_LEN, token_len);
-    memcpy(coap_pkt->token, token, coap_pkt->token_len);
+    pkt->token_len = MIN(COAP_TOKEN_LEN, token_len);
+    memcpy(pkt->token, token, pkt->token_len);
 
-    return coap_pkt->token_len;
+    return pkt->token_len;
 }
 #ifdef OC_CLIENT
 int
-coap_get_header_content_format(coap_packet_t *coap_pkt, unsigned int *format)
+coap_get_header_content_format(coap_packet_t *pkt, unsigned int *format)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_CONTENT_FORMAT)) {
         return 0;
     }
-    *format = coap_pkt->content_format;
+    *format = pkt->content_format;
     return 1;
 }
 #endif
 int
-coap_set_header_content_format(coap_packet_t *coap_pkt, unsigned int format)
+coap_set_header_content_format(coap_packet_t *pkt, unsigned int format)
 {
-    coap_pkt->content_format = format;
-    SET_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT);
+    pkt->content_format = format;
+    SET_OPTION(pkt, COAP_OPTION_CONTENT_FORMAT);
     return 1;
 }
 /*---------------------------------------------------------------------------*/
 #if 0
 int
-coap_get_header_accept(coap_packet_t *coap_pkt, unsigned int *accept)
+coap_get_header_accept(coap_packet_t *pkt, unsigned int *accept)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_ACCEPT)) {
         return 0;
     }
-    *accept = coap_pkt->accept;
+    *accept = pkt->accept;
     return 1;
 }
 #endif
 
 #ifdef OC_CLIENT
 int
-coap_set_header_accept(coap_packet_t *coap_pkt, unsigned int accept)
+coap_set_header_accept(coap_packet_t *pkt, unsigned int accept)
 {
-    coap_pkt->accept = accept;
-    SET_OPTION(coap_pkt, COAP_OPTION_ACCEPT);
+    pkt->accept = accept;
+    SET_OPTION(pkt, COAP_OPTION_ACCEPT);
     return 1;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 #if 0
 int
-coap_get_header_max_age(coap_packet_t *coap_pkt, uint32_t *age)
+coap_get_header_max_age(coap_packet_t *pkt, uint32_t *age)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_MAX_AGE)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_MAX_AGE)) {
         *age = COAP_DEFAULT_MAX_AGE;
     } else {
-        *age = coap_pkt->max_age;
+        *age = pkt->max_age;
     }
     return 1;
 }
 #endif
 int
-coap_set_header_max_age(coap_packet_t *coap_pkt, uint32_t age)
+coap_set_header_max_age(coap_packet_t *pkt, uint32_t age)
 {
-    coap_pkt->max_age = age;
-    SET_OPTION(coap_pkt, COAP_OPTION_MAX_AGE);
+    pkt->max_age = age;
+    SET_OPTION(pkt, COAP_OPTION_MAX_AGE);
     return 1;
 }
 /*---------------------------------------------------------------------------*/
 #if 0
 int
-coap_get_header_etag(coap_packet_t *coap_pkt, const uint8_t **etag)
+coap_get_header_etag(coap_packet_t *pkt, const uint8_t **etag)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_ETAG)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_ETAG)) {
         return 0;
     }
-    *etag = coap_pkt->etag;
-    return coap_pkt->etag_len;
+    *etag = pkt->etag;
+    return pkt->etag_len;
 }
 
 int
-coap_set_header_etag(coap_packet_t *coap_pkt, const uint8_t *etag,
+coap_set_header_etag(coap_packet_t *pkt, const uint8_t *etag,
   size_t etag_len)
 {
-    coap_pkt->etag_len = MIN(COAP_ETAG_LEN, etag_len);
-    memcpy(coap_pkt->etag, etag, coap_pkt->etag_len);
+    pkt->etag_len = MIN(COAP_ETAG_LEN, etag_len);
+    memcpy(pkt->etag, etag, pkt->etag_len);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_ETAG);
-    return coap_pkt->etag_len;
+    SET_OPTION(pkt, COAP_OPTION_ETAG);
+    return pkt->etag_len;
 }
 /*---------------------------------------------------------------------------*/
 /*FIXME support multiple ETags */
 
 int
-coap_get_header_if_match(coap_packet_t *coap_pkt, const uint8_t **etag)
+coap_get_header_if_match(coap_packet_t *pkt, const uint8_t **etag)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_IF_MATCH)) {
         return 0;
     }
-    *etag = coap_pkt->if_match;
-    return coap_pkt->if_match_len;
+    *etag = pkt->if_match;
+    return pkt->if_match_len;
 }
 
 int
-coap_set_header_if_match(coap_packet_t *coap_pkt, const uint8_t *etag,
+coap_set_header_if_match(coap_packet_t *pkt, const uint8_t *etag,
   size_t etag_len)
 {
-    coap_pkt->if_match_len = MIN(COAP_ETAG_LEN, etag_len);
-    memcpy(coap_pkt->if_match, etag, coap_pkt->if_match_len);
+    pkt->if_match_len = MIN(COAP_ETAG_LEN, etag_len);
+    memcpy(pkt->if_match, etag, pkt->if_match_len);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_IF_MATCH);
-    return coap_pkt->if_match_len;
+    SET_OPTION(pkt, COAP_OPTION_IF_MATCH);
+    return pkt->if_match_len;
 }
 
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_if_none_match(coap_packet_t *coap_pkt)
+coap_get_header_if_none_match(coap_packet_t *pkt)
 {
-    return IS_OPTION(coap_pkt, COAP_OPTION_IF_NONE_MATCH) ? 1 : 0;
+    return IS_OPTION(pkt, COAP_OPTION_IF_NONE_MATCH) ? 1 : 0;
 }
 
 int
-coap_set_header_if_none_match(coap_packet_t *coap_pkt)
+coap_set_header_if_none_match(coap_packet_t *pkt)
 {
-    SET_OPTION(coap_pkt, COAP_OPTION_IF_NONE_MATCH);
+    SET_OPTION(pkt, COAP_OPTION_IF_NONE_MATCH);
     return 1;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_proxy_uri(coap_packet_t *coap_pkt, const char **uri)
+coap_get_header_proxy_uri(coap_packet_t *pkt, const char **uri)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_PROXY_URI)) {
         return 0;
     }
-    *uri = coap_pkt->proxy_uri;
-    return coap_pkt->proxy_uri_len;
+    *uri = pkt->proxy_uri;
+    return pkt->proxy_uri_len;
 }
 
 int
-coap_set_header_proxy_uri(coap_packet_t *coap_pkt, const char *uri)
+coap_set_header_proxy_uri(coap_packet_t *pkt, const char *uri)
 {
     /*TODO Provide alternative that sets Proxy-Scheme and Uri-* options and provide er-coap-conf define */
 
-    coap_pkt->proxy_uri = uri;
-    coap_pkt->proxy_uri_len = strlen(uri);
+    pkt->proxy_uri = uri;
+    pkt->proxy_uri_len = strlen(uri);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_PROXY_URI);
-    return coap_pkt->proxy_uri_len;
+    SET_OPTION(pkt, COAP_OPTION_PROXY_URI);
+    return pkt->proxy_uri_len;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_uri_host(coap_packet_t *coap_pkt, const char **host)
+coap_get_header_uri_host(coap_packet_t *pkt, const char **host)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_URI_HOST)) {
         return 0;
     }
-    *host = coap_pkt->uri_host;
-    return coap_pkt->uri_host_len;
+    *host = pkt->uri_host;
+    return pkt->uri_host_len;
 }
 
 int
-coap_set_header_uri_host(coap_packet_t *coap_pkt, const char *host)
+coap_set_header_uri_host(coap_packet_t *pkt, const char *host)
 {
-    coap_pkt->uri_host = host;
-    coap_pkt->uri_host_len = strlen(host);
+    pkt->uri_host = (char *)host;
+    pkt->uri_host_len = strlen(host);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_URI_HOST);
-    return coap_pkt->uri_host_len;
+    SET_OPTION(pkt, COAP_OPTION_URI_HOST);
+    return pkt->uri_host_len;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_uri_path(coap_packet_t *coap_pkt, const char **path)
+coap_get_header_uri_path(coap_packet_t *pkt, const char **path)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_URI_PATH)) {
         return 0;
     }
-    *path = coap_pkt->uri_path;
-    return coap_pkt->uri_path_len;
+    *path = pkt->uri_path;
+    return pkt->uri_path_len;
 }
 #ifdef OC_CLIENT
 int
-coap_set_header_uri_path(coap_packet_t *coap_pkt, const char *path)
+coap_set_header_uri_path(coap_packet_t *pkt, const char *path)
 {
     while (path[0] == '/') {
         ++path;
     }
-    coap_pkt->uri_path = path;
-    coap_pkt->uri_path_len = strlen(path);
+    pkt->uri_path = (char *)path;
+    pkt->uri_path_len = strlen(path);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_URI_PATH);
-    return coap_pkt->uri_path_len;
+    SET_OPTION(pkt, COAP_OPTION_URI_PATH);
+    return pkt->uri_path_len;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_uri_query(coap_packet_t *coap_pkt, const char **query)
+coap_get_header_uri_query(coap_packet_t *pkt, const char **query)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_URI_QUERY)) {
         return 0;
     }
-    *query = coap_pkt->uri_query;
-    return coap_pkt->uri_query_len;
+    *query = pkt->uri_query;
+    return pkt->uri_query_len;
 }
 #ifdef OC_CLIENT
 int
-coap_set_header_uri_query(coap_packet_t *coap_pkt, const char *query)
+coap_set_header_uri_query(coap_packet_t *pkt, const char *query)
 {
     while (query[0] == '?') {
         ++query;
     }
-    coap_pkt->uri_query = query;
-    coap_pkt->uri_query_len = strlen(query);
+    pkt->uri_query = (char *)query;
+    pkt->uri_query_len = strlen(query);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_URI_QUERY);
-    return coap_pkt->uri_query_len;
+    SET_OPTION(pkt, COAP_OPTION_URI_QUERY);
+    return pkt->uri_query_len;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 #if 0
 int
-coap_get_header_location_path(coap_packet_t *coap_pkt, const char **path)
+coap_get_header_location_path(coap_packet_t *pkt, const char **path)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_LOCATION_PATH)) {
         return 0;
     }
-    *path = coap_pkt->location_path;
-    return coap_pkt->location_path_len;
+    *path = pkt->location_path;
+    return pkt->location_path_len;
 }
 
 int
-coap_set_header_location_path(coap_packet_t *coap_pkt, const char *path)
+coap_set_header_location_path(coap_packet_t *pkt, const char *path)
 {
     char *query;
 
@@ -932,84 +913,88 @@ coap_set_header_location_path(coap_packet_t *coap_pkt, const char *path)
     }
     if ((query = strchr(path, '?'))) {
         coap_set_header_location_query(packet, query + 1);
-        coap_pkt->location_path_len = query - path;
+        pkt->location_path_len = query - path;
     } else {
-        coap_pkt->location_path_len = strlen(path);
+        pkt->location_path_len = strlen(path);
     }
-    coap_pkt->location_path = path;
+    pkt->location_path = path;
 
-    if (coap_pkt->location_path_len > 0) {
-        SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH);
+    if (pkt->location_path_len > 0) {
+        SET_OPTION(pkt, COAP_OPTION_LOCATION_PATH);
     }
-    return coap_pkt->location_path_len;
+    return pkt->location_path_len;
 }
+
+#if 0
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_location_query(coap_packet_t *coap_pkt, const char **query)
+coap_get_header_location_query(coap_packet_t *pkt, const char **query)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_LOCATION_QUERY)) {
         return 0;
     }
-    *query = coap_pkt->location_query;
-    return coap_pkt->location_query_len;
+    *query = pkt->location_query;
+    return pkt->location_query_len;
 }
 #endif
 int
-coap_set_header_location_query(coap_packet_t *coap_pkt, const char *query)
+coap_set_header_location_query(coap_packet_t *pkt, const char *query)
 {
     while (query[0] == '?') {
         ++query;
     }
-    coap_pkt->location_query = query;
-    coap_pkt->location_query_len = strlen(query);
+    pkt->loc_query = query;
+    pkt->loc_query_len = strlen(query);
 
-    SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY);
-    return coap_pkt->location_query_len;
+    SET_OPTION(pkt, COAP_OPTION_LOCATION_QUERY);
+    return pkt->loc_query_len;
 }
+#endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_observe(coap_packet_t *coap_pkt, uint32_t *observe)
+coap_get_header_observe(coap_packet_t *pkt, uint32_t *observe)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_OBSERVE)) {
         return 0;
     }
-    *observe = coap_pkt->observe;
+    *observe = pkt->observe;
     return 1;
 }
 
 int
-coap_set_header_observe(coap_packet_t *coap_pkt, uint32_t observe)
+coap_set_header_observe(coap_packet_t *pkt, uint32_t observe)
 {
-    coap_pkt->observe = observe;
-    SET_OPTION(coap_pkt, COAP_OPTION_OBSERVE);
+    pkt->observe = observe;
+    SET_OPTION(pkt, COAP_OPTION_OBSERVE);
     return 1;
 }
+
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_block2(coap_packet_t *coap_pkt, uint32_t *num,
+coap_get_header_block2(coap_packet_t *pkt, uint32_t *num,
                        uint8_t *more, uint16_t *size, uint32_t *offset)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_BLOCK2)) {
         return 0;
     }
     /* pointers may be NULL to get only specific block parameters */
     if (num != NULL) {
-        *num = coap_pkt->block2_num;
+        *num = pkt->block2_num;
     }
     if (more != NULL) {
-        *more = coap_pkt->block2_more;
+        *more = pkt->block2_more;
     }
     if (size != NULL) {
-        *size = coap_pkt->block2_size;
+        *size = pkt->block2_size;
     }
     if (offset != NULL) {
-        *offset = coap_pkt->block2_offset;
+        *offset = pkt->block2_offset;
     }
     return 1;
 }
 
 int
-coap_set_header_block2(coap_packet_t *coap_pkt, uint32_t num,
+coap_set_header_block2(coap_packet_t *pkt, uint32_t num,
                        uint8_t more, uint16_t size)
 {
     if (size < 16) {
@@ -1021,39 +1006,39 @@ coap_set_header_block2(coap_packet_t *coap_pkt, uint32_t num,
     if (num > 0x0FFFFF) {
         return 0;
     }
-    coap_pkt->block2_num = num;
-    coap_pkt->block2_more = more ? 1 : 0;
-    coap_pkt->block2_size = size;
+    pkt->block2_num = num;
+    pkt->block2_more = more ? 1 : 0;
+    pkt->block2_size = size;
 
-    SET_OPTION(coap_pkt, COAP_OPTION_BLOCK2);
+    SET_OPTION(pkt, COAP_OPTION_BLOCK2);
     return 1;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_block1(coap_packet_t *coap_pkt, uint32_t *num, uint8_t *more,
+coap_get_header_block1(coap_packet_t *pkt, uint32_t *num, uint8_t *more,
                        uint16_t *size, uint32_t *offset)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_BLOCK1)) {
         return 0;
     }
     /* pointers may be NULL to get only specific block parameters */
     if (num != NULL) {
-        *num = coap_pkt->block1_num;
+        *num = pkt->block1_num;
     }
     if (more != NULL) {
-        *more = coap_pkt->block1_more;
+        *more = pkt->block1_more;
     }
     if (size != NULL) {
-        *size = coap_pkt->block1_size;
+        *size = pkt->block1_size;
     }
     if (offset != NULL) {
-        *offset = coap_pkt->block1_offset;
+        *offset = pkt->block1_offset;
     }
     return 1;
 }
 
 int
-coap_set_header_block1(coap_packet_t *coap_pkt, uint32_t num, uint8_t more,
+coap_set_header_block1(coap_packet_t *pkt, uint32_t num, uint8_t more,
                        uint16_t size)
 {
     if (size < 16) {
@@ -1065,67 +1050,67 @@ coap_set_header_block1(coap_packet_t *coap_pkt, uint32_t num, uint8_t more,
     if (num > 0x0FFFFF) {
         return 0;
     }
-    coap_pkt->block1_num = num;
-    coap_pkt->block1_more = more;
-    coap_pkt->block1_size = size;
+    pkt->block1_num = num;
+    pkt->block1_more = more;
+    pkt->block1_size = size;
 
-    SET_OPTION(coap_pkt, COAP_OPTION_BLOCK1);
+    SET_OPTION(pkt, COAP_OPTION_BLOCK1);
     return 1;
 }
 /*---------------------------------------------------------------------------*/
 #if 0
-int coap_get_header_size2(coap_packet_t * const coap_pkt, uint32_t *size)
+int coap_get_header_size2(coap_packet_t * const pkt, uint32_t *size)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_SIZE2)) {
         return 0;
     }
-    *size = coap_pkt->size2;
+    *size = pkt->size2;
     return 1;
 }
 
 int
-coap_set_header_size2(coap_packet_t *coap_pkt, uint32_t size)
+coap_set_header_size2(coap_packet_t *pkt, uint32_t size)
 {
-    coap_pkt->size2 = size;
-    SET_OPTION(coap_pkt, COAP_OPTION_SIZE2);
+    pkt->size2 = size;
+    SET_OPTION(pkt, COAP_OPTION_SIZE2);
     return 1;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_size1(coap_packet_t *coap_pkt, uint32_t *size)
+coap_get_header_size1(coap_packet_t *pkt, uint32_t *size)
 {
-    if (!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1)) {
+    if (!IS_OPTION(pkt, COAP_OPTION_SIZE1)) {
         return 0;
     }
-    *size = coap_pkt->size1;
+    *size = pkt->size1;
     return 1;
 }
 int
-coap_set_header_size1(coap_packet_t *coap_pkt, uint32_t size)
+coap_set_header_size1(coap_packet_t *pkt, uint32_t size)
 {
-    coap_pkt->size1 = size;
-    SET_OPTION(coap_pkt, COAP_OPTION_SIZE1);
+    pkt->size1 = size;
+    SET_OPTION(pkt, COAP_OPTION_SIZE1);
     return 1;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_payload(coap_packet_t *coap_pkt, const uint8_t **payload)
+coap_get_payload(coap_packet_t *pkt, const uint8_t **payload)
 {
-    if (coap_pkt->payload) {
-        *payload = coap_pkt->payload;
-        return coap_pkt->payload_len;
+    if (pkt->payload) {
+        *payload = pkt->payload;
+        return pkt->payload_len;
     } else {
         *payload = NULL;
         return 0;
     }
 }
 int
-coap_set_payload(coap_packet_t *coap_pkt, const void *payload, size_t length)
+coap_set_payload(coap_packet_t *pkt, const void *payload, size_t length)
 {
-    coap_pkt->payload = (uint8_t *)payload;
-    coap_pkt->payload_len = MIN(MAX_PAYLOAD_SIZE, length);
+    pkt->payload = (uint8_t *)payload;
+    pkt->payload_len = MIN(MAX_PAYLOAD_SIZE, length);
 
-    return coap_pkt->payload_len;
+    return pkt->payload_len;
 }
 /*---------------------------------------------------------------------------*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fe3c27f6/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index aef230f..11377eb 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -97,58 +97,67 @@ enum
 
 /* parsed message struct */
 typedef struct coap_packet {
-  uint8_t *buffer; /* pointer to CoAP header / incoming packet buffer / memory
-                      to serialize packet */
-
-  uint8_t version;
-  coap_message_type_t type;
-  uint8_t code;
-  uint16_t mid;
-
-  uint8_t token_len;
-  uint8_t token[COAP_TOKEN_LEN];
-
-  uint8_t options[COAP_OPTION_SIZE1 / OPTION_MAP_SIZE +
-                  1]; /* bitmap to check if option is set */
-
-  uint16_t content_format; /* parse options once and store; allows setting
-                              options in random order  */
-  uint32_t max_age;
-  uint8_t etag_len;
-  uint8_t etag[COAP_ETAG_LEN];
-  size_t proxy_uri_len;
-  const char *proxy_uri;
-  size_t proxy_scheme_len;
-  const char *proxy_scheme;
-  size_t uri_host_len;
-  const char *uri_host;
-  size_t location_path_len;
-  const char *location_path;
-  uint16_t uri_port;
-  size_t location_query_len;
-  const char *location_query;
-  size_t uri_path_len;
-  const char *uri_path;
-  int32_t observe;
-  uint16_t accept;
-  uint8_t if_match_len;
-  uint8_t if_match[COAP_ETAG_LEN];
-  uint32_t block2_num;
-  uint8_t block2_more;
-  uint16_t block2_size;
-  uint32_t block2_offset;
-  uint32_t block1_num;
-  uint8_t block1_more;
-  uint16_t block1_size;
-  uint32_t block1_offset;
-  uint32_t size2;
-  uint32_t size1;
-  size_t uri_query_len;
-  const char *uri_query;
-  uint8_t if_none_match;
-
-  uint16_t payload_len;
-  uint8_t *payload;
+    /* pointer to CoAP header / incoming packet buffer / memory
+       to serialize packet */
+    uint8_t *buffer;
+
+    uint8_t version;
+    coap_message_type_t type;
+    uint8_t code;
+    uint16_t mid;   /* message ID */
+
+    uint8_t token_len;
+    uint8_t token[COAP_TOKEN_LEN];
+
+    /* bitmap to check if option is set */
+    uint8_t options[COAP_OPTION_SIZE1 / OPTION_MAP_SIZE + 1];
+
+    /* parse options once and store; allows setting options in random order  */
+    uint16_t content_format;
+    uint32_t max_age;
+#if 0
+    uint8_t etag_len;
+    uint8_t etag[COAP_ETAG_LEN];
+#endif
+#if COAP_PROXY_OPTION_PROCESSING
+    uint16_t proxy_uri_len;
+    char *proxy_uri;
+    uint16_t proxy_scheme_len;
+    char *proxy_scheme;
+#endif
+    uint16_t uri_host_len;
+    char *uri_host;
+#if 0
+    uint16_t loc_path_len;
+    char *loc_path;
+    uint16_t loc_query_len;
+    char *loc_query;
+#endif
+    uint16_t uri_port;
+    uint16_t uri_path_len;
+    char *uri_path;
+    int32_t observe;
+    uint16_t accept;
+#if 0
+    uint8_t if_match_len;
+    uint8_t if_match[COAP_ETAG_LEN];
+#endif
+    uint32_t block2_num;
+    uint8_t block2_more;
+    uint16_t block2_size;
+    uint32_t block2_offset;
+    uint32_t block1_num;
+    uint8_t block1_more;
+    uint16_t block1_size;
+    uint32_t block1_offset;
+    uint32_t size2;
+    uint32_t size1;
+    uint16_t uri_query_len;
+    char *uri_query;
+    uint8_t if_none_match;
+
+    uint16_t payload_len;
+    uint8_t *payload;
 } coap_packet_t;
 
 /* option format serialization */