📄 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.1 2004/05/09 00:24:47 Louis Exp $
*
*/
#ifndef __UIP_H__
#define __UIP_H__
#include "uipopt.h"
/*-----------------------------------------------------------------------------------*/
/* 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.
*
* \param addr A pointer to a 4-byte representation of the IP address.
*
* \hideinitializer
*/
#define uip_sethostaddr(addr) do { uip_hostaddr[0] = addr[0]; \
uip_hostaddr[1] = addr[1]; } while(0)
/**
* 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.
*
* \param addr A pointer to a 4-byte array that will be filled in with
* the currently configured IP address.
*
* \hideinitializer
*/
#define uip_gethostaddr(addr) do { addr[0] = uip_hostaddr[0]; \
addr[1] = uip_hostaddr[1]; } while(0)
/** @} */
/**
* \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);
/** @} */
/**
* \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)
/**
* 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)
#if UIP_UDP
/**
* Periodic processing for a UDP connection identified by its number.
*
* This function is essentially the same as uip_prerioic(), 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)
{
hwsend(&uip_buf[0], UIP_LLH_LEN);
hwsend(&uip_buf[UIP_LLH_LEN], 40);
hwsend(uip_appdata, uip_len - 40 - UIP_LLH_LEN);
}
\endcode
*/
extern u8_t uip_buf[UIP_BUFSIZE+2];
/** @} */
/*-----------------------------------------------------------------------------------*/
/* Functions that are used by the uIP application program. Opening and
* closing connections, sending and receiving data, etc. is all
* handled by the functions below.
*/
/**
* \defgroup uipappfunc uIP application functions
* @{
*
* Functions used by an application running of top of uIP.
*/
/**
* Start listening to the specified port.
*
* \note Since this function expects the port number in network byte
* order, a conversion using HTONS() or htons() is necessary.
*
\code
uip_listen(HTONS(80));
\endcode
*
* \param port A 16-bit port number in network byte order.
*/
void uip_listen(u16_t port);
/**
* Stop listening to the specified port.
*
* \note Since this function expects the port number in network byte
* order, a conversion using HTONS() or htons() is necessary.
*
\code
uip_unlisten(HTONS(80));
\endcode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -