Contiki 2.6

mesh.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup rime
00003  * @{
00004  */
00005 
00006 /**
00007  * \defgroup rimemesh Mesh routing
00008  * @{
00009  *
00010  * The mesh module sends packets using multi-hop routing to a specified
00011  * receiver somewhere in the network.
00012  *
00013  *
00014  * \section channels Channels
00015  *
00016  * The mesh module uses 3 channel; one for the multi-hop forwarding
00017  * (\ref rimemultihop "multihop") and two for the route disovery (\ref
00018  * routediscovery "route-discovery").
00019  *
00020  */
00021 
00022 /*
00023  * Copyright (c) 2007, Swedish Institute of Computer Science.
00024  * All rights reserved.
00025  *
00026  * Redistribution and use in source and binary forms, with or without
00027  * modification, are permitted provided that the following conditions
00028  * are met:
00029  * 1. Redistributions of source code must retain the above copyright
00030  *    notice, this list of conditions and the following disclaimer.
00031  * 2. Redistributions in binary form must reproduce the above copyright
00032  *    notice, this list of conditions and the following disclaimer in the
00033  *    documentation and/or other materials provided with the distribution.
00034  * 3. Neither the name of the Institute nor the names of its contributors
00035  *    may be used to endorse or promote products derived from this software
00036  *    without specific prior written permission.
00037  *
00038  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00039  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00040  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00041  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00042  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00043  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00044  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00045  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00046  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00047  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00048  * SUCH DAMAGE.
00049  *
00050  * This file is part of the Contiki operating system.
00051  *
00052  * $Id: mesh.h,v 1.16 2010/06/14 19:19:17 adamdunkels Exp $
00053  */
00054 
00055 /**
00056  * \file
00057  *         Header file for the Rime mesh routing protocol
00058  * \author
00059  *         Adam Dunkels <adam@sics.se>
00060  */
00061 
00062 #ifndef __MESH_H__
00063 #define __MESH_H__
00064 
00065 #include "net/queuebuf.h"
00066 #include "net/rime/multihop.h"
00067 #include "net/rime/route-discovery.h"
00068 
00069 struct mesh_conn;
00070 
00071 /**
00072  * \brief     Mesh callbacks
00073  */
00074 struct mesh_callbacks {
00075   /** Called when a packet is received. */
00076   void (* recv)(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops);
00077   /** Called when a packet, sent with mesh_send(), is actually transmitted. */
00078   void (* sent)(struct mesh_conn *c);
00079   /** Called when a packet, sent with mesh_send(), times out and is dropped. */
00080   void (* timedout)(struct mesh_conn *c);
00081 };
00082 
00083 struct mesh_conn {
00084   struct multihop_conn multihop;
00085   struct route_discovery_conn route_discovery_conn;
00086   struct queuebuf *queued_data;
00087   rimeaddr_t queued_data_dest;
00088   const struct mesh_callbacks *cb;
00089 };
00090 
00091 /**
00092  * \brief      Open a mesh connection
00093  * \param c    A pointer to a struct mesh_conn
00094  * \param channels The channels on which the connection will operate; mesh uses 3 channels
00095  * \param callbacks Pointer to callback structure
00096  *
00097  *             This function sets up a mesh connection on the
00098  *             specified channel. The caller must have allocated the
00099  *             memory for the struct mesh_conn, usually by declaring it
00100  *             as a static variable.
00101  *
00102  *             The struct mesh_callbacks pointer must point to a structure
00103  *             containing function pointers to functions that will be called
00104  *             when a packet arrives on the channel.
00105  *
00106  */
00107 void mesh_open(struct mesh_conn *c, uint16_t channels,
00108                const struct mesh_callbacks *callbacks);
00109 
00110 /**
00111  * \brief      Close an mesh connection
00112  * \param c    A pointer to a struct mesh_conn
00113  *
00114  *             This function closes an mesh connection that has
00115  *             previously been opened with mesh_open().
00116  *
00117  *             This function typically is called as an exit handler.
00118  *
00119  */
00120 void mesh_close(struct mesh_conn *c);
00121 
00122 /**
00123  * \brief      Send a mesh packet
00124  * \param c    The mesh connection on which the packet should be sent
00125  * \param dest The address of the final destination of the packet
00126  * \retval     Non-zero if the packet could be queued for sending, zero otherwise
00127  *
00128  *             This function sends a mesh packet. The packet must be
00129  *             present in the packetbuf before this function is called.
00130  *
00131  *             The parameter c must point to an abc connection that
00132  *             must have previously been set up with mesh_open().
00133  *
00134  */
00135 int mesh_send(struct mesh_conn *c, const rimeaddr_t *dest);
00136 
00137 #endif /* __MESH_H__ */
00138 /** @} */
00139 /** @} */