00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __EAP_AUTHFSM_HXX__
00039 #define __EAP_AUTHFSM_HXX__
00040
00041 #include <ace/Basic_Types.h>
00042 #include <string>
00043 #include "eap.hxx"
00044 #include "eap_fsm.hxx"
00045 #include "eap_method_registrar.hxx"
00046
00047
00050 class EAP_EXPORTS EapAuthSwitchStateMachine : public EapSwitchStateMachine
00051 {
00052 public:
00053
00056 void Receive(AAAMessageBlock*);
00057
00067 virtual void Success(AAAMessageBlock *b)=0;
00068
00071 virtual void Success()=0;
00072
00082 virtual void Failure(AAAMessageBlock *b)=0;
00083
00086 virtual void Failure()=0;
00087
00090 inline ACE_UINT16& MaxRetransmissionCount()
00091 { return maxRetransmissionCount; }
00092
00095 inline ACE_UINT16& RetransmissionInterval()
00096 { return retransmissionInterval; }
00097
00099
00100
00102 virtual inline bool IsEapBackend(void) { return false; }
00103
00105 inline bool RetransmissionEnabled() { return (retransmissionInterval != 0); }
00106
00109 inline void NeedInitialRequestToSend(bool b) { needInitialRequestToSend=b; }
00110
00113 inline bool NeedInitialRequestToSend() { return needInitialRequestToSend; }
00114
00116 inline std::string& NotificationString() { return notificationString; }
00117
00119 inline ACE_UINT16& RetransmissionCount() { return retransmissionCount; }
00120
00121 enum EapAuthDecision {
00122 DecisionSuccess,
00123 DecisionFailure,
00124 DecisionContinue,
00125 DecisionPassthrough
00126 };
00127
00129 virtual EapAuthDecision Decision();
00130
00133
00134 enum EapAuthMethodState {
00135 PROPOSED=0,
00136 CONT,
00137 END,
00138 };
00139
00140
00141 EapAuthMethodState& MethodState();
00142
00144 enum event {
00145 EvRxMsg=-1,
00146
00147
00148 EvSgPortEnabled=-2,
00149
00150 EvSgValidResp=-3,
00151
00152
00153 EvSgInvalidResp=-4,
00154
00155 EvSgEndMethod=-5,
00156
00157
00158 EvSgRestart=-6,
00159
00160 EvSgAaaContinue=-7,
00161
00162 EvSgAaaSuccess=-8,
00163
00164 EvSgAaaFailure=-9,
00165 };
00166
00167 protected:
00168
00169
00170 EapAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h)
00171 : EapSwitchStateMachine(r, h),
00172 discardCount(0),
00173 retransmissionCount(0),
00174 maxRetransmissionCount(defaultMaxRetransmissionCount),
00175 retransmissionInterval(defaultRetransmissionInterval),
00176 needInitialRequestToSend(true)
00177 {}
00178
00179 virtual ~EapAuthSwitchStateMachine() {}
00180
00181 static const ACE_UINT16 defaultMaxRetransmissionCount;
00182 static const ACE_UINT16 defaultRetransmissionInterval;
00183
00184 ACE_UINT16 discardCount;
00185 ACE_UINT16 retransmissionCount;
00186 ACE_UINT16 maxRetransmissionCount;
00187 ACE_UINT16 retransmissionInterval;
00188
00189 std::string notificationString;
00190
00191 bool needInitialRequestToSend;
00192
00194 EapAuthMethodState methodState;
00195 };
00196
00199 class EAP_EXPORTS EapStandAloneAuthSwitchStateMachine :
00200 public EapAuthSwitchStateMachine,
00201 public EapStateMachine<EapStandAloneAuthSwitchStateMachine>
00202 {
00203 public:
00204
00205 void Start() throw(AAA_Error)
00206 {
00207
00208
00209 policy.CurrentPolicyElement(policy.InitialPolicyElement());
00210
00211
00212 DeleteMethodStateMachine();
00213
00214
00215 EapStateMachine<EapStandAloneAuthSwitchStateMachine>::Start();
00216
00217
00218 keyData.resize(0);
00219 keyAvailable=false;
00220
00221
00222 Notify(EapAuthSwitchStateMachine::EvSgRestart);
00223 }
00224
00225 inline void Notify(AAA_Event ev)
00226 {
00227 try {
00228 EapStateMachine<EapStandAloneAuthSwitchStateMachine>::Notify(ev);
00229 }
00230 catch (int i) {
00231 ACE_UNUSED_ARG(i);
00232 EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00233 Abort();
00234 }
00235 }
00236
00237 protected:
00238 EapStandAloneAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00239
00240 virtual ~EapStandAloneAuthSwitchStateMachine();
00241 };
00242
00245 class EAP_EXPORTS EapBackendAuthSwitchStateMachine :
00246 public EapAuthSwitchStateMachine,
00247 public EapStateMachine<EapBackendAuthSwitchStateMachine>
00248 {
00249 public:
00250
00251 void Start() throw(AAA_Error)
00252 {
00253
00254
00255 policy.CurrentPolicyElement(policy.InitialPolicyElement());
00256
00257
00258 EapStateMachine<EapBackendAuthSwitchStateMachine>::Start();
00259
00260
00261 keyData.resize(0);
00262 keyAvailable=false;
00263
00264
00265 Notify(EapAuthSwitchStateMachine::EvSgRestart);
00266 }
00267
00268 inline void Notify(AAA_Event ev)
00269 {
00270 try {
00271 EapStateMachine<EapBackendAuthSwitchStateMachine>::Notify(ev);
00272 }
00273 catch (int i) {
00274 ACE_UNUSED_ARG(i);
00275 EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00276 Abort();
00277 }
00278 }
00279
00281 void Start(AAAMessageBlock *msg);
00282
00283 inline bool IsEapBackend(void) { return true; }
00284
00285 protected:
00286 EapBackendAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00287
00288 virtual ~EapBackendAuthSwitchStateMachine();
00289 };
00290
00293 class EAP_EXPORTS EapPassThroughAuthSwitchStateMachine :
00294 public EapAuthSwitchStateMachine,
00295 public EapStateMachine<EapPassThroughAuthSwitchStateMachine>
00296 {
00297 public:
00298
00299 void Start() throw(AAA_Error)
00300 {
00301
00302
00303 policy.CurrentPolicyElement(policy.InitialPolicyElement());
00304
00305
00306 EapStateMachine<EapPassThroughAuthSwitchStateMachine>::Start();
00307
00308
00309 keyData.resize(0);
00310 keyAvailable=false;
00311
00312
00313 Notify(EapAuthSwitchStateMachine::EvSgRestart);
00314 }
00315
00316 inline void Notify(AAA_Event ev)
00317 {
00318 try {
00319 EapStateMachine<EapPassThroughAuthSwitchStateMachine>::Notify(ev);
00320 }
00321 catch (int i) {
00322 ACE_UNUSED_ARG(i);
00323 EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00324 Abort();
00325 }
00326 }
00327
00331 virtual void ForwardResponse(AAAMessageBlock *msg)=0;
00332
00334 inline EapMessageQueue& AAARxQueue() throw() { return aaaRxQueue; }
00335
00337 ACE_Byte GetNextIdentifier(ACE_Byte id) { return id; }
00338
00340 EapAuthDecision Decision();
00341
00343 void AAA_Success(AAAMessageBlock *msg) throw(int)
00344 {
00345
00346 if (Decision() != DecisionPassthrough)
00347 {
00348 EAP_LOG(LM_ERROR, "Not operating in pass-through mode");
00349 throw -1;
00350 }
00351
00352 if (msg)
00353 AAARxQueue().enqueue_tail(AAAMessageBlock::Acquire(msg));
00354
00355 Notify(EvSgAaaSuccess);
00356 }
00357
00359 void AAA_Failure(AAAMessageBlock *msg) throw(int)
00360 {
00361
00362 if (Decision() != DecisionPassthrough)
00363 {
00364 EAP_LOG(LM_ERROR, "Not operating in pass-through mode.\n");
00365 throw -1;
00366 }
00367
00368 if (msg)
00369 AAARxQueue().enqueue_tail(AAAMessageBlock::Acquire(msg));
00370
00371 Notify(EvSgAaaFailure);
00372 }
00373
00376 void AAA_Continue(AAAMessageBlock *msg) throw(int)
00377 {
00378
00379 if (Decision() != DecisionPassthrough)
00380 {
00381 EAP_LOG(LM_ERROR, "Not operating in pass-through mode.\n");
00382 throw -1;
00383 }
00384
00385 if (!msg)
00386 {
00387 EAP_LOG(LM_ERROR, "AAAContinue must contain non-null msg.\n");
00388 throw -1;
00389 }
00390 AAARxQueue().enqueue_tail(AAAMessageBlock::Acquire(msg));
00391 Notify(EvSgAaaContinue);
00392 }
00393
00394 protected:
00395 EapPassThroughAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00396 virtual ~EapPassThroughAuthSwitchStateMachine();
00397
00399 EapMessageQueue aaaRxQueue;
00400 };
00401
00402 #endif // __EAP_AUTHFSM_HXX__