Contiki 3.x
mesh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, 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 mesh routing protocol
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43  */
44 
45 /**
46  * \defgroup rimemesh Mesh routing
47  * @{
48  *
49  * The mesh module sends packets using multi-hop routing to a specified
50  * receiver somewhere in the network.
51  *
52  *
53  * \section channels Channels
54  *
55  * The mesh module uses 3 channel; one for the multi-hop forwarding
56  * (\ref rimemultihop "multihop") and two for the route disovery (\ref
57  * routediscovery "route-discovery").
58  *
59  */
60 
61 #ifndef MESH_H_
62 #define MESH_H_
63 
64 #include "net/queuebuf.h"
65 #include "net/rime/multihop.h"
67 
68 struct mesh_conn;
69 
70 /**
71  * \brief Mesh callbacks
72  */
74  /** Called when a packet is received. */
75  void (* recv)(struct mesh_conn *c, const linkaddr_t *from, uint8_t hops);
76  /** Called when a packet, sent with mesh_send(), is actually transmitted. */
77  void (* sent)(struct mesh_conn *c);
78  /** Called when a packet, sent with mesh_send(), times out and is dropped. */
79  void (* timedout)(struct mesh_conn *c);
80 };
81 
82 struct mesh_conn {
83  struct multihop_conn multihop;
84  struct route_discovery_conn route_discovery_conn;
85  struct queuebuf *queued_data;
86  linkaddr_t queued_data_dest;
87  const struct mesh_callbacks *cb;
88 };
89 
90 /**
91  * \brief Open a mesh connection
92  * \param c A pointer to a struct mesh_conn
93  * \param channels The channels on which the connection will operate; mesh uses 3 channels
94  * \param callbacks Pointer to callback structure
95  *
96  * This function sets up a mesh connection on the
97  * specified channel. The caller must have allocated the
98  * memory for the struct mesh_conn, usually by declaring it
99  * as a static variable.
100  *
101  * The struct mesh_callbacks pointer must point to a structure
102  * containing function pointers to functions that will be called
103  * when a packet arrives on the channel.
104  *
105  */
106 void mesh_open(struct mesh_conn *c, uint16_t channels,
107  const struct mesh_callbacks *callbacks);
108 
109 /**
110  * \brief Close an mesh connection
111  * \param c A pointer to a struct mesh_conn
112  *
113  * This function closes an mesh connection that has
114  * previously been opened with mesh_open().
115  *
116  * This function typically is called as an exit handler.
117  *
118  */
119 void mesh_close(struct mesh_conn *c);
120 
121 /**
122  * \brief Send a mesh packet
123  * \param c The mesh connection on which the packet should be sent
124  * \param dest The address of the final destination of the packet
125  * \retval Non-zero if the packet could be queued for sending, zero otherwise
126  *
127  * This function sends a mesh packet. The packet must be
128  * present in the packetbuf before this function is called.
129  *
130  * The parameter c must point to an abc connection that
131  * must have previously been set up with mesh_open().
132  *
133  */
134 int mesh_send(struct mesh_conn *c, const linkaddr_t *dest);
135 
136 /**
137  * \brief Test if mesh is ready to send a packet (or packet is queued)
138  * \param c The mesh connection on which is to be tested
139  * \retval 0 Packet queued
140  * \retval !0 Ready
141  */
142 int mesh_ready(struct mesh_conn *c);
143 
144 #endif /* MESH_H_ */
145 /** @} */
146 /** @} */
int mesh_send(struct mesh_conn *c, const linkaddr_t *to)
Send a mesh packet.
Definition: mesh.c:184
void(* timedout)(struct mesh_conn *c)
Called when a packet, sent with mesh_send(), times out and is dropped.
Definition: mesh.h:79
void mesh_close(struct mesh_conn *c)
Close an mesh connection.
Definition: mesh.c:177
Mesh callbacks.
Definition: mesh.h:73
int mesh_ready(struct mesh_conn *c)
Test if mesh is ready to send a packet (or packet is queued)
Definition: mesh.c:205
Header file for the Rime queue buffer management
Header file for the Rime mesh routing protocol
void(* recv)(struct mesh_conn *c, const linkaddr_t *from, uint8_t hops)
Called when a packet is received.
Definition: mesh.h:75
void mesh_open(struct mesh_conn *c, uint16_t channels, const struct mesh_callbacks *callbacks)
Open a mesh connection.
Definition: mesh.c:164
Multihop forwarding header file
void(* sent)(struct mesh_conn *c)
Called when a packet, sent with mesh_send(), is actually transmitted.
Definition: mesh.h:77