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.

154 lines
3.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // eapfsm.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class EAPFSM.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 08/26/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <ias.h>
  19. #include <eapfsm.h>
  20. //////////
  21. // We'll allow the client to send up to three NAK's.
  22. //////////
  23. const BYTE MAX_NAKS = 3;
  24. void EAPFSM::onDllEvent(
  25. PPP_EAP_ACTION action,
  26. const PPP_EAP_PACKET& sendPkt
  27. ) throw ()
  28. {
  29. switch (action)
  30. {
  31. case EAPACTION_NoAction:
  32. {
  33. passive = 1;
  34. break;
  35. }
  36. case EAPACTION_Done:
  37. case EAPACTION_SendAndDone:
  38. {
  39. state = (BYTE)STATE_DONE;
  40. break;
  41. }
  42. case EAPACTION_Send:
  43. case EAPACTION_SendWithTimeout:
  44. case EAPACTION_SendWithTimeoutInteractive:
  45. {
  46. passive = 0;
  47. expectedId = sendPkt.Id;
  48. break;
  49. }
  50. }
  51. }
  52. EAPFSM::Action EAPFSM::onReceiveEvent(
  53. const PPP_EAP_PACKET& recvPkt
  54. ) throw ()
  55. {
  56. // Only responses are ever expected.
  57. if (recvPkt.Code != EAPCODE_Response) { return DISCARD; }
  58. // Default is to discard.
  59. Action action = DISCARD;
  60. switch (state)
  61. {
  62. case STATE_INITIAL:
  63. {
  64. // In the initial state we only accept Response/Identity.
  65. if (recvPkt.Data[0] == 1)
  66. {
  67. state = (BYTE)STATE_NEGOTIATING;
  68. action = MAKE_MESSAGE;
  69. }
  70. break;
  71. }
  72. case STATE_NEGOTIATING:
  73. {
  74. // In the negotiating state, NAK's are allowed.
  75. if (recvPkt.Data[0] == 3)
  76. {
  77. if (++naks <= MAX_NAKS)
  78. {
  79. action = REPLAY_LAST;
  80. }
  81. else
  82. {
  83. // He's over the limit, so negotiation failed.
  84. action = FAIL_NEGOTIATE;
  85. }
  86. }
  87. else if (isRepeat(recvPkt))
  88. {
  89. action = REPLAY_LAST;
  90. }
  91. else if (isExpected(recvPkt))
  92. {
  93. if (recvPkt.Data[0] == eapType)
  94. {
  95. // Once the client agrees to our type; he's locked in.
  96. state = (BYTE)STATE_ACTIVE;
  97. }
  98. action = MAKE_MESSAGE;
  99. }
  100. break;
  101. }
  102. case STATE_ACTIVE:
  103. {
  104. if (recvPkt.Data[0] == 3)
  105. {
  106. action = DISCARD;
  107. }
  108. else if (isRepeat(recvPkt))
  109. {
  110. action = REPLAY_LAST;
  111. }
  112. else if (isExpected(recvPkt))
  113. {
  114. action = MAKE_MESSAGE;
  115. }
  116. break;
  117. }
  118. case STATE_DONE:
  119. {
  120. // The session is over, so all we do is replay repeats.
  121. if (isRepeat(recvPkt))
  122. {
  123. action = REPLAY_LAST;
  124. }
  125. }
  126. }
  127. // If the packet made it through our filters, then we count it as the
  128. // last received.
  129. if (action == MAKE_MESSAGE)
  130. {
  131. lastId = recvPkt.Id;
  132. lastType = recvPkt.Data[0];
  133. }
  134. return action;
  135. }