Contiki 2.5
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  * $Id: runicast.h,v 1.7 2010/03/19 13:22:08 adamdunkels Exp $
70  */
71 
72 /**
73  * \file
74  * Reliable unicast header file
75  * \author
76  * Adam Dunkels <adam@sics.se>
77  */
78 
79 #ifndef __RUNICAST_H__
80 #define __RUNICAST_H__
81 
82 #include "net/rime/stunicast.h"
83 
84 struct runicast_conn;
85 
86 
87 #define RUNICAST_PACKET_ID_BITS 2
88 
89 #define RUNICAST_ATTRIBUTES { PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_BIT }, \
90  { PACKETBUF_ATTR_PACKET_ID, PACKETBUF_ATTR_BIT * RUNICAST_PACKET_ID_BITS }, \
91  STUNICAST_ATTRIBUTES
92 struct runicast_callbacks {
93  void (* recv)(struct runicast_conn *c, const rimeaddr_t *from, uint8_t seqno);
94  void (* sent)(struct runicast_conn *c, const rimeaddr_t *to, uint8_t retransmissions);
95  void (* timedout)(struct runicast_conn *c, const rimeaddr_t *to, uint8_t retransmissions);
96 };
97 
98 struct runicast_conn {
99  struct stunicast_conn c;
100  const struct runicast_callbacks *u;
101  uint8_t sndnxt;
102  uint8_t is_tx;
103  uint8_t rxmit;
104  uint8_t max_rxmit;
105 };
106 
107 void runicast_open(struct runicast_conn *c, uint16_t channel,
108  const struct runicast_callbacks *u);
109 void runicast_close(struct runicast_conn *c);
110 
111 int runicast_send(struct runicast_conn *c, const rimeaddr_t *receiver,
112  uint8_t max_retransmissions);
113 
114 uint8_t runicast_is_transmitting(struct runicast_conn *c);
115 
116 #endif /* __RUNICAST_H__ */
117 /** @} */
118 /** @} */