Contiki 3.x
abc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  */
34 
35 /**
36  * \file
37  * Anonymous best-effort local area Broad Cast (abc)
38  * \author
39  * Adam Dunkels <adam@sics.se>
40  */
41 
42 /**
43  * \addtogroup rimeabc
44  * @{
45  */
46 
47 #include "contiki-net.h"
48 #include "net/rime/rime.h"
49 
50 
51 #define DEBUG 0
52 #if DEBUG
53 #include <stdio.h>
54 #define PRINTF(...) printf(__VA_ARGS__)
55 #else
56 #define PRINTF(...)
57 #endif
58 
59 static const struct packetbuf_attrlist attributes[] =
60  { ABC_ATTRIBUTES PACKETBUF_ATTR_LAST };
61 
62 /*---------------------------------------------------------------------------*/
63 void
64 abc_open(struct abc_conn *c, uint16_t channelno,
65  const struct abc_callbacks *callbacks)
66 {
67  channel_open(&c->channel, channelno);
68  c->u = callbacks;
69  channel_set_attributes(channelno, attributes);
70 }
71 /*---------------------------------------------------------------------------*/
72 void
73 abc_close(struct abc_conn *c)
74 {
75  channel_close(&c->channel);
76 }
77 /*---------------------------------------------------------------------------*/
78 int
79 abc_send(struct abc_conn *c)
80 {
81  PRINTF("%d.%d: abc: abc_send on channel %d\n",
83  c->channel.channelno);
84  return rime_output(&c->channel);
85 }
86 /*---------------------------------------------------------------------------*/
87 void
88 abc_input(struct channel *channel)
89 {
90  struct abc_conn *c = (struct abc_conn *)channel;
91  PRINTF("%d.%d: abc: abc_input_packet on channel %d\n",
93  channel->channelno);
94 
95  if(c->u->recv) {
96  c->u->recv(c);
97  }
98 }
99 /*---------------------------------------------------------------------------*/
100 void
101 abc_sent(struct channel *channel, int status, int num_tx)
102 {
103  struct abc_conn *c = (struct abc_conn *)channel;
104  PRINTF("%d.%d: abc: abc_sent on channel %d\n",
106  channel->channelno);
107 
108  if(c->u->sent) {
109  c->u->sent(c, status, num_tx);
110  }
111 }
112 /*---------------------------------------------------------------------------*/
113 
114 /** @} */
linkaddr_t linkaddr_node_addr
The Rime address of the node.
Definition: linkaddr.c:48
int abc_send(struct abc_conn *c)
Send an anonymous best-effort broadcast packet.
Definition: abc.c:79
void abc_input(struct channel *channel)
Internal Rime function: Pass a packet to the abc layer.
Definition: abc.c:88
Header file for the Rime stack
void abc_close(struct abc_conn *c)
Close an abc connection.
Definition: abc.c:73
void abc_open(struct abc_conn *c, uint16_t channelno, const struct abc_callbacks *callbacks)
Set up an anonymous best-effort broadcast connection.
Definition: abc.c:64
Callback structure for abc.
Definition: abc.h:72