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

📄 pppp.h

📁 用于嵌入式系统的TCP/IP协议栈
💻 H
字号:
/***********************************************************************//*                                                                     *//*   Module:  tcp_ip/ppp/pppp.h                                        *//*   Release: 2001.3                                                   *//*   Version: 2001.0                                                   *//*   Purpose: Private PPP header file                                  *//*                                                                     *//*---------------------------------------------------------------------*//*                                                                     *//*               Copyright 2001, Blunk Microsystems                    *//*                      ALL RIGHTS RESERVED                            *//*                                                                     *//*   Licensees have the non-exclusive right to use, modify, or extract *//*   this computer program for software development at a single site.  *//*   This program may be resold or disseminated in executable format   *//*   only. The source code may not be redistributed or resold.         *//*                                                                     *//***********************************************************************/#ifndef _PPPP_H   /* Don't include this file more than once */#define _PPPP_H#include "../tcp_ipp.h"#include "vjhc.h"/***********************************************************************//* Configuration                                                       *//***********************************************************************/#define RCN_LIMIT       20      /* NAK/REJECT limit */#define LCP_MRU_LO      128     /* lower MRU limit */#define CHAT_ABORTS     3       /* number of abort strings *//***********************************************************************//* Symbol Definitions                                                  *//***********************************************************************//*** PPP Frame Constants*/#define PPP_HDR_LEN     4       /* PPP/HDLC envelope header bytes */#define PPP_MTU         1500#define CRC16_LEN       2#define PPP_FLAG        0x7E    /* ends each frame */#define LCP_MRU_HI      (TCP_MED_SIZE - (NIMHLEN + CRC16_LEN))/*** FSM Configuration Codes*/#define CONFIG_REQ      1#define CONFIG_ACK      2#define CONFIG_NAK      3#define CONFIG_REJ      4#define TERM_REQ        5#define TERM_ACK        6#define CODE_REJ        7#define PROT_REJ        8#define ECHO_REQ        9#define ECHO_REPLY      10#define DISCARD_REQ     11#define UNRECOGNIZED    12  /* make last *//*** LCP option types*/#define LCP_MRU         1#define LCP_ACCM        2#define LCP_AUTHENT     3#define LCP_MAGIC       5#define LCP_PFC         7#define LCP_ACFC        8#define LCP_OPT_LIMIT   8   /* highest # we can handle *//*** LCP Negotiation Flags*/#define LCP_N_MRU       (1 << LCP_MRU)#define LCP_N_ACCM      (1 << LCP_ACCM)#define LCP_N_AUTHENT   (1 << LCP_AUTHENT)#define LCP_N_MAGIC     (1 << LCP_MAGIC)#define LCP_N_PFC       (1 << LCP_PFC)#define LCP_N_ACFC      (1 << LCP_ACFC)/*** IPCP Option Types*/#define IPCP_COMPRESS       2#define IPCP_ADDRESS        3#define IPCP_OPT_LIMIT      3   /* highest # we can handle *//*** IPCP Option Flags*/#define IPCP_N_COMPRESS     (1 << IPCP_COMPRESS)#define IPCP_N_ADDRESS      (1 << IPCP_ADDRESS)/*** PPP Protocol Codes*/#define PPP_IP_PROTO        0x0021  /* Internet Protocol */#define PPP_COMP_PROTO      0x002D  /* VJ Compressed TCP/IP */#define PPP_UNCOMP_PROTO    0x002F  /* VJ Uncompressed TCP/IP */#define PPP_IPCP_PROTO      0x8021  /* IP Control Protocol */#define PPP_LCP_PROTO       0xC021  /* Link Control Protocol */#define PPP_PAP_PROTO       0xC023  /* Password Authentication Proto */#define PPP_CHAP_PROTO      0xC223  /* Challenge Handshake Auth Proto *//*** PPP Internal Flags*/#define PPPF_PAP_LOCAL      (1 << 8)    /* local PAP authentication */#define PPPF_PAP_REMOTE     (1 << 9)    /* remote PAP authentication */#define PPPF_CHAP_LOCAL     (1 << 10)   /* local CHAP authentication */#define PPPF_CHAP_REMOTE    (1 << 11)   /* remote CHAP authentication */#define PPPF_AUTHENTICATION (PPPF_PAP_LOCAL | PPPF_PAP_REMOTE | \                             PPPF_CHAP_LOCAL | PPPF_CHAP_REMOTE)#define PPPF_CHAP_RESPONDED (1 << 12)   /* CHAP response sent *//*** Link Phases*/enum{  pppDEAD,      /* waiting for physical layer */  pppCHAT,      /* processing CHAT scripts */  pppLCP,       /* link control phase */  pppAUTHEN,    /* authentication phase */  pppNETWORK,   /* link ready for network traffic */  pppTERMINATE, /* termination phase */  pppPhase_Size};/*** Supported Configuration Protocol Index*/enum{  kLCP,  kPAP,  kCHAP,  kIPCP,  fsmi_Size};/*** Finite State Machine States*/enum{  fsmINITIAL,  fsmSTARTING,  fsmCLOSED,  fsmSTOPPED,  fsmCLOSING,  fsmSTOPPING,  fsmReqSent,  fsmAckRcvd,  fsmAckSent,  fsmOPENED,  fsmState_Size};/***********************************************************************//* Type Definitions                                                    *//***********************************************************************//*** PPP Header*/struct ppp_hdr{  ui8  addr;  ui8  control;  ui16 protocol;};/*** Config Option Header*/typedef struct option_hdr{  ui8 type;    /* protocol dependent types */  ui8 len;} OptHdr;#define OPTION_HDR_LEN  2   /* length of option header *//*** LCP Configuration Options*/typedef struct{  uint options;         /* "negotiated" flags */  uint mru;             /* maximum receive unit */  ui32 accm;            /* async control char map */  uint auth_proto;      /* authentication protocol */  ui32 magic;           /* magic number value */} LcpOpts;/*** IPCP Configuration Options*/typedef struct{  uint options;         /* "negotiated" flags */  ui32 address;         /* address for this side */  uint comp_proto;      /* compression protocol */  uint slots;           /* number of slots (0-n) */  ui8  comp_slot;       /* slots may be compressed (flag) */} IpcpOpts;/*** LCP Control Block*/typedef struct{  LcpOpts local;  LcpOpts remote;} LcpCB;/*** IPCP Control Block*/typedef struct{  IpcpOpts local;  IpcpOpts remote;} IpcpCB;/*** FSM Config Packet Header*/typedef struct{  ui8  code;  ui8  id;  ui16 len;} ConfigHdr;#define CONFIG_HDR_LEN  4   /* length of config packet header *//*** State Machine Control Block*/typedef struct fsm_s{  ui8 state;            /* FSM state */  ui8 lastid;           /* ID of last REQ we sent */  ui8 retry;            /* counter for timeouts */  ui8 rcn_cnt;          /* counts retry resets and sent NAKs/REJs */  TcpTmr timer;         /* timer for retries and timeouts */  const struct fsm_constants *pdc; /* protocol dependent constants */} FSM;/*** State Machine Protocol Constants*/struct fsm_constants{  char *name;           /* protocol name */  uint protocol;        /* protocol number */  uint recognize;       /* config codes to use (bit mask) */  ui8 fsmi;             /* finite State Machine index */  ui8 req_limit;        /* max config request sends */  ui8 nak_limit;        /* max NAK sends */  ui8 terminate_limit;  /* max terminate request sends */  ui32 timeout;         /* timer for timeouts (tenths of sec) */  void (*starting)(FSM *fsm); /* set negotiation to initial values */  void (*up)(FSM *fsm);       /* entering Opened */  void (*down)(FSM *fsm);     /* leaving Opened */  void (*finished)(FSM *fsm); /* after termination */  NetBuf *(*makereq)(FSM *fsm);  int (*request)(FSM *fsm, ConfigHdr *hdr); /* process request */  int (*ack)(FSM *fsm, ConfigHdr *hdr);     /* process ACK */  int (*nak)(FSM *fsm, ConfigHdr *hdr);     /* process NAK */  int (*reject)(FSM *fsm, ConfigHdr *hdr);  /* process reject */};/*** CHAT Expect String Data*/typedef struct{  char *compare;    /* points to location in receive buffer */  char *string;     /* expect string pointer */  int length;} Match;/*** CHAT Data*/typedef struct{  NetBuf *buf;      /* CHAT temporary buffer */  char *snd_buf;    /* points to CHAT send buffer */  char *rcv_buf;    /* points to CHAT receive buffer */  char *script;     /* points to current CHAT command script */  char *send;       /* points to current output string */  char *saved;      /* points to saved script or output string */  Match abort[CHAT_ABORTS];  /* abort string data */  Match match;      /* expect command data */  volatile char *uart_put;   /* points to location in receive buffer */  char *uart_get;   /* points to location in send buffer */  char *output;     /* points to location in send buffer */  int timeout;      /* CHAT timeouts (tenths of sec) */  volatile int sb_count; /* send buffer count */  TcpTmr timer;     /* timer for retries and timeouts */  ui8 major_state;  ui8 minor_state;  ui8 num_trys;} ChatData;/*** UART Framer Control Block*/typedef struct{  NetBuf *rbuf;     /* pointer to receive buffer */  int received;     /* number of characters written to receive buffer */  ui8 *rx_dst;      /* pointer to next location in receive buffer */  NetBuf *tx_head;  /* pointer to first queued transmit buffer */  NetBuf *tx_tail;  /* pointer to last queued transmit buffer */  ui16 rx_crc;      /* receive CRC calculation */  ui16 tx_crc;      /* transmit CRC calculation */  ui8  next_char;   /* tx holding */  ui8  idle;        /* tx idle flag */  ui8  escaped;     /* just saw escape char (0x7D) */  ui8  hunt;        /* if TRUE, flushing input until next flag */} UartData;/*** PPP Control Block*/typedef struct PppCB{  /*  ** Shared with pppPublic structure  */  pppPublic public;  /*  ** Private to PPP directory  */  UartData uart;            /* framer data */  ChatData chat;            /* CHAT data */  LcpCB lcp;                /* LCP control block */  IpcpCB ipcp;              /* IPCP control block */  struct vjcompress comp;   /* VJ compression data structures */  TcpTmr timer;             /* timer for retries and timeouts */  TcpTmr timer2;            /* timer for line control signal polling */  ui32 rx_accm;             /* rx asynchronous control character map */  ui32 tx_accm[8];          /* tx asynchronous control character map */  ui32 lcp_request_opts;    /* options we request */  ui32 lcp_accept_opts;     /* peer requests that are accepted */  ui32 ipcp_request_opts;   /* options we request */  ui32 ipcp_accept_opts;    /* peer requests that are accepted */  ui32 borrowed_addr;       /* used if local address not provided */  FSM  fsm[fsmi_Size];      /* finite state machines */  ui32 txOctetCount;        /* number of octets sent */  uint txOctet[fsmi_Size];  /* number of packets sent by protocol */  uint txError;             /* number of packets with error on send */  ui32 rxOctetCount;        /* number of octets received */  uint rxOctet[fsmi_Size];  /* number of packets received by protocol */  uint rxUnknown;           /* number of packets with unknown protocol */  uint rxChecksum;          /* number of checksum errors */  uint rxFrame;             /* number of packets with frame error */  uint rxError;             /* number of packets with other error */  ui16 dcd_persist;         /* DCD signal persistence */  ui16 dsr_persist;         /* DSR signal persistence */  ui16 rbuf_size;           /* PPP receive buffer size */  ui8  phase;               /* phase of link initialization */  ui8  id;                  /* packet id counter */  ui8  last_response;       /* id of last response */  ui8  response_hash[16];   /* last CHAP response hash */  ui8  challenge_val[16];   /* last CHAP challenge value */} *PPP;typedef const struct PppCB *CPPP;/***********************************************************************//* Function Prototypes                                                 *//***********************************************************************/#if PPP_TRACEvoid pppLog(char *format, ...);void pppLogn(char *format, ...);void pppFsmLog(FSM *fsm, char *comment);#endifvoid *put16(ui8 *dst, ui16 word);void *put32(ui8 *dst, ui32 word);void ppp_send(NetBuf *buf, void *voidp);void PppOutput(uint protocol, NetBuf *buf);void pppReady(void);void pppFinish(void);void uartDataInd(void *handle, ui8 *src, int length, int increment);int  uartDataReq(void *handle, ui8 *dst, int space, int increment);void pppSigCheck(void *handle);void pppFsmInit(FSM *fsm);void PppFsmProc(FSM *fsm);void pppFsmOpen(FSM *fsm);void pppFsmUp(FSM *fsm);void pppFsmDown(FSM *fsm);int  PppFsmNoCheck(FSM *fsm, ConfigHdr *hdr);void PppFsmNoAction(FSM *fsm);void pppFsmSend(FSM *fsm, ui8 code, ui8 id, NetBuf *data);void fsmSendReq(FSM *fsm);void fsmLcpClose(void);void fsmFree(FSM *fsm);void pppStart(void *ppp);int  pppRdOpt(OptHdr *opt);int  pppRdConf(ConfigHdr *hdr, NetBuf *buf);int  pull32(NetBuf *buf);int  pull16(NetBuf *buf);int  pullchar(NetBuf *buf);void lcpInit(PPP ppp);void ipcpInit(PPP ppp);void chapInit(PPP ppp);void chapProc(FSM *fsm, NetBuf *buf);void chapOpen(void);void chapDown(void);void chapNcpMsg(void);void papInit(PPP ppp);void papProc(FSM *fsm, NetBuf *buf);void papOpen(void);void papDown(void);void chatInit(PPP ppp);void chatClose(void *handle);void chatStart(void *handle);void chatDown(void);char *pppIps(ui32 address);void pppPrintCfg(CPPP ppp);void pppAttnReq(void (*func)(void *ptr), PPP ppp);/***********************************************************************//* Global Variable Declarations                                        *//***********************************************************************/extern PPP Ppp;         /* global PPP channel identifier */extern char *const fsmCodes[];extern NetBuf *pppRcvBuf;#endif /* _PPPP_H */

⌨️ 快捷键说明

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