Contiki 3.x
er-coap-transactions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  */
31 
32 /**
33  * \file
34  * CoAP module for reliable transport
35  * \author
36  * Matthias Kovatsch <kovatsch@inf.ethz.ch>
37  */
38 
39 #ifndef COAP_TRANSACTIONS_H_
40 #define COAP_TRANSACTIONS_H_
41 
42 #include "er-coap.h"
43 
44 /*
45  * Modulo mask (thus +1) for a random number to get the tick number for the random
46  * retransmission time between COAP_RESPONSE_TIMEOUT and COAP_RESPONSE_TIMEOUT*COAP_RESPONSE_RANDOM_FACTOR.
47  */
48 #define COAP_RESPONSE_TIMEOUT_TICKS (CLOCK_SECOND * COAP_RESPONSE_TIMEOUT)
49 #define COAP_RESPONSE_TIMEOUT_BACKOFF_MASK (long)((CLOCK_SECOND * COAP_RESPONSE_TIMEOUT * ((float)COAP_RESPONSE_RANDOM_FACTOR - 1.0)) + 0.5) + 1
50 
51 /* container for transactions with message buffer and retransmission info */
52 typedef struct coap_transaction {
53  struct coap_transaction *next; /* for LIST */
54 
55  uint16_t mid;
56  struct etimer retrans_timer;
57  uint8_t retrans_counter;
58 
59  uip_ipaddr_t addr;
60  uint16_t port;
61 
62  restful_response_handler callback;
63  void *callback_data;
64 
65  uint16_t packet_len;
66  uint8_t packet[COAP_MAX_PACKET_SIZE + 1]; /* +1 for the terminating '\0' which will not be sent
67  * Use snprintf(buf, len+1, "", ...) to completely fill payload */
68 } coap_transaction_t;
69 
70 void coap_register_as_transaction_handler();
71 
72 coap_transaction_t *coap_new_transaction(uint16_t mid, uip_ipaddr_t *addr,
73  uint16_t port);
74 void coap_send_transaction(coap_transaction_t *t);
75 void coap_clear_transaction(coap_transaction_t *t);
76 coap_transaction_t *coap_get_transaction_by_mid(uint16_t mid);
77 
78 void coap_check_transactions();
79 
80 #endif /* COAP_TRANSACTIONS_H_ */
An implementation of the Constrained Application Protocol (RFC).
A timer.
Definition: etimer.h:76