Main Page | Class List | Directories | File List | Class Members

diameter_mip4_aaas_server_session.hxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General License for more details.                               */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 
00035 /* 
00036    diameter_mip4_aaas_server_session.hxx
00037    Server Session definition for Diameter MIP4 AAA Server Application 
00038    Written by Miriam Tauil
00039    Created October 8th, 2004.
00040 */
00041 
00042 #ifndef __MIP4_AAAS_SERVER_SESSION_H__
00043 #define __MIP4_AAAS_SERVER_SESSION_H__
00044 
00045 #include <string>
00046 #include <list>
00047 #include "ace/Synch.h"
00048 #include "diameter_api.h"
00049 #include "diameter_mip4_parser.hxx"
00050 #include "diameter_mip4_aaas_server_fsm.hxx"
00051 #include "diameter_mip4_aaas_server_sint_interface.hxx"
00052 #include "diameter_mip4_aaas_client_session.hxx"
00053 
00054 #include "aaa_data_defs.h"  //retrieve local realm from configuration file
00055 
00059 template<class SpecificAaaSServerSession > 
00060 class DIAMETER_MIP4_AAAS_SERVER_EXPORTS DiameterMip4AaaSServerSession : 
00061   public AAAServerSession, public DiameterMip4AaaSServerStateMachine,
00062   public DiameterMip4AaaSServerSessionInterface
00063 {
00064  public:
00065 
00067   //class DIAMETER_MIP4_AAAS_SERVER_EXPORTS AMR_Handler:public AAASessionMessageHandler
00068 class AMR_Handler:public AAASessionMessageHandler
00069   {
00070   public:
00071     AMR_Handler(AAAApplicationCore &appCore, 
00072                 DiameterMip4AaaSServerSession<SpecificAaaSServerSession >  &s) 
00073       : AAASessionMessageHandler(appCore, MipAmrCommandCode),
00074         session(s)
00075     {}
00076   private:
00077     DiameterMip4AaaSServerSession<SpecificAaaSServerSession >  &session;
00078     AAAReturnCode HandleMessage (AAAMessage &msg)
00079     {
00080       // Header flag check.
00081       if (!msg.hdr.flags.r)
00082         {
00083           AAA_LOG(LM_ERROR, "[%N] Received AMA instead of AMR.\n");
00084           return AAA_ERR_UNKNOWN_CMD;
00085         }
00086 
00087       // Parse the received message.
00088       AMR_Parser parser;
00089       parser.setAppData(&session.amrData);
00090       parser.setRawData(&msg);
00091 
00092       try {
00093         parser.parseRawToApp();
00094       }
00095       catch ( DiameterParserError ) 
00096         {
00097           AAA_LOG(LM_ERROR, "[%N] Payload error.\n");
00098           return AAA_ERR_PARSING_ERROR;
00099         }
00100 
00101       session.Notify(DiameterMip4AaaSServerStateMachine::EvRxAMR);
00102       return AAA_ERR_SUCCESS;
00103    
00104     }
00105   };
00106 
00108   DiameterMip4AaaSServerSession( AAAApplicationCore &appCore, 
00109                          diameter_unsigned32_t appId=Mip4ApplicationId):
00110     AAAServerSession(appCore, Mip4ApplicationId),  
00111     DiameterMip4AaaSServerStateMachine(*this, appCore.GetTask().JobHandle()),
00112     specificAaaSServerSession(*new SpecificAaaSServerSession()),
00113     clientSession( *new DiameterMip4AaaSClientSession( appCore, *this))
00114   {
00115 
00116     requestHandler = (new AMR_Handler(appCore, *this));
00117     
00118     // Register the AMR message handler
00119     if (RegisterMessageHandler( requestHandler) != AAA_ERR_SUCCESS)
00120     {
00121       AAA_LOG(LM_ERROR, "[%N] AMR_Handler registration failed.\n");
00122       throw -1; 
00123     }
00124   }
00125 
00127   ~DiameterMip4AaaSServerSession() 
00128   {
00129     delete (&specificAaaSServerSession);
00130     delete (&clientSession);
00131     delete requestHandler;
00132   }
00133   
00134 
00135   // this is for aaas client session to pass information back to this session  
00136   // part of implementation of the DiameterMip4AaaSServerSessionInterface
00137   void ServerSessionNotify (AAA_Event ev)
00138   {
00139     Notify(ev);
00140   }
00141 
00142   //this is for the aaas server fsm to notify aaas client session to send HAR
00143   void NotifyClientSession( int event)
00144   {
00145     clientSession.Notify( event);
00146   }
00147   
00148 
00150   DiameterMip4AaaSServerSession* Self() { return this; }
00151 
00153   AAAReturnCode HandleMessage(AAAMessage &msg)
00154   {
00155     AAA_LOG(LM_ERROR, "[%N] Unknown command.\n");
00156     return AAA_ERR_UNKNOWN_CMD;
00157   }
00158 
00160   AAAReturnCode HandleDisconnect()
00161   {
00162     AAA_LOG(LM_ERROR, "[%N] Session termination event received.\n");
00163     Notify(DiameterMip4AaaSServerStateMachine::EvSgDisconnect);
00164     return AAA_ERR_SUCCESS; 
00165   }
00166 
00168   AAAReturnCode HandleSessionTimeout()
00169   { 
00170     AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n");
00171     Notify(DiameterMip4AaaSServerStateMachine::EvSgSessionTimeout);
00172     return AAA_ERR_SUCCESS; 
00173   }
00174           
00176   AAAReturnCode HandleAuthLifetimeTimeout()
00177   { 
00178     AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00179     Notify(DiameterMip4AaaSServerStateMachine::EvSgAuthLifetimeTimeout);
00180     return AAA_ERR_SUCCESS; 
00181   }
00182                                                                                
00184   AAAReturnCode HandleAuthGracePeriodTimeout()
00185   { 
00186     AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00187     Notify(DiameterMip4AaaSServerStateMachine::EvSgAuthGracePeriodTimeout);
00188     return AAA_ERR_SUCCESS; 
00189   }
00190 
00192   AAAReturnCode HandleAbort() { return AAA_ERR_SUCCESS; }
00193 
00196   AAAReturnCode HandleTimeout()
00197   { 
00198     AAA_LOG(LM_ERROR, "[%N] General timeout received.\n");
00199     Notify(DiameterMip4AaaSServerStateMachine::EvSgTimeout);
00200     return AAA_ERR_SUCCESS; 
00201   }
00202 
00203   void Start() throw (AAA_Error)
00204   {
00205     DiameterMip4AaaSServerStateMachine::Start();
00206 
00207   }
00208 
00209   AAAReturnCode Reset() throw (AAA_Error)
00210   {    
00211     AAAServerSession::Reset();  //Start();
00212 
00213     //sets the session state to StInitialize
00214     DiameterMip4AaaSServerStateMachine::Restart();
00215    
00216     return( specificAaaSServerSession.Reset() );
00217   }
00218 
00219   int SetMnHaNonce( diameter_octetstring_t &mnHaNonce)     //MnHaNonce for Mn
00220   {
00221     return specificAaaSServerSession.SetMnHaNonce( mnHaNonce);
00222     //return 1;
00223   }
00224   int SetHaMnKey(  AAA_ScholarAttribute<diameter_octetstring_t> &mipSessionKey)  //MnHaKey for HA
00225   {
00226     diameter_octetstring_t _mipSessionKey;
00227     int rc = specificAaaSServerSession.SetHaMnKey( _mipSessionKey);
00228     if (rc)
00229       mipSessionKey.Set( _mipSessionKey);
00230     return rc;
00231     
00232   }
00233   int SetAlgorithmType( AAA_ScholarAttribute<diameter_unsigned32_t> &mipAlgorithmType)
00234   {
00235     diameter_unsigned32_t _mipAlgorithmType;
00236     specificAaaSServerSession.SetAlgorithmType( &_mipAlgorithmType);
00237     mipAlgorithmType.Set( _mipAlgorithmType);
00238     return 1;
00239   }
00240 
00241   int SetReplayMode( AAA_ScholarAttribute<diameter_unsigned32_t> &mipReplayMode)
00242   {
00243     diameter_unsigned32_t _mipReplayMode;
00244     specificAaaSServerSession.SetReplayMode( &_mipReplayMode);
00245     mipReplayMode.Set( _mipReplayMode);
00246     return 1;
00247   }
00248 
00249   int SetAuthorizationLifetime(
00250                AAA_ScholarAttribute<diameter_unsigned32_t>&authLifetime)
00251   {
00252     diameter_unsigned32_t _authorizationLifetime;
00253     if ( specificAaaSServerSession.SetAuthorizationLifetime(
00254                                          &_authorizationLifetime) == 0 )
00255         authLifetime.Set(0);
00256     else
00257         authLifetime.Set(_authorizationLifetime);
00258     return 1;
00259   }
00260 
00261   void SetAuthState( AAA_ScholarAttribute<diameter_enumerated_t> &state)
00262   {
00263     diameter_enumerated_t _state;
00264     specificAaaSServerSession.SetAuthState( &_state);
00265     state.Set( _state);
00266   }
00267  bool AuthenticateUser(std::string UserName, 
00268                              diameter_address_t MipMobileNodeAddress,
00269                              diameter_unsigned32_t MipMnAaaSpi,
00270                              diameter_unsigned32_t MipAuthInputDataLength,
00271                              diameter_unsigned32_t MipAuthenticatorLength,
00272                              diameter_unsigned32_t MipAuthenticatorOffset,
00273                              std::string MipRegRequest )
00274   {
00275     return ( specificAaaSServerSession.AuthenticateUser( 
00276          UserName,  MipMobileNodeAddress,
00277          MipMnAaaSpi, MipAuthInputDataLength, MipAuthenticatorLength,
00278          MipAuthenticatorOffset, MipRegRequest ) );
00279   }
00280 
00281   int SetMipMsaLifetime( 
00282                AAA_ScholarAttribute<diameter_unsigned32_t>&mipMsaLifetime)
00283   {
00284       diameter_unsigned32_t _mipMsaLifetime;
00285       specificAaaSServerSession.SetMipMsaLifetime( &_mipMsaLifetime);
00286       mipMsaLifetime.Set(_mipMsaLifetime);
00287       return 1;
00288   }
00289 
00290   int SetErrorMessage(diameter_utf8string_t &errorMessage)
00291   {
00292     return (specificAaaSServerSession.SetErrorMessage( errorMessage));
00293   }
00294 
00295   bool IsItLocalRealm(diameter_identity_t realm)
00296   {
00297 
00298     // get local realm from config file
00299      if (realm == AAA_CFG_TRANSPORT()->realm)
00300        return 1;
00301      else 
00302        return 0;
00303   }
00304 
00305   // mnFaNonce => MIP-Mn-to-Fa-Msa
00306   int SetMnFaNonce(diameter_octetstring_t &mnFaNonce)
00307   {
00308     return ( specificAaaSServerSession.SetMnFaNonce( mnFaNonce) );
00309   }
00310   
00311   // sent to the Fa in AMA in Mip-Fa-To-Mn-Msa 
00312   int SetMnFaKey(diameter_octetstring_t &mipSessionKey)
00313   {
00314     return ( specificAaaSServerSession.SetMnFaKey( mipSessionKey) );
00315   }
00316   
00317   // sent to the Fa in AMA in Mip-Fa-To-Ha-Msa & to Ha in HAR
00318   int SetFaHaKey(diameter_octetstring_t &mipSessionKey)
00319   {
00320     return ( specificAaaSServerSession.SetFaHaKey( mipSessionKey) );
00321   }
00322   
00323   
00324   int SetAaaSAllocatedHomeAgentHost(
00325                          AAA_ScholarAttribute<diameter_identity_t> &hostname)
00326   {
00327     //return 
00328       (specificAaaSServerSession.SetAaaSAllocatedHomeAgentHost(hostname));
00329     printf ("hostname %s\n", hostname().data());
00330     return 1;
00331   }
00332   
00333 
00334   AMR_Data amrData;
00335   AMA_Data amaData;
00336   HAR_Data harData;
00337   HAA_Data haaData;
00338 
00339   AMR_Data& AMR() { return amrData; }
00340   AMA_Data& AMA() { return amaData; }
00341 
00342   HAR_Data& HAR() { return harData; }
00343   HAA_Data& HAA() { return haaData; }
00344 
00345  protected:
00346  private:
00347 
00348   SpecificAaaSServerSession &specificAaaSServerSession;
00349   DiameterMip4AaaSClientSession &clientSession;
00350 
00351   AMR_Handler *requestHandler;
00352 
00353 };
00354 
00355 #endif

Generated on Thu Apr 7 09:08:51 2005 for Diameter Mobile IP v4 C++ API by  doxygen 1.4.2