Contiki 3.x
runicast.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
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 /**
34  * \file
35  * Reliable unicast header file
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43  */
44 
45 /**
46  * \defgroup rimerunicast Single-hop reliable unicast
47  * @{
48  *
49  * The reliable single-hop unicast primitive (runicast) reliably sends
50  * a packet to a single-hop neighbor. The runicast primitive uses
51  * acknowledgements and retransmissions to ensure that the neighbor
52  * successfully receives the packet. When the receiver has
53  * acknowledged the packet, the ruc module notifies the sending
54  * application via a callback. The ruc primitive uses the stubborn
55  * single-hop unicast primitive to do retransmissions. Thus, the ruc
56  * primitive does not have to manage the details of setting up timers
57  * and doing retransmissions, but can concentrate on dealing with
58  * acknowledgements.
59  *
60  * The runicast primitive adds two packet attributes: the single-hop
61  * packet type and the single-hop packet ID. The runicast primitive
62  * uses the packet ID attribute as a sequence number for matching
63  * acknowledgement packets to the corresponding data packets.
64  *
65  * The application or protocol that uses the runicast primitive can
66  * specify the maximum number of transmissions that the ruc module
67  * should attempt before the packet times out. If a packet times out,
68  * the application or protocol that sent the packet is notified with a
69  * callback.
70  *
71  *
72  * \section channels Channels
73  *
74  * The runicast module uses 1 channel.
75  *
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 /** @} */
Stubborn unicast header file