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 #include "pana_paa_fsm.h"
00035
00036 PANA_PaaStateTable PANA_PaaSession::m_StateTable;
00037 typedef PANA_SessionRxInterface<PANA_Paa> PANA_PaaSessionRxInterface;
00038
00039 class PANA_PsmRxDiscover : public PANA_PaaSessionRxInterface
00040 {
00041 public:
00042 PANA_PsmRxDiscover(PANA_Paa &a, PANA_PaaSession &s) :
00043 PANA_PaaSessionRxInterface(a),
00044 m_Session(s) { }
00045 virtual void operator()(PANA_Message &msg) {
00046
00047 m_arg.ValidateMessage(msg);
00048
00049 ACE_DEBUG((LM_INFO, "(%P|%t) RECV: Discover [session], S-flag %d, tseq=%d, rseq=%d\n",
00050 msg.flags().separate, msg.tseq(), msg.rseq()));
00051
00052 m_arg.m_RxMessageQueue.push_back(&msg);
00053 m_Session.Notify(PANA_RX_DISCOVER);
00054 }
00055 virtual PANA_PaaSessionRxInterface *clone() { return (new PANA_PsmRxDiscover(*this)); }
00056 private:
00057 PANA_PaaSession &m_Session;
00058 };
00059
00060 class PANA_PsmRxStartMsg : public PANA_PaaSessionRxInterface
00061 {
00062 public:
00063 PANA_PsmRxStartMsg(PANA_Paa &a, PANA_PaaSession &s) :
00064 PANA_PaaSessionRxInterface(a),
00065 m_Session(s) { }
00066 virtual void operator()(PANA_Message &msg) {
00067
00068 if (msg.flags().request) {
00069 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00070 "server received invalid message in discovery state"));
00071 }
00072
00073 if (m_arg.m_SessionId.size() > 0) {
00074 if (! PANA_CONFIG_AUTHAGENT().use_cookie_) {
00075 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00076 "PSA w/ session id received under stateful mode"));
00077 }
00078 if (! PANA_CONFIG_GENERAL().mobility_) {
00079 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00080 "Session resumption not enabled, discarding message"));
00081 }
00082 PANA_Paa::ValidateCookie(msg);
00083 m_Session.Notify(PANA_RX_START_ANSWER_SR);
00084 return;
00085 }
00086
00087 m_arg.ValidateMessage(msg);
00088
00089 m_arg.m_RxMessageQueue.push_back(&msg);
00090 m_Session.Notify(PANA_RX_START_ANSWER);
00091 }
00092 virtual PANA_PaaSessionRxInterface *clone() { return (new PANA_PsmRxStartMsg(*this)); }
00093 private:
00094 PANA_PaaSession &m_Session;
00095 };
00096
00097 class PANA_PsmRxAuthMsg : public PANA_PaaSessionRxInterface
00098 {
00099 public:
00100 PANA_PsmRxAuthMsg(PANA_Paa &a, PANA_PaaSession &s) :
00101 PANA_PaaSessionRxInterface(a),
00102 m_Session(s) { }
00103 virtual void operator()(PANA_Message &msg) {
00104
00105 m_arg.ValidateMessage(msg);
00106
00107 if (msg.flags().request) {
00108 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00109 "server received invalid message"));
00110 }
00111 m_arg.m_RxMessageQueue.push_back(&msg);
00112 m_Session.Notify(PANA_RX_AUTH_ANSWER);
00113 }
00114 virtual PANA_PaaSessionRxInterface *clone() { return (new PANA_PsmRxAuthMsg(*this)); }
00115 private:
00116 PANA_PaaSession &m_Session;
00117 };
00118
00119 class PANA_PsmRxBindMsg : public PANA_PaaSessionRxInterface
00120 {
00121 public:
00122 PANA_PsmRxBindMsg(PANA_Paa &a, PANA_PaaSession &s) :
00123 PANA_PaaSessionRxInterface(a),
00124 m_Session(s) { }
00125 virtual void operator()(PANA_Message &msg) {
00126
00127 m_arg.ValidateMessage(msg);
00128
00129
00130 if ((msg.type() != PANA_MTYPE_BIND) && msg.flags().request) {
00131 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00132 "server received invalid message"));
00133 }
00134
00135 ACE_DEBUG((LM_INFO, "(%P|%t) RECV: Bind answer [session], S-flag %d, tseq=%d, rseq=%d\n",
00136 msg.flags().separate, msg.tseq(), msg.rseq()));
00137
00138 AAA_Event ev;
00139 AAAAvpContainer *c_keyId;
00140 switch (m_arg.BindResult()) {
00141 case PANA_BIND_SUCCESS_INITIAL:
00142 case PANA_BIND_SUCCESS_FINAL:
00143
00144 if ((c_keyId = msg.avpList().search("Key-Id"))) {
00145 diameter_integer32_t &id = (*c_keyId)[0]->dataRef
00146 (Type2Type<diameter_integer32_t>());
00147 if (id != m_arg.SA().KeyId()) {
00148 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00149 "server received bind answer with mis-match key id"));
00150 }
00151 ACE_DEBUG((LM_INFO, "(%P|%t) key id=%d\n", id));
00152 }
00153
00154
00155 m_Session.Timer().Schedule(PANA_TID_SESSION,
00156 PANA_CONFIG_AUTHAGENT().sessionLifetime_);
00157
00158 case PANA_BIND_FAILED: ev = PANA_RX_BIND_ANSWER; break;
00159 case PANA_BIND_INTERIM: ev = PANA_RX_BIND_ANSWER_2NDEAP; break;
00160 default:
00161 throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE,
00162 "server computed invalid bind result"));
00163 }
00164 m_arg.m_RxMessageQueue.push_back(&msg);
00165 m_Session.Notify(ev);
00166 };
00167 virtual PANA_PaaSessionRxInterface *clone() { return (new PANA_PsmRxBindMsg(*this)); }
00168 private:
00169 PANA_PaaSession &m_Session;
00170 };
00171
00172 class PANA_PsmRxReAuthMsg : public PANA_PaaSessionRxInterface
00173 {
00174 public:
00175 PANA_PsmRxReAuthMsg(PANA_Paa &a, PANA_PaaSession &s) :
00176 PANA_PaaSessionRxInterface(a),
00177 m_Session(s) { }
00178 virtual void operator()(PANA_Message &msg) {
00179
00180 m_arg.ValidateMessage(msg);
00181
00182 if (msg.flags().request) {
00183 m_arg.m_RxMessageQueue.push_back(&msg);
00184 m_Session.Notify(PANA_RX_REAUTH_REQUEST);
00185 }
00186 else if ((m_arg.SA().MSK().size() > 0) && PANA_CONFIG_GENERAL().mobility_) {
00187 m_arg.m_RxMessageQueue.push_back(&msg);
00188 m_Session.Notify(PANA_RX_REAUTH_ANSWER);
00189 }
00190 else {
00191 delete &msg;
00192 }
00193 };
00194 virtual PANA_PaaSessionRxInterface *clone() { return (new PANA_PsmRxReAuthMsg(*this)); }
00195 private:
00196 PANA_PaaSession &m_Session;
00197 };
00198
00199 class PANA_PsmRxTermMsg : public PANA_PaaSessionRxInterface
00200 {
00201 public:
00202 PANA_PsmRxTermMsg(PANA_Paa &a, PANA_PaaSession &s) :
00203 PANA_PaaSessionRxInterface(a),
00204 m_Session(s) { }
00205 virtual void operator()(PANA_Message &msg) {
00206
00207 m_arg.ValidateMessage(msg);
00208
00209 m_arg.m_RxMessageQueue.push_back(&msg);
00210 (msg.flags().request) ? m_Session.Notify(PANA_RX_TERM_REQUEST) :
00211 m_Session.Notify(PANA_RX_TERM_ANSWER);
00212 };
00213 virtual PANA_PaaSessionRxInterface *clone() { return (new PANA_PsmRxTermMsg(*this)); }
00214 private:
00215 PANA_PaaSession &m_Session;
00216 };
00217
00218 void PANA_PaaSession::InitializeMsgMaps()
00219 {
00220 PANA_PsmRxDiscover discover(m_Paa, *this);
00221 m_MsgHandlers.Register(PANA_MTYPE_DISCOVER, discover);
00222
00223 PANA_PsmRxStartMsg startMsg(m_Paa, *this);
00224 m_MsgHandlers.Register(PANA_MTYPE_START, startMsg);
00225
00226 PANA_PsmRxAuthMsg authMsg(m_Paa, *this);
00227 m_MsgHandlers.Register(PANA_MTYPE_AUTH, authMsg);
00228
00229 PANA_PsmRxBindMsg bindMsg(m_Paa, *this);
00230 m_MsgHandlers.Register(PANA_MTYPE_BIND, bindMsg);
00231
00232 PANA_PsmRxReAuthMsg reAuthMsg(m_Paa, *this);
00233 m_MsgHandlers.Register(PANA_MTYPE_REAUTH, reAuthMsg);
00234
00235 PANA_PsmRxTermMsg termMsg(m_Paa, *this);
00236 m_MsgHandlers.Register(PANA_MTYPE_TERM, termMsg);
00237 }
00238
00239 void PANA_PaaSession::FlushMsgMaps()
00240 {
00241 m_MsgHandlers.Remove(PANA_MTYPE_START);
00242 m_MsgHandlers.Remove(PANA_MTYPE_AUTH);
00243 m_MsgHandlers.Remove(PANA_MTYPE_BIND);
00244 m_MsgHandlers.Remove(PANA_MTYPE_REAUTH);
00245 m_MsgHandlers.Remove(PANA_MTYPE_TERM);
00246 }
00247
00248 PANA_PaaSessionChannel::PANA_PaaSessionChannel(PANA_Node &n) :
00249 m_Node(n),
00250 m_UdpChannel(n.Job(), "PAA UDP Channel"),
00251 m_McastChannel(n.Job(), "PAA Mcast Channel")
00252 {
00253 ACE_INET_Addr addr;
00254 PANA_UdpTransport tempSock;
00255 try {
00256 if (tempSock.open(PANA_CONFIG_GENERAL().iface_name_, addr) < 0) {
00257 throw (0);
00258 }
00259
00260 PANA_DeviceIdContainer dev;
00261 if (tempSock.get_local_addr(dev) < 0) {
00262 throw (1);
00263 }
00264
00265 PANA_DeviceId *id = dev.search(PANA_DeviceId::IPV4_ADDRESS);
00266 if (id == NULL) {
00267 throw (1);
00268 }
00269
00270 ACE_UINT32 *ipAddr = (ACE_UINT32*)id->id().data();
00271 addr.set((u_short)PANA_CONFIG_GENERAL().listen_port_, *ipAddr);
00272 tempSock.close();
00273 }
00274 catch (int rc) {
00275 if (rc) {
00276 tempSock.close();
00277 }
00278 char localBuf[64];
00279 ACE_OS::sprintf(localBuf, "Failed to retrieve local address for %s",
00280 PANA_CONFIG_GENERAL().iface_name_.data());
00281 throw (PANA_Exception(PANA_Exception::FAILED, localBuf));
00282 }
00283
00284 m_UdpChannel.Open(addr);
00285
00286 char strAddr[64];
00287 ACE_OS::sprintf(strAddr, "%s:%d",
00288 PANA_CONFIG_AUTHAGENT().mcast_address_.data(),
00289 PANA_CONFIG_AUTHAGENT().mcast_port_number_);
00290 addr.set(strAddr);
00291 m_McastChannel.Open(addr);
00292 }
00293
00294 PANA_PaaSessionChannel::~PANA_PaaSessionChannel()
00295 {
00296 m_UdpChannel.Close();
00297 m_McastChannel.Close();
00298 }
00299
00300