netdev.h
来自「ADS下的bios工程」· C头文件 代码 · 共 275 行
H
275 行
#ifndef _BIOS_NETDEV_H#define _BIOS_NETDEV_H#include <bios/types.h>/* HEX NUMBER ENDIAN TRANSLATION */#ifdef CONFIG_CPU_BIG_ENDIAN#define htonl(x) (x)#define htons(x) (x)#else#define htonl(x) (((x) & 0x000000ff) << 24 |\ ((x) & 0x0000ff00) << 8 |\ ((x) & 0x00ff0000) >> 8 |\ ((x) & 0xff000000) >> 24)#define htons(x) (((x) & 0x000000ff) << 8 |\ ((x) & 0x0000ff00) >> 8)#endif/* Define structure media type */typedef enum { media_autodetect, media_coax, media_utp, media_aui} media_t;/* ********************************************//* Define structure for network device buffer *//* ********************************************/struct buflist { void *data; int size; struct buflist *next;}; /* ********************************************//* Ethernet Protocol *//* ********************************************/#define SIZEOF_ETHHDR 14#define ETH_P_UDP 0x11#define ETH_P_IP 0x0800#define ETH_P_ARP 0x0806#define ETH_ALEN 6 /* 6 bytes */#define ETH_DATA_LEN 1506 /* 6 bytes */#define ETH_FRAME_LEN 1514+22 /* 1536 bytes */#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */struct ethhdr { unsigned char eth_dest[ETH_ALEN]; unsigned char eth_source[ETH_ALEN]; unsigned short eth_proto;};/*********************************************//* ARP Protocol *//*********************************************/#define ARPHRD_ETHER 1 /* Ethernet 10/100Mbps. */struct arphdr { u16 ar_hrd; /* format of hardware address */ u16 ar_pro; /* format of protocol address */ u8 ar_hln; /* length of hardware address */ u8 ar_pln; /* length of protocol address */ u16 ar_op; /* ARP opcode (command) */ u8 ar_sha[6]; /* sender h/w address */ u8 ar_sip[4]; /* sender ip address */ u8 ar_tha[6]; /* target h/w address */ u8 ar_tip[4]; /* target ip address */};/*********************************************//* IP Protocal *//*********************************************/#ifndef INADDR_ANY#define INADDR_ANY (0xffffffffUL)#endifstruct sin { u32 sin_addr; u16 sin_port;};struct iphdr {#ifdef BIG_ENDIAN u8 ip_ver:4; u8 ip_ihl:4;#else u8 ip_ihl:4; u8 ip_ver:4;#endif u8 ip_tos; u16 ip_len; u16 ip_id; u16 ip_frag; u8 ip_ttl; u8 ip_proto; u16 ip_check; u32 ip_source; u32 ip_dest;};/*********************************************//* UDP protocol header *//*********************************************/struct udphdr { u16 udp_source; u16 udp_dest; u16 udp_length; u16 udp_check;};/*********************************************//* BOOTP protocol header *//*********************************************/struct bootp_pkt { /* BOOTP packet format */ u8 op; /* 1=request, 2=reply */ u8 htype; /* HW address type */ u8 hlen; /* HW address length */ u8 hops; /* Used only by gateways */ u32 xid; /* Transaction ID */ u16 secs; /* Seconds since we started */ u16 flags; /* Just what it says */ u32 client_ip; /* Client's IP address if known */ u32 your_ip; /* Assigned IP address */ u32 server_ip; /* Server's IP address */ u32 relay_ip; /* IP address of BOOTP relay */ u8 hw_addr[16]; /* Client's HW address */ u8 serv_name[64]; /* Server host name */ u8 boot_file[128]; /* Name of boot file */ u8 vendor_area[128]; /* Area for extensions */};/*********************************************//* TFTP PROTOCOL *//*********************************************/#define CONF_TIMEOUT_MINOR_BASE 10#define CONF_TIMEOUT_MAJOR_BASE 500#define CONF_TIMEOUT_MULT 5/4#define CONF_TIMEOUT_MAX 1500#define CONF_RETRIES 10/* TFTP packet opcode(2bytes) */ #define TFTP_RRQ 1 /* Read Request */#define TFTP_WRQ 2 /* Write Request */#define TFTP_DATA 3 /* Data */#define TFTP_ACK 4 /* Acknowledgment */#define TFTP_ERROR 5 /* TFTP Error */#define TFTP_STATE_RRQ 0#define TFTP_STATE_ACK 1#define TFTP_STATE_COMPLETE 2/* TFTP error code (2bytes) */#define TFTP_ERR_UNDEF 0 /* Not defined, */#define TFTP_ERR_NOFILE 1 /* File not found */#define TFTP_ERR_ACCESS 2 /* Access violation */#define TFTP_ERR_NOSPACE 3 /* Disk full or allocation exceeded */#define TFTP_ERR_BADOP 4 /* Illegal TFTP operation */#define TFTP_ERR_BADID 5 /* Unknown port number */#define TFTP_ERR_FILE 6 /* File already exists */#define TFTP_ERR_NOUSER 7 /* No such user *//* Define data structure for TFTP packet format */struct tftp_rrq { u16 cmd; u8 filename[100];};struct tftp_ack { u16 cmd; u16 block;};struct tftp_data { u16 cmd; u16 block; u8 data[512];};/**************************************************//* Define structure for network device operations *//**************************************************/struct netdev { /* ethernet transfer functions */ struct buflist *(*eth_header)(struct netdev *nd, u8 *dest, u16 proto, struct buflist *blp); int (*eth_send)(struct netdev *nd, struct buflist *blp); int (*eth_recv)(struct netdev *nd, u16 proto, u8 *buf); char *name; /* ethernet driver's functions */ int (*open)(struct netdev *); int (*close)(struct netdev *); //int (*status)(struct netdev *); //int (*set_media)(struct netdev *, media_t media); //int (*check_media)(struct netdev *); int (*send)(struct netdev *, void *buffer, int size); int (*recv)(struct netdev *, void *buf); u32 base_addr; u8 hw_addr[6]; u8 hw_broadcast[6]; u8 hw_addr_len; u8 boot_file[128]; u32 ip_addr; u32 serv_ip_addr; u32 default_gw; media_t media; int up:1; u8 tha_addr[6]; struct netdev *next;};/* * Network device statistics. Akin to the 2.0 ether stats but * with byte counters. */ struct net_device_stats{ unsigned long rx_packets; /* total packets received */ unsigned long tx_packets; /* total packets transmitted */ unsigned long rx_bytes; /* total bytes received */ unsigned long tx_bytes; /* total bytes transmitted */ unsigned long rx_errors; /* bad packets received */ unsigned long tx_errors; /* packet transmit problems */ unsigned long rx_dropped; /* no space in linux buffers */ unsigned long tx_dropped; /* no space available in linux */ unsigned long multicast; /* multicast packets received */ unsigned long collisions; /* detailed rx_errors: */ unsigned long rx_length_errors; unsigned long rx_over_errors; /* receiver ring buff overflow */ unsigned long rx_crc_errors; /* recved pkt with crc error */ unsigned long rx_frame_errors; /* recv'd frame alignment error */ unsigned long rx_fifo_errors; /* recv'r fifo overrun */ unsigned long rx_missed_errors; /* receiver missed packet */ /* detailed tx_errors */ unsigned long tx_aborted_errors; unsigned long tx_carrier_errors; unsigned long tx_fifo_errors; unsigned long tx_heartbeat_errors; unsigned long tx_window_errors; /* for cslip etc */ unsigned long rx_compressed; unsigned long tx_compressed;};/* Define network device probe function */struct probe_dev{ int (*probe)(struct netdev *dev); int status; /* non-zero if autoprobe has failed */};extern char *in_ntoa(u32 addr);extern unsigned int in_aton(char *s);#endif /* End of _BIOS_NETDEV_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?