📄 irlapio.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
/*****************************************************************************
*
*
* File: irlapio.c
*
* Description: IRLAP I/O routines
*
* Date: 4/25/95
*
*/
#include <irda.h>
#include <irlap.h>
#include <irlmp.h>
#include <irlapp.h>
#include <irlapio.h>
#include <irlaplog.h>
extern UCHAR IrlapBroadcastDevAddr[];
__inline
VOID
SendFrame(PIRLAP_CB pIrlapCb, PIRDA_MSG pMsg)
{
pMsg->Prim = MAC_DATA_REQ;
IrmacDown(pIrlapCb->pIrdaLinkCb, pMsg);
// IRLAP_LOG_ACTION((pIrlapCb, TEXT("MAC_DATA_REQ: %s"), FrameToStr(pMsg)));
}
/*****************************************************************************
*
* @func ret_type | func_name | funcdesc
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm data_type | parm_name | description
*
* @comm
* comments
*/
VOID
ClearRxWindow(PIRLAP_CB pIrlapCb)
{
UINT i;
// Remove everything from Rx window
for (i = pIrlapCb->Vr; i != pIrlapCb->RxWin.End; i = (i+1) % IRLAP_MOD)
{
if (pIrlapCb->RxWin.pMsg[i] != NULL)
{
pIrlapCb->RxWin.pMsg[i]->Prim = MAC_DATA_RESP;
IrmacDown(pIrlapCb->pIrdaLinkCb, pIrlapCb->RxWin.pMsg[i]);
pIrlapCb->RxWin.pMsg[i] = NULL;
}
pIrlapCb->RxWin.End = pIrlapCb->Vr;
}
}
/*****************************************************************************
*
* @func ret_type | func_name | funcdesc
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm data_type | parm_name | description
*
* @comm
* comments
*/
VOID
SendDscvXIDCmd(PIRLAP_CB pIrlapCb)
{
UINT rc = SUCCESS;
IRLAP_XID_DSCV_FORMAT XIDFormat;
CHAR *DscvInfo;
int DscvInfoLen;
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
RtlCopyMemory(XIDFormat.SrcAddr, pIrlapCb->LocalDevice.DevAddr,
IRDA_DEV_ADDR_LEN);
RtlCopyMemory(XIDFormat.DestAddr, IrlapBroadcastDevAddr,
IRDA_DEV_ADDR_LEN);
XIDFormat.NoOfSlots = IRLAP_SLOT_FLAG(pIrlapCb->MaxSlot);
XIDFormat.GenNewAddr = pIrlapCb->GenNewAddr;
XIDFormat.Reserved = 0;
if (pIrlapCb->SlotCnt == pIrlapCb->MaxSlot)
{
DscvInfo = pIrlapCb->LocalDevice.DscvInfo;
DscvInfoLen = pIrlapCb->LocalDevice.DscvInfoLen;
XIDFormat.SlotNo = IRLAP_END_DSCV_SLOT_NO;
}
else
{
DscvInfo = NULL;
DscvInfoLen = 0;
XIDFormat.SlotNo = pIrlapCb->SlotCnt;
}
XIDFormat.Version = pIrlapCb->LocalDevice.IRLAP_Version;
pIMsg->IRDA_MSG_pWrite = Format_DscvXID(pIMsg,
IRLAP_BROADCAST_CONN_ADDR,
IRLAP_CMD, IRLAP_PFBIT_SET,
&XIDFormat, DscvInfo,
DscvInfoLen);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx DscvXidCmd")));
SendFrame(pIrlapCb, pIMsg);
}
/****************************************************************************S*
*
* @func ret_type | func_name | funcdesc
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm data_type | parm_name | description
*
* @comm
* comments
*/
VOID
SendDscvXIDRsp(PIRLAP_CB pIrlapCb)
{
IRLAP_XID_DSCV_FORMAT XIDFormat;
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
XIDFormat.GenNewAddr = pIrlapCb->GenNewAddr;
if (pIrlapCb->GenNewAddr)
{
StoreULAddr(pIrlapCb->LocalDevice.DevAddr, GetMyDevAddr(TRUE));
pIrlapCb->GenNewAddr = FALSE;
}
RtlCopyMemory(XIDFormat.SrcAddr, pIrlapCb->LocalDevice.DevAddr,
IRDA_DEV_ADDR_LEN);
RtlCopyMemory(XIDFormat.DestAddr, pIrlapCb->RemoteDevice.DevAddr,
IRDA_DEV_ADDR_LEN);
XIDFormat.NoOfSlots = IRLAP_SLOT_FLAG(pIrlapCb->RemoteMaxSlot);
XIDFormat.Reserved = 0;
XIDFormat.SlotNo = pIrlapCb->RespSlot;
XIDFormat.Version = pIrlapCb->LocalDevice.IRLAP_Version;
pIMsg->IRDA_MSG_pWrite = Format_DscvXID(
pIMsg,
IRLAP_BROADCAST_CONN_ADDR,
IRLAP_RSP, IRLAP_PFBIT_SET,
&XIDFormat,
pIrlapCb->LocalDevice.DscvInfo,
pIrlapCb->LocalDevice.DscvInfoLen);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx DscvXidRsp")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendSNRM | formats a SNRM frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm UCHAR | ConnAddr | Connection address
*
* @comm
* The ConnAddr can be different than that in the control block.
* For reset, its the same, but set to broadcast for initial
* connection.
*/
VOID
SendSNRM(PIRLAP_CB pIrlapCb, BOOLEAN SendQos)
{
IRDA_QOS_PARMS *pQos = NULL;
int ConnAddr = pIrlapCb->ConnAddr;
IRDA_MSG *pIMsg;
if (SendQos)
{
ConnAddr = IRLAP_BROADCAST_CONN_ADDR;
pQos = &pIrlapCb->LocalQos;
}
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_SNRM(pIMsg, ConnAddr,
IRLAP_CMD,
IRLAP_PFBIT_SET,
pIrlapCb->LocalDevice.DevAddr,
pIrlapCb->RemoteDevice.DevAddr,
pIrlapCb->ConnAddr,
pQos);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx SNRM")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendUA | formats a UA frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
* @parm BOOLEAN | SendQos | Send the Qos
*
* @comm
* comments
*/
VOID
SendUA(PIRLAP_CB pIrlapCb, BOOLEAN SendQos)
{
IRDA_QOS_PARMS NegQos;
IRDA_QOS_PARMS *pNegQos = NULL;
UCHAR *pSrcAddr = NULL;
UCHAR *pDestAddr = NULL;
IRDA_MSG *pIMsg;
if (SendQos)
{
// Put all parms (type 0 and 1) in NegQos
RtlCopyMemory(&NegQos, &pIrlapCb->LocalQos, sizeof(IRDA_QOS_PARMS));
// Overwrite type 0 parameters that have already been negotiated
NegQos.bfBaud = pIrlapCb->NegotiatedQos.bfBaud;
NegQos.bfDisconnectTime = pIrlapCb->NegotiatedQos.bfDisconnectTime;
pNegQos = &NegQos;
}
// This will be moved into the "if" above when the spec is clarified
pSrcAddr = pIrlapCb->LocalDevice.DevAddr;
pDestAddr = pIrlapCb->RemoteDevice.DevAddr;
//------------------------------------------------------------------
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_UA(pIMsg,
pIrlapCb->ConnAddr,
IRLAP_RSP,
IRLAP_PFBIT_SET,
pSrcAddr, pDestAddr, pNegQos);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx UA")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendDM | formats a DM frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendDM(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_DM(pIMsg,
pIrlapCb->ConnAddr,
IRLAP_RSP,
IRLAP_PFBIT_SET);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx DM")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendRD | formats a RD frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendRD(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_RD(pIMsg,
pIrlapCb->ConnAddr,
IRLAP_RSP,
IRLAP_PFBIT_SET);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx RD")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendRR | formats a RR frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendRR(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
ClearRxWindow(pIrlapCb);
pIrlapCb->RxWin.Start = pIrlapCb->Vr; // RxWin.Start = what we've acked
pIMsg->IRDA_MSG_pWrite = Format_RR(pIMsg, pIrlapCb->ConnAddr,
pIrlapCb->CRBit, IRLAP_PFBIT_SET,
pIrlapCb->Vr);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx RR")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendRNR | formats a RNR frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendRR_RNR(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
UCHAR *(*pFormatRR_RNR)();
if (pIrlapCb->LocalBusy)
{
pFormatRR_RNR = Format_RNR;
}
else
{
pFormatRR_RNR = Format_RR;
}
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
ClearRxWindow(pIrlapCb);
pIrlapCb->RxWin.Start = pIrlapCb->Vr; // RxWin.Start = what we've acked
pIMsg->IRDA_MSG_pWrite = (*pFormatRR_RNR)(pIMsg, pIrlapCb->ConnAddr,
pIrlapCb->CRBit, IRLAP_PFBIT_SET,
pIrlapCb->Vr);
IRLAP_LOG_ACTION((pIrlapCb, (TEXT("Tx %s"), Format_RNR? TEXT("RNR"):TEXT("RR"))));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendDISC | formats a DISC frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendDISC(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_DISC(pIMsg, pIrlapCb->ConnAddr,
IRLAP_CMD, IRLAP_PFBIT_SET);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx DISC")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendRNRM | formats a RNRM frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendRNRM(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
pIMsg->IRDA_MSG_pWrite = Format_RNRM(pIMsg, pIrlapCb->ConnAddr,
IRLAP_RSP, IRLAP_PFBIT_SET);
IRLAP_LOG_ACTION((pIrlapCb, TEXT("Tx RNRM")));
SendFrame(pIrlapCb, pIMsg);
}
/*****************************************************************************
*
* @func UINT | SendREJ | formats a REJ frame and sends it
*
* @rdesc SUCCESS, otherwise one of the following errors:
* @flag val | desc
*
*
* @comm
* comments
*/
VOID
SendREJ(PIRLAP_CB pIrlapCb)
{
IRDA_MSG *pIMsg;
pIMsg = AllocTxMsg(pIrlapCb->pIrdaLinkCb);
ClearRxWindow(pIrlapCb);
pIrlapCb->RxWin.Start = pIrlapCb->Vr; // RxWin.Start = what we've acked
pIMsg->IRDA_MSG_pWrite = Format_REJ(pIMsg, pIrlapCb->ConnAddr,
pIrlapCb->CRBit, IRLAP_PFBIT_SET,
pIrlapCb->Vr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -