/* Process model C form file: sgsnSignallingProcedure2.pr.c */
/* Portions of this file copyright 1986-2010 by OPNET Technologies, Inc. */


/*
 =========================== NOTE ==========================
 This file is automatically generated from sgsnSignallingProcedure2.pr.m
 during a process model compilation.

 Do NOT manually edit this file.
 Manual edits will be lost during the next compilation.
 =========================== NOTE ==========================
*/



/* This variable carries the header into the object file */
const char sgsnSignallingProcedure2_pr_c [] = "MIL_3_Tfile_Hdr_ 160A 30A modeler 7 516CFDFC 516CFDFC 1 esl2-10 skathire 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 2871 6                                                                                                                                                                                                                                                                                                                                                                                                         ";
#include <string.h>



/* OPNET system definitions */
#include <opnet.h>



/* Header Block */

#include "gtp.h"
#include "msRecord.h"
#include "mmContext.h"
#include "pdpContext.h"

#define MM_RCV_IN_STRM_FROM_MS 0
#define SM_RCV_IN_STRM_FROM_MS 2
#define MM_XMT_OUT_STRM_TO_MS 0
#define SM_XMT_OUT_STRM_TO_MS 2
#define INTERNAL_HLR_RCV_IN_STRM 1
#define INTERNAL_HLR_XMT_OUT_STRM 1
#define GGSN_RCV_IN_STRM 4
#define GGSN_XMT_OUT_STRM 4
#define MS_DATA_RCV_IN_STRM 3

#define ATTACH_REQUEST 0x01
#define ATTACH_COMPLETE 0x03
#define DETACH_REQUEST 5
#define ACTIVATION_REQUEST 65
#define DEACTIVATION_REQUEST 70

#define CREATE_PDP_CONTEXT_RESPONSE 17
#define DELETE_PDP_CONTEXT_RESPONSE 21


/* End of Header Block */

#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define	BOUT	BIN
#define	BINIT	FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __LINE__;
#else
#define	BINIT
#endif /* #if !defined (VOSD_NO_FIN) */



/* State variable definitions */
typedef struct
	{
	/* Internal state tracking for FSM */
	FSM_SYS_STATE
	/* State Variables */
	char	                   		debugStr[1000]                                  ;
	Stathandle	             		numOfAttachReqRcvd                              ;
	Stathandle	             		numOfAttachAcceptSent                           ;
	Stathandle	             		numOfAttachCompleteRcvd                         ;
	Stathandle	             		numOfAttachRejectSent                           ;
	Stathandle	             		numOfDetachReqRcvd                              ;
	Stathandle	             		numOfDetachAcceptSent                           ;
	Stathandle	             		numOfActivatePDPContextReqRcvd                  ;
	Stathandle	             		numOfActivatePDPContextAcceptSent               ;
	Stathandle	             		numOfActivatePDPContextRejectSent               ;
	Stathandle	             		numOfDeactivatePDPContextReqRcvd                ;
	Stathandle	             		numOfDeactivatePDPContextAcceptSent             ;
	int	                    		attachRequestCounter                            ;
	int	                    		attachAcceptCounter                             ;
	int	                    		attachCompleteCounter                           ;
	int	                    		detachRequestCounter                            ;
	int	                    		detachAcceptCounter                             ;
	int	                    		activatePDPContextRequestCounter                ;
	int	                    		activatePDPContextAcceptCounter                 ;
	int	                    		attachRejectCounter                             ;
	int	                    		activatePDPContextRejectCounter                 ;
	int	                    		deactivatePDPContextRequestCounter              ;
	int	                    		deactivatePDPContextAcceptCounter               ;
	Stathandle	             		numOfCreatePDPContextResponseRcvd               ;
	Stathandle	             		numOfCreatePDPContextRequestSent                ;
	int	                    		createPDPContextRequestCounter                  ;
	int	                    		createPDPContextResponseCounter                 ;
	Stathandle	             		numOfDeletePDPContextRequestSent                ;
	Stathandle	             		numOfDeletePDPContextResponseRcvd               ;
	int	                    		deletePDPContextRequestCounter                  ;
	int	                    		deletePDPContextResponseCounter                 ;
	MMContext	              		mmContext[100]                                  ;	/* MM Context information kept in SGSN.  Information initially */
	                        		                                                	/* retrieved from Internal HLR and then information is then    */
	                        		                                                	/* updated during the process of signalling procedures.        */
	                        		                                                	/* Indexed by imsi                                             */
	                        		                                                	/* Allocated memory space for 100 subscribers but currently    */
	                        		                                                	/* only supported 15 MS (constant defined in msRecord.h)       */
	} sgsnSignallingProcedure2_state;

#define debugStr                		op_sv_ptr->debugStr
#define numOfAttachReqRcvd      		op_sv_ptr->numOfAttachReqRcvd
#define numOfAttachAcceptSent   		op_sv_ptr->numOfAttachAcceptSent
#define numOfAttachCompleteRcvd 		op_sv_ptr->numOfAttachCompleteRcvd
#define numOfAttachRejectSent   		op_sv_ptr->numOfAttachRejectSent
#define numOfDetachReqRcvd      		op_sv_ptr->numOfDetachReqRcvd
#define numOfDetachAcceptSent   		op_sv_ptr->numOfDetachAcceptSent
#define numOfActivatePDPContextReqRcvd		op_sv_ptr->numOfActivatePDPContextReqRcvd
#define numOfActivatePDPContextAcceptSent		op_sv_ptr->numOfActivatePDPContextAcceptSent
#define numOfActivatePDPContextRejectSent		op_sv_ptr->numOfActivatePDPContextRejectSent
#define numOfDeactivatePDPContextReqRcvd		op_sv_ptr->numOfDeactivatePDPContextReqRcvd
#define numOfDeactivatePDPContextAcceptSent		op_sv_ptr->numOfDeactivatePDPContextAcceptSent
#define attachRequestCounter    		op_sv_ptr->attachRequestCounter
#define attachAcceptCounter     		op_sv_ptr->attachAcceptCounter
#define attachCompleteCounter   		op_sv_ptr->attachCompleteCounter
#define detachRequestCounter    		op_sv_ptr->detachRequestCounter
#define detachAcceptCounter     		op_sv_ptr->detachAcceptCounter
#define activatePDPContextRequestCounter		op_sv_ptr->activatePDPContextRequestCounter
#define activatePDPContextAcceptCounter		op_sv_ptr->activatePDPContextAcceptCounter
#define attachRejectCounter     		op_sv_ptr->attachRejectCounter
#define activatePDPContextRejectCounter		op_sv_ptr->activatePDPContextRejectCounter
#define deactivatePDPContextRequestCounter		op_sv_ptr->deactivatePDPContextRequestCounter
#define deactivatePDPContextAcceptCounter		op_sv_ptr->deactivatePDPContextAcceptCounter
#define numOfCreatePDPContextResponseRcvd		op_sv_ptr->numOfCreatePDPContextResponseRcvd
#define numOfCreatePDPContextRequestSent		op_sv_ptr->numOfCreatePDPContextRequestSent
#define createPDPContextRequestCounter		op_sv_ptr->createPDPContextRequestCounter
#define createPDPContextResponseCounter		op_sv_ptr->createPDPContextResponseCounter
#define numOfDeletePDPContextRequestSent		op_sv_ptr->numOfDeletePDPContextRequestSent
#define numOfDeletePDPContextResponseRcvd		op_sv_ptr->numOfDeletePDPContextResponseRcvd
#define deletePDPContextRequestCounter		op_sv_ptr->deletePDPContextRequestCounter
#define deletePDPContextResponseCounter		op_sv_ptr->deletePDPContextResponseCounter
#define mmContext               		op_sv_ptr->mmContext

/* These macro definitions will define a local variable called	*/
/* "op_sv_ptr" in each function containing a FIN statement.	*/
/* This variable points to the state variable data structure,	*/
/* and can be used from a C debugger to display their values.	*/
#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE
#define FIN_PREAMBLE_DEC	sgsnSignallingProcedure2_state *op_sv_ptr;
#define FIN_PREAMBLE_CODE	\
		op_sv_ptr = ((sgsnSignallingProcedure2_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr));


/* Function Block */

#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ + 2};
#endif

void
ggsnRcvd ()
	{
	FIN (ggsnRcvd ());
	sprintf (debugStr, "GGSN messages received");
    op_prg_odb_print_major ("Debug message for SGSN", 
		debugStr, OPC_NIL);	
	FOUT;
    }

void
endSimRcvd ()
	{
	FIN (endSimRcvd ());
	sprintf (debugStr, "EndSim received");
    op_prg_odb_print_major ("Debug message for SGSN", 
		debugStr, OPC_NIL);	
	FOUT;
    }


/* End of Function Block */

/* Undefine optional tracing in FIN/FOUT/FRET */
/* The FSM has its own tracing code and the other */
/* functions should not have any tracing.		  */
#undef FIN_TRACING
#define FIN_TRACING

#undef FOUTRET_TRACING
#define FOUTRET_TRACING

