IOT-1072 Unfork libcoap: update forked headers
authorDave Thaler <dthaler@microsoft.com>
Wed, 13 Jul 2016 22:24:11 +0000 (15:24 -0700)
committerDave Thaler <dthaler@microsoft.com>
Fri, 16 Sep 2016 22:31:46 +0000 (22:31 +0000)
Make the .h files compatible between the forked libcoap and the official
libcoap, so that no breaking changes (only additions) are done to the
official libcoap, which other projects depend on the current
types/prototypes in.

Make any additions (that are beyond the official libcoap, but that are
already used by IoTivity code) to libcoap .h files follow the conventions of
libcoap, to make it more likely they'll be accepted back into the upstream
libcoap.  E.g., coap_transport_type -> coap_transport_t, etc.

Leaving WITH_UPSTREAM_LIBCOAP off by default on all OS's in this change.
Turning it on by default in certain OS's will be done as part of a
separate change.

Change-Id: I373ef818b8aeb7608c5e3511dc9880047946fbe0
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9373
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: David Antler <david.a.antler@intel.com>
31 files changed:
extlibs/libcoap/SConscript
extlibs/tinydtls/tinydtls.h
resource/csdk/connectivity/inc/caprotocolmessage.h
resource/csdk/connectivity/inc/catcpinterface.h
resource/csdk/connectivity/lib/libcoap-4.1.1/async.c
resource/csdk/connectivity/lib/libcoap-4.1.1/block.c
resource/csdk/connectivity/lib/libcoap-4.1.1/debug.c
resource/csdk/connectivity/lib/libcoap-4.1.1/include/coap/option.h
resource/csdk/connectivity/lib/libcoap-4.1.1/include/coap/pdu.h
resource/csdk/connectivity/lib/libcoap-4.1.1/net.c
resource/csdk/connectivity/lib/libcoap-4.1.1/option.c
resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c
resource/csdk/connectivity/lib/libcoap-4.1.1/resource.c
resource/csdk/connectivity/lib/libcoap-4.1.1/subscribe.c
resource/csdk/connectivity/src/SConscript
resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c
resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrclient.c
resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp
resource/csdk/connectivity/src/cablockwisetransfer.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/connectivity/src/ra_adapter/caraadapter.c
resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/connectivity/test/cablocktransfertest.cpp
resource/csdk/connectivity/test/caprotocolmessagetest.cpp
resource/csdk/stack/include/octypes.h
resource/csdk/stack/src/occlientcb.c
resource/csdk/stack/src/ocstack.c
run.bat

index 338e650..52a75ac 100644 (file)
@@ -36,13 +36,17 @@ ca_transport = libcoap_env.get('TARGET_TRANSPORT')
 with_tcp = libcoap_env.get('WITH_TCP')
 with_upstream_libcoap = libcoap_env.get('WITH_UPSTREAM_LIBCOAP')
 
+# Temporary LibCoAP URL is a fork of the original.
+# Once a pull request is merged, change this back to the obgm original below.
+libcoap_repo_url    = 'https://github.com/dthaler/libcoap'
+#libcoap_repo_url    = 'https://github.com/obgm/libcoap'
+
 ######################################################################
 # Download libCoAP
 ######################################################################
 libcoap_branch           = 'develop'
 libcoap_dir              = os.path.join(src_dir, 'extlibs', 'libcoap', 'libcoap')
 libcoap_zip_file         = os.path.join(src_dir, 'extlibs', 'libcoap', libcoap_branch + '.zip')
-libcoap_repo_url         = 'https://github.com/obgm/libcoap'
 libcoap_url              = libcoap_repo_url + '/archive/' + libcoap_branch + '.zip'
 libcoap_checkout_command = 'git clone ' + libcoap_repo_url + '.git extlibs/libcoap/libcoap --branch ' + libcoap_branch
 
@@ -134,6 +138,7 @@ if env.get('LOGGING') == '1':
 ######################################################################
 with_upstream_libcoap = libcoap_env.get('WITH_UPSTREAM_LIBCOAP')
 if with_upstream_libcoap == '1':
+    libcoap_env.PrependUnique(CPPPATH = ['libcoap/include/coap'])
     libcoap_env.AppendUnique(CPPDEFINES = ['WITH_UPSTREAM_LIBCOAP'])
     libcoap_src_root = os.path.join(libcoap_dir, 'src')
 
@@ -151,11 +156,14 @@ if with_upstream_libcoap == '1':
         '\@LIBCOAP_PACKAGE_VERSION\@'       : libcoap_version
         }
     libcoap_env.Substfile(coap_h_pc_file, SUBST_DICT = pc_vars)
+
+    libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
+    libcoap_src.remove(os.path.join(libcoap_src_root, 'coap_io_lwip.c'))
 else:
     # For bring up purposes only, the forked version will live here.
     libcoap_src_root = src_dir + '/resource/csdk/connectivity/lib/libcoap-4.1.1'
+    libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
 
-libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
 libcoap = libcoap_env.StaticLibrary('coap', libcoap_src, OBJPREFIX='libcoap_')
 
 libcoap_env.InstallTarget([libcoap], 'coap')
index eca7ff7..7921b08 100644 (file)
@@ -52,7 +52,7 @@
 #  if defined(__cplusplus)
 #    define INLINE_API inline
 #  else
-#    ifdef _WIN32
+#    ifdef _MSC_VER
 #      define INLINE_API static __inline
 #    else
 #      define INLINE_API static inline
index 4323120..6e23174 100644 (file)
@@ -60,7 +60,7 @@ static const uint8_t PAYLOAD_MARKER = 1;
  * @return  generated pdu.
  */
 coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_t *endpoint,
-                          coap_list_t **optlist, coap_transport_type *transport);
+                          coap_list_t **optlist, coap_transport_t *transport);
 
 /**
  * extracts request information from received pdu.
@@ -102,7 +102,7 @@ CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endp
  */
 coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
                               const CAEndpoint_t *endpoint, coap_list_t *options,
-                              coap_transport_type *transport);
+                              coap_transport_t *transport);
 
 /**
  * parse the URI and creates the options.
@@ -201,7 +201,8 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode,
  * @param[in]    endpoint            endpoint information.
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
-CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo,
+CAResult_t CAGetTokenFromPDU(const coap_hdr_transport_t *pdu_hdr,
+                             CAInfo_t *outInfo,
                              const CAEndpoint_t *endpoint);
 
 /**
index 1ce03a7..23b9c46 100644 (file)
@@ -94,7 +94,7 @@ void CATCPPullData();
  * @param[out]   transport    TCP Server address.
  * @param[out]   headerlen    TCP Server port.
  */
-void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_type *transport,
+void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_t *transport,
                            size_t *headerlen);
 
 /**
index 236d0c4..fd2852e 100644 (file)
 #include "include/coap/async.h"
 
 coap_async_state_t *
-coap_register_async(coap_context_t *context, coap_address_t *peer, coap_pdu_t *request,
-        unsigned char flags, void *data)
-{
+coap_register_async(coap_context_t *context, coap_address_t *peer,
+        coap_pdu_t *request, unsigned char flags, void *data) {
     coap_async_state_t *s;
     coap_tid_t id;
 
     coap_transaction_id(peer, request, &id);
     LL_SEARCH_SCALAR(context->async_state, s, id, id);
 
-    if (s != NULL)
-    {
+    if (s != NULL) {
         /* We must return NULL here as the caller must know that he is
          * responsible for releasing @p data. */
         debug("asynchronous state for transaction %d already registered\n", id);
