Contiki-Inga 3.x
mesh.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimemesh Mesh routing
8  * @{
9  *
10  * The mesh module sends packets using multi-hop routing to a specified
11  * receiver somewhere in the network.
12  *
13  *
14  * \section channels Channels
15  *
16  * The mesh module uses 3 channel; one for the multi-hop forwarding
17  * (\ref rimemultihop "multihop") and two for the route disovery (\ref
18  * routediscovery "route-discovery").
19  *
20  */
21 
22 /*
23  * Copyright (c) 2007, Swedish Institute of Computer Science.
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions
28  * are met:
29  * 1. Redistributions of source code must retain the above copyright
30  * notice, this list of conditions and the following disclaimer.
31  * 2. Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * 3. Neither the name of the Institute nor the names of its contributors
35  * may be used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
39  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
42  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  *
50  * This file is part of the Contiki operating system.
51  *
52  */
53 
54 /**
55  * \file
56  * Header file for the Rime mesh routing protocol
57  * \author
58  * Adam Dunkels <adam@sics.se>
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 /** @} */