📄 irlapio.c
字号:
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx REJ")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendSREJ | formats a SREJ frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm int | Nr | Nr to be placed in SREJ frame
*
* @comm
* comments
*/
VOID
SendSREJ(PIRLAP_CB pIrlapCb, int Nr)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_SREJ(pIMsg, pIrlapCb->ConnAddr,
pIrlapCb->CRBit, IRLAP_PFBIT_SET,
Nr);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx SREJ")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendFRMR | formats a FRMR frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm int | Nr | Nr to be placed in SREJ frame
*
* @comm
* comments
*/
VOID
SendFRMR(PIRLAP_CB pIrlapCb, IRLAP_FRMR_FORMAT *pFRMRFormat)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_FRMR(pIMsg, pIrlapCb->ConnAddr,
pIrlapCb->CRBit, IRLAP_PFBIT_SET,
pFRMRFormat);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx FRMR")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendIFrame | Builds and sends an I frame to MAC
*
* @rdesc SUCCESS otherwise one of the following errors:
* @flag val | desc
*
* @parm | |
*
* @comm
* comments
*/
VOID
SendIFrame(PIRLAP_CB pIrlapCb, PIRDA_MSG pMsg, int Ns, int PFBit)
{
if (NULL == pMsg)
{
ASSERT(0);
return; // LOG AN ERROR !!!
}
ClearRxWindow(pIrlapCb);
pIrlapCb->RxWin.Start = pIrlapCb->Vr; // RxWin.Start = what we've acked
(void) Format_I(pMsg, pIrlapCb->ConnAddr, pIrlapCb->CRBit, PFBit,
pIrlapCb->Vr, Ns);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx IFrame")));
InterlockedIncrement(&pMsg->IRDA_MSG_SendRefCnt);
SendFrame(pIrlapCb, pMsg);
pMsg->IRDA_MSG_pHdrRead +=2; // uglyness.. chop header in case frame
// requires retransmission
return;
}
/*****************************************************************************
*
* @func UINT | SendUIFrame | Builds and sends an UI frame to MAC
*
* @rdesc SUCCESS otherwise one of the following errors:
* @flag val | desc
*
* @parm | |
*
* @comm
* comments
*/
VOID
SendUIFrame(PIRLAP_CB pIrlapCb, PIRDA_MSG pMsg)
{
if (NULL == pMsg)
{
ASSERT(0);
return;
}
(void) Format_UI(pMsg, pIrlapCb->ConnAddr,
pIrlapCb->CRBit,IRLAP_PFBIT_SET);
InterlockedIncrement(&pMsg->IRDA_MSG_SendRefCnt);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx UIFrame")));
SendFrame(pIrlapCb, pMsg);
}
/*****************************************************************************
*
* @func UINT | _IRLMP_Up | Adds logging to the IRLMP_Up
*
* @rdesc returns of IRLMP_Up
*
* @parm PIRDA_MSG | pMsg | pointer to IRDA message
*
* @comm
* comments
*/
/*
UINT
_IRLMP_Up(PIRDA_MSG pMsg)
{
IRLAP_LOG_ACTION((TEXT("%s%s"), IRDA_PrimStr[pMsg->Prim],
pMsg->Prim == IRLAP_DISCOVERY_CONF ?
IRDA_StatStr[pMsg->IRDA_MSG_DscvStatus] :
pMsg->Prim == IRLAP_CONNECT_CONF ?
IRDA_StatStr[pMsg->IRDA_MSG_ConnStatus] :
pMsg->Prim == IRLAP_DISCONNECT_IND ?
IRDA_StatStr[pMsg->IRDA_MSG_DiscStatus] :
pMsg->Prim == IRLAP_DATA_CONF || pMsg->Prim == IRLAP_UDATA_CONF ?
IRDA_StatStr[pMsg->IRDA_MSG_DataStatus] : TEXT("")));
return (IRLMP_Up(pMsg));
}
*/
UCHAR *
BuildTuple(UCHAR *pBuf, UCHAR Pi, UINT BitField)
{
*pBuf++ = Pi;
if (BitField > 0xFF)
{
*pBuf++ = 2; // Pl
*pBuf++ = (UCHAR) (BitField);
*pBuf++ = (UCHAR) (BitField >> 8);
}
else
{
*pBuf++ = 1; // Pl
*pBuf++ = (UCHAR) (BitField);
}
return pBuf;
}
UCHAR *
BuildNegParms(UCHAR *pBuf, IRDA_QOS_PARMS *pQos)
{
pBuf = BuildTuple(pBuf, QOS_PI_BAUD, pQos->bfBaud);
pBuf = BuildTuple(pBuf, QOS_PI_MAX_TAT, pQos->bfMaxTurnTime);
pBuf = BuildTuple(pBuf, QOS_PI_DATA_SZ, pQos->bfDataSize);
pBuf = BuildTuple(pBuf, QOS_PI_WIN_SZ, pQos->bfWindowSize);
pBuf = BuildTuple(pBuf, QOS_PI_BOFS, pQos->bfBofs);
pBuf = BuildTuple(pBuf, QOS_PI_MIN_TAT, pQos->bfMinTurnTime);
pBuf = BuildTuple(pBuf, QOS_PI_DISC_THRESH, pQos->bfDisconnectTime);
return pBuf;
}
void
StoreULAddr(UCHAR Addr[], ULONG ULAddr)
{
Addr[0] = (UCHAR) ( 0xFF & ULAddr);
Addr[1] = (UCHAR) ((0xFF00 & ULAddr) >> 8);
Addr[2] = (UCHAR) ((0xFF0000 & ULAddr) >> 16);
Addr[3] = (UCHAR) ((0xFF000000 & ULAddr) >> 24);
}
UCHAR *
_PutAddr(UCHAR *pBuf, UCHAR Addr[])
{
*pBuf++ = Addr[0];
*pBuf++ = Addr[1];
*pBuf++ = Addr[2];
*pBuf++ = Addr[3];
return (pBuf);
}
void
BuildUHdr(IRDA_MSG *pMsg, int FrameType, int Addr, int CRBit, int PFBit)
{
if (pMsg->IRDA_MSG_pHdrRead != NULL)
{
pMsg->IRDA_MSG_pHdrRead -= 2;
ASSERT(pMsg->IRDA_MSG_pHdrRead >= pMsg->IRDA_MSG_Header);
*(pMsg->IRDA_MSG_pHdrRead) = (UCHAR) _MAKE_ADDR(Addr, CRBit);
*(pMsg->IRDA_MSG_pHdrRead+1) = (UCHAR) _MAKE_UCNTL(FrameType, PFBit);
}
else
{
pMsg->IRDA_MSG_pRead -= 2;
*(pMsg->IRDA_MSG_pRead) = (UCHAR) _MAKE_ADDR(Addr, CRBit);
*(pMsg->IRDA_MSG_pRead+1) = (UCHAR) _MAKE_UCNTL(FrameType, PFBit);
}
return;
}
void
BuildSHdr(IRDA_MSG *pMsg, int FrameType, int Addr, int CRBit, int PFBit,
int Nr)
{
if (pMsg->IRDA_MSG_pHdrRead != NULL)
{
pMsg->IRDA_MSG_pHdrRead -= 2;
ASSERT(pMsg->IRDA_MSG_pHdrRead >= pMsg->IRDA_MSG_Header);
*(pMsg->IRDA_MSG_pHdrRead) = (UCHAR) _MAKE_ADDR(Addr, CRBit);
*(pMsg->IRDA_MSG_pHdrRead+1) = (UCHAR) _MAKE_SCNTL(FrameType,
PFBit, Nr);
}
else
{
pMsg->IRDA_MSG_pRead -= 2;
*(pMsg->IRDA_MSG_pRead) = (UCHAR) _MAKE_ADDR(Addr, CRBit);
*(pMsg->IRDA_MSG_pRead+1) = (UCHAR) _MAKE_SCNTL(FrameType, PFBit, Nr);
}
return;
}
UCHAR *
Format_SNRM(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, UCHAR SAddr[],
UCHAR DAddr[], int CAddr, IRDA_QOS_PARMS *pQos)
{
BuildUHdr(pMsg, IRLAP_SNRM, Addr, CRBit, PFBit);
if (pQos != NULL)
{
pMsg->IRDA_MSG_pWrite = _PutAddr(pMsg->IRDA_MSG_pWrite, SAddr);
pMsg->IRDA_MSG_pWrite = _PutAddr(pMsg->IRDA_MSG_pWrite, DAddr);
*pMsg->IRDA_MSG_pWrite++ = CAddr << 1; // Thats what the f'n spec says
pMsg->IRDA_MSG_pWrite = BuildNegParms(pMsg->IRDA_MSG_pWrite, pQos);
}
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_DISC(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit)
{
BuildUHdr(pMsg, IRLAP_DISC, Addr, CRBit, PFBit);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_UI(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit)
{
BuildUHdr(pMsg, IRLAP_UI, Addr, CRBit, PFBit);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_DscvXID(IRDA_MSG *pMsg, int ConnAddr, int CRBit, int PFBit,
IRLAP_XID_DSCV_FORMAT *pXIDFormat,
CHAR DscvInfo[], int DscvInfoLen)
{
if (pMsg->IRDA_MSG_pHdrRead != NULL)
{
pMsg->IRDA_MSG_pHdrRead -= 2;
ASSERT(pMsg->IRDA_MSG_pHdrRead >= pMsg->IRDA_MSG_Header);
*(pMsg->IRDA_MSG_pHdrRead) = (UCHAR) _MAKE_ADDR(ConnAddr, CRBit);
if (CRBit)
*(pMsg->IRDA_MSG_pHdrRead+1)=
(UCHAR) _MAKE_UCNTL(IRLAP_XID_CMD, PFBit);
else
*(pMsg->IRDA_MSG_pHdrRead+1)=
(UCHAR) _MAKE_UCNTL(IRLAP_XID_RSP, PFBit);
}
else
{
pMsg->IRDA_MSG_pRead -= 2;
*(pMsg->IRDA_MSG_pRead) = (UCHAR) _MAKE_ADDR(ConnAddr, CRBit);
if (CRBit)
*(pMsg->IRDA_MSG_pRead+1)=
(UCHAR) _MAKE_UCNTL(IRLAP_XID_CMD, PFBit);
else
*(pMsg->IRDA_MSG_pRead+1)=
(UCHAR) _MAKE_UCNTL(IRLAP_XID_RSP, PFBit);
}
*pMsg->IRDA_MSG_pWrite++ = IRLAP_XID_DSCV_FORMAT_ID;
RtlCopyMemory(pMsg->IRDA_MSG_pWrite, (CHAR *) pXIDFormat,
sizeof(IRLAP_XID_DSCV_FORMAT) - 1); // Subtract for FirstDscvUCHAR
// in structure
pMsg->IRDA_MSG_pWrite += sizeof(IRLAP_XID_DSCV_FORMAT) - 1;
if (DscvInfo != NULL)
{
RtlCopyMemory(pMsg->IRDA_MSG_pWrite, DscvInfo, DscvInfoLen);
pMsg->IRDA_MSG_pWrite += DscvInfoLen;
}
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_TEST(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit,
UCHAR SAddr[], UCHAR DAddr[])
{
BuildUHdr(pMsg, IRLAP_TEST, Addr, CRBit, PFBit);
pMsg->IRDA_MSG_pWrite = _PutAddr(pMsg->IRDA_MSG_pWrite, SAddr);
pMsg->IRDA_MSG_pWrite = _PutAddr(pMsg->IRDA_MSG_pWrite, DAddr);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_RNRM(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit)
{
BuildUHdr(pMsg, IRLAP_RNRM, Addr, CRBit, PFBit);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_UA(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, UCHAR SAddr[],
UCHAR DAddr[], IRDA_QOS_PARMS *pQos)
{
BuildUHdr(pMsg, IRLAP_UA, Addr, CRBit, PFBit);
if (SAddr != NULL)
{
pMsg->IRDA_MSG_pWrite = _PutAddr(pMsg->IRDA_MSG_pWrite, SAddr);
}
if (DAddr != NULL)
{
pMsg->IRDA_MSG_pWrite = _PutAddr(pMsg->IRDA_MSG_pWrite, DAddr);
}
if (pQos != NULL)
pMsg->IRDA_MSG_pWrite = BuildNegParms(pMsg->IRDA_MSG_pWrite, pQos);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_FRMR(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit,
IRLAP_FRMR_FORMAT *pFormat)
{
BuildUHdr(pMsg, IRLAP_FRMR, Addr, CRBit, PFBit);
RtlCopyMemory(pMsg->IRDA_MSG_pWrite, (CHAR *)pFormat,
sizeof(IRLAP_FRMR_FORMAT));
pMsg->IRDA_MSG_pWrite += sizeof(IRLAP_FRMR_FORMAT);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_DM(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit)
{
BuildUHdr(pMsg, IRLAP_DM, Addr, CRBit, PFBit);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_RD(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit)
{
BuildUHdr(pMsg, IRLAP_RD, Addr, CRBit, PFBit);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_RR(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr)
{
BuildSHdr(pMsg, IRLAP_RR, Addr, CRBit, PFBit, Nr);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_RNR(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr)
{
BuildSHdr(pMsg, IRLAP_RNR, Addr, CRBit, PFBit, Nr);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_REJ(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr)
{
BuildSHdr(pMsg, IRLAP_REJ, Addr, CRBit, PFBit, Nr);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_SREJ(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr)
{
BuildSHdr(pMsg, IRLAP_SREJ, Addr, CRBit, PFBit, Nr);
return (pMsg->IRDA_MSG_pWrite);
}
UCHAR *
Format_I(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr, int Ns)
{
if (pMsg->IRDA_MSG_pHdrRead != NULL)
{
pMsg->IRDA_MSG_pHdrRead -= 2;
ASSERT(pMsg->IRDA_MSG_pHdrRead >= pMsg->IRDA_MSG_Header);
*(pMsg->IRDA_MSG_pHdrRead) = (UCHAR) _MAKE_ADDR(Addr, CRBit);
*(pMsg->IRDA_MSG_pHdrRead+1) = (UCHAR) (((Ns & 7) << 1) +
((PFBit & 1)<< 4) + (Nr <<5));
}
else
{
pMsg->IRDA_MSG_pRead -= 2;
*(pMsg->IRDA_MSG_pRead) = (UCHAR) _MAKE_ADDR(Addr, CRBit);
*(pMsg->IRDA_MSG_pRead+1) = (UCHAR) (((Ns & 7) << 1) +
((PFBit & 1)<< 4) + (Nr <<5));
}
return (pMsg->IRDA_MSG_pWrite);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -