📄 uip.h
字号:
/**
* \addtogroup uip
* @{
*/
/**
* \file
* Header file for the uIP TCP/IP stack.
* \author Adam Dunkels <adam@dunkels.com>
*
* The uIP TCP/IP stack header file contains definitions for a number
* of C macros that are used by uIP programs as well as internal uIP
* structures, TCP/IP header structures and function declarations.
*
*/
/*
* Copyright (c) 2001-2003, Adam Dunkels.
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
*
* $Id: uip.h,v 1.40 2006/06/08 07:12:07 adam Exp $
*
*/
#ifndef __UIP_H__
#define __UIP_H__
#include "uipopt.h"
/**
* Repressentation of an IP address.
*
*/
typedef u16_t uip_ip4addr_t[2];
typedef u16_t uip_ip6addr_t[8];
#if UIP_CONF_IPV6
typedef uip_ip6addr_t uip_ipaddr_t;
#else /* UIP_CONF_IPV6 */
typedef uip_ip4addr_t uip_ipaddr_t;
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/
/* First, the functions that should be called from the
* system. Initialization, the periodic timer and incoming packets are
* handled by the following three functions.
*/
/**
* \defgroup uipconffunc uIP configuration functions
* @{
*
* The uIP configuration functions are used for setting run-time
* parameters in uIP such as IP addresses.
*/
/**
* Set the IP address of this host.
*
* The IP address is represented as a 4-byte array where the first
* octet of the IP address is put in the first member of the 4-byte
* array.
*
* Example:
\code
uip_ipaddr_t addr;
uip_ipaddr(&addr, 192,168,1,2);
uip_sethostaddr(&addr);
\endcode
* \param addr A pointer to an IP address of type uip_ipaddr_t;
*
* \sa uip_ipaddr()
*
* \hideinitializer
*/
#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr))
/**
* Get the IP address of this host.
*
* The IP address is represented as a 4-byte array where the first
* octet of the IP address is put in the first member of the 4-byte
* array.
*
* Example:
\code
uip_ipaddr_t hostaddr;
uip_gethostaddr(&hostaddr);
\endcode
* \param addr A pointer to a uip_ipaddr_t variable that will be
* filled in with the currently configured IP address.
*
* \hideinitializer
*/
#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr)
/**
* Set the default router's IP address.
*
* \param addr A pointer to a uip_ipaddr_t variable containing the IP
* address of the default router.
*
* \sa uip_ipaddr()
*
* \hideinitializer
*/
#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))
/**
* Set the netmask.
*
* \param addr A pointer to a uip_ipaddr_t variable containing the IP
* address of the netmask.
*
* \sa uip_ipaddr()
*
* \hideinitializer
*/
#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr))
/**
* Get the default router's IP address.
*
* \param addr A pointer to a uip_ipaddr_t variable that will be
* filled in with the IP address of the default router.
*
* \hideinitializer
*/
#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)
/**
* Get the netmask.
*
* \param addr A pointer to a uip_ipaddr_t variable that will be
* filled in with the value of the netmask.
*
* \hideinitializer
*/
#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask)
/** @} */
/**
* \defgroup uipinit uIP initialization functions
* @{
*
* The uIP initialization functions are used for booting uIP.
*/
/**
* uIP initialization function.
*
* This function should be called at boot up to initilize the uIP
* TCP/IP stack.
*/
void uip_init(void);
/**
* uIP initialization function.
*
* This function may be used at boot time to set the initial ip_id.
*/
void uip_setipid(u16_t id);
/** @} */
/**
* \defgroup uipdevfunc uIP device driver functions
* @{
*
* These functions are used by a network device driver for interacting
* with uIP.
*/
/**
* Process an incoming packet.
*
* This function should be called when the device driver has received
* a packet from the network. The packet from the device driver must
* be present in the uip_buf buffer, and the length of the packet
* should be placed in the uip_len variable.
*
* When the function returns, there may be an outbound packet placed
* in the uip_buf packet buffer. If so, the uip_len variable is set to
* the length of the packet. If no packet is to be sent out, the
* uip_len variable is set to 0.
*
* The usual way of calling the function is presented by the source
* code below.
\code
uip_len = devicedriver_poll();
if(uip_len > 0) {
uip_input();
if(uip_len > 0) {
devicedriver_send();
}
}
\endcode
*
* \note If you are writing a uIP device driver that needs ARP
* (Address Resolution Protocol), e.g., when running uIP over
* Ethernet, you will need to call the uIP ARP code before calling
* this function:
\code
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
uip_len = ethernet_devicedrver_poll();
if(uip_len > 0) {
if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
uip_arp_ipin();
uip_input();
if(uip_len > 0) {
uip_arp_out();
ethernet_devicedriver_send();
}
} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
uip_arp_arpin();
if(uip_len > 0) {
ethernet_devicedriver_send();
}
}
\endcode
*
* \hideinitializer
*/
#define uip_input() uip_process(UIP_DATA)
/**
* Periodic processing for a connection identified by its number.
*
* This function does the necessary periodic processing (timers,
* polling) for a uIP TCP conneciton, and should be called when the
* periodic uIP timer goes off. It should be called for every
* connection, regardless of whether they are open of closed.
*
* When the function returns, it may have an outbound packet waiting
* for service in the uIP packet buffer, and if so the uip_len
* variable is set to a value larger than zero. The device driver
* should be called to send out the packet.
*
* The ususal way of calling the function is through a for() loop like
* this:
\code
for(i = 0; i < UIP_CONNS; ++i) {
uip_periodic(i);
if(uip_len > 0) {
devicedriver_send();
}
}
\endcode
*
* \note If you are writing a uIP device driver that needs ARP
* (Address Resolution Protocol), e.g., when running uIP over
* Ethernet, you will need to call the uip_arp_out() function before
* calling the device driver:
\code
for(i = 0; i < UIP_CONNS; ++i) {
uip_periodic(i);
if(uip_len > 0) {
uip_arp_out();
ethernet_devicedriver_send();
}
}
\endcode
*
* \param conn The number of the connection which is to be periodically polled.
*
* \hideinitializer
*/
#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
uip_process(UIP_TIMER); } while (0)
/**
*
*
*/
#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
/**
* Perform periodic processing for a connection identified by a pointer
* to its structure.
*
* Same as uip_periodic() but takes a pointer to the actual uip_conn
* struct instead of an integer as its argument. This function can be
* used to force periodic processing of a specific connection.
*
* \param conn A pointer to the uip_conn struct for the connection to
* be processed.
*
* \hideinitializer
*/
#define uip_periodic_conn(conn) do { uip_conn = conn; \
uip_process(UIP_TIMER); } while (0)
/**
* Reuqest that a particular connection should be polled.
*
* Similar to uip_periodic_conn() but does not perform any timer
* processing. The application is polled for new data.
*
* \param conn A pointer to the uip_conn struct for the connection to
* be processed.
*
* \hideinitializer
*/
#define uip_poll_conn(conn) do { uip_conn = conn; \
uip_process(UIP_POLL_REQUEST); } while (0)
#if UIP_UDP
/**
* Periodic processing for a UDP connection identified by its number.
*
* This function is essentially the same as uip_periodic(), but for
* UDP connections. It is called in a similar fashion as the
* uip_periodic() function:
\code
for(i = 0; i < UIP_UDP_CONNS; i++) {
uip_udp_periodic(i);
if(uip_len > 0) {
devicedriver_send();
}
}
\endcode
*
* \note As for the uip_periodic() function, special care has to be
* taken when using uIP together with ARP and Ethernet:
\code
for(i = 0; i < UIP_UDP_CONNS; i++) {
uip_udp_periodic(i);
if(uip_len > 0) {
uip_arp_out();
ethernet_devicedriver_send();
}
}
\endcode
*
* \param conn The number of the UDP connection to be processed.
*
* \hideinitializer
*/
#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
uip_process(UIP_UDP_TIMER); } while (0)
/**
* Periodic processing for a UDP connection identified by a pointer to
* its structure.
*
* Same as uip_udp_periodic() but takes a pointer to the actual
* uip_conn struct instead of an integer as its argument. This
* function can be used to force periodic processing of a specific
* connection.
*
* \param conn A pointer to the uip_udp_conn struct for the connection
* to be processed.
*
* \hideinitializer
*/
#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
uip_process(UIP_UDP_TIMER); } while (0)
#endif /* UIP_UDP */
/**
* The uIP packet buffer.
*
* The uip_buf array is used to hold incoming and outgoing
* packets. The device driver should place incoming data into this
* buffer. When sending data, the device driver should read the link
* level headers and the TCP/IP headers from this buffer. The size of
* the link level headers is configured by the UIP_LLH_LEN define.
*
* \note The application data need not be placed in this buffer, so
* the device driver must read it from the place pointed to by the
* uip_appdata pointer as illustrated by the following example:
\code
void
devicedriver_send(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -