Renamed CoAP transaction ID (tid) to message ID (mid).

This commit is contained in:
Matthias Kovatsch 2012-01-28 19:21:13 +01:00
parent bca4d56eec
commit a4589ee9da
7 changed files with 38 additions and 38 deletions

View file

@ -102,7 +102,7 @@ handle_incoming_data(void)
/*TODO duplicates suppression, if required */
PRINTF(" Parsed: v %u, t %u, oc %u, c %u, tid %u\n", message->version, message->type, message->option_count, message->code, message->tid);
PRINTF(" Parsed: v %u, t %u, oc %u, c %u, mid %u\n", message->version, message->type, message->option_count, message->code, message->mid);
PRINTF(" URL: %.*s\n", message->uri_path_len, message->uri_path);
PRINTF(" Payload: %.*s\n", message->payload_len, message->payload);
@ -110,7 +110,7 @@ handle_incoming_data(void)
if (message->code >= COAP_GET && message->code <= COAP_DELETE)
{
/* Use transaction buffer for response to confirmable request. */
if ( (transaction = coap_new_transaction(message->tid, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport)) )
if ( (transaction = coap_new_transaction(message->mid, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport)) )
{
static uint32_t block_num = 0;
static uint16_t block_size = REST_MAX_CHUNK_SIZE;
@ -121,12 +121,12 @@ handle_incoming_data(void)
if (message->type==COAP_TYPE_CON)
{
/* Reliable CON requests are answered with an ACK. */
coap_init_message(response, COAP_TYPE_ACK, CONTENT_2_05, message->tid);
coap_init_message(response, COAP_TYPE_ACK, CONTENT_2_05, message->mid);
}
else
{
/* Unreliable NON requests are answered with a NON as well. */
coap_init_message(response, COAP_TYPE_NON, CONTENT_2_05, coap_get_tid());
coap_init_message(response, COAP_TYPE_NON, CONTENT_2_05, coap_get_mid());
}
/* resource handlers must take care of different handling (e.g., TOKEN_OPTION_REQUIRED_240) */
@ -228,7 +228,7 @@ handle_incoming_data(void)
}
}
if ( (transaction = coap_get_transaction_by_tid(message->tid)) )
if ( (transaction = coap_get_transaction_by_mid(message->mid)) )
{
/* Free transaction memory before callback, as it may create a new transaction. */
restful_response_handler callback = transaction->callback;
@ -258,7 +258,7 @@ handle_incoming_data(void)
coap_error_code = INTERNAL_SERVER_ERROR_5_00;
}
/* Reuse input buffer for error message. */
coap_init_message(message, COAP_TYPE_ACK, coap_error_code, message->tid);
coap_init_message(message, COAP_TYPE_ACK, coap_error_code, message->mid);
coap_set_payload(message, coap_error_message, strlen(coap_error_message));
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata));
}
@ -462,8 +462,8 @@ PT_THREAD(coap_blocking_request(struct request_state_t *state, process_event_t e
block_error = 0;
do {
request->tid = coap_get_tid();
if ((state->transaction = coap_new_transaction(request->tid, remote_ipaddr, remote_port)))
request->mid = coap_get_mid();
if ((state->transaction = coap_new_transaction(request->mid, remote_ipaddr, remote_port)))
{
state->transaction->callback = blocking_request_callback;
state->transaction->callback_data = state;
@ -476,7 +476,7 @@ PT_THREAD(coap_blocking_request(struct request_state_t *state, process_event_t e
state->transaction->packet_len = coap_serialize_message(request, state->transaction->packet);
coap_send_transaction(state->transaction);
PRINTF("Requested #%lu (TID %u)\n", state->block_num, request->tid);
PRINTF("Requested #%lu (MID %u)\n", state->block_num, request->mid);
PT_YIELD_UNTIL(&state->pt, ev == PROCESS_EVENT_POLL);

View file

@ -154,7 +154,7 @@ coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payl
/*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */
if ( (transaction = coap_new_transaction(coap_get_tid(), &obs->addr, obs->port)) )
if ( (transaction = coap_new_transaction(coap_get_mid(), &obs->addr, obs->port)) )
{
/* Use CON to check whether client is still there/interested after COAP_OBSERVING_REFRESH_INTERVAL. */
if (stimer_expired(&obs->refresh_timer))
@ -166,7 +166,7 @@ coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payl
/* prepare response */
coap_packet_t push[1]; /* This way the packet can be treated as pointer as usual. */
coap_init_message(push, (coap_message_type_t)type, CONTENT_2_05, transaction->tid );
coap_init_message(push, (coap_message_type_t)type, CONTENT_2_05, transaction->mid );
coap_set_header_observe(push, observe);
coap_set_header_token(push, obs->token, obs->token_len);
coap_set_payload(push, payload, payload_len);

View file

@ -62,11 +62,11 @@ void coap_separate_handler(resource_t *resource, void *request, void *response)
/* send separate ACK. */
coap_packet_t ack[1];
/* ACK with empty code (0) */
coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->tid);
coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);
/* Should only overwrite Header which is already parsed to request. */
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, (uip_appdata + uip_ext_len), coap_serialize_message(ack, (uip_appdata + uip_ext_len)));
/* Change response to separate response. */
coap_res->type = COAP_TYPE_CON;
coap_res->tid = coap_get_tid();
coap_res->mid = coap_get_mid();
}

View file

@ -75,13 +75,13 @@ coap_register_as_transaction_handler()
}
coap_transaction_t *
coap_new_transaction(uint16_t tid, uip_ipaddr_t *addr, uint16_t port)
coap_new_transaction(uint16_t mid, uip_ipaddr_t *addr, uint16_t port)
{
coap_transaction_t *t = memb_alloc(&transactions_memb);
if (t)
{
t->tid = tid;
t->mid = mid;
t->retrans_counter = 0;
/* save client address */
@ -95,7 +95,7 @@ coap_new_transaction(uint16_t tid, uip_ipaddr_t *addr, uint16_t port)
void
coap_send_transaction(coap_transaction_t *t)
{
PRINTF("Sending transaction %u\n", t->tid);
PRINTF("Sending transaction %u\n", t->mid);
coap_send_message(&t->addr, t->port, t->packet, t->packet_len);
@ -103,7 +103,7 @@ coap_send_transaction(coap_transaction_t *t)
{
if (t->retrans_counter<COAP_MAX_RETRANSMIT)
{
PRINTF("Keeping transaction %u\n", t->tid);
PRINTF("Keeping transaction %u\n", t->mid);
if (t->retrans_counter==0)
{
@ -154,7 +154,7 @@ coap_clear_transaction(coap_transaction_t *t)
{
if (t)
{
PRINTF("Freeing transaction %u: %p\n", t->tid, t);
PRINTF("Freeing transaction %u: %p\n", t->mid, t);
etimer_stop(&t->retrans_timer);
list_remove(transactions_list, t);
@ -163,15 +163,15 @@ coap_clear_transaction(coap_transaction_t *t)
}
coap_transaction_t *
coap_get_transaction_by_tid(uint16_t tid)
coap_get_transaction_by_mid(uint16_t mid)
{
coap_transaction_t *t = NULL;
for (t = (coap_transaction_t*)list_head(transactions_list); t; t = t->next)
{
if (t->tid==tid)
if (t->mid==mid)
{
PRINTF("Found transaction for TID %u: %p\n", t->tid, t);
PRINTF("Found transaction for MID %u: %p\n", t->mid, t);
return t;
}
}
@ -188,7 +188,7 @@ coap_check_transactions()
if (etimer_expired(&t->retrans_timer))
{
++(t->retrans_counter);
PRINTF("Retransmitting %u (%u)\n", t->tid, t->retrans_counter);
PRINTF("Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
coap_send_transaction(t);
}
}

View file

@ -52,7 +52,7 @@
typedef struct coap_transaction {
struct coap_transaction *next; /* for LIST */
uint16_t tid;
uint16_t mid;
struct etimer retrans_timer;
uint8_t retrans_counter;
@ -68,10 +68,10 @@ typedef struct coap_transaction {
void coap_register_as_transaction_handler();
coap_transaction_t *coap_new_transaction(uint16_t tid, uip_ipaddr_t *addr, uint16_t port);
coap_transaction_t *coap_new_transaction(uint16_t mid, uip_ipaddr_t *addr, uint16_t port);
void coap_send_transaction(coap_transaction_t *t);
void coap_clear_transaction(coap_transaction_t *t);
coap_transaction_t *coap_get_transaction_by_tid(uint16_t tid);
coap_transaction_t *coap_get_transaction_by_mid(uint16_t mid);
void coap_check_transactions();

View file

@ -61,7 +61,7 @@
/*- Variables -----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
static struct uip_udp_conn *udp_conn = NULL;
static uint16_t current_tid = 0;
static uint16_t current_mid = 0;
coap_status_t coap_error_code = NO_ERROR;
char *coap_error_message = "";
@ -274,19 +274,19 @@ coap_init_connection(uint16_t port)
PRINTF("Listening on port %u\n", uip_ntohs(udp_conn->lport));
/* Initialize transaction ID. */
current_tid = random_rand();
current_mid = random_rand();
}
/*-----------------------------------------------------------------------------------*/
uint16_t
coap_get_tid()
coap_get_mid()
{
return ++current_tid;
return ++current_mid;
}
/*-----------------------------------------------------------------------------------*/
/*- MEASSAGE PROCESSING -------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
void
coap_init_message(void *packet, coap_message_type_t type, uint8_t code, uint16_t tid)
coap_init_message(void *packet, coap_message_type_t type, uint8_t code, uint16_t mid)
{
coap_packet_t *const coap_pkt = (coap_packet_t *) packet;
@ -295,7 +295,7 @@ coap_init_message(void *packet, coap_message_type_t type, uint8_t code, uint16_t
coap_pkt->type = type;
coap_pkt->code = code;
coap_pkt->tid = tid;
coap_pkt->mid = mid;
}
/*-----------------------------------------------------------------------------------*/
size_t
@ -508,8 +508,8 @@ coap_serialize_message(void *packet, uint8_t *buffer)
coap_pkt->buffer[0] |= COAP_HEADER_TYPE_MASK & (coap_pkt->type)<<COAP_HEADER_TYPE_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_OPTION_COUNT_MASK & (coap_pkt->option_count)<<COAP_HEADER_OPTION_COUNT_POSITION;
coap_pkt->buffer[1] = coap_pkt->code;
coap_pkt->buffer[2] = 0xFF & (coap_pkt->tid)>>8;
coap_pkt->buffer[3] = 0xFF & coap_pkt->tid;
coap_pkt->buffer[2] = 0xFF & (coap_pkt->mid)>>8;
coap_pkt->buffer[3] = 0xFF & coap_pkt->mid;
PRINTF("-Done %u options, header len %u, payload len %u-\n", coap_pkt->option_count, option - buffer, coap_pkt->payload_len);
@ -547,7 +547,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
coap_pkt->type = (COAP_HEADER_TYPE_MASK & coap_pkt->buffer[0])>>COAP_HEADER_TYPE_POSITION;
coap_pkt->option_count = (COAP_HEADER_OPTION_COUNT_MASK & coap_pkt->buffer[0])>>COAP_HEADER_OPTION_COUNT_POSITION;
coap_pkt->code = coap_pkt->buffer[1];
coap_pkt->tid = coap_pkt->buffer[2]<<8 | coap_pkt->buffer[3];
coap_pkt->mid = coap_pkt->buffer[2]<<8 | coap_pkt->buffer[3];
if (coap_pkt->version != 1)
{

View file

@ -54,7 +54,7 @@
#define COAP_RESPONSE_RANDOM_FACTOR 1.5
#define COAP_MAX_RETRANSMIT 4
#define COAP_HEADER_LEN 4 /* | oc:0xF0 type:0x0C version:0x03 | code | tid:0x00FF | tid:0xFF00 | */
#define COAP_HEADER_LEN 4 /* | oc:0xF0 type:0x0C version:0x03 | code | mid:0x00FF | mid:0xFF00 | */
#define COAP_ETAG_LEN 8 /* The maximum number of bytes for the ETag */
#define COAP_TOKEN_LEN 8 /* The maximum number of bytes for the Token */
#define COAP_MAX_ACCEPT_NUM 2 /* The maximum number of accept preferences to parse/store */
@ -206,7 +206,7 @@ typedef struct {
coap_message_type_t type;
uint8_t option_count;
uint8_t code;
uint16_t tid;
uint16_t mid;
uint32_t options; /* Bitmap to check if option is set */
@ -255,9 +255,9 @@ extern coap_status_t coap_error_code;
extern char *coap_error_message;
void coap_init_connection(uint16_t port);
uint16_t coap_get_tid(void);
uint16_t coap_get_mid(void);
void coap_init_message(void *packet, coap_message_type_t type, uint8_t code, uint16_t tid);
void coap_init_message(void *packet, coap_message_type_t type, uint8_t code, uint16_t mid);
size_t coap_serialize_message(void *packet, uint8_t *buffer);
void coap_send_message(uip_ipaddr_t *addr, uint16_t port, uint8_t *data, uint16_t length);
coap_status_t coap_parse_message(void *request, uint8_t *data, uint16_t data_len);