📄 uip.h
字号:
#ifndef __UIP_H__
#define __UIP_H__
#include "uipopt.h"
void uip_send(unsigned char * mdata, int len);
/*-----------------------------------------------------------------------------------*/
/* 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
*
* \param port A 16-bit port number in network byte order.
*/
void uip_unlisten(u16_t port);
/**
* Connect to a remote host using TCP.
*
* This function is used to start a new connection to the specified
* port on the specied host. It allocates a new connection identifier,
* sets the connection to the SYN_SENT state and sets the
* retransmission timer to 0. This will cause a TCP SYN segment to be
* sent out the next time this connection is periodically processed,
* which usually is done within 0.5 seconds after the call to
* uip_connect().
*
* \note This function is avaliable only if support for active open
* has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
*
* \note Since this function requires the port number to be in network
* byte order, a convertion using HTONS() or htons() is necessary.
*
\code
u16_t ipaddr[2];
uip_ipaddr(ipaddr, 192,168,1,2);
uip_connect(ipaddr, HTONS(80));
\endcode
*
* \param ripaddr A pointer to a 4-byte array representing the IP
* address of the remote hot.
*
* \param port A 16-bit port number in network byte order.
*
* \return A pointer to the uIP connection identifier for the new connection,
* or NULL if no connection could be allocated.
*
*/
struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port);
/**
* \internal
*
* Check if a connection has outstanding (i.e., unacknowledged) data.
*
* \param conn A pointer to the uip_conn structure for the connection.
*
* \hideinitializer
*/
#define uip_outstanding(conn) ((conn)->len)
/**
* Send data on the current connection.
*
* This function is used to send out a single segment of TCP
* data. Only applications that have been invoked by uIP for event
* processing can send data.
*
* The amount of data that actually is sent out after a call to this
* funcion is determined by the maximum amount of data TCP allows. uIP
* will automatically crop the data so that only the appropriate
* amount of data is sent. The function uip_mss() can be used to query
* uIP for the amount of data that actually will be sent.
*
* \note This function does not guarantee that the sent data will
* arrive at the destination. If the data is lost in the network, the
* application will be invoked with the uip_rexmit() event being
* set. The application will then have to resend the data using this
* function.
*
* \param data A pointer to the data which is to be sent.
*
* \param len The maximum amount of data bytes to be sent.
*
* \hideinitializer
*/
//#define uip_send(data, len) do { uip_sappdata = (data); uip_slen = (len);} while(0)
/**
* The length of any incoming data that is currently avaliable (if avaliable)
* in the uip_appdata buffer.
*
* The test function uip_data() must first be used to check if there
* is any data available at all.
*
* \hideinitializer
*/
#define uip_datalen() uip_len
/**
* The length of any out-of-band data (urgent data) that has arrived
* on the connection.
*
* \note The configuration parameter UIP_URGDATA must be set for this
* function to be enabled.
*
* \hideinitializer
*/
#define uip_urgdatalen() uip_urglen
/**
* Close the current connection.
*
* This function will close the current connection in a nice way.
*
* \hideinitializer
*/
#define uip_close() (uip_flags = UIP_CLOSE)
/**
* Abort the current connection.
*
* This function will abort (reset) the current connection, and is
* usually used when an error has occured that prevents using the
* uip_close() function.
*
* \hideinitializer
*/
#define uip_abort() (uip_flags = UIP_ABORT)
/**
* Tell the sending host to stop sending data.
*
* This function will close our receiver's window so that we stop
* receiving data for the current connection.
*
* \hideinitializer
*/
#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
/**
* Find out if the current connection has been previously stopped with
* uip_stop().
*
* \hideinitializer
*/
#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
/**
* Restart the current connection, if is has previously been stopped
* with uip_stop().
*
* This function will open the receiver's window again so that we
* start receiving data for the current connection.
*
* \hideinitializer
*/
#define uip_restart() do { uip_flags |= UIP_NEWDATA; \
uip_conn->tcpstateflags &= ~UIP_STOPPED; \
} while(0)
/* uIP tests that can be made to determine in what state the current
connection is, and what the application function should do. */
/**
* Is new incoming data available?
*
* Will reduce to non-zero if there is new data for the application
* present at the uip_appdata pointer. The size of the data is
* avaliable through the uip_len variable.
*
* \hideinitializer
*/
#define uip_newdata() (uip_flags & UIP_NEWDATA)
/**
* Has previously sent data been acknowledged?
*
* Will reduce to non-zero if the previously sent data has been
* acknowledged by the remote host. This means that the application
* can send new data.
*
* \hideinitializer
*/
#define uip_acked() (uip_flags & UIP_ACKDATA)
/**
* Has the connection just been connected?
*
* Reduces to non-zero if the current connection has been connected to
* a remote host. This will happen both if the connection has been
* actively opened (with uip_connect()) or passively opened (with
* uip_listen()).
*
* \hideinitializer
*/
#define uip_connected() (uip_flags & UIP_CONNECTED)
/**
* Has the connection been closed by the other end?
*
* Is non-zero if the connection has been closed by the remote
* host. The application may then do the necessary clean-ups.
*
* \hideinitializer
*/
#define uip_closed() (uip_flags & UIP_CLOSE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -