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

📄 cms_wtp.c

📁 wap 协议栈 包括1.2 和2.0 由c开发 基于brew平台
💻 C
📖 第 1 页 / 共 5 页
字号:
				
				wtp_timer_stop( &WTPGlobalTimer[3] );
				WTPNACK = 0;
				wtp_send_ack(0,WTPGlobalMachine,NULL,1,0x03,&tpi);
			}
		}
#else
		if(machine->seg_pdu != NULL)//2003.7.29
		{
			octstr_destroy(machine->seg_pdu);
			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);
				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);
			}
		octstr_append_data(machine->seg_pdu,event->user_data->data,event->user_data->len);
#endif
	}
	
	WTPRCR = 0;
	wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);
	
#if (!defined CMS_WAP_CENT_RELEASE) && (!defined CMS_WAP_CENT_DEBUG)
	Cms_UDPInput();   
#endif
#ifdef DOPOD_TEST
	Cms_WinRecvPDU();
#endif
	return;
err:
	{
		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);
	}

}
/* the are other PDU later*/
static void rw_rr_gt0_rrw(WTPMachine *machine,WTPEvent *event)
{
	/* clear the machine->InvokeEvent and clear the machine->packet_for_retransmit */
	if(machine->InvokeEvent)
	{
		wtp_event_destroy((WTPEvent *)machine->InvokeEvent);
		machine->InvokeEvent = NULL;
	}
	
	memset(machine->buff_of_retrans,0,sizeof(machine->buff_of_retrans));
	machine->len_of_retrans = 0;

#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;*/
	}
	else if(wtp_timer_timeleft(&WTPGlobalTimer[3]) > 0 )//ifdef __SELECTIVE_RETRANSMISSION__
	{
		if(cmsIfPackageContinuous())
		{
			
			
			Octstr tpi;
			unsigned char psn = 0;
			psn = (unsigned char)cmsGetMaxPackageNum();
			
			memset(&tpi,0,sizeof(tpi));

			tpi.data = &psn;
			tpi.len = 1;

			wtp_timer_stop( &WTPGlobalTimer[3] );
			WTPNACK = 0;
			wtp_send_ack(0,WTPGlobalMachine,NULL,1,0x03,&tpi);
		}
	}
#else
	if(machine->seg_pdu != NULL)//2003.7.29
	{
		octstr_destroy(machine->seg_pdu);
		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);
				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);
			}
	octstr_append_data(machine->seg_pdu,event->user_data->data,event->user_data->len);
#endif
#ifdef DOPOD_TEST
	Cms_WinRecvPDU();
#endif
	return;
err:
	{
		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);
	}

	
}

/*the last packet*/
static void rw_rr_gt1_rrw(WTPMachine *machine,WTPEvent *event)
{
    WSPEvent *wsp_event = NULL;
	
	if(machine->InvokeEvent)
	{
		wtp_event_destroy((WTPEvent *)machine->InvokeEvent);
		machine->InvokeEvent = NULL;
	}
	
	memset(machine->buff_of_retrans,0,sizeof(machine->buff_of_retrans));
	machine->len_of_retrans = 0;

	if (machine->seg_pdu != NULL)
	{
        octstr_append_data(machine->seg_pdu,event->user_data->data,event->user_data->len);
	}
	else 
	{
        machine->seg_pdu = octstr_create_empty();
		machine->seg_pdu->data = event->user_data->data;
		machine->seg_pdu->len = event->user_data->len;
		event->user_data->data = NULL;
		event->user_data->len = 0;
	}

    WTPRCR = 0;
	HoldOn = 0;
	machine->get_first = 0;
	machine->get_last = 0;
	machine->psn = 0;
	cmsFreeSarProgress();
	wtp_timer_stop( &WTPGlobalTimer[1] );
	wtp_timer_start(&WTPGlobalTimer[0],L_A_WITHOUT_USER_ACK);

    wsp_event = pack_wsp_event( TRResultIndication, event, machine);

    wsp_dispatch_event( machine, wsp_event);
}

#ifdef __SELECTIVE_RETRANSMISSION__
static void wrw_timn_wrw(WTPMachine *machine,WTPEvent *event)
{
	if(cmsIfPackageContinuous())
		return;
	else
	{
		//send nack
		wtp_timer_start(&WTPGlobalTimer[3],NACK_TIMER_EXPIRE);
		wtp_send_nack(machine);
	}
}
#endif

static void rw_ra_1_null(WTPMachine *machine,WTPEvent *event)
{
	WSPEvent *wsp_event = NULL;
	
	//cms_debug("WTP STATUS:WTP_RESULT_WAIT-->RcvAbort-->1-->WTP_NULL%s\n","");
	

	wsp_event = pack_wsp_event(TRAbortIndication, event, machine);
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
	wsp_dispatch_event( machine, wsp_event);
	/*wtp_event_destroy(event);
	event = NULL;*/
}

