From: jihwan.seo Date: Fri, 2 Oct 2015 04:42:15 +0000 (+0900) Subject: modified some code to make tcp header. X-Git-Tag: 1.0.0~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=24b2526a8f611d0cfc5437017cdeea9e9fbdd1f4;p=contrib%2Fiotivity.git modified some code to make tcp header. I have modified for tcp header which has 0 ~ 12 length or 8bit message length. since previous code has potential issue for byte ordering. Change-Id: Id2f63608442ccf85558c61dbfd631a01f59ad8b9 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/3401 Tested-by: jenkins-iotivity Reviewed-by: Patrick Lankswert (cherry picked from commit 27f18c55a2d55c5f9b3e3006d5ca8845f27d69a5) Reviewed-on: https://gerrit.iotivity.org/gerrit/3519 --- diff --git a/resource/csdk/connectivity/lib/libcoap-4.1.1/option.c b/resource/csdk/connectivity/lib/libcoap-4.1.1/option.c index 67272d9..8cf2ae6 100644 --- a/resource/csdk/connectivity/lib/libcoap-4.1.1/option.c +++ b/resource/csdk/connectivity/lib/libcoap-4.1.1/option.c @@ -35,11 +35,11 @@ options_start(coap_pdu_t *pdu, coap_transport_type transport) } #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 @@ -151,15 +151,15 @@ coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi, { #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: diff --git a/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c b/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c index b5dd712..175394b 100644 --- a/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c +++ b/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c @@ -170,13 +170,12 @@ coap_pdu_init(unsigned char type, unsigned char code, unsigned short id, 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; @@ -291,12 +290,12 @@ void coap_add_length(const coap_pdu_t *pdu, coap_transport_type transport, unsig 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; @@ -358,10 +357,10 @@ unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transpor 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 = @@ -481,10 +480,10 @@ void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport, unsigne 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); @@ -510,10 +509,10 @@ unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_type transport) 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]; @@ -546,12 +545,14 @@ int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data, 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; @@ -598,11 +599,11 @@ void coap_get_token(const coap_hdr_t *pdu_hdr, coap_transport_type transport, 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: @@ -865,18 +866,21 @@ int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu, 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; diff --git a/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.h b/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.h index b8cc1ea..87f6044 100644 --- a/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.h +++ b/resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.h @@ -204,30 +204,21 @@ typedef union 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; @@ -253,18 +244,13 @@ typedef union 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;