📄 icmp.h
字号:
/**
* \addtogroup icmp
* @{
*/
/**
* \file
* \brief ICMP layer configuration and API header file
* \author glyin <glyin@fameg.com>
*/
/*
******************************************************************************
*
Copyright (c) 2006 FameG Shanghai, Inc. All rights reserved.
*
This is unpublished proprietary source code of FameG Shanghai, Inc.
*
The copyright notice above does not evidence any actual or intended
*
publication of such source code.
******************************************************************************
*/
/*
******************************************************************************
*
Project: T4 L4MCU FPGA verification
*
Filename: icmp.h
*
Date: 28/02/06
*
Purpose: ICMP functions for L4MCU (Keil C Compiler)
*
Author: Guanglei Yin
******************************************************************************
*/
#ifndef __ICMP_H__
#define __ICMP_H__
#include "kernel/system.h"
#include "user_config.h"
/*****************************************************************************
* CONSTANT DEFINES *
*****************************************************************************/
/*!\brief Define ICMP header len.
*/
#define ICMP_HLEN 8
/*!\brief Define UDP header len.
*/
#define UDP_HLEN 8
/* IP protocol */
/// \cond DOXYGEN_SKIP
#define IP_ICMP 1
#define IP_UDP 17
#define IP_IGMP 2
#define IP_TCP 6
/* IP option */
#define IP_OPT_TIMESTAMP 68
#define IP_OPT_RECORD_ROUTER 7
/* ICMP message types */
#define ICMP_DEST_UNREACHABLE 3
#define ICMP_ECHO_REQUEST 8
#define ICMP_ECHO_REPLY 0
#define ICMP_ROUTER_ADVERTISEMENT 9
#define ICMP_ROUTER_SOLICITATION 10
#define ICMP_INFORMATION_REQUEST 15
#define ICMP_INFORMATION_REPLY 16
/// \endcond
/* ICMP destination unreachable message code */
/*!\brief net unreachable type flag.
*/
#define NET_UNREACH 0
/*!\brief host unreachable type flag.
*/
#define HOST_UNREACH 1
/*!\brief protocol unreachable type flag.
*/
#define PRO_UNREACH 2
/*!\brief port unreachable type flag.
*/
#define PORT_UNREACH 3
/*!\brief fragmentation needed DF set type flag.
*/
#define FRAGMENTATION_NEEDED_DF_SET 4
/*****************************************************************************
* MACROS *
*****************************************************************************/
/*!\brief Get ICMP RXFIFO Write Pointer.
*/
#define GET_ICMP_RFWP() icmp_GetRFWP()
/*!\brief Get ICMP RXFIFO Read Pointer.
*/
#define GET_ICMP_RFRP() icmp_GetRFRP()
/*!\brief Set ICMP RXFIFO Read Pointer.
*/
#define SET_ICMP_RFRP(p) icmp_SetRFRP(p)
/*!\brief Get ICMP TXFIFO Write Pointer.
*/
#define GET_ICMP_TFWP() icmp_GetTFWP()
/*!\brief Get ICMP TXFIFO Read Pointer.
*/
#define GET_ICMP_TFRP() icmp_GetTFRP()
/*!\brief Set ICMP TXFIFO Write Pointer.
*/
#define SET_ICMP_TFWP(p) icmp_SetTFWP(p)
/*!\brief Get ICMP TXFIFO free space.
*/
#define GET_ICMP_TFFS() icmp_GetTFFS()
/*!\brief Get ICMP interrupt status.
*/
#define GET_ICMP_INT_STATUS() inb(SYS_ICMP_INTSTAT)
/*****************************************************************************
* DATA TYPES *
*****************************************************************************/
/*!\brief Record some information pass to echo request packet.
*/
struct echo_request_t
{
UINT8 ttl; //!< The ttl field in IP header of ICMP echo request packet.
UINT8 tos; //!< The tos field in IP header of ICMP echo request packet.
#if IPOPTION
UINT8 route_count; //!< The count of record router in ICMP echo request packet.
UINT8 timestamp_count; //!< The count of record timestamp in ICMP echo request packet.
#endif
};
/*!\brief Record the first 8 bytes ICMP header in ICMP echo packet.
*/
typedef struct
{
/* ICMP header. */
UINT8 type; //!< The type field in ICMP header.
UINT8 code_; //!< The code field in ICMP header.
UINT16 chksum; //!< The checksum field in ICMP header.
UINT16 ident; //!< The identifier field in ICMP header.
UINT16 seqnum; //!< The sequence number field in ICMP header.
} icmp_hdr;
/*****************************************************************************
* FUNCTIONS DECLARATION *
*****************************************************************************/
/* ICMP function */
extern void icmp_Init(void); /* Initialize ICMP */
extern void icmp_TxAbort(void); /* TXFIFO transmit abort */
extern void icmp_Reset(void);
extern INT16 icmp_write_to_fifo(struct tx_descriptor_t *desc, UINT8 XDATA *txbuf, UINT16 len ); /* Send out packet through ICMP channel*/
extern INT16 icmp_read_from_fifo(struct rx_descriptor_t *desc, UINT8 XDATA*rxbuf, UINT16 buf_len); /* Receive packet through ICMP channel */
extern void icmp_process_in(void); /* process ICMP RX channel */
#if 1//INCLUDE_PING_APP
extern INT8 icmp_SendEchoReqPkt(UINT32 dest_addr, UINT16 pkt_size,struct echo_request_t *echo); /* send ICMP echo request packet */
#endif
/* ICMP interrupt function */
extern void icmp_IntService(void); /* ICMP interrupt service handler */
extern void register_icmp_igmp_interrupt(UINT8 type, int_function handler); /* Initialize ICMP interrupt handler */
/*****************************************************************************
* GLOBAL VARIABLES DECLARATION *
*****************************************************************************/
/// \cond DOXYGEN_SKIP
#if INCLUDE_ICMP_RESPONSE
extern BOOL response_en;
#endif
/// \endcond
#if 1//INCLUDE_PING_APP
#if IPOPTION
extern UINT8 timestamp_addr[4][4];
extern union dword_byte_u timestamp_val[4];
extern UINT8 route_val[9][4];
extern UINT8 timestamp_count;
extern UINT8 route_count;
#endif
extern UINT32 ping_addr;
extern UINT8 echo_reqest_flag;
extern UINT8 IsReceived;
#endif
#endif /*__ICMP_H__*/
/** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -