Contiki 2.5
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  * $Id: mesh.h,v 1.16 2010/06/14 19:19:17 adamdunkels Exp $
53  */
54 
55 /**
56  * \file
57  * Header file for the Rime mesh routing protocol
58  * \author
59  * Adam Dunkels <adam@sics.se>
60  */
61 
62 #ifndef __MESH_H__
63 #define __MESH_H__
64 
65 #include "net/queuebuf.h"
66 #include "net/rime/multihop.h"
68 
69 struct mesh_conn;
70 
71 /**
72  * \brief Mesh callbacks
73  */
75  /** Called when a packet is received. */
76  void (* recv)(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops);
77  /** Called when a packet, sent with mesh_send(), is actually transmitted. */
78  void (* sent)(struct mesh_conn *c);
79  /** Called when a packet, sent with mesh_send(), times out and is dropped. */
80  void (* timedout)(struct mesh_conn *c);
81 };
82 
83 struct mesh_conn {
84  struct multihop_conn multihop;
85  struct route_discovery_conn route_discovery_conn;
86  struct queuebuf *queued_data;
87  rimeaddr_t queued_data_dest;
88  const struct mesh_callbacks *cb;
89 };
90 
91 /**
92  * \brief Open a mesh connection
93  * \param c A pointer to a struct mesh_conn
94  * \param channels The channels on which the connection will operate; mesh uses 3 channels
95  * \param callbacks Pointer to callback structure
96  *
97  * This function sets up a mesh connection on the
98  * specified channel. The caller must have allocated the
99  * memory for the struct mesh_conn, usually by declaring it
100  * as a static variable.
101  *
102  * The struct mesh_callbacks pointer must point to a structure
103  * containing function pointers to functions that will be called
104  * when a packet arrives on the channel.
105  *
106  */
107 void mesh_open(struct mesh_conn *c, uint16_t channels,
108  const struct mesh_callbacks *callbacks);
109 
110 /**
111  * \brief Close an mesh connection
112  * \param c A pointer to a struct mesh_conn
113  *
114  * This function closes an mesh connection that has
115  * previously been opened with mesh_open().
116  *
117  * This function typically is called as an exit handler.
118  *
119  */
120 void mesh_close(struct mesh_conn *c);
121 
122 /**
123  * \brief Send a mesh packet
124  * \param c The mesh connection on which the packet should be sent
125  * \param dest The address of the final destination of the packet
126  * \retval Non-zero if the packet could be queued for sending, zero otherwise
127  *
128  * This function sends a mesh packet. The packet must be
129  * present in the packetbuf before this function is called.
130  *
131  * The parameter c must point to an abc connection that
132  * must have previously been set up with mesh_open().
133  *
134  */
135 int mesh_send(struct mesh_conn *c, const rimeaddr_t *dest);
136 
137 #endif /* __MESH_H__ */
138 /** @} */
139 /** @} */