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