home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / packet / n17jsrc / pppfsm.h < prev    next >
C/C++ Source or Header  |  1991-06-06  |  6KB  |  216 lines

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