fsm.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
  3. *
  4. * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. *
  18. * 3. The name "Carnegie Mellon University" must not be used to
  19. * endorse or promote products derived from this software without
  20. * prior written permission. For permission or any legal
  21. * details, please contact
  22. * Office of Technology Transfer
  23. * Carnegie Mellon University
  24. * 5000 Forbes Avenue
  25. * Pittsburgh, PA 15213-3890
  26. * (412) 268-4387, fax: (412) 268-7395
  27. * tech-transfer@andrew.cmu.edu
  28. *
  29. * 4. Redistributions of any form whatsoever must retain the following
  30. * acknowledgment:
  31. * "This product includes software developed by Computing Services
  32. * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
  33. *
  34. * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
  35. * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  36. * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
  37. * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  38. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  39. * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  40. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  41. *
  42. * $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $
  43. */
  44. /*
  45. * Packet header = Code, id, length.
  46. */
  47. #define HEADERLEN 4
  48. /*
  49. * CP (LCP, IPCP, etc.) codes.
  50. */
  51. #define CONFREQ 1 /* Configuration Request */
  52. #define CONFACK 2 /* Configuration Ack */
  53. #define CONFNAK 3 /* Configuration Nak */
  54. #define CONFREJ 4 /* Configuration Reject */
  55. #define TERMREQ 5 /* Termination Request */
  56. #define TERMACK 6 /* Termination Ack */
  57. #define CODEREJ 7 /* Code Reject */
  58. /*
  59. * Each FSM is described by an fsm structure and fsm callbacks.
  60. */
  61. typedef struct fsm {
  62. int unit; /* Interface unit number */
  63. int protocol; /* Data Link Layer Protocol field value */
  64. int state; /* State */
  65. int flags; /* Contains option bits */
  66. u_char id; /* Current id */
  67. u_char reqid; /* Current request id */
  68. u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
  69. int timeouttime; /* Timeout time in milliseconds */
  70. int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
  71. int retransmits; /* Number of retransmissions left */
  72. int maxtermtransmits; /* Maximum Terminate-Request transmissions */
  73. int nakloops; /* Number of nak loops since last ack */
  74. int rnakloops; /* Number of naks received */
  75. int maxnakloops; /* Maximum number of nak loops tolerated */
  76. struct fsm_callbacks *callbacks; /* Callback routines */
  77. char *term_reason; /* Reason for closing protocol */
  78. int term_reason_len; /* Length of term_reason */
  79. } fsm;
  80. typedef struct fsm_callbacks {
  81. void (*resetci) /* Reset our Configuration Information */
  82. __P((fsm *));
  83. int (*cilen) /* Length of our Configuration Information */
  84. __P((fsm *));
  85. void (*addci) /* Add our Configuration Information */
  86. __P((fsm *, u_char *, int *));
  87. int (*ackci) /* ACK our Configuration Information */
  88. __P((fsm *, u_char *, int));
  89. int (*nakci) /* NAK our Configuration Information */
  90. __P((fsm *, u_char *, int, int));
  91. int (*rejci) /* Reject our Configuration Information */
  92. __P((fsm *, u_char *, int));
  93. int (*reqci) /* Request peer's Configuration Information */
  94. __P((fsm *, u_char *, int *, int));
  95. void (*up) /* Called when fsm reaches OPENED state */
  96. __P((fsm *));
  97. void (*down) /* Called when fsm leaves OPENED state */
  98. __P((fsm *));
  99. void (*starting) /* Called when we want the lower layer */
  100. __P((fsm *));
  101. void (*finished) /* Called when we don't want the lower layer */
  102. __P((fsm *));
  103. void (*protreject) /* Called when Protocol-Reject received */
  104. __P((int));
  105. void (*retransmit) /* Retransmission is necessary */
  106. __P((fsm *));
  107. int (*extcode) /* Called when unknown code received */
  108. __P((fsm *, int, int, u_char *, int));
  109. char *proto_name; /* String name for protocol (for messages) */
  110. } fsm_callbacks;
  111. /*
  112. * Link states.
  113. */
  114. #define INITIAL 0 /* Down, hasn't been opened */
  115. #define STARTING 1 /* Down, been opened */
  116. #define CLOSED 2 /* Up, hasn't been opened */
  117. #define STOPPED 3 /* Open, waiting for down event */
  118. #define CLOSING 4 /* Terminating the connection, not open */
  119. #define STOPPING 5 /* Terminating, but open */
  120. #define REQSENT 6 /* We've sent a Config Request */
  121. #define ACKRCVD 7 /* We've received a Config Ack */
  122. #define ACKSENT 8 /* We've sent a Config Ack */
  123. #define OPENED 9 /* Connection available */
  124. /*
  125. * Flags - indicate options controlling FSM operation
  126. */
  127. #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
  128. #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
  129. #define OPT_SILENT 4 /* Wait for peer to speak first */
  130. /*
  131. * Timeouts.
  132. */
  133. #define DEFTIMEOUT 3 /* Timeout time in seconds */
  134. #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
  135. #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
  136. #define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
  137. /*
  138. * Prototypes
  139. */
  140. void fsm_init __P((fsm *));
  141. void fsm_lowerup __P((fsm *));
  142. void fsm_lowerdown __P((fsm *));
  143. void fsm_open __P((fsm *));
  144. void fsm_close __P((fsm *, char *));
  145. void fsm_input __P((fsm *, u_char *, int));
  146. void fsm_protreject __P((fsm *));
  147. void fsm_sdata __P((fsm *, int, int, u_char *, int));
  148. /*
  149. * Variables
  150. */
  151. extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */