⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cms_wtp.c

📁 wap 协议栈 包括1.2 和2.0 由c开发 基于brew平台
💻 C
📖 第 1 页 / 共 5 页
字号:
		new_event->RcvInvoke.packet_count = ( ((new_event->user_data->len+new_event->big_data->len) % WTP_PACKET_SIZE)==0 )? (new_event->user_data->len+new_event->big_data->len)/WTP_PACKET_SIZE :(new_event->user_data->len+new_event->big_data->len)/WTP_PACKET_SIZE+1;
		////cms_debug("new_event->RcvInvoke.packet_count=%d\n",new_event->RcvInvoke.packet_count);
		////CmsDebugFunc((unsigned char*)"8880013",(short)0,(void*)NULL);
			
		if(machine->InvokeEvent)
		{
			wtp_event_destroy(machine->InvokeEvent);
			machine->InvokeEvent = NULL;
		}
		

		machine->InvokeEvent = new_event;
		new_event = NULL;
		//wtp_segment(event->user_data);             //segment
		//wtp_segment(machine->InvokeEvent->user_data);
		mms_StartTimer(WTPGlobalMachine->timer_id,1000);//修改定时器
		wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);

		wtp_seg_send_invoke( machine, machine->InvokeEvent );

		WTPRCR = 0;
#ifdef DOPOD_TEST
		Cms_WinRecvPDU();
#endif
}

static void wssaw_abort_1_null(WTPMachine *machine,WTPEvent *event)
{
	CMS_S32 type;
	CMS_S32 reason;
	CMS_S32 tid;
	WSPEvent *wsp_event = NULL;
	WTPEvent *wtp_event = NULL;
	
	//cms_debug("WTP STATUS:WTP_SEG_SEND_ACK_WAIT-->TRAbort-->1-->WTP_NULL%s\n","");
	////CmsDebugFunc((unsigned char*)"8880014",(short)0,(void*)NULL);

	/************** add by teng yong**************************/
	//////cms_trace("access abort free machine->seg_pdu wssaw_abort_1_null****************************************\n" );
	octstr_destroy( machine->seg_pdu );
	machine->seg_pdu = NULL;
	//////cms_trace("access abort free machine->seg_pdu wssaw_abort_1_null****************************************\n" );

	type = event->TRAbort.abort_type;
	reason = event->TRAbort.abort_reason;
	tid = event->TRAbort.tid;
	wtp_send_abort(type,reason,tid);



	wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, machine);//2003.6.26
	if(wsp_event)
	{
		if(event->TRAbort.abort_reason == USERREQ)
		{
			wsp_event->TRAbortIndication.abort_code = WSP_ABORT_USERREQ;
		}
		else
		{
			wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
		}
	}
	
	wsp_dispatch_event( machine, wsp_event);
}
static void wssaw_rcverrpdu_1_null(WTPMachine *machine,WTPEvent *event)
{
	CMS_S32 type;
	CMS_S32 reason;
	CMS_S32 tid;

	WTPEvent *wtp_event = NULL;
	WSPEvent *wsp_event = NULL;

	//cms_debug("WTP STATUS:WTP_SEG_SEND_ACK_WAIT-->rcverrpdu-->tcl == 2-->WTP_NULL%s\n","");
	
	type = event->TRAbort.abort_type;
	reason = event->TRAbort.abort_reason;
	tid = event->TRAbort.tid;
	wtp_send_abort(type,reason,tid);


	wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, machine);//2003.6.26
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;       //2003.9.1
	wsp_dispatch_event( machine, wsp_event);
}
static void wssaw_rcvabort_1_null(WTPMachine *machine,WTPEvent *event)
{
	WSPEvent *wsp_event = NULL;

	//cms_debug("WTP STATUS:WTP_SETRESULT_WAIT-->RcvAbort-->1-->WTP_NULL%s\n","");
	

	wsp_event = pack_wsp_event(TRAbortIndication, event, machine);
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;       //2003.9.1
	wsp_dispatch_event( machine, wsp_event);
}
/*2003.8.19*/
static void wssaw_ra_21_wssaw(WTPMachine *machine,WTPEvent *event)
{
	WTPRCR = 0;
	wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);//
	wtp_seg_send_invoke( machine, event );

}
static void wssaw_tim_rcrltmax_wssaw(WTPMachine *machine,WTPEvent *event)
{
	WTPRCR++;
	//cms_debug("@-@-@-@-@-@ WTP_SEG_SEND_ACK_WAIT-->TimerTO_R-->WTP_SEG_SEND_ACK_WAIT @-@-@-@-@-@\n","");

	wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);
	wtp_re_send_invoke( machine, machine->InvokeEvent );

	
}
static void wssaw_tim_rcreqmax_null(WTPMachine *machine,WTPEvent *event)
{

	WTPEvent *wtp_event = NULL;
	WSPEvent *wsp_event = NULL;

	//cms_debug("WTP STATUS:WTP_SEG_SEND_ACK_WAIT-->TimerTO_R-->WTPRCR == MAX_RCR-->WTP_NULL%s\n","");
	////cms_trace("access WTPRCR: = %d\n", WTPRCR );
	////cms_trace("access MAX_RCR: = %d\n", MAX_RCR );

	WTPRCR = 0;    //RESET WTPRCR
	wtp_timer_stop(&WTPGlobalTimer[1]);

	/*wtp_event = wtp_event_create( TRAbort );
	wtp_event->TRAbort.tid = machine->tid;
	wtp_event->TRAbort.abort_type = PROVIDER ;
	wtp_event->TRAbort.abort_reason = WTPPROTOERR ;
	wtp_handle_event(WTPGlobalMachine,event);*/

	wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, machine);//2003.6.26
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;       //2003.9.1
	wsp_dispatch_event( machine, wsp_event);
}
static void wssaw_ra_lastpacket_wssaw(WTPMachine *machine,WTPEvent *event)
{
	WTPRCR = 0;
	wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);//2003.8.19
	wtp_seg_send_invoke( machine, event );
#ifdef DOPOD_TEST
		Cms_WinRecvPDU();
#endif
}

static void rw_tra_2_null(WTPMachine *machine,WTPEvent *event)
{
	CMS_S32 type;
	CMS_S32 reason;
	CMS_S32 tid;

	WTPEvent *wtp_event = NULL;
	WSPEvent *wsp_event = NULL;

	//cms_debug("WTP STATUS:WTP_RESULT_WAIT-->TRAbort-->tcl == 2-->WTP_NULL%s\n","");
	//CmsDebugFunc((unsigned char*)"8880019",(short)0,(void*)NULL);

	/************** add by teng yong**************************/
	////cms_trace("access abort free machine->seg_pdu rw_tra_2_null rw_tra_2_null****************************************\n" );
	octstr_destroy( machine->seg_pdu );
	machine->seg_pdu = NULL;
	////cms_trace("access abort free machine->seg_pdu rw_tra_2_null rw_tra_2_null****************************************\n" );



	type = event->TRAbort.abort_type;
	reason = event->TRAbort.abort_reason;
	tid = event->TRAbort.tid;
	wtp_send_abort(type,reason,tid);

	wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, machine);//2003.6.26
	if(wsp_event)  //2003.9.1
	{
		if(event->TRAbort.abort_reason == USERREQ)
		{
			wsp_event->TRAbortIndication.abort_code = WSP_ABORT_USERREQ;
		}
		else
		{
			wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
		}
	}
	wsp_dispatch_event( machine, wsp_event);
}
static void rw_rcverrpdu_2_null(WTPMachine *machine,WTPEvent *event)
{
	WTPEvent * wtp_event= NULL;
	WSPEvent *wsp_event = NULL;
	wtp_event = wtp_event_create( TRAbort );
	wtp_event->TRAbort.tid = machine->tid;
	wtp_event->TRAbort.abort_type = PROVIDER ;
	wtp_event->TRAbort.abort_reason = WTPPROTOERR ;
	wtp_handle_event(WTPGlobalMachine,wtp_event);
	
	wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, machine);
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
	wsp_dispatch_event( machine, wsp_event);
}

