broadcast.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup rime
00003  * @{
00004  */
00005 
00006 /**
00007  * \defgroup rimeibc Best-effort local area broadcast
00008  * @{
00009  *
00010  * The broadcast module sends packets to all local area neighbors with an a
00011  * header that identifies the sender.
00012  *
00013  * The broadcast module sends a packet to all local neighbors.  The
00014  * module adds the single-hop sender address as a packet attribute to
00015  * outgoing packets.  All Rime primitives that need the identity of
00016  * the sender in the outgoing packets use the broadcast primitive,
00017  * either directly or indirectly through any of the other
00018  * communication primitives that are based on the broadcast primitive.
00019  *
00020  * \section channels Channels
00021  *
00022  * The broadcast module uses 1 channel.
00023  *
00024  */
00025 
00026 /*
00027  * Copyright (c) 2006, Swedish Institute of Computer Science.
00028  * All rights reserved.
00029  *
00030  * Redistribution and use in source and binary forms, with or without
00031  * modification, are permitted provided that the following conditions
00032  * are met:
00033  * 1. Redistributions of source code must retain the above copyright
00034  *    notice, this list of conditions and the following disclaimer.
00035  * 2. Redistributions in binary form must reproduce the above copyright
00036  *    notice, this list of conditions and the following disclaimer in the
00037  *    documentation and/or other materials provided with the distribution.
00038  * 3. Neither the name of the Institute nor the names of its contributors
00039  *    may be used to endorse or promote products derived from this software
00040  *    without specific prior written permission.
00041  *
00042  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00043  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00044  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00045  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00046  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00047  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00048  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00049  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00050  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00051  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00052  * SUCH DAMAGE.
00053  *
00054  * This file is part of the Contiki operating system.
00055  *
00056  * $Id: broadcast.h,v 1.5 2010/02/23 18:38:05 adamdunkels Exp $
00057  */
00058 
00059 /**
00060  * \file
00061  *         Header file for identified best-effort local area broadcast
00062  * \author
00063  *         Adam Dunkels <adam@sics.se>
00064  */
00065 
00066 #ifndef __BROADCAST_H__
00067 #define __BROADCAST_H__
00068 
00069 #include "net/rime/abc.h"
00070 #include "net/rime/rimeaddr.h"
00071 
00072 struct broadcast_conn;
00073 
00074 #define BROADCAST_ATTRIBUTES  { PACKETBUF_ADDR_SENDER, PACKETBUF_ADDRSIZE }, \
00075                         ABC_ATTRIBUTES
00076 
00077 /**
00078  * \brief     Callback structure for broadcast
00079  *
00080  */
00081 struct broadcast_callbacks {
00082   /** Called when a packet has been received by the broadcast module. */
00083   void (* recv)(struct broadcast_conn *ptr, const rimeaddr_t *sender);
00084   void (* sent)(struct broadcast_conn *ptr, int status, int num_tx);
00085 };
00086 
00087 struct broadcast_conn {
00088   struct abc_conn c;
00089   const struct broadcast_callbacks *u;
00090 };
00091 
00092 /**
00093  * \brief      Set up an identified best-effort broadcast connection
00094  * \param c    A pointer to a struct broadcast_conn
00095  * \param channel The channel on which the connection will operate
00096  * \param u    A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received
00097  *
00098  *             This function sets up a broadcast connection on the
00099  *             specified channel. The caller must have allocated the
00100  *             memory for the struct broadcast_conn, usually by declaring it
00101  *             as a static variable.
00102  *
00103  *             The struct broadcast_callbacks pointer must point to a structure
00104  *             containing a pointer to a function that will be called
00105  *             when a packet arrives on the channel.
00106  *
00107  */
00108 void broadcast_open(struct broadcast_conn *c, uint16_t channel,
00109                const struct broadcast_callbacks *u);
00110 
00111 /**
00112  * \brief      Close a broadcast connection
00113  * \param c    A pointer to a struct broadcast_conn
00114  *
00115  *             This function closes a broadcast connection that has
00116  *             previously been opened with broadcast_open().
00117  *
00118  *             This function typically is called as an exit handler.
00119  *
00120  */
00121 void broadcast_close(struct broadcast_conn *c);
00122 
00123 /**
00124  * \brief      Send an identified best-effort broadcast packet
00125  * \param c    The broadcast connection on which the packet should be sent
00126  * \retval     Non-zero if the packet could be sent, zero otherwise
00127  *
00128  *             This function sends an identified best-effort broadcast
00129  *             packet. The packet must be present in the packetbuf
00130  *             before this function is called.
00131  *
00132  *             The parameter c must point to a broadcast connection that
00133  *             must have previously been set up with broadcast_open().
00134  *
00135  */
00136 int broadcast_send(struct broadcast_conn *c);
00137 
00138 #endif /* __BROADCAST_H__ */
00139 /** @} */
00140 /** @} */

Generated on Mon Apr 11 14:23:30 2011 for Contiki 2.5 by  doxygen 1.6.1