home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / PPPFSM.H < prev    next >
C/C++ Source or Header  |  1994-04-17  |  7KB  |  229 lines

  1. #ifndef _PPPFSM_H
  2. #define _PPPFSM_H
  3.   
  4. #ifndef _MBUF_H
  5. #include "mbuf.h"
  6. #endif
  7.   
  8. #ifndef _PROC_H
  9. #include "proc.h"
  10. #endif
  11.   
  12. #ifndef _IFACE_H
  13. #include "iface.h"
  14. #endif
  15.   
  16. #ifndef _TIMER_H
  17. #include "timer.h"
  18. #endif
  19.   
  20.                 /* 00: serious internal problems */
  21.                 /* 01: interoperability problems */
  22.                 /* 02: state machine messages */
  23.   
  24. /* #define PPP_DEBUG_RAW */
  25.   
  26. #ifdef PPP_DEBUG_RAW
  27. #define PPP_DEBUG_OPTIONS   0x08
  28. #define PPP_DEBUG_CHECKS(x) if(PPPtrace & 0x40) trace_log(PPPiface,x);
  29. #define PPP_DEBUG_ROUTINES(x)   if(PPPtrace & 0x80) trace_log(PPPiface,x);
  30. #else
  31. #define PPP_DEBUG_CHECKS(x)
  32. #define PPP_DEBUG_ROUTINES(x)
  33. #endif
  34.   
  35. /* config packet header */
  36. struct config_hdr {
  37.     byte_t code;
  38. #define CONFIG_REQ   1
  39. #define CONFIG_ACK   2
  40. #define CONFIG_NAK   3
  41. #define CONFIG_REJ   4
  42. #define TERM_REQ     5
  43. #define TERM_ACK     6
  44. #define CODE_REJ     7
  45. #define PROT_REJ     8
  46. #define ECHO_REQ     9
  47. #define ECHO_REPLY  10
  48. #define DISCARD_REQ 11
  49. #define QUALITY_REPORT  12
  50.   
  51.     byte_t id;
  52.     int16 len;
  53. };
  54. #define CONFIG_HDR_LEN  4   /* Length of config packet header */
  55.   
  56.   
  57. /* config option header */
  58. struct option_hdr {
  59.     byte_t type;        /* protocol dependant types */
  60.     byte_t len;
  61. };
  62. #define OPTION_HDR_LEN  2   /* Length of option header */
  63.   
  64.   
  65. /* Supported Configuration Protocol index */
  66. enum {
  67.     Lcp,
  68.     Pap,
  69.     IPcp,
  70.     fsmi_Size
  71. };
  72.   
  73. struct fsm_s;       /* forward declaration */
  74.   
  75. /* Protocol Constants needed by State Machine */
  76. struct fsm_constant_s {
  77.     char *name;         /* Name of protocol */
  78.     int16 protocol;         /* Protocol number */
  79.     int16 recognize;        /* Config codes to use (bits) */
  80.   
  81.     byte_t fsmi;            /* Finite State Machine index */
  82.     byte_t try_req;         /* # tries for request */
  83.     byte_t try_nak;         /* # tries for nak substitutes */
  84.     byte_t try_terminate;       /* # tries for terminate */
  85.     int32 timeout;          /* Time for timeouts (milliseconds)*/
  86.   
  87.     /* To free structure */
  88.     void (*free)        __ARGS((struct fsm_s *fsm_p));
  89.   
  90.     /* Set negotiation to initial values */
  91.     void (*reset)       __ARGS((struct fsm_s *fsm_p));
  92.     /* When leaving Closed or Listen */
  93.     void (*starting)    __ARGS((struct fsm_s *fsm_p));
  94.     /* When entering Opened */
  95.     void (*opening)     __ARGS((struct fsm_s *fsm_p));
  96.     /* When leaving Opened */
  97.     void (*closing)     __ARGS((struct fsm_s *fsm_p));
  98.     /* When entering Closed or Listen (after termination) */
  99.     void (*stopping)    __ARGS((struct fsm_s *fsm_p));
  100.   
  101.     struct mbuf *(*makereq) __ARGS((struct fsm_s *fsm_p));
  102.   
  103.     int (*request)      __ARGS((struct fsm_s *fsm_p,
  104.     struct config_hdr *hdr,
  105.     struct mbuf *bp));
  106.     int (*ack)      __ARGS((struct fsm_s *fsm_p,
  107.     struct config_hdr *hdr,
  108.     struct mbuf *bp));
  109.     int (*nak)      __ARGS((struct fsm_s *fsm_p,
  110.     struct config_hdr *hdr,
  111.     struct mbuf *bp));
  112.     int (*reject)       __ARGS((struct fsm_s *fsm_p,
  113.     struct config_hdr *hdr,
  114.     struct mbuf *bp));
  115. };
  116.   
  117. /* FSM states */
  118. enum {
  119.     fsmCLOSED,
  120.     fsmLISTEN,
  121.     fsmREQ_Sent,
  122.     fsmACK_Rcvd,
  123.     fsmACK_Sent,
  124.     fsmOPENED,
  125.     fsmTERM_Sent,
  126.     fsmState_Size
  127. };
  128.   
  129. /* State Machine Control Block */
  130. struct fsm_s {
  131.     byte_t state;           /* FSM state */
  132.     byte_t lastid;          /* ID of last REQ we sent */
  133.   
  134.     byte_t flags;
  135. #define PPP_ESCAPED 0x01
  136. #define PPP_TOSS    0x02
  137. #define FSM_PASSIVE 0x40    /* opened passive */
  138. #define FSM_ACTIVE  0x80    /* opened active */
  139.   
  140.     byte_t retry;           /* counter for timeouts */
  141.     byte_t try_req;         /* # tries for request */
  142.     byte_t try_terminate;       /* # tries for terminate */
  143.   
  144.     byte_t retry_nak;       /* counter for naks of requests */
  145.     byte_t try_nak;         /* # tries for nak substitutes */
  146.   
  147.     struct ppp_s *ppp_p;        /* the ppp we belong to */
  148.     struct timer timer;
  149.     struct fsm_constant_s *pdc; /* protocol dependent constants */
  150.     void *pdv;          /* protocol dependent variables */
  151. };
  152.   
  153.   
  154. /* Link Phases */
  155. enum {
  156.     pppDEAD,        /* Waiting for physical layer */
  157.     pppLCP,         /* Link Control Phase */
  158.     pppAP,          /* Authentication Phase */
  159.     pppREADY,       /* Link ready for traffic */
  160.     pppTERMINATE,       /* Termination Phase */
  161.     pppPhase_Size
  162. };
  163.   
  164. /* PPP control block */
  165. struct ppp_s {
  166.     struct iface *iface;        /* pointer to interface block */
  167.   
  168.     byte_t phase;           /* phase of link initialization */
  169.     byte_t id;          /* id counter for connection */
  170.   
  171.     byte_t flags;
  172. #define PPP_AP_LOCAL    0x10    /* local authentication */
  173. #define PPP_AP_REMOTE   0x20    /* remote authentication */
  174.   
  175.     byte_t trace;           /* trace flags for connection */
  176.   
  177.     struct fsm_s fsm[fsmi_Size];    /* finite state machines */
  178.   
  179.     int32 upsince;          /* Timestamp when Link Opened */
  180.     char *peername;         /* Peername from remote (if any) */
  181.   
  182.     int32 OutTxOctetCount;      /* # octets sent */
  183.     int32 OutOpenFlag;      /* # of open flags sent */
  184.     int16 OutNCP[fsmi_Size];    /* # NCP packets sent by protocol */
  185.     int16 OutError;         /* # packets with error on send */
  186.     int16 OutMemory;        /* # alloc failures on send */
  187.   
  188.     int32 InRxOctetCount;       /* # octets received */
  189.     int32 InOpenFlag;       /* # of open flags */
  190.     int16 InNCP[fsmi_Size];     /* # NCP packets by protocol */
  191.     int16 InUnknown;        /* # unknown packets received */
  192.     int16 InChecksum;       /* # packets with bad checksum */
  193.     int16 InFrame;          /* # packets with frame error */
  194.     int16 InError;          /* # packets with other error */
  195.     int16 InMemory;         /* # alloc failures */
  196. };
  197. #define NULLPPP (struct ppp_s *)0
  198.   
  199.   
  200. extern char *fsmStates[];
  201. extern char *fsmCodes[];
  202.   
  203. struct mbuf *htoncnf __ARGS((struct config_hdr *cnf, struct mbuf *data));
  204. int ntohcnf __ARGS((struct config_hdr *cnf, struct mbuf **bpp));
  205. int ntohopt __ARGS((struct option_hdr *opt, struct mbuf **bpp));
  206.   
  207. void fsm_no_action  __ARGS((struct fsm_s *fsm_p));
  208. int fsm_no_check    __ARGS((struct fsm_s *fsm_p,
  209. struct config_hdr *hdr,
  210. struct mbuf *bp));
  211.   
  212. void fsm_log    __ARGS((struct fsm_s *fsm_p, char *comment));
  213. void fsm_timer  __ARGS((struct fsm_s *fsm_p));
  214.   
  215. int fsm_send    __ARGS((struct fsm_s *fsm_p, byte_t code,
  216. byte_t id, struct mbuf *data));
  217. int fsm_sendreq __ARGS((struct fsm_s *fsm_p));
  218.   
  219. void fsm_proc   __ARGS((struct fsm_s *fsm_p, struct mbuf *bp));
  220.   
  221. void fsm_start  __ARGS((struct fsm_s *fsm_p));
  222. void fsm_down   __ARGS((struct fsm_s *fsm_p));
  223. void fsm_close  __ARGS((struct fsm_s *fsm_p));
  224.   
  225. void fsm_init   __ARGS((struct fsm_s *fsm_p));
  226. void fsm_free   __ARGS((struct fsm_s *fsm_p));
  227.   
  228. #endif /* _PPPFSM_H */
  229.