Contiki 2.5
stbroadcast.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4 */
5 
6 /**
7  * \defgroup rimestbroadcast Stubborn best-effort local area broadcast
8  * @{
9  *
10  * The stbroadcast module provides stubborn anonymous best-effort local area
11  * broadcast. A message sent with the stbroadcast module is repeated until
12  * either the message is canceled or a new message is sent. Messages
13  * sent with the stbroadcast module are not identified with a sender ID.
14  *
15  * \section channels Channels
16  *
17  * The stbroadcast module uses 1 channel.
18  *
19  */
20 
21 /*
22  * Copyright (c) 2006, Swedish Institute of Computer Science.
23  * All rights reserved.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution.
33  * 3. Neither the name of the Institute nor the names of its contributors
34  * may be used to endorse or promote products derived from this software
35  * without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
38  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
41  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  *
49  * This file is part of the Contiki operating system.
50  *
51  * $Id: stbroadcast.h,v 1.4 2010/06/14 19:19:17 adamdunkels Exp $
52  */
53 
54 /**
55  * \file
56  * Header file for the Rime module Stubborn Anonymous BroadCast (stbroadcast)
57  * \author
58  * Adam Dunkels <adam@sics.se>
59  */
60 
61 #ifndef __STBROADCAST_H__
62 #define __STBROADCAST_H__
63 
64 #include "sys/ctimer.h"
65 
66 #include "net/rime/broadcast.h"
67 #include "net/queuebuf.h"
68 
69 struct stbroadcast_conn;
70 
71 struct stbroadcast_callbacks {
72  void (* recv)(struct stbroadcast_conn *c);
73  void (* sent)(struct stbroadcast_conn *c);
74 };
75 
76 /**
77  * A stbroadcast connection. This is an opaque structure with no user-visible
78  * fields. The stbroadcast_open() function is used for setting up a stbroadcast
79  * connection.
80  */
82  struct broadcast_conn c;
83  struct ctimer t;
84  struct queuebuf *buf;
85  const struct stbroadcast_callbacks *u;
86 };
87 
88 
89 /**
90  * \brief Set up a stbroadcast connection.
91  * \param c A pointer to a user-supplied struct stbroadcast variable.
92  * \param channel The Rime channel on which messages should be sent.
93  * \param u Pointer to the upper layer functions that should be used
94  * for this connection.
95  *
96  * This function sets up a stbroadcast connection on the
97  * specified channel. No checks are made if the channel is
98  * currently used by another connection.
99  *
100  * This function must be called before any other function
101  * that operates on the connection is called.
102  *
103  */
104 void stbroadcast_open(struct stbroadcast_conn *c, uint16_t channel,
105  const struct stbroadcast_callbacks *u);
106 void stbroadcast_close(struct stbroadcast_conn *c);
107 
108 /**
109  * \brief Send a stubborn message.
110  * \param c A stbroadcast connection that must have been previously set up
111  * with stbroadcast_open()
112  * \param t The time between message retransmissions.
113  *
114  * This function sends a message from the Rime buffer. The
115  * message must have been previously constructed in the
116  * Rime buffer. When this function returns, the message
117  * has been copied into a queue buffer.
118  *
119  * If another message has previously been sent, the old
120  * message is canceled.
121  *
122  */
123 int stbroadcast_send_stubborn(struct stbroadcast_conn *c, clock_time_t t);
124 
125 /**
126  * \brief Cancel the current stubborn message.
127  * \param c A stbroadcast connection that must have been previously set up
128  * with stbroadcast_open()
129  *
130  * This function cancels a stubborn message that has
131  * previously been sent with the stbroadcast_send_stubborn()
132  * function.
133  *
134  */
135 void stbroadcast_cancel(struct stbroadcast_conn *c);
136 
137 
138 
139 /**
140  * \brief Set the retransmission time of the current stubborn message.
141  * \param c A stbroadcast connection that must have been previously set up
142  * with stbroadcast_open()
143  * \param t The new time between message retransmissions.
144  *
145  * This function sets the retransmission timer for the
146  * current stubborn message to a new value.
147  *
148  */
149 void stbroadcast_set_timer(struct stbroadcast_conn *c, clock_time_t t);
150 
151 #endif /* __STBROADCAST_H__ */
152 
153 /** @} */
154 /** @} */