EVE 1.0
The Contiki/uIP interface
Collaboration diagram for The Contiki/uIP interface:

Files

file  tcpip.h
 

Variables

CCIF process_event_t tcpip_event
 

TCP functions

CCIF void tcp_attach (struct uip_conn *conn, void *appstate)
 
CCIF void tcp_listen (uint16_t port)
 
CCIF void tcp_unlisten (uint16_t port)
 
CCIF struct uip_conntcp_connect (uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
 
void tcpip_poll_tcp (struct uip_conn *conn)
 
#define tcp_markconn(conn, appstate)   tcp_attach(conn, appstate)
 

UDP functions

void udp_attach (struct uip_udp_conn *conn, void *appstate)
 
CCIF struct uip_udp_connudp_new (const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
 
struct uip_udp_connudp_broadcast_new (uint16_t port, void *appstate)
 
CCIF void tcpip_poll_udp (struct uip_udp_conn *conn)
 
#define udp_markconn(conn, appstate)   udp_attach(conn, appstate)
 
#define udp_bind(conn, port)   uip_udp_bind(conn, port)
 

TCP/IP packet processing

unsigned char tcpip_do_forwarding
 This function does address resolution and then calls tcpip_output. More...
 
unsigned char tcpip_is_forwarding
 
CCIF void tcpip_input (void)
 Deliver an incoming packet to the TCP/IP stack. More...
 
bool tcpip_quote (const uip_ipaddr_t *destipaddr)
 
void tcpip_set_quotefunc (bool(*f)(const uip_ipaddr_t *destipaddr))
 
void tcpip_flow_on (void)
 
uint8_t tcpip_output (void)
 Output packet to layer 2 The eventual parameter is the MAC address of the destination.
 
void tcpip_set_outputfunc (uint8_t(*f)(void))
 
#define tcpip_set_forwarding(forwarding)   tcpip_do_forwarding = (forwarding)
 

Detailed Description

TCP/IP support in Contiki is implemented using the uIP TCP/IP stack. For sending and receiving data, Contiki uses the functions provided by the uIP module, but Contiki adds a set of functions for connection management. The connection management functions make sure that the uIP TCP/IP connections are connected to the correct process.

Contiki also includes an optional protosocket library that provides an API similar to the BSD socket API.

See also
The uIP TCP/IP stack
Protosockets library

Macro Definition Documentation

#define udp_bind (   conn,
  port 
)    uip_udp_bind(conn, port)

Bind a UDP connection to a local port.

This function binds a UDP connection to a specified local port.

When a connection is created with udp_new(), it gets a local port number assigned automatically. If the application needs to bind the connection to a specified local port, this function should be used.

Note
The port number must be provided in network byte order so a conversion with UIP_HTONS() usually is necessary.
Parameters
connA pointer to the UDP connection that is to be bound.
portThe port number in network byte order to which to bind the connection.

Definition at line 262 of file tcpip.h.

Referenced by simple_udp_register(), and tcpip_output().

Function Documentation

CCIF void tcp_attach ( struct uip_conn conn,
void *  appstate 
)

Attach a TCP connection to the current process

This function attaches the current process to a TCP connection. Each TCP connection must be attached to a process in order for the process to be able to receive and send data. Additionally, this function can add a pointer with connection state to the connection.

Parameters
connA pointer to the TCP connection.
appstateAn opaque pointer that will be passed to the process whenever an event occurs on the connection.

Referenced by tcpip_output().

CCIF void tcp_listen ( uint16_t  port)

Open a TCP port.

This function opens a TCP port for listening. When a TCP connection request occurs for the port, the process will be sent a tcpip_event with the new connection request.

Note
Port numbers must always be given in network byte order. The functions UIP_HTONS() and uip_htons() can be used to convert port numbers from host byte order to network byte order.
Parameters
portThe port number in network byte order.

Referenced by tcpip_output().

CCIF void tcp_unlisten ( uint16_t  port)

Close a listening TCP port.

This function closes a listening TCP port.

Note
Port numbers must always be given in network byte order. The functions UIP_HTONS() and uip_htons() can be used to convert port numbers from host byte order to network byte order.
Parameters
portThe port number in network byte order.

Referenced by tcpip_output().

CCIF struct uip_conn* tcp_connect ( uip_ipaddr_t ripaddr,
uint16_t  port,
void *  appstate 
)

Open a TCP connection to the specified IP address and port.

This function opens a TCP connection to the specified port at the host specified with an IP address. Additionally, an opaque pointer can be attached to the connection. This pointer will be sent together with uIP events to the process.

Note
The port number must be provided in network byte order so a conversion with UIP_HTONS() usually is necessary.
This function will only create the connection. The connection is not opened directly. uIP will try to open the connection the next time the uIP stack is scheduled by Contiki.
Parameters
ripaddrPointer to the IP address of the remote host.
portPort number in network byte order.
appstatePointer to application defined data.
Returns
A pointer to the newly created connection, or NULL if memory could not be allocated for the connection.

Referenced by tcpip_output().

void tcpip_poll_tcp ( struct uip_conn conn)

Cause a specified TCP connection to be polled.

This function causes uIP to poll the specified TCP connection. The function is used when the application has data that is to be sent immediately and do not wish to wait for the periodic uIP polling mechanism.

Parameters
connA pointer to the TCP connection that should be polled.

Referenced by tcpip_input(), and tcpip_output().

void udp_attach ( struct uip_udp_conn conn,
void *  appstate 
)

Attach the current process to a UDP connection

This function attaches the current process to a UDP connection. Each UDP connection must have a process attached to it in order for the process to be able to receive and send data over the connection. Additionally, this function can add a pointer with connection state to the connection.

Parameters
connA pointer to the UDP connection.
appstateAn opaque pointer that will be passed to the process whenever an event occurs on the connection.

Referenced by tcpip_output().

CCIF struct uip_udp_conn* udp_new ( const uip_ipaddr_t ripaddr,
uint16_t  port,
void *  appstate 
)

Create a new UDP connection.

This function creates a new UDP connection with the specified remote endpoint.

Note
The port number must be provided in network byte order so a conversion with UIP_HTONS() usually is necessary.
See also
udp_bind()
Parameters
ripaddrPointer to the IP address of the remote host.
portPort number in network byte order.
appstatePointer to application defined data.
Returns
A pointer to the newly created connection, or NULL if memory could not be allocated for the connection.

Referenced by simple_udp_register(), and tcpip_output().

struct uip_udp_conn* udp_broadcast_new ( uint16_t  port,
void *  appstate 
)

Create a new UDP broadcast connection.

This function creates a new (link-local) broadcast UDP connection to a specified port.

Parameters
portPort number in network byte order.
appstatePointer to application defined data.
Returns
A pointer to the newly created connection, or NULL if memory could not be allocated for the connection.

Referenced by tcpip_output().

CCIF void tcpip_poll_udp ( struct uip_udp_conn conn)

Cause a specified UDP connection to be polled.

This function causes uIP to poll the specified UDP connection. The function is used when the application has data that is to be sent immediately and do not wish to wait for the periodic uIP polling mechanism.

Parameters
connA pointer to the UDP connection that should be polled.

Referenced by tcpip_input().

CCIF void tcpip_input ( void  )

Deliver an incoming packet to the TCP/IP stack.

This function is called by network device drivers to deliver an incoming packet to the TCP/IP stack. The incoming packet must be present in the uip_buf buffer, and the length of the packet must be in the global uip_len variable.

Definition at line 553 of file tcpip.c.

References uip_conn::appstate, uip_udp_conn::appstate, CLOCK_SECOND, etimer_set(), uip_conn::lport, process_alloc_event(), PROCESS_BEGIN, PROCESS_CURRENT, PROCESS_END, process_post(), process_post_synch(), PROCESS_THREAD, PROCESS_YIELD, stimer_set(), tcpip_event, tcpip_output(), tcpip_poll_tcp(), tcpip_poll_udp(), uip_connected, UIP_CONNS, uip_ext_len, uip_init(), uip_len, UIP_LINK_MTU, and UIP_LISTENPORTS.

Variable Documentation

CCIF process_event_t tcpip_event

The uIP event.

This event is posted to a process whenever a uIP event has occurred.

Definition at line 81 of file tcpip.c.

Referenced by simple_udp_deregister(), and tcpip_input().

unsigned char tcpip_do_forwarding

This function does address resolution and then calls tcpip_output.

Is forwarding generally enabled?