From: Vyacheslav F. <vf...@us...> - 2005-05-14 17:07:11
|
Update of /cvsroot/com0com/com0com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2477 Modified Files: com0com.h io.c ioctl.c openclos.c Log Message: Implemented SERIAL_LSRMST_MST insertion Index: io.c =================================================================== RCS file: /cvsroot/com0com/com0com/io.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** io.c 13 May 2005 16:58:03 -0000 1.4 --- io.c 14 May 2005 17:07:02 -0000 1.5 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.5 2005/05/14 17:07:02 vfrolov + * Implemented SERIAL_LSRMST_MST insertion + * * Revision 1.4 2005/05/13 16:58:03 vfrolov * Implemented IOCTL_SERIAL_LSRMST_INSERT *************** *** 41,44 **** --- 44,86 ---- (((PUCHAR)(pIrp)->AssociatedIrp.SystemBuffer) + (pIrp)->IoStatus.Information) + VOID CompactRawData(PC0C_RAW_DATA pRawData, ULONG writeDone) + { + if (writeDone) { + pRawData->size = (UCHAR)(pRawData->size - writeDone); + + if (pRawData->size) { + ASSERT((pRawData->size + writeDone) <= sizeof(pRawData->data)); + + RtlMoveMemory(pRawData->data, pRawData->data + writeDone, pRawData->size); + } + } + } + + NTSTATUS MoveRawData(PC0C_RAW_DATA pDstRawData, PC0C_RAW_DATA pSrcRawData) + { + int free; + + if (!pSrcRawData->size) + return STATUS_SUCCESS; + + free = sizeof(pDstRawData->data) - pDstRawData->size; + + if (free > 0) { + ULONG length; + + if (free > pSrcRawData->size) + length = pSrcRawData->size; + else + length = free; + + ASSERT((pDstRawData->size + length) <= sizeof(pDstRawData->data)); + + RtlCopyMemory(pDstRawData->data + pDstRawData->size, pSrcRawData->data, length); + pDstRawData->size = (UCHAR)(pDstRawData->size + length); + CompactRawData(pSrcRawData, length); + } + return pSrcRawData->size ? STATUS_PENDING : STATUS_SUCCESS; + } + NTSTATUS ReadBuffer(PIRP pIrp, PC0C_BUFFER pBuf) { *************** *** 68,73 **** pIrp->IoStatus.Information++; readLength--; ! if (!readLength) status = STATUS_SUCCESS; } break; --- 110,133 ---- pIrp->IoStatus.Information++; readLength--; ! if (!readLength) { status = STATUS_SUCCESS; + break; + } + } + if (pBuf->insertData.size) { + length = pBuf->insertData.size; + + if (length > readLength) + length = readLength; + + RtlCopyMemory(pReadBuf, pBuf->insertData.data, length); + pReadBuf += length; + pIrp->IoStatus.Information += length; + readLength -= length; + CompactRawData(&pBuf->insertData, length); + if (!readLength) { + status = STATUS_SUCCESS; + break; + } } break; *************** *** 105,109 **** VOID CopyCharsWithEscape( ! PC0C_IO_PORT pReadIoPort, PUCHAR pReadBuf, ULONG readLength, PUCHAR pWriteBuf, ULONG writeLength, --- 165,169 ---- VOID CopyCharsWithEscape( ! PC0C_BUFFER pBuf, UCHAR escapeChar, PUCHAR pReadBuf, ULONG readLength, PUCHAR pWriteBuf, ULONG writeLength, *************** *** 113,122 **** ULONG readDone; ULONG writeDone; - UCHAR escapeChar; readDone = 0; ! if (pReadIoPort->readBuf.escape && readLength) { ! pReadIoPort->readBuf.escape = FALSE; *pReadBuf++ = SERIAL_LSRMST_ESCAPE; readDone++; --- 173,181 ---- ULONG readDone; ULONG writeDone; readDone = 0; ! if (pBuf->escape && readLength) { ! pBuf->escape = FALSE; *pReadBuf++ = SERIAL_LSRMST_ESCAPE; readDone++; *************** *** 124,128 **** } ! escapeChar = pReadIoPort->escapeChar; if (!escapeChar) { --- 183,198 ---- } ! if (pBuf->insertData.size && readLength) { ! ULONG length = pBuf->insertData.size; ! ! if (length > readLength) ! length = readLength; ! ! RtlCopyMemory(pReadBuf, pBuf->insertData.data, length); ! pReadBuf += length; ! readDone += length; ! readLength -= length; ! CompactRawData(&pBuf->insertData, length); ! } if (!escapeChar) { *************** *** 149,153 **** if (curChar == escapeChar) { if (!readLength--) { ! pReadIoPort->readBuf.escape = TRUE; break; } --- 219,223 ---- if (curChar == escapeChar) { if (!readLength--) { ! pBuf->escape = TRUE; break; } *************** *** 186,189 **** --- 256,261 ---- } + pWriteBuf = GET_REST_BUFFER(pIrp); + if ((ULONG)(pBuf->pEnd - pBuf->pBase) <= pBuf->busy) break; *************** *** 192,200 **** pBuf->pEnd - pBuf->pFree : pBuf->pBusy - pBuf->pFree; - pWriteBuf = GET_REST_BUFFER(pIrp); pReadBuf = pBuf->pFree; CopyCharsWithEscape( ! pReadIoPort, pReadBuf, readLength, pWriteBuf, writeLength, --- 264,271 ---- pBuf->pEnd - pBuf->pFree : pBuf->pBusy - pBuf->pFree; pReadBuf = pBuf->pFree; CopyCharsWithEscape( ! pBuf, pReadIoPort->escapeChar, pReadBuf, readLength, pWriteBuf, writeLength, *************** *** 215,218 **** --- 286,340 ---- } + NTSTATUS InsertBuffer(PC0C_RAW_DATA pRawData, PC0C_BUFFER pBuf) + { + NTSTATUS status; + + if (!pBuf->pBase) + return STATUS_PENDING; + + status = STATUS_PENDING; + + for (;;) { + ULONG writeLength, readLength; + PVOID pWriteBuf, pReadBuf; + ULONG readDone, writeDone; + + writeLength = pRawData->size; + + if (!writeLength) { + status = STATUS_SUCCESS; + break; + } + + pWriteBuf = pRawData->data; + + if ((ULONG)(pBuf->pEnd - pBuf->pBase) <= pBuf->busy) + break; + + readLength = pBuf->pBusy <= pBuf->pFree ? + pBuf->pEnd - pBuf->pFree : pBuf->pBusy - pBuf->pFree; + + pReadBuf = pBuf->pFree; + + CopyCharsWithEscape( + pBuf, 0, + pReadBuf, readLength, + pWriteBuf, writeLength, + &readDone, &writeDone); + + pBuf->busy += readDone; + pBuf->pFree += readDone; + if (pBuf->pFree == pBuf->pEnd) + pBuf->pFree = pBuf->pBase; + + CompactRawData(pRawData, writeDone); + } + + if (status == STATUS_PENDING) + status = MoveRawData(&pBuf->insertData, pRawData); + + return status; + } + VOID ReadWriteDirect( PIRP pIrpLocal, *************** *** 246,250 **** pReadBuf = GET_REST_BUFFER(pIrpRead); readLength = IoGetCurrentIrpStackLocation(pIrpRead)->Parameters.Read.Length ! - pIrpRemote->IoStatus.Information; pWriteBuf = GET_REST_BUFFER(pIrpWrite); writeLength = IoGetCurrentIrpStackLocation(pIrpWrite)->Parameters.Write.Length --- 368,372 ---- pReadBuf = GET_REST_BUFFER(pIrpRead); readLength = IoGetCurrentIrpStackLocation(pIrpRead)->Parameters.Read.Length ! - pIrpRead->IoStatus.Information; pWriteBuf = GET_REST_BUFFER(pIrpWrite); writeLength = IoGetCurrentIrpStackLocation(pIrpWrite)->Parameters.Write.Length *************** *** 252,256 **** CopyCharsWithEscape( ! pReadIoPort, pReadBuf, readLength, pWriteBuf, writeLength, --- 374,378 ---- CopyCharsWithEscape( ! &pReadIoPort->readBuf, pReadIoPort->escapeChar, pReadBuf, readLength, pWriteBuf, writeLength, *************** *** 269,272 **** --- 391,426 ---- } + VOID InsertDirect( + PC0C_RAW_DATA pRawData, + PIRP pIrpRead, + PNTSTATUS pStatusWrite, + PNTSTATUS pStatusRead, + PC0C_BUFFER pBuf) + { + ULONG readDone, writeDone; + ULONG writeLength, readLength; + PVOID pWriteBuf, pReadBuf; + + pReadBuf = GET_REST_BUFFER(pIrpRead); + readLength = IoGetCurrentIrpStackLocation(pIrpRead)->Parameters.Read.Length + - pIrpRead->IoStatus.Information; + pWriteBuf = pRawData->data; + writeLength = pRawData->size; + + CopyCharsWithEscape( + pBuf, 0, + pReadBuf, readLength, + pWriteBuf, writeLength, + &readDone, &writeDone); + + pIrpRead->IoStatus.Information += readDone; + CompactRawData(pRawData, writeDone); + + if (readDone == readLength) + *pStatusRead = STATUS_SUCCESS; + if (writeDone == writeLength) + *pStatusWrite = STATUS_SUCCESS; + } + NTSTATUS FdoPortIo( int ioType, *************** *** 322,325 **** --- 476,483 ---- statusCurrent = STATUS_SUCCESS; break; + case C0C_IO_TYPE_INSERT: + ASSERT(pParam); + InsertDirect((PC0C_RAW_DATA)pParam, pIrpCurrent, &status, &statusCurrent, &pIoPort->readBuf); + break; } *************** *** 369,377 **** } ! if (ioType == C0C_IO_TYPE_WRITE && status == STATUS_PENDING) { ! ASSERT(pParam); ! status = WriteBuffer((PIRP)pParam, pIoPort, pQueueToComplete); } - return status; } --- 527,542 ---- } ! if (status == STATUS_PENDING) { ! switch (ioType) { ! case C0C_IO_TYPE_WRITE: ! ASSERT(pParam); ! status = WriteBuffer((PIRP)pParam, pIoPort, pQueueToComplete); ! break; ! case C0C_IO_TYPE_INSERT: ! ASSERT(pParam); ! status = InsertBuffer((PC0C_RAW_DATA)pParam, &pIoPort->readBuf); ! break; ! } } return status; } *************** *** 380,384 **** IN PC0C_IO_PORT pIoPort, IN ULONG bits, ! IN BOOLEAN set) { ULONG modemStatusOld; --- 545,550 ---- IN PC0C_IO_PORT pIoPort, IN ULONG bits, ! IN BOOLEAN set, ! PLIST_ENTRY pQueueToComplete) { ULONG modemStatusOld; *************** *** 403,417 **** modemStatusChanged = modemStatusOld ^ pIoPort->modemStatus; ! if (modemStatusChanged & C0C_MSB_CTS) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_CTS; ! if (modemStatusChanged & C0C_MSB_DSR) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_DSR; ! if (modemStatusChanged & C0C_MSB_RING) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_RING; ! if (modemStatusChanged & C0C_MSB_RLSD) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_RLSD; } --- 569,607 ---- modemStatusChanged = modemStatusOld ^ pIoPort->modemStatus; ! if (modemStatusChanged) { ! if (pIoPort->escapeChar) { ! C0C_RAW_DATA insertData; ! insertData.size = 3; ! insertData.data[0] = pIoPort->escapeChar; ! insertData.data[1] = SERIAL_LSRMST_MST; ! insertData.data[2] = (UCHAR)(pIoPort->modemStatus | (modemStatusChanged >> 4)); ! FdoPortIo( ! C0C_IO_TYPE_INSERT, ! &insertData, ! pIoPort, ! &pIoPort->irpQueues[C0C_QUEUE_READ], ! pQueueToComplete); ! #if DBG ! if (insertData.size) ! Trace0((PC0C_COMMON_EXTENSION)pIoPort->pDevExt, L"WARNING: Lost SERIAL_LSRMST_MST"); ! #endif /* DBG */ ! } ! if (modemStatusChanged & C0C_MSB_CTS) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_CTS; ! ! if (modemStatusChanged & C0C_MSB_DSR) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_DSR; ! ! if (modemStatusChanged & C0C_MSB_RING) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_RING; ! ! if (modemStatusChanged & C0C_MSB_RLSD) ! pIoPort->eventMask |= pIoPort->waitMask & SERIAL_EV_RLSD; ! ! WaitComplete(pIoPort, pQueueToComplete); ! } } *************** *** 436,441 **** if (bits) ! SetModemStatus(pDevExt->pIoPortRemote, bits, TRUE); ! ! WaitComplete(pDevExt->pIoPortRemote, pQueueToComplete); } --- 626,629 ---- if (bits) ! SetModemStatus(pDevExt->pIoPortRemote, bits, TRUE, pQueueToComplete); } Index: openclos.c =================================================================== RCS file: /cvsroot/com0com/com0com/openclos.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** openclos.c 13 May 2005 16:58:03 -0000 1.4 --- openclos.c 14 May 2005 17:07:02 -0000 1.5 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.5 2005/05/14 17:07:02 vfrolov + * Implemented SERIAL_LSRMST_MST insertion + * * Revision 1.4 2005/05/13 16:58:03 vfrolov * Implemented IOCTL_SERIAL_LSRMST_INSERT *************** *** 103,109 **** KeAcquireSpinLock(pDevExt->pIoLock, &oldIrql); ! SetModemStatus(pDevExt->pIoPortRemote, C0C_MSB_CTS | C0C_MSB_DSR, FALSE); ! ! WaitComplete(pDevExt->pIoPortRemote, &queueToComplete); readBuf = pDevExt->pIoPortLocal->readBuf; --- 106,110 ---- KeAcquireSpinLock(pDevExt->pIoLock, &oldIrql); ! SetModemStatus(pDevExt->pIoPortRemote, C0C_MSB_CTS | C0C_MSB_DSR, FALSE, &queueToComplete); readBuf = pDevExt->pIoPortLocal->readBuf; Index: ioctl.c =================================================================== RCS file: /cvsroot/com0com/com0com/ioctl.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ioctl.c 13 May 2005 16:58:03 -0000 1.3 --- ioctl.c 14 May 2005 17:07:02 -0000 1.4 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.4 2005/05/14 17:07:02 vfrolov + * Implemented SERIAL_LSRMST_MST insertion + * * Revision 1.3 2005/05/13 16:58:03 vfrolov * Implemented IOCTL_SERIAL_LSRMST_INSERT *************** *** 65,71 **** pDevExt->pIoPortRemote, C0C_MSB_CTS, ! (BOOLEAN)(code == IOCTL_SERIAL_SET_RTS)); ! ! WaitComplete(pDevExt->pIoPortRemote, &queueToComplete); KeReleaseSpinLock(pDevExt->pIoLock, oldIrql); --- 68,73 ---- pDevExt->pIoPortRemote, C0C_MSB_CTS, ! (BOOLEAN)(code == IOCTL_SERIAL_SET_RTS), ! &queueToComplete); KeReleaseSpinLock(pDevExt->pIoLock, oldIrql); *************** *** 90,96 **** pDevExt->pIoPortRemote, C0C_MSB_DSR, ! (BOOLEAN)(code == IOCTL_SERIAL_SET_DTR)); ! ! WaitComplete(pDevExt->pIoPortRemote, &queueToComplete); KeReleaseSpinLock(pDevExt->pIoLock, oldIrql); --- 92,97 ---- pDevExt->pIoPortRemote, C0C_MSB_DSR, ! (BOOLEAN)(code == IOCTL_SERIAL_SET_DTR), ! &queueToComplete); KeReleaseSpinLock(pDevExt->pIoLock, oldIrql); Index: com0com.h =================================================================== RCS file: /cvsroot/com0com/com0com/com0com.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** com0com.h 13 May 2005 16:58:03 -0000 1.5 --- com0com.h 14 May 2005 17:07:02 -0000 1.6 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.6 2005/05/14 17:07:02 vfrolov + * Implemented SERIAL_LSRMST_MST insertion + * * Revision 1.5 2005/05/13 16:58:03 vfrolov * Implemented IOCTL_SERIAL_LSRMST_INSERT *************** *** 82,85 **** --- 85,93 ---- } C0C_IRP_QUEUE, *PC0C_IRP_QUEUE; + typedef struct _C0C_RAW_DATA { + UCHAR size; + UCHAR data[7]; + } C0C_RAW_DATA, *PC0C_RAW_DATA; + typedef struct _C0C_BUFFER { PUCHAR pBase; *************** *** 89,92 **** --- 97,101 ---- ULONG busy; BOOLEAN escape; + C0C_RAW_DATA insertData; } C0C_BUFFER, *PC0C_BUFFER; *************** *** 94,98 **** (buf).pFree = (buf).pBusy = (buf).pBase; \ (buf).busy = 0; \ ! (buf).escape = FALSE struct _C0C_FDOPORT_EXTENSION; --- 103,108 ---- (buf).pFree = (buf).pBusy = (buf).pBase; \ (buf).busy = 0; \ ! (buf).escape = FALSE; \ ! (buf).insertData.size = 0 struct _C0C_FDOPORT_EXTENSION; *************** *** 258,261 **** --- 268,272 ---- #define C0C_IO_TYPE_WRITE 2 #define C0C_IO_TYPE_WAIT_COMPLETE 3 + #define C0C_IO_TYPE_INSERT 4 NTSTATUS FdoPortIo( *************** *** 269,273 **** IN PC0C_IO_PORT pIoPort, IN ULONG bits, ! IN BOOLEAN set); VOID UpdateHandFlow( --- 280,285 ---- IN PC0C_IO_PORT pIoPort, IN ULONG bits, ! IN BOOLEAN set, ! PLIST_ENTRY pQueueToComplete); VOID UpdateHandFlow( |