Contiki 2.5
broadcast.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimeibc Best-effort local area broadcast
8  * @{
9  *
10  * The broadcast module sends packets to all local area neighbors with an a
11  * header that identifies the sender.
12  *
13  * The broadcast module sends a packet to all local neighbors. The
14  * module adds the single-hop sender address as a packet attribute to
15  * outgoing packets. All Rime primitives that need the identity of
16  * the sender in the outgoing packets use the broadcast primitive,
17  * either directly or indirectly through any of the other
18  * communication primitives that are based on the broadcast primitive.
19  *
20  * \section channels Channels
21  *
22  * The broadcast module uses 1 channel.
23  *
24  */
25 
26 /*
27  * Copyright (c) 2006, Swedish Institute of Computer Science.
28  * All rights reserved.
29  *
30  * Redistribution and use in source and binary forms, with or without
31  * modification, are permitted provided that the following conditions
32  * are met:
33  * 1. Redistributions of source code must retain the above copyright
34  * notice, this list of conditions and the following disclaimer.
35  * 2. Redistributions in binary form must reproduce the above copyright
36  * notice, this list of conditions and the following disclaimer in the
37  * documentation and/or other materials provided with the distribution.
38  * 3. Neither the name of the Institute nor the names of its contributors
39  * may be used to endorse or promote products derived from this software
40  * without specific prior written permission.
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
43  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
46  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  *
54  * This file is part of the Contiki operating system.
55  *
56  * $Id: broadcast.h,v 1.5 2010/02/23 18:38:05 adamdunkels Exp $
57  */
58 
59 /**
60  * \file
61  * Header file for identified best-effort local area broadcast
62  * \author
63  * Adam Dunkels <adam@sics.se>
64  */
65 
66 #ifndef __BROADCAST_H__
67 #define __BROADCAST_H__
68 
69 #include "net/rime/abc.h"
70 #include "net/rime/rimeaddr.h"
71 
72 struct broadcast_conn;
73 
74 #define BROADCAST_ATTRIBUTES { PACKETBUF_ADDR_SENDER, PACKETBUF_ADDRSIZE }, \
75  ABC_ATTRIBUTES
76 
77 /**
78  * \brief Callback structure for broadcast
79  *
80  */
82  /** Called when a packet has been received by the broadcast module. */
83  void (* recv)(struct broadcast_conn *ptr, const rimeaddr_t *sender);
84  void (* sent)(struct broadcast_conn *ptr, int status, int num_tx);
85 };
86 
87 struct broadcast_conn {
88  struct abc_conn c;
89  const struct broadcast_callbacks *u;
90 };
91 
92 /**
93  * \brief Set up an identified best-effort broadcast connection
94  * \param c A pointer to a struct broadcast_conn
95  * \param channel The channel on which the connection will operate
96  * \param u A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received
97  *
98  * This function sets up a broadcast connection on the
99  * specified channel. The caller must have allocated the
100  * memory for the struct broadcast_conn, usually by declaring it
101  * as a static variable.
102  *
103  * The struct broadcast_callbacks pointer must point to a structure
104  * containing a pointer to a function that will be called
105  * when a packet arrives on the channel.
106  *
107  */
108 void broadcast_open(struct broadcast_conn *c, uint16_t channel,
109  const struct broadcast_callbacks *u);
110 
111 /**
112  * \brief Close a broadcast connection
113  * \param c A pointer to a struct broadcast_conn
114  *
115  * This function closes a broadcast connection that has
116  * previously been opened with broadcast_open().
117  *
118  * This function typically is called as an exit handler.
119  *
120  */
121 void broadcast_close(struct broadcast_conn *c);
122 
123 /**
124  * \brief Send an identified best-effort broadcast packet
125  * \param c The broadcast connection on which the packet should be sent
126  * \retval Non-zero if the packet could be sent, zero otherwise
127  *
128  * This function sends an identified best-effort broadcast
129  * packet. The packet must be present in the packetbuf
130  * before this function is called.
131  *
132  * The parameter c must point to a broadcast connection that
133  * must have previously been set up with broadcast_open().
134  *
135  */
136 int broadcast_send(struct broadcast_conn *c);
137 
138 #endif /* __BROADCAST_H__ */
139 /** @} */
140 /** @} */