static void wrw_tim_rcrltmax_wrw(WTPMachine *machine, WTPEvent *event)
{
	//cms_debug("@ @ @ @ @ @ WTP_RESULT_WAIT -- TimerTO_R -- WTP_RESULT_WAIT  @ @ @ @ @ @\n\n%s","");
	//CmsDebugFunc((unsigned char*)"8880028",(short)0,(void*)NULL);

	WTPRCR++;
    wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);   //该处重传时间没有用组重传时间3秒。以后考虑。

	//wtp_re_send_invoke( machine, machine->InvokeEvent );
	wtp_re_send_ack(machine);
#ifdef DOPOD_TEST
		Cms_WinRecvPDU();
#endif

}
static void wrw_tim_rcrltmaxtidok_wrw(WTPMachine *machine, WTPEvent *event)
{
		WTPEvent * new_event = NULL;
		int tid_ok = 0;
		//cms_debug("%s","WTP_RESULT_WAIT -- TimerTO_R --WTPRCR < MAX_RCR  && TIDOK ALREAD SENT-- WTP_RESULT_WAIT\n");
		//CmsDebugFunc((unsigned char*)"8880029",(short)0,(void*)NULL);

		WTPRCR++;
	    wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);
		
		tid_ok = 1;
		wtp_send_ack(tid_ok, machine , new_event,0,0x03,NULL);
#ifdef DOPOD_TEST
		Cms_WinRecvPDU();
#endif
}
/*----------------------------------
	wtp-state : WTP_RESULT_WAIT
	event-type : TimerTO_R
	condition : WTPRCR == MAX_RCR
	action: THIS FUNCTION
	next state : WTP_NULL
-----------------------------------*/
static void wrw_tim_rcreqmax_wrw(WTPMachine *machine, WTPEvent *event)
{
	WSPEvent *wsp_event = NULL;

	//cms_debug("%s","WTP_RESULT_WAIT -- TimerTO_R --WTPRCR == MAX_RCR-- WTP_NULL\n");
	//CmsDebugFunc((unsigned char*)"8880030",(short)0,(void*)NULL);

	WTPRCR = 0;
	HoldOn = 0;   //2003.6.27
	wtp_timer_stop( &WTPGlobalTimer[1] );
	mms_StopTimer(machine->timer_id);//修改定时器

	wsp_event = pack_wsp_event(TRAbortIndication, event, machine);
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
	wsp_dispatch_event( machine, wsp_event);
}


static void wrw_timn_wrw_max(WTPMachine *machine, WTPEvent *event)
{
	WSPEvent *wsp_event = NULL;

	//cms_debug("%s","WTP_RESULT_WAIT -- TimerTO_N --WTPNACK == MAX_NACK-- WTP_NULL\n");
	//CmsDebugFunc((unsigned char*)"88823450",(short)0,(void*)NULL);

	WTPNACK= 0;
	wtp_timer_stop( &WTPGlobalTimer[3] );
	WTPNACK = 0;
	mms_StopTimer(machine->timer_id);//修改定时器

	wsp_event = pack_wsp_event(TRAbortIndication, event, machine);
	wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
	wsp_dispatch_event( machine, wsp_event);
}



/************************************************************************* 
 * 描  述:  用户wtp断开 
 * 返回值:  void
 * 全局量:  
 * 日  期:  2004-12-10
 * 作  者:  滕永; yongt@mobilesoft.com.cn
 ************************************************************************/
void CmsWtpUserAbort( void )
{
	WTPEvent *event = NULL;

	if(NULL != WTPGlobalMachine)
	{
		event = wtp_event_create(TRAbort);
		event->TRAbort.abort_type = USER;
		event->TRAbort.abort_reason = USERREQ;
		

		event->TRAbort.tid = WTPGlobalMachine->tid;
		wtp_handle_event(WTPGlobalMachine,event);
	}
	return;
}

/************************************************************************* 
 * 描  述:  启动wtp定时器 
 * 返回值:  void
 * 全局量:  
 * 日  期:  2004-12-10
 * 作  者:  滕永; yongt@mobilesoft.com.cn
 ************************************************************************/
void CmsWtpSetTimer( void )
{
	if(WTPGlobalMachine)
	{
		////cms_trace("access CmsWtpSetTimer: start timer!\n" );
		mms_StartTimer(WTPGlobalMachine->timer_id,1000);
	}

	return;
}


/************************************************************************* 
 * 描  述:  设置msg size 
 * 返回值:  
 * 全局量:  
 * 日  期:  2004-12-10
 * 作  者:  滕永; yongt@mobilesoft.com.cn
 ************************************************************************/
void CmsWtpSetMsgSize( unsigned int size )
{
	if(WTPGlobalMachine)
		WTPGlobalMachine->recv_msgsize = size ;
	
	return;
}

/************************************************************************* 
 * 描  述:  判断wtp状态机是否为null状态
 * 返回值:  int 
 * 全局量:  
 * 日  期:  2005-10-25
 * 作  者:  陈飞feich@mobilesoft.com.cn
 ************************************************************************/
int CmsIsWtpNullState( void )
{
	if ( (NULL != WTPGlobalMachine) && (WTP_NULL == WTPGlobalMachine->state) )
	{
		return 1;
	}
	return 0;
}



⌨️ 快捷键说明

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