⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ethernet.h

📁 基于S3C2410和SM501的彩屏控制器程序
💻 H
字号:
#ifndef ETHERNET_H
#define ETHERNET_H

//********************** Including Libs **********************
#include <stdio.h>
#include <string.h>
#include "comdef.h"
#include "dm9000.h"

#include "comdef.h"
#include "2410.h"
#include "S3C2410.h"
#include "S3C24x0.h"
#include "uart.h"
#include "global.h"


//**************** Structure & Type Definition ****************
typedef struct {
	uchar		ip_hl_v;	/* header length and version	*/
	uchar		ip_tos;		/* type of service		*/
	ushort		ip_len;		/* total length			*/
	ushort		ip_id;		/* identification		*/
	ushort		ip_off;		/* fragment offset field	*/
	uchar		ip_ttl;		/* time to live			*/
	uchar		ip_p;		/* protocol			*/
	ushort		ip_sum;		/* checksum			*/
	IPaddr_t	ip_src;		/* Source IP address		*/
	IPaddr_t	ip_dst;		/* Destination IP address	*/
	ushort		udp_src;	/* UDP source port		,如果是ICMP包则为类型和代码*/
	ushort		udp_dst;	/* UDP destination port,	如果是ICMP包为校验和	*/
	ushort		udp_len;	/* Length of UDP packet	,如果是ICMP包为标识符	*/
	ushort		udp_xsum;	/* Checksum	,如果是ICMP包为序号,
	序列号从0开始,每发送一次新的回显请求就加1		*/
} IP_t;

typedef struct
{
	uchar		et_dest[6]; 	/* Destination node	*/
	uchar		et_src[6];		/* Source node */
	ushort		et_protlen;		/* Protocol or length */
	uchar		et_dsap;		/* 802 DSAP	*/
	uchar		et_ssap;		/* 802 SSAP	*/
	uchar		et_ctl;			/* 802 control */
	uchar		et_snap1;		/* SNAP	*/
	uchar		et_snap2;
	uchar		et_snap3;
	ushort		et_prot;		/* 802 protocol	*/
} Ethernet_t;

typedef struct
{
	ushort		ar_hrd;		/* Format of hardware address	*/
	ushort		ar_pro;		/* Format of protocol address	*/
	uchar		ar_hln;		/* Length of hardware address,ethernet :6	*/
	uchar		ar_pln;		/* Length of protocol address,ip:4*/
	ushort		ar_op;		/* Operation			*/

	/*
	 * The remaining fields are variable in size, according to
	 * the sizes above, and are defined as appropriate for
	 * specific hardware/protocol combinations.
	 */
	uchar		ar_data[20];//20bytes
#if 0
	uchar		ar_sha[];	/* Sender hardware address	*/
	uchar		ar_spa[];	/* Sender protocol address	*/
	uchar		ar_tha[];	/* Target hardware address	*/
	uchar		ar_tpa[];	/* Target protocol address	*/
#endif /* 0 */
} ARP_t;

typedef struct icmphdr {
	uchar		type;
	uchar		code;
	ushort		checksum;
	union {
		struct {
			ushort	id;
			ushort	sequence;
		} echo;
		ulong	gateway;
		struct {
			ushort	__unused;
			ushort	mtu;
		} frag;
	} un;
} ICMP_t;

typedef void rxhand_f(uchar *, unsigned, unsigned, unsigned);
typedef void thand_f(void);


//********************** Macro Definition **********************
#define IP_HDR_SIZE_NO_UDP		(sizeof (IP_t) - 8)
#define IP_HDR_SIZE				(sizeof (IP_t))

#define 	ARP_ETHER	    1		// Ethernet  hardware address

#define 	ARPOP_REQUEST	1		// Request  to resolve  address
#define 	ARPOP_REPLY		2		// Response to previous request
#define 	RARPOP_REQUEST	3		// Request  to resolve  address
#define 	RARPOP_REPLY	4		// Response to previous request

#define 	ICMP_ECHO_REPLY		0	// Echo reply
#define 	ICMP_REDIRECT		5	// Redirect (change route)
#define 	ICMP_ECHO_REQUEST	8	// Echo request
#define 	ICMP_REDIR_NET		0	// Redirect Net
#define 	ICMP_REDIR_HOST		1	// Redirect Host

#define 	IPPROTO_ICMP	 	1	// Internet Control Message Protocol
#define 	IPPROTO_UDP			17	// User Datagram Protocol

#define 	NETLOOP_CONTINUE	1
#define 	NETLOOP_RESTART		2
#define 	NETLOOP_SUCCESS		3
#define 	NETLOOP_FAIL		4

#define 	ARP_HDR_SIZE		(8+20)		// Size assuming ethernet

#define NAMESIZE 		16
#define ETHER_HDR_SIZE	14		// Ethernet header size
#define E802_HDR_SIZE	22		// 802 ethernet header size
#define PROT_IP		0x0800		// IP protocol
#define PROT_ARP	0x0806		// IP ARP protocol
#define PROT_RARP	0x8035		// IP ARP protocol
#define __be16_to_cpu(x) __swab16((x))
#define ___ntohs(x) __be16_to_cpu(x)
#define ntohs(x) ___ntohs(x)
#define __swab32(x)    ((__u32)( \
						(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
						(((__u32)(x) & (__u32)0x0000ff00UL) <<  8) | \
						(((__u32)(x) & (__u32)0x00ff0000UL) >>  8) | \
						(((__u32)(x) & (__u32)0xff000000UL) >> 24) ))

#define __be32_to_cpu(x) __swab32((x))
#define ___ntohl(x) __be32_to_cpu(x)
#define ntohl(x) ___ntohl(x)
#define __swab16(x) \
						((__u16)( \
						(((__u16)(x) & (__u16)0x00ffU) << 8) | \
						(((__u16)(x) & (__u16)0xff00U) >> 8) ))
#define __cpu_to_be16(x) __swab16((x))
#define ___htons(x) __cpu_to_be16(x)
#define htons(x) ___htons(x)
#define __cpu_to_be32(x) ((__swab32)(x))
#define ___htonl(x) __be32_to_cpu(x)
#define htonl(x) ((unsigned long)___htonl(x))

#define ARP_TIMEOUT			5		// Seconds before trying ARP again
#define ARP_TIMEOUT_COUNT	5		// # of timeouts before giving up


//********************** Local Function **********************
#ifdef __TEMPLATE
	#define EXTERN
#else
	#define EXTERN	extern
#endif

EXTERN void NetTRPackInit(void);
EXTERN ushort NetRxPack (uchar *udpdata, char *srcipaddr,ushort *srcport);
EXTERN int NetTrPack (uchar *udpdata, char *ipstring, int sport, int len);
EXTERN void PingAck (uchar *ipaddr, uchar *etheraddr);
EXTERN void NetReceiveProcess (volatile uchar * pkt, int len);

#undef EXTERN


//********************** Extern Variable **********************
extern volatile uchar * NetTxPacket;	// THE transmit packet
extern volatile uchar * NetRxPackets[PKTBUFSRX];/* Receive packets	*/

extern char MACAddr[];
extern IPaddr_t IPAddr;
extern IPaddr_t GateAddr;
extern IPaddr_t MaskAddr;
extern IPaddr_t ServerAddr;


//********************** Extern Function **********************
ulong get_timer(int t);

//*****************************************************************
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -