diff --git a/include/coap/pdu.h b/include/coap/pdu.h index f6d6f441..57b68d09 100644 --- a/include/coap/pdu.h +++ b/include/coap/pdu.h @@ -155,9 +155,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 #ifdef WORDS_BIGENDIAN diff --git a/src/net.c b/src/net.c index db385fe5..bc8e5f86 100644 --- a/src/net.c +++ b/src/net.c @@ -523,7 +523,7 @@ coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, coap_hash((const unsigned char *)&pdu->hdr->id, sizeof(unsigned short), h); - *id = ((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3]); + *id = (((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3])) & INT_MAX; } coap_tid_t