Contiki 3.x
broadcast.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  * Header file for identified best-effort local area broadcast
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43  */
44 
45 /**
46  * \defgroup rimeibc Best-effort local area broadcast
47  * @{
48  *
49  * The broadcast module sends packets to all local area neighbors with an a
50  * header that identifies the sender.
51  *
52  * The broadcast module sends a packet to all local neighbors. The
53  * module adds the single-hop sender address as a packet attribute to
54  * outgoing packets. All Rime primitives that need the identity of
55  * the sender in the outgoing packets use the broadcast primitive,
56  * either directly or indirectly through any of the other
57  * communication primitives that are based on the broadcast primitive.
58  *
59  * \section channels Channels
60  *
61  * The broadcast module uses 1 channel.
62  *
63  */
64 
65 #ifndef BROADCAST_H_
66 #define BROADCAST_H_
67 
68 #include "net/rime/abc.h"
69 #include "net/linkaddr.h"
70 
71 struct broadcast_conn;
72 
73 #define BROADCAST_ATTRIBUTES { PACKETBUF_ADDR_SENDER, PACKETBUF_ADDRSIZE }, \
74  ABC_ATTRIBUTES
75 
76 /**
77  * \brief Callback structure for broadcast
78  *
79  */
81  /** Called when a packet has been received by the broadcast module. */
82  void (* recv)(struct broadcast_conn *ptr, const linkaddr_t *sender);
83  void (* sent)(struct broadcast_conn *ptr, int status, int num_tx);
84 };
85 
86 struct broadcast_conn {
87  struct abc_conn c;
88  const struct broadcast_callbacks *u;
89 };
90 
91 /**
92  * \brief Set up an identified best-effort broadcast connection
93  * \param c A pointer to a struct broadcast_conn
94  * \param channel The channel on which the connection will operate
95  * \param u A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received
96  *
97  * This function sets up a broadcast connection on the
98  * specified channel. The caller must have allocated the
99  * memory for the struct broadcast_conn, usually by declaring it
100  * as a static variable.
101  *
102  * The struct broadcast_callbacks pointer must point to a structure
103  * containing a pointer to a function that will be called
104  * when a packet arrives on the channel.
105  *
106  */
107 void broadcast_open(struct broadcast_conn *c, uint16_t channel,
108  const struct broadcast_callbacks *u);
109 
110 /**
111  * \brief Close a broadcast connection
112  * \param c A pointer to a struct broadcast_conn
113  *
114  * This function closes a broadcast connection that has
115  * previously been opened with broadcast_open().
116  *
117  * This function typically is called as an exit handler.
118  *
119  */
120 void broadcast_close(struct broadcast_conn *c);
121 
122 /**
123  * \brief Send an identified best-effort broadcast packet
124  * \param c The broadcast connection on which the packet should be sent
125  * \retval Non-zero if the packet could be sent, zero otherwise
126  *
127  * This function sends an identified best-effort broadcast
128  * packet. The packet must be present in the packetbuf
129  * before this function is called.
130  *
131  * The parameter c must point to a broadcast connection that
132  * must have previously been set up with broadcast_open().
133  *
134  */
135 int broadcast_send(struct broadcast_conn *c);
136 
137 #endif /* BROADCAST_H_ */
138 /** @} */
139 /** @} */
Header file for the Rime module Anonymous BroadCast (abc)
void broadcast_close(struct broadcast_conn *c)
Close a broadcast connection.
Definition: broadcast.c:105
void(* recv)(struct broadcast_conn *ptr, const linkaddr_t *sender)
Called when a packet has been received by the broadcast module.
Definition: broadcast.h:82
Callback structure for broadcast.
Definition: broadcast.h:80
int broadcast_send(struct broadcast_conn *c)
Send an identified best-effort broadcast packet.
Definition: broadcast.c:111
void broadcast_open(struct broadcast_conn *c, uint16_t channel, const struct broadcast_callbacks *u)
Set up an identified best-effort broadcast connection.
Definition: broadcast.c:96
Header file for the Rime address representation