@@ -39,28 +37,26 @@ coap_register_async(coap_context_t *context, coap_address_t *peer, coap_pdu_t *r
 
     /* store information for handling the asynchronous task */
     s = (coap_async_state_t *) coap_malloc(sizeof(coap_async_state_t) +
-            request->hdr->coap_hdr_udp_t.token_length);
-    if (!s)
-    {
+            request->transport_hdr->udp.token_length);
+    if (!s) {
         coap_log(LOG_CRIT, "coap_register_async: insufficient memory\n");
         return NULL;
     }
 
-    memset(s, 0, sizeof(coap_async_state_t) + request->hdr->coap_hdr_udp_t.token_length);
+    memset(s, 0, sizeof(coap_async_state_t) + request->transport_hdr->udp.token_length);
 
     /* set COAP_ASYNC_CONFIRM according to request's type */
     s->flags = flags & ~COAP_ASYNC_CONFIRM;
-    if (request->hdr->coap_hdr_udp_t.type == COAP_MESSAGE_CON)
+    if (request->transport_hdr->udp.type == COAP_MESSAGE_CON)
         s->flags |= COAP_ASYNC_CONFIRM;
 
     s->appdata = data;
 
     memcpy(&s->peer, peer, sizeof(coap_address_t));
 
-    if (request->hdr->coap_hdr_udp_t.token_length)
-    {
-        s->tokenlen = request->hdr->coap_hdr_udp_t.token_length;
-        memcpy(s->token, request->hdr->coap_hdr_udp_t.token, request->hdr->coap_hdr_udp_t.token_length);
+    if (request->transport_hdr->udp.token_length) {
+        s->tokenlen = request->transport_hdr->udp.token_length;
+        memcpy(s->token, request->transport_hdr->udp.token, request->transport_hdr->udp.token_length);
     }
 
     memcpy(&s->id, &id, sizeof(coap_tid_t));
@@ -73,15 +69,14 @@ coap_register_async(coap_context_t *context, coap_address_t *peer, coap_pdu_t *r
 }
 
 coap_async_state_t *
-coap_find_async(coap_context_t *context, coap_tid_t id)
-{
+coap_find_async(coap_context_t *context, coap_tid_t id) {
     coap_async_state_t *tmp;
     LL_SEARCH_SCALAR(context->async_state, tmp, id, id);
     return tmp;
 }
 
-int coap_remove_async(coap_context_t *context, coap_tid_t id, coap_async_state_t **s)
-{
+int
+coap_remove_async(coap_context_t *context, coap_tid_t id, coap_async_state_t **s) {
     coap_async_state_t *tmp = coap_find_async(context, id);
 
     if (tmp)
@@ -91,8 +86,8 @@ int coap_remove_async(coap_context_t *context, coap_tid_t id, coap_async_state_t
     return tmp != NULL;
 }
 
-void coap_free_async(coap_async_state_t *s)
-{
+void
+coap_free_async(coap_async_state_t *s) {
     if (s && (s->flags & COAP_ASYNC_RELEASE_DATA) != 0)
         coap_free(s->appdata);
     coap_free(s);
index f431689..d014f3d 100644 (file)
 #define min(a,b) ((a) < (b) ? (a) : (b))
 
 #ifndef WITHOUT_BLOCK
-unsigned int coap_opt_block_num(const coap_opt_t *block_opt)
-{
+unsigned int
+coap_opt_block_num(const coap_opt_t *block_opt) {
     unsigned int num = 0;
     unsigned short len;
 
     len = coap_opt_length(block_opt);
 
-    if (len == 0)
-    {
+    if (len == 0) {
         return 0;
     }
 
-    if (len > 1)
-    {
-        num = coap_decode_var_bytes(COAP_OPT_VALUE(block_opt), COAP_OPT_LENGTH(block_opt) - 1);
+    if (len > 1) {
+        num = coap_decode_var_bytes(COAP_OPT_VALUE(block_opt),
+                                    COAP_OPT_LENGTH(block_opt) - 1);
     }
 
     return (num << 4) | ((*COAP_OPT_BLOCK_LAST(block_opt) & 0xF0) >> 4);
 }
 
-int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block)
-{
+int
+coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block) {
     coap_opt_iterator_t opt_iter;
     coap_opt_t *option;
 
     assert(block);
     memset(block, 0, sizeof(coap_block_t));
 
-    if (pdu && (option = coap_check_option(pdu, type, &opt_iter)))
-    {
+    if (pdu && (option = coap_check_option(pdu, type, &opt_iter)) != NULL) {
         block->szx = COAP_OPT_BLOCK_SZX(option);
         if (COAP_OPT_BLOCK_MORE(option))
             block->m = 1;
@@ -63,24 +61,22 @@ int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block)
     return 0;
 }
 
-int coap_write_block_opt(coap_block_t *block, unsigned short type, coap_pdu_t *pdu,
-        size_t data_length)
-{
+int
+coap_write_block_opt(coap_block_t *block, unsigned short type,
+        coap_pdu_t *pdu, size_t data_length) {
     size_t start, want, avail;
     unsigned char buf[3];
 
     assert(pdu);
 
     /* Block2 */
-    if (type != COAP_OPTION_BLOCK2)
-    {
+    if (type != COAP_OPTION_BLOCK2) {
         warn("coap_write_block_opt: skipped unknown option\n");
         return -1;
     }
 
     start = block->num << (block->szx + 4);
-    if (data_length <= start)
-    {
+    if (data_length <= start) {
         debug("illegal block requested\n");
         return -2;
     }
@@ -89,30 +85,24 @@ int coap_write_block_opt(coap_block_t *block, unsigned short type, coap_pdu_t *p
     want = 1 << (block->szx + 4);
 
     /* check if entire block fits in message */
-    if (want <= avail)
-    {
+    if (want <= avail) {
         block->m = want < data_length - start;
-    }
-    else
-    {
+    } else {
         /* Sender has requested a block that is larger than the remaining
          * space in pdu. This is ok if the remaining data fits into the pdu
          * anyway. The block size needs to be adjusted only if there is more
          * data left that cannot be delivered in this message. */
 
-        if (data_length - start <= avail)
-        {
+        if (data_length - start <= avail) {
 
             /* it's the final block and everything fits in the message */
             block->m = 0;
         }
-        else
-        {
+        else {
             unsigned char szx;
 
             /* we need to decrease the block size */
-            if (avail < 16)
-            { /* bad luck, this is the smallest block size */
+            if (avail < 16) { /* bad luck, this is the smallest block size */
                 debug("not enough space, even the smallest block does not fit");
                 return -3;
             }
@@ -126,21 +116,22 @@ int coap_write_block_opt(coap_block_t *block, unsigned short type, coap_pdu_t *p
 
     /* to re-encode the block option */
     coap_add_option(pdu, type,
-            coap_encode_var_bytes(buf, ((block->num << 4) | (block->m << 3) | block->szx)), buf,
-            coap_udp);
+            coap_encode_var_bytes(buf, ((block->num << 4) | (block->m << 3) | block->szx)), buf);
 
     return 1;
 }
 
-int coap_add_block(coap_pdu_t *pdu, unsigned int len, const unsigned char *data,
-        unsigned int block_num, unsigned char block_szx)
-{
+int
+coap_add_block(coap_pdu_t *pdu, unsigned int len, const unsigned char *data,
+        unsigned int block_num, unsigned char block_szx) {
     size_t start;
     start = block_num << (block_szx + 4);
 
     if (len <= start)
         return 0;
 
-    return coap_add_data(pdu, min(len - start, (unsigned int)(1 << (block_szx + 4))), data + start);
+    return coap_add_data(pdu,
+                         min(len - start, (unsigned int)(1 << (block_szx + 4))),
+                         data + start);
 }
 #endif /* WITHOUT_BLOCK  */
index 2970459..215e4d4 100644 (file)
 
 static coap_log_t maxlog = LOG_WARNING; /* default maximum log level */
 
-coap_log_t coap_get_log_level()
-{
+coap_log_t
+coap_get_log_level() {
     return maxlog;
 }
 
-void coap_set_log_level(coap_log_t level)
-{
+void
+coap_set_log_level(coap_log_t level) {
     maxlog = level;
 }
 
 /* this array has the same order as the type log_t */
-static char *loglevels[] =
-{ "EMRG", "ALRT", "CRIT", "ERR", "WARN", "NOTE", "INFO", "DEBG" };
+static char *loglevels[] = {
+ "EMRG", "ALRT", "CRIT", "ERR", "WARN", "NOTE", "INFO", "DEBG"
+};
 
 #ifdef HAVE_TIME_H
 
-INLINE_API size_t print_timestamp(char *s, size_t len, coap_tick_t t)
-{
+INLINE_API size_t
+print_timestamp(char *s, size_t len, coap_tick_t t) {
     struct tm *tmp;
     time_t now = clock_offset + (t / COAP_TICKS_PER_SECOND);
     tmp = localtime(&now);
@@ -64,8 +65,7 @@ INLINE_API size_t print_timestamp(char *s, size_t len, coap_tick_t t)
 #else /* alternative implementation: just print the timestamp */
 
 INLINE_API size_t
-print_timestamp(char *s, size_t len, coap_tick_t t)
-{
+print_timestamp(char *s, size_t len, coap_tick_t t) {
 #ifdef HAVE_SNPRINTF
     return snprintf(s, len, "%u.%03u",
             (unsigned int)(clock_offset + (t / COAP_TICKS_PER_SECOND)),
@@ -90,8 +90,7 @@ print_timestamp(char *s, size_t len, coap_tick_t t)
  * @return The length of @p s.
  */
 INLINE_API size_t
-strnlen(const char *s, size_t maxlen)
-{
+strnlen(const char *s, size_t maxlen) {
     size_t n = 0;
     while(*s++ && n < maxlen)
     ++n;
@@ -99,9 +98,9 @@ strnlen(const char *s, size_t maxlen)
 }
 #endif /* HAVE_STRNLEN */
 
-unsigned int print_readable(const unsigned char *data, unsigned int len, unsigned char *result,
-        unsigned int buflen, int encode_always)
-{
+unsigned int
+print_readable(const unsigned char *data, unsigned int len, unsigned char *result,
+        unsigned int buflen, int encode_always) {
     const unsigned char hex[] = "0123456789ABCDEF";
     unsigned int cnt = 0;
     assert(data || len == 0);
@@ -109,19 +108,14 @@ unsigned int print_readable(const unsigned char *data, unsigned int len, unsigne
     if (buflen == 0 || len == 0)
         return 0;
 
-    while (len)
-    {
-        if (!encode_always && isprint(*data))
-        {
+    while (len) {
+        if (!encode_always && isprint(*data)) {
             if (cnt == buflen)
                 break;
             *result++ = *data;
             ++cnt;
-        }
-        else
-        {
-            if (cnt + 4 < buflen)
-            {
+        } else {
+            if (cnt + 4 < buflen) {
                 *result++ = '\\';
                 *result++ = 'x';
                 *result++ = hex[(*data & 0xf0) >> 4];
@@ -144,8 +138,8 @@ unsigned int print_readable(const unsigned char *data, unsigned int len, unsigne
 #define min(a,b) ((a) < (b) ? (a) : (b))
 #endif
 
-size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len)
-{
+size_t
+coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len) {
 #if defined(HAVE_ARPA_INET_H) || defined(_WIN32)
     const void *addrptr = NULL;
 #if defined(__ANDROID__)
@@ -157,8 +151,7 @@ size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, si
 #endif
     unsigned char *p = buf;
 
-    switch (addr->addr.sa.sa_family)
-    {
+    switch (addr->addr.sa.sa_family) {
         case AF_INET:
             addrptr = &addr->addr.sin.sin_addr;
             port = ntohs(addr->addr.sin.sin_port);
@@ -178,18 +171,15 @@ size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, si
             return min(22, len);
     }
 
-    if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *) p, len) == 0)
-    {
+    if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *) p, len) == 0) {
         perror("coap_print_addr");
         return 0;
     }
 
     p += strnlen((char *) p, len);
 
-    if (addr->addr.sa.sa_family == AF_INET6)
-    {
-        if (p < buf + len)
-        {
+    if (addr->addr.sa.sa_family == AF_INET6) {
+        if (p < buf + len) {
             *p++ = ']';
         }
         else
@@ -215,10 +205,8 @@ size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, si
 
     *p++ = '[';
 
-    for (i=0; i < 16; i += 2)
-    {
-        if (i)
-        {
+    for (i=0; i < 16; i += 2) {
+        if (i) {
             *p++ = ':';
         }
         *p++ = hex[(addr->addr.u8[i] & 0xf0) >> 4];
@@ -252,8 +240,8 @@ size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, si
 }
 
 #ifndef WITH_CONTIKI
-void coap_show_pdu(const coap_pdu_t *pdu)
-{
+void
+coap_show_pdu(const coap_pdu_t *pdu) {
 #ifndef WITH_TCP
     unsigned char buf[COAP_MAX_PDU_SIZE]; /* need some space for output creation */
 #else
@@ -263,22 +251,18 @@ void coap_show_pdu(const coap_pdu_t *pdu)
     coap_opt_iterator_t opt_iter;
     coap_opt_t *option;
 
-    fprintf(COAP_DEBUG_FD, "v:%d t:%d tkl:%d c:%d id:%u", pdu->hdr->coap_hdr_udp_t.version,
-            pdu->hdr->coap_hdr_udp_t.type, pdu->hdr->coap_hdr_udp_t.token_length,
-            pdu->hdr->coap_hdr_udp_t.code, ntohs(pdu->hdr->coap_hdr_udp_t.id));
+    fprintf(COAP_DEBUG_FD, "v:%d t:%d tkl:%d c:%d id:%u", pdu->transport_hdr->udp.version,
+            pdu->transport_hdr->udp.type, pdu->transport_hdr->udp.token_length,
+            pdu->transport_hdr->udp.code, ntohs(pdu->transport_hdr->udp.id));
 
     /* show options, if any */
-    coap_option_iterator_init((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL, coap_udp);
+    coap_option_iterator_init((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL);
 
-    while ((option = coap_option_next(&opt_iter)))
-    {
-        if (!have_options)
-        {
+    while ((option = coap_option_next(&opt_iter))) {
+        if (!have_options) {
             have_options = 1;
             fprintf(COAP_DEBUG_FD, " o: [");
-        }
-        else
-        {
+        } else {
             fprintf(COAP_DEBUG_FD, ",");
         }
 
@@ -286,12 +270,9 @@ void coap_show_pdu(const coap_pdu_t *pdu)
                 || opt_iter.type == COAP_OPTION_URI_HOST
                 || opt_iter.type == COAP_OPTION_LOCATION_PATH
                 || opt_iter.type == COAP_OPTION_LOCATION_QUERY
-                || opt_iter.type == COAP_OPTION_URI_PATH || opt_iter.type == COAP_OPTION_URI_QUERY)
-        {
+                || opt_iter.type == COAP_OPTION_URI_PATH || opt_iter.type == COAP_OPTION_URI_QUERY) {
             encode = 0;
-        }
-        else
-        {
+        } else {
             encode = 1;
         }
 
@@ -303,8 +284,7 @@ void coap_show_pdu(const coap_pdu_t *pdu)
     if (have_options)
         fprintf(COAP_DEBUG_FD, " ]");
 
-    if (pdu->data)
-    {
+    if (pdu->data) {
         assert(pdu->data < (unsigned char *) pdu->hdr + pdu->length);
         print_readable(pdu->data, (unsigned char *) pdu->hdr + pdu->length - pdu->data, buf,
                 sizeof(buf), 0);
@@ -317,25 +297,22 @@ void coap_show_pdu(const coap_pdu_t *pdu)
 #else /* WITH_CONTIKI */
 
 void
-coap_show_pdu(const coap_pdu_t *pdu)
-{
+coap_show_pdu(const coap_pdu_t *pdu) {
     unsigned char buf[80]; /* need some space for output creation */
 
     PRINTF("v:%d t:%d oc:%d c:%d id:%u",
-            pdu->hdr->coap_hdr_udp_t.version, pdu->hdr->coap_hdr_udp_t.type,
-            pdu->hdr->coap_hdr_udp_t.optcnt, pdu->hdr->coap_hdr_udp_t.code,
-            uip_ntohs(pdu->hdr->coap_hdr_udp_t.id));
+            pdu->transport_hdr->udp.version, pdu->transport_hdr->udp.type,
+            pdu->transport_hdr->udp.optcnt, pdu->transport_hdr->udp.code,
+            uip_ntohs(pdu->transport_hdr->udp.id));
 
     /* show options, if any */
-    if (pdu->hdr->coap_hdr_udp_t.optcnt)
-    {
+    if (pdu->transport_hdr->udp.optcnt) {
         coap_opt_iterator_t opt_iter;
         coap_opt_t *option;
-        coap_option_iterator_init((coap_pdu_t *)pdu, &opt_iter, COAP_OPT_ALL, coap_udp);
+        coap_option_iterator_init((coap_pdu_t *)pdu, &opt_iter, COAP_OPT_ALL);
 
         PRINTF(" o:");
-        while ((option = coap_option_next(&opt_iter)))
-        {
+        while ((option = coap_option_next(&opt_iter))) {
 
             if (print_readable(COAP_OPT_VALUE(option),
                             COAP_OPT_LENGTH(option),
@@ -344,8 +321,7 @@ coap_show_pdu(const coap_pdu_t *pdu)
         }
     }
 
-    if (pdu->data < (unsigned char *)pdu->hdr + pdu->length)
-    {
+    if (pdu->data < (unsigned char *)pdu->hdr + pdu->length) {
         print_readable(pdu->data,
                 (unsigned char *)pdu->hdr + pdu->length - pdu->data,
                 buf, sizeof(buf), 0 );
@@ -358,16 +334,16 @@ coap_show_pdu(const coap_pdu_t *pdu)
 #endif /* NDEBUG */
 
 #ifdef WITH_ARDUINO
-void coap_log_impl(coap_log_t level, const char *format, ...)
-{
+void
+coap_log_impl(coap_log_t level, const char *format, ...) {
     //TODO: Implement logging functionalities for Arduino
 }
 #endif
 
 #ifndef WITH_ARDUINO
 #ifndef WITH_CONTIKI
-void coap_log_impl(coap_log_t level, const char *format, ...)
-{
+void
+coap_log_impl(coap_log_t level, const char *format, ...) {
     char timebuf[32];
     coap_tick_t now;
     va_list ap;
@@ -392,8 +368,7 @@ void coap_log_impl(coap_log_t level, const char *format, ...)
 }
 #else /* WITH_CONTIKI */
 void
-coap_log_impl(coap_log_t level, const char *format, ...)
-{
+coap_log_impl(coap_log_t level, const char *format, ...) {
     char timebuf[32];
     coap_tick_t now;
     va_list ap;
index 8441d5a..6463afd 100644 (file)
@@ -82,7 +82,7 @@ size_t coap_opt_size(const coap_opt_t *opt);
  * @param pdu The PDU containing the options.
  * @return A pointer to the first option if available, or @c NULL otherwise.
  */
-coap_opt_t *options_start(coap_pdu_t *pdu, coap_transport_type transport);
+coap_opt_t *options_start(coap_pdu_t *pdu, coap_transport_t transport);
 
 /**
  * Interprets @p opt as pointer to a CoAP option and advances to
@@ -189,6 +189,26 @@ typedef struct
 } coap_opt_iterator_t;
 
 /**
+ * Initializes the given option iterator @p oi to point to the beginning of the
+ * @p pdu's option list. This function returns @p oi on success, @c NULL
+ * otherwise (i.e. when no options exist). Note that a length check on the
+ * option list must be performed before coap_option_iterator_init() is called.
+ *
+ * @param pdu    The PDU the options of which should be walked through.
+ * @param oi     An iterator object that will be initilized.
+ * @param filter An optional option type filter.
+ *               With @p type != @c COAP_OPT_ALL, coap_option_next()
+ *               will return only options matching this bitmask.
+ *               Fence-post options @c 14, @c 28, @c 42, ... are always
+ *               skipped.
+ *
+ * @return       The iterator object @p oi on success, @c NULL otherwise.
+ */
+coap_opt_iterator_t *coap_option_iterator_init(coap_pdu_t *pdu,
+                                               coap_opt_iterator_t *oi,
+                                               const coap_opt_filter_t filter);
+
+/**
  * Initializes the given option iterator @p oi to point to the
  * beginning of the @p pdu's option list. This function returns @p oi
  * on success, @c NULL otherwise (i.e. when no options exist).
@@ -205,8 +225,8 @@ typedef struct
  *
  * @return The iterator object @p oi on success, @c NULL otherwise.
  */
-coap_opt_iterator_t *coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
-        const coap_opt_filter_t filter, coap_transport_type transport);
+coap_opt_iterator_t *coap_option_iterator_init2(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
+        const coap_opt_filter_t filter, coap_transport_t transport);
 
 /**
  * Updates the iterator @p oi to point to the next option. This
index 34b1b5c..417473f 100644 (file)
@@ -6,8 +6,8 @@
  * README for terms of use.
  */
 
-#ifndef _PDU_H_
-#define _PDU_H_
+#ifndef _COAP_PDU_H_
+#define _COAP_PDU_H_
 
 #include "config.h"
 #include "coap_list.h"
 
 #ifndef SHORT_ERROR_RESPONSE
 /**
- * Returns a human-readable response phrase for the specified CoAP
- * response @p code. This function returns @c NULL if not found.
+ * Returns a human-readable response phrase for the specified CoAP response @p
+ * code. This function returns @c NULL if not found.
  *
- * @param code The response code for which the literal phrase should
- * be retrieved.
+ * @param code The response code for which the literal phrase should be
+ *             retrieved.
  *
- * @return A zero-terminated string describing the error, or @c NULL
- * if not found.
+ * @return     A zero-terminated string describing the error, or @c NULL if not
+ *             found.
  */
 char *coap_response_phrase(unsigned char code);
 
@@ -156,9 +156,14 @@ char *coap_response_phrase(unsigned char code);
  * use an unallocated type here and hope for the best. */
 #define COAP_MEDIATYPE_ANY                         0xff /* any media type */
 
-/* CoAP transaction id */
-/*typedef unsigned short coap_tid_t; */
+/**
+  * coap_tid_t is used to store CoAP transaction id, i.e. a hash value
+  * built from the remote transport address and the message id of a
+  * CoAP PDU.  Valid transaction ids are greater or equal zero.
+  */
 typedef int coap_tid_t;
+
+/** Indicates an invalid transaction id. */
 #define COAP_INVALID_TID -1
 
 #define COAP_TCP_HEADER_NO_FIELD    2
@@ -182,100 +187,75 @@ typedef int coap_tid_t;
 #define COAP_OPTION_FIELD_16_BIT     256
 #define COAP_OPTION_FIELD_32_BIT     65536
 
-typedef enum
-{
-    coap_udp = 0,
-    coap_tcp,
-    coap_tcp_8bit,
-    coap_tcp_16bit,
-    coap_tcp_32bit
-} coap_transport_type;
+typedef enum {
+    COAP_UDP = 0,
+    COAP_TCP,
+    COAP_TCP_8BIT,
+    COAP_TCP_16BIT,
+    COAP_TCP_32BIT
+} coap_transport_t;
 
 #ifdef WORDS_BIGENDIAN
-typedef union
-{
-    struct
-    {
-        unsigned int version:2; /* protocol version */
-        unsigned int type:2; /* type flag */
-        unsigned int token_length:4; /* length of Token */
-        unsigned int code:8; /* request method (value 1--10) or response code (value 40-255) */
-        unsigned short id; /* message id */
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_udp_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_NO_FIELD];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_8_BIT];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_8bit_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_16_BIT];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_16bit_t;
-
-    struct
-    {
-        unsigned char header_data[6];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_32bit_t;
-
-} coap_hdr_t;
+typedef struct {
+  unsigned short version:2;      /* protocol version */
+  unsigned short type:2;         /* type flag */
+  unsigned short token_length:4; /* length of Token */
+  unsigned short code:8;         /* request method (value 1--10) or response
+                                    code (value 40-255) */
+  unsigned short id;             /* message id */
+  unsigned char token[];         /* the actual token, if any */
+} coap_hdr_udp_t;
 #else
-typedef union
-{
-    struct
-    {
-        unsigned short token_length :4; /* length of Token */
-        unsigned short type :2; /* type flag */
-        unsigned short version :2; /* protocol version */
-        unsigned short code :8; /* request method (value 1--10) or response code (value 40-255) */
-        unsigned short id; /* transaction id (network byte order!) */
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_udp_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_NO_FIELD];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_8_BIT];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_8bit_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_16_BIT];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_16bit_t;
-
-    struct
-    {
-        unsigned char header_data[COAP_TCP_HEADER_32_BIT];
-        unsigned char token[]; /* the actual token, if any */
-    } coap_hdr_tcp_32bit_t;
-
-} coap_hdr_t;
+typedef struct {
+  unsigned short token_length:4; /* length of Token */
+  unsigned short type:2;         /* type flag */
+  unsigned short version:2;      /* protocol version */
+  unsigned short code:8;         /* request method (value 1--10) or response
+                                    code (value 40-255) */
+  unsigned short id;             /* transaction id (network byte order!) */
+  unsigned char token[];         /* the actual token, if any */
+} coap_hdr_udp_t;
 #endif
 
+typedef struct {
+  unsigned char header_data[COAP_TCP_HEADER_NO_FIELD];
+  unsigned char token[]; /* the actual token, if any */
+} coap_hdr_tcp_t;
+
+typedef struct {
+  unsigned char header_data[COAP_TCP_HEADER_8_BIT];
+  unsigned char token[]; /* the actual token, if any */
+} coap_hdr_tcp_8bit_t;
+
+typedef struct {
+  unsigned char header_data[COAP_TCP_HEADER_16_BIT];
+  unsigned char token[]; /* the actual token, if any */
+} coap_hdr_tcp_16bit_t;
+
+typedef struct {
+  unsigned char header_data[6];
+  unsigned char token[]; /* the actual token, if any */
+} coap_hdr_tcp_32bit_t;
+
+typedef union {
+  coap_hdr_udp_t udp;
+  coap_hdr_tcp_t tcp;
+  coap_hdr_tcp_8bit_t tcp_8bit;
+  coap_hdr_tcp_16bit_t tcp_16bit;
+  coap_hdr_tcp_32bit_t tcp_32bit;
+} coap_hdr_transport_t;
+
+// Typedef for backwards compatibility.
+typedef coap_hdr_udp_t coap_hdr_t;
+
 #define COAP_MESSAGE_IS_EMPTY(MSG)    ((MSG).code == 0)
 #define COAP_MESSAGE_IS_REQUEST(MSG)  (!COAP_MESSAGE_IS_EMPTY(MSG)  \
                        && ((MSG).code < 32))
 #define COAP_MESSAGE_IS_RESPONSE(MSG) ((MSG).code >= 64 && (MSG).code <= 191)
 
-#define COAP_OPT_LONG 0x0F  /* OC == 0b1111 indicates that the option list in a
-                 * CoAP message is limited by 0b11110000 marker */
+#define COAP_OPT_LONG 0x0F  /* OC == 0b1111 indicates that the option list
+                             * in a CoAP message is limited by 0b11110000
+                             * marker */
 
 #define COAP_OPT_END 0xF0   /* end marker */
 
@@ -286,8 +266,7 @@ typedef union
  * coap_list_t.) The option's data will be added to the end of the coap_option
  * structure (see macro COAP_OPTION_DATA).
  */
-typedef struct
-{
+typedef struct {
     unsigned short key; /* the option key (no delta coding) */
     unsigned int length;
 } coap_option;
@@ -296,25 +275,43 @@ typedef struct
 #define COAP_OPTION_LENGTH(option) (option).length
 #define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
 
-/** Header structure for CoAP PDUs */
+/**
+ * Header structure for CoAP PDUs
+ */
 
-typedef struct
-{
+typedef struct {
     size_t max_size; /**< allocated storage for options and data */
 
-    coap_hdr_t *hdr;
+    union {
+        coap_hdr_t *hdr;          /**< Address of the first byte of the CoAP message.
+                                   *   This may or may not equal (coap_hdr_t*)(pdu+1)
+                                   *   depending on the memory management
+                                   *   implementation. */
+        coap_hdr_transport_t *transport_hdr; /**< Address of the first byte of the CoAP message.
+                                               *   This may or may not equal (coap_hdr_t*)(pdu+1)
+                                               *   depending on the memory management
+                                               *   implementation. */
+    };
     unsigned short max_delta; /**< highest option number */
     unsigned int length; /**< PDU length (including header, options, data)  */
     unsigned char *data; /**< payload */
 
 #ifdef WITH_LWIP
-    struct pbuf
-            *pbuf; /**< lwIP PBUF. The allocated coap_pdu_t will always reside inside the pbuf's payload, but the pointer has to be kept because no exact offset can be given. This field must not be accessed from outside, because the pbuf's reference count is checked to be 1 when the pbuf is assigned to the pdu, and the pbuf stays exclusive to this pdu. */
+    struct pbuf *pbuf;        /**< lwIP PBUF. The package data will always reside
+                               *    inside the pbuf's payload, but this pointer
+                               *    has to be kept because no exact offset can be
+                               *    given. This field must not be accessed from
+                               *    outside, because the pbuf's reference count
+                               *    is checked to be 1 when the pbuf is assigned
+                               *    to the pdu, and the pbuf stays exclusive to
+                               *    this pdu. */
 #endif
 
 } coap_pdu_t;
 
-/** Options in coap_pdu_t are accessed with the macro COAP_OPTION. */
+/**
+ * Options in coap_pdu_t are accessed with the macro COAP_OPTION.
+ */
 #define COAP_OPTION(node) ((coap_option *)(node)->options)
 #ifdef __cplusplus
 extern "C"
@@ -322,16 +319,16 @@ extern "C"
 #endif
 #ifdef WITH_LWIP
 /**
- * Creates a CoAP PDU from an lwIP @p pbuf, whose reference is passed on to
- * this function.
+ * Creates a CoAP PDU from an lwIP @p pbuf, whose reference is passed on to this
+ * function.
  *
  * The pbuf is checked for being contiguous, for having enough head space for
  * the PDU struct (which is located directly in front of the data, overwriting
  * the old other headers), and for having only one reference. The reference is
  * stored in the PDU and will be freed when the PDU is freed.
  *
- * (For now, these are errors; in future, a new pbuf might be allocated, the
- * data copied and the passed pbuf freed).
+ * (For now, these are fatal errors; in future, a new pbuf might be allocated,
+ * the data copied and the passed pbuf freed).
  *
  * This behaves like coap_pdu_init(0, 0, 0, pbuf->tot_len), and afterwards
  * copying the contents of the pbuf to the pdu.
@@ -343,6 +340,26 @@ coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
 
 /**
  * Creates a new CoAP PDU of given @p size (must be large enough to hold the
+ * basic CoAP message header (coap_hdr_t). The function returns a pointer to the
+ * node coap_pdu_t object on success, or @c NULL on error. The storage allocated
+ * for the result must be released with coap_delete_pdu().
+ *
+ * @param type The type of the PDU (one of COAP_MESSAGE_CON, COAP_MESSAGE_NON,
+ *             COAP_MESSAGE_ACK, COAP_MESSAGE_RST).
+ * @param code The message code.
+ * @param id   The message id to set or COAP_INVALID_TID if unknown.
+ * @param size The number of bytes to allocate for the actual message.
+ *
+ * @return A pointer to the new PDU object or @c NULL on error.
+ */
+coap_pdu_t *
+coap_pdu_init(unsigned char type,
+              unsigned char code,
+              unsigned short id,
+              size_t size);
+
+/**
+ * Creates a new CoAP PDU of given @p size (must be large enough to hold the
  * basic CoAP message header (coap_hdr_t). The function returns a pointer to
  * the node coap_pdu_t object on success, or @c NULL on error. The storage
  * allocated for the result must be released with coap_delete_pdu().
@@ -357,8 +374,16 @@ coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
  * @return A pointer to the new PDU object or @c NULL on error.
  */
 coap_pdu_t *
-coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
-              size_t size, coap_transport_type transport);
+coap_pdu_init2(unsigned char type, unsigned char code, unsigned short id,
+               size_t size, coap_transport_t transport);
+
+/**
+ * Clears any contents from @p pdu and resets @c version field, @c
+ * length and @c data pointers. @c max_size is set to @p size, any
+ * other field is set to @c 0. Note that @p pdu must be a valid
+ * pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
+ */
+void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
 
 /**
  * Clears any contents from @p pdu and resets @c version field, @c
@@ -366,24 +391,49 @@ coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
  * other field is set to @c 0. Note that @p pdu must be a valid
  * pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
  */
-void coap_pdu_clear(coap_pdu_t *pdu, size_t size, coap_transport_type transport,
-                    unsigned int length);
+void coap_pdu_clear2(coap_pdu_t *pdu, size_t size, coap_transport_t transport,
+                     unsigned int length);
+
+/**
+ * Creates a new CoAP PDU.
+ * The object is created on the heap and must be released using
+ * coap_delete_pdu();
+ *
+ * @deprecated This function allocates the maximum storage for each
+ * PDU. Use coap_pdu_init() instead.
+ */
+coap_pdu_t *coap_new_pdu(void);
 
 /**
  * Creates a new CoAP PDU. The object is created on the heap and must be released
  * using coap_delete_pdu();
  *
  * @deprecated This function allocates the maximum storage for each
- * PDU. Use coap_pdu_init() instead.
+ * PDU. Use coap_pdu_init2() instead.
  */
-coap_pdu_t *coap_new_pdu(coap_transport_type transport, unsigned int size);
+coap_pdu_t *coap_new_pdu2(coap_transport_t transport, unsigned int size);
 
 void coap_delete_pdu(coap_pdu_t *);
 
 /**
- * Parses @p data into the CoAP PDU structure given in @p result. This
- * function returns @c 0 on error or a number greater than zero on
- * success.
+ * Parses @p data into the CoAP PDU structure given in @p result.
+ * This function returns @c 0 on error or a number greater than zero on success.
+ *
+ * @param data   The raw data to parse as CoAP PDU
+ * @param length The actual size of @p data
+ * @param result The PDU structure to fill. Note that the structure must
+ *               provide space for at least @p length bytes to hold the
+ *               entire CoAP PDU.
+ *
+ * @return A value greater than zero on success or @c 0 on error.
+ */
+int coap_pdu_parse(unsigned char *data,
+                   size_t length,
+                   coap_pdu_t *result);
+
+/**
+ * Parses @p data into the CoAP PDU structure given in @p result.
+ * This function returns @c 0 on error or a number greater than zero on success.
  *
  * @param data   The raw data to parse as CoAP PDU
  * @param length The actual size of @p data
@@ -393,8 +443,8 @@ void coap_delete_pdu(coap_pdu_t *);
  * @param transport The transport type.
  * @return A value greater than zero on success or @c 0 on error.
  */
-int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
-                   coap_transport_type transport);
+int coap_pdu_parse2(unsigned char *data, size_t length, coap_pdu_t *pdu,
+                    coap_transport_t transport);
 
 #ifdef WITH_TCP
 /**
@@ -413,7 +463,7 @@ size_t coap_get_total_message_length(const unsigned char *data, size_t size);
  * @param size   payload size of pdu.
  * @return The transport type.
  */
-coap_transport_type coap_get_tcp_header_type_from_size(unsigned int size);
+coap_transport_t coap_get_tcp_header_type_from_size(unsigned int size);
 
 /**
  * Get transport type of coap header for coap over tcp
@@ -422,7 +472,7 @@ coap_transport_type coap_get_tcp_header_type_from_size(unsigned int size);
  * @param legnth   length value of init byte.
 * @return The transport type.
  */
-coap_transport_type coap_get_tcp_header_type_from_initbyte(unsigned int length);
+coap_transport_t coap_get_tcp_header_type_from_initbyte(unsigned int length);
 
 /**
  * Add length of option/payload into 'Len+ byte...' field of coap header
@@ -432,7 +482,7 @@ coap_transport_type coap_get_tcp_header_type_from_initbyte(unsigned int length);
  * @param transport The transport type.
  * @param length  length value of init byte.
  */
-void coap_add_length(const coap_pdu_t *pdu, coap_transport_type transport,
+void coap_add_length(const coap_pdu_t *pdu, coap_transport_t transport,
                      unsigned int length);
 
 /**
@@ -442,7 +492,7 @@ void coap_add_length(const coap_pdu_t *pdu, coap_transport_type transport,
  * @param transport The transport type.
  * @return length value of init byte.
  */
-unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transport);
+unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_t transport);
 
 /**
  * Get the length of option/payload field of coap header for coap over tcp.
@@ -451,7 +501,7 @@ unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transpor
  * @return transport The transport type.
  */
 unsigned int coap_get_length_from_header(const unsigned char *header,
-                                         coap_transport_type transport);
+                                         coap_transport_t transport);
 
 /**
  * Get length of header including len, TKL, Len+bytes, Code, token bytes for coap over tcp.
@@ -468,7 +518,7 @@ unsigned int coap_get_tcp_header_length(unsigned char *data);
  * @param transport The transport type.
  * @return header length.
  */
-unsigned int coap_get_tcp_header_length_for_transport(coap_transport_type transport);
+unsigned int coap_get_tcp_header_length_for_transport(coap_transport_t transport);
 
 /**
  * Get option length.
@@ -478,7 +528,7 @@ unsigned int coap_get_tcp_header_length_for_transport(coap_transport_type transp
  * @return total option length
  */
 size_t coap_get_opt_header_length(unsigned short key, size_t length);
-#endif
+#endif /* WITH_TCP */
 
 /**
  * Add code in coap header.
@@ -487,7 +537,7 @@ size_t coap_get_opt_header_length(unsigned short key, size_t length);
  * @param transport The transport type.
  * @param code  The message code.
  */
-void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport,
+void coap_add_code(const coap_pdu_t *pdu, coap_transport_t transport,
                    unsigned int code);
 
 /**
@@ -497,11 +547,29 @@ void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport,
  * @param transport The transport type.
  * @return The message code.
  */
-unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_type transport);
+unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_t transport);
+
+/**
+ * Adds token of length @p len to @p pdu.
+ * Adding the token destroys any following contents of the pdu. Hence options
+ * and data must be added after coap_add_token() has been called. In @p pdu,
+ * length is set to @p len + @c 4, and max_delta is set to @c 0.  This funtion
+ * returns @c 0 on error or a value greater than zero on success.
+ *
+ * @param pdu  The PDU where the token is to be added.
+ * @param len  The length of the new token.
+ * @param data The token to add.
+ *
+ * @return A value greater than zero on success, or @c 0 on error.
+ */
+int coap_add_token(coap_pdu_t *pdu,
+                   size_t len,
+                   const unsigned char *data);
+
 /**
  * Adds token of length @p len to @p pdu. Adding the token destroys
  * any following contents of the pdu. Hence options and data must be
- * added after coap_add_token() has been called. In @p pdu, length is
+ * added after coap_add_token2() has been called. In @p pdu, length is
  * set to @p len + @c 4, and max_delta is set to @c 0.  This funtion
  * returns @c 0 on error or a value greater than zero on success.
  *
@@ -511,54 +579,82 @@ unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_type transport)
  * @param transport The transport type.
  * @return A value greater than zero on success, or @c 0 on error.
  */
-int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data,
-                   coap_transport_type transport);
+int coap_add_token2(coap_pdu_t *pdu, size_t len, const unsigned char *data,
+                    coap_transport_t transport);
 
 /**
- * Get token from coap header base on transport type
+ * Get token from coap header
  *
  * @param pdu_hdr  The header pointer of PDU.
- * @param transport The transport type.
  * @param token  out parameter to get token.
  * @param token_length  out parameter to get token length.
  */
-void coap_get_token(const coap_hdr_t *pdu_hdr, coap_transport_type transport,
+void coap_get_token(const coap_hdr_t *pdu_hdr,
                     unsigned char **token, unsigned int *token_length);
 
 /**
+ * Get token from coap header based on transport type
+ *
+ * @param pdu_hdr  The header pointer of PDU.
+ * @param transport The transport type.
+ * @param token  out parameter to get token.
+ * @param token_length  out parameter to get token length.
+ */
+void coap_get_token2(const coap_hdr_transport_t *pdu_hdr, coap_transport_t transport,
+                     unsigned char **token, unsigned int *token_length);
+
+/**
+ * Adds option of given type to pdu that is passed as first parameter. 
+ * coap_add_option() destroys the PDU's data, so coap_add_data() must be called
+ * after all options have been added. As coap_add_token() destroys the options
+ * following the token, the token must be added before coap_add_option() is
+ * called. This function returns the number of bytes written or @c 0 on error.
+ */
+size_t coap_add_option(coap_pdu_t *pdu,
+                       unsigned short type,
+                       unsigned int len,
+                       const unsigned char *data);
+
+/**
  * Adds option of given type to pdu that is passed as first
- * parameter. coap_add_option() destroys the PDU's data, so
+ * parameter. coap_add_option2() destroys the PDU's data, so
  * coap_add_data() must be called after all options have been added.
- * As coap_add_token() destroys the options following the token,
- * the token must be added before coap_add_option() is called.
+ * As coap_add_token2() destroys the options following the token,
+ * the token must be added before coap_add_option2() is called.
  * This function returns the number of bytes written or @c 0 on error.
  */
-size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len,
-        const unsigned char *data, coap_transport_type transport);
+size_t coap_add_option2(coap_pdu_t *pdu, unsigned short type, unsigned int len,
+                        const unsigned char *data, coap_transport_t transport);
 
 /**
- * Adds option of given type to pdu that is passed as first
- * parameter, but does not write a val13ue. It works like coap_add_option with
- * respect to calling sequence (i.e. after token and before data).
- * This function returns a memory address to which the option data has to be
- * written before the PDU can be sent, or @c NULL on error.
+ * Adds option of given type to pdu that is passed as first parameter, but does
+ * not write a value. It works like coap_add_option with respect to calling
+ * sequence (i.e. after token and before data). This function returns a memory
+ * address to which the option data has to be written before the PDU can be
+ * sent, or @c NULL on error.
  */
-unsigned char *coap_add_option_later(coap_pdu_t *pdu, unsigned short type, unsigned int len);
+unsigned char *coap_add_option_later(coap_pdu_t *pdu,
+                                     unsigned short type,
+                                     unsigned int len);
 
 /**
- * Adds given data to the pdu that is passed as first parameter. Note
- * that the PDU's data is destroyed by coap_add_option(). coap_add_data()
- * must be called only once per PDU, otherwise the result is undefined.
+ * Adds given data to the pdu that is passed as first parameter. Note that the
+ * PDU's data is destroyed by coap_add_option(). coap_add_data() must be called
+ * only once per PDU, otherwise the result is undefined.
  */
-int coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data);
+int coap_add_data(coap_pdu_t *pdu,
+                  unsigned int len,
+                  const unsigned char *data);
 
 /**
- * Retrieves the length and data pointer of specified PDU. Returns 0 on error
- * or 1 if *len and *data have correct values. Note that these values are
- * destroyed with the pdu.
+ * Retrieves the length and data pointer of specified PDU. Returns 0 on error or
+ * 1 if *len and *data have correct values. Note that these values are destroyed
+ * with the pdu.
  */
-int coap_get_data(const coap_pdu_t *pdu, size_t *len, unsigned char **data);
+int coap_get_data(const coap_pdu_t *pdu,
+                  size_t *len,
+                  unsigned char **data);
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
-#endif /* _PDU_H_ */
+#endif /* _COAP_PDU_H_ */
index e81acae..d40388f 100644 (file)
@@ -510,7 +510,7 @@ int coap_option_check_critical(coap_context_t *ctx, coap_pdu_t *pdu, coap_opt_fi
     coap_opt_iterator_t opt_iter;
     int ok = 1;
 
-    coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL, coap_udp);
+    coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL);
 
     while (coap_option_next(&opt_iter))
     {
@@ -574,7 +574,7 @@ void coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, coap
     coap_hash((const unsigned char *)&peer->addr, sizeof(peer->addr), h);
 #endif /* WITH_LWIP || WITH_CONTIKI */
 
-    coap_hash((const unsigned char *)&pdu->hdr->coap_hdr_udp_t.id, sizeof(unsigned short), h);
+    coap_hash((const unsigned char *)&pdu->transport_hdr->udp.id, sizeof(unsigned short), h);
 
     *id = ((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3]);
 }
@@ -584,10 +584,10 @@ coap_tid_t coap_send_ack(coap_context_t *context, const coap_address_t *dst, coa
     coap_pdu_t *response;
     coap_tid_t result = COAP_INVALID_TID;
 
-    if (request && request->hdr->coap_hdr_udp_t.type == COAP_MESSAGE_CON)
+    if (request && request->transport_hdr->udp.type == COAP_MESSAGE_CON)
     {
-        response = coap_pdu_init(COAP_MESSAGE_ACK, 0, request->hdr->coap_hdr_udp_t.id,
-                                 sizeof(coap_pdu_t), coap_udp);
+        response = coap_pdu_init(COAP_MESSAGE_ACK, 0, request->transport_hdr->udp.id,
+                                 sizeof(coap_pdu_t));
         if (response)
         {
             result = coap_send(context, dst, response);
@@ -748,8 +748,8 @@ coap_tid_t coap_send_message_type(coap_context_t *context, const coap_address_t
 
     if (request)
     {
-        response = coap_pdu_init(type, 0, request->hdr->coap_hdr_udp_t.id,
-                                 sizeof(coap_pdu_t), coap_udp);
+        response = coap_pdu_init(type, 0, request->transport_hdr->udp.id,
+                                 sizeof(coap_pdu_t));
         if (response)
         {
             result = coap_send(context, dst, response);
@@ -851,7 +851,7 @@ coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
 
         debug(
                 "** retransmission #%d of transaction %d\n", node->retransmit_cnt,
-                ntohs(node->pdu->hdr->coap_hdr_udp_t.id));
+                ntohs(node->pdu->transport_hdr->udp.id));
 
         node->id = coap_send_impl(context, &node->remote, node->pdu);
         return node->id;
@@ -866,13 +866,13 @@ coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
 #ifndef WITHOUT_OBSERVE
     /* Check if subscriptions exist that should be canceled after
      COAP_MAX_NOTIFY_FAILURES */
-    if (node->pdu->hdr->coap_hdr_udp_t.code >= 64)
+    if (node->pdu->transport_hdr->udp.code >= 64)
     {
         str token =
         { 0, NULL };
 
-        token.length = node->pdu->hdr->coap_hdr_udp_t.token_length;
-        token.s = node->pdu->hdr->coap_hdr_udp_t.token;
+        token.length = node->pdu->transport_hdr->udp.token_length;
+        token.s = node->pdu->transport_hdr->udp.token;
 
         coap_handle_failed_notify(context, &node->remote, &token);
     }
@@ -963,7 +963,7 @@ int coap_read(coap_context_t *ctx)
         goto error_early;
     }
 
-    if (pdu->coap_hdr_udp_t.version != COAP_DEFAULT_VERSION)
+    if (pdu->version != COAP_DEFAULT_VERSION)
     {
         debug("coap_read: unknown protocol version\n");
         goto error_early;
@@ -977,7 +977,7 @@ int coap_read(coap_context_t *ctx)
     node->pdu = coap_pdu_from_pbuf(ctx->pending_package);
     ctx->pending_package = NULL;
 #else
-    node->pdu = coap_pdu_init(0, 0, 0, bytes_read, coap_udp);
+    node->pdu = coap_pdu_init(0, 0, 0, bytes_read);
 #endif
     if (!node->pdu)
         goto error;
@@ -986,7 +986,7 @@ int coap_read(coap_context_t *ctx)
     memcpy(&node->local, &dst, sizeof(coap_address_t));
     memcpy(&node->remote, &src, sizeof(coap_address_t));
 
-    if (!coap_pdu_parse((unsigned char *) buf, bytes_read, node->pdu, coap_udp))
+    if (!coap_pdu_parse((unsigned char *) buf, bytes_read, node->pdu))
     {
         warn("discard malformed PDU");
         goto error;
@@ -1091,12 +1091,12 @@ void coap_cancel_all_messages(coap_context_t *context, const coap_address_t *dst
 
     debug("cancel_all_messages\n");
     while (context->sendqueue && coap_address_equals(dst, &context->sendqueue->remote)
-            && token_match(token, token_length, context->sendqueue->pdu->hdr->coap_hdr_udp_t.token,
-                    context->sendqueue->pdu->hdr->coap_hdr_udp_t.token_length))
+            && token_match(token, token_length, context->sendqueue->pdu->transport_hdr->udp.token,
+                    context->sendqueue->pdu->transport_hdr->udp.token_length))
     {
         q = context->sendqueue;
         context->sendqueue = q->next;
-        debug("**** removed transaction %d\n", ntohs(q->pdu->hdr->coap_hdr_udp_t.id));
+        debug("**** removed transaction %d\n", ntohs(q->pdu->transport_hdr->udp.id));
         coap_delete_node(q);
     }
 
@@ -1110,11 +1110,11 @@ void coap_cancel_all_messages(coap_context_t *context, const coap_address_t *dst
     while (q)
     {
         if (coap_address_equals(dst, &q->remote)
-                && token_match(token, token_length, q->pdu->hdr->coap_hdr_udp_t.token,
-                               q->pdu->hdr->coap_hdr_udp_t.token_length))
+                && token_match(token, token_length, q->pdu->transport_hdr->udp.token,
+                               q->pdu->transport_hdr->udp.token_length))
         {
             p->next = q->next;
-            debug("**** removed transaction %d\n", ntohs(q->pdu->hdr->coap_hdr_udp_t.id));
+            debug("**** removed transaction %d\n", ntohs(q->pdu->transport_hdr->udp.id));
             coap_delete_node(q);
             q = p->next;
         }
@@ -1140,7 +1140,7 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code, coap_opt_filter
 {
     coap_opt_iterator_t opt_iter;
     coap_pdu_t *response;
-    size_t size = sizeof(coap_hdr_t) + request->hdr->coap_hdr_udp_t.token_length;
+    size_t size = sizeof(coap_hdr_t) + request->transport_hdr->udp.token_length;
     int type;
     coap_opt_t *option;
     unsigned short opt_type = 0; /* used for calculating delta-storage */
@@ -1156,14 +1156,14 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code, coap_opt_filter
     assert(request);
 
     /* cannot send ACK if original request was not confirmable */
-    type = request->hdr->coap_hdr_udp_t.type == COAP_MESSAGE_CON ? COAP_MESSAGE_ACK : COAP_MESSAGE_NON;
+    type = request->transport_hdr->udp.type == COAP_MESSAGE_CON ? COAP_MESSAGE_ACK : COAP_MESSAGE_NON;
 
     /* Estimate how much space we need for options to copy from
      * request. We always need the Token, for 4.02 the unknown critical
      * options must be included as well. */
     coap_option_clrb(opts, COAP_OPTION_CONTENT_TYPE); /* we do not want this */
 
-    coap_option_iterator_init(request, &opt_iter, opts, coap_udp);
+    coap_option_iterator_init(request, &opt_iter, opts);
 
     /* Add size of each unknown critical option. As known critical
      options as well as elective options are not copied, the delta
@@ -1206,12 +1206,12 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code, coap_opt_filter
     }
 
     /* Now create the response and fill with options and payload data. */
-    response = coap_pdu_init(type, code, request->hdr->coap_hdr_udp_t.id, size, coap_udp);
+    response = coap_pdu_init(type, code, request->transport_hdr->udp.id, size);
     if (response)
     {
         /* copy token */
-        if (!coap_add_token(response, request->hdr->coap_hdr_udp_t.token_length,
-                            request->hdr->coap_hdr_udp_t.token, coap_udp))
+        if (!coap_add_token(response, request->transport_hdr->udp.token_length,
+                            request->transport_hdr->udp.token))
         {
             debug("cannot add token to error response\n");
             coap_delete_pdu(response);
@@ -1219,10 +1219,10 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code, coap_opt_filter
         }
 
         /* copy all options */
-        coap_option_iterator_init(request, &opt_iter, opts, coap_udp);
+        coap_option_iterator_init(request, &opt_iter, opts);
         while ((option = coap_option_next(&opt_iter)))
             coap_add_option(response, opt_iter.type, COAP_OPT_LENGTH(option),
-                    COAP_OPT_VALUE(option), coap_udp);
+                    COAP_OPT_VALUE(option));
 
 #if COAP_ERROR_PHRASE_LENGTH > 0
         /* note that diagnostic messages do not need a Content-Format option. */
@@ -1270,17 +1270,17 @@ wellknown_response(coap_context_t *context, coap_pdu_t *request)
     size_t offset = 0;
 
     resp = coap_pdu_init(
-            request->hdr->coap_hdr_udp_t.type == COAP_MESSAGE_CON ? COAP_MESSAGE_ACK : COAP_MESSAGE_NON,
+            request->transport_hdr->udp.type == COAP_MESSAGE_CON ? COAP_MESSAGE_ACK : COAP_MESSAGE_NON,
             COAP_RESPONSE_CODE(205),
-            request->hdr->coap_hdr_udp_t.id, COAP_MAX_PDU_SIZE, coap_udp);
+            request->transport_hdr->udp.id, COAP_MAX_PDU_SIZE);
     if (!resp)
     {
         debug("wellknown_response: cannot create PDU\n");
         return NULL;
     }
 
-    if (!coap_add_token(resp, request->hdr->coap_hdr_udp_t.token_length,
-                        request->hdr->coap_hdr_udp_t.token, coap_udp))
+    if (!coap_add_token(resp, request->transport_hdr->udp.token_length,
+                        request->transport_hdr->udp.token))
     {
         debug("wellknown_response: cannot add token\n");
         goto error;
@@ -1295,7 +1295,7 @@ wellknown_response(coap_context_t *context, coap_pdu_t *request)
         offset = block.num << (block.szx + 4);
         if (block.szx > 6)
         { /* invalid, MUST lead to 4.00 Bad Request */
-            resp->hdr->coap_hdr_udp_t.code = COAP_RESPONSE_CODE(400);
+            resp->transport_hdr->udp.code = COAP_RESPONSE_CODE(400);
             return resp;
         }
         else if (block.szx > COAP_MAX_BLOCK_SZX)
@@ -1321,7 +1321,7 @@ wellknown_response(coap_context_t *context, coap_pdu_t *request)
      * nothing should go wrong here. */
     assert(coap_encode_var_bytes(buf, COAP_MEDIATYPE_APPLICATION_LINK_FORMAT) == 1);
     coap_add_option(resp, COAP_OPTION_CONTENT_FORMAT,
-            coap_encode_var_bytes(buf, COAP_MEDIATYPE_APPLICATION_LINK_FORMAT), buf, coap_udp);
+            coap_encode_var_bytes(buf, COAP_MEDIATYPE_APPLICATION_LINK_FORMAT), buf);
 
     /* check if Block2 option is required even if not requested */
     if (!need_block2 && (resp->max_size - (size_t) resp->length < wkc_len))
@@ -1379,13 +1379,13 @@ wellknown_response(coap_context_t *context, coap_pdu_t *request)
 
     error:
     /* set error code 5.03 and remove all options and data from response */
-    resp->hdr->coap_hdr_udp_t.code = COAP_RESPONSE_CODE(503);
-    resp->length = sizeof(coap_hdr_t) + resp->hdr->coap_hdr_udp_t.token_length;
+    resp->transport_hdr->udp.code = COAP_RESPONSE_CODE(503);
+    resp->length = sizeof(coap_hdr_t) + resp->transport_hdr->udp.token_length;
     return resp;
 }
 
 #define WANT_WKC(Pdu,Key)                   \
-  (((Pdu)->hdr->coap_hdr_udp_t.code == COAP_REQUEST_GET) && is_wkc(Key))
+  (((Pdu)->transport_hdr->udp.code == COAP_REQUEST_GET) && is_wkc(Key))
 
 void handle_request(coap_context_t *context, coap_queue_t *node, const char* responseData)
 {
@@ -1408,7 +1408,7 @@ void handle_request(coap_context_t *context, coap_queue_t *node, const char* res
          * be the well-known URI. In that case, we generate a default
          * response, otherwise, we return 4.04 */
 
-        switch (node->pdu->hdr->coap_hdr_udp_t.code)
+        switch (node->pdu->transport_hdr->udp.code)
         {
 
             case COAP_REQUEST_GET:
@@ -1448,43 +1448,43 @@ void handle_request(coap_context_t *context, coap_queue_t *node, const char* res
     }
 
     /* the resource was found, check if there is a registered handler */
-    if ((size_t) node->pdu->hdr->coap_hdr_udp_t.code - 1
+    if ((size_t) node->pdu->transport_hdr->udp.code - 1
             < sizeof(resource->handler) / sizeof(coap_method_handler_t))
-        h = resource->handler[node->pdu->hdr->coap_hdr_udp_t.code - 1];
+        h = resource->handler[node->pdu->transport_hdr->udp.code - 1];
 
     if (h)
     {
         debug(
                 "call custom handler for resource 0x%02x%02x%02x%02x\n", key[0], key[1], key[2], key[3]);
         response = coap_pdu_init(
-                node->pdu->hdr->coap_hdr_udp_t.type ==
+                node->pdu->transport_hdr->udp.type ==
                         COAP_MESSAGE_CON ? COAP_MESSAGE_ACK : COAP_MESSAGE_NON,
-                0, node->pdu->hdr->coap_hdr_udp_t.id, COAP_MAX_PDU_SIZE, coap_udp);
+                0, node->pdu->transport_hdr->udp.id, COAP_MAX_PDU_SIZE);
 
         /* Implementation detail: coap_add_token() immediately returns 0
          if response == NULL */
-        if (coap_add_token(response, node->pdu->hdr->coap_hdr_udp_t.token_length,
-                           node->pdu->hdr->coap_hdr_udp_t.token, coap_udp))
+        if (coap_add_token(response, node->pdu->transport_hdr->udp.token_length,
+                           node->pdu->transport_hdr->udp.token))
         {
             str token =
-            { node->pdu->hdr->coap_hdr_udp_t.token_length, node->pdu->hdr->coap_hdr_udp_t.token };
+            { node->pdu->transport_hdr->udp.token_length, node->pdu->transport_hdr->udp.token };
 
             h(context, resource, &node->remote, node->pdu, &token, response);
 
             unsigned char buf[3];
-            response->hdr->coap_hdr_udp_t.code = COAP_RESPONSE_CODE(205);
+            response->transport_hdr->udp.code = COAP_RESPONSE_CODE(205);
             coap_add_option(response, COAP_OPTION_CONTENT_TYPE,
-                    coap_encode_var_bytes(buf, COAP_MEDIATYPE_TEXT_PLAIN), buf, coap_udp);
-            coap_add_option(response, COAP_OPTION_MAXAGE, coap_encode_var_bytes(buf, 0x2ffff), buf, coap_udp);
+                    coap_encode_var_bytes(buf, COAP_MEDIATYPE_TEXT_PLAIN), buf);
+            coap_add_option(response, COAP_OPTION_MAXAGE, coap_encode_var_bytes(buf, 0x2ffff), buf);
             coap_add_data(response, strlen(responseData), (unsigned char *) responseData);
 
-            if (response->hdr->coap_hdr_udp_t.type != COAP_MESSAGE_NON
-                    || (response->hdr->coap_hdr_udp_t.code >= 64 && !coap_is_mcast(&node->local)))
+            if (response->transport_hdr->udp.type != COAP_MESSAGE_NON
+                    || (response->transport_hdr->udp.code >= 64 && !coap_is_mcast(&node->local)))
             {
 
                 if (coap_send(context, &node->remote, response) == COAP_INVALID_TID)
                 {
-                    debug("cannot send response for message %d\n", node->pdu->hdr->coap_hdr_udp_t.id);
+                    debug("cannot send response for message %d\n", node->pdu->transport_hdr->udp.id);
                 }
             }
 
@@ -1562,8 +1562,8 @@ handle_locally(coap_context_t *context __attribute__ ((unused)),
          * get token from sent and try to find a matching resource. Uh!
          */
 
-        COAP_SET_STR(&token, sent->pdu->hdr->coap_hdr_udp_t.token_length,
-                     sent->pdu->hdr->coap_hdr_udp_t.token);
+        COAP_SET_STR(&token, sent->pdu->transport_hdr->udp.token_length,
+                     sent->pdu->transport_hdr->udp.token);
 
 #ifndef WITH_CONTIKI
 #ifdef COAP_RESOURCES_NOHASH
@@ -1609,29 +1609,29 @@ handle_locally(coap_context_t *context __attribute__ ((unused)),
             context->recvqueue = context->recvqueue->next;
             rcvd->next = NULL;
 
-            if (rcvd->pdu->hdr->coap_hdr_udp_t.version != COAP_DEFAULT_VERSION)
+            if (rcvd->pdu->transport_hdr->udp.version != COAP_DEFAULT_VERSION)
             {
-                debug("dropped packet with unknown version %u\n", rcvd->pdu->hdr->coap_hdr_udp_t.version);
+                debug("dropped packet with unknown version %u\n", rcvd->pdu->transport_hdr->udp.version);
                 goto cleanup;
             }
 
-            switch (rcvd->pdu->hdr->coap_hdr_udp_t.type)
+            switch (rcvd->pdu->transport_hdr->udp.type)
             {
                 case COAP_MESSAGE_ACK:
                     /* find transaction in sendqueue to stop retransmission */
                     coap_remove_from_queue(&context->sendqueue, rcvd->id, &sent);
 
-                    if (rcvd->pdu->hdr->coap_hdr_udp_t.code == 0)
+                    if (rcvd->pdu->transport_hdr->udp.code == 0)
                         goto cleanup;
 
                     /* FIXME: if sent code was >= 64 the message might have been a
                      * notification. Then, we must flag the observer to be alive
                      * by setting obs->fail_cnt = 0. */
-                    if (sent && COAP_RESPONSE_CLASS(sent->pdu->hdr->coap_hdr_udp_t.code) == 2)
+                    if (sent && COAP_RESPONSE_CLASS(sent->pdu->transport_hdr->udp.code) == 2)
                     {
                         const str token =
-                        { sent->pdu->hdr->coap_hdr_udp_t.token_length,
-                          sent->pdu->hdr->coap_hdr_udp_t.token };
+                        { sent->pdu->transport_hdr->udp.token_length,
+                          sent->pdu->transport_hdr->udp.token };
 
                         coap_touch_observer(context, &sent->remote, &token);
                     }
@@ -1643,7 +1643,7 @@ handle_locally(coap_context_t *context __attribute__ ((unused)),
                      * have. */
 
                     coap_log(LOG_ALERT, "got RST for message %u\n",
-                             ntohs(rcvd->pdu->hdr->coap_hdr_udp_t.id));
+                             ntohs(rcvd->pdu->transport_hdr->udp.id));
 
                     /* find transaction in sendqueue to stop retransmission */
                     coap_remove_from_queue(&context->sendqueue, rcvd->id, &sent);
@@ -1686,9 +1686,9 @@ handle_locally(coap_context_t *context __attribute__ ((unused)),
              * registered for a request that should be handled locally. */
             if (handle_locally(context, rcvd))
             {
-                if (COAP_MESSAGE_IS_REQUEST(rcvd->pdu->hdr->coap_hdr_udp_t))
+                if (COAP_MESSAGE_IS_REQUEST(rcvd->pdu->transport_hdr->udp))
                     handle_request(context, rcvd, responseData);
-                else if (COAP_MESSAGE_IS_RESPONSE(rcvd->pdu->hdr->coap_hdr_udp_t))
+                else if (COAP_MESSAGE_IS_RESPONSE(rcvd->pdu->transport_hdr->udp))
                     handle_response(context, sent, rcvd);
                 else
                 {
index f4ec497..13efdac 100644 (file)
 #include "include/coap/pdu.h"
 
 coap_opt_t *
-options_start(coap_pdu_t *pdu, coap_transport_type transport)
+options_start(coap_pdu_t *pdu, coap_transport_t transport)
 {
     if (pdu && pdu->hdr)
     {
-        if (coap_udp == transport && (pdu->hdr->coap_hdr_udp_t.token +
-                pdu->hdr->coap_hdr_udp_t.token_length
+        if (COAP_UDP == transport && (pdu->transport_hdr->udp.token +
+                pdu->transport_hdr->udp.token_length
                 < (unsigned char *) pdu->hdr + pdu->length))
         {
-            coap_opt_t *opt = pdu->hdr->coap_hdr_udp_t.token +
-                    pdu->hdr->coap_hdr_udp_t.token_length;
+            coap_opt_t *opt = pdu->transport_hdr->udp.token +
+                    pdu->transport_hdr->udp.token_length;
             return (*opt == COAP_PAYLOAD_START) ? NULL : opt;
         }
 #ifdef WITH_TCP
-        else if(coap_tcp == transport && (pdu->hdr->coap_hdr_tcp_t.token +
-                ((pdu->hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f)
+        else if(COAP_TCP == transport && (pdu->transport_hdr->tcp.token +
+                ((pdu->transport_hdr->tcp.header_data[0]) & 0x0f)
                 < (unsigned char *) pdu->hdr + pdu->length))
         {
-            coap_opt_t *opt = pdu->hdr->coap_hdr_tcp_t.token +
-                    ((pdu->hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f);
+            coap_opt_t *opt = pdu->transport_hdr->tcp.token +
+                    ((pdu->transport_hdr->tcp.header_data[0]) & 0x0f);
             return (*opt == COAP_PAYLOAD_START) ? NULL : opt;
         }
 #endif
@@ -138,7 +138,14 @@ size_t coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *resul
 
 coap_opt_iterator_t *
 coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
-                          const coap_opt_filter_t filter, coap_transport_type transport)
+                          const coap_opt_filter_t filter)
+{
+    return coap_option_iterator_init2(pdu, oi, filter, COAP_UDP);
+}
+
+coap_opt_iterator_t *
+coap_option_iterator_init2(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
+                           const coap_opt_filter_t filter, coap_transport_t transport)
 {
     assert(pdu);
     assert(pdu->hdr);
@@ -152,34 +159,34 @@ coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
     switch(transport)
     {
 #ifdef WITH_TCP
-        case coap_tcp:
-            token_length = (pdu->hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f;
+        case COAP_TCP:
+            token_length = (pdu->transport_hdr->tcp.header_data[0]) & 0x0f;
             headerSize = COAP_TCP_HEADER_NO_FIELD;
             break;
-        case coap_tcp_8bit:
-            token_length = (pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0]) & 0x0f;
+        case COAP_TCP_8BIT:
+            token_length = (pdu->transport_hdr->tcp_8bit.header_data[0]) & 0x0f;
             headerSize = COAP_TCP_HEADER_8_BIT;
             break;
-        case coap_tcp_16bit:
-            token_length = (pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0]) & 0x0f;
+        case COAP_TCP_16BIT:
+            token_length = (pdu->transport_hdr->tcp_16bit.header_data[0]) & 0x0f;
             headerSize = COAP_TCP_HEADER_16_BIT;
             break;
-        case coap_tcp_32bit:
-            token_length = pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] & 0x0f;
+        case COAP_TCP_32BIT:
+            token_length = pdu->transport_hdr->tcp_32bit.header_data[0] & 0x0f;
             headerSize = COAP_TCP_HEADER_32_BIT;
             break;
 #endif
         default:
-            token_length = pdu->hdr->coap_hdr_udp_t.token_length;
-            headerSize = sizeof(pdu->hdr->coap_hdr_udp_t);
+            token_length = pdu->transport_hdr->udp.token_length;
+            headerSize = sizeof(pdu->transport_hdr->udp);
             break;
     }
 
     oi->next_option = (unsigned char *) pdu->hdr + headerSize + token_length;
 
-    if (coap_udp == transport)
+    if (COAP_UDP == transport)
     {
-        if ((unsigned char *) &(pdu->hdr->coap_hdr_udp_t) + pdu->length <= oi->next_option)
+        if ((unsigned char *) &(pdu->transport_hdr->udp) + pdu->length <= oi->next_option)
         {
             oi->bad = 1;
             return NULL;
@@ -188,7 +195,7 @@ coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
 #ifdef WITH_TCP
     else
     {
-        if ((unsigned char *) &(pdu->hdr->coap_hdr_tcp_t) + pdu->length <= oi->next_option)
+        if ((unsigned char *) &(pdu->transport_hdr->tcp) + pdu->length <= oi->next_option)
         {
             oi->bad = 1;
             return NULL;
@@ -283,7 +290,7 @@ coap_check_option(coap_pdu_t *pdu, unsigned char type, coap_opt_iterator_t *oi)
     coap_option_filter_clear(f);
     coap_option_setb(f, type);
 
-    coap_option_iterator_init(pdu, oi, f, coap_udp);
+    coap_option_iterator_init(pdu, oi, f);
 
     return coap_option_next(oi);
 }
index 6e869c3..d2ca93e 100644 (file)
@@ -50,7 +50,12 @@ coap_pdu_resources_init()
 #include "include/coap/mem.h"
 #endif /* WITH_CONTIKI */
 
-void coap_pdu_clear(coap_pdu_t *pdu, size_t size, coap_transport_type transport, unsigned int length)
+void coap_pdu_clear(coap_pdu_t *pdu, size_t size)
+{
+    coap_pdu_clear2(pdu, size, COAP_UDP, 0);
+}
+
+void coap_pdu_clear2(coap_pdu_t *pdu, size_t size, coap_transport_t transport, unsigned int length)
 {
     assert(pdu);
 
@@ -58,11 +63,11 @@ void coap_pdu_clear(coap_pdu_t *pdu, size_t size, coap_transport_type transport,
     pdu->max_size = size;
     pdu->hdr = (coap_hdr_t *) ((unsigned char *) pdu + sizeof(coap_pdu_t));
 
-    if (coap_udp == transport)
+    if (COAP_UDP == transport)
     {
-        pdu->hdr->coap_hdr_udp_t.version = COAP_DEFAULT_VERSION;
+        pdu->transport_hdr->udp.version = COAP_DEFAULT_VERSION;
         /* data is NULL unless explicitly set by coap_add_data() */
-        pdu->length = sizeof(pdu->hdr->coap_hdr_udp_t);
+        pdu->length = sizeof(pdu->transport_hdr->udp);
     }
 #ifdef WITH_TCP
     else
@@ -103,7 +108,14 @@ coap_pdu_from_pbuf(struct pbuf *pbuf)
 
 coap_pdu_t *
 coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
-              size_t size, coap_transport_type transport)
+              size_t size)
+{
+    return coap_pdu_init2(type, code, id, size, COAP_UDP);
+}
+
+coap_pdu_t *
+coap_pdu_init2(unsigned char type, unsigned char code, unsigned short id,
+               size_t size, coap_transport_t transport)
 {
     coap_pdu_t *pdu;
 #ifdef WITH_LWIP
@@ -113,20 +125,20 @@ coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
     unsigned int length = 0;
     switch(transport)
     {
-        case coap_udp:
-            length = sizeof(pdu->hdr->coap_hdr_udp_t);
+        case COAP_UDP:
+            length = sizeof(pdu->transport_hdr->udp);
             break;
 #ifdef WITH_TCP
-        case coap_tcp:
+        case COAP_TCP:
             length = COAP_TCP_HEADER_NO_FIELD;
             break;
-        case coap_tcp_8bit:
+        case COAP_TCP_8BIT:
             length = COAP_TCP_HEADER_8_BIT;
             break;
-        case coap_tcp_16bit:
+        case COAP_TCP_16BIT:
             length = COAP_TCP_HEADER_16_BIT;
             break;
-        case coap_tcp_32bit:
+        case COAP_TCP_32BIT:
             length = COAP_TCP_HEADER_32_BIT;
             break;
 #endif
@@ -165,31 +177,31 @@ coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
 #endif
     if (pdu)
     {
-        coap_pdu_clear(pdu, size, transport, length);
+        coap_pdu_clear2(pdu, size, transport, length);
 
         switch(transport)
         {
-            case coap_udp:
-                pdu->hdr->coap_hdr_udp_t.id = id;
-                pdu->hdr->coap_hdr_udp_t.type = type;
-                pdu->hdr->coap_hdr_udp_t.code = code;
+            case COAP_UDP:
+                pdu->transport_hdr->udp.id = id;
+                pdu->transport_hdr->udp.type = type;
+                pdu->transport_hdr->udp.code = code;
                 break;
 #ifdef WITH_TCP
-            case coap_tcp:
-                pdu->hdr->coap_hdr_tcp_t.header_data[0] = 0;
-                pdu->hdr->coap_hdr_tcp_t.header_data[1] = code;
+            case COAP_TCP:
+                pdu->transport_hdr->tcp.header_data[0] = 0;
+                pdu->transport_hdr->tcp.header_data[1] = code;
                 break;
-            case coap_tcp_8bit:
-                pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_8_BIT << 4;
-                pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2] = code;
+            case COAP_TCP_8BIT:
+                pdu->transport_hdr->tcp_8bit.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_8_BIT << 4;
+                pdu->transport_hdr->tcp_8bit.header_data[2] = code;
                 break;
-            case coap_tcp_16bit:
-                pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_16_BIT << 4;
-                pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3] = code;
+            case COAP_TCP_16BIT:
+                pdu->transport_hdr->tcp_16bit.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_16_BIT << 4;
+                pdu->transport_hdr->tcp_16bit.header_data[3] = code;
                 break;
-            case coap_tcp_32bit:
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_32_BIT << 4;
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5] = code;
+            case COAP_TCP_32BIT:
+                pdu->transport_hdr->tcp_32bit.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_32_BIT << 4;
+                pdu->transport_hdr->tcp_32bit.header_data[5] = code;
                 break;
 #endif
             default:
@@ -204,7 +216,7 @@ coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
 }
 
 coap_pdu_t *
-coap_new_pdu(coap_transport_type transport, unsigned int size)
+coap_new_pdu2(coap_transport_t transport, unsigned int size)
 {
 #ifndef WITH_TCP
     (void)size;
@@ -212,22 +224,22 @@ coap_new_pdu(coap_transport_type transport, unsigned int size)
     coap_pdu_t *pdu;
 
 #ifndef WITH_CONTIKI
-    pdu = coap_pdu_init(0, 0,
-                        ntohs(COAP_INVALID_TID),
+    pdu = coap_pdu_init2(0, 0,
+                         ntohs(COAP_INVALID_TID),
 #ifndef WITH_TCP
-                        COAP_MAX_PDU_SIZE,
+                         COAP_MAX_PDU_SIZE,
 #else
-                        size,
+                         size,
 #endif
-                        transport);
+                         transport);
 #else /* WITH_CONTIKI */
-    pdu = coap_pdu_init(0, 0, uip_ntohs(COAP_INVALID_TID),
+    pdu = coap_pdu_init2(0, 0, uip_ntohs(COAP_INVALID_TID),
 #ifndef WITH_TCP
-                        COAP_MAX_PDU_SIZE,
+                         COAP_MAX_PDU_SIZE,
 #else
-                        size,
+                         size,
 #endif
-                        transport);
+                         transport);
 #endif /* WITH_CONTIKI */
 
 #ifndef NDEBUG
@@ -260,7 +272,7 @@ size_t coap_get_total_message_length(const unsigned char *data, size_t size)
         return 0;
     }
 
-    coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+    coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
             ((unsigned char *)data)[0] >> 4);
     size_t optPaylaodLen = coap_get_length_from_header((unsigned char *)data,
                                                         transport);
@@ -269,78 +281,78 @@ size_t coap_get_total_message_length(const unsigned char *data, size_t size)
     return headerLen + optPaylaodLen;
 }
 
-coap_transport_type coap_get_tcp_header_type_from_size(unsigned int size)
+coap_transport_t coap_get_tcp_header_type_from_size(unsigned int size)
 {
     if (size < COAP_TCP_LENGTH_FIELD_8_BIT)
     {
-        return coap_tcp;
+        return COAP_TCP;
     }
     else if (size < COAP_TCP_LENGTH_FIELD_16_BIT)
     {
-        return coap_tcp_8bit;
+        return COAP_TCP_8BIT;
     }
     else if (size < COAP_TCP_LENGTH_FIELD_32_BIT)
     {
-        return coap_tcp_16bit;
+        return COAP_TCP_16BIT;
     }
     else
     {
-        return coap_tcp_32bit;
+        return COAP_TCP_32BIT;
     }
 }
 
-coap_transport_type coap_get_tcp_header_type_from_initbyte(unsigned int length)
+coap_transport_t coap_get_tcp_header_type_from_initbyte(unsigned int length)
 {
-    coap_transport_type type;
+    coap_transport_t type;
     switch(length)
     {
         case COAP_TCP_LENGTH_FIELD_NUM_8_BIT:
-            type = coap_tcp_8bit;
+            type = COAP_TCP_8BIT;
             break;
         case COAP_TCP_LENGTH_FIELD_NUM_16_BIT:
-            type = coap_tcp_16bit;
+            type = COAP_TCP_16BIT;
             break;
         case COAP_TCP_LENGTH_FIELD_NUM_32_BIT:
-            type = coap_tcp_32bit;
+            type = COAP_TCP_32BIT;
             break;
         default:
-            type = coap_tcp;
+            type = COAP_TCP;
     }
     return type;
 }
 
-void coap_add_length(const coap_pdu_t *pdu, coap_transport_type transport, unsigned int length)
+void coap_add_length(const coap_pdu_t *pdu, coap_transport_t transport, unsigned int length)
 {
     assert(pdu);
 
     switch(transport)
     {
-        case coap_tcp:
-            pdu->hdr->coap_hdr_tcp_t.header_data[0] = length << 4;
+        case COAP_TCP:
+            pdu->transport_hdr->tcp.header_data[0] = length << 4;
             break;
-        case coap_tcp_8bit:
+        case COAP_TCP_8BIT:
             if (length > COAP_TCP_LENGTH_FIELD_8_BIT)
             {
-                pdu->hdr->coap_hdr_tcp_8bit_t.header_data[1] =
+                pdu->transport_hdr->tcp_8bit.header_data[1] =
                         length - COAP_TCP_LENGTH_FIELD_8_BIT;
             }
             break;
-        case coap_tcp_16bit:
+        case COAP_TCP_16BIT:
             if (length > COAP_TCP_LENGTH_FIELD_16_BIT)
             {
                 unsigned int total_length = length - COAP_TCP_LENGTH_FIELD_16_BIT;
-                pdu->hdr->coap_hdr_tcp_16bit_t.header_data[1] = (total_length >> 8) & 0x0000ff;
-                pdu->hdr->coap_hdr_tcp_16bit_t.header_data[2] = total_length & 0x000000ff;
+                pdu->transport_hdr->tcp_16bit.header_data[1] = (total_length >> 8) & 0x0000ff;
+                pdu->transport_hdr->tcp_16bit.header_data[2] = total_length & 0x000000ff;
             }
             break;
-        case coap_tcp_32bit:
+        case COAP_TCP_32BIT:
             if (length > COAP_TCP_LENGTH_FIELD_32_BIT)
             {
                 unsigned int total_length = length - COAP_TCP_LENGTH_FIELD_32_BIT;
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[1] = total_length >> 24;
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[2] = (total_length >> 16) & 0x00ff;
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[3] = (total_length >> 8) & 0x0000ff;
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[4] = total_length & 0x000000ff;
+                pdu->transport_hdr->tcp_32bit.header_data[1] = total_length >> 24;
+                pdu->transport_hdr->tcp_32bit.header_data[2] = (total_length >> 16) & 0x00ff;
+                pdu->transport_hdr->tcp_32bit.header_data[3] = (total_length >> 8) & 0x0000ff;
+                pdu->transport_hdr->tcp_32bit.header_data[4] = total_length & 0x000000ff;
             }
             break;
         default:
@@ -348,7 +360,7 @@ void coap_add_length(const coap_pdu_t *pdu, coap_transport_type transport, unsig
     }
 }
 
-unsigned int coap_get_length_from_header(const unsigned char *header, coap_transport_type transport)
+unsigned int coap_get_length_from_header(const unsigned char *header, coap_transport_t transport)
 {
     assert(header);
 
@@ -356,17 +368,17 @@ unsigned int coap_get_length_from_header(const unsigned char *header, coap_trans
     unsigned int length_field_data = 0;
     switch(transport)
     {
-        case coap_tcp:
+        case COAP_TCP:
             length = header[0] >> 4;
             break;
-        case coap_tcp_8bit:
+        case COAP_TCP_8BIT:
             length = header[1] + COAP_TCP_LENGTH_FIELD_8_BIT;
             break;
-        case coap_tcp_16bit:
+        case COAP_TCP_16BIT:
             length_field_data = (header[1] << 8 | header[2]);
             length = length_field_data + COAP_TCP_LENGTH_FIELD_16_BIT;
             break;
-        case coap_tcp_32bit:
+        case COAP_TCP_32BIT:
             length_field_data = header[1] << 24 | header[2] << 16 | header[3] << 8 | header[4];
             length = length_field_data + COAP_TCP_LENGTH_FIELD_32_BIT;
             break;
@@ -377,7 +389,7 @@ unsigned int coap_get_length_from_header(const unsigned char *header, coap_trans
     return length;
 }
 
-unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transport)
+unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_t transport)
 {
     assert(pdu);
 
@@ -385,24 +397,24 @@ unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transpor
     unsigned int length_field_data = 0;
     switch(transport)
     {
-        case coap_tcp:
-            length = pdu->hdr->coap_hdr_tcp_t.header_data[0] >> 4;
+        case COAP_TCP:
+            length = pdu->transport_hdr->tcp.header_data[0] >> 4;
             break;
-        case coap_tcp_8bit:
-            length = pdu->hdr->coap_hdr_tcp_8bit_t.header_data[1] + COAP_TCP_LENGTH_FIELD_8_BIT;
+        case COAP_TCP_8BIT:
+            length = pdu->transport_hdr->tcp_8bit.header_data[1] + COAP_TCP_LENGTH_FIELD_8_BIT;
             break;
-        case coap_tcp_16bit:
+        case COAP_TCP_16BIT:
             length_field_data =
-                    pdu->hdr->coap_hdr_tcp_16bit_t.header_data[1] << 8 |
-                    pdu->hdr->coap_hdr_tcp_16bit_t.header_data[2];
+                    pdu->transport_hdr->tcp_16bit.header_data[1] << 8 |
+                    pdu->transport_hdr->tcp_16bit.header_data[2];
             length = length_field_data + COAP_TCP_LENGTH_FIELD_16_BIT;
             break;
-        case coap_tcp_32bit:
+        case COAP_TCP_32BIT:
             length_field_data =
-                    pdu->hdr->coap_hdr_tcp_32bit_t.header_data[1] << 24 |
-                    pdu->hdr->coap_hdr_tcp_32bit_t.header_data[2] << 16 |
-                    pdu->hdr->coap_hdr_tcp_32bit_t.header_data[3] << 8 |
-                    pdu->hdr->coap_hdr_tcp_32bit_t.header_data[4];
+                    pdu->transport_hdr->tcp_32bit.header_data[1] << 24 |
+                    pdu->transport_hdr->tcp_32bit.header_data[2] << 16 |
+                    pdu->transport_hdr->tcp_32bit.header_data[3] << 8 |
+                    pdu->transport_hdr->tcp_32bit.header_data[4];
             length = length_field_data + COAP_TCP_LENGTH_FIELD_32_BIT;
             break;
         default:
@@ -417,7 +429,7 @@ unsigned int coap_get_tcp_header_length(unsigned char *data)
     assert(data);
 
     unsigned int tokenLength =  data[0] & 0x0f;
-    coap_transport_type transport =
+    coap_transport_t transport =
             coap_get_tcp_header_type_from_initbyte(data[0] >> 4);
     unsigned int length = 0;
 
@@ -425,21 +437,21 @@ unsigned int coap_get_tcp_header_length(unsigned char *data)
     return length;
 }
 
-unsigned int coap_get_tcp_header_length_for_transport(coap_transport_type transport)
+unsigned int coap_get_tcp_header_length_for_transport(coap_transport_t transport)
 {
     unsigned int length = 0;
     switch(transport)
     {
-        case coap_tcp:
+        case COAP_TCP:
             length = COAP_TCP_HEADER_NO_FIELD;
             break;
-        case coap_tcp_8bit:   /* len(4bit) + TKL(4bit) + Len+bytes(1byte) + Code(1byte) */
+        case COAP_TCP_8BIT:   /* len(4bit) + TKL(4bit) + Len+bytes(1byte) + Code(1byte) */
             length = COAP_TCP_HEADER_8_BIT;
             break;
-        case coap_tcp_16bit:  /* len(4bit) + TKL(4bit) + Len+bytes(2byte) + Code(1byte) */
+        case COAP_TCP_16BIT:  /* len(4bit) + TKL(4bit) + Len+bytes(2byte) + Code(1byte) */
             length = COAP_TCP_HEADER_16_BIT;
             break;
-        case coap_tcp_32bit:  /* len(4bit) + TKL(4bit) + Len+bytes(4byte) + Code(1byte) */
+        case COAP_TCP_32BIT:  /* len(4bit) + TKL(4bit) + Len+bytes(4byte) + Code(1byte) */
             length = COAP_TCP_HEADER_32_BIT;
             break;
         default:
@@ -493,27 +505,27 @@ size_t coap_get_opt_header_length(unsigned short key, size_t length)
 
 #endif
 
-void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport, unsigned int code)
+void coap_add_code(const coap_pdu_t *pdu, coap_transport_t transport, unsigned int code)
 {
     assert(pdu);
 
     switch(transport)
     {
-        case coap_udp:
-            pdu->hdr->coap_hdr_udp_t.code = COAP_RESPONSE_CODE(code);
+        case COAP_UDP:
+            pdu->transport_hdr->udp.code = COAP_RESPONSE_CODE(code);
             break;
 #ifdef WITH_TCP
-        case coap_tcp:
-            pdu->hdr->coap_hdr_tcp_t.header_data[1] = COAP_RESPONSE_CODE(code);
+        case COAP_TCP:
+            pdu->transport_hdr->tcp.header_data[1] = COAP_RESPONSE_CODE(code);
             break;
-        case coap_tcp_8bit:
-            pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2] = COAP_RESPONSE_CODE(code);
+        case COAP_TCP_8BIT:
+            pdu->transport_hdr->tcp_8bit.header_data[2] = COAP_RESPONSE_CODE(code);
             break;
-        case coap_tcp_16bit:
-            pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3] = COAP_RESPONSE_CODE(code);
+        case COAP_TCP_16BIT:
+            pdu->transport_hdr->tcp_16bit.header_data[3] = COAP_RESPONSE_CODE(code);
             break;
-        case coap_tcp_32bit:
-            pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5] = COAP_RESPONSE_CODE(code);
+        case COAP_TCP_32BIT:
+            pdu->transport_hdr->tcp_32bit.header_data[5] = COAP_RESPONSE_CODE(code);
             break;
 #endif
         default:
@@ -521,28 +533,28 @@ void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport, unsigne
     }
 }
 
-unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_type transport)
+unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_t transport)
 {
     assert(pdu);
 
     unsigned int code = 0;
     switch(transport)
     {
-        case coap_udp:
-            code = pdu->hdr->coap_hdr_udp_t.code;
+        case COAP_UDP:
+            code = pdu->transport_hdr->udp.code;
             break;
 #ifdef WITH_TCP
-        case coap_tcp:
-            code = pdu->hdr->coap_hdr_tcp_t.header_data[1];
+        case COAP_TCP:
+            code = pdu->transport_hdr->tcp.header_data[1];
             break;
-        case coap_tcp_8bit:
-            code = pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2];
+        case COAP_TCP_8BIT:
+            code = pdu->transport_hdr->tcp_8bit.header_data[2];
             break;
-        case coap_tcp_16bit:
-            code = pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3];
+        case COAP_TCP_16BIT:
+            code = pdu->transport_hdr->tcp_16bit.header_data[3];
             break;
-        case coap_tcp_32bit:
-            code = pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5];
+        case COAP_TCP_32BIT:
+            code = pdu->transport_hdr->tcp_32bit.header_data[5];
             break;
 #endif
         default:
@@ -551,8 +563,13 @@ unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_type transport)
     return code;
 }
 
-int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data,
-                   coap_transport_type transport)
+int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data)
+{
+    return coap_add_token2(pdu, len, data, COAP_UDP);
+}
+
+int coap_add_token2(coap_pdu_t *pdu, size_t len, const unsigned char *data,
+                    coap_transport_t transport)
 {
     const size_t HEADERLENGTH = len + 4;
     /* must allow for pdu == NULL as callers may rely on this */
@@ -562,34 +579,34 @@ int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data,
     unsigned char* token = NULL;
     switch(transport)
     {
-        case coap_udp:
-            pdu->hdr->coap_hdr_udp_t.token_length = len;
-            token = pdu->hdr->coap_hdr_udp_t.token;
+        case COAP_UDP:
+            pdu->transport_hdr->udp.token_length = len;
+            token = pdu->transport_hdr->udp.token;
             pdu->length = HEADERLENGTH;
             break;
 #ifdef WITH_TCP
-        case coap_tcp:
-            pdu->hdr->coap_hdr_tcp_t.header_data[0] =
-                    pdu->hdr->coap_hdr_tcp_t.header_data[0] | len;
-            token = pdu->hdr->coap_hdr_tcp_t.token;
+        case COAP_TCP:
+            pdu->transport_hdr->tcp.header_data[0] =
+                    pdu->transport_hdr->tcp.header_data[0] | len;
+            token = pdu->transport_hdr->tcp.token;
             pdu->length = len + COAP_TCP_HEADER_NO_FIELD;
             break;
-        case coap_tcp_8bit:
-            pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0] =
-                    pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0] | len;
-            token = pdu->hdr->coap_hdr_tcp_8bit_t.token;
+        case COAP_TCP_8BIT:
+            pdu->transport_hdr->tcp_8bit.header_data[0] =
+                    pdu->transport_hdr->tcp_8bit.header_data[0] | len;
+            token = pdu->transport_hdr->tcp_8bit.token;
             pdu->length = len + COAP_TCP_HEADER_8_BIT;
             break;
-        case coap_tcp_16bit:
-            pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] =
-                    pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] | len;
-            token = pdu->hdr->coap_hdr_tcp_16bit_t.token;
+        case COAP_TCP_16BIT:
+            pdu->transport_hdr->tcp_16bit.header_data[0] =
+                    pdu->transport_hdr->tcp_16bit.header_data[0] | len;
+            token = pdu->transport_hdr->tcp_16bit.token;
             pdu->length = len + COAP_TCP_HEADER_16_BIT;
             break;
-        case coap_tcp_32bit:
-            pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] =
-                    pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] | len;
-            token = pdu->hdr->coap_hdr_tcp_32bit_t.token;
+        case COAP_TCP_32BIT:
+            pdu->transport_hdr->tcp_32bit.header_data[0] =
+                    pdu->transport_hdr->tcp_32bit.header_data[0] | len;
+            token = pdu->transport_hdr->tcp_32bit.token;
             pdu->length = len + COAP_TCP_HEADER_32_BIT;
             break;
 #endif
@@ -608,35 +625,41 @@ int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data,
     return 1;
 }
 
-void coap_get_token(const coap_hdr_t *pdu_hdr, coap_transport_type transport,
+void coap_get_token(const coap_hdr_t *pdu_hdr,
                     unsigned char **token, unsigned int *token_length)
 {
+    coap_get_token2((const coap_hdr_transport_t *)pdu_hdr, COAP_UDP, token, token_length);
+}
+
+void coap_get_token2(const coap_hdr_transport_t *pdu_hdr, coap_transport_t transport,
+                     unsigned char **token, unsigned int *token_length)
+{
     assert(pdu_hdr);
     assert(token);
     assert(token_length);
 
     switch(transport)
     {
-        case coap_udp:
-            *token_length = pdu_hdr->coap_hdr_udp_t.token_length;
-            *token = (unsigned char *)pdu_hdr->coap_hdr_udp_t.token;
+        case COAP_UDP:
+            *token_length = pdu_hdr->udp.token_length;
+            *token = (unsigned char *)pdu_hdr->udp.token;
             break;
 #ifdef WITH_TCP
-        case coap_tcp:
-            *token_length = (pdu_hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f;
-            *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_t.token;
+        case COAP_TCP:
+            *token_length = (pdu_hdr->tcp.header_data[0]) & 0x0f;
+            *token = (unsigned char *)pdu_hdr->tcp.token;
             break;
-        case coap_tcp_8bit:
-            *token_length = (pdu_hdr->coap_hdr_tcp_8bit_t.header_data[0]) & 0x0f;
-            *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_8bit_t.token;
+        case COAP_TCP_8BIT:
+            *token_length = (pdu_hdr->tcp_8bit.header_data[0]) & 0x0f;
+            *token = (unsigned char *)pdu_hdr->tcp_8bit.token;
             break;
-        case coap_tcp_16bit:
-            *token_length = (pdu_hdr->coap_hdr_tcp_16bit_t.header_data[0]) & 0x0f;
-            *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_16bit_t.token;
+        case COAP_TCP_16BIT:
+            *token_length = (pdu_hdr->tcp_16bit.header_data[0]) & 0x0f;
+            *token = (unsigned char *)pdu_hdr->tcp_16bit.token;
             break;
-        case coap_tcp_32bit:
-            *token_length = (pdu_hdr->coap_hdr_tcp_32bit_t.header_data[0]) & 0x0f;
-            *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_32bit_t.token;
+        case COAP_TCP_32BIT:
+            *token_length = (pdu_hdr->tcp_32bit.header_data[0]) & 0x0f;
+            *token = (unsigned char *)pdu_hdr->tcp_32bit.token;
             break;
 #endif
         default:
@@ -644,9 +667,15 @@ void coap_get_token(const coap_hdr_t *pdu_hdr, coap_transport_type transport,
     }
 }
 
-/** @FIXME de-duplicate code with coap_add_option_later */
 size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len,
-        const unsigned char *data, coap_transport_type transport)
+                       const unsigned char *data)
+{
+    return coap_add_option2(pdu, type, len, data, COAP_UDP);
+}
+
+/** @FIXME de-duplicate code with coap_add_option_later */
+size_t coap_add_option2(coap_pdu_t *pdu, unsigned short type, unsigned int len,
+                        const unsigned char *data, coap_transport_t transport)
 {
     size_t optsize;
     coap_opt_t *opt;
@@ -656,28 +685,28 @@ size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len,
 
     if (type < pdu->max_delta)
     {
-        warn("coap_add_option: options are not in correct order\n");
+        warn("coap_add_option2: options are not in correct order\n");
         return 0;
     }
 
     switch(transport)
     {
 #ifdef WITH_TCP
-        case coap_tcp:
-            opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_t) + pdu->length;
+        case COAP_TCP:
+            opt = (unsigned char *) &(pdu->transport_hdr->tcp) + pdu->length;
             break;
-        case coap_tcp_8bit:
-            opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_8bit_t) + pdu->length;
+        case COAP_TCP_8BIT:
+            opt = (unsigned char *) &(pdu->transport_hdr->tcp_8bit) + pdu->length;
             break;
-        case coap_tcp_16bit:
-            opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_16bit_t) + pdu->length;
+        case COAP_TCP_16BIT:
+            opt = (unsigned char *) &(pdu->transport_hdr->tcp_16bit) + pdu->length;
             break;
-        case coap_tcp_32bit:
-            opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_32bit_t) + pdu->length;
+        case COAP_TCP_32BIT:
+            opt = (unsigned char *) &(pdu->transport_hdr->tcp_32bit) + pdu->length;
             break;
 #endif
         default:
-            opt = (unsigned char *) &(pdu->hdr->coap_hdr_udp_t) + pdu->length;
+            opt = (unsigned char *) &(pdu->transport_hdr->udp) + pdu->length;
             break;
     }
 
@@ -686,7 +715,7 @@ size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len,
 
     if (!optsize)
     {
-        warn("coap_add_option: cannot add option\n");
+        warn("coap_add_option2: cannot add option\n");
         /* error */
         return 0;
     }
@@ -699,7 +728,7 @@ size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len,
     return optsize;
 }
 
-/** @FIXME de-duplicate code with coap_add_option */
+/** @FIXME de-duplicate code with coap_add_option2 */
 unsigned char*
 coap_add_option_later(coap_pdu_t *pdu, unsigned short type, unsigned int len)
 {
@@ -851,8 +880,13 @@ static size_t next_option_safe(coap_opt_t **optp, size_t *length, coap_option_t*
     return optsize;
 }
 
-int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
-                   coap_transport_type transport)
+int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu)
+{
+    return coap_pdu_parse2(data, length, pdu, COAP_UDP);
+}
+
+int coap_pdu_parse2(unsigned char *data, size_t length, coap_pdu_t *pdu,
+                    coap_transport_t transport)
 {
     assert(data);
     assert(pdu);
@@ -866,9 +900,9 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
 
     unsigned int headerSize = 0;
 
-    if (coap_udp == transport)
+    if (COAP_UDP == transport)
     {
-        headerSize = sizeof(pdu->hdr->coap_hdr_udp_t);
+        headerSize = sizeof(pdu->transport_hdr->udp);
     }
 #ifdef WITH_TCP
     else
@@ -887,44 +921,44 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
 #ifdef WITH_TCP
     switch(transport)
     {
-        case coap_udp:
+        case COAP_UDP:
             break;
-        case coap_tcp:
+        case COAP_TCP:
             for (size_t i = 0 ; i < headerSize ; i++)
             {
-                pdu->hdr->coap_hdr_tcp_t.header_data[i] = data[i];
+                pdu->transport_hdr->tcp.header_data[i] = data[i];
             }
 
             tokenLength = data[0] & 0x0f;
-            opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_t) + 1) + tokenLength;
+            opt = (unsigned char *) (&(pdu->transport_hdr->tcp) + 1) + tokenLength;
             break;
-        case coap_tcp_8bit:
+        case COAP_TCP_8BIT:
             for (size_t i = 0 ; i < headerSize ; i++)
             {
-                pdu->hdr->coap_hdr_tcp_8bit_t.header_data[i] = data[i];
+                pdu->transport_hdr->tcp_8bit.header_data[i] = data[i];
             }
 
             tokenLength = data[0] & 0x0f;
-            opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_8bit_t))
+            opt = (unsigned char *) (&(pdu->transport_hdr->tcp_8bit))
                     + tokenLength + COAP_TCP_HEADER_8_BIT;
             break;
-        case coap_tcp_16bit:
+        case COAP_TCP_16BIT:
             for (size_t i = 0 ; i < headerSize ; i++)
             {
-                pdu->hdr->coap_hdr_tcp_16bit_t.header_data[i] = data[i];
+                pdu->transport_hdr->tcp_16bit.header_data[i] = data[i];
             }
 
             tokenLength = data[0] & 0x0f;
-            opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_16bit_t) + 1) + tokenLength;
+            opt = (unsigned char *) (&(pdu->transport_hdr->tcp_16bit) + 1) + tokenLength;
             break;
-        case coap_tcp_32bit:
+        case COAP_TCP_32BIT:
             for (size_t i = 0 ; i < headerSize ; i++)
             {
-                pdu->hdr->coap_hdr_tcp_32bit_t.header_data[i] = data[i];
+                pdu->transport_hdr->tcp_32bit.header_data[i] = data[i];
             }
 
             tokenLength = data[0] & 0x0f;
-            opt = ((unsigned char *) &(pdu->hdr->coap_hdr_tcp_32bit_t)) +
+            opt = ((unsigned char *) &(pdu->transport_hdr->tcp_32bit)) +
                     headerSize + tokenLength;
             break;
         default:
@@ -933,43 +967,43 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
 #endif
     pdu->length = length;
 
-    if (coap_udp == transport)
+    if (COAP_UDP == transport)
     {
-        pdu->hdr->coap_hdr_udp_t.version = data[0] >> 6;
-        pdu->hdr->coap_hdr_udp_t.type = (data[0] >> 4) & 0x03;
-        pdu->hdr->coap_hdr_udp_t.token_length = data[0] & 0x0f;
-        pdu->hdr->coap_hdr_udp_t.code = data[1];
+        pdu->transport_hdr->udp.version = data[0] >> 6;
+        pdu->transport_hdr->udp.type = (data[0] >> 4) & 0x03;
+        pdu->transport_hdr->udp.token_length = data[0] & 0x0f;
+        pdu->transport_hdr->udp.code = data[1];
         pdu->data = NULL;
 
-        tokenLength = pdu->hdr->coap_hdr_udp_t.token_length;
+        tokenLength = pdu->transport_hdr->udp.token_length;
 
         /* sanity checks */
-        if (pdu->hdr->coap_hdr_udp_t.code == 0)
+        if (pdu->transport_hdr->udp.code == 0)
         {
             if (length != headerSize || tokenLength)
             {
-                debug("coap_pdu_parse: empty message is not empty\n");
+                debug("coap_pdu_parse2: empty message is not empty\n");
                 goto discard;
             }
         }
 
         if (length < headerSize + tokenLength || tokenLength > 8)
         {
-            debug("coap_pdu_parse: invalid Token\n");
+            debug("coap_pdu_parse2: invalid Token\n");
             goto discard;
         }
 
-        memcpy(&pdu->hdr->coap_hdr_udp_t.id, data + 2, 2);
+        memcpy(&pdu->transport_hdr->udp.id, data + 2, 2);
 
         /* Finally calculate beginning of data block and thereby check integrity
          * of the PDU structure. */
 
         /* append data (including the Token) to pdu structure */
-        memcpy(&(pdu->hdr->coap_hdr_udp_t) + 1, data + headerSize, length - headerSize);
+        memcpy(&(pdu->transport_hdr->udp) + 1, data + headerSize, length - headerSize);
 
         /* skip header + token */
         length -= (tokenLength + headerSize);
-        opt = (unsigned char *) (&(pdu->hdr->coap_hdr_udp_t) + 1) + tokenLength;
+        opt = (unsigned char *) (&(pdu->transport_hdr->udp) + 1) + tokenLength;
     }
 #ifdef WITH_TCP
     else // common for tcp header setting
@@ -978,7 +1012,7 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
 
         if (length < headerSize + tokenLength || tokenLength > 8)
         {
-            debug("coap_pdu_parse: invalid Token\n");
+            debug("coap_pdu_parse2: invalid Token\n");
             goto discard;
         }
         /* Finally calculate beginning of data block and thereby check integrity
@@ -999,7 +1033,7 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
         memset(&option, 0, sizeof(coap_option_t));
         if (!next_option_safe(&opt, (size_t *) &length, &option))
         {
-            debug("coap_pdu_parse: drop\n");
+            debug("coap_pdu_parse2: drop\n");
             goto discard;
         }
     }
@@ -1013,7 +1047,7 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
 
         if (!length)
         {
-            debug("coap_pdu_parse: message ending in payload start marker\n");
+            debug("coap_pdu_parse2: message ending in payload start marker\n");
             goto discard;
         }
 
index cc00899..dc619e2 100644 (file)
@@ -471,7 +471,7 @@ void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key)
     coap_option_filter_clear(filter);
     coap_option_setb(filter, COAP_OPTION_URI_PATH);
 
-    coap_option_iterator_init((coap_pdu_t *) request, &opt_iter, filter, coap_udp);
+    coap_option_iterator_init((coap_pdu_t *) request, &opt_iter, filter);
     while ((option = coap_option_next(&opt_iter)))
         coap_hash(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option), key);
 }
@@ -766,7 +766,7 @@ static void coap_notify_observers(coap_context_t *context, coap_resource_t *r)
             coap_tid_t tid = COAP_INVALID_TID;
             obs->dirty = 0;
             /* initialize response */
-            response = coap_pdu_init(COAP_MESSAGE_CON, 0, 0, COAP_MAX_PDU_SIZE, coap_udp);
+            response = coap_pdu_init(COAP_MESSAGE_CON, 0, 0, COAP_MAX_PDU_SIZE);
             if (!response)
             {
                 obs->dirty = 1;
@@ -775,7 +775,7 @@ static void coap_notify_observers(coap_context_t *context, coap_resource_t *r)
                 continue;
             }
 
-            if (!coap_add_token(response, obs->token_length, obs->token, coap_udp))
+            if (!coap_add_token(response, obs->token_length, obs->token))
             {
                 obs->dirty = 1;
                 r->partiallydirty = 1;
@@ -787,19 +787,19 @@ static void coap_notify_observers(coap_context_t *context, coap_resource_t *r)
             token.length = obs->token_length;
             token.s = obs->token;
 
-            response->hdr->coap_hdr_udp_t.id = coap_new_message_id(context);
+            response->transport_hdr->udp.id = coap_new_message_id(context);
             if (obs->non && obs->non_cnt < COAP_OBS_MAX_NON)
             {
-                response->hdr->coap_hdr_udp_t.type = COAP_MESSAGE_NON;
+                response->transport_hdr->udp.type = COAP_MESSAGE_NON;
             }
             else
             {
-                response->hdr->coap_hdr_udp_t.type = COAP_MESSAGE_CON;
+                response->transport_hdr->udp.type = COAP_MESSAGE_CON;
             }
             /* fill with observer-specific data */
             h(context, r, &obs->subscriber, NULL, &token, response);
 
-            if (response->hdr->coap_hdr_udp_t.type == COAP_MESSAGE_CON)
+            if (response->transport_hdr->udp.type == COAP_MESSAGE_CON)
             {
                 tid = coap_send_confirmed(context, &obs->subscriber, response);
                 obs->non_cnt = 0;
@@ -810,7 +810,7 @@ static void coap_notify_observers(coap_context_t *context, coap_resource_t *r)
                 obs->non_cnt++;
             }
 
-            if (COAP_INVALID_TID == tid || response->hdr->coap_hdr_udp_t.type != COAP_MESSAGE_CON)
+            if (COAP_INVALID_TID == tid || response->transport_hdr->udp.type != COAP_MESSAGE_CON)
                 coap_delete_pdu(response);
             if (COAP_INVALID_TID == tid)
             {
index 9ff35ad..3a031e2 100644 (file)
@@ -51,9 +51,9 @@ notify(coap_context_t *context, coap_resource_t *res,
     if ( !context || !res || !sub || !(pdu = coap_new_pdu()) )
     return;
 
-    pdu->hdr->coap_hdr_udp_t.type = COAP_MESSAGE_CON;
-    pdu->hdr->coap_hdr_udp_t.id = rand(); /* use a random transaction id */
-    pdu->hdr->coap_hdr_udp_t.code = code;
+    pdu->hdr->type = COAP_MESSAGE_CON;
+    pdu->hdr->id = rand(); /* use a random transaction id */
+    pdu->hdr->code = code;
 
     /* FIXME: content-type and data (how about block?) */
     if (res->uri->host.length)
index 98037eb..77e96f2 100644 (file)
@@ -27,6 +27,7 @@ with_upstream_libcoap = env.get('WITH_UPSTREAM_LIBCOAP')
 if with_upstream_libcoap == '1':
        # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
        env.AppendUnique(CPPPATH = [os.path.join('#extlibs', 'libcoap', 'libcoap', 'include')])
+       env.AppendUnique(CPPDEFINES = ['WITH_UPSTREAM_LIBCOAP'])
 else:
        # For bring up purposes only, the forked version will live here.
        env.AppendUnique(CPPPATH = [ os.path.join(root_dir, 'lib', 'libcoap-4.1.1', 'include')])
index b1cf8a0..36e9b35 100644 (file)
@@ -687,7 +687,7 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t idx)
 
         if (!deviceInfo->totalDataLen)
         {
-            coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+            coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
                     ((unsigned char *) deviceInfo->recvData)[0] >> 4);
             size_t headerLen = coap_get_tcp_header_length_for_transport(transport);
             if (deviceInfo->recvData && deviceInfo->recvDataLen >= headerLen)
index 55bffcc..5d20ca9 100644 (file)
@@ -1006,7 +1006,7 @@ void CAEDRDataRecvCallback(bt_socket_received_data_s *data, void *userData)
 
     if (!deviceInfo->totalDataLen)
     {
-        coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+        coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
                 ((unsigned char *)deviceInfo->recvData)[0] >> 4);
         size_t headerLen = coap_get_tcp_header_length_for_transport(transport);
 
index 0eb0ed6..c16186b 100644 (file)
@@ -68,7 +68,7 @@ static size_t g_packetDataLen = 0;
 
 void CAGetTCPHeaderDetails(unsigned char* recvBuffer, size_t *headerlen)
 {
-    coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+    coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
         ((unsigned char *)recvBuffer)[0] >> 4);
     *headerlen = coap_get_tcp_header_length_for_transport(transport);
 }
index ed79118..1cd1864 100644 (file)
@@ -307,12 +307,12 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
 {
     OIC_LOG(DEBUG, TAG, "CAReceiveBlockWiseData");
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
     VERIFY_NON_NULL(endpoint, TAG, "endpoint");
     VERIFY_NON_NULL(receivedData, TAG, "receivedData");
 
     // check if received message type is CA_MSG_RESET
-    if (CA_EMPTY == pdu->hdr->coap_hdr_udp_t.code)
+    if (CA_EMPTY == pdu->transport_hdr->udp.code)
     {
         OIC_LOG(DEBUG, TAG, "code is CA_EMPTY..");
 
@@ -392,8 +392,8 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     if (!isBlock1 && !isBlock2)
     {
         CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
-                (CAToken_t)pdu->hdr->coap_hdr_udp_t.token,
-                pdu->hdr->coap_hdr_udp_t.token_length,
+                (CAToken_t)pdu->transport_hdr->udp.token,
+                pdu->transport_hdr->udp.token_length,
                 endpoint->port);
         if (NULL == blockDataID || blockDataID->idLength < 1)
         {
@@ -402,7 +402,7 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
             return CA_STATUS_FAILED;
         }
 
-        uint32_t code = CA_RESPONSE_CODE(pdu->hdr->coap_hdr_udp_t.code);
+        uint32_t code = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
         if (CA_REQUEST_ENTITY_INCOMPLETE == code)
         {
             CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockDataID);
@@ -496,9 +496,9 @@ CAResult_t CAProcessNextStep(const coap_pdu_t *pdu, const CAData_t *receivedData
             if (data->responseInfo)
             {
                 data->responseInfo->info.type =
-                        (pdu->hdr->coap_hdr_udp_t.type == CA_MSG_CONFIRM) ?
+                        (pdu->transport_hdr->udp.type == CA_MSG_CONFIRM) ?
                                 CA_MSG_ACKNOWLEDGE : CA_MSG_NONCONFIRM;
-                data->responseInfo->info.messageId = pdu->hdr->coap_hdr_udp_t.id;
+                data->responseInfo->info.messageId = pdu->transport_hdr->udp.id;
 
                 res = CAAddSendThreadQueue(data, blockID);
                 if (CA_STATUS_OK != res)
@@ -512,7 +512,7 @@ CAResult_t CAProcessNextStep(const coap_pdu_t *pdu, const CAData_t *receivedData
         case CA_OPTION1_RESPONSE:
         case CA_OPTION2_RESPONSE:
         case CA_OPTION1_REQUEST_BLOCK:
-            res = CASendBlockMessage(pdu, pdu->hdr->coap_hdr_udp_t.type, blockID);
+            res = CASendBlockMessage(pdu, pdu->transport_hdr->udp.type, blockID);
             if (CA_STATUS_OK != res)
             {
                 OIC_LOG(ERROR, TAG, "send has failed");
@@ -571,7 +571,7 @@ CAResult_t CAProcessNextStep(const coap_pdu_t *pdu, const CAData_t *receivedData
             }
             else if (receivedData->responseInfo)
             {
-                res = CASendBlockMessage(pdu, pdu->hdr->coap_hdr_udp_t.type, blockID);
+                res = CASendBlockMessage(pdu, pdu->transport_hdr->udp.type, blockID);
                 if (CA_STATUS_OK != res)
                 {
                     OIC_LOG(ERROR, TAG, "send has failed");
@@ -605,7 +605,7 @@ CAResult_t CASendBlockMessage(const coap_pdu_t *pdu, CAMessageType_t msgType,
                               const CABlockDataID_t *blockID)
 {
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
     VERIFY_NON_NULL(blockID, TAG, "blockID");
 
     CAData_t *data = CAGetDataSetFromBlockDataList(blockID);
@@ -629,13 +629,13 @@ CAResult_t CASendBlockMessage(const coap_pdu_t *pdu, CAMessageType_t msgType,
             break;
     }
 
-    uint32_t code = pdu->hdr->coap_hdr_udp_t.code;
+    uint32_t code = pdu->transport_hdr->udp.code;
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
         if (data->responseInfo)
         {
             OIC_LOG(DEBUG, TAG, "set response info");
-            data->responseInfo->info.messageId = pdu->hdr->coap_hdr_udp_t.id;
+            data->responseInfo->info.messageId = pdu->transport_hdr->udp.id;
             data->responseInfo->info.type = sentMsgType;
             data->responseInfo->result = CA_CONTINUE;
         }
@@ -673,7 +673,7 @@ CAResult_t CASendErrorMessage(const coap_pdu_t *pdu, uint8_t status,
                               CAResponseResult_t responseResult, const CABlockDataID_t *blockID)
 {
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
     VERIFY_NON_NULL(blockID, TAG, "blockID");
 
     // create error responseInfo
@@ -685,7 +685,7 @@ CAResult_t CASendErrorMessage(const coap_pdu_t *pdu, uint8_t status,
     }
 
     CAMessageType_t sentMsgType = CA_MSG_NONCONFIRM;
-    switch (pdu->hdr->coap_hdr_udp_t.type)
+    switch (pdu->transport_hdr->udp.type)
     {
         case CA_MSG_CONFIRM:
             sentMsgType = CA_MSG_ACKNOWLEDGE;
@@ -709,20 +709,20 @@ CAResult_t CASendErrorMessage(const coap_pdu_t *pdu, uint8_t status,
 
         if (cloneData->responseInfo)
         {
-            cloneData->responseInfo->info.messageId = pdu->hdr->coap_hdr_udp_t.id;
+            cloneData->responseInfo->info.messageId = pdu->transport_hdr->udp.id;
             cloneData->responseInfo->info.type = sentMsgType;
             cloneData->responseInfo->result = responseResult;
         }
         else
         {
-            CAInfo_t responseData = { .tokenLength = pdu->hdr->coap_hdr_udp_t.token_length };
+            CAInfo_t responseData = { .tokenLength = pdu->transport_hdr->udp.token_length };
             responseData.token = (CAToken_t) OICMalloc(responseData.tokenLength);
             if (!responseData.token)
             {
                 OIC_LOG(ERROR, TAG, "out of memory");
                 return CA_MEMORY_ALLOC_FAILED;
             }
-            memcpy(responseData.token, pdu->hdr->coap_hdr_udp_t.token, responseData.tokenLength);
+            memcpy(responseData.token, pdu->transport_hdr->udp.token, responseData.tokenLength);
 
             cloneData->responseInfo = (CAResponseInfo_t*) OICCalloc(1, sizeof(CAResponseInfo_t));
             if (!cloneData->responseInfo)
@@ -861,15 +861,15 @@ CAResult_t CASetNextBlockOption1(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
 {
     OIC_LOG(INFO, TAG, "CASetNextBlockOption1");
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
     VERIFY_NON_NULL(endpoint, TAG, "endpoint");
     VERIFY_NON_NULL(receivedData, TAG, "receivedData");
 
     OIC_LOG_V(INFO, TAG, "num:%d, M:%d, sze:%d", block.num, block.m, block.szx);
 
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
-            (CAToken_t)pdu->hdr->coap_hdr_udp_t.token,
-            pdu->hdr->coap_hdr_udp_t.token_length,
+            (CAToken_t)pdu->transport_hdr->udp.token,
+            pdu->transport_hdr->udp.token_length,
             endpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
@@ -889,7 +889,7 @@ CAResult_t CASetNextBlockOption1(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     }
 
     uint8_t blockWiseStatus = CA_BLOCK_UNKNOWN;
-    uint32_t code = pdu->hdr->coap_hdr_udp_t.code;
+    uint32_t code = pdu->transport_hdr->udp.code;
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
         // received message type is request
@@ -942,7 +942,7 @@ CAResult_t CASetNextBlockOption1(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     else
     {
         // received message type is response
-        uint32_t code = CA_RESPONSE_CODE(pdu->hdr->coap_hdr_udp_t.code);
+        uint32_t code = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
         if (0 == block.m && (CA_REQUEST_ENTITY_INCOMPLETE != code
                 && CA_REQUEST_ENTITY_TOO_LARGE != code))
         {
@@ -1006,13 +1006,13 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     OIC_LOG_V(INFO, TAG, "num:%d, M:%d, sze:%d", block.num, block.m, block.szx);
 
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
     VERIFY_NON_NULL(endpoint, TAG, "endpoint");
     VERIFY_NON_NULL(receivedData, TAG, "receivedData");
 
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
-            (CAToken_t)pdu->hdr->coap_hdr_udp_t.token,
-            pdu->hdr->coap_hdr_udp_t.token_length,
+            (CAToken_t)pdu->transport_hdr->udp.token,
+            pdu->transport_hdr->udp.token_length,
             endpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
@@ -1032,7 +1032,7 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     }
 
     uint8_t blockWiseStatus = CA_BLOCK_UNKNOWN;
-    if (0 == block.num && CA_GET == pdu->hdr->coap_hdr_udp_t.code && 0 == block.m)
+    if (0 == block.num && CA_GET == pdu->transport_hdr->udp.code && 0 == block.m)
     {
         OIC_LOG(INFO, TAG, "first block number");
 
@@ -1054,7 +1054,7 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     }
     else
     {
-        uint32_t code = pdu->hdr->coap_hdr_udp_t.code;
+        uint32_t code = pdu->transport_hdr->udp.code;
         if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
         {
             // received message type is request
@@ -1086,7 +1086,7 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
                                                                           COAP_OPTION_SIZE2,
                                                                           &(data->payloadLength));
 
-            uint32_t code = CA_RESPONSE_CODE(pdu->hdr->coap_hdr_udp_t.code);
+            uint32_t code = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
             if (CA_REQUEST_ENTITY_INCOMPLETE != code && CA_REQUEST_ENTITY_TOO_LARGE != code)
             {
                 // check if received payload is exact
@@ -1164,7 +1164,7 @@ CAResult_t CAUpdateBlockOptionItems(CABlockData_t *currData, const coap_pdu_t *p
 
     // update block data
     CAResult_t res = CA_STATUS_OK;
-    uint32_t code = CA_RESPONSE_CODE(pdu->hdr->coap_hdr_udp_t.code);
+    uint32_t code = CA_RESPONSE_CODE(pdu->transport_hdr->udp.code);
 
     if (CA_REQUEST_ENTITY_INCOMPLETE == code || CA_REQUEST_ENTITY_TOO_LARGE == code)
     {
@@ -1259,10 +1259,10 @@ CAResult_t CANegotiateBlockSize(CABlockData_t *currData, coap_block_t *block,
     VERIFY_NON_NULL(currData, TAG, "currData");
     VERIFY_NON_NULL(block, TAG, "block");
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
 
     bool isReqMsg = false;
-    uint32_t code = pdu->hdr->coap_hdr_udp_t.code;
+    uint32_t code = pdu->transport_hdr->udp.code;
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
         isReqMsg = true;
@@ -1359,7 +1359,7 @@ CAResult_t CAUpdateBlockData(CABlockData_t *currData, coap_block_t block,
 CAResult_t CAUpdateMessageId(coap_pdu_t *pdu, const CABlockDataID_t *blockID)
 {
     VERIFY_NON_NULL(pdu, TAG, "pdu");
-    VERIFY_NON_NULL(pdu->hdr, TAG, "pdu->hdr");
+    VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
     VERIFY_NON_NULL(blockID, TAG, "blockID");
 
     // if message is sent, update messageId in block-wise transfer list
@@ -1372,7 +1372,7 @@ CAResult_t CAUpdateMessageId(coap_pdu_t *pdu, const CABlockDataID_t *blockID)
 
     if (cadata->requestInfo)
     {
-        cadata->requestInfo->info.messageId = pdu->hdr->coap_hdr_udp_t.id;
+        cadata->requestInfo->info.messageId = pdu->transport_hdr->udp.id;
     }
 
     return CA_STATUS_OK;
@@ -1384,7 +1384,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
     OIC_LOG(DEBUG, TAG, "IN-AddBlockOption");
     VERIFY_NON_NULL(pdu, TAG, "pdu");
     VERIFY_NON_NULL((*pdu), TAG, "(*pdu)");
-    VERIFY_NON_NULL((*pdu)->hdr, TAG, "(*pdu)->hdr");
+    VERIFY_NON_NULL((*pdu)->transport_hdr, TAG, "(*pdu)->transport_hdr");
     VERIFY_NON_NULL(info, TAG, "info");
     VERIFY_NON_NULL(endpoint, TAG, "endpoint");
     VERIFY_NON_NULL(options, TAG, "options");
@@ -1398,8 +1398,8 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
     }
 
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
-            (CAToken_t)(*pdu)->hdr->coap_hdr_udp_t.token,
-            (*pdu)->hdr->coap_hdr_udp_t.token_length,
+            (CAToken_t)(*pdu)->transport_hdr->udp.token,
+            (*pdu)->transport_hdr->udp.token_length,
             endpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
@@ -1408,7 +1408,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
         goto exit;
     }
 
-    uint32_t repCode = CA_RESPONSE_CODE((*pdu)->hdr->coap_hdr_udp_t.code);
+    uint32_t repCode = CA_RESPONSE_CODE((*pdu)->transport_hdr->udp.code);
     if (CA_REQUEST_ENTITY_INCOMPLETE == repCode)
     {
         OIC_LOG(INFO, TAG, "don't use option");
@@ -1450,7 +1450,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
                 OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", (*pdu)->length);
                 coap_add_option(*pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
                                 COAP_OPTION_LENGTH(*(coap_option *) opt->data),
-                                COAP_OPTION_DATA(*(coap_option *) opt->data), coap_udp);
+                                COAP_OPTION_DATA(*(coap_option *) opt->data));
             }
         }
 
@@ -1469,7 +1469,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
         }
     }
 
-    uint32_t code = (*pdu)->hdr->coap_hdr_udp_t.code;
+    uint32_t code = (*pdu)->transport_hdr->udp.code;
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
         // if received message type is RESET from remote device,
@@ -1498,7 +1498,7 @@ CAResult_t CAAddBlockOption2(coap_pdu_t **pdu, const CAInfo_t *info, size_t data
     OIC_LOG(DEBUG, TAG, "IN-AddBlockOption2");
     VERIFY_NON_NULL(pdu, TAG, "pdu");
     VERIFY_NON_NULL((*pdu), TAG, "(*pdu)");
-    VERIFY_NON_NULL((*pdu)->hdr, TAG, "(*pdu)->hdr");
+    VERIFY_NON_NULL((*pdu)->transport_hdr, TAG, "(*pdu)->transport_hdr");
     VERIFY_NON_NULL(info, TAG, "info");
     VERIFY_NON_NULL(blockID, TAG, "blockID");
     VERIFY_NON_NULL(options, TAG, "options");
@@ -1513,7 +1513,7 @@ CAResult_t CAAddBlockOption2(coap_pdu_t **pdu, const CAInfo_t *info, size_t data
     }
 
     CAResult_t res = CA_STATUS_OK;
-    uint32_t code = (*pdu)->hdr->coap_hdr_udp_t.code;
+    uint32_t code = (*pdu)->transport_hdr->udp.code;
     if (CA_GET != code && CA_POST != code && CA_PUT != code && CA_DELETE != code)
     {
         CASetMoreBitFromBlock(dataLength, block2);
@@ -1603,7 +1603,7 @@ CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t data
     OIC_LOG(DEBUG, TAG, "IN-AddBlockOption1");
     VERIFY_NON_NULL(pdu, TAG, "pdu");
     VERIFY_NON_NULL((*pdu), TAG, "(*pdu)");
-    VERIFY_NON_NULL((*pdu)->hdr, TAG, "(*pdu)->hdr");
+    VERIFY_NON_NULL((*pdu)->transport_hdr, TAG, "(*pdu)->transport_hdr");
     VERIFY_NON_NULL(info, TAG, "info");
     VERIFY_NON_NULL(blockID, TAG, "blockID");
     VERIFY_NON_NULL(options, TAG, "options");
@@ -1617,7 +1617,7 @@ CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t data
     }
 
     CAResult_t res = CA_STATUS_OK;
-    uint32_t code = (*pdu)->hdr->coap_hdr_udp_t.code;
+    uint32_t code = (*pdu)->transport_hdr->udp.code;
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
         CASetMoreBitFromBlock(dataLength, block1);
@@ -1746,7 +1746,7 @@ CAResult_t CAAddOptionToPDU(coap_pdu_t *pdu, coap_list_t **options)
             OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length);
             int ret = coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
                                       COAP_OPTION_LENGTH(*(coap_option *) opt->data),
-                                      COAP_OPTION_DATA(*(coap_option *) opt->data), coap_udp);
+                                      COAP_OPTION_DATA(*(coap_option *) opt->data));
             if (!ret)
             {
                 return CA_STATUS_FAILED;
@@ -2002,23 +2002,23 @@ CAResult_t CAUpdatePayloadData(CABlockData_t *currData, const CAData_t *received
 CAData_t* CACreateNewDataSet(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint)
 {
     VERIFY_NON_NULL_RET(pdu, TAG, "pdu", NULL);
-    VERIFY_NON_NULL_RET(pdu->hdr, TAG, "pdu->hdr", NULL);
+    VERIFY_NON_NULL_RET(pdu->transport_hdr, TAG, "pdu->transport_hdr", NULL);
     VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
 
     CARequestInfo_t* requestInfo = NULL;
     CAResponseInfo_t* responseInfo = NULL;
 
-    uint32_t code = pdu->hdr->coap_hdr_udp_t.code;
+    uint32_t code = pdu->transport_hdr->udp.code;
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
-        CAInfo_t responseData = { .tokenLength = pdu->hdr->coap_hdr_udp_t.token_length };
+        CAInfo_t responseData = { .tokenLength = pdu->transport_hdr->udp.token_length };
         responseData.token = (CAToken_t) OICMalloc(responseData.tokenLength);
         if (!responseData.token)
         {
             OIC_LOG(ERROR, TAG, "out of memory");
             return NULL;
         }
-        memcpy(responseData.token, pdu->hdr->coap_hdr_udp_t.token, responseData.tokenLength);
+        memcpy(responseData.token, pdu->transport_hdr->udp.token, responseData.tokenLength);
 
         responseInfo = (CAResponseInfo_t*) OICCalloc(1, sizeof(CAResponseInfo_t));
         if (!responseInfo)
@@ -2031,14 +2031,14 @@ CAData_t* CACreateNewDataSet(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint
     }
     else
     {
-        CAInfo_t requestData = { .tokenLength = pdu->hdr->coap_hdr_udp_t.token_length };
+        CAInfo_t requestData = { .tokenLength = pdu->transport_hdr->udp.token_length };
         requestData.token = (CAToken_t) OICMalloc(requestData.tokenLength);
         if (!requestData.token)
         {
             OIC_LOG(ERROR, TAG, "out of memory");
             return NULL;
         }
-        memcpy(requestData.token, pdu->hdr->coap_hdr_udp_t.token, requestData.tokenLength);
+        memcpy(requestData.token, pdu->transport_hdr->udp.token, requestData.tokenLength);
 
         requestInfo = (CARequestInfo_t*) OICCalloc(1, sizeof(CARequestInfo_t));
         if (!requestInfo)
@@ -2061,7 +2061,7 @@ CAData_t* CACreateNewDataSet(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint
 
         CAGetResponseInfoFromPDU(pdu, resInfo, endpoint);
         requestInfo->method = CA_GET;
-        requestInfo->info.messageId = CAGetMessageIdFromPduBinaryData(pdu->hdr, pdu->length);
+        requestInfo->info.messageId = CAGetMessageIdFromPduBinaryData(pdu->transport_hdr, pdu->length);
         requestInfo->info.resourceUri = OICStrdup(resInfo->info.resourceUri);
 
         // after copying the resource uri, destroy response info.
@@ -2316,7 +2316,7 @@ CAResult_t CAGetTokenFromBlockDataList(const coap_pdu_t *pdu, const CAEndpoint_t
 
         if (NULL != currData->sentData && NULL != currData->sentData->requestInfo)
         {
-            if (pdu->hdr->coap_hdr_udp_t.id == currData->sentData->requestInfo->info.messageId &&
+            if (pdu->transport_hdr->udp.id == currData->sentData->requestInfo->info.messageId &&
                     endpoint->adapter == currData->sentData->remoteEndpoint->adapter)
             {
                 if (NULL != currData->sentData->requestInfo->info.token)
index ba1106a..18f8039 100644 (file)
@@ -275,7 +275,7 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
     resInfo->info.type = CAGetMessageTypeFromPduBinaryData(pdu, size);
     resInfo->info.messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
 
-    CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *) pdu, &(resInfo->info),
+    CAResult_t res = CAGetTokenFromPDU((const coap_hdr_transport_t *) pdu, &(resInfo->info),
                                        endpoint);
     if (CA_STATUS_OK != res)
     {
@@ -421,7 +421,7 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data)
     coap_pdu_t *pdu = NULL;
     CAInfo_t *info = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
     CAResult_t res = CA_SEND_FAILED;
 
     if (!data->requestInfo && !data->responseInfo)
@@ -470,9 +470,9 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data)
     CALogPDUInfo(pdu, data->remoteEndpoint);
 
     OIC_LOG(DEBUG, TAG, "pdu to send :");
-    OIC_LOG_BUFFER(DEBUG, TAG,  (uint8_t*)pdu->hdr, pdu->length);
+    OIC_LOG_BUFFER(DEBUG, TAG,  (uint8_t*)pdu->transport_hdr, pdu->length);
 
-    res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length, data->dataType);
+    res = CASendMulticastData(data->remoteEndpoint, pdu->transport_hdr, pdu->length, data->dataType);
     if (CA_STATUS_OK != res)
     {
         OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
@@ -484,7 +484,7 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data)
     return res;
 
 exit:
-    CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+    CAErrorHandler(data->remoteEndpoint, pdu->transport_hdr, pdu->length, res);
     coap_delete_list(options);
     coap_delete_pdu(pdu);
     return res;
@@ -502,7 +502,7 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
     coap_pdu_t *pdu = NULL;
     CAInfo_t *info = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     if (SEND_TYPE_UNICAST == type)
     {
@@ -559,7 +559,7 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
                     if (CA_STATUS_OK != res)
                     {
                         OIC_LOG(INFO, TAG, "to write block option has failed");
-                        CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+                        CAErrorHandler(data->remoteEndpoint, pdu->transport_hdr, pdu->length, res);
                         coap_delete_list(options);
                         coap_delete_pdu(pdu);
                         return res;
@@ -570,11 +570,11 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
             CALogPDUInfo(pdu, data->remoteEndpoint);
 
             OIC_LOG_V(INFO, TAG, "CASendUnicastData type : %d", data->dataType);
-            res = CASendUnicastData(data->remoteEndpoint, pdu->hdr, pdu->length, data->dataType);
+            res = CASendUnicastData(data->remoteEndpoint, pdu->transport_hdr, pdu->length, data->dataType);
             if (CA_STATUS_OK != res)
             {
                 OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
-                CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+                CAErrorHandler(data->remoteEndpoint, pdu->transport_hdr, pdu->length, res);
                 coap_delete_list(options);
                 coap_delete_pdu(pdu);
                 return res;
@@ -595,7 +595,7 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
                 res = CARetransmissionSentData(&g_retransmissionContext,
                                                data->remoteEndpoint,
                                                data->dataType,
-                                               pdu->hdr, pdu->length);
+                                               pdu->transport_hdr, pdu->length);
                 if ((CA_STATUS_OK != res) && (CA_NOT_SUPPORTED != res))
                 {
                     //when retransmission not supported this will return CA_NOT_SUPPORTED, ignore
@@ -777,7 +777,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
         {
             // for retransmission
             void *retransmissionPdu = NULL;
-            CARetransmissionReceivedData(&g_retransmissionContext, cadata->remoteEndpoint, pdu->hdr,
+            CARetransmissionReceivedData(&g_retransmissionContext, cadata->remoteEndpoint, pdu->transport_hdr,
                                          pdu->length, &retransmissionPdu);
 
             // get token from saved data in retransmission list
@@ -786,7 +786,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
                 if (cadata->responseInfo)
                 {
                     CAInfo_t *info = &cadata->responseInfo->info;
-                    CAResult_t res = CAGetTokenFromPDU((const coap_hdr_t *)retransmissionPdu,
+                    CAResult_t res = CAGetTokenFromPDU((const coap_hdr_transport_t *)retransmissionPdu,
                                                        info, &(sep->endpoint));
                     if (CA_STATUS_OK != res)
                     {
@@ -1230,19 +1230,19 @@ void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint)
     if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
     {
         OIC_LOG(DEBUG, TAG, "pdu header data :");
-        OIC_LOG_BUFFER(DEBUG, TAG,  (const uint8_t *) pdu->hdr, pdu->length);
+        OIC_LOG_BUFFER(DEBUG, TAG,  (const uint8_t *) pdu->transport_hdr, pdu->length);
     }
     else
 #endif
     {
-        OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->coap_hdr_udp_t.type);
+        OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->transport_hdr->udp.type);
 
-        OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->coap_hdr_udp_t.code);
+        OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->transport_hdr->udp.code);
 
         OIC_LOG(DEBUG, TAG, "PDU Maker - token :");
 
-        OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr->coap_hdr_udp_t.token,
-                       pdu->hdr->coap_hdr_udp_t.token_length);
+        OIC_LOG_BUFFER(DEBUG, TAG, pdu->transport_hdr->udp.token,
+                       pdu->transport_hdr->udp.token_length);
     }
 }
 
index d8f1f06..96cfbb7 100644 (file)
@@ -100,7 +100,7 @@ CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endp
 }
 
 coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_t *endpoint,
-                          coap_list_t **optlist, coap_transport_type *transport)
+                          coap_list_t **optlist, coap_transport_t *transport)
 {
     VERIFY_NON_NULL_RET(info, TAG, "info", NULL);
     VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
@@ -187,19 +187,15 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode,
     VERIFY_NON_NULL_RET(data, TAG, "data", NULL);
     VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
 
-    coap_transport_type transport;
+    coap_transport_t transport = COAP_UDP;
 #ifdef WITH_TCP
     if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
     {
         transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)data)[0] >> 4);
     }
-    else
 #endif
-    {
-        transport = coap_udp;
-    }
 
-    coap_pdu_t *outpdu = coap_new_pdu(transport, length);
+    coap_pdu_t *outpdu = coap_new_pdu2(transport, length);
     if (NULL == outpdu)
     {
         OIC_LOG(ERROR, TAG, "outpdu is null");
@@ -208,7 +204,7 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode,
 
     OIC_LOG_V(DEBUG, TAG, "pdu parse-transport type : %d", transport);
 
-    int ret = coap_pdu_parse((unsigned char *) data, length, outpdu, transport);
+    int ret = coap_pdu_parse2((unsigned char *) data, length, outpdu, transport);
     OIC_LOG_V(DEBUG, TAG, "pdu parse ret: %d", ret);
     if (0 >= ret)
     {
@@ -224,16 +220,16 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode,
     else
 #endif
     {
-        if (outpdu->hdr->coap_hdr_udp_t.version != COAP_DEFAULT_VERSION)
+        if (outpdu->transport_hdr->udp.version != COAP_DEFAULT_VERSION)
         {
             OIC_LOG_V(ERROR, TAG, "coap version is not available : %d",
-                      outpdu->hdr->coap_hdr_udp_t.version);
+                      outpdu->transport_hdr->udp.version);
             goto exit;
         }
-        if (outpdu->hdr->coap_hdr_udp_t.token_length > CA_MAX_TOKEN_LEN)
+        if (outpdu->transport_hdr->udp.token_length > CA_MAX_TOKEN_LEN)
         {
             OIC_LOG_V(ERROR, TAG, "token length has been exceed : %d",
-                      outpdu->hdr->coap_hdr_udp_t.token_length);
+                      outpdu->transport_hdr->udp.token_length);
             goto exit;
         }
     }
@@ -252,7 +248,7 @@ exit:
 
 coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
                               const CAEndpoint_t *endpoint, coap_list_t *options,
-                              coap_transport_type *transport)
+                              coap_transport_t *transport)
 {
     VERIFY_NON_NULL_RET(info, TAG, "info", NULL);
     VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
@@ -301,10 +297,10 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
     else
 #endif
     {
-        *transport = coap_udp;
+        *transport = COAP_UDP;
     }
 
-    coap_pdu_t *pdu = coap_new_pdu(*transport, length);
+    coap_pdu_t *pdu = coap_new_pdu2(*transport, length);
 
     if (NULL == pdu)
     {
@@ -337,10 +333,10 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
             /* use saved message id */
             message_id = info->messageId;
         }
-        pdu->hdr->coap_hdr_udp_t.id = message_id;
-        OIC_LOG_V(DEBUG, TAG, "messageId in pdu is %d, %d", message_id, pdu->hdr->coap_hdr_udp_t.id);
+        pdu->transport_hdr->udp.id = message_id;
+        OIC_LOG_V(DEBUG, TAG, "messageId in pdu is %d, %d", message_id, pdu->transport_hdr->udp.id);
 
-        pdu->hdr->coap_hdr_udp_t.type = info->type;
+        pdu->transport_hdr->udp.type = info->type;
     }
 
     coap_add_code(pdu, *transport, code);
@@ -351,7 +347,7 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
         OIC_LOG_V(DEBUG, TAG, "token info token length: %d, token :", tokenLength);
         OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)info->token, tokenLength);
 
-        int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *)info->token, *transport);
+        int32_t ret = coap_add_token2(pdu, tokenLength, (unsigned char *)info->token, *transport);
         if (0 == ret)
         {
             OIC_LOG(ERROR, TAG, "can't add token");
@@ -378,9 +374,9 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
                       COAP_OPTION_DATA(*(coap_option *) opt->data));
 
             OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length);
-            coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
-                            COAP_OPTION_LENGTH(*(coap_option *) opt->data),
-                            COAP_OPTION_DATA(*(coap_option *) opt->data), *transport);
+            coap_add_option2(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
+                             COAP_OPTION_LENGTH(*(coap_option *) opt->data),
+                             COAP_OPTION_DATA(*(coap_option *) opt->data), *transport);
         }
     }
 
@@ -701,20 +697,20 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     VERIFY_NON_NULL(outCode, TAG, "outCode");
     VERIFY_NON_NULL(outInfo, TAG, "outInfo");
 
-    coap_transport_type transport;
+    coap_transport_t transport;
 #ifdef WITH_TCP
     if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
     {
-        transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)pdu->hdr)[0] >> 4);
+        transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)pdu->transport_hdr)[0] >> 4);
     }
     else
 #endif
     {
-        transport = coap_udp;
+        transport = COAP_UDP;
     }
 
     coap_opt_iterator_t opt_iter;
-    coap_option_iterator_init((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL, transport);
+    coap_option_iterator_init2((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL, transport);
 
     if (outCode)
     {
@@ -740,10 +736,10 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
 #endif
     {
         // set type
-        outInfo->type = pdu->hdr->coap_hdr_udp_t.type;
+        outInfo->type = pdu->transport_hdr->udp.type;
 
         // set message id
-        outInfo->messageId = pdu->hdr->coap_hdr_udp_t.id;
+        outInfo->messageId = pdu->transport_hdr->udp.id;
         outInfo->payloadFormat = CA_FORMAT_UNDEFINED;
         outInfo->acceptFormat = CA_FORMAT_UNDEFINED;
     }
@@ -917,7 +913,7 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
 
     unsigned char* token = NULL;
     unsigned int token_length = 0;
-    coap_get_token(pdu->hdr, transport, &token, &token_length);
+    coap_get_token2(pdu->transport_hdr, transport, &token, &token_length);
 
     // set token data
     if (token_length > 0)
@@ -991,14 +987,15 @@ exit:
     return CA_STATUS_FAILED;
 }
 
-CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo,
+CAResult_t CAGetTokenFromPDU(const coap_hdr_transport_t *pdu_hdr,
+                             CAInfo_t *outInfo,
                              const CAEndpoint_t *endpoint)
 {
     VERIFY_NON_NULL(pdu_hdr, TAG, "pdu_hdr");
     VERIFY_NON_NULL(outInfo, TAG, "outInfo");
     VERIFY_NON_NULL(endpoint, TAG, "endpoint");
 
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 #ifdef WITH_TCP
     if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
     {
@@ -1008,7 +1005,7 @@ CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo,
 
     unsigned char* token = NULL;
     unsigned int token_length = 0;
-    coap_get_token(pdu_hdr, transport, &token, &token_length);
+    coap_get_token2(pdu_hdr, transport, &token, &token_length);
 
     // set token data
     if (token_length > 0)
@@ -1108,7 +1105,7 @@ CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size
 
     coap_hdr_t *hdr = (coap_hdr_t *) pdu;
 
-    return (CAMessageType_t) hdr->coap_hdr_udp_t.type;
+    return (CAMessageType_t) hdr->type;
 }
 
 uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size)
@@ -1124,7 +1121,7 @@ uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size)
 
     coap_hdr_t *hdr = (coap_hdr_t *) pdu;
 
-    return hdr->coap_hdr_udp_t.id;
+    return hdr->id;
 }
 
 CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size)
@@ -1140,7 +1137,7 @@ CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size)
 
     coap_hdr_t *hdr = (coap_hdr_t *) pdu;
 
-    return (CAResponseResult_t) CA_RESPONSE_CODE(hdr->coap_hdr_udp_t.code);
+    return (CAResponseResult_t) CA_RESPONSE_CODE(hdr->code);
 }
 
 CAPayloadFormat_t CAConvertFormat(uint8_t format)
index 86741fe..905d2dd 100644 (file)
@@ -231,16 +231,16 @@ static char *CARAGetSIDFromPDU(coap_pdu_t *pdu)
 
     VERIFY_NON_NULL_RET(pdu, RA_ADAPTER_TAG, "Invalid parameter!", NULL);
 
-    if (pdu->hdr->coap_hdr_udp_t.token_length * 2 > MAX_IBB_SESSION_ID_LENGTH)
+    if (pdu->hdr->token_length * 2 > MAX_IBB_SESSION_ID_LENGTH)
     {
         OIC_LOG(ERROR, RA_ADAPTER_TAG, "Token length more than expected!");
         return NULL;
     }
 
     char hex[3] = {0};
-    for (int i = 0; i < pdu->hdr->coap_hdr_udp_t.token_length; i++)
+    for (int i = 0; i < pdu->hdr->token_length; i++)
     {
-        snprintf(hex, 3, "%02x", pdu->hdr->coap_hdr_udp_t.token[i]);
+        snprintf(hex, 3, "%02x", pdu->hdr->token[i]);
         OICStrcat(s_sid, sizeof(s_sid), hex);
     }
 
index 77fd1ae..de9b2d4 100644 (file)
@@ -212,7 +212,7 @@ void CATCPReadDataInternal()
 
             if (!isHeaderChecked && totalReceivedLen)
             {
-                coap_transport_type transport;
+                coap_transport_t transport;
                 size_t headerLen;
                 CAGetTCPHeaderDetails(recvBuffer, &transport, &headerLen);
                 if (totalReceivedLen >= headerLen)
@@ -326,4 +326,4 @@ void CATCPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen,
             sendData(endpoint, data, datalen);
         }
     }
-}
\ No newline at end of file
+}
index cec1f42..e0d8fac 100644 (file)
@@ -549,7 +549,7 @@ size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t
         return 0;
     }
 
-    coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+    coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
             ((unsigned char *)recvBuffer)[0] >> 4);
     size_t optPaylaodLen = coap_get_length_from_header((unsigned char *)recvBuffer,
                                                         transport);
@@ -563,7 +563,7 @@ size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t
     return headerLen + optPaylaodLen;
 }
 
-void CAGetTCPHeaderDetails(unsigned char* recvBuffer, coap_transport_type *transport,
+void CAGetTCPHeaderDetails(unsigned char* recvBuffer, coap_transport_t *transport,
                            size_t *headerlen)
 {
     if (NULL == recvBuffer)
index 42fa112..c3034e0 100644 (file)
@@ -467,7 +467,7 @@ static CAResult_t CAReadHeader(CATCPSessionInfo_t *svritem)
         svritem->protocol = COAP;
 
         //seems CoAP data received. read full coap header.
-        coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(svritem->data[0] >> 4);
+        coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(svritem->data[0] >> 4);
 
         size_t headerLen = coap_get_tcp_header_length_for_transport(transport);
 
@@ -726,7 +726,7 @@ static int CACreateAcceptSocket(int family, CASocket_t *sock)
 
     if (family == AF_INET6)
     {
-        // the socket is restricted to sending and receiving IPv6 packets only.
+        // the socket is restricted to sending and receiving IPv6 packets only.
         int on = 1;
         if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
         {
@@ -949,17 +949,17 @@ static size_t CACheckPayloadLength(const void *data, size_t dlen)
 {
     VERIFY_NON_NULL_RET(data, TAG, "data", -1);
 
-    coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+    coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
             ((unsigned char *)data)[0] >> 4);
 
-    coap_pdu_t *pdu = coap_new_pdu(transport, dlen);
+    coap_pdu_t *pdu = coap_new_pdu2(transport, dlen);
     if (!pdu)
     {
         OIC_LOG(ERROR, TAG, "outpdu is null");
         return 0;
     }
 
-    int ret = coap_pdu_parse((unsigned char *) data, dlen, pdu, transport);
+    int ret = coap_pdu_parse2((unsigned char *) data, dlen, pdu, transport);
     if (0 >= ret)
     {
         OIC_LOG(ERROR, TAG, "pdu parse failed");
@@ -1245,7 +1245,7 @@ size_t CAGetTotalLengthFromHeader(const unsigned char *recvBuffer)
 {
     OIC_LOG(DEBUG, TAG, "IN - CAGetTotalLengthFromHeader");
 
-    coap_transport_type transport = coap_get_tcp_header_type_from_initbyte(
+    coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
             ((unsigned char *)recvBuffer)[0] >> 4);
     size_t optPaylaodLen = coap_get_length_from_header((unsigned char *)recvBuffer,
                                                         transport);
index 5efc456..040c7e0 100644 (file)
@@ -47,7 +47,7 @@ TEST_F(CABlockTransferTests, CACreateNewDataSetTest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -100,7 +100,7 @@ TEST_F(CABlockTransferTests, CARemoveBlockDataFromListWithSeed)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -151,7 +151,7 @@ TEST_F(CABlockTransferTests, CAGetBlockDataFromBlockDataListTest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -194,7 +194,7 @@ TEST_F(CABlockTransferTests, CAGetPayloadFromBlockDataListTest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -242,7 +242,7 @@ TEST_F(CABlockTransferTests, CAAddBlockOptionTest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -282,7 +282,7 @@ TEST_F(CABlockTransferTests, CAAddBlockOption1InRequest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -337,7 +337,7 @@ TEST_F(CABlockTransferTests, CAAddBlockOption1InResponse)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -393,7 +393,7 @@ TEST_F(CABlockTransferTests, CAAddBlockOption2InResponse)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -449,7 +449,7 @@ TEST_F(CABlockTransferTests, CAAddBlockOption2InRequest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -503,7 +503,7 @@ TEST_F(CABlockTransferTests, CAGetBlockSizeOptionFromPduTest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -535,7 +535,7 @@ TEST_F(CABlockTransferTests, CASetNextBlockOption1WithRequest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -573,7 +573,7 @@ TEST_F(CABlockTransferTests, CASetNextBlockOption1WithResponse)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -612,7 +612,7 @@ TEST_F(CABlockTransferTests, CASetNextBlockOption2WithRequest)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
@@ -650,7 +650,7 @@ TEST_F(CABlockTransferTests, CASetNextBlockOption2WithResponse)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAToken_t tempToken = NULL;
     CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
index 718c3d3..3e6b283 100644 (file)
@@ -77,7 +77,7 @@ void verifyParsedOptions(CoAPOptionCase const *cases,
 
 TEST(CAProtocolMessage, CAParseURIBase)
 {
-    char sampleURI[] = "coap://[::]/oic/res?rt=core.sensor;if=core.mi.ll";
+    char sampleURI[] = "coap://[::]/oic/res?rt=core.sensor&if=core.mi.ll";
     CoAPOptionCase cases[] = {
         {COAP_OPTION_URI_PATH, 3, "oic"},
         {COAP_OPTION_URI_PATH, 3, "res"},
@@ -99,8 +99,8 @@ TEST(CAProtocolMessage, CAParseURIBase)
 TEST(CAProtocolMessage, CAParseURIManyPath)
 {
     char sampleURI[] = "coap://[::]"
-        "/medium/a/b/c/d/e/f/g/h/i/j/"
-        "?rt=core.sensor;if=core.mi.ll";
+        "/medium/a/b/c/d/e/f/g/h/i/j"
+        "?rt=core.sensor&if=core.mi.ll";
 
     CoAPOptionCase cases[] = {
         {COAP_OPTION_URI_PATH, 6, "medium"},
@@ -131,8 +131,8 @@ TEST(CAProtocolMessage, CAParseURIManyPath)
 // Try for multiple URI parameters that still total less than 128
 TEST(CAProtocolMessage, CAParseURIManyParams)
 {
-    char sampleURI[] = "coap://[::]/oic/res/"
-        "?rt=core.sensor;a=0;b=1;c=2;d=3;e=4;f=5;g=6;h=7;i=8;j=9";
+    char sampleURI[] = "coap://[::]/oic/res"
+        "?rt=core.sensor&a=0&b=1&c=2&d=3&e=4&f=5&g=6&h=7&i=8&j=9";
 
     CoAPOptionCase cases[] = {
         {COAP_OPTION_URI_PATH, 3, "oic"},
@@ -166,7 +166,7 @@ TEST(CAProtocolMessage, CAParseURILongPath)
     char sampleURI[] = "coap://[::]/oic"
         "123456789012345678901234567890123456789012345678901234567890"
         "12345678901234567890123456789012345678901234567890"
-        "/res?rt=core.sensor;if=core.mi.ll";
+        "/res?rt=core.sensor&if=core.mi.ll";
 
     CoAPOptionCase cases[] = {
         {COAP_OPTION_URI_PATH, 113, "oic"
@@ -197,7 +197,7 @@ TEST(CAProtocolMessage, CAGetTokenFromPDU)
 
     coap_pdu_t *pdu = NULL;
     coap_list_t *options = NULL;
-    coap_transport_type transport = coap_udp;
+    coap_transport_t transport = COAP_UDP;
 
     CAInfo_t inData;
     memset(&inData, 0, sizeof(CAInfo_t));
@@ -211,5 +211,5 @@ TEST(CAProtocolMessage, CAGetTokenFromPDU)
     memset(&outData, 0, sizeof(CAInfo_t));
     outData.type = CA_MSG_NONCONFIRM;
 
-    EXPECT_EQ(CA_STATUS_OK, CAGetTokenFromPDU(pdu->hdr, &outData, &tempRep));
+    EXPECT_EQ(CA_STATUS_OK, CAGetTokenFromPDU(pdu->transport_hdr, &outData, &tempRep));
 }
index aade6ad..7fd01d8 100644 (file)
@@ -1765,7 +1765,7 @@ typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
  *
  * @param[OUT] ctx - user context returned in the callback.
  * @param[OUT] peer - pairing device info.
- * @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
+ * @param[OUT] result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
  *                                   if D2D pairing is success without error
  */
 typedef void (*OCDirectPairingCB)(void *ctx, OCDPDev_t *peer, OCStackResult result);
index 9619889..6f1a702 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "iotivity_config.h"
 #include "occlientcb.h"
-#include <coap/utlist.h>
+#include <coap/coap.h>
 #include "logger.h"
 #include "oic_malloc.h"
 #include <string.h>
@@ -31,7 +31,6 @@
 #ifdef HAVE_ARDUINO_TIME_H
 #include "Time.h"
 #endif
-#include <coap/coap_time.h>
 
 #include "cacommon.h"
 #include "cainterface.h"
index a6df796..7042ad9 100644 (file)
@@ -80,9 +80,7 @@
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
-#include <coap/coap_time.h>
-#include <coap/utlist.h>
-#include <coap/pdu.h>
+#include <coap/coap.h>
 
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
@@ -137,8 +135,8 @@ static bool gRASetInfo = false;
 #endif
 OCDeviceEntityHandler defaultDeviceHandler;
 void* defaultDeviceHandlerCallbackParameter = NULL;
-static const char COAP_TCP[] = "coap+tcp:";
-static const char COAPS_TCP[] = "coaps+tcp:";
+static const char COAP_TCP_SCHEME[] = "coap+tcp:";
+static const char COAPS_TCP_SCHEME[] = "coaps+tcp:";
 static const char CORESPEC[] = "core";
 
 //-----------------------------------------------------------------------------
@@ -2453,8 +2451,8 @@ static OCStackResult ParseRequestUri(const char *fullUri,
     bool istcp = false;
     if (prefixLen)
     {
-        if (((prefixLen == sizeof(COAP_TCP) - 1) && (!strncmp(fullUri, COAP_TCP, prefixLen)))
-        || ((prefixLen == sizeof(COAPS_TCP) - 1) && (!strncmp(fullUri, COAPS_TCP, prefixLen))))
+        if (((prefixLen == sizeof(COAP_TCP_SCHEME) - 1) && (!strncmp(fullUri, COAP_TCP_SCHEME, prefixLen)))
+        || ((prefixLen == sizeof(COAPS_TCP_SCHEME) - 1) && (!strncmp(fullUri, COAPS_TCP_SCHEME, prefixLen))))
         {
             istcp = true;
         }
diff --git a/run.bat b/run.bat
index cac279d..1856907 100644 (file)
--- a/run.bat
+++ b/run.bat
@@ -95,6 +95,7 @@ if "!CURRENT_ARG!"=="server" (
   echo   TARGET_OS=%TARGET_OS%
   echo   TARGET_ARCH=%TARGET_ARCH%
   echo   SECURED=%SECURED%
+  echo   TEST=%TEST%
   echo   LOGGING=%LOGGING%
   echo   WITH_RD=%WITH_RD%
   echo   ROUTING=%ROUTING%