Contiki 3.x
abc.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 the Rime module Anonymous BroadCast (abc)
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43  */
44 
45 /**
46  * \defgroup rimeabc Anonymous best-effort local area broadcast
47  * @{
48  *
49  * The abc module sends packets to all local area neighbors. The abc
50  * module adds no headers to outgoing packets.
51  *
52  * \section channels Channels
53  *
54  * The abc module uses 1 channel.
55  *
56  */
57 
58 #ifndef ABC_H_
59 #define ABC_H_
60 
61 #include "net/packetbuf.h"
62 #include "net/rime/channel.h"
63 
64 struct abc_conn;
65 
66 #define ABC_ATTRIBUTES
67 
68 /**
69  * \brief Callback structure for abc
70  *
71  */
72 struct abc_callbacks {
73  /** Called when a packet has been received by the abc module. */
74  void (* recv)(struct abc_conn *ptr);
75  void (* sent)(struct abc_conn *ptr, int status, int num_tx);
76 };
77 
78 struct abc_conn {
79  struct channel channel;
80  const struct abc_callbacks *u;
81 };
82 
83 /**
84  * \brief Set up an anonymous best-effort broadcast connection
85  * \param c A pointer to a struct abc_conn
86  * \param channel The channel on which the connection will operate
87  * \param u A struct abc_callbacks with function pointers to functions that will be called when a packet has been received
88  *
89  * This function sets up an abc connection on the
90  * specified channel. The caller must have allocated the
91  * memory for the struct abc_conn, usually by declaring it
92  * as a static variable.
93  *
94  * The struct abc_callbacks pointer must point to a structure
95  * containing a pointer to a function that will be called
96  * when a packet arrives on the channel.
97  *
98  */
99 void abc_open(struct abc_conn *c, uint16_t channel,
100  const struct abc_callbacks *u);
101 
102 /**
103  * \brief Close an abc connection
104  * \param c A pointer to a struct abc_conn
105  *
106  * This function closes an abc connection that has
107  * previously been opened with abc_open().
108  *
109  * This function typically is called as an exit handler.
110  *
111  */
112 void abc_close(struct abc_conn *c);
113 
114 /**
115  * \brief Send an anonymous best-effort broadcast packet
116  * \param c The abc connection on which the packet should be sent
117  * \retval Non-zero if the packet could be sent, zero otherwise
118  *
119  * This function sends an anonymous best-effort broadcast
120  * packet. The packet must be present in the packetbuf
121  * before this function is called.
122  *
123  * The parameter c must point to an abc connection that
124  * must have previously been set up with abc_open().
125  *
126  */
127 int abc_send(struct abc_conn *c);
128 
129 /**
130  * \brief Internal Rime function: Pass a packet to the abc layer
131  *
132  * This function is used internally by Rime to pass
133  * packets to the abc layer. Should never be called
134  * directly.
135  *
136  */
137 
138 void abc_input(struct channel *channel);
139 
140 void abc_sent(struct channel *channel, int status, int num_tx);
141 
142 #endif /* ABC_H_ */
143 /** @} */
144 /** @} */
int abc_send(struct abc_conn *c)
Send an anonymous best-effort broadcast packet.
Definition: abc.c:79
Header file for the Rime buffer (packetbuf) management
Header file for Rime&#39;s channel abstraction
void abc_input(struct channel *channel)
Internal Rime function: Pass a packet to the abc layer.
Definition: abc.c:88
void(* recv)(struct abc_conn *ptr)
Called when a packet has been received by the abc module.
Definition: abc.h:74
void abc_close(struct abc_conn *c)
Close an abc connection.
Definition: abc.c:73
void abc_open(struct abc_conn *c, uint16_t channelno, const struct abc_callbacks *callbacks)
Set up an anonymous best-effort broadcast connection.
Definition: abc.c:64
Callback structure for abc.
Definition: abc.h:72