Contiki-Inga 3.x
runicast.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimerunicast Single-hop reliable unicast
8  * @{
9  *
10  * The reliable single-hop unicast primitive (runicast) reliably sends
11  * a packet to a single-hop neighbor. The runicast primitive uses
12  * acknowledgements and retransmissions to ensure that the neighbor
13  * successfully receives the packet. When the receiver has
14  * acknowledged the packet, the ruc module notifies the sending
15  * application via a callback. The ruc primitive uses the stubborn
16  * single-hop unicast primitive to do retransmissions. Thus, the ruc
17  * primitive does not have to manage the details of setting up timers
18  * and doing retransmissions, but can concentrate on dealing with
19  * acknowledgements.
20  *
21  * The runicast primitive adds two packet attributes: the single-hop
22  * packet type and the single-hop packet ID. The runicast primitive
23  * uses the packet ID attribute as a sequence number for matching
24  * acknowledgement packets to the corresponding data packets.
25  *
26  * The application or protocol that uses the runicast primitive can
27  * specify the maximum number of transmissions that the ruc module
28  * should attempt before the packet times out. If a packet times out,
29  * the application or protocol that sent the packet is notified with a
30  * callback.
31  *
32  *
33  * \section channels Channels
34  *
35  * The runicast module uses 1 channel.
36  *
37  */
38 
39 /*
40  * Copyright (c) 2006, Swedish Institute of Computer Science.
41  * All rights reserved.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  * notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  * notice, this list of conditions and the following disclaimer in the
50  * documentation and/or other materials provided with the distribution.
51  * 3. Neither the name of the Institute nor the names of its contributors
52  * may be used to endorse or promote products derived from this software
53  * without specific prior written permission.
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65  * SUCH DAMAGE.
66  *
67  * This file is part of the Contiki operating system.
68  *
69  */
70 
71 /**
72  * \file
73  * Reliable unicast header file
74  * \author
75  * Adam Dunkels <adam@sics.se>
76  */
77 
78 #ifndef RUNICAST_H_
79 #define RUNICAST_H_
80 
81 #include "net/rime/stunicast.h"
82 
83 struct runicast_conn;
84 
85 
86 #define RUNICAST_PACKET_ID_BITS 2
87 
88 #define RUNICAST_ATTRIBUTES { PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_BIT }, \
89  { PACKETBUF_ATTR_PACKET_ID, PACKETBUF_ATTR_BIT * RUNICAST_PACKET_ID_BITS }, \
90  STUNICAST_ATTRIBUTES
91 struct runicast_callbacks {
92  void (* recv)(struct runicast_conn *c, const linkaddr_t *from, uint8_t seqno);
93  void (* sent)(struct runicast_conn *c, const linkaddr_t *to, uint8_t retransmissions);
94  void (* timedout)(struct runicast_conn *c, const linkaddr_t *to, uint8_t retransmissions);
95 };
96 
97 struct runicast_conn {
98  struct stunicast_conn c;
99  const struct runicast_callbacks *u;
100  uint8_t sndnxt;
101  uint8_t is_tx;
102  uint8_t rxmit;
103  uint8_t max_rxmit;
104 };
105 
106 void runicast_open(struct runicast_conn *c, uint16_t channel,
107  const struct runicast_callbacks *u);
108 void runicast_close(struct runicast_conn *c);
109 
110 int runicast_send(struct runicast_conn *c, const linkaddr_t *receiver,
111  uint8_t max_retransmissions);
112 
113 uint8_t runicast_is_transmitting(struct runicast_conn *c);
114 
115 #endif /* RUNICAST_H_ */
116 /** @} */
117 /** @} */