📄 cms_wtpsend.c
字号:
octet = (int)insert_pdu_type(INVOKE, (CMS_U8)octet);
octet = (int)insert_gtr_ttr((CMS_U8)octet);
octet = (int)insert_rid(0, (CMS_U8)octet);
wtp_pdu[0] = octet;
insert_tid(wtp_pdu, event->RcvInvoke.tid);
wtp_pdu[3] = (CMS_U8)(machine->tcl&0x03);
wtp_pdu[3] |=(CMS_U8)(event->RcvInvoke.up_flag<<4);
memcpy(wtp_pdu_for_retrans,wtp_pdu,sizeof(wtp_pdu_for_retrans));
wtp_pdu_for_retrans[0] = (int)insert_rid(1, (CMS_U8)wtp_pdu_for_retrans[0]);
octstr_insert_data(pdu_for_retrans, 0L, wtp_pdu_for_retrans, 4);
octstr_insert_data(msg->wdp_datagram.user_data, 0L, wtp_pdu, 4);
memset(machine->buff_of_retrans,0,sizeof(machine->buff_of_retrans));
machine->len_of_retrans = 0;
memcpy(machine->buff_of_retrans,msg->wdp_datagram.user_data->data,msg->wdp_datagram.user_data->len);
machine->buff_of_retrans[0] |=0x01;
machine->len_of_retrans = msg->wdp_datagram.user_data->len;
return msg;
}
/*
static Msg *pack_result(Msg *msg, WTPMachine *machine, WTPEvent *event)
{
CMS_S32 octet;
CMS_U8 wtp_pdu[4];
int tag_rid = 0;
octet = -42;
msg->wdp_datagram.user_data = octstr_duplicate(event->user_data);
octet = (CMS_S32)insert_pdu_type(RESULT, (CMS_U8)octet);
octet = (CMS_S32)insert_gtr_ttr((CMS_U8)octet);
octet = (CMS_S32)insert_rid(tag_rid, (CMS_U8)octet);
wtp_pdu[0] = octet;
insert_tid(wtp_pdu, event->TRResult.tid);
octstr_insert_data(msg->wdp_datagram.user_data, 0L, wtp_pdu, 3);
return msg;
}
*/
/*
* Packs a message object, of wdp datagram type, consisting of Abort PDU header.
* Fetches abort type and reason from direct input, tid from WTP event. Handles all
* errors by itself.
*/
static Msg *pack_abort(Msg *msg, CMS_S64 abort_type, CMS_S64 abort_reason,CMS_S32 tid)
{
CMS_S32 octet;
CMS_U8 wtp_pdu[4];
octet = -42;
msg->wdp_datagram.user_data = octstr_create_empty();
octet = (CMS_S32)insert_pdu_type(ABORT, (CMS_U8)octet);
octet = (CMS_S32)insert_abort_type((CMS_S32)abort_type, (CMS_U8)octet);
wtp_pdu[0] = octet;
insert_tid(wtp_pdu, tid);
wtp_pdu[3] = (CMS_U8)abort_reason;
octstr_insert_data(msg->wdp_datagram.user_data, 0L, wtp_pdu, 4);
return msg;
}
/*msg should be pre malloc space and msg.wdp_datagram.user->data should be pre malloc*/
static int pack_ack_2(Msg *msg, CMS_S64 ack_type, WTPMachine *machine,
WTPEvent *event,CMS_U8 con,CMS_U8 tpi_type,Octstr *tpi)/*--Shawn 2003-01-04*/
{
CMS_U8 octet=0;
CMS_U8 tpi_oct = 0; //tpi_oct is the first octet of the tpi.
CMS_U8 wtp_pdu[3];
/*
* Ack PDU is generated solely by WTP. Inputs are rid, ack type (are we doing tid
* verification or not) and tid.
*/
octet = insert_pdu_type(ACK, octet);
octet = indicate_ack_type((CMS_U8)ack_type, octet);
octet = insert_rid(0, octet);//is not re-transmit
if(con)
octet |= 0x80;
wtp_pdu[0] = octet;
insert_tid(wtp_pdu, machine->tid);
memcpy(msg->wdp_datagram.user_data->data,wtp_pdu,3);
msg->wdp_datagram.user_data->len +=3;
if(con)
{
/*if(tpi->len !=0)
tpi_oct |= 0x80;*/
/* here tpi_type is TPI Identity,e.g Packet Seqence Number 0x03. */
tpi_oct |= tpi_type <<3;
/* tpi len */
if (tpi->len <=3)
tpi_oct |= tpi->len;
memcpy(msg->wdp_datagram.user_data->data+msg->wdp_datagram.user_data->len,&tpi_oct,1);
msg->wdp_datagram.user_data->len+=1;
memcpy(msg->wdp_datagram.user_data->data+msg->wdp_datagram.user_data->len,tpi->data,tpi->len);
msg->wdp_datagram.user_data->len+=tpi->len;
}
return 1;
}
/*--Shawn 2003-01-04*/
static Msg *pack_ack(Msg *msg, CMS_S64 ack_type, WTPMachine *machine,
WTPEvent *event,CMS_U8 con,CMS_U8 tpi_type,Octstr *tpi)/*--Shawn 2003-01-04*/
{
CMS_U8 octet=0;
CMS_U8 tpi_oct = 0; //tpi_oct is the first octet of the tpi.
CMS_U8 wtp_pdu[3];
/*
* Ack PDU is generated solely by WTP. Inputs are rid, ack type (are we doing tid
* verification or not) and tid.
*/
octet = insert_pdu_type(ACK, octet);
octet = indicate_ack_type((CMS_U8)ack_type, octet);
octet = insert_rid(0, octet);//is not re-transmit
if(con)
octet |= 0x80;
wtp_pdu[0] = octet;
insert_tid(wtp_pdu, machine->tid);
msg->wdp_datagram.user_data = octstr_create_empty();
octstr_insert_data(msg->wdp_datagram.user_data, 0L, wtp_pdu, 3);
if(con)
{
/*if(tpi->len !=0)
tpi_oct |= 0x80;*/
/* here tpi_type is TPI Identity,e.g Packet Seqence Number 0x03. */
tpi_oct |= tpi_type <<3;
/* tpi len */
if (tpi->len <=3)
tpi_oct |= tpi->len;
octstr_append_data(msg->wdp_datagram.user_data,&tpi_oct,1);
octstr_append_data(msg->wdp_datagram.user_data,tpi->data,tpi->len);
}
return msg;
}
#ifdef __SELECTIVE_RETRANSMISSION__
int insert_missing_psn(unsigned char *nack,unsigned char psn,int pos)
{
if(!nack)
return 0;
nack[pos] = psn;
return 1;
}
static void pack_nack(unsigned char * buf,int *len,int tid)
{
int i = 0;
int missing_packet_num = 0;
WTP_Get_Package *currentPackage=cmsWtpSarPregress.sarPackage,*tempPackage=NULL;
if(!buf)
return;
buf[0] = insert_pdu_type(NEGATIVE_ACK,buf[0]);
insert_tid(buf, tid);
while(currentPackage)
{
/* insert the number of every missing packet */
if(currentPackage->currentIndex != i)
{
missing_packet_num++;
insert_missing_psn(buf,(unsigned char)i,3+missing_packet_num);
i++;
}
else
{
currentPackage=currentPackage->next;
i++;
}
}
/* insert number of the missing packets */
buf[3] = missing_packet_num;
*len = 3+missing_packet_num +1;
return ;
}
#endif
static CMS_U8 insert_pdu_type (CMS_S32 type, CMS_U8 octet)
{
octet = type;
octet <<= 3;
return octet;
}
static CMS_U8 insert_gtr_ttr(CMS_U8 octet)
{
/*gtr ttr is 0 1,means the last packet of the message.*/
octet |= 0x02; //2003.4.8
return octet;
}
static CMS_U8 insert_rid(CMS_S64 attribute, CMS_U8 octet)
{
octet += (CMS_U8)attribute;
return octet;
}
static CMS_VOID insert_tid(P_CMS_U8 pdu, CMS_S64 attribute)
{
CMS_S32 tid;
CMS_U8 first_tid, last_tid;
tid = (CMS_S32)attribute;
first_tid = tid>>8;
last_tid = (CMS_U8)(attribute&0xff);
pdu[1] = first_tid;
pdu[2] = last_tid;
}
static CMS_U8 insert_abort_type(CMS_S32 abort_type, CMS_U8 octet)
{
return octet + abort_type;
}
static CMS_U8 indicate_ack_type(CMS_U8 ack_type, CMS_U8 octet)
{
CMS_U8 tid_ve_octet;
tid_ve_octet = ack_type&1;
tid_ve_octet <<= 2;
octet += tid_ve_octet;
return octet;
}
#if (!defined CMS_WAP_CENT_RELEASE) && (!defined CMS_WAP_CENT_DEBUG)
static CMS_VOID wtp_segment(WTPEvent *event)
{
Octstr *user_data = NULL;
Octstr *seg_invoke_pdu = NULL;
Octstr *seg_pdu = NULL;
CMS_U8 seq_num = 0;
CMS_U8 packet_count;
CMS_U8 group_count; /*--Shawn 2002-12-25*/
CMS_U8 tag_rid = 0;
CMS_U8 i = 0;
CMS_BOOL flag = 0;
Msg *msg = NULL;
user_data = event->user_data;
//send_seg_invoke_pdu();
packet_count = ( (user_data->len % WTP_PACKET_SIZE)==0 )? user_data->len/WTP_PACKET_SIZE :user_data->len/WTP_PACKET_SIZE+1;
cms_debug("packet_count segmented to send=%d\n",packet_count);
CmsDebugFunc((unsigned char*)"8880034",(short)0,(void*)NULL);
group_count = ((packet_count % WTP_PACKET_NUM_IN_GROUP) == 0 )? packet_count/WTP_PACKET_NUM_IN_GROUP:packet_count/WTP_PACKET_NUM_IN_GROUP+1;
cms_debug("group_count to send=%d\n",group_count);
/*When there are packet_count == N,seq_num : 0..N-1*/
for(;group_count>0;group_count--)
{
//for(;packet_count>0;packet_count--,seq_num++)
for(i = 0;i<WTP_PACKET_NUM_IN_GROUP;i++,packet_count--,seq_num++)
{
if (group_count ==1 && packet_count==1) /*--Shawn 2003-01-09*/
{
insert_seg_pdu_head(user_data,packet_count,seq_num,tag_rid);
msg = msg_create(wdp_datagram);
msg->wdp_datagram.user_data = octstr_duplicate(user_data);
octstr_destroy(user_data);
put_msg_in_queue(msg);
}
else
{
seg_pdu = octstr_create_from_data(user_data->data,WTP_PACKET_SIZE);
octstr_delete(user_data,0,WTP_PACKET_SIZE);
/*build a seg pdu*/
insert_seg_pdu_head(seg_pdu,packet_count,seq_num,tag_rid);
msg = msg_create(wdp_datagram);
msg->wdp_datagram.user_data = octstr_duplicate(seg_pdu);
octstr_destroy(seg_pdu);
put_msg_in_queue(msg);
}
}
if(WTP_PACKET_NUM_IN_GROUP ==1)
{
#if (!defined CMS_WAP_CENT_RELEASE) && (!defined CMS_WAP_CENT_DEBUG)
if(group_count == 1)
{
flag = Cms_UDPInput();
if (flag == 0)/*received no data,timeout,create a abort event.*/
{
WTPEvent * wtp_event= NULL;
WSPEvent *wsp_event = NULL;
wtp_event = wtp_event_create( TRAbort );
wtp_event->TRAbort.tid = WTPGlobalMachine->tid;
wtp_event->TRAbort.abort_type = PROVIDER ;/*wsp abort not wtp abort*/
wtp_event->TRAbort.abort_reason = WTPPROTOERR ;
wtp_handle_event(WTPGlobalMachine,wtp_event);
wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, WTPGlobalMachine);
wsp_dispatch_event( WTPGlobalMachine, wsp_event);
}
}
else if(wtp_recv_ack())
{
cms_debug("At the %d times group send,recv the ack...\n",group_count);
}
else
{
//wtp_retrans();
//now,we don't retransmit the missing packet but abort this transaction.
WTPEvent * wtp_event= NULL;
WSPEvent *wsp_event = NULL;
cms_debug("At the %d times group send,recv the Nack...\n",group_count);
wtp_event = wtp_event_create( TRAbort );
wtp_event->TRAbort.tid = WTPGlobalMachine->tid;
wtp_event->TRAbort.abort_type = PROVIDER ;/*wsp abort not wtp abort*/
wtp_event->TRAbort.abort_reason = WTPPROTOERR ;
wtp_handle_event(WTPGlobalMachine,wtp_event);
wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, WTPGlobalMachine);
wsp_dispatch_event( WTPGlobalMachine, wsp_event);
}
#else
return;
#endif
}
else if(packet_count%WTP_PACKET_NUM_IN_GROUP == 1)/*the last packet of message or in a group*/
{
#if (!defined CMS_WAP_CENT_RELEASE) && (!defined CMS_WAP_CENT_DEBUG)
if(packet_count == 1)
{
flag = Cms_UDPInput();
if (flag == 0)/*received no data,timeout,create a abort event.*/
{
WTPEvent * wtp_event= NULL;
WSPEvent *wsp_event = NULL;
wtp_event = wtp_event_create( TRAbort );
wtp_event->TRAbort.tid = WTPGlobalMachine->tid;
wtp_event->TRAbort.abort_type = PROVIDER ;/*wsp abort not wtp abort*/
wtp_event->TRAbort.abort_reason = WTPPROTOERR ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -