Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // eapfsm.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // Declares the class EAPFSM
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 08/26/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef _EAPFSM_H_
  19. #define _EAPFSM_H_
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif
  23. #include <raseapif.h>
  24. ///////////////////////////////////////////////////////////////////////////////
  25. //
  26. // CLASS
  27. //
  28. // EAPFSM
  29. //
  30. // DESCRIPTION
  31. //
  32. // Implements a Finite State Machine governing the EAP session lifecycle.
  33. // The state machine must be shown all incoming packets and all outgoing
  34. // actions. The main purpose of the FSM is to decide how to respond to
  35. // incoming messages.
  36. //
  37. ///////////////////////////////////////////////////////////////////////////////
  38. class EAPFSM
  39. {
  40. public:
  41. EAPFSM(BYTE eapType) throw ()
  42. : eapType(eapType),
  43. state(0),
  44. naks(0)
  45. { }
  46. // Actions in response to messages.
  47. enum Action
  48. {
  49. MAKE_MESSAGE, // Invoke RasEapMakeMessage.
  50. REPLAY_LAST, // Replay the last response from the DLL.
  51. FAIL_NEGOTIATE, // Negotiation failed -- reject the user.
  52. DISCARD // Unexpected packet -- silently discard.
  53. };
  54. // Called whenever the EAP extension DLL generates a new response.
  55. void onDllEvent(
  56. PPP_EAP_ACTION action,
  57. const PPP_EAP_PACKET& sendPacket
  58. ) throw ();
  59. // Called whenever a new packet is received.
  60. Action onReceiveEvent(
  61. const PPP_EAP_PACKET& recvPkt
  62. ) throw ();
  63. protected:
  64. // Returns TRUE if the packet is an expected reponse.
  65. BOOL isExpected(const PPP_EAP_PACKET& recvPkt) const throw ()
  66. {
  67. return (recvPkt.Id == expectedId) || passive;
  68. }
  69. // Returns TRUE if the packet is a repeat.
  70. BOOL isRepeat(const PPP_EAP_PACKET& recvPkt) const throw ()
  71. {
  72. return (recvPkt.Id == lastId) && (recvPkt.Data[0] == lastType);
  73. }
  74. /////////
  75. // Various states for an EAP session.
  76. /////////
  77. enum State
  78. {
  79. STATE_INITIAL = 0,
  80. STATE_NEGOTIATING = 1,
  81. STATE_ACTIVE = 2,
  82. STATE_DONE = 3
  83. };
  84. BYTE eapType; // EAP type being negotiated.
  85. BYTE state; // State of the session.
  86. BYTE naks; // Number of NAK's received so far.
  87. BYTE passive; // Non-zero if we're in passive listening mode.
  88. BYTE lastId; // Last packet ID received.
  89. BYTE lastType; // Last packet type received.
  90. BYTE expectedId; // Next packet ID expected.
  91. };
  92. #endif // _EAPFSM_H_