2007-03-31 20:31:27 +02:00
|
|
|
/**
|
2008-06-30 10:28:53 +02:00
|
|
|
* \addtogroup rimestbroadcast
|
2007-03-31 20:31:27 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2007-02-28 17:38:51 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Implementation of the Rime module Stubborn Anonymous
|
2008-06-30 10:28:53 +02:00
|
|
|
* BroadCast (stbroadcast)
|
2007-02-28 17:38:51 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
2008-06-30 10:28:53 +02:00
|
|
|
#include "net/rime/stbroadcast.h"
|
2013-12-12 20:50:07 +01:00
|
|
|
#include "net/rime/rime.h"
|
2007-02-28 17:38:51 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2013-12-12 23:58:52 +01:00
|
|
|
recv_from_broadcast(struct broadcast_conn *broadcast, const linkaddr_t *sender)
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
2008-06-30 10:28:53 +02:00
|
|
|
register struct stbroadcast_conn *c = (struct stbroadcast_conn *)broadcast;
|
|
|
|
/* DEBUGF(3, "stbroadcast: recv_from_broadcast from %d\n", from_id);*/
|
2007-02-28 17:38:51 +01:00
|
|
|
if(c->u->recv != NULL) {
|
|
|
|
c->u->recv(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-06-30 10:28:53 +02:00
|
|
|
static const struct broadcast_callbacks stbroadcast = {recv_from_broadcast};
|
2007-02-28 17:38:51 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-06-30 10:28:53 +02:00
|
|
|
stbroadcast_open(struct stbroadcast_conn *c, uint16_t channel,
|
|
|
|
const struct stbroadcast_callbacks *u)
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
2008-06-30 10:28:53 +02:00
|
|
|
broadcast_open(&c->c, channel, &stbroadcast);
|
2007-02-28 17:38:51 +01:00
|
|
|
c->u = u;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-19 23:10:16 +01:00
|
|
|
void
|
2008-06-30 10:28:53 +02:00
|
|
|
stbroadcast_close(struct stbroadcast_conn *c)
|
2007-03-19 23:10:16 +01:00
|
|
|
{
|
2008-06-30 10:28:53 +02:00
|
|
|
broadcast_close(&c->c);
|
2007-03-20 13:26:57 +01:00
|
|
|
ctimer_stop(&c->t);
|
2007-03-19 23:10:16 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-02-28 17:38:51 +01:00
|
|
|
static void
|
|
|
|
send(void *ptr)
|
|
|
|
{
|
2008-06-30 10:28:53 +02:00
|
|
|
struct stbroadcast_conn *c = ptr;
|
2007-02-28 17:38:51 +01:00
|
|
|
|
2008-06-30 10:28:53 +02:00
|
|
|
/* DEBUGF(3, "stbroadcast: send()\n");*/
|
2009-03-12 22:58:20 +01:00
|
|
|
queuebuf_to_packetbuf(c->buf);
|
2008-06-30 10:28:53 +02:00
|
|
|
broadcast_send(&c->c);
|
2007-02-28 17:38:51 +01:00
|
|
|
ctimer_reset(&c->t);
|
|
|
|
if(c->u->sent != NULL) {
|
|
|
|
c->u->sent(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-06-30 10:28:53 +02:00
|
|
|
stbroadcast_set_timer(struct stbroadcast_conn *c, clock_time_t t)
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
|
|
|
ctimer_set(&c->t, t, send, c);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
2008-06-30 10:28:53 +02:00
|
|
|
stbroadcast_send_stubborn(struct stbroadcast_conn *c, clock_time_t t)
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
|
|
|
if(c->buf != NULL) {
|
|
|
|
queuebuf_free(c->buf);
|
|
|
|
}
|
2009-03-12 22:58:20 +01:00
|
|
|
c->buf = queuebuf_new_from_packetbuf();
|
2007-02-28 17:38:51 +01:00
|
|
|
if(c->buf == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-20 13:26:57 +01:00
|
|
|
send(c);
|
2008-06-30 10:28:53 +02:00
|
|
|
stbroadcast_set_timer(c, t);
|
2007-02-28 17:38:51 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2008-06-30 10:28:53 +02:00
|
|
|
stbroadcast_cancel(struct stbroadcast_conn *c)
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
|
|
|
ctimer_stop(&c->t);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-31 20:31:27 +02:00
|
|
|
/** @} */
|