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 #include "pana_client_fsm.h"
00036
00037 PANA_ClientStateTable PANA_PacSession::m_StateTable;
00038 typedef PANA_SessionRxInterface<PANA_Client> PANA_ClientSessionRxInterface;
00039
00040 class PANA_CsmRxStartMsg : public PANA_ClientSessionRxInterface
00041 {
00042 public:
00043 PANA_CsmRxStartMsg(PANA_Client &c, PANA_PacSession &s) :
00044 PANA_ClientSessionRxInterface(c), m_Session(s) { }
00045 virtual void operator()(PANA_Message &msg) {
00046
00047 m_arg.ValidateMessage(msg);
00048
00049 if (! msg.flags().request) {
00050 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00051 "client received invalid message in discovery state"));
00052 }
00053
00054 if (msg.tseq() == 0 || msg.rseq() != 0) {
00055 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00056 "Rseq or Tseq field of start answer message is zero"));
00057 }
00058 m_arg.m_RxMessageQueue.push_back(&msg);
00059 m_Session.Notify(PANA_RX_START_REQUEST);
00060 }
00061 virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxStartMsg(*this)); }
00062 private:
00063 PANA_PacSession &m_Session;
00064 };
00065
00066 class PANA_CsmRxAuthMsg : public PANA_ClientSessionRxInterface
00067 {
00068 public:
00069 PANA_CsmRxAuthMsg(PANA_Client &c, PANA_PacSession &s) :
00070 PANA_ClientSessionRxInterface(c), m_Session(s) { }
00071 virtual void operator()(PANA_Message &msg) {
00072
00073 m_arg.ValidateMessage(msg);
00074
00075 if (! msg.flags().request) {
00076 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00077 "client received invalid message"));
00078 }
00079 m_arg.m_RxMessageQueue.push_back(&msg);
00080 m_Session.Notify(PANA_RX_AUTH_REQUEST);
00081 }
00082 virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxAuthMsg(*this)); }
00083 private:
00084 PANA_PacSession &m_Session;
00085 };
00086
00087 class PANA_CsmRxBindMsg : public PANA_ClientSessionRxInterface
00088 {
00089 public:
00090 PANA_CsmRxBindMsg(PANA_Client &c, PANA_PacSession &s) :
00091 PANA_ClientSessionRxInterface(c), m_Session(s) { }
00092 virtual void operator()(PANA_Message &msg) {
00093
00094 m_arg.ValidateMessage(msg);
00095
00096 if (! msg.flags().request) {
00097 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00098 "client received invalid message"));
00099 }
00100
00101 AAAAvpContainer* c_rcode = msg.avpList().search("Result-Code");
00102 if (c_rcode == NULL) {
00103 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00104 "PANA client received bind msg with no result code"));
00105 }
00106 diameter_unsigned32_t &rcode = (*c_rcode)[0]->dataRef(Type2Type<diameter_unsigned32_t>());
00107
00108 AAA_Event ev = PANA_RX_BIND_FAILURE;
00109 switch (m_arg.BindResult(rcode)) {
00110 case PANA_BIND_SUCCESS_INITIAL:
00111 case PANA_BIND_SUCCESS_FINAL: ev = PANA_RX_BIND_FINAL; break;
00112 case PANA_BIND_INTERIM: ev = PANA_RX_BIND_FIRST; break;
00113 case PANA_BIND_FAILED: ev = PANA_RX_BIND_FAILURE; break;
00114 default: break;
00115 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00116 "PANA client received invalid bind event"));
00117 }
00118 m_arg.m_RxMessageQueue.push_back(&msg);
00119 m_Session.Notify(ev);
00120 };
00121 virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxBindMsg(*this)); }
00122 private:
00123 PANA_PacSession &m_Session;
00124 };
00125
00126 class PANA_CsmRxReAuthMsg : public PANA_ClientSessionRxInterface
00127 {
00128 public:
00129 PANA_CsmRxReAuthMsg(PANA_Client &c, PANA_PacSession &s) :
00130 PANA_ClientSessionRxInterface(c), m_Session(s) { }
00131 virtual void operator()(PANA_Message &msg) {
00132
00133 m_arg.ValidateMessage(msg);
00134
00135 if (msg.flags().request && m_Session.IsSessionResumption()) {
00136 m_Session.Notify(PANA_RX_REAUTH_REQUEST);
00137 }
00138 else {
00139 m_arg.m_RxMessageQueue.push_back(&msg);
00140 m_Session.Notify(PANA_RX_REAUTH_ANSWER);
00141 }
00142 };
00143 virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxReAuthMsg(*this)); }
00144 private:
00145 PANA_PacSession &m_Session;
00146 };
00147
00148 class PANA_CsmRxTermMsg : public PANA_ClientSessionRxInterface
00149 {
00150 public:
00151 PANA_CsmRxTermMsg(PANA_Client &c, PANA_PacSession &s) :
00152 PANA_ClientSessionRxInterface(c), m_Session(s) { }
00153 virtual void operator()(PANA_Message &msg) {
00154
00155 m_arg.ValidateMessage(msg);
00156
00157 m_arg.m_RxMessageQueue.push_back(&msg);
00158 (msg.flags().request) ? m_Session.Notify(PANA_RX_TERM_REQUEST) :
00159 m_Session.Notify(PANA_RX_TERM_ANSWER);
00160 };
00161 virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxTermMsg(*this)); }
00162 private:
00163 PANA_PacSession &m_Session;
00164 };
00165
00166 void PANA_PacSession::InitializeMsgMaps()
00167 {
00168 PANA_CsmRxStartMsg startMsg(m_Client, *this);
00169 m_MsgHandlers.Register(PANA_MTYPE_START, startMsg);
00170
00171 PANA_CsmRxAuthMsg authMsg(m_Client, *this);
00172 m_MsgHandlers.Register(PANA_MTYPE_AUTH, authMsg);
00173
00174 PANA_CsmRxBindMsg bindMsg(m_Client, *this);
00175 m_MsgHandlers.Register(PANA_MTYPE_BIND, bindMsg);
00176
00177 PANA_CsmRxReAuthMsg reAuthMsg(m_Client, *this);
00178 m_MsgHandlers.Register(PANA_MTYPE_REAUTH, reAuthMsg);
00179
00180 PANA_CsmRxTermMsg termMsg(m_Client, *this);
00181 m_MsgHandlers.Register(PANA_MTYPE_TERM, termMsg);
00182 }
00183
00184 void PANA_PacSession::FlushMsgMaps()
00185 {
00186 m_MsgHandlers.Remove(PANA_MTYPE_START);
00187 m_MsgHandlers.Remove(PANA_MTYPE_AUTH);
00188 m_MsgHandlers.Remove(PANA_MTYPE_BIND);
00189 m_MsgHandlers.Remove(PANA_MTYPE_REAUTH);
00190 m_MsgHandlers.Remove(PANA_MTYPE_TERM);
00191 }
00192
00193