📄 lap_p.c
字号:
*************************************************************************/
void Do_u_frame_p ( kal_uint8 * frame )
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG21);
#endif
//STOP_F_TIMER();
switch(irlap_state)
{
case IRLAP_NDM:
switch (frame[1])
{
case SNRM_COMMAND:
if((frame[0]&0x01)==1)/*commmand or not*/
Process_peer_SNRM_com (frame);
break;
#ifdef ULTRA_FLAG
case UI_COMMAND:
Ultra_SAR_RX ( frame );
break;
#endif
default:
break;
}
break;
case IRLAP_SETUP:
switch (frame[1])
{
#if 0 /*not chage hie role in this state*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
case UA_RESPONSE:
Init_connection_state(IRLAP_NRMP);
Apply_connection_params(frame);
SET_CONNECT_CONFIRM();
Com_write(Format_packet (1,RR_COMMAND));
retrycount=0;
/* set f timer back to default once we are connected */
f_mstimeout = F_MSTIMEOUT_DEFAULT;
irda_lmp_flag=MSG_ID_LAP_CONNECT_CONFIRM;
START_F_TIMER();
gprs_flc_activate_context(IRDA_DATA, 0, GPRS_FLC_DL, 0);
break;
default:
break;
}
break;
case IRLAP_QUERY:
switch (frame[1])
{
case XID_RESPONSE:
Log_response_info(frame);
break;
default:
break;
}
break;
case IRLAP_NRMP:
switch (frame[1])
{
case FRMR_RESPONSE:
goto here3;
case RD_RESPONSE:
here3:
Com_write(Format_packet (1,DISC_COMMAND));
retrycount=0;
START_F_TIMER();
irlap_state=IRLAP_PCLOSE;
break;
default:
break;
}
break;
case IRLAP_PCLOSE:
switch (frame[1])
{
case UA_RESPONSE:
irda_lmp_flag=MSG_ID_LAP_DISCONNECT_INDICATION;
/* state is set is below function as IRLAP_NDM */
LAP_disconnect_reset(UNSPECIFIED_REASON);
Reset_Baudrate();
break;
default:
break;
}
break;
default:
break;
}
}
/*************************************************************************
* FUNCTION
* Log_response_info
*
* DESCRIPTION
* Log the discovery response information
*
* PARAMETERS
* kal_uint8 * frame
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Log_response_info( kal_uint8 * frame )
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG22);
#endif
if (frame[12] < MAX_SLOTS )/*the slot the remote response*/
{
xmemcpy ((kal_uint8*)&discovery_log[frame[12]].addr,(kal_uint8*)&frame[3],4);
xmemcpy ((kal_uint8*)&discovery_log[frame[12]].info,(kal_uint8*)&frame[14],23);
}
#ifdef IRDA_KAL_TRACE
else
kal_trace(TRACE_WARNING, IRDA_MSG23);
#endif
}
/*************************************************************************
* FUNCTION
* Clear_log
*
* DESCRIPTION
* Clean all discovery log information
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Clear_log( void )
{
kal_uint8 i,j;
for (i=0;i<MAX_SLOTS;i++)
{
discovery_log[i].addr=0;
discovery_log[i].conflict=0;
for (j=0;j<21;j++)
discovery_log[i].info[j]=0;
}
}
/*************************************************************************
* FUNCTION
* IrLAP_CONNECT_request
*
* DESCRIPTION
* Perform a LAP connect request
*
* PARAMETERS
* kal_uint32 dev_addr
* RETURNS
* 0 = success
1 = media_busy
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint8 dbg_timer=0;
kal_uint8 IrLAP_CONNECT_request ( kal_uint32 dev_addr )
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG24);
#endif
/*@@@@@*/ media_busy=0;
if (media_busy==0)
{
connection_address = DEFAULT_CONNECTION_ADDRESS;
destination_address=dev_addr;
Com_write(Format_packet (1,SNRM_COMMAND));
retrycount=0;
/* give f timer a little longer to wait for the response */
f_mstimeout = 2*F_MSTIMEOUT_DEFAULT;
START_F_TIMER();
irlap_state=IRLAP_SETUP;
}
else/*media busy*/
{
irp_connect=DISCONNECT_INDICATION;
LAP_disconnect_reset(USER_REQUESTED);
irda_lmp_flag=MSG_ID_LAP_DISCOVERY_MEDIA_BUSY_ERROR;
return( MEDIA_IS_BUSY );
}
return( 0 );
}
/*************************************************************************
* FUNCTION
* Apply_connection_params
*
* DESCRIPTION
* Resolve and apply the negotiated connection parameters
*
* PARAMETERS
* kal_uint8 * frame
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Apply_connection_params( kal_uint8 * frame )
{
kal_int16 i1;
kal_uint8 * tmpptr;
kal_uint8 offset=0;
kal_uint8 mask=0;
kal_uint16 tmp_ms_timeout;
kal_uint32 savedMask;
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG25);
#endif
new_baud=0;
new_ttt=0;
new_size=0;
new_xbofs=0;
new_minttt=0;
new_ld=0;
tmpptr=&frame[10]; /* point to UA response packet */
/* validate returned mask values */
/* process baud */
if ( (tmpptr[0]==0x01)&&
((tmpptr[1]==1)||(tmpptr[1]==2)) )
{
mask = tmpptr[2];
for (i1=7;i1>-1&&!new_baud; )
{
switch(mask&(1<<i1--))
{
/*bit0*/ case 1 : new_baud=0;
/*bit1*/ case 2 : new_baud=9600l; break;
/*bit2*/ case 4 : new_baud=19200l; break;
/*bit3*/ case 8 : new_baud=38400l; break;
/*bit4*/ case 0x10 : new_baud=57600l; break;
/*bit5*/ case 0x20 : new_baud=115200l; break;
/*bit6*/ case 0x40 : new_baud=576000l; break;
/*bit7*/ case 0x80 : new_baud=1152000l; break;
}
}
mask=1<<(i1+1);
if (new_baud==0)/* set a valid mask */
{
new_baud=9600;
mask=2;
}
#ifdef __IRDA_FIR_SUPPORT__
if ((tmpptr[0]==0x01)&&
(tmpptr[1]==2)&& /* remote 4Mbps field included */
(connect_params[1]==2)&& /* our 4Mbps field is included */
(tmpptr[3]==1)){ /* 4Mbps is set */
new_baud=4000000l;
mask=1;
//result_params[2]=0;
//result_params[3]=1;
}
#endif
}
if (( tmpptr[0]==1 )&& /* add one if additional baud byte */
( tmpptr[1]==2 ))
offset=1;
/* process ttt */
if (new_baud>=115200 )
{
if ( (tmpptr[3+offset]==0x82)&&
(tmpptr[4+offset]==1) )
{
mask=tmpptr[5+offset];
for (i1=3;i1>-1&&!new_ttt; )
{
switch(mask&(1<<i1--))
{
case 1 : new_ttt=500;break;
case 2 : new_ttt=250;break;
case 4 : new_ttt=100;break;
case 8 : new_ttt=50;break;
}
}
mask=1<<(i1+1);
}
}
if(new_ttt==0) /* default */
new_ttt=500;
/* process data size */
if ( (tmpptr[6+offset]==0x83)&&
(tmpptr[7+offset]==1) )
{
mask=tmpptr[8+offset];
for (i1=5;i1>-1&&!new_size;)
{
switch(mask&(1<<i1--))
{
case 1 : new_size=64;break;
case 2 : new_size=128;break;
case 4 : new_size=256;break;
case 8 : new_size=512;break;
case 0x10 : new_size=1024;break;
case 0x20 : new_size=2048;break;
}
}
mask=1<<(i1+1);
/* ensure that the new size does not exceed the max frame size
for this station
*/
if (new_size > IRLAP_FRAME_SIZE-4)
new_size = IRLAP_FRAME_SIZE-4;
}
/* process window size*/
/* our window size is current fixed at one */
/* process additional bofs */
if ( (tmpptr[12+offset]==0x85)&&
(tmpptr[13+offset]==1) )
{
mask=tmpptr[14+offset];
for (i1=7;i1>-1&&!new_xbofs;)
{
switch(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:
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) )
{
mask=tmpptr[17+offset];
for (i1=7;i1>-1&&!new_minttt;)
{
switch(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:
mask=1<<(i1+1);
}
/* 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 */
/* values for N1 and N2 are set on primary only */
if ( (tmpptr[18+offset]==0x08)&&
(tmpptr[19+offset]==1) )
{
mask=tmpptr[20+offset];
for (i1=7;i1>-1&&!new_ld;)
{
switch(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -