📄 lap_s.c
字号:
case 0x10 : new_size=1024;break;
case 0x20 : new_size=2048;break;
}
}
if (bit_mask)
{
bit_mask=1<<(i1+1);
switch(new_size)
{
case 64 : bit_mask=0x1;break;
case 128 : bit_mask=0x3;break;
case 256 : bit_mask=0x7;break;
case 512 : bit_mask=0xf;break;
case 1024 : bit_mask=0x1f;break;
case 2048 : bit_mask=0x3f;break;
}
}
/* set defaults */
else
{
bit_mask=1;
new_size=64;
}
result_params[8+offset]=bit_mask;
}
else
{
bit_mask=1;
new_size=64;
result_params[8+offset]=bit_mask;
}
/* process window size*/
/* our window size is current fixed at one */
/* process additional bofs */
if ( (tmpptr[12+offset]==0x85)&&
(tmpptr[13+offset]==1) )
{
bit_mask=tmpptr[14+offset];
for (i1=7;i1>-1&&!new_xbofs;)
{
switch(bit_mask&(1<<i1--))
{
case 1 : new_xbofs=48;break;
case 2 : new_xbofs=24;break;
case 4 : new_xbofs=12;break;
case 8 : new_xbofs=5;break;
case 0x10 : new_xbofs=3;break;
case 0x20 : new_xbofs=2;break;
case 0x40 : new_xbofs=1;break;
case 0x80 : new_xbofs=0;goto exit;
}
}
exit:
bit_mask=1<<(i1+1);
}
/* recalculate actual xbofs based on our new_baud */
switch (new_baud)
{
case 9600l: new_xbofs/=12; break;
case 19200l:new_xbofs/=6; break;
case 38400l:new_xbofs/=3; break;
case 57600l:new_xbofs/=2; break;
case 115200l:new_xbofs/=1; break;
}
/* process minimum turnaround time */
/* values based on 115Kbaud additions to xbof */
if ( (tmpptr[15+offset]==0x86)&&
(tmpptr[16+offset]==1) )
{
bit_mask=tmpptr[17+offset];
for (i1=7;i1>-1&&!new_minttt;)
{
switch(bit_mask&(1<<i1--))
{
case 1 : new_minttt=128;break;/* 10ms*/
case 2 : new_minttt=64;break;/*5ms */
case 4 : new_minttt=13;break;/*1ms */
case 8 : new_minttt=6;break;/*.5ms */
case 0x10 : new_minttt=1;break;/*.1ms */
case 0x20 : new_minttt=0;goto exit1;/*.05ms*/
case 0x40 : new_minttt=0;goto exit1;/*.01ms*/
case 0x80 : new_minttt=0;goto exit1;/* 0ms */
}
}
exit1:
bit_mask=1<<(i1+1);
}
else
{
new_minttt=128;
}
/* recalculate actual minttt based on our new_baud */
switch (new_baud)
{
case 9600l: new_minttt/=12; break;
case 19200l: new_minttt/=6; break;
case 38400l: new_minttt/=3; break;
case 57600l: new_minttt/=2; break;
case 115200l:new_minttt/=1; break;
}
/* process link disconnect/threshold time */
if ( (tmpptr[18+offset]==0x08)&&
(tmpptr[19+offset]==1) )
{
bit_mask=connect_params[21]&tmpptr[20+offset];
/* commented out because secondary does not use N1 or N2 */
for (i1=7;i1>-1&&!new_ld;)
{
switch(bit_mask&(1<<i1--))
{
case 1 : new_ld=3;break;
case 2 : new_ld=8;break;
case 4 : new_ld=12;break;
case 8 : new_ld=16;break;
case 0x10 : new_ld=20;break;
case 0x20 : new_ld=25;break;
case 0x40 : new_ld=30;break;
case 0x80 : new_ld=40;break;
}
}
bit_mask=1<<(i1+1);
result_params[20+offset]=bit_mask;
}
else
{
new_ld=8;
result_params[20+offset]=2;
}
/* send u:ua:rsp:F:Connection-Parameters */
ua_response_sent=0; /* used as a sync flag */
tx_lap_frame = result_params; /* pass global address to Format_packet */
/*Max turn around time and additional bof*/
bofs=new_minttt+new_xbofs;
/* Set Baudrate flag before Com_wirte*/
Com_ioctl( IOCTL_BAUD, new_baud );
IRDA_SetBof(bofs);
/* send two UA responses */
Com_write(Format_packet (0,UA_RESPONSE));
/* must wait for response to be sent before changing
the device com parameters*/
/* apply connection parameters */
/*Window size=1*/
/*Data size*/
if (new_size==0)
max_frame_size=IRLAP_FRAME_SIZE;
else if ( new_size <= IRLAP_FRAME_SIZE )
max_frame_size=new_size+4;
else
max_frame_size=IRLAP_FRAME_SIZE;
Init_connection_state(IRLAP_NRMS);
/* ??? where to init these ? */
Nr = 127;
Ns = 127;
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_INFO, IRDA_MSG26, new_baud);
kal_trace(TRACE_INFO, IRDA_MSG27, new_size);
kal_trace(TRACE_INFO, IRDA_MSG28, new_ttt);
kal_trace(TRACE_INFO, IRDA_MSG29, bofs);
kal_trace(TRACE_INFO, IRDA_MSG30, new_minttt);
kal_trace(TRACE_INFO, IRDA_MSG31, new_ld);
kal_trace(TRACE_INFO, IRDA_MSG32, N1);
kal_trace(TRACE_INFO, IRDA_MSG33, N2);
#endif
/* start wd timer for quick disconnect */
START_WD_TIMER();
}
/*************************************************************************
* FUNCTION
* Send_NRM_Response
*
* DESCRIPTION
* Send a NRM response
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
extern kal_uint8 local_lsap_sel;
//extern void obex_flc_release_callback(void);//attar
void Send_NRM_Response( void )
{
FBUF * tmpptr;
peer_buff_struct* tmp_peer_buf_ptr;
if(lap_disconnect_flag==1)/*send RD to Primary*/
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG45);
#endif
IrLAP_DISCONNECT_request_s();
lap_disconnect_flag=0;
return;
}
kal_prompt_trace(MOD_LAP,"Nr %d AS %d VS %d",Nr, As, Vs);
if((Nr==Vs)&&(unacked_frame!=0))/*free unacked frame*/
{
if((ctrl_buff_cnt)&&(unacked_frame->type==CONTROL_BUF_TYPE)
&&(FRAME_IN_QUEUE(ctrl_buff_q)))
{
QUEUE_PEAK(ctrl_buff_q, tmp_peer_buf_ptr);
kal_prompt_trace(MOD_TTP,"ctrl buf %d unack %d",tmp_peer_buf_ptr->pdu_len, (unacked_frame->size-5));
if(tmp_peer_buf_ptr->pdu_len>=(tmp_peer_buf_ptr->pdu_len-(unacked_frame->size-5)))
tmp_peer_buf_ptr->pdu_len=tmp_peer_buf_ptr->pdu_len-(unacked_frame->size-5);/*2LAP+2LMP+1TTP*/
else
tmp_peer_buf_ptr->pdu_len=0;
if(tmp_peer_buf_ptr->pdu_len==0)
{
QUEUE_REMOVE(ctrl_buff_q,tmp_peer_buf_ptr,MAX_TTP_FRAMES);
//Robin 0920
if( KAL_TRUE == gprs_flc_is_flc_context_activated(IRDA_DATA, GPRS_INVALID_SAPI, GPRS_FLC_UL, 0 ) )
{
gprs_flc_free_peer_buff (
IRDA_DATA,
0,
GPRS_FLC_UL,
0,
tmp_peer_buf_ptr);
}
ctrl_buff_cnt--;
dbg_ctrl_buff_count--;
}
/*Robin 20040906: Call back obex */
if(local_lsap_sel==OBEX_LSAP_SEL||local_lsap_sel==OBEX_IRXFER_LSAP_SEL)
{
/*Attar 20060227: remove it because of race condition */
// obex_flc_release_callback();
}
{
gprs_flc_pool_presence_enum is_pool_created;
kal_uint16 u_available_half_blocks; kal_uint16 u_available_full_blocks;
kal_uint16 d_available_half_blocks; kal_uint16 d_available_full_blocks;
gprs_flc_query_fix_size_pool_occupy( IRDA_DATA, GPRS_INVALID_SAPI, GPRS_FLC_UL, 0, \
&is_pool_created, &u_available_half_blocks, &u_available_full_blocks );
gprs_flc_query_fix_size_pool_occupy( IRDA_DATA, GPRS_INVALID_SAPI, GPRS_FLC_DL, 0, \
&is_pool_created, &d_available_half_blocks, &d_available_full_blocks );
kal_prompt_trace(MOD_TTP, "[LAP] [UL: (%d) (%d)][DL: (%d) (%d)]", u_available_half_blocks, u_available_full_blocks, d_available_half_blocks, d_available_full_blocks );
kal_prompt_trace(MOD_LAP, "[LAP] [UL: (%d) (%d)][DL: (%d) (%d)]", u_available_half_blocks, u_available_full_blocks, d_available_half_blocks, d_available_full_blocks );
}
}
Freebuf((FBUF*)unacked_frame);
unacked_frame=0;
}
if (!remote_busy&&!((local_busy&1)^(local_busy>>1)))
{/*remote and local are not busy*/
if((Nr==As)&&(unacked_frame!=0))/*send unacked frame*/
{
/* adjust Vs before retransmit */
if (Vs==0)
Vs=7;
else
Vs--;
unacked_frame->size-=2; /*2 for A and C field */
Com_write( Format_I_Packet ( 0, 0x10, unacked_frame, unacked_frame->size));
As=Vs;
Vs=(Vs+1)%8;
}
else if(FRAME_IN_QUEUE(lap_request_q)&&(Nr==Vs))
{ /*send normal I frame*/
QUEUE_REMOVE(lap_request_q,tmpptr,MAX_REQUEST);
Com_write(Format_I_Packet ( 0, 0x10, tmpptr, tmpptr->size));
unacked_frame=tmpptr;
As=Vs;
Vs=(Vs+1)%8;
}
else
{
SEND_S_RESPONSE();
}
}
else/*remote or local us busy*/
{
if (local_busy&1)
local_busy=3;
else
local_busy=0;
SEND_S_RESPONSE();
}
}
/*************************************************************************
* FUNCTION
* WD_timer_expired
*
* DESCRIPTION
* Process the WD timeout
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void WD_timer_expired (void )
{
LAP_disconnect_reset(LOST_LAP_CON);
irda_lmp_flag=MSG_ID_LAP_DISCONNECT_INDICATION;
Reset_Baudrate();
}
/*************************************************************************
* FUNCTION
* Check_WD_Timer
*
* DESCRIPTION
* Check the wd timer
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Check_WD_Timer ( void )
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG46);
#endif
switch (irlap_state)
{
case IRLAP_NRMS:
WD_timer_expired();
case IRLAP_SCLOSE:
WD_timer_expired();
case IRLAP_NDM:
//WD_timer_expired
//STOP_WD_TIMER();
break;
default:
WD_timer_expired();
break;
}
}
/*************************************************************************
* FUNCTION
* Do_XID_response
*
* DESCRIPTION
* Process XID Command in IrFramer
*
* PARAMETERS
* FBUF *rframe: Received XID Command
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/* if flag>1 then XID command was processed*/
kal_uint8 Do_XID_response ( FBUF * rframe )
{
kal_uint8 total_slots;
kal_uint8 * frame;
kal_uint8 flag=0;
frame=(kal_uint8 *)rframe+FBUF_HEAD;
if(irlap_state==IRLAP_NDM)
{
if (frame[1]==XID_COMMAND)
{
if (frame[12]==0xff)/*the last XID Command*/
{
old_slot = 127;
/*copy XID information to discovery log*/
xmemcpy ((kal_uint8*)&discovery_log[0].addr,(kal_uint8*)&frame[3],4);
xmemcpy ((kal_uint8*)&discovery_log[0].info,(kal_uint8*)&frame[14],23);
irda_lmp_flag=MSG_ID_LAP_DISCOVERY_INDICATION;
goto exit;
}
switch (0x03&frame[DISCOVERY_FLAGS_OFFSET])
{
case 0: total_slots=1;
break;
case 1: total_slots=6;
break;
case 2: total_slots=8;
break;
case 3: total_slots=16;
break;
}
if (frame[12] <= old_slot)
{ /*replt a.s.a.p*/
slot = 0;//(kal_uint8)((random32()&0x000000ff)%5+1);
frame_sent=FALSE;
}
#ifdef STORE_DEVICE_INFO /*we dont store the remote device information*/
/* store the device info, if there is any */
/* subtract crc, add one */
if ((frame[12] == 0xff ) && (rframe->size-2 > 14+1))
xmemcpy(rx_device_info, &frame[14],frame->size-15);
#endif
old_slot = frame[12];
if ( (frame[12] >= slot )&&
(frame[12] != 0xff )&&
(frame_sent==FALSE) )
{
/* primary says:generate new address */
if (frame[DISCOVERY_FLAGS_OFFSET]&0x04)
{
dev_address= random32();
}
Com_write(Format_XID_RES_packet ((FBUF*)rframe));
frame_sent=TRUE;
flag=1;
}
}
}
/* free XID frames that are not responded to */
exit:
if (flag==0)
{
Freebuf((FBUF*)rframe);
}
return(flag);
}
/*************************************************************************
* FUNCTION
* Format_XID_RES_packet
*
* DESCRIPTION
* Do a LAP discovery request
*
* PARAMETERS
* An allocated buffer
* RETURNS
* pointer to formatted buffer
*
* GLOBALS AFFECTED
*
*************************************************************************/
FBUF *Format_XID_RES_packet ( FBUF *tmpptr )
{
extern kal_uint8 *irda_get_device_info(void);
extern kal_uint16 irda_get_device_info_size(void);
kal_uint8 *frame;
kal_int16 fsize=0;
kal_uint32 tmplong;
frame=(kal_uint8 *)tmpptr+FBUF_HEAD;
/* dest 32bit address */
xmemcpy ((kal_uint8 *)&frame[7],(kal_uint8 *)&frame[3],4);
/* broadcast address = 0xfe */
frame[0]=0xfe;
frame[1]=XID_RESPONSE;
/* format id */
frame[2]=0x01;
/* src 32bit address */
tmplong= Swap_long_order(dev_address);
xmemcpy ((kal_uint8 *)&frame[3],(kal_uint8 *)&tmplong,4);
/* our generated slot */
frame[12]=slot;
frame[13]=IRLAP_VERSION;
#if 1
xmemcpy (&frame[14],(kal_uint8*)irda_get_device_info(),irda_get_device_info_size() );
fsize = 14+irda_get_device_info_size();
#else
/* under construction !*/
/* under construction !*/
#endif
tmpptr->size=fsize;
return((FBUF*)tmpptr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -