Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/windows/ndis/MPUsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4502,7 +4502,28 @@ VOID MPUSB_TLPTxPacket
Qmap->PadCD |= (paddingBytes);
Qmap->MuxId = pAdapter->MuxId;
sendBytes += paddingBytes;
Qmap->PacketLen = RtlUshortByteSwap(sendBytes);
/* When QMAPEnabledV4/V2/V3 is active, the QMAP_UL_CHECKSUM structure
* (8 bytes) is placed between the QMAP header and the IP payload. The
* PacketLen field must cover all bytes that follow the QMAP header, so it
* must include sizeof(QMAP_UL_CHECKSUM). Without this fix, PacketLen is
* undersized by sizeof(QMAP_UL_CHECKSUM); IPA advances its frame-boundary
* pointer sizeof(QMAP_UL_CHECKSUM) bytes early, misreads trailing IP
* payload as the next QMAP header, and raises exception=4
* (status.pkt_len < qmap.pkt_len). */
if ((pAdapter->QMAPEnabledV4 == TRUE)
#ifdef QCUSB_MUX_PROTOCOL
#if defined(QCMP_QMAP_V2_SUPPORT)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a new QMAP version with UL checksum gets added later, it's easy to miss this block and silently get wrong PacketLen again. consider extracting the condition into a helper macro

For example, add this on top of the file,
#if defined(QCUSB_MUX_PROTOCOL) && defined(QCMP_QMAP_V2_SUPPORT)
#define QMAP_UL_CHECKSUM_ENABLED(pAdapter)
((pAdapter)->QMAPEnabledV4 || (pAdapter)->QMAPEnabledV2 || (pAdapter)->QMAPEnabledV3)
#else
#define QMAP_UL_CHECKSUM_ENABLED(pAdapter)
((pAdapter)->QMAPEnabledV4)
#endif

And then use it here,
if (QMAP_UL_CHECKSUM_ENABLED(pAdapter))
Qmap->PacketLen = RtlUshortByteSwap((USHORT)(sendBytes + sizeof(QMAP_UL_CHECKSUM)));
else
Qmap->PacketLen = RtlUshortByteSwap((USHORT)sendBytes);

This eliminates the #ifdef nesting inside the if condition, removes the duplication, and makes future QMAP version additions a single-point change.

|| (pAdapter->QMAPEnabledV2 == TRUE) || (pAdapter->QMAPEnabledV3 == TRUE)
#endif
#endif
)
{
Qmap->PacketLen = RtlUshortByteSwap((USHORT)(sendBytes + sizeof(QMAP_UL_CHECKSUM)));
}
else
{
Qmap->PacketLen = RtlUshortByteSwap((USHORT)sendBytes);
}
if (pAdapter->QMAPEnabledV4 == TRUE)
{
PQMAP_UL_CHECKSUM pULCheckSum = (PQMAP_UL_CHECKSUM)((PUCHAR)Qmap + sizeof(QMAP_STRUCT));
Expand Down Expand Up @@ -5798,7 +5819,28 @@ VOID MPUSB_TLPTxPacketEx
Qmap->PadCD |= (paddingBytes);
Qmap->MuxId = pAdapter->MuxId;
sendBytes += paddingBytes;
Qmap->PacketLen = RtlUshortByteSwap(sendBytes);
/* When QMAPEnabledV4/V2/V3 is active, the QMAP_UL_CHECKSUM structure
* (8 bytes) is placed between the QMAP header and the IP payload. The
* PacketLen field must cover all bytes that follow the QMAP header, so it
* must include sizeof(QMAP_UL_CHECKSUM). Without this fix, PacketLen is
* undersized by sizeof(QMAP_UL_CHECKSUM); IPA advances its frame-boundary
* pointer sizeof(QMAP_UL_CHECKSUM) bytes early, misreads trailing IP
* payload as the next QMAP header, and raises exception=4
* (status.pkt_len < qmap.pkt_len). */
if ((pAdapter->QMAPEnabledV4 == TRUE)
#ifdef QCUSB_MUX_PROTOCOL
#if defined(QCMP_QMAP_V2_SUPPORT)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

|| (pAdapter->QMAPEnabledV2 == TRUE) || (pAdapter->QMAPEnabledV3 == TRUE)
#endif
#endif
)
{
Qmap->PacketLen = RtlUshortByteSwap((USHORT)(sendBytes + sizeof(QMAP_UL_CHECKSUM)));
}
else
{
Qmap->PacketLen = RtlUshortByteSwap((USHORT)sendBytes);
}
if (pAdapter->QMAPEnabledV4 == TRUE)
{
PQMAP_UL_CHECKSUM pULCheckSum = (PQMAP_UL_CHECKSUM)((PUCHAR)Qmap + sizeof(QMAP_STRUCT));
Expand Down
Loading