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 #ifndef __PANA_PAA_FSM_H__
00035 #define __PANA_PAA_FSM_H__
00036
00037 #include "ace/Singleton.h"
00038 #include "pana_exports.h"
00039 #include "pana_fsm.h"
00040 #include "pana_paa.h"
00041 #include "pana_database.h"
00042
00043 class PANA_EXPORT PANA_PaaStateTable : public AAA_StateTable<PANA_Paa>
00044 {
00045 public:
00046 class PaaReceiveDiscover : public AAA_Action<PANA_Paa> {
00047 virtual void operator()(PANA_Paa &a) { a.ReceiveDiscover(); }
00048 };
00049
00050 class PaaReceiveStartAnswer : public AAA_Action<PANA_Paa> {
00051 virtual void operator()(PANA_Paa &a) { a.ReceiveStartAnswer(); }
00052 };
00053
00054 class PaaReceiveEapReAuth : public AAA_Action<PANA_Paa> {
00055 virtual void operator()(PANA_Paa &a) { a.ReceiveEapReAuth(); }
00056 };
00057
00058 class PaaReceiveEapResponse : public AAA_Action<PANA_Paa> {
00059 virtual void operator()(PANA_Paa &a) { a.ReceiveEapResponse(); }
00060 };
00061
00062 class PaaReceive2ndEapStart : public AAA_Action<PANA_Paa> {
00063 virtual void operator()(PANA_Paa &a) { a.Receive2ndEapStart(); }
00064 };
00065
00066 class PaaSendReAuthRequest : public AAA_Action<PANA_Paa> {
00067 virtual void operator()(PANA_Paa &a) { a.SendReAuthenticateRequest(); }
00068 };
00069
00070 class PaaReceiveReAuthRequest : public AAA_Action<PANA_Paa> {
00071 virtual void operator()(PANA_Paa &a) { a.ReceiveReAuthenticateRequest(); }
00072 };
00073
00074 class PaaReceiveReAuthAnswer : public AAA_Action<PANA_Paa> {
00075 virtual void operator()(PANA_Paa &a) { a.ReceiveReAuthenticateAnswer(); }
00076 };
00077
00078 class PaaReceiveBindAnswer : public AAA_Action<PANA_Paa> {
00079 virtual void operator()(PANA_Paa &a) { a.ReceiveBindAnswer(); }
00080 };
00081
00082 class PaaSendTermRequest : public AAA_Action<PANA_Paa> {
00083 virtual void operator()(PANA_Paa &a) { a.SendTerminationRequest(); }
00084 };
00085
00086 class PaaReceiveTermRequest : public AAA_Action<PANA_Paa> {
00087 virtual void operator()(PANA_Paa &a) { a.ReceiveTerminationRequest(); }
00088 };
00089
00090 class PaaReceiveTermAnswer : public AAA_Action<PANA_Paa> {
00091 virtual void operator()(PANA_Paa &a) { a.ReceiveTerminationAnswer(); }
00092 };
00093
00094 class PaaDisconnect : public AAA_Action<PANA_Paa> {
00095 virtual void operator()(PANA_Paa &a) { a.Disconnect(PANA_AUTHENTICATION_REJECTED); }
00096 };
00097
00098 class PaaReAuthTimeout : public AAA_Action<PANA_Paa> {
00099 virtual void operator()(PANA_Paa &a) { a.Disconnect(PANA_SESSION_TIMEOUT); }
00100 };
00101
00102 class PaaBindRequestTimeout : public AAA_Action<PANA_Paa> {
00103 virtual void operator()(PANA_Paa &a) { a.RetryBindRequest(); }
00104 };
00105
00106 class PaaReAuthRequestTimeout : public AAA_Action<PANA_Paa> {
00107 virtual void operator()(PANA_Paa &a) { a.RetryReAuthenticateRequest(); }
00108 };
00109
00110 class PaaTermRequestTimeout : public AAA_Action<PANA_Paa> {
00111 virtual void operator()(PANA_Paa &a) { a.RetryTerminationRequest(); }
00112 };
00113
00114 class PaaRetryTimeout : public AAA_Action<PANA_Paa> {
00115 virtual void operator()(PANA_Paa &a) { a.Disconnect(PANA_RETRY_TIMEOUT); }
00116 };
00117
00118 typedef AAA_NullAction<PANA_Paa> PaaNullAction;
00119
00120 PANA_PaaStateTable() {
00121
00122 AddStateTableEntry(PANA_ST_OFFLINE, PANA_RX_DISCOVER,
00123 PANA_ST_STATEFUL_DISC, m_acReceiveDiscover);
00124
00125 AddStateTableEntry(PANA_ST_OFFLINE, PANA_RX_START_ANSWER,
00126 PANA_ST_WAIT_AUTH_ANSWER, m_acReceiveStartAnswer);
00127
00128 AddStateTableEntry(PANA_ST_OFFLINE, PANA_RX_START_ANSWER_SR,
00129 PANA_ST_WAIT_AUTH_ANSWER, m_acSendReAuthRequest);
00130
00131 AddWildcardStateTableEntry(PANA_ST_OFFLINE, PANA_ST_OFFLINE);
00132
00133 AddStateTableEntry(PANA_ST_STATEFUL_DISC, PANA_SIG_EAP_REQUEST,
00134 PANA_ST_STATEFUL_DISC, m_acNullAction());
00135
00136 AddStateTableEntry(PANA_ST_STATEFUL_DISC, PANA_RX_START_ANSWER,
00137 PANA_ST_WAIT_AUTH_ANSWER, m_acReceiveStartAnswer);
00138
00139 AddWildcardStateTableEntry(PANA_ST_STATEFUL_DISC, PANA_ST_STATEFUL_DISC);
00140
00141 AddStateTableEntry(PANA_ST_AUTH_FAILED, PANA_RX_BIND_ANSWER,
00142 PANA_ST_OFFLINE, m_acDisconnect);
00143
00144 AddStateTableEntry(PANA_ST_AUTH_FAILED, PANA_TM_BINDREQ_TIMEOUT,
00145 PANA_ST_AUTH_FAILED, m_acBindRequestTimeout);
00146
00147 AddStateTableEntry(PANA_ST_AUTH_FAILED, PANA_TM_DISCONNECT,
00148 PANA_ST_OFFLINE, m_acRetryTimeout);
00149
00150 AddWildcardStateTableEntry(PANA_ST_AUTH_FAILED, PANA_ST_AUTH_FAILED);
00151
00152 AddStateTableEntry(PANA_ST_WAIT_AUTH_ANSWER, PANA_SIG_EAP_REQUEST,
00153 PANA_ST_WAIT_AUTH_ANSWER, m_acNullAction());
00154
00155 AddStateTableEntry(PANA_ST_WAIT_AUTH_ANSWER, PANA_RX_AUTH_ANSWER,
00156 PANA_ST_WAIT_EAP, m_acReceiveEapResponse);
00157
00158 AddWildcardStateTableEntry(PANA_ST_WAIT_AUTH_ANSWER, PANA_ST_WAIT_AUTH_ANSWER);
00159
00160 AddStateTableEntry(PANA_ST_WAIT_EAP, PANA_SIG_EAP_FAILURE,
00161 PANA_ST_AUTH_FAILED, m_acNullAction());
00162
00163 AddStateTableEntry(PANA_ST_WAIT_EAP, PANA_SIG_EAP_REQUEST,
00164 PANA_ST_WAIT_AUTH_ANSWER, m_acNullAction());
00165
00166 AddStateTableEntry(PANA_ST_WAIT_EAP, PANA_SIG_EAP_SUCCESS,
00167 PANA_ST_WAIT_SUCCESS_BIND_ANSWER, m_acNullAction());
00168
00169 AddWildcardStateTableEntry(PANA_ST_WAIT_EAP, PANA_ST_WAIT_EAP);
00170
00171 AddStateTableEntry(PANA_ST_WAIT_SUCCESS_BIND_ANSWER, PANA_RX_BIND_ANSWER,
00172 PANA_ST_OPEN, m_acReceiveBindAnswer);
00173
00174 AddStateTableEntry(PANA_ST_WAIT_SUCCESS_BIND_ANSWER, PANA_RX_BIND_ANSWER_2NDEAP,
00175 PANA_ST_WAIT_AUTH_ANSWER, m_acReceive2ndEapStart);
00176
00177 AddStateTableEntry(PANA_ST_WAIT_SUCCESS_BIND_ANSWER, PANA_TM_BINDREQ_TIMEOUT,
00178 PANA_ST_WAIT_SUCCESS_BIND_ANSWER, m_acBindRequestTimeout);
00179
00180 AddStateTableEntry(PANA_ST_WAIT_SUCCESS_BIND_ANSWER, PANA_TM_DISCONNECT,
00181 PANA_ST_OFFLINE, m_acRetryTimeout);
00182
00183 AddWildcardStateTableEntry(PANA_ST_WAIT_SUCCESS_BIND_ANSWER, PANA_ST_WAIT_SUCCESS_BIND_ANSWER);
00184
00185 AddStateTableEntry(PANA_ST_OPEN, PANA_TM_SESSION_TIMEOUT,
00186 PANA_ST_WAIT_AUTH_ANSWER, m_acReceiveEapReAuth);
00187
00188 AddStateTableEntry(PANA_ST_OPEN, PANA_RX_DISCOVER,
00189 PANA_ST_WAIT_AUTH_ANSWER, m_acReceiveEapReAuth);
00190
00191 AddStateTableEntry(PANA_ST_OPEN, PANA_RX_REAUTH_REQUEST,
00192 PANA_ST_OPEN, m_acReceiveReAuthRequest);
00193
00194 AddStateTableEntry(PANA_ST_OPEN, PANA_SIG_TERMINATE_SESSION,
00195 PANA_ST_SESSION_TERMINATION, m_acSendTermRequest);
00196
00197 AddStateTableEntry(PANA_ST_OPEN, PANA_RX_TERM_REQUEST,
00198 PANA_ST_OFFLINE, m_acReceiveTermRequest);
00199
00200 AddStateTableEntry(PANA_ST_OPEN, PANA_SIG_REAUTH_USER,
00201 PANA_ST_WAIT_REAUTH_ANSWER, m_acSendReAuthRequest);
00202
00203 AddWildcardStateTableEntry(PANA_ST_OPEN, PANA_ST_OPEN);
00204
00205 AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_RX_REAUTH_ANSWER,
00206 PANA_ST_OPEN, m_acReceiveReAuthAnswer);
00207
00208 AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_TM_REAUTHREQ_TIMEOUT,
00209 PANA_ST_WAIT_REAUTH_ANSWER, m_acReAuthRequestTimeout);
00210
00211 AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_TM_DISCONNECT,
00212 PANA_ST_OFFLINE, m_acRetryTimeout);
00213
00214 AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_TM_SESSION_TIMEOUT,
00215 PANA_ST_OFFLINE, m_acReAuthTimeout);
00216
00217 AddWildcardStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_ST_WAIT_REAUTH_ANSWER);
00218
00219 AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_TM_SESSION_TIMEOUT,
00220 PANA_ST_OFFLINE, m_acDisconnect);
00221
00222 AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_RX_TERM_ANSWER,
00223 PANA_ST_OFFLINE, m_acReceiveTermAnswer);
00224
00225 AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_TM_TERMREQ_TIMEOUT,
00226 PANA_ST_SESSION_TERMINATION, m_acTermRequestTimeout);
00227
00228 AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_TM_DISCONNECT,
00229 PANA_ST_OFFLINE, m_acRetryTimeout);
00230
00231 AddWildcardStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_ST_SESSION_TERMINATION);
00232
00233 InitialState(PANA_ST_OFFLINE);
00234 }
00235
00236 private:
00237 PaaReceiveDiscover m_acReceiveDiscover;
00238 PaaReceiveStartAnswer m_acReceiveStartAnswer;
00239 PaaReceiveEapResponse m_acReceiveEapResponse;
00240 PaaReceiveEapReAuth m_acReceiveEapReAuth;
00241 PaaReceive2ndEapStart m_acReceive2ndEapStart;
00242 PaaReceiveBindAnswer m_acReceiveBindAnswer;
00243 PaaSendReAuthRequest m_acSendReAuthRequest;
00244 PaaReceiveReAuthRequest m_acReceiveReAuthRequest;
00245 PaaReceiveReAuthAnswer m_acReceiveReAuthAnswer;
00246 PaaSendTermRequest m_acSendTermRequest;
00247 PaaReceiveTermRequest m_acReceiveTermRequest;
00248 PaaReceiveTermAnswer m_acReceiveTermAnswer;
00249 PaaReAuthTimeout m_acReAuthTimeout;
00250 PaaReAuthRequestTimeout m_acReAuthRequestTimeout;
00251 PaaBindRequestTimeout m_acBindRequestTimeout;
00252 PaaTermRequestTimeout m_acTermRequestTimeout;
00253 PaaRetryTimeout m_acRetryTimeout;
00254 PaaDisconnect m_acDisconnect;
00255 PaaNullAction m_acNullAction;
00256 };
00257
00258 class PANA_EXPORT PANA_PaaSessionChannel
00259 {
00260 public:
00261 PANA_PaaSessionChannel(PANA_Node &n);
00262 ~PANA_PaaSessionChannel();
00263
00264 PANA_Node &Node() {
00265 return m_Node;
00266 }
00267 PANA_UdpChannel &UdpChannel() {
00268 return m_UdpChannel;
00269 }
00270 PANA_McastChannel &McastChannel() {
00271 return m_McastChannel;
00272 }
00273 void RegisterHandler(AAA_CbFunction1<PANA_Message&> &h) {
00274 m_UdpChannel.RegisterHandler(h);
00275 m_McastChannel.RegisterHandler(h);
00276 }
00277 void RegisterHandler(AAA_CbFunction1<int> &h) {
00278 m_UdpChannel.RegisterHandler(h);
00279 m_McastChannel.RegisterHandler(h);
00280 }
00281 void RemoveHandler() {
00282 m_UdpChannel.RemoveHandler();
00283 m_McastChannel.RemoveHandler();
00284 }
00285
00286 protected:
00287 PANA_Node &m_Node;
00288 PANA_UdpChannel m_UdpChannel;
00289 PANA_McastChannel m_McastChannel;
00290 };
00291
00292 class PANA_EXPORT PANA_PaaSession : public PANA_StateMachine<PANA_Paa>
00293 {
00294 public:
00295 PANA_PaaSession(PANA_PaaSessionChannel &ch,
00296 PANA_PaaEventInterface &eif) :
00297 PANA_StateMachine<PANA_Paa>(m_Paa,
00298 m_StateTable,
00299 ch.Node(),
00300 ch.UdpChannel()),
00301 m_Paa(m_TxChannel, m_Timer, eif) {
00302 InitializeMsgMaps();
00303 PANA_StateMachine<PANA_Paa>::Start();
00304 }
00305 virtual ~PANA_PaaSession() {
00306 PANA_StateMachine<PANA_Paa>::Stop();
00307 FlushMsgMaps();
00308 }
00309 virtual void Start() throw (AAA_Error) {
00310 }
00311 virtual void SendEapRequest(AAAMessageBlock *request,
00312 PANA_PINFO type = PANA_PINFO_NONE) {
00313 m_Paa.SendEapMessage(request, type);
00314 Notify(PANA_SIG_EAP_REQUEST);
00315 }
00316 virtual void SendBindRequest(AAAMessageBlock *request,
00317 ACE_UINT32 resultCode) {
00318 PANA_SIG ev;
00319 switch (m_Paa.BindResult(resultCode)) {
00320 case PANA_BIND_SUCCESS_INITIAL:
00321 case PANA_BIND_SUCCESS_FINAL:
00322 case PANA_BIND_INTERIM: ev = PANA_SIG_EAP_SUCCESS; break;
00323 case PANA_BIND_FAILED: ev = PANA_SIG_EAP_FAILURE; break;
00324 default:
00325 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00326 "PANA paa received invalid bind event"));
00327 }
00328 m_Paa.SendBindRequest(request, resultCode);
00329 Notify(ev);
00330 }
00331 virtual void InstallMSK(diameter_octetstring_t &msk) {
00332 m_Paa.MSK(msk);
00333 }
00334 virtual PANA_DeviceId *PeerDeviceId() {
00335 return m_Paa.PeerDeviceId();
00336 }
00337 PANA_CfgProviderInfo &PreferedISP() {
00338 return m_Paa.PreferedISP();
00339 }
00340 PANA_CfgProviderInfo &PreferedNAP() {
00341 return m_Paa.PreferedNAP();
00342 }
00343 virtual void ReAuthenticate() {
00344 Notify(PANA_SIG_REAUTH_USER);
00345 }
00346 virtual void Stop() {
00347 m_Paa.m_TerminationCause = PANA_TC_ADMINISTRATIVE;
00348 Notify(PANA_SIG_TERMINATE_SESSION);
00349 }
00350
00351 private:
00352 void InitializeMsgMaps();
00353 void FlushMsgMaps();
00354
00355 static PANA_PaaStateTable m_StateTable;
00356 PANA_Paa m_Paa;
00357 };
00358
00362 typedef PANA_SessionTree<PANA_PaaSession> PANA_SessionDb;
00363 typedef ACE_Singleton<PANA_SessionDb, ACE_Recursive_Thread_Mutex> PANA_SessionDb_S;
00364
00368 #define PANA_SESSIONDB() PANA_SessionDb_S::instance()
00369 #define PANA_SESSIONDB_ADD(x, y) PANA_SessionDb_S::instance()->Add((x), (y))
00370 #define PANA_SESSIONDB_DEL(x, y) PANA_SessionDb_S::instance()->Remove((x), (y))
00371 #define PANA_SESSIONDB_SEARCH(x) PANA_SessionDb_S::instance()->Search((x))
00372
00373 #endif
00374