libcoap_env = env.Clone()
target_os = env.get('TARGET_OS')
+ca_transport = env.get('TARGET_TRANSPORT')
# As in the source code(C) includes arduino Time library head file(C++)
# It requires compile the .c with g++
if target_os == 'arduino':
libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
'-fdata-sections', '-fno-exceptions'])
+if target_os == 'linux':
+ if (('CI' in ca_transport) or ('ALL' in ca_transport)):
+ libcoap_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
+
if target_os == 'android':
libcoap_env.AppendUnique(LIBS = ['log'])
libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
libcoap_env.InstallTarget([libcoap], 'libcoap')
-libcoap_env.UserInstallTargetLib([libcoap], 'libcoap')
+libcoap_env.UserInstallTargetLib([libcoap], 'libcoap')
\ No newline at end of file
pdu->hdr->coap_hdr_udp_t.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.token_length
< (unsigned char *) pdu->hdr + pdu->length))
pdu->hdr->coap_hdr_tcp_t.token_length;
return (*opt == COAP_PAYLOAD_START) ? NULL : opt;
}
+#endif
}
else
return NULL;
switch(transport)
{
+#ifdef WITH_TCP
case coap_tcp:
case coap_tcp_8bit:
case coap_tcp_16bit:
token_length = pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] & 0x0f;
headerSize = sizeof(pdu->hdr->coap_hdr_tcp_32bit_t);
break;
+#endif
default:
token_length = pdu->hdr->coap_hdr_udp_t.token_length;
headerSize = sizeof(pdu->hdr->coap_hdr_udp_t);
return NULL;
}
}
+#ifdef WITH_TCP
else
{
if ((unsigned char *) &(pdu->hdr->coap_hdr_tcp_t) + pdu->length <= oi->next_option)
return NULL;
}
}
+#endif
assert((headerSize + token_length) <= pdu->length);
return l + length;
}
-
/* data is NULL unless explicitly set by coap_add_data() */
pdu->length = sizeof(pdu->hdr->coap_hdr_udp_t);
}
+#ifdef WITH_TCP
else
{
/* data is NULL unless explicitly set by coap_add_data() */
pdu->length = length;
}
+#endif
}
#ifdef WITH_LWIP
case coap_udp:
length = sizeof(pdu->hdr->coap_hdr_udp_t);
break;
+#ifdef WITH_TCP
case coap_tcp:
length = COAP_TCP_HEADER_NO_FIELD;
break;
case coap_tcp_32bit:
length = COAP_TCP_HEADER_32_BIT;
break;
+#endif
default:
debug("it has wrong type\n");
}
pdu->hdr->coap_hdr_udp_t.type = type;
pdu->hdr->coap_hdr_udp_t.code = code;
break;
+#ifdef WITH_TCP
case coap_tcp:
pdu->hdr->coap_hdr_tcp_t.message_length = 0;
pdu->hdr->coap_hdr_tcp_t.code = code;
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;
break;
+#endif
default:
debug("it has wrong type\n");
}
#endif
}
+#ifdef WITH_TCP
coap_transport_type coap_get_tcp_header_type_from_size(unsigned int size)
{
if (COAP_TCP_LENGTH_LIMIT_8_BIT < size && COAP_TCP_LENGTH_LIMIT_16_BIT >= size)
return length;
}
+#endif
void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport, unsigned int code)
{
case coap_udp:
pdu->hdr->coap_hdr_udp_t.code = COAP_RESPONSE_CODE(code);
break;
+#ifdef WITH_TCP
case coap_tcp:
pdu->hdr->coap_hdr_tcp_t.code = COAP_RESPONSE_CODE(code);
break;
case coap_tcp_32bit:
pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5] = COAP_RESPONSE_CODE(code);
break;
+#endif
default:
debug("it has wrong type\n");
}
case coap_udp:
code = pdu->hdr->coap_hdr_udp_t.code;
break;
+#ifdef WITH_TCP
case coap_tcp:
code = pdu->hdr->coap_hdr_tcp_t.code;
break;
case coap_tcp_32bit:
code = pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5];
break;
+#endif
default:
debug("it has wrong type\n");
}
token = pdu->hdr->coap_hdr_udp_t.token;
pdu->length = HEADERLENGTH;
break;
+#ifdef WITH_TCP
case coap_tcp:
pdu->hdr->coap_hdr_tcp_t.token_length = len;
token = pdu->hdr->coap_hdr_tcp_t.token;
token = pdu->hdr->coap_hdr_tcp_32bit_t.token;
pdu->length = len + COAP_TCP_HEADER_32_BIT;
break;
+#endif
default:
debug("it has wrong type\n");
}
*token_length = pdu_hdr->coap_hdr_udp_t.token_length;
*token = (unsigned char *)pdu_hdr->coap_hdr_udp_t.token;
break;
+#ifdef WITH_TCP
case coap_tcp:
*token_length = pdu_hdr->coap_hdr_tcp_t.token_length;
*token = (unsigned char *)pdu_hdr->coap_hdr_tcp_t.token;
*token_length = (pdu_hdr->coap_hdr_tcp_32bit_t.header_data[0]) & 0x0f;
*token = (unsigned char *)pdu_hdr->coap_hdr_tcp_32bit_t.token;
break;
+#endif
default:
debug("it has wrong type\n");
}
switch(transport)
{
+#ifdef WITH_TCP
case coap_tcp:
opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_t) + pdu->length;
break;
case coap_tcp_32bit:
opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_32bit_t) + pdu->length;
break;
+#endif
default:
opt = (unsigned char *) &(pdu->hdr->coap_hdr_udp_t) + pdu->length;
break;
unsigned int headerSize = 0;
switch(transport)
{
+#ifdef WITH_TCP
case coap_tcp:
headerSize = COAP_TCP_HEADER_NO_FIELD;
break;
case coap_tcp_32bit:
headerSize = COAP_TCP_HEADER_32_BIT;
break;
+#endif
default:
headerSize = sizeof(pdu->hdr->coap_hdr_udp_t);
break;
coap_opt_t *opt = NULL;
unsigned int tokenLength = 0;
+#ifdef WITH_TCP
switch(transport)
{
case coap_tcp:
default:
debug("it has wrong type\n");
}
+#endif
pdu->length = length;
if (coap_udp == transport)
length -= (tokenLength + headerSize);
opt = (unsigned char *) (&(pdu->hdr->coap_hdr_udp_t) + 1) + tokenLength;
}
+#ifdef WITH_TCP
else // common for tcp header setting
{
pdu->data = NULL;
/* skip header + token */
length -= (tokenLength + headerSize);
}
+#endif
while (length && *opt != COAP_PAYLOAD_START)
{
#ifdef WITH_ARDUINO
#define COAP_MAX_PDU_SIZE 320 /* maximum size of a CoAP PDU for embedded platforms*/
#else
+#ifdef WITH_TCP
+#define COAP_MAX_PDU_SIZE 65536 /* maximum size of a CoAP PDU for big platforms*/
+#else
#define COAP_MAX_PDU_SIZE 1400 /* maximum size of a CoAP PDU for big platforms*/
#endif
+#endif
#endif /* COAP_MAX_PDU_SIZE */
#define COAP_DEFAULT_VERSION 1 /* version of CoAP supported */
struct
{
- unsigned char header_data[6]; /* coap header which 32bit payload length*/
+ unsigned char header_data[6];
unsigned char token[]; /* the actual token, if any */
} coap_hdr_tcp_32bit_t;
int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
coap_transport_type transport);
+#ifdef WITH_TCP
/**
* Get transport type of coap header for coap over tcp through payload size.
*
* @return length value of init byte.
*/
unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transport);
+#endif
/**
* Add code in coap header.
/**
* 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
+ * 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.