Leaked source code of windows server 2003
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.

102 lines
2.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Declares the class EAPFSM.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef EAPFSM_H
  11. #define EAPFSM_H
  12. #pragma once
  13. #include <raseapif.h>
  14. #include <vector>
  15. #include "eaptype.h"
  16. ///////////////////////////////////////////////////////////////////////////////
  17. //
  18. // CLASS
  19. //
  20. // EAPFSM
  21. //
  22. // DESCRIPTION
  23. //
  24. // Implements a Finite State Machine governing the EAP session lifecycle.
  25. // The state machine must be shown all incoming packets and all outgoing
  26. // actions. The main purpose of the FSM is to decide how to respond to
  27. // incoming messages.
  28. //
  29. ///////////////////////////////////////////////////////////////////////////////
  30. class EAPFSM
  31. {
  32. public:
  33. EAPFSM(std::vector<EAPType*>& eapTypes) throw ()
  34. : eapType((eapTypes.front())->dwEapTypeId),
  35. lastSendCode(0),
  36. state(0)
  37. {
  38. types.swap(eapTypes);
  39. }
  40. // Actions in response to messages.
  41. enum Action
  42. {
  43. MAKE_MESSAGE, // Invoke RasEapMakeMessage.
  44. REPLAY_LAST, // Replay the last response from the DLL.
  45. FAIL_NEGOTIATE, // Negotiation failed -- reject the user.
  46. DISCARD // Unexpected packet -- silently discard.
  47. };
  48. // Called to begin a session and retrieve the first type.
  49. EAPType* onBegin() throw ();
  50. // Called whenever the EAP extension DLL generates a new response.
  51. void onDllEvent(
  52. PPP_EAP_ACTION action,
  53. const PPP_EAP_PACKET& sendPacket
  54. ) throw ();
  55. // Called whenever a new packet is received.
  56. Action onReceiveEvent(
  57. const PPP_EAP_PACKET& recvPkt,
  58. EAPType*& newType
  59. ) throw ();
  60. private:
  61. // Returns TRUE if the packet is an expected reponse.
  62. BOOL isExpected(const PPP_EAP_PACKET& recvPkt) const throw ();
  63. // Returns TRUE if the packet is a repeat.
  64. BOOL isRepeat(const PPP_EAP_PACKET& recvPkt) const throw ();
  65. Action selectNewType(BYTE proposal, EAPType*& newType) throw ();
  66. /////////
  67. // Various states for an EAP session.
  68. /////////
  69. enum State
  70. {
  71. STATE_INITIAL = 0,
  72. STATE_NEGOTIATING = 1,
  73. STATE_ACTIVE = 2,
  74. STATE_DONE = 3
  75. };
  76. // Last EAP type offered.
  77. BYTE eapType;
  78. std::vector<EAPType*> types;
  79. BYTE state; // State of the session.
  80. BYTE lastRecvCode; // Last packet code received.
  81. BYTE lastRecvId; // Last packet ID received.
  82. BYTE lastRecvType; // Last packet type received.
  83. BYTE lastSendCode; // Last packet code sent.
  84. BYTE lastSendId; // Next packet ID sent.
  85. };
  86. #endif // EAPFSM_H