}
#ifdef WITH_TCP
else if(coap_tcp == transport && (pdu->hdr->coap_hdr_tcp_t.token +
- pdu->hdr->coap_hdr_tcp_t.token_length
+ ((pdu->hdr->coap_hdr_tcp_t.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.token_length;
+ ((pdu->hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f);
return (*opt == COAP_PAYLOAD_START) ? NULL : opt;
}
#endif
{
#ifdef WITH_TCP
case coap_tcp:
- token_length = pdu->hdr->coap_hdr_tcp_t.token_length;
+ token_length = (pdu->hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f;
headerSize = COAP_TCP_HEADER_NO_FIELD;
break;
case coap_tcp_8bit:
- token_length = pdu->hdr->coap_hdr_tcp_t.token_length;
+ token_length = (pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0]) & 0x0f;
headerSize = COAP_TCP_HEADER_8_BIT;
break;
case coap_tcp_16bit:
- token_length = pdu->hdr->coap_hdr_tcp_t.token_length;
+ token_length = (pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0]) & 0x0f;
headerSize = COAP_TCP_HEADER_16_BIT;
break;
case coap_tcp_32bit:
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_t.header_data[0] = 0;
+ pdu->hdr->coap_hdr_tcp_t.header_data[1] = code;
break;
case coap_tcp_8bit:
- pdu->hdr->coap_hdr_tcp_8bit_t.message_length = COAP_TCP_LENGTH_FIELD_NUM_8_BIT;
- pdu->hdr->coap_hdr_tcp_8bit_t.length_byte = 0;
- pdu->hdr->coap_hdr_tcp_8bit_t.code = code;
+ 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;
break;
case coap_tcp_16bit:
pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_16_BIT << 4;
switch(transport)
{
case coap_tcp:
- pdu->hdr->coap_hdr_tcp_t.message_length = length;
+ pdu->hdr->coap_hdr_tcp_t.header_data[0] = length << 4;
break;
case coap_tcp_8bit:
if (length > COAP_TCP_LENGTH_FIELD_8_BIT)
{
- pdu->hdr->coap_hdr_tcp_8bit_t.length_byte =
+ pdu->hdr->coap_hdr_tcp_8bit_t.header_data[1] =
length - COAP_TCP_LENGTH_FIELD_8_BIT;
}
break;
switch(transport)
{
case coap_tcp:
- length = pdu->hdr->coap_hdr_tcp_t.message_length;
+ length = pdu->hdr->coap_hdr_tcp_t.header_data[0] >> 4;
break;
case coap_tcp_8bit:
- length = pdu->hdr->coap_hdr_tcp_8bit_t.length_byte + COAP_TCP_LENGTH_FIELD_8_BIT;
+ length = pdu->hdr->coap_hdr_tcp_8bit_t.header_data[1] + COAP_TCP_LENGTH_FIELD_8_BIT;
break;
case coap_tcp_16bit:
length_field_data =
break;
#ifdef WITH_TCP
case coap_tcp:
- pdu->hdr->coap_hdr_tcp_t.code = COAP_RESPONSE_CODE(code);
+ pdu->hdr->coap_hdr_tcp_t.header_data[1] = COAP_RESPONSE_CODE(code);
break;
case coap_tcp_8bit:
- pdu->hdr->coap_hdr_tcp_8bit_t.code = COAP_RESPONSE_CODE(code);
+ pdu->hdr->coap_hdr_tcp_8bit_t.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);
break;
#ifdef WITH_TCP
case coap_tcp:
- code = pdu->hdr->coap_hdr_tcp_t.code;
+ code = pdu->hdr->coap_hdr_tcp_t.header_data[1];
break;
case coap_tcp_8bit:
- code = pdu->hdr->coap_hdr_tcp_8bit_t.code;
+ code = pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2];
break;
case coap_tcp_16bit:
code = pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3];
break;
#ifdef WITH_TCP
case coap_tcp:
- pdu->hdr->coap_hdr_tcp_t.token_length = len;
+ 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;
pdu->length = len + COAP_TCP_HEADER_NO_FIELD;
break;
case coap_tcp_8bit:
- pdu->hdr->coap_hdr_tcp_8bit_t.token_length = len;
+ 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;
pdu->length = len + COAP_TCP_HEADER_8_BIT;
break;
break;
#ifdef WITH_TCP
case coap_tcp:
- *token_length = pdu_hdr->coap_hdr_tcp_t.token_length;
+ *token_length = (pdu_hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f;
*token = (unsigned char *)pdu_hdr->coap_hdr_tcp_t.token;
break;
case coap_tcp_8bit:
- *token_length = pdu_hdr->coap_hdr_tcp_8bit_t.token_length;
+ *token_length = (pdu_hdr->coap_hdr_tcp_8bit_t.header_data[0]) & 0x0f;
*token = (unsigned char *)pdu_hdr->coap_hdr_tcp_8bit_t.token;
break;
case coap_tcp_16bit:
case coap_udp:
break;
case coap_tcp:
- pdu->hdr->coap_hdr_tcp_t.message_length = data[0] >> 4;
- pdu->hdr->coap_hdr_tcp_t.token_length = data[0] & 0x0f;
- pdu->hdr->coap_hdr_tcp_t.code = data[1];
- tokenLength = pdu->hdr->coap_hdr_tcp_t.token_length;
+ for (size_t i = 0 ; i < headerSize ; i++)
+ {
+ pdu->hdr->coap_hdr_tcp_t.header_data[i] = data[i];
+ }
+
+ tokenLength = data[0] & 0x0f;
opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_t) + 1) + tokenLength;
break;
case coap_tcp_8bit:
- pdu->hdr->coap_hdr_tcp_8bit_t.message_length = data[0] >> 4;
- pdu->hdr->coap_hdr_tcp_8bit_t.token_length = data[0] & 0x0f;
- pdu->hdr->coap_hdr_tcp_8bit_t.length_byte = data[1];
- pdu->hdr->coap_hdr_tcp_8bit_t.code = data[2];
- tokenLength = pdu->hdr->coap_hdr_tcp_8bit_t.token_length;
+ for (size_t i = 0 ; i < headerSize ; i++)
+ {
+ pdu->hdr->coap_hdr_tcp_8bit_t.header_data[i] = data[i];
+ }
+
+ tokenLength = data[0] & 0x0f;
opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_8bit_t))
+ tokenLength + COAP_TCP_HEADER_8_BIT;
break;
unsigned char token[]; /* the actual token, if any */
} coap_hdr_udp_t;
-
struct
{
- unsigned int message_length :4; /* length of message */
- unsigned int token_length :4; /* length of Token */
- unsigned int code :8; /* request method (value 1--10) or response code (value 40-255) */
+ unsigned char header_data[COAP_TCP_HEADER_NO_FIELD];
unsigned char token[]; /* the actual token, if any */
} coap_hdr_tcp_t;
struct
{
- unsigned int message_length :4; /* length of message */
- unsigned int token_length :4; /* length of Token */
- unsigned int length_byte :8; /* extend length of message */
- unsigned int code :8; /* request method (value 1--10) or response code (value 40-255) */
+ unsigned char header_data[COAP_TCP_HEADER_8_BIT];
unsigned char token[]; /* the actual token, if any */
} coap_hdr_tcp_8bit_t;
struct
{
- unsigned int message_length :4; /* length of message */
- unsigned int token_length :4; /* length of Token */
- unsigned short length_byte :16; /* extend length of message */
- unsigned int code :8; /* request method (value 1--10) or response code (value 40-255) */
+ unsigned char header_data[COAP_TCP_HEADER_16_BIT];
unsigned char token[]; /* the actual token, if any */
} coap_hdr_tcp_16bit_t;
struct
{
- unsigned int token_length :4; /* length of Token */
- unsigned int message_length :4; /* length of message */
- unsigned int code :8; /* request method (value 1--10) or response code (value 40-255) */
+ unsigned char header_data[COAP_TCP_HEADER_NO_FIELD];
unsigned char token[]; /* the actual token, if any */
} coap_hdr_tcp_t;
struct
{
- unsigned int token_length :4; /* length of Token */
- unsigned int message_length :4; /* length of message */
- unsigned int length_byte :8; /* extend length of message */
- unsigned int code :8; /* request method (value 1--10) or response code (value 40-255) */
+ unsigned char header_data[COAP_TCP_HEADER_8_BIT];
unsigned char token[]; /* the actual token, if any */
} coap_hdr_tcp_8bit_t;