/* ??? */
static void rw_ra_2_rw(WTPMachine *machine,WTPEvent *event)
{
    WTPRCR = 0;
	wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);
	HoldOn = 1;
}
static void rw_ra_tve_rw(WTPMachine *machine,WTPEvent *event)
{
	WTPEvent * new_event = NULL;
	int tid_ok = 1;

	WTPRCR++;
	wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);
	wtp_send_ack((CMS_S64)tid_ok, machine, new_event,0,0,NULL);
	machine->ack_sended = 1;
}
static void rrw_trrr_1_null(WTPMachine *machine,WTPEvent *event)
{
	WTPEvent * new_event = NULL;
	int tid_ok = 0;
	
	////cms_trace("WTP STATUS:WTP_RESULT_RESP_WAIT-->TRResultResponse-->1-->WTP_NULL: in\n");
	////cms_trace("WTP STATUS:WTP_RESULT_RESP_WAIT-->TRResultResponse-->1-->WTP_NULL: in\n");
	////cms_trace("WTP STATUS:WTP_RESULT_RESP_WAIT-->TRResultResponse-->1-->WTP_NULL: in\n");
	
	WTPAEC = 0;
	wtp_timer_stop(&WTPGlobalTimer[0]);
	mms_StopTimer(machine->timer_id);//修改定时器
	wtp_send_ack( tid_ok, machine , new_event,0,0,NULL);

	////cms_trace("WTP STATUS:WTP_RESULT_RESP_WAIT-->TRResultResponse-->1-->WTP_NULL: out\n");
}
/*----------------------------------
	wtp-state : WTP_WAIT_TIMEOUT,
	event-type : RcvResult
	condition : 1
	action: THIS FUNCTION
	next state : WTP_NULL
-----------------------------------*/
static void wrrw_ra_1_null(WTPMachine *machine, WTPEvent *event)
{
	WSPEvent *wsp_event = NULL;

	//cms_debug("%s","WTP_RESULT_RES_WAIT -- RcvAck --1-- WTP_NULL\n");
	//CmsDebugFunc((unsigned char*)"8880022",(short)0,(void*)NULL);
	WTPAEC = 0;
	wtp_timer_stop( &WTPGlobalTimer[0] );
	wsp_event = pack_wsp_event(TRAbortIndication, event, machine);
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
	wsp_dispatch_event( machine, wsp_event);
}
/*----------------------------------
	wtp-state : WTP_RESULT_RES_WAIT
	event-type : TRAbort
	condition : 1
	action: THIS FUNCTION
	next state : WTP_NULL
-----------------------------------*/
static void wrrw_tra_1_null(WTPMachine *machine, WTPEvent *event)
{
	/************** add by teng yong**************************/
	////cms_trace("access abort free machine->seg_pdu wrrw_tra_1_null ****************************************\n" );
	octstr_destroy( machine->seg_pdu );
	machine->seg_pdu = NULL;
	////cms_trace("access abort free machine->seg_pdu wrrw_tra_1_null****************************************\n" );

	WTPAEC = 0;
	wtp_timer_stop( &WTPGlobalTimer[0] );
	wtp_send_abort(event->TRAbort.abort_type, event->TRAbort.abort_reason,event->TRAbort.tid);
}
static void wrrw_timeout_aeceqmax_null(WTPMachine *machine, WTPEvent *event)
{
	CMS_S32 type;
	CMS_S32 reason;
	CMS_S32 tid;
	
	//cms_debug("WTP STATUS:WTP_RESULT_RESP_WAIT-->TimerTO_R-->WTPRCR == MAX_RCR-->WTP_NULL%s\n","");
	//CmsDebugFunc((unsigned char*)"8880023",(short)0,(void*)NULL);
	WTPAEC = 0;    
	wtp_timer_stop(&WTPGlobalTimer[0]);
	
	type = PROVIDER ;/*wtp abort*/
	reason= NORESPONSE;
	tid = machine->tid;
	wtp_send_abort(type, reason,tid );
	
}
static void wt_rr_1_wt(WTPMachine *machine,WTPEvent *event)
{
	WTPEvent * new_event = NULL;
	int tid_ok = 0;
	
	wtp_send_ack((CMS_S64)tid_ok, machine, new_event,0,0,NULL);
	
	/*wtp_event_destroy(event);
	event = NULL;*/
}
static void wwt_tim_1_null(WTPMachine *machine,WTPEvent *event)
{
	//cms_debug("%s","WTP_WAIT_TIMEOUT -- TimerTO_W -- WTP_NULL\n");
	//CmsDebugFunc((unsigned char*)"8880024",(short)0,(void*)NULL);
}

