Contiki 2.5
simple-udp.h
1 /**
2  * \addtogroup uip
3  * @{
4  */
5 
6 
7 /**
8  * \defgroup simple-udp
9  *
10  * The default Contiki UDP API is difficult to use. The simple-udp
11  * module provides a significantly simpler API.
12  *
13  * @{
14  */
15 
16 /*
17  * Copyright (c) 2011, Swedish Institute of Computer Science.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  * 1. Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * 2. Redistributions in binary form must reproduce the above copyright
26  * notice, this list of conditions and the following disclaimer in the
27  * documentation and/or other materials provided with the distribution.
28  * 3. Neither the name of the Institute nor the names of its contributors
29  * may be used to endorse or promote products derived from this software
30  * without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  * This file is part of the Contiki operating system.
45  *
46  * \file
47  * Header file for the simple-udp module.
48  * \author
49  * Adam Dunkels <adam@sics.se>
50  *
51  */
52 
53 #ifndef SIMPLE_UDP_H
54 #define SIMPLE_UDP_H
55 
56 #include "net/uip.h"
57 
58 struct simple_udp_connection;
59 
60 typedef void (* simple_udp_callback)(struct simple_udp_connection *c,
61  const uip_ipaddr_t *source_addr,
62  uint16_t source_port,
63  const uip_ipaddr_t *dest_addr,
64  uint16_t dest_port,
65  const uint8_t *data, uint16_t datalen);
66 
67 struct simple_udp_connection {
68  struct simple_udp_connection *next;
69  uip_ipaddr_t remote_addr;
70  uint16_t remote_port, local_port;
71  simple_udp_callback receive_callback;
72  struct uip_udp_conn *udp_conn;
73  struct process *client_process;
74 };
75 
76 int simple_udp_register(struct simple_udp_connection *c,
77  uint16_t local_port,
78  uip_ipaddr_t *remote_addr,
79  uint16_t remote_port,
80  simple_udp_callback receive_callback);
81 
82 int simple_udp_send(struct simple_udp_connection *c,
83  const void *data, uint16_t datalen);
84 
85 int simple_udp_sendto(struct simple_udp_connection *c,
86  const void *data, uint16_t datalen,
87  const uip_ipaddr_t *to);
88 
89 void simple_udp_init(void);
90 
91 #endif /* SIMPLE_UDP_H */
92 
93 /** @} */
94 /** @} */