fsm.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:5k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* fsm.h - {Link, IP} Control Protocol Finite State Machine header */
  2. /* Copyright 1995 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1989 Carnegie Mellon University.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms are permitted
  8.  * provided that the above copyright notice and this paragraph are
  9.  * duplicated in all such forms and that any documentation,
  10.  * advertising materials, and other materials related to such
  11.  * distribution and use acknowledge that the software was developed
  12.  * by Carnegie Mellon University.  The name of the
  13.  * University may not be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19. /*
  20. modification history
  21. --------------------
  22. 01a,16jan95,dzb  WRS-ize.
  23. */
  24. #ifndef __INCfsmh
  25. #define __INCfsmh
  26. #ifdef  __cplusplus
  27. extern "C" {
  28. #endif
  29. /*
  30.  * Packet header = Code, id, length.
  31.  */
  32. #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
  33. /*
  34.  *  CP (LCP, IPCP, etc.) codes.
  35.  */
  36. #define CONFREQ 1 /* Configuration Request */
  37. #define CONFACK 2 /* Configuration Ack */
  38. #define CONFNAK 3 /* Configuration Nak */
  39. #define CONFREJ 4 /* Configuration Reject */
  40. #define TERMREQ 5 /* Termination Request */
  41. #define TERMACK 6 /* Termination Ack */
  42. #define CODEREJ 7 /* Code Reject */
  43. /*
  44.  * Each FSM is described by a fsm_callbacks and a fsm structure.
  45.  */
  46. typedef struct fsm_callbacks {
  47.     void (*resetci)(); /* Reset our Configuration Information */
  48.     int  (*cilen)(); /* Length of our Configuration Information */
  49.     void (*addci)(); /* Add our Configuration Information */
  50.     int  (*ackci)(); /* ACK our Configuration Information */
  51.     int  (*nakci)(); /* NAK our Configuration Information */
  52.     int  (*rejci)(); /* Reject our Configuration Information */
  53.     int  (*reqci)(); /* Request peer's Configuration Information */
  54.     void (*up)(); /* Called when fsm reaches OPENED state */
  55.     void (*down)(); /* Called when fsm leaves OPENED state */
  56.     void (*starting)(); /* Called when we want the lower layer */
  57.     void (*finished)(); /* Called when we don't want the lower layer */
  58.     void (*protreject)(); /* Called when Protocol-Reject received */
  59.     void (*retransmit)(); /* Retransmission is necessary */
  60.     int  (*extcode)(); /* Called when unknown code received */
  61.     char *proto_name; /* String name for protocol (for messages) */
  62. } fsm_callbacks;
  63. typedef struct fsm {
  64.     int unit; /* Interface unit number */
  65.     int protocol; /* Data Link Layer Protocol field value */
  66.     int state; /* State */
  67.     int flags; /* Contains option bits */
  68.     u_char id; /* Current id */
  69.     u_char reqid; /* Current request id */
  70.     int timeouttime; /* Timeout time in milliseconds */
  71.     int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
  72.     int retransmits; /* Number of retransmissions left */
  73.     int maxtermtransmits; /* Maximum Terminate-Request transmissions */
  74.     int nakloops; /* Number of nak loops since last ack */
  75.     int maxnakloops; /* Maximum number of nak loops tolerated */
  76.     fsm_callbacks *callbacks; /* Callback routines */
  77. } fsm;
  78. /*
  79.  * Link states.
  80.  */
  81. #define INITIAL 0 /* Down, hasn't been opened */
  82. #define STARTING 1 /* Down, been opened */
  83. #define CLOSED 2 /* Up, hasn't been opened */
  84. #define STOPPED 3 /* Open, waiting for down event */
  85. #define CLOSING 4 /* Terminating the connection, not open */
  86. #define STOPPING 5 /* Terminating, but open */
  87. #define REQSENT 6 /* We've sent a Config Request */
  88. #define ACKRCVD 7 /* We've received a Config Ack */
  89. #define ACKSENT 8 /* We've sent a Config Ack */
  90. #define OPENED 9 /* Connection available */
  91. /*
  92.  * Flags - indicate options controlling FSM operation
  93.  */
  94. #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
  95. #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
  96. #define OPT_SILENT 4 /* Wait for peer to speak first */
  97. /*
  98.  * Timeouts.
  99.  */
  100. #define DEFTIMEOUT 3 /* Timeout time in seconds */
  101. #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
  102. #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
  103. #define DEFMAXNAKLOOPS 10 /* Maximum number of nak loops */
  104. /*
  105.  * Prototypes
  106.  */
  107. extern void fsm_init __ARGS((fsm *));
  108. extern void fsm_lowerup __ARGS((fsm *));
  109. extern void fsm_lowerdown __ARGS((fsm *));
  110. extern void fsm_open __ARGS((fsm *));
  111. extern void fsm_close __ARGS((fsm *));
  112. extern void fsm_input __ARGS((fsm *, u_char *, int));
  113. extern void fsm_protreject __ARGS((fsm *));
  114. extern void fsm_sdata __ARGS((fsm *, int, int, u_char *, int));
  115. #ifdef  __cplusplus
  116. }
  117. #endif
  118. #endif /* __INCfsmh */