📄 mnpdrvr.c
字号:
** of the real pointer.
*/
case RF_INFOL:
if ((rcv_char != DLE) || ((rcv_char == DLE) && rdle_flg))
{
if ((rcv_char == ETX) && rdle_flg)
{
fcscalc(&rcv_fcs, rcv_char);
rf_state = RF_FCS1;
}
else
{
rdle_flg = 0;
rf_tiptr = rb_iptr;
put_char();
rf_state++;
}
}
else
rdle_flg = 1;
break;
/* State RF_INFO - Receive data bytes until the stop flag is found.
*/
case RF_INFO:
if ((rcv_char != DLE) || ((rcv_char == DLE) && rdle_flg))
{
if ((rcv_char == ETX) && rdle_flg)
{
fcscalc(&rcv_fcs, rcv_char);
rf_state++;
}
else
put_char();
rdle_flg = 0;
}
else
rdle_flg = 1;
break;
/* State RF_FCS1 - Receive first byte of fcs.
*/
case RF_FCS1:
rfcs.hi = rcv_char;
rf_state++;
break;
/* State RF_FCS2 - Receive second (low) byte of fcs and take end-of-
** frame action. If the calculated fcs is not identical to that
** received, the received frame is "broken". Signal this to the sender
** by setting the LPDU type to 0 and setting the FORCE_ACK flag. If the
** FCS's match, take action based on the type of LPDU received.
*/
case RF_FCS2:
if ((rcv_fcs.hi != rfcs.hi) || (rcv_fcs.low != rcv_char))
{
lcb.lpdu_type = 0;
SETBIT2(FORCE_ACK);
ret_b(&rlkb, hdr_struct);
}
else
{
switch (lcb.lpdu_type = *(hdr_struct->bptr + PDU_TYPE))
{
case LT:
rcv_lt();
break;
case LA:
rcv_la();
break;
/* Link Request - If an LR arrives during what we think is the data
** phase, the other side may be retransmitting. In this case, just
** discard the LR. Otherwise, save the LR for the mainline to process.
** In either case, signal the mainline to ack.
*/
case LR:
if (BIT1SET(LINK_EST))
ret_b(&rlkb, hdr_struct);
else
rlkb.used_lst = hdr_struct;
SETBIT2(FORCE_ACK)
break;
case LN:
rcv_ln();
break;
case LNA:
rcv_lna();
break;
/* Link Disconnect - Signal link termination to the mainline. If the LD
** contains a user reason byte (signalled by parm 1 having a value of
** 255), save it in the LCB.
*/
case LD:
CLRBIT1(LINK_EST)
if (*(hdr_struct->bptr + 4) == 255)
{
p_mnpcb->ld_source = 1;
p_mnpcb->ld_reason =
*(hdr_struct->bptr+7);
}
else
p_mnpcb->ld_source = 0;
break;
}
}
/* Signal the mainline that a frame has been received and reset the
** receive frame state machine for the next frame.
*/
frame_rcvd = 1;
rf_state = RF_INIT;
break;
}
}
/*LOCAL----------------------------------------------------------------
rcv_la - process a received LA LPDU
---------------------------------------------------------------------*/
void rcv_la()
{
register USIGN_8 *p;
USIGN_16 i;
USIGN_8 lt_ret_seq;
/* Ignore this LA LPDU if a destructive attention is in progress.
*/
if (BIT3SET(LN_SENT))
{
ret_b(&rlkb,hdr_struct);
return;
}
/* For reasons of robustness, check the validity of the LA LPDU
*/
p = hdr_struct->bptr + 2; /* point to parm 1 */
if ((*p++ != 1) || (*p != 1))
{
ret_b(&rlkb,hdr_struct);
return;
}
p += 2;
if ((*p++ != 2) || (*p != 1))
{
ret_b(&rlkb,hdr_struct);
return;
}
/* If the receive sequence number of this LA is the same as the last
** one received, it may be an implied negative acknowledgment. Force
** the mainline to consider retransmission by setting the 'force
** retransmission' flag. Otherwise, save the new number as the last
** acked and set the 'good ack received' flag.
*/
p -= 2;
if (*p == lcb.ltssn_acked)
SETBIT2(FORCE_RET)
else
{
lcb.ltssn_acked = *p;
SETBIT1(LA_RECEIVED)
}
/* Process the new credit information received. If it is zero, return.
*/
p += 3;
if ((lcb.rem_credit = *p) == 0)
{
ret_b(&rlkb,hdr_struct);
return;
}
/* If credit is not zero and this ack was a good one, take into account
** the LT LPDUs that may have been sent since the correspondent sent
** this LA. That is, subtract from the credit the number of these not
** yet acked LTs.
*/
if (BIT1SET(LA_RECEIVED) && tbcnt)
{
lt_ret_seq = *(ftb.used_lst->bptr + LT_SEQ);
if (lt_ret_seq <= lcb.ltssn_acked)
i = (lcb.ltssn_acked - lt_ret_seq) + 1;
else
i = (256 - lt_ret_seq) + lcb.ltssn_acked + 1;
i = tbcnt - i;
if (lcb.rem_credit >= i)
{
lcb.rem_credit -= i;
if (lcb.rem_credit < 0)
lcb.rem_credit = 0;
}
else
lcb.rem_credit = 0;
}
/* Clean up
*/
ret_b(&rlkb, hdr_struct);
}
/*LOCAL----------------------------------------------------------------
rcv_ln - process a received LN LPDU
---------------------------------------------------------------------*/
void rcv_ln()
{
register USIGN_8 *p;
/* Check the sequence number of this LN LPDU. If it is the next one
** in the sequence space, signal its arrival to the sender by
** setting the LN_RECEIVED flag. Also remember the type of the LN LPDU
** by saving the type parameter value in the LCB.
*/
p = hdr_struct->bptr + 4;
if (*p == (USIGN_8) ++lcb.ln_rsn)
{
lcb.ln_rtype = *(p + 3);
SETBIT3(LN_RECEIVED)
}
/* If this is not the next one, then decrement the receive sequence
** number which was incremented above and signal the need to send an
** LNA LPDU.
*/
else
{
lcb.ln_rsn--;
SETBIT3(FORCE_LNA)
}
ret_b(&rlkb, hdr_struct);
}
/*LOCAL----------------------------------------------------------------
rcv_lna - process a received LNA LPDU
---------------------------------------------------------------------*/
void rcv_lna()
{
register USIGN_8 *p;
/* If the LNA LPDU is an acknowledgment of an outstanding LN, its
** sequence number will match that of the last LN sent. In this
** case, signal the sender that the LN has been acknowledged.
** Otherwise, just ignore this LPDU.
*/
if (*(hdr_struct->bptr + 4) == lcb.ln_ssn)
{
lcb.ln_ret_cnt = NULL;
CLRBIT3(LN_SENT)
CLRBIT3(LN_TIMER)
ln_tm=NULL;
}
ret_b(&rlkb, hdr_struct);
}
/*LOCAL----------------------------------------------------------------
rcv_lt - process a received LT LPDU
---------------------------------------------------------------------*/
void rcv_lt()
{
/* Ignore this LT LPDU if a destructive attention is in progress.
*/
if (BIT3SET(LN_SENT))
{
ret_b(&rlkb, hdr_struct);
return;
}
/* Reset window timer, if window timer is enabled.
*/
if (BIT2SET(WNDW_TIMER))
fcw_tm = lcb.window_tmr;
/* Accept this LT LPDU if it is the next one in the sequence space
** and there is room for it (i.e. there is a receive credit).
*/
if ((lcb.lcl_credit > 0)
&& (*(hdr_struct->bptr + LT_SEQ) == (USIGN_8) lcb.lt_rsn + 1))
{
++lcb.lt_rsn;
--lcb.lcl_credit;
CLRBIT3(DUP_IGNORED)
rb_iptr = rf_tiptr;
rb_cnt = rb_cnt + rf_datlen;
}
/* Otherwise, ignore the LT LPDU. In this case, set the FORCE_ACK flag
** to get the sender to ack as rapidly as possible.
*/
else
{
SETBIT2(FORCE_ACK)
/* If the LT LPDU is the same as the last one which arrived, i.e. it is
** an immediate duplicate, and this is the first occurrence of the
** immediate duplicate, then don't force the sender to ack this time.
*/
if ((*(hdr_struct->bptr + LT_SEQ) == lcb.lt_rsn)
&& !BIT3SET(DUP_IGNORED))
{
CLRBIT2(FORCE_ACK)
SETBIT3(DUP_IGNORED)
}
}
/* Clean up
*/
ret_b(&rlkb, hdr_struct);
}
/*LOCAL----------------------------------------------------------------
snd_framer - handle a transmit holding register empty
interrupt. This subroutine sends a byte-mode frame.
---------------------------------------------------------------------*/
void snd_framer()
{
extern USIGN_16 port_add;
/* Take action based on the current state of the framer state machine.
*/
switch (sf_state)
{
/* State SF_INIT - initial state. If the mainline has designated an
** LPDU to frame, the sf_busy flag will be true. If this is the case,
** begin the start flag of the frame.
*/
case SF_INIT:
if (sf_busy)
{
snd_char = SYN;
sf_state++;
break;
}
else
{
frame_dne = 1;
modem_out_busy = 0;
return;
}
/* State SF_DLE - Send DLE of start flag.
*/
case SF_DLE:
snd_fcs.hi = snd_fcs.low = 0;
snd_char = DLE;
sf_state++;
break;
/* State SF_STX - Send STX of start flag.
*/
case SF_STX:
snd_char = STX;
sf_state++;
break;
/* State SF_INFO - As long as there are info field bytes, send a
** byte and double DLE's as necessary. At the end of the information
** field of the frame, start the end flag. Signal the mainline code
** that it can enqueue another frame if it is already waiting on
** 'frame_snt'. Clearing 'sf_busy' will cause the framer to stop after
** the end flag unless another frame has been enqueued.
*/
case SF_INFO:
if (sf_len > 0)
{
if ((snd_char = get_char()) == DLE)
sf_state++;
fcscalc(&snd_fcs, snd_char);
}
else
{
sf_busy = sf_lt = 0;
frame_snt = 1;
snd_char = DLE;
sf_state = SF_ETX;
}
break;
/* State SF_DLEINFO - Double an info field DLE.
*/
case SF_DLEINFO:
snd_char = DLE;
sf_state--;
break;
/* State SF_ETX - Send ETX of end flag.
*/
case SF_ETX:
snd_char = ETX;
fcscalc(&snd_fcs, snd_char);
sf_state++;
break;
/* State SF_FCS1 - Send first byte of frame check sequence.
*/
case SF_FCS1:
snd_char = snd_fcs.hi;
sf_state++;
break;
/* State SF_FCS2 - Send second byte of frame check sequence.
** After this byte is sent, the send framer goes back to its
** initial state.
*/
case SF_FCS2:
snd_char = snd_fcs.low;
sf_state = SF_INIT;
break;
}
/* Send byte out RS-232 port
*/
outp(port_add, snd_char);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -