netif.h
来自「AMLOGIC DPF source code」· C头文件 代码 · 共 336 行
H
336 行
/*******************************************************************
*
* Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
*
* Description:
*
* Author: Amlogic Software
* Created: Fri Nov 11 00:41:28 2005
*
*******************************************************************/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __LWIP_NETIF_H__
#define __LWIP_NETIF_H__
#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/ether_phy.h"
#include "lwip/ip_addr.h"
#include "lwip/inet.h"
#include "lwip/pbuf.h"
#if LWIP_DHCP
# include "lwip/dhcp.h"
#endif
#include <lwip/igmp.h>
#include <listop.h>
/** must be the maximum of all used hardware address lengths
across all types of interfaces in use */
#define NETIF_MAX_HWADDR_LEN 6U
/** TODO: define the use (where, when, whom) of netif flags */
/** whether the network interface is 'up'. this is
* a software flag used to control whether this network
* interface is enabled and processes traffic.
*/
#define NETIF_FLAG_UP (1<<0)
/** if set, the netif has broadcast capability */
#define NETIF_FLAG_BROADCAST (1<<1)
/** if set, the netif is one end of a point-to-point connection */
#define NETIF_FLAG_POINTTOPOINT (1<<2)
/** if set, the interface is configured using DHCP */
#define NETIF_FLAG_DHCP (1<<3)
/* Loopback flag */
#define NETIF_FLAG_LOOPBACK (1<<4)
/* Put hardware into promiscuous mode */
#define NETIF_FLAG_PROMISC (1<<5)
/* Accept all multicast packets */
#define NETIF_FLAG_ALLMULTI (1<<6)
/* AVOS extension, interface enable/disable flag */
#define NETIF_FLAG_ENABLE (1<<7)
#define ARPHRD_ETHER 1 /* Ethernet 10Mbps */
#define ETH_ALEN 6 /* Octets in one ethernet addr */
#define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
#define IFNAMSIZ 16 /* Interface name size */
/** Generic data structure used for all lwIP network interfaces.
* The following fields should be filled in by the initialization
* function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
struct router_info;
#ifdef AVOS
/** Wireless ioctl handler.
* Defined in <net/iw_handler.h> */
struct iw_handler_def;
#endif /* AVOS */
struct netif {
/* List of multicast groups subscribed to on this interface */
list_t multi;
/** pointer to next in linked list */
struct netif *next;
/** IP address configuration in network byte order */
struct ip_addr ip_addr;
struct ip_addr netmask;
struct ip_addr gw;
/** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */
err_t (* input)(struct pbuf *p, struct netif *inp);
/** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically
* first resolves the hardware address, then sends the packet. */
err_t (* output)(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr);
/** This function is called by the ARP module when it wants
* to send a packet on the interface. This function outputs
* the pbuf as-is on the link medium. */
err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
/** This function updates multicast hash tables for ethernet
* interfaces */
err_t (* update_multi)(struct netif *netif);
/** This function updates the hardware configuration */
err_t (* update_config)(struct netif *netif);
/** This field can be set by the device driver and could point
* to state information for the device. */
void *state;
/* AVOS sys event we subscribe to for change notifications. */
#ifdef AVOS
AVSysEvent_t sys_event_id;
#endif
#if LWIP_DHCP
/** the DHCP client state information for this netif */
struct dhcp *dhcp;
#endif
/* PHY configuration information */
ether_phy_t phy;
/** number of bytes used in hwaddr */
unsigned char hwaddr_len;
/** link level hardware address of this interface */
unsigned char hwaddr[NETIF_MAX_HWADDR_LEN];
/** maximum transfer unit (in bytes) */
u16_t mtu;
/** flags (see NETIF_FLAG_ above) */
u8_t flags;
/** link type */
u8_t link_type;
/** descriptive abbreviation */
char *name;
/** number of this interface */
u8_t num;
#ifdef HAS_USB_NET
/* Device driver specific initialization routine. */
int (* open) (struct netif * netif);
int (* close) (struct netif * netif);
int (* ioctl) (struct netif * netif, void * ifr, int cmd);
const struct iw_handler_def * wireless_handlers;
#endif /* HAS_USB_NET */
};
/** The list of network interfaces. */
extern struct netif *netif_list;
/** The default network interface. */
extern struct netif *netif_default;
/* netif_init() must be called first. */
void netif_init(void);
struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw,
void *state,
err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif));
void
netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw);
void netif_remove(struct netif * netif);
/* Returns a network interface given its name. The name is of the form
"et0", where the first two letters are the "name" field in the
netif structure, and the digit is in the num field in the same
structure. */
struct netif *netif_find(char *name);
extern struct netif *netif_get_default(void);
void netif_set_default(struct netif *netif);
extern struct netif *netif_create (char *name);
/* Initialize a single interface */
extern struct netif *netif_init_interface (struct netif *netif, char *name);
void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
void netif_set_gw(struct netif *netif, struct ip_addr *gw);
void netif_set_up(struct netif *netif);
void netif_set_down(struct netif *netif);
u8_t netif_is_up(struct netif *netif);
extern struct netif *netif_next(struct netif *netif);
extern void netif_remove_multi(struct netif *netif, struct ip_addr group);
extern struct in_multi *netif_find_multi (struct netif *netif, struct ip_addr group);
extern int netif_add_multi(struct netif *netif, struct ip_addr group);
extern void netif_unlock_multi(void);
extern void netif_lock_multi (void);
extern void netif_enable(struct netif *netif);
extern void netif_disable(struct netif *netif);
extern u8_t netif_is_enabled(struct netif *netif);
#ifdef AVOS
/**
* Subscribe to changes on netif.
*
* @param sub Event subscriber.
* @param cb Event Callback.
*/
extern void
netif_subscribe(struct netif *netif,
EventSubscriber_t *sub,
void (*cb)(unsigned));
#endif
/**
* Set physical layer hardware configuration
*
* @param netif a pre-allocated netif structure
* @param phy_speed Speed you want configured for this interface
* @param phy_duplex Duplex you want configured for this interface
*/
extern void netif_phy_config(struct netif *netif,
EtherPhySpeed phy_speed,
EtherPhyDuplex phy_duplex);
/**
* Retrieve current PHY operational status
*
* @param netif a pre-allocated netif structure
* @param phy_speed Pointer to variable to store operational speed
* @param phy_duplex Pointer to variable to store operational duplex
*/
extern void netif_phy_get_status(struct netif *netif,
EtherPhySpeed *phy_speed,
EtherPhyDuplex *phy_duplex);
/**
* Retrieve current PHY configuration
*
* @param netif a pre-allocated netif structure
* @param phy_speed Pointer to variable to store configured speed
* @param phy_duplex Pointer to variable to store configured duplex
*/
extern void netif_phy_get_config(struct netif *netif,
EtherPhySpeed *phy_speed,
EtherPhyDuplex *phy_duplex);
/**
* Poll the hardware for physical layer changes.
* This will set the operational speed and duplex when
* the interface status changes.
*
* @param netif a pre-allocated netif structure
*/
extern void netif_phy_poll(struct netif *netif);
extern int netif_ioctl(int socket, int cmd, void *param);
struct netif_config
{
char name[IFNAMSIZ + 1];
u8_t has_mtu;
u16_t mtu;
u8_t has_ipaddr;
u8_t dhcp;
struct in_addr ipaddr;
struct in_addr netmask;
struct in_addr gateway;
struct in_addr primary_dns;
struct in_addr secondary_dns;
u8_t has_status;
int status;
u8_t has_hwaddr;
unsigned char hwaddr[NETIF_MAX_HWADDR_LEN];
};
/**
* Structure for storing netif configuration setting in EEPROM.
*
* Total size of this structure should *NOT* change, otherwise all old
* configuration saved with old code can *NOT* read back correctly.
*
* There is 32 bytes of reserved space for future extension, please
* adjust that if new fields needs to be inserted.
*/
#define NETWORK_CONFIG_MAGIC 0xADDC
#define NETWORK_CONFIG_VERSION 0x0001
struct netif_setting
{
short magic;
short version;
char name[IFNAMSIZ + 1];
unsigned char status;
unsigned char dhcp;
struct in_addr ipaddr;
struct in_addr netmask;
struct in_addr gateway;
struct in_addr primary_dns;
struct in_addr secondary_dns;
char unused[32];
};
int
netif_get_config(struct netif_config *config);
int
netif_set_config(struct netif_config *config);
typedef int (*netif_setting_func) (struct netif_setting *);
void
netif_setting_func_init(netif_setting_func read_func,
netif_setting_func write_func);
#endif /* __LWIP_NETIF_H__ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?