#if defined (__cplusplus)
extern "C" {
#endif
	void sgsnSignallingProcedure2 (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Obtype _op_sgsnSignallingProcedure2_init (int * init_block_ptr);
	void _op_sgsnSignallingProcedure2_diag (OP_SIM_CONTEXT_ARG_OPT);
	void _op_sgsnSignallingProcedure2_terminate (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Address _op_sgsnSignallingProcedure2_alloc (VosT_Obtype, int);
	void _op_sgsnSignallingProcedure2_svar (void *, const char *, void **);


#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
sgsnSignallingProcedure2 (OP_SIM_CONTEXT_ARG_OPT)
	{
#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	FIN_MT (sgsnSignallingProcedure2 ());

		{
		/* Temporary Variables */
		Packet *pkptr;
		/* End of Temporary Variables */


		FSM_ENTER ("sgsnSignallingProcedure2")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "sgsnSignallingProcedure2 [init enter execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [init enter execs]", state0_enter_exec)
				{
				int i;
				
				numOfAttachReqRcvd = op_stat_reg ("Num of Attach Request Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfAttachAcceptSent = op_stat_reg ("Num of Attach Accept Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfAttachCompleteRcvd = op_stat_reg ("Num of Attach Complete Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfAttachRejectSent = op_stat_reg ("Num of Attach Reject Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfDetachReqRcvd = op_stat_reg ("Num of Detach Request Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfDetachAcceptSent = op_stat_reg ("Num of Detach Accept Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfActivatePDPContextReqRcvd = op_stat_reg ("Num of Activate PDP Context Request Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfActivatePDPContextAcceptSent = op_stat_reg ("Num of Activate PDP Context Accept Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfActivatePDPContextRejectSent = op_stat_reg ("Num of Activate PDP Context Reject Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfDeactivatePDPContextReqRcvd = op_stat_reg ("Num of Deactivate PDP Context Request Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				numOfDeactivatePDPContextAcceptSent = op_stat_reg ("Num of DeactivatePDP Context Accept Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfCreatePDPContextRequestSent = op_stat_reg ("Num of Create PDP Context Request Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfCreatePDPContextResponseRcvd = op_stat_reg ("Num of Create PDP Context Response Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfDeletePDPContextRequestSent = op_stat_reg ("Num of Delete PDP Context Request Sent",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				numOfDeletePDPContextResponseRcvd = op_stat_reg ("Num of Delete PDP Context Response Received",
					OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
				
				// initialize the statistics counter
				attachRequestCounter = 0;
				attachAcceptCounter = 0;
				attachCompleteCounter = 0;
				attachRejectCounter = 0;
				detachRequestCounter = 0;
				detachAcceptCounter = 0;
				activatePDPContextRequestCounter = 0;
				activatePDPContextAcceptCounter = 0;
				activatePDPContextRejectCounter = 0;
				deactivatePDPContextRequestCounter = 0;
				deactivatePDPContextAcceptCounter = 0;
				createPDPContextRequestCounter = 0;
				createPDPContextResponseCounter = 0;
				deletePDPContextRequestCounter = 0;
				deletePDPContextResponseCounter = 0;
				
				
				// initialize the imsi and tlli in the mmState state var
				
				for (i=0; i < MAX_SUPPORTED_MS; i++)
					{
					mmContext[i].imsi = -1;
					mmContext[i].tlli = -1;
					mmContext[i].mmState = 0;
					}
				}
				FSM_PROFILE_SECTION_OUT (state0_enter_exec)

			/** state (init) exit executives **/
			FSM_STATE_EXIT_FORCED (0, "init", "sgsnSignallingProcedure2 [init exit execs]")


			/** state (init) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "idle", "tr_17", "sgsnSignallingProcedure2 [init -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (idle) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, "idle", state1_enter_exec, "sgsnSignallingProcedure2 [idle enter execs]")

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (3,"sgsnSignallingProcedure2")


			/** state (idle) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "idle", "sgsnSignallingProcedure2 [idle exit execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [idle exit execs]", state1_exit_exec)
				{
				int intrpt_type, i;
				
				/* Determine the interrupt type as the model perform .	*/
				intrpt_type = op_intrpt_type ();
				
				if (intrpt_type == OPC_INTRPT_ENDSIM)
					{
					printf("SGSN MM and PDP Context after simulation\n");
				    printf("MM State 0 = detached, 1 = Attached\n");
					printf("Attached + Is Active = Activated\n");
					//printf("MM Context\n");
					printf("==========\n");
					for (i=0; i < 13; i++)
						{
						printf("IMSI:   %d\tMM State: %d\tIs Active: %d\n", mmContext[i].imsi, 
							mmContext[i].mmState, mmContext[i].pdpContext.isActive);
						//printf("PTMSI: %d\n", mmContext[i].tlli);
						//printf("MM State: %d\n", mmContext[i].mmState);
						/*
						printf("\tPDPContext\n");
						printf("\t==========\n");
						printf("\tisActive: %d\n", mmContext[i].pdpContext.isActive);
						printf("\tNSAPI: %d\n", mmContext[i].pdpContext.nsapi);
						printf("\tAPN: %s\n", 
							mmContext[i].pdpContext.apnSubscribed.apnNetworkID);
						printf("\tQoS Subscribed - Reliability Class %d\n", 
							mmContext[i].pdpContext.qosSubscribed.reliabilityClass);
						printf("\tQoS Subscribed - Delay Class %d\n", 
							mmContext[i].pdpContext.qosSubscribed.delayClass);
						printf("\tQoS Subscribed - Precedence Class %d\n", 
							mmContext[i].pdpContext.qosSubscribed.precedenceClass);
						printf("\tQoS Subscribed - Peak Bit Rate %d\n", 
							mmContext[i].pdpContext.qosSubscribed.peakBitRate);
						printf("\tQoS Subscribed - Mean Bit Rate %d\n", 
							mmContext[i].pdpContext.qosSubscribed.meanBitRate);
						*/
						}
					}
				}
				FSM_PROFILE_SECTION_OUT (state1_exit_exec)


			/** state (idle) transition processing **/
			FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [idle trans conditions]", state1_trans_conds)
			FSM_INIT_COND (GMM_FROM_MS)
			FSM_TEST_COND (SM_FROM_MS)
			FSM_TEST_COND (RECEIVE_FROM_INTERNAL_HLR)
			FSM_TEST_COND (RECEIVE_FROM_GGSN)
			FSM_TEST_COND (SNDCP_FROM_MS)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("idle")
			FSM_PROFILE_SECTION_OUT (state1_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "GMM_FROM_MS", "", "idle", "gmmMsgRcv", "tr_0", "sgsnSignallingProcedure2 [idle -> gmmMsgRcv : GMM_FROM_MS / ]")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "SM_FROM_MS", "", "idle", "smMsgRcv", "tr_4", "sgsnSignallingProcedure2 [idle -> smMsgRcv : SM_FROM_MS / ]")
				FSM_CASE_TRANSIT (2, 5, state5_enter_exec, ;, "RECEIVE_FROM_INTERNAL_HLR", "", "idle", "internalHLRMsgRcvd", "tr_28", "sgsnSignallingProcedure2 [idle -> internalHLRMsgRcvd : RECEIVE_FROM_INTERNAL_HLR / ]")
				FSM_CASE_TRANSIT (3, 4, state4_enter_exec, ;, "RECEIVE_FROM_GGSN", "", "idle", "ggsnMsgRcvd", "tr_39", "sgsnSignallingProcedure2 [idle -> ggsnMsgRcvd : RECEIVE_FROM_GGSN / ]")
				FSM_CASE_TRANSIT (4, 6, state6_enter_exec, ;, "SNDCP_FROM_MS", "", "idle", "sndcpMsgRcvd", "tr_41", "sgsnSignallingProcedure2 [idle -> sndcpMsgRcvd : SNDCP_FROM_MS / ]")
				FSM_CASE_TRANSIT (5, 1, state1_enter_exec, ;, "default", "", "idle", "idle", "tr_21", "sgsnSignallingProcedure2 [idle -> idle : default / ]")
				}
				/*---------------------------------------------------------*/



			/** state (gmmMsgRcv) enter executives **/
			FSM_STATE_ENTER_FORCED (2, "gmmMsgRcv", state2_enter_exec, "sgsnSignallingProcedure2 [gmmMsgRcv enter execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [gmmMsgRcv enter execs]", state2_enter_exec)
				{
				int messageType;
				double attachReqSentTime;
				int imsi;
				
				int tlli;
				double detachReqSentTime;
				Packet * detachAcceptPkPtr;
				Packet * getInternalHLRInfoReqPtr;
				
				
				pkptr = op_pk_get(MM_RCV_IN_STRM_FROM_MS);
				// retrieve the message type of message sent by SGSN
				op_pk_nfd_get (pkptr, "messageType", &messageType);
				
				switch (messageType) {
				    case ATTACH_REQUEST:
				        // increment the number of attach request received
						attachRequestCounter++;
					    op_stat_write(numOfAttachReqRcvd, attachRequestCounter);
				        	
					    // retrieve the imsi from attach request
					    op_pk_nfd_get(pkptr, "imsi", &imsi);
					
				        // Get MM and PDP Context information from Internal HLR
						getInternalHLRInfoReqPtr = op_pk_create_fmt ("GetInternalHLRInfoRequest");
					  	op_pk_nfd_set(getInternalHLRInfoReqPtr, "imsi", 
							imsi);
					    op_pk_send(getInternalHLRInfoReqPtr, INTERNAL_HLR_XMT_OUT_STRM);
						
					    break;
				     case ATTACH_COMPLETE:
				        // retrieve the tlli of the ms
						op_pk_nfd_get(pkptr, "TLLI", &tlli);
				
					    // change the status of the ms to attached after
						// attach complete is received
						mmContext[tlli].mmState = MSStatus_Attached;
				
						// increment the number of attach complete received
						attachCompleteCounter++;
					    op_stat_write(numOfAttachCompleteRcvd, attachCompleteCounter);	    
						break;
				    case DETACH_REQUEST:
					    // increment the number of detach request received
				        detachRequestCounter++;
				        op_stat_write(numOfDetachReqRcvd, detachRequestCounter);
				
				        // retrieve the tlli of the ms
				        op_pk_nfd_get(pkptr, "TLLI", &tlli);
				        // reply MS with detach accept
				        detachAcceptPkPtr = op_pk_create_fmt ("detachAccept");
				       
				        // set tlli
				        op_pk_nfd_set(detachAcceptPkPtr, "TLLI", 
				            tlli);
						
						//sprintf (debugStr, "Detach Accept sent time %f", op_sim_time());
				        //op_prg_odb_print_major ("Debug message for MS-SGSN", debugStr, OPC_NIL);
				
				         op_pk_send(detachAcceptPkPtr, MM_XMT_OUT_STRM_TO_MS);
				        // change the status of the MS to detached
				        mmContext[tlli].mmState = MSStatus_Detached;
						// change the isActive status to inactive
						mmContext[tlli].pdpContext.isActive = 0;
				
				        // increment the number of detach accept sent
				       detachAcceptCounter++;
				       op_stat_write(numOfDetachAcceptSent, detachAcceptCounter);
						break;
					default:
					    break;
					}
				op_pk_destroy(pkptr);
				}
				FSM_PROFILE_SECTION_OUT (state2_enter_exec)

			/** state (gmmMsgRcv) exit executives **/
			FSM_STATE_EXIT_FORCED (2, "gmmMsgRcv", "sgsnSignallingProcedure2 [gmmMsgRcv exit execs]")


			/** state (gmmMsgRcv) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "gmmMsgRcv", "idle", "tr_1", "sgsnSignallingProcedure2 [gmmMsgRcv -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (smMsgRcv) enter executives **/
			FSM_STATE_ENTER_FORCED (3, "smMsgRcv", state3_enter_exec, "sgsnSignallingProcedure2 [smMsgRcv enter execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [smMsgRcv enter execs]", state3_enter_exec)
				{
				
				double activationReqSentTime;
				Packet * activatePDPContextRejectPkPtr;
				Packet * createPDPContextRequestPkPtr;
				GTPEndUserAddress *gtpEndUserAddressPtr;
				TID *tidStructPtr;
				APN *apnStructPtr;
				QoS *qosStructPtr;
				double deactivationReqSentTime;
				Packet * deactivatePDPContextAcceptPkPtr;
				Packet * deletePDPContextRequestPtr;
				int tlli, nsapi;
				int messageType, rejectCause;
				
				pkptr = op_pk_get(SM_RCV_IN_STRM_FROM_MS);
				// retrieve the message type of message sent by SGSN
				op_pk_nfd_get (pkptr, "messageType", &messageType);
				
				switch (messageType) {
				    case ACTIVATION_REQUEST:
				        // increment the number of activate PDP context request received
				        activatePDPContextRequestCounter++;
				        op_stat_write(numOfActivatePDPContextReqRcvd, activatePDPContextRequestCounter);
				
				        // retrieve the tlli of the ms
				        op_pk_nfd_get(pkptr, "TLLI", &tlli);
					    // retrieve the requested nsapi
					    op_pk_nfd_get(pkptr, "requestedNSAPI", &nsapi);
					
					    // send Create PDP Context Request to GGSN only if the MS is attached
					    // and pdpContext is not active
					    if ( (mmContext[tlli].mmState == MSStatus_Attached) && 
							 (mmContext[tlli].pdpContext.isActive == 0) )
							{
							 // send CreatePDPContextRequest to GGSN
				             createPDPContextRequestPkPtr = op_pk_create_fmt ("CreatePDPContextRequest");
				
							  // allocate a new data structure for TID
						     tidStructPtr = (TID *) op_prg_mem_alloc (sizeof (TID));
						     // set end user address
				             tidStructPtr->imsi = mmContext[tlli].imsi;
							 
							 // save and set the nsapi in CreatePDPContextRequest
							 mmContext[tlli].pdpContext.nsapi = nsapi;
				             tidStructPtr->nsapi = nsapi;
						     // assign the data structure to TID field in the packet
				             op_pk_nfd_set(createPDPContextRequestPkPtr, "TID", tidStructPtr,
				                 op_prg_mem_copy_create, op_prg_mem_free, sizeof (TID));
							 
				             // allocate a new data structure for GTPEndUserAddress
						     gtpEndUserAddressPtr = (GTPEndUserAddress *) 
							 op_prg_mem_alloc (sizeof (GTPEndUserAddress));
						     // set end user address
				             gtpEndUserAddressPtr->type = 128;
				             gtpEndUserAddressPtr->length = 6;
				             gtpEndUserAddressPtr->pdpOrganization = 17;
				             gtpEndUserAddressPtr->pdpType = 33;
						     // assign the data structure to endUserAddress field in the packet
				             op_pk_nfd_set(createPDPContextRequestPkPtr, "endUserAddress", gtpEndUserAddressPtr,
				                 op_prg_mem_copy_create, op_prg_mem_free, sizeof (GTPEndUserAddress));
							 
							 // allocate a new data structure for APN
							 apnStructPtr = (APN *)
								 op_prg_mem_alloc (sizeof (APN));
							 // set APN
							 strncpy(apnStructPtr->apnNetworkID, mmContext[tlli].pdpContext.apnSubscribed.apnNetworkID, 
						         strlen(mmContext[tlli].pdpContext.apnSubscribed.apnNetworkID)+1);
							 // assign the data structure to apn field in the packet
				             op_pk_nfd_set(createPDPContextRequestPkPtr, "apn", apnStructPtr,
				                 op_prg_mem_copy_create, op_prg_mem_free, sizeof (APN));
							 
							 // allocate a new data structure for QoS requested
							 qosStructPtr = (QoS *)
								 op_prg_mem_alloc (sizeof (QoS));
							 // set QoS
							 qosStructPtr->reliabilityClass = mmContext[tlli].pdpContext.qosSubscribed.reliabilityClass;
							 qosStructPtr->delayClass = mmContext[tlli].pdpContext.qosSubscribed.delayClass;
							 qosStructPtr->precedenceClass = mmContext[tlli].pdpContext.qosSubscribed.precedenceClass;
							 qosStructPtr->peakBitRate = mmContext[tlli].pdpContext.qosSubscribed.peakBitRate;
							 qosStructPtr->meanBitRate = mmContext[tlli].pdpContext.qosSubscribed.meanBitRate;
							 
							 // assign the data structure to apn field in the packet
				             op_pk_nfd_set(createPDPContextRequestPkPtr, "qos", qosStructPtr,
				                 op_prg_mem_copy_create, op_prg_mem_free, sizeof (QoS));
							 
							 
				             op_pk_send(createPDPContextRequestPkPtr, GGSN_XMT_OUT_STRM);
						
						     // increment the number of Create PDP context request sent
				             createPDPContextRequestCounter++;
				             op_stat_write(numOfCreatePDPContextRequestSent, createPDPContextRequestCounter);
						     }
					    else
							{
							// reply MS with activate PDP context reject
				            activatePDPContextRejectPkPtr = op_pk_create_fmt ("activatePDPContextReject");
				            // set activtion reject sm Cause, 31 = Activation rejected, unspecified
							rejectCause = 31;
				            op_pk_nfd_set(activatePDPContextRejectPkPtr, "smCause", 
				                rejectCause);
							op_pk_nfd_set(activatePDPContextRejectPkPtr, "TLLI", 
				                tlli);
				            op_pk_send(activatePDPContextRejectPkPtr, SM_XMT_OUT_STRM_TO_MS);
							// increment the number of activate PDP context accept sent
				            //activatePDPContextRejectCounter++;
				            //op_stat_write(numOfActivatePDPContextRejectSent, activatePDPContextRejectCounter);
				            }
				        break;
					case DEACTIVATION_REQUEST:
					    // increment the number of deactivate PDP context request received
				       
				       op_pk_nfd_get(pkptr, "TLLI", &tlli);
				       
					   
					   // send Delete PDP Context Request to GGSN only if the MS is attached
					   // and pdpContext is active
					   if ( (mmContext[tlli].mmState == MSStatus_Attached) && 
							(mmContext[tlli].pdpContext.isActive == 1) )
					       {		
				           deactivatePDPContextRequestCounter++;
				           op_stat_write(numOfDeactivatePDPContextReqRcvd, deactivatePDPContextRequestCounter);
				
						   // send DeletePDPContextRequest to GGSN
				           deletePDPContextRequestPtr = op_pk_create_fmt ("DeletePDPContextRequest");
				           
						   // allocate a new data structure for TID
						   tidStructPtr = (TID *) op_prg_mem_alloc (sizeof (TID));
						   // set end user address
				           tidStructPtr->imsi = mmContext[tlli].imsi;
				           tidStructPtr->nsapi = mmContext[tlli].pdpContext.nsapi;
						   // assign the data structure to TID field in the packet
				           op_pk_nfd_set(deletePDPContextRequestPtr, "TID", tidStructPtr,
				               op_prg_mem_copy_create, op_prg_mem_free, sizeof (TID));
						   
				           op_pk_send(deletePDPContextRequestPtr, GGSN_XMT_OUT_STRM);
						
					       // increment the number of Create PDP context request sent
				           deletePDPContextRequestCounter++;
				           op_stat_write(numOfDeletePDPContextRequestSent, deletePDPContextRequestCounter);
						   }
						else
							{
							// reply MS with deactivate PDP context accept
				            deactivatePDPContextAcceptPkPtr = op_pk_create_fmt ("deactivatePDPContextAccept");
				
							// set tlli
				            op_pk_nfd_set(deactivatePDPContextAcceptPkPtr, "TLLI", 
				                tlli);
				            op_pk_send(deactivatePDPContextAcceptPkPtr, SM_XMT_OUT_STRM_TO_MS);
				            
				            // increment the number of deactivate PDP context accept sent
				            //deactivatePDPContextAcceptCounter++;
				            //op_stat_write(numOfDeactivatePDPContextAcceptSent, deactivatePDPContextAcceptCounter);
							
							}
					   break;
				    default:
					    break;
					   }
				op_pk_destroy(pkptr);
				}
				FSM_PROFILE_SECTION_OUT (state3_enter_exec)

			/** state (smMsgRcv) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "smMsgRcv", "sgsnSignallingProcedure2 [smMsgRcv exit execs]")


			/** state (smMsgRcv) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "smMsgRcv", "idle", "tr_5", "sgsnSignallingProcedure2 [smMsgRcv -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (ggsnMsgRcvd) enter executives **/
			FSM_STATE_ENTER_FORCED (4, "ggsnMsgRcvd", state4_enter_exec, "sgsnSignallingProcedure2 [ggsnMsgRcvd enter execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [ggsnMsgRcvd enter execs]", state4_enter_exec)
				{
				Packet * activatePDPContextAcceptPkPtr;
				Packet * activatePDPContextRejectPkPtr;
				Packet * deactivatePDPContextAcceptPkPtr;
				int messageType, tlli, cause, smCause;
				TID *tidStructPtr;
				QoS *qosStructPtr;
				
				pkptr = op_pk_get(GGSN_RCV_IN_STRM);
				// retrieve the message type of message sent by SGSN
				op_pk_nfd_get (pkptr, "messageType", &messageType);
				
				switch (messageType) {
				    case CREATE_PDP_CONTEXT_RESPONSE:
				        // increment the number of Create PDP Context Response received
				        createPDPContextResponseCounter++;
				        op_stat_write(numOfCreatePDPContextResponseRcvd, createPDPContextResponseCounter);
				
					    // retrieve the TID from CreatePDPContextResponse
					    op_pk_nfd_access(pkptr, "TID", &tidStructPtr);
					
					    tlli = tidStructPtr->imsi;
					
					    // retrieve the cause code to determine whether the 
					    // creation of PDP Context in GGSN is successful or not
					    op_pk_nfd_get (pkptr, "cause", &cause);
				        // if request accepted
					    if (cause == 128)
							{
					        // retrieve the negotiated QoS from CreatePDPContextResponse
					        // and store it into mmContext
					        op_pk_nfd_access(pkptr, "qos", &qosStructPtr);
					        mmContext[tlli].pdpContext.qosNegotiated.reliabilityClass = 
							    qosStructPtr->reliabilityClass;
					        mmContext[tlli].pdpContext.qosNegotiated.delayClass = 
							    qosStructPtr->delayClass;
					        mmContext[tlli].pdpContext.qosNegotiated.precedenceClass = 
							    qosStructPtr->precedenceClass;
					        mmContext[tlli].pdpContext.qosNegotiated.peakBitRate = 
							    qosStructPtr->peakBitRate;
					        mmContext[tlli].pdpContext.qosNegotiated.meanBitRate = 
							    qosStructPtr->meanBitRate;
						    	   
					        // reply MS with activate PDP context accept
				            activatePDPContextAcceptPkPtr = op_pk_create_fmt ("activatePDPContextAccept");
				        
					        // set the tlli (imsi) in the activatePDPContextAccept
					        op_pk_nfd_set(activatePDPContextAcceptPkPtr, "TLLI", 
				                tlli);
				            op_pk_send(activatePDPContextAcceptPkPtr, SM_XMT_OUT_STRM_TO_MS);
				            // change the status of the MS to activated
				            mmContext[tlli].pdpContext.isActive = 1;
				
				            // increment the number of activate PDP context accept sent
				            activatePDPContextAcceptCounter++;
				            op_stat_write(numOfActivatePDPContextAcceptSent, activatePDPContextAcceptCounter);
							}
					    else
							{
							 // reply MS with activate PDP context reject
				            activatePDPContextRejectPkPtr = op_pk_create_fmt ("activatePDPContextReject");
				        
					        // set the tlli (imsi) in the activatePDPContextReject
					        op_pk_nfd_set(activatePDPContextRejectPkPtr, "TLLI", 
				                tlli);
							// set the sm cause in the activatePDPContextReject
				            // smCause = Activation rejected by GGSN
							smCause = 30;
					        op_pk_nfd_set(activatePDPContextRejectPkPtr, "smCause", 
				                smCause);
										
				            op_pk_send(activatePDPContextRejectPkPtr, SM_XMT_OUT_STRM_TO_MS);
				            // MS PDP context status is still inactive
				            mmContext[tlli].pdpContext.isActive = 0;
				
				            // increment the number of activate PDP context accept sent
				            activatePDPContextRejectCounter++;
				            op_stat_write(numOfActivatePDPContextRejectSent, activatePDPContextRejectCounter);
							
							}
					    break;
					case DELETE_PDP_CONTEXT_RESPONSE:
					   // increment the number of Create PDP Context Response received
				        deletePDPContextResponseCounter++;
				        op_stat_write(numOfDeletePDPContextResponseRcvd, deletePDPContextResponseCounter);
						
						// retrieve the TID from CreatePDPContextResponse
					    op_pk_nfd_access(pkptr, "TID", &tidStructPtr);
					    tlli = tidStructPtr->imsi;
						
						// reply MS with deactivate PDP context accept
				        deactivatePDPContextAcceptPkPtr = op_pk_create_fmt ("deactivatePDPContextAccept");
				        // set tlli
				        op_pk_nfd_set(deactivatePDPContextAcceptPkPtr, "TLLI", 
				            tlli);
				        op_pk_send(deactivatePDPContextAcceptPkPtr, SM_XMT_OUT_STRM_TO_MS);
				        
						// change the isActive status to inactive
						mmContext[tlli].pdpContext.isActive = 0;
						
				        // increment the number of deactivate PDP context accept sent
				        deactivatePDPContextAcceptCounter++;
				        op_stat_write(numOfDeactivatePDPContextAcceptSent, deactivatePDPContextAcceptCounter);
						
					    break;
					default:
					    break;
					}
				op_pk_destroy(pkptr);
				}
				FSM_PROFILE_SECTION_OUT (state4_enter_exec)

			/** state (ggsnMsgRcvd) exit executives **/
			FSM_STATE_EXIT_FORCED (4, "ggsnMsgRcvd", "sgsnSignallingProcedure2 [ggsnMsgRcvd exit execs]")


			/** state (ggsnMsgRcvd) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "ggsnMsgRcvd", "idle", "tr_26", "sgsnSignallingProcedure2 [ggsnMsgRcvd -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (internalHLRMsgRcvd) enter executives **/
			FSM_STATE_ENTER_FORCED (5, "internalHLRMsgRcvd", state5_enter_exec, "sgsnSignallingProcedure2 [internalHLRMsgRcvd enter execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [internalHLRMsgRcvd enter execs]", state5_enter_exec)
				{
				int imsi, result, rejectCause;
				APN *apnStructPtr;
				QoS *qosStructPtr;
				PDPAddress *pdpAddressStructPtr;
				
				QoS qosSubscribedStruct;
				PDPAddress pdpAddressStruct;
				APN apnStruct;
				Packet * attachAcceptPkPtr;
				Packet * attachRejectPkPtr;
				
				pkptr = op_pk_get(INTERNAL_HLR_RCV_IN_STRM);
				// retrieve the imsi from the GetInternalHLRInfoResponse
				op_pk_nfd_get (pkptr, "imsi", &imsi);
				op_pk_nfd_get (pkptr, "result", &result);
				
				if (result == RECORD_FOUND)
					{
					sprintf (debugStr, "Retrieve IMSI: %d, Record Found", imsi);
				    //op_prg_odb_print_major ("Debug message for SGSN", debugStr, OPC_NIL);
					
					// retrieve the APN from the MS Record
					op_pk_nfd_access(pkptr, "apn", &apnStructPtr);
					// retrieve the QoS subscribed from the MS Record
					op_pk_nfd_access(pkptr, "qos", &qosStructPtr);
					// retrieve the PDP Address from the MS Record
					op_pk_nfd_access(pkptr, "pdpAddress", &pdpAddressStructPtr);
					
					// update the mmContext information stored inside SGSN
					
					mmContext[imsi].imsi = imsi;
					mmContext[imsi].tlli = imsi;
					
					qosSubscribedStruct.reliabilityClass = qosStructPtr->reliabilityClass;
					qosSubscribedStruct.delayClass = qosStructPtr->delayClass;
					qosSubscribedStruct.precedenceClass = qosStructPtr->precedenceClass;
					qosSubscribedStruct.peakBitRate = qosStructPtr->peakBitRate;
					qosSubscribedStruct.meanBitRate = qosStructPtr->meanBitRate;
					mmContext[imsi].pdpContext.qosSubscribed = qosSubscribedStruct;
					
					memset(pdpAddressStruct.pdpAddressValue, '\0', 16);
					pdpAddressStruct.pdpType = pdpAddressStructPtr->pdpType;
					strncpy(pdpAddressStruct.pdpAddressValue, pdpAddressStructPtr->pdpAddressValue, 
						strlen(pdpAddressStructPtr->pdpAddressValue)+1);
					mmContext[imsi].pdpContext.msPDPAddress = pdpAddressStruct;
					
					memset(apnStruct.apnNetworkID, '\0', 64);
					strncpy(apnStruct.apnNetworkID, apnStructPtr->apnNetworkID, 
						strlen(apnStructPtr->apnNetworkID)+1);
					mmContext[imsi].pdpContext.apnSubscribed = apnStruct;
					
					/*
					sprintf (debugStr, "The APN of IMSI %d from Internal HLR is: %s", imsi, 
						mmContext[imsi].pdpContext.apnSubscribed.apnNetworkID);
				    op_prg_odb_print_major ("Debug message for SGSN", debugStr, OPC_NIL);
					
					sprintf (debugStr, "The Subscribed QoS of IMSI %d from Internal HLR is: %d %d %d %d %d", 
						imsi, mmContext[imsi].pdpContext.qosSubscribed.reliabilityClass, 
						mmContext[imsi].pdpContext.qosSubscribed.delayClass, 
						mmContext[imsi].pdpContext.qosSubscribed.precedenceClass,
						mmContext[imsi].pdpContext.qosSubscribed.peakBitRate, 
						mmContext[imsi].pdpContext.qosSubscribed.meanBitRate);
				    op_prg_odb_print_major ("Debug message for SGSN", debugStr, OPC_NIL);
					
					sprintf (debugStr, "The PDP Address of IMSI %d from Internal HLR is: %d %s", imsi, 
						mmContext[imsi].pdpContext.msPDPAddress.pdpType, mmContext[imsi].pdpContext.msPDPAddress.pdpAddressValue);
				    op_prg_odb_print_major ("Debug message for SGSN", debugStr, OPC_NIL);
					*/
					
					// reply MS with AttachAccept
					attachAcceptPkPtr = op_pk_create_fmt ("attachAccept");
					// set allocated ptmsi
					// which is same as the imsi of the MS
					op_pk_nfd_set(attachAcceptPkPtr, "allocatedPTMSI", 
						imsi);
						
					op_pk_send(attachAcceptPkPtr, MM_XMT_OUT_STRM_TO_MS);
						
					// increment number of attach accept sent
					attachAcceptCounter++;
					op_stat_write(numOfAttachAcceptSent, attachAcceptCounter);
					}
				else
					{
					sprintf (debugStr, "Retrieve IMSI: %d, No Record Found", imsi);
				    //op_prg_odb_print_major ("Debug message for SGSN", debugStr, OPC_NIL);	
				
					// update the mmContext information stored inside SGSN
					mmContext[imsi].mmState = -1;
					
					// reply MS with AttachAccept
					attachRejectPkPtr = op_pk_create_fmt ("attachReject");
					// set tlli
					// which is same as the imsi of the MS
					op_pk_nfd_set(attachRejectPkPtr, "TLLI", 
						imsi);
					// set the reject cause code = 2,IMSI unknown in HLR
					rejectCause = 2;
					op_pk_nfd_set(attachRejectPkPtr, "gmmCause", 
						rejectCause);
						
					op_pk_send(attachRejectPkPtr, MM_XMT_OUT_STRM_TO_MS);
						
					// increment number of attach reject sent
					attachRejectCounter++;
					op_stat_write(numOfAttachRejectSent, attachRejectCounter);
					}
				
				
				op_pk_destroy(pkptr);
				}
				FSM_PROFILE_SECTION_OUT (state5_enter_exec)

			/** state (internalHLRMsgRcvd) exit executives **/
			FSM_STATE_EXIT_FORCED (5, "internalHLRMsgRcvd", "sgsnSignallingProcedure2 [internalHLRMsgRcvd exit execs]")


			/** state (internalHLRMsgRcvd) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "internalHLRMsgRcvd", "idle", "tr_27", "sgsnSignallingProcedure2 [internalHLRMsgRcvd -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (sndcpMsgRcvd) enter executives **/
			FSM_STATE_ENTER_FORCED (6, "sndcpMsgRcvd", state6_enter_exec, "sgsnSignallingProcedure2 [sndcpMsgRcvd enter execs]")
				FSM_PROFILE_SECTION_IN ("sgsnSignallingProcedure2 [sndcpMsgRcvd enter execs]", state6_enter_exec)
				{
				Packet * encPkPtr;
				Packet * tpduPkPtr;
				int tlli, nsapi;
				TID *tidStructPtr;
				
				pkptr = op_pk_get(MS_DATA_RCV_IN_STRM);
				
				// retrieve the tlli
				op_pk_nfd_get(pkptr, "TLLI", &tlli);
				// retrieve the requested nsapi
				op_pk_nfd_get(pkptr, "nsapi", &nsapi);
				
				//retrieve the encapsulated IP data packet from sndcp
				op_pk_nfd_get (pkptr, "data", &encPkPtr);
				
				// send Create PDP Context Request to GGSN only if the MS is attached
				// and pdpContext is not active
				if ( (mmContext[tlli].mmState == 1) && 
				     (mmContext[tlli].pdpContext.isActive == 1) )
				    {
					// transmit data through GTP T-PDU
					tpduPkPtr = op_pk_create_fmt ("GTP_TPDU");
				    // allocate a new data structure for TID
					tidStructPtr = (TID *) op_prg_mem_alloc (sizeof (TID));
					// set tid value
				    tidStructPtr->imsi = mmContext[tlli].imsi;
				    tidStructPtr->nsapi = nsapi;
					// assign the data structure to TID field in the packet
				    op_pk_nfd_set(tpduPkPtr, "TID", tidStructPtr,
				        op_prg_mem_copy_create, op_prg_mem_free, sizeof (TID));
				    // set the encapsulated data
					op_pk_nfd_set (tpduPkPtr, "data", encPkPtr);
					op_pk_send(tpduPkPtr, GGSN_XMT_OUT_STRM);
					}
				else
					{
					op_pk_destroy(pkptr);
					}
				}
				FSM_PROFILE_SECTION_OUT (state6_enter_exec)

			/** state (sndcpMsgRcvd) exit executives **/
			FSM_STATE_EXIT_FORCED (6, "sndcpMsgRcvd", "sgsnSignallingProcedure2 [sndcpMsgRcvd exit execs]")


			/** state (sndcpMsgRcvd) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "sndcpMsgRcvd", "idle", "tr_43", "sgsnSignallingProcedure2 [sndcpMsgRcvd -> idle : default / ]")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,"sgsnSignallingProcedure2")
		}
	}




void
_op_sgsnSignallingProcedure2_diag (OP_SIM_CONTEXT_ARG_OPT)
	{
	/* No Diagnostic Block */
	}




void
_op_sgsnSignallingProcedure2_terminate (OP_SIM_CONTEXT_ARG_OPT)
	{

	FIN_MT (_op_sgsnSignallingProcedure2_terminate ())


	/* No Termination Block */

	Vos_Poolmem_Dealloc (op_sv_ptr);

	FOUT
	}


/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in _op_sgsnSignallingProcedure2_svar function. */
#undef debugStr
#undef numOfAttachReqRcvd
#undef numOfAttachAcceptSent
#undef numOfAttachCompleteRcvd
#undef numOfAttachRejectSent
#undef numOfDetachReqRcvd
#undef numOfDetachAcceptSent
#undef numOfActivatePDPContextReqRcvd
#undef numOfActivatePDPContextAcceptSent
#undef numOfActivatePDPContextRejectSent
#undef numOfDeactivatePDPContextReqRcvd
#undef numOfDeactivatePDPContextAcceptSent
#undef attachRequestCounter
#undef attachAcceptCounter
#undef attachCompleteCounter
#undef detachRequestCounter
#undef detachAcceptCounter
#undef activatePDPContextRequestCounter
#undef activatePDPContextAcceptCounter
#undef attachRejectCounter
#undef activatePDPContextRejectCounter
#undef deactivatePDPContextRequestCounter
#undef deactivatePDPContextAcceptCounter
#undef numOfCreatePDPContextResponseRcvd
#undef numOfCreatePDPContextRequestSent
#undef createPDPContextRequestCounter
#undef createPDPContextResponseCounter
#undef numOfDeletePDPContextRequestSent
#undef numOfDeletePDPContextResponseRcvd
#undef deletePDPContextRequestCounter
#undef deletePDPContextResponseCounter
#undef mmContext

#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE

#define FIN_PREAMBLE_DEC
#define FIN_PREAMBLE_CODE

VosT_Obtype
_op_sgsnSignallingProcedure2_init (int * init_block_ptr)
	{
	VosT_Obtype obtype = OPC_NIL;
	FIN_MT (_op_sgsnSignallingProcedure2_init (init_block_ptr))

	obtype = Vos_Define_Object_Prstate ("proc state vars (sgsnSignallingProcedure2)",
		sizeof (sgsnSignallingProcedure2_state));
	*init_block_ptr = 0;

	FRET (obtype)
	}

VosT_Address
_op_sgsnSignallingProcedure2_alloc (VosT_Obtype obtype, int init_block)
	{
#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	sgsnSignallingProcedure2_state * ptr;
	FIN_MT (_op_sgsnSignallingProcedure2_alloc (obtype))

	ptr = (sgsnSignallingProcedure2_state *)Vos_Alloc_Object (obtype);
	if (ptr != OPC_NIL)
		{
		ptr->_op_current_block = init_block;
#if defined (OPD_ALLOW_ODB)
		ptr->_op_current_state = "sgsnSignallingProcedure2 [init enter execs]";
#endif
		}
	FRET ((VosT_Address)ptr)
	}



void
_op_sgsnSignallingProcedure2_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr)
	{
	sgsnSignallingProcedure2_state		*prs_ptr;

	FIN_MT (_op_sgsnSignallingProcedure2_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (void *)OPC_NIL;
		FOUT
		}
	prs_ptr = (sgsnSignallingProcedure2_state *)gen_ptr;

	if (strcmp ("debugStr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->debugStr);
		FOUT
		}
	if (strcmp ("numOfAttachReqRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfAttachReqRcvd);
		FOUT
		}
	if (strcmp ("numOfAttachAcceptSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfAttachAcceptSent);
		FOUT
		}
	if (strcmp ("numOfAttachCompleteRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfAttachCompleteRcvd);
		FOUT
		}
	if (strcmp ("numOfAttachRejectSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfAttachRejectSent);
		FOUT
		}
	if (strcmp ("numOfDetachReqRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfDetachReqRcvd);
		FOUT
		}
	if (strcmp ("numOfDetachAcceptSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfDetachAcceptSent);
		FOUT
		}
	if (strcmp ("numOfActivatePDPContextReqRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfActivatePDPContextReqRcvd);
		FOUT
		}
	if (strcmp ("numOfActivatePDPContextAcceptSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfActivatePDPContextAcceptSent);
		FOUT
		}
	if (strcmp ("numOfActivatePDPContextRejectSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfActivatePDPContextRejectSent);
		FOUT
		}
	if (strcmp ("numOfDeactivatePDPContextReqRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfDeactivatePDPContextReqRcvd);
		FOUT
		}
	if (strcmp ("numOfDeactivatePDPContextAcceptSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfDeactivatePDPContextAcceptSent);
		FOUT
		}
	if (strcmp ("attachRequestCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->attachRequestCounter);
		FOUT
		}
	if (strcmp ("attachAcceptCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->attachAcceptCounter);
		FOUT
		}
	if (strcmp ("attachCompleteCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->attachCompleteCounter);
		FOUT
		}
	if (strcmp ("detachRequestCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->detachRequestCounter);
		FOUT
		}
	if (strcmp ("detachAcceptCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->detachAcceptCounter);
		FOUT
		}
	if (strcmp ("activatePDPContextRequestCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->activatePDPContextRequestCounter);
		FOUT
		}
	if (strcmp ("activatePDPContextAcceptCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->activatePDPContextAcceptCounter);
		FOUT
		}
	if (strcmp ("attachRejectCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->attachRejectCounter);
		FOUT
		}
	if (strcmp ("activatePDPContextRejectCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->activatePDPContextRejectCounter);
		FOUT
		}
	if (strcmp ("deactivatePDPContextRequestCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->deactivatePDPContextRequestCounter);
		FOUT
		}
	if (strcmp ("deactivatePDPContextAcceptCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->deactivatePDPContextAcceptCounter);
		FOUT
		}
	if (strcmp ("numOfCreatePDPContextResponseRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfCreatePDPContextResponseRcvd);
		FOUT
		}
	if (strcmp ("numOfCreatePDPContextRequestSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfCreatePDPContextRequestSent);
		FOUT
		}
	if (strcmp ("createPDPContextRequestCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->createPDPContextRequestCounter);
		FOUT
		}
	if (strcmp ("createPDPContextResponseCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->createPDPContextResponseCounter);
		FOUT
		}
	if (strcmp ("numOfDeletePDPContextRequestSent" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfDeletePDPContextRequestSent);
		FOUT
		}
	if (strcmp ("numOfDeletePDPContextResponseRcvd" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->numOfDeletePDPContextResponseRcvd);
		FOUT
		}
	if (strcmp ("deletePDPContextRequestCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->deletePDPContextRequestCounter);
		FOUT
		}
	if (strcmp ("deletePDPContextResponseCounter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->deletePDPContextResponseCounter);
		FOUT
		}
	if (strcmp ("mmContext" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->mmContext);
		FOUT
		}
	*var_p_ptr = (void *)OPC_NIL;

	FOUT
	}