/*the last packet in a group*/
static void rw_rr_gt2_rrw(WTPMachine *machine,WTPEvent *event)
{
	Octstr * tpi = octstr_create_from_data("a",1);
	
	//clear the machine->InvokeEvent and clear the machine->packet_for_retransmit
	if(machine->InvokeEvent)
	{
		wtp_event_destroy((WTPEvent *)machine->InvokeEvent);
		machine->InvokeEvent = NULL;
	}
	//if(machine->packet_for_retransmit)
	//{
	//	octstr_destroy(machine->packet_for_retransmit);
	//	machine->packet_for_retransmit = NULL;
	//}
	
	//2003.9.9
	memset(machine->buff_of_retrans,0,sizeof(machine->buff_of_retrans));
	machine->len_of_retrans = 0;
	
	
	//send ack
	memset(tpi->data,0,1);
	//cms_debug("Congratulations! Received segmented result pdu%s\n","!");
	//CmsDebugFunc((unsigned char*)"8880025",(short)0,(void*)NULL);
	wtp_send_ack(0,machine,event,1,0x03,tpi);		
	octstr_destroy(tpi);
	
	//get data & continue to receive  --Shawn 2002-12-25
	if(event->user_data != NULL)
	{
	/*if(machine->seg_pdu == NULL)
				machine->seg_pdu = octstr_create_empty();
		octstr_append_data(machine->seg_pdu,event->user_data->data,event->user_data->len);*/
#ifdef __CMS_TOOLKIT__
		cmsInsertPackage(0,(unsigned short)event->user_data->len);
		if(machine->seg_pdu==NULL)
		{
			machine->seg_pdu=octstr_create_empty();
			
			if(machine->recv_msgsize >0)
			{
				machine->seg_pdu->data = (unsigned char *)malloc(machine->recv_msgsize+2000);
				if(!machine->seg_pdu->data)
				{
					//CmsDebugFunc((unsigned char*)"!!!!_____xxx",(short)4,(void*)&(machine->recv_msgsize));
					goto err;
				}
				machine->seg_pdu->size = machine->recv_msgsize+2000;
				memset(machine->seg_pdu->data,0,machine->seg_pdu->size);
			}
			else
			{
				machine->seg_pdu->data = (unsigned char *)malloc(DEFAULT_WTP_SIZE);
				machine->seg_pdu->size = DEFAULT_WTP_SIZE;
				memset(machine->seg_pdu->data,0,machine->seg_pdu->size);
			}
		}

		if(event->user_data)
		{
			int ret = 0;
			ret = octstr_insert_data(machine->seg_pdu,0, event->user_data->data,event->user_data->len);
			if(ret <0)
			{
				octstr_destroy(machine->seg_pdu);
				machine->seg_pdu = NULL;
				goto err;
			}
				
		}
		
		cmsWtpSarPregress.curQuantity++;

		if(cmsIfGetAll() && WTPGlobalMachine->get_first==1 && WTPGlobalMachine->get_last==1)
		{
			WTPEvent* new_event = NULL;
			if(cmsIfPackageContinuous())
			{
				
				Octstr stpi;
				unsigned char psn = 0;
				wtp_timer_stop( &WTPGlobalTimer[3] );
				WTPNACK = 0;
				memset(&stpi,0,sizeof(stpi));
				psn = (unsigned char)cmsGetMaxPackageNum();
				stpi.data = &psn;
				stpi.len = 1;
				wtp_send_ack(0,WTPGlobalMachine,new_event,1,0x03,&stpi);
			}
			
			new_event = wtp_event_create(RcvResult);
			new_event->RcvResult.tid = machine->tid;
			new_event->RcvResult.gtr_ttr = 0x01;
			new_event->user_data = machine->seg_pdu;
			machine->seg_pdu = NULL;
			wtp_handle_event(WTPGlobalMachine,new_event);	
			/*WSPEvent *wsp_event = NULL;
			
			  WTPRCR = 0;
			  HoldOn = 0;
			  wtp_timer_stop( &WTPGlobalTimer[1] );
			  wtp_timer_start(&WTPGlobalTimer[0],L_A_WITHOUT_USER_ACK);//2003.8.19
			  
				wsp_event = pack_wsp_event( TRResultIndication, event, machine);
				wsp_dispatch_event( machine, wsp_event);
			return;*/
		}
		//#ifdef __SELECTIVE_RETRANSMISSION__
		else if(wtp_timer_timeleft(&WTPGlobalTimer[3]) > 0 )
		{
			if(cmsIfPackageContinuous())
			{
				
				
				Octstr tpi;
				unsigned char psn = 0;
				psn = (unsigned char)cmsGetMaxPackageNum();
				
				memset(&tpi,0,sizeof(tpi));
				
				tpi.data = &psn;
				tpi.len = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -