2007-08-27 01:12:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* uip-arch.h
|
|
|
|
* Defines architecture-specific device driver interfaces to uIP
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* Derived largely from portions of uIP with has a similar BSD-styple license:
|
|
|
|
*
|
|
|
|
* 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. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "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
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIP_ARCH_H
|
|
|
|
#define __UIP_ARCH_H
|
|
|
|
|
2007-09-16 19:46:25 +02:00
|
|
|
#include <nuttx/config.h>
|
2007-08-27 01:12:17 +02:00
|
|
|
#include <sys/types.h>
|
2007-09-16 19:46:25 +02:00
|
|
|
#include <sys/ioctl.h>
|
2007-11-30 21:46:29 +01:00
|
|
|
#include <net/if.h>
|
2007-08-27 01:12:17 +02:00
|
|
|
#include <net/uip/uip.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <net/uip/uipopt.h>
|
2007-12-11 15:28:16 +01:00
|
|
|
#include <net/ethernet.h>
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This structure collects information that is specific to a specific network
|
|
|
|
* interface driver. If the hardware platform supports only a single instance
|
|
|
|
* of this structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct uip_driver_s
|
|
|
|
{
|
2007-09-16 19:46:25 +02:00
|
|
|
/* This link is used to maintain a single-linked list of ethernet drivers.
|
|
|
|
* Must be the first field in the structure due to blink type casting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
FAR struct uip_driver_s *flink;
|
|
|
|
|
|
|
|
/* This is the name of network device assigned when netdev_register was called.
|
|
|
|
* This name is only used to support socket ioctl lookups by device name
|
|
|
|
* Examples: "eth0"
|
|
|
|
*/
|
|
|
|
|
|
|
|
char d_ifname[IFNAMSIZ];
|
|
|
|
#endif
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/* Device identitity */
|
|
|
|
|
2007-12-11 15:28:16 +01:00
|
|
|
struct ether_addr d_mac; /* Device MAC address */
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
/* Network identity */
|
|
|
|
|
|
|
|
uip_ipaddr_t d_ipaddr; /* Host IP address assigned to the network interface */
|
|
|
|
uip_ipaddr_t d_draddr; /* Default router IP address */
|
|
|
|
uip_ipaddr_t d_netmask; /* Network subnet mask */
|
|
|
|
|
2007-09-16 19:46:25 +02:00
|
|
|
/* The d_buf array is used to hold incoming and outgoing
|
2007-09-16 00:45:45 +02:00
|
|
|
* 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
|
|
|
|
* d_appdata pointer as illustrated by the following example:
|
|
|
|
*
|
|
|
|
* void
|
|
|
|
* devicedriver_send(void)
|
|
|
|
* {
|
2007-11-22 15:42:52 +01:00
|
|
|
* hwsend(&dev->d_buf[0], UIP_LLH_LEN);
|
|
|
|
* if(dev->d_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN)
|
|
|
|
* {
|
|
|
|
* hwsend(&dev->d_buf[UIP_LLH_LEN], dev->d_len - UIP_LLH_LEN);
|
|
|
|
* }
|
|
|
|
* else
|
|
|
|
* {
|
|
|
|
* hwsend(&dev->d_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
|
|
|
|
* hwsend(dev->d_appdata, dev->d_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
|
|
|
|
* }
|
|
|
|
* }
|
2007-09-16 00:45:45 +02:00
|
|
|
*/
|
|
|
|
|
2007-11-20 00:09:39 +01:00
|
|
|
uint8 d_buf[CONFIG_NET_BUFSIZE + 2];
|
2007-09-16 00:45:45 +02:00
|
|
|
|
|
|
|
/* d_appdata points to the location where application data can be read from
|
|
|
|
* or written into a packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8 *d_appdata;
|
|
|
|
|
|
|
|
/* This is a pointer into d_buf where a user application may append
|
|
|
|
* data to be sent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8 *d_snddata;
|
|
|
|
|
2007-11-22 15:42:52 +01:00
|
|
|
#ifdef CONFIG_NET_TCPURGDATA
|
|
|
|
/* This pointer points to any urgent TCP data that has been received. Only
|
|
|
|
* present if compiled with support for urgent data (CONFIG_NET_TCPURGDATA).
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8 *d_urgdata;
|
|
|
|
|
|
|
|
/* Length of the (received) urgent data */
|
|
|
|
|
|
|
|
uint16 d_urglen;
|
|
|
|
#endif
|
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
/* The length of the packet in the d_buf buffer.
|
|
|
|
*
|
|
|
|
* Holds the length of the packet in the d_buf buffer.
|
|
|
|
*
|
|
|
|
* When the network device driver calls the uIP input function,
|
|
|
|
* d_len should be set to the length of the packet in the d_buf
|
|
|
|
* buffer.
|
|
|
|
*
|
|
|
|
* When sending packets, the device driver should use the contents of
|
|
|
|
* the d_len variable to determine the length of the outgoing
|
|
|
|
* packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint16 d_len;
|
|
|
|
|
|
|
|
/* When d_buf contains outgoing xmit data, xmtlen is nonzero and represents
|
|
|
|
* the amount of appllcation data after d_snddata
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint16 d_sndlen;
|
2007-11-02 21:20:34 +01:00
|
|
|
|
|
|
|
/* Driver callbacks */
|
|
|
|
|
2007-11-06 17:17:50 +01:00
|
|
|
int (*d_ifup)(struct uip_driver_s *dev);
|
|
|
|
int (*d_ifdown)(struct uip_driver_s *dev);
|
2007-11-22 15:42:52 +01:00
|
|
|
int (*d_txavail)(struct uip_driver_s *dev);
|
2007-11-02 21:20:34 +01:00
|
|
|
|
|
|
|
/* Drivers may attached device-specific, private information */
|
|
|
|
|
|
|
|
void *d_private;
|
2007-09-16 00:45:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2008-08-02 19:22:22 +02:00
|
|
|
* Public Function Prototypes
|
2007-09-16 00:45:45 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2007-08-27 01:12:17 +02:00
|
|
|
/* 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
|
2007-09-16 00:45:45 +02:00
|
|
|
* be present in the d_buf buffer, and the length of the packet
|
|
|
|
* should be placed in the d_len field.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* When the function returns, there may be an outbound packet placed
|
2007-09-16 00:45:45 +02:00
|
|
|
* in the d_buf packet buffer. If so, the d_len field is set to
|
2007-08-27 01:12:17 +02:00
|
|
|
* the length of the packet. If no packet is to be sent out, the
|
2007-09-16 00:45:45 +02:00
|
|
|
* d_len field is set to 0.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* The usual way of calling the function is presented by the source
|
|
|
|
* code below.
|
|
|
|
*
|
2007-09-16 00:45:45 +02:00
|
|
|
* dev->d_len = devicedriver_poll();
|
|
|
|
* if(dev->d_len > 0) {
|
2007-11-07 19:54:35 +01:00
|
|
|
* uip_input(dev);
|
2007-09-16 00:45:45 +02:00
|
|
|
* if(dev->d_len > 0) {
|
2007-08-27 01:12:17 +02:00
|
|
|
* devicedriver_send();
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
*
|
2007-09-16 00:45:45 +02:00
|
|
|
* #define BUF ((struct uip_eth_hdr *)&dev->d_buf[0])
|
|
|
|
* dev->d_len = ethernet_devicedrver_poll();
|
|
|
|
* if(dev->d_len > 0) {
|
2007-08-27 01:12:17 +02:00
|
|
|
* if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
|
|
|
|
* uip_arp_ipin();
|
2007-11-07 19:54:35 +01:00
|
|
|
* uip_input(dev);
|
2007-09-16 00:45:45 +02:00
|
|
|
* if(dev->d_len > 0) {
|
2007-08-27 01:12:17 +02:00
|
|
|
* uip_arp_out();
|
2007-11-06 00:04:16 +01:00
|
|
|
* devicedriver_send();
|
2007-08-27 01:12:17 +02:00
|
|
|
* }
|
|
|
|
* } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
|
|
|
|
* uip_arp_arpin();
|
2007-09-16 00:45:45 +02:00
|
|
|
* if(dev->d_len > 0) {
|
2007-11-06 00:04:16 +01:00
|
|
|
* devicedriver_send();
|
2007-08-27 01:12:17 +02:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
extern void uip_input(struct uip_driver_s *dev);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-07 23:54:51 +01:00
|
|
|
/* Polling of connections
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-07 23:54:51 +01:00
|
|
|
* These functions will traverse each active uIP connection structure and
|
|
|
|
* perform appropriate operatios: uip_timer() will perform TCP timer
|
|
|
|
* operations (and UDP polling operations); uip_poll() will perform TCP
|
|
|
|
* and UDP polling operations. The CAN driver MUST implement logic to
|
|
|
|
* periodically call uip_timer(); uip_poll() may be called asychronously
|
|
|
|
* from the network driver can accept another outgoing packet.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-07 23:54:51 +01:00
|
|
|
* In both cases, these functions will call the provided callback function
|
|
|
|
* for every active connection. Polling will continue until all connections
|
|
|
|
* have been polled or until the user-suplied function returns a non-zero
|
|
|
|
* value (which it should do only if it cannot accept further write data).
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-06 00:04:16 +01:00
|
|
|
* When the callback function is called, there may be an outbound packet
|
|
|
|
* waiting for service in the uIP packet buffer, and if so the d_len field
|
2007-11-07 23:54:51 +01:00
|
|
|
* is set to a value larger than zero. The device driver should then send
|
|
|
|
* out the packet.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-06 00:04:16 +01:00
|
|
|
* Example:
|
|
|
|
* int driver_callback(struct uip_driver_dev *dev)
|
|
|
|
* {
|
|
|
|
* if (dev->d_len > 0)
|
2007-09-02 23:58:35 +02:00
|
|
|
* {
|
2007-11-06 00:04:16 +01:00
|
|
|
* devicedriver_send();
|
|
|
|
* return 1; <-- Terminates polling if necessary
|
2007-08-27 01:12:17 +02:00
|
|
|
* }
|
2007-11-06 00:04:16 +01:00
|
|
|
* return 0;
|
|
|
|
* }
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-06 00:04:16 +01:00
|
|
|
* ...
|
2007-11-07 23:54:51 +01:00
|
|
|
* uip_poll(dev, driver_callback);
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-06 00:04:16 +01:00
|
|
|
* 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 in the callback function
|
|
|
|
* before sending the packet:
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-06 00:04:16 +01:00
|
|
|
* int driver_callback(struct uip_driver_dev *dev)
|
|
|
|
* {
|
|
|
|
* if (dev->d_len > 0)
|
2007-09-03 01:11:10 +02:00
|
|
|
* {
|
2007-11-06 00:04:16 +01:00
|
|
|
* uip_arp_out();
|
|
|
|
* devicedriver_send();
|
|
|
|
* return 1; <-- Terminates polling if necessary
|
2007-08-27 01:12:17 +02:00
|
|
|
* }
|
2007-11-06 00:04:16 +01:00
|
|
|
* return 0;
|
|
|
|
* }
|
2007-08-27 01:12:17 +02:00
|
|
|
*/
|
|
|
|
|
2007-11-06 00:04:16 +01:00
|
|
|
typedef int (*uip_poll_callback_t)(struct uip_driver_s *dev);
|
2007-11-07 23:54:51 +01:00
|
|
|
extern int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback);
|
|
|
|
extern int uip_timer(struct uip_driver_s *dev, uip_poll_callback_t callback, int hsec);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/* By defining UIP_ARCH_CHKSUM, the architecture can replace the following
|
|
|
|
* functions with hardware assisted solutions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Carry out a 32-bit addition.
|
|
|
|
*
|
2007-11-07 19:54:35 +01:00
|
|
|
* op32 - A pointer to a 4-byte array representing a 32-bit
|
|
|
|
* integer in network byte order (big endian). This value may not
|
|
|
|
* be word aligned.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-07 19:54:35 +01:00
|
|
|
* For uip_incr32, the value pointed to by op32 is modified in place
|
|
|
|
* For uip_add32, the value pointed to by op32 is unmodified
|
|
|
|
*
|
|
|
|
* op16 - A 16-bit integer in host byte order.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-07 19:54:35 +01:00
|
|
|
* sum - The location to return the result (32-bit, network byte order,
|
|
|
|
* possibly unaligned).
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-07 19:54:35 +01:00
|
|
|
* uip_add32 only.
|
2007-08-27 01:12:17 +02:00
|
|
|
*/
|
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
extern void uip_add32(const uint8 *op32, uint16 op16, uint8 *sum);
|
|
|
|
extern void uip_incr32(uint8 *op32, uint16 op16);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/* Calculate the Internet checksum over a buffer.
|
|
|
|
*
|
|
|
|
* The Internet checksum is the one's complement of the one's
|
|
|
|
* complement sum of all 16-bit words in the buffer.
|
|
|
|
*
|
|
|
|
* See RFC1071.
|
|
|
|
*
|
|
|
|
* Note: This function is not called in the current version of uIP,
|
|
|
|
* but future versions might make use of it.
|
|
|
|
*
|
|
|
|
* buf A pointer to the buffer over which the checksum is to be
|
|
|
|
* computed.
|
|
|
|
*
|
|
|
|
* len The length of the buffer over which the checksum is to
|
|
|
|
* be computed.
|
|
|
|
*
|
|
|
|
* Return: The Internet checksum of the buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern uint16 uip_chksum(uint16 *buf, uint16 len);
|
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
/* Calculate the IP header checksum of the packet header in d_buf.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* The IP header checksum is the Internet checksum of the 20 bytes of
|
|
|
|
* the IP header.
|
|
|
|
*
|
2007-09-16 00:45:45 +02:00
|
|
|
* Return: The IP header checksum of the IP header in the d_buf
|
2007-08-27 01:12:17 +02:00
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
extern uint16 uip_ipchksum(struct uip_driver_s *dev);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
/* Calculate the TCP checksum of the packet in d_buf and d_appdata.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* The TCP checksum is the Internet checksum of data contents of the
|
|
|
|
* TCP segment, and a pseudo-header as defined in RFC793.
|
|
|
|
*
|
2007-09-16 00:45:45 +02:00
|
|
|
* Note: The d_appdata pointer that points to the packet data may
|
2007-08-27 01:12:17 +02:00
|
|
|
* point anywhere in memory, so it is not possible to simply calculate
|
2007-09-16 00:45:45 +02:00
|
|
|
* the Internet checksum of the contents of the d_buf buffer.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-09-16 00:45:45 +02:00
|
|
|
* Return: The TCP checksum of the TCP segment in d_buf and pointed
|
|
|
|
* to by d_appdata.
|
2007-08-27 01:12:17 +02:00
|
|
|
*/
|
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
extern uint16 uip_tcpchksum(struct uip_driver_s *dev);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
extern uint16 uip_udpchksum(struct uip_driver_s *dev);
|
2008-09-03 01:04:10 +02:00
|
|
|
extern uint16 uip_icmpchksum(struct uip_driver_s *dev);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
#endif /* __UIP_ARCH_H */
|
2008-09-03 01:04:10 +02:00
|
|
|
|