Made MAC_CONF_CHANNEL_CHECK_RATE identical to CLOCK_CONF_SECOND in order to make...
[contiki-2.x.git] / core / net / tcpip.h
blobeaf8557b1861b4a0f9d86ff552235bf726cc13e9
1 /**
2 * \addtogroup uip
3 * @{
4 */
6 /**
7 * \defgroup tcpip The Contiki/uIP interface
8 * @{
10 * TCP/IP support in Contiki is implemented using the uIP TCP/IP
11 * stack. For sending and receiving data, Contiki uses the functions
12 * provided by the uIP module, but Contiki adds a set of functions for
13 * connection management. The connection management functions make
14 * sure that the uIP TCP/IP connections are connected to the correct
15 * process.
17 * Contiki also includes an optional protosocket library that provides
18 * an API similar to the BSD socket API.
20 * \sa \ref uip "The uIP TCP/IP stack"
21 * \sa \ref psock "Protosockets library"
25 /**
26 * \file
27 * Header for the Contiki/uIP interface.
28 * \author Adam Dunkels <adam@sics.se>
29 * \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
30 * \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
34 * Copyright (c) 2004, Swedish Institute of Computer Science.
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. Neither the name of the Institute nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
61 * This file is part of the Contiki operating system.
63 * Author: Adam Dunkels <adam@sics.se>
65 * $Id: tcpip.h,v 1.16 2010/02/05 12:43:37 nifi Exp $
67 #ifndef __TCPIP_H__
68 #define __TCPIP_H__
70 #include "contiki.h"
72 struct uip_conn;
74 struct tcpip_uipstate {
75 struct process *p;
76 void *state;
79 #define UIP_APPCALL tcpip_uipcall
80 #define UIP_UDP_APPCALL tcpip_uipcall
81 #define UIP_ICMP6_APPCALL tcpip_icmp6_call
83 /*#define UIP_APPSTATE_SIZE sizeof(struct tcpip_uipstate)*/
85 typedef struct tcpip_uipstate uip_udp_appstate_t;
86 typedef struct tcpip_uipstate uip_tcp_appstate_t;
87 typedef struct tcpip_uipstate uip_icmp6_appstate_t;
88 #include "net/uip.h"
89 void tcpip_uipcall(void);
91 /**
92 * \name TCP functions
93 * @{
96 /**
97 * Attach a TCP connection to the current process
99 * This function attaches the current process to a TCP
100 * connection. Each TCP connection must be attached to a process in
101 * order for the process to be able to receive and send
102 * data. Additionally, this function can add a pointer with connection
103 * state to the connection.
105 * \param conn A pointer to the TCP connection.
107 * \param appstate An opaque pointer that will be passed to the
108 * process whenever an event occurs on the connection.
111 CCIF void tcp_attach(struct uip_conn *conn,
112 void *appstate);
113 #define tcp_markconn(conn, appstate) tcp_attach(conn, appstate)
116 * Open a TCP port.
118 * This function opens a TCP port for listening. When a TCP connection
119 * request occurs for the port, the process will be sent a tcpip_event
120 * with the new connection request.
122 * \note Port numbers must always be given in network byte order. The
123 * functions HTONS() and htons() can be used to convert port numbers
124 * from host byte order to network byte order.
126 * \param port The port number in network byte order.
129 CCIF void tcp_listen(u16_t port);
132 * Close a listening TCP port.
134 * This function closes a listening TCP port.
136 * \note Port numbers must always be given in network byte order. The
137 * functions HTONS() and htons() can be used to convert port numbers
138 * from host byte order to network byte order.
140 * \param port The port number in network byte order.
143 CCIF void tcp_unlisten(u16_t port);
146 * Open a TCP connection to the specified IP address and port.
148 * This function opens a TCP connection to the specified port at the
149 * host specified with an IP address. Additionally, an opaque pointer
150 * can be attached to the connection. This pointer will be sent
151 * together with uIP events to the process.
153 * \note The port number must be provided in network byte order so a
154 * conversion with HTONS() usually is necessary.
156 * \note This function will only create the connection. The connection
157 * is not opened directly. uIP will try to open the connection the
158 * next time the uIP stack is scheduled by Contiki.
160 * \param ripaddr Pointer to the IP address of the remote host.
161 * \param port Port number in network byte order.
162 * \param appstate Pointer to application defined data.
164 * \return A pointer to the newly created connection, or NULL if
165 * memory could not be allocated for the connection.
168 CCIF struct uip_conn *tcp_connect(uip_ipaddr_t *ripaddr, u16_t port,
169 void *appstate);
172 * Cause a specified TCP connection to be polled.
174 * This function causes uIP to poll the specified TCP connection. The
175 * function is used when the application has data that is to be sent
176 * immediately and do not wish to wait for the periodic uIP polling
177 * mechanism.
179 * \param conn A pointer to the TCP connection that should be polled.
182 void tcpip_poll_tcp(struct uip_conn *conn);
184 /** @} */
187 * \name UDP functions
188 * @{
191 struct uip_udp_conn;
193 * Attach the current process to a UDP connection
195 * This function attaches the current process to a UDP
196 * connection. Each UDP connection must have a process attached to it
197 * in order for the process to be able to receive and send data over
198 * the connection. Additionally, this function can add a pointer with
199 * connection state to the connection.
201 * \param conn A pointer to the UDP connection.
203 * \param appstate An opaque pointer that will be passed to the
204 * process whenever an event occurs on the connection.
207 void udp_attach(struct uip_udp_conn *conn,
208 void *appstate);
209 #define udp_markconn(conn, appstate) udp_attach(conn, appstate)
212 * Create a new UDP connection.
214 * This function creates a new UDP connection with the specified
215 * remote endpoint.
217 * \note The port number must be provided in network byte order so a
218 * conversion with HTONS() usually is necessary.
220 * \sa udp_bind()
222 * \param ripaddr Pointer to the IP address of the remote host.
223 * \param port Port number in network byte order.
224 * \param appstate Pointer to application defined data.
226 * \return A pointer to the newly created connection, or NULL if
227 * memory could not be allocated for the connection.
229 CCIF struct uip_udp_conn *udp_new(const uip_ipaddr_t *ripaddr, u16_t port,
230 void *appstate);
233 * Create a new UDP broadcast connection.
235 * This function creates a new (link-local) broadcast UDP connection
236 * to a specified port.
238 * \param port Port number in network byte order.
239 * \param appstate Pointer to application defined data.
241 * \return A pointer to the newly created connection, or NULL if
242 * memory could not be allocated for the connection.
244 struct uip_udp_conn *udp_broadcast_new(u16_t port, void *appstate);
247 * Bind a UDP connection to a local port.
249 * This function binds a UDP connection to a specified local port.
251 * When a connection is created with udp_new(), it gets a local port
252 * number assigned automatically. If the application needs to bind the
253 * connection to a specified local port, this function should be used.
255 * \note The port number must be provided in network byte order so a
256 * conversion with HTONS() usually is necessary.
258 * \param conn A pointer to the UDP connection that is to be bound.
259 * \param port The port number in network byte order to which to bind
260 * the connection.
262 #define udp_bind(conn, port) uip_udp_bind(conn, port)
265 * Cause a specified UDP connection to be polled.
267 * This function causes uIP to poll the specified UDP connection. The
268 * function is used when the application has data that is to be sent
269 * immediately and do not wish to wait for the periodic uIP polling
270 * mechanism.
272 * \param conn A pointer to the UDP connection that should be polled.
275 CCIF void tcpip_poll_udp(struct uip_udp_conn *conn);
277 /** @} */
280 * \name ICMPv6 functions
281 * @{
284 #if UIP_CONF_ICMP6
287 * The ICMP6 event.
289 * This event is posted to a process whenever a uIP ICMP event has occurred.
291 CCIF extern process_event_t tcpip_icmp6_event;
294 * \brief register an ICMPv6 callback
295 * \return 0 if success, 1 if failure (one application already registered)
297 * This function just registers a process to be polled when
298 * an ICMPv6 message is received.
299 * If no application registers, some ICMPv6 packets will be
300 * processed by the "kernel" as usual (NS, NA, RS, RA, Echo request),
301 * others will be dropped.
302 * If an application registers here, it will be polled with a
303 * process_post_synch every time an ICMPv6 packet is received.
305 u8_t icmp6_new(void *appstate);
308 * This function is called at reception of an ICMPv6 packet
309 * If an application registered as an ICMPv6 listener (with
310 * icmp6_new), it will be called through a process_post_synch()
312 void tcpip_icmp6_call(u8_t type);
313 #endif /*UIP_CONF_ICMP6*/
315 /** @} */
317 * The uIP event.
319 * This event is posted to a process whenever a uIP event has occurred.
321 CCIF extern process_event_t tcpip_event;
324 * \name TCP/IP packet processing
325 * @{
329 * \brief Deliver an incoming packet to the TCP/IP stack
331 * This function is called by network device drivers to
332 * deliver an incoming packet to the TCP/IP stack. The
333 * incoming packet must be present in the uip_buf buffer,
334 * and the length of the packet must be in the global
335 * uip_len variable.
337 CCIF void tcpip_input(void);
340 * \brief Output packet to layer 2
341 * The eventual parameter is the MAC address of the destination.
343 #if UIP_CONF_IPV6
344 u8_t tcpip_output(uip_lladdr_t *);
345 void tcpip_set_outputfunc(u8_t (* f)(uip_lladdr_t *));
346 #else
347 u8_t tcpip_output(void);
348 void tcpip_set_outputfunc(u8_t (* f)(void));
349 #endif
352 * \brief This function does address resolution and then calls tcpip_output
354 #if UIP_CONF_IPV6
355 void tcpip_ipv6_output(void);
356 #endif
359 * \brief Is forwarding generally enabled?
361 extern unsigned char tcpip_do_forwarding;
364 * Are we at the moment forwarding the contents of uip_buf[]?
366 extern unsigned char tcpip_is_forwarding;
369 #define tcpip_set_forwarding(forwarding) tcpip_do_forwarding = (forwarding)
371 /** @} */
373 PROCESS_NAME(tcpip_process);
375 #endif /* __TCPIP_H__ */
377 /** @} */
378 /** @} */