Changeset 108371 in vbox
- Timestamp:
- Feb 25, 2025 1:57:42 PM (8 weeks ago)
- svn:sync-xref-src-repo-rev:
- 167732
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/UsbNet.cpp
r107875 r108371 422 422 STAMCOUNTER StatTransmitBytes; 423 423 424 uint32_t u32PktNo; 424 425 /** 425 426 * LUN\#0 data. … … 1133 1134 static int usbNetCompleteOk(PUSBNET pThis, PVUSBURB pUrb, size_t cbData) 1134 1135 { 1135 LogF unc(("/#%u/ pUrb=%p:%s cbData=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData));1136 LogFlowFunc(("/#%u/ pUrb=%p:%s cbData=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData)); 1136 1137 1137 1138 pUrb->enmStatus = VUSBSTATUS_OK; … … 1149 1150 static void usbNetCompleteNotificationOk(PUSBNET pThis, PVUSBURB pUrb, const void *pSrc, size_t cbSrc) 1150 1151 { 1151 LogF unc(("/#%u/ pUrb=%p:%s (cbData=%#x) cbSrc=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->cbData, cbSrc));1152 LogFlowFunc(("/#%u/ pUrb=%p:%s (cbData=%#x) cbSrc=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->cbData, cbSrc)); 1152 1153 1153 1154 pUrb->enmStatus = VUSBSTATUS_OK; … … 1164 1165 memcpy(pDst, pSrc, cbCopy); 1165 1166 pUrb->cbData = (uint32_t)cbCopy; 1166 Log (("Copied %zu bytes to pUrb->abData, source had %zu bytes\n", cbCopy, cbSrc));1167 Log2Func(("/#%u/ Copied %zu bytes to pUrb->abData, source had %zu bytes\n", pThis->pUsbIns->iInstance, cbCopy, cbSrc)); 1167 1168 1168 1169 /* … … 1267 1268 } 1268 1269 1270 #ifdef LOG_ENABLED 1271 1272 DECLINLINE(void) usbNetProtocolDump(const uint8_t *cpPacket, uint32_t cb) 1273 { 1274 RT_NOREF(cb); 1275 uint8_t protocol; 1276 uint16_t offset = sizeof(RTNETETHERHDR); 1277 uint16_t uEthType = RT_N2H_U16(*(uint16_t*)(cpPacket+12)); 1278 if (uEthType == RTNET_ETHERTYPE_VLAN) 1279 { 1280 uEthType = RT_N2H_U16(*(uint16_t*)(cpPacket+16)); 1281 offset += 4; 1282 } 1283 if (uEthType == RTNET_ETHERTYPE_ARP) 1284 { 1285 Log4(("\tARP\n")); 1286 return; 1287 } 1288 else if (uEthType == RTNET_ETHERTYPE_IPV4) 1289 { 1290 PRTNETIPV4 pHdr = (PRTNETIPV4)(cpPacket + offset); 1291 offset += pHdr->ip_hl * 4; 1292 protocol = pHdr->ip_p; 1293 Log4(("\tIPv4: %RTnaipv4 => %RTnaipv4\n", pHdr->ip_src, pHdr->ip_dst)); 1294 } 1295 else if (uEthType == RTNET_ETHERTYPE_IPV6) 1296 { 1297 PRTNETIPV6 pHdr = (PRTNETIPV6)(cpPacket + offset); 1298 protocol = pHdr->ip6_nxt; 1299 offset += sizeof(RTNETIPV6); 1300 if (protocol == 0 || protocol == 60) 1301 { 1302 /* Skip hop-by-hop and destination options */ 1303 while (cpPacket[offset] == 0 || cpPacket[offset] == 60) 1304 offset += 8 * (1 + cpPacket[offset+1]); 1305 protocol = cpPacket[offset]; 1306 offset += 8 * (1 + cpPacket[offset+1]); 1307 } 1308 Log4(("\tIPv6: %RTnaipv6 => %RTnaipv6\n", pHdr->ip6_src, pHdr->ip6_dst)); 1309 } 1310 else 1311 { 1312 Log4(("\tEthernet: 0x%04x\n", uEthType)); 1313 return; 1314 } 1315 switch (protocol) 1316 { 1317 case 1: Log4(("\tICMP\n")); break; 1318 case 2: Log4(("\tIGMP\n")); break; 1319 case 58: Log4(("\tICMPv6\n")); break; 1320 1321 case 6: 1322 { 1323 PRTNETTCP pTcp = (PRTNETTCP)(cpPacket + offset); 1324 Log4(("\tTCP: %u => %u, seq=%u ack=%u\n", RT_N2H_U16(pTcp->th_sport), RT_N2H_U16(pTcp->th_dport), 1325 RT_N2H_U32(pTcp->th_seq), RT_N2H_U32(pTcp->th_ack))); 1326 } 1327 break; 1328 case 17: 1329 { 1330 PRTNETUDP pUdp = (PRTNETUDP)(cpPacket + offset); 1331 Log4(("\tUDP: %u => %u\n", RT_N2H_U16(pUdp->uh_sport), RT_N2H_U16(pUdp->uh_dport))); 1332 } 1333 break; 1334 default: 1335 Log4(("\tUnknown (%u)", protocol)); 1336 break; 1337 } 1338 } 1339 1340 DECLINLINE(void) usbNetPacketDump(PUSBNET pThis, const void *pvBuf, size_t cb, const char *pcszText) 1341 { 1342 const uint8_t *cpPacket = (const uint8_t *)pvBuf; 1343 if (cb < 14) 1344 Log3(("/#%u/ %s packet #%d is too small (%u bytes):\n%.*Rhxd\n", 1345 pThis->pUsbIns->iInstance, pcszText, ++pThis->u32PktNo, (uint32_t)cb, (uint32_t)cb, cpPacket)); 1346 else 1347 { 1348 Log3(("/#%u/ %s packet #%d, %u bytes, %RTmac => %RTmac\n", 1349 pThis->pUsbIns->iInstance, pcszText, ++pThis->u32PktNo, (uint32_t)cb, cpPacket+6, cpPacket)); 1350 if (LogIs4Enabled()) 1351 usbNetProtocolDump(cpPacket, (uint32_t)cb); 1352 Log5(("%.*Rhxd\n", (uint32_t)cb, cpPacket)); 1353 } 1354 } 1355 1356 #else 1357 #define usbNetPacketDump(pUsbIns, pvBuf, cb, pcszText) 1358 #endif 1269 1359 1270 1360 /** … … 1309 1399 return VINF_SUCCESS; 1310 1400 } 1401 1402 usbNetPacketDump(pThis, pvBuf, cb, "<-- Rx"); 1311 1403 1312 1404 PUSBNCMNTH16 pNth16 = (PUSBNCMNTH16)&pUrb->abData[0]; … … 1468 1560 1469 1561 if (pUrb) 1470 Log Func(("/#%u/ pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc));1562 Log2Func(("/#%u/ pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc)); 1471 1563 return pUrb; 1472 1564 } … … 1525 1617 if (pUrb->cbData < sizeof(*pNth16)) 1526 1618 { 1527 Log (("UsbNet: Bad NTH16: cbData=%#x < min=%#x\n", pUrb->cbData, sizeof(*pNth16) ));1619 LogFunc(("/#%u/ Bad NTH16: cbData=%#x < min=%#x\n", pThis->pUsbIns->iInstance, pUrb->cbData, sizeof(*pNth16) )); 1528 1620 return usbNetCompleteStall(pThis, NULL, pUrb, "BAD NTH16"); 1529 1621 } 1530 1622 if (pNth16->dwSignature != USBNCMNTH16_SIGNATURE) 1531 1623 { 1532 Log (("UsbNet:NTH16: Invalid dwSignature value: %#x\n", pNth16->dwSignature));1624 LogFunc(("/#%u/ NTH16: Invalid dwSignature value: %#x\n", pNth16->dwSignature)); 1533 1625 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16"); 1534 1626 } 1535 Log (("UsbNet: NTH16: wHeaderLength=%#x wSequence=%#x wBlockLength=%#x wNdpIndex=%#x cbData=%#x fShortNotOk=%RTbool\n",1536 pNth16->wHeaderLength, pNth16->wSequence, pNth16->wBlockLength, pNth16->wNdpIndex, pUrb->cbData, pUrb->fShortNotOk));1627 Log2Func(("/#%u/ NTH16: wHeaderLength=%#x wSequence=%#x wBlockLength=%#x wNdpIndex=%#x cbData=%#x fShortNotOk=%RTbool\n", pThis->pUsbIns->iInstance, 1628 pNth16->wHeaderLength, pNth16->wSequence, pNth16->wBlockLength, pNth16->wNdpIndex, pUrb->cbData, pUrb->fShortNotOk)); 1537 1629 if (pNth16->wHeaderLength != sizeof(*pNth16)) 1538 1630 { 1539 Log (("UsbNet: NTH16: Bad wHeaderLength value: %#x\n", pNth16->wHeaderLength));1631 LogFunc(("/#%u/ NTH16: Bad wHeaderLength value: %#x\n", pThis->pUsbIns->iInstance, pNth16->wHeaderLength)); 1540 1632 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16"); 1541 1633 … … 1543 1635 if (pNth16->wBlockLength > pUrb->cbData) 1544 1636 { 1545 Log (("UsbNet: NTH16: Bad wBlockLength value: %#x\n", pNth16->wBlockLength));1637 LogFunc(("/#%u/ NTH16: Bad wBlockLength value: %#x\n", pThis->pUsbIns->iInstance, pNth16->wBlockLength)); 1546 1638 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16"); 1547 1639 } … … 1549 1641 if (pNth16->wNdpIndex < sizeof(*pNth16)) 1550 1642 { 1551 Log (("UsbNet: NTH16: wNdpIndex is too small: %#x (%u), at least required %#x\n",1643 LogFunc(("/#%u/ NTH16: wNdpIndex is too small: %#x (%u), at least required %#x\n", pThis->pUsbIns->iInstance, 1552 1644 pNth16->wNdpIndex, pNth16->wNdpIndex, sizeof(*pNth16) )); 1553 1645 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16"); … … 1560 1652 if (offNdp16Next >= pUrb->cbData) 1561 1653 { 1562 Log (("UsbNet: Bad NDP16: offNdp16Next=%#x >= cbData=%#x\n", offNdp16Next, pUrb->cbData));1654 LogFunc(("/#%u/ Bad NDP16: offNdp16Next=%#x >= cbData=%#x\n", pThis->pUsbIns->iInstance, offNdp16Next, pUrb->cbData)); 1563 1655 return usbNetCompleteStall(pThis, NULL, pUrb, "BAD NDP16"); 1564 1656 } … … 1568 1660 if (cbNdpMax < sizeof(*pNdp16)) 1569 1661 { 1570 Log (("UsbNet: Bad NDP16: cbNdpMax=%#x < min=%#x\n", cbNdpMax, sizeof(*pNdp16) ));1662 LogFunc(("/#%u/ Bad NDP16: cbNdpMax=%#x < min=%#x\n", pThis->pUsbIns->iInstance, cbNdpMax, sizeof(*pNdp16) )); 1571 1663 return usbNetCompleteStall(pThis, NULL, pUrb, "BAD NDP16"); 1572 1664 } … … 1575 1667 && pNdp16->dwSignature != USBNCMNDP16_SIGNATURE_NCM1) 1576 1668 { 1577 Log (("UsbNet: NDP16: Invalid dwSignature value: %#x\n", pNdp16->dwSignature));1669 LogFunc(("/#%u/ NDP16: Invalid dwSignature value: %#x\n", pThis->pUsbIns->iInstance, pNdp16->dwSignature)); 1578 1670 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NDP16"); 1579 1671 } … … 1583 1675 || pNdp16->wLength > cbNdpMax) 1584 1676 { 1585 Log (("UsbNet: NDP16: Invalid size value: %#x, req. (min %#x max %#x)\n",1677 LogFunc(("/#%u/ NDP16: Invalid size value: %#x, req. (min %#x max %#x)\n", pThis->pUsbIns->iInstance, 1586 1678 pNdp16->wLength, sizeof(*pNdp16), cbNdpMax)); 1587 1679 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NDP16"); … … 1607 1699 || pDGram->wDatagramIndex >= pUrb->cbData) 1608 1700 { 1609 Log (("UsbNet: DGRAM16: Invalid wDatagramIndex value: %#x\n", pDGram->wDatagramIndex));1701 LogFunc(("/#%u/ DGRAM16: Invalid wDatagramIndex value: %#x\n", pThis->pUsbIns->iInstance, pDGram->wDatagramIndex)); 1610 1702 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad DGRAM16"); 1611 1703 } … … 1613 1705 if (pUrb->cbData - pDGram->wDatagramIndex < pDGram->wDatagramLength) 1614 1706 { 1615 Log (("UsbNet: DGRAM16: Invalid wDatagramLength value: %#x (max %#x)\n",1707 LogFunc(("/#%u/ DGRAM16: Invalid wDatagramLength value: %#x (max %#x)\n", pThis->pUsbIns->iInstance, 1616 1708 pDGram->wDatagramLength, pUrb->cbData - pDGram->wDatagramIndex)); 1617 1709 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad DGRAM16"); … … 1624 1716 uint8_t *pbBuf = pSgBuf ? (uint8_t *)pSgBuf->aSegs[0].pvSeg : NULL; 1625 1717 memcpy(pbBuf, &pUrb->abData[pDGram->wDatagramIndex], pDGram->wDatagramLength); 1718 usbNetPacketDump(pThis, pbBuf, pDGram->wDatagramLength, "--> Tx"); 1626 1719 pSgBuf->cbUsed = pDGram->wDatagramLength; 1627 1720 rc = pThis->Lun0.pINetwork->pfnSendBuf(pThis->Lun0.pINetwork, pSgBuf, true /* fOnWorkerThread */); … … 1640 1733 else 1641 1734 { 1642 Log (("UsbNet: NDP16: Not implemented\n"));1735 LogFunc(("/#%u/ NDP16: Not implemented\n", pThis->pUsbIns->iInstance)); 1643 1736 return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NDP16"); 1644 1737 } … … 1754 1847 if (pSetup->bmRequestType != (VUSB_TO_DEVICE | VUSB_REQ_STANDARD | VUSB_DIR_TO_HOST)) 1755 1848 { 1756 Log (("UsbNet: Bad GET_DESCRIPTOR req: bmRequestType=%#x\n", pSetup->bmRequestType));1849 LogFunc(("/#%u/ Bad GET_DESCRIPTOR req: bmRequestType=%#x\n", pThis->pUsbIns->iInstance, pSetup->bmRequestType)); 1757 1850 return usbNetCompleteStall(pThis, pEp, pUrb, "Bad GET_DESCRIPTOR"); 1758 1851 } … … 1763 1856 1764 1857 case VUSB_DT_STRING: 1765 Log (("UsbNet: GET_DESCRIPTOR DT_STRING wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));1858 LogFunc(("/#%u/ GET_DESCRIPTOR DT_STRING wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex)); 1766 1859 break; 1767 1860 case VUSB_DT_DEVICE_QUALIFIER: 1768 Log (("UsbNet: GET_DESCRIPTOR DT_DEVICE_QUALIFIER wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));1861 LogFunc(("/#%u/ GET_DESCRIPTOR DT_DEVICE_QUALIFIER wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex)); 1769 1862 /* Returned data is written after the setup message. */ 1770 1863 cbCopy = pUrb->cbData - sizeof(*pSetup); … … 1773 1866 return usbNetCompleteOk(pThis, pUrb, cbCopy + sizeof(*pSetup)); 1774 1867 case VUSB_DT_BOS: 1775 Log (("UsbNet: GET_DESCRIPTOR DT_BOS wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));1868 LogFunc(("/#%u/ GET_DESCRIPTOR DT_BOS wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex)); 1776 1869 /* Returned data is written after the setup message. */ 1777 1870 cbCopy = pUrb->cbData - sizeof(*pSetup); … … 1780 1873 return usbNetCompleteOk(pThis, pUrb, cbCopy + sizeof(*pSetup)); 1781 1874 default: 1782 Log (("UsbNet: GET_DESCRIPTOR, huh? wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));1875 LogFunc(("/#%u/ GET_DESCRIPTOR, huh? wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex)); 1783 1876 break; 1784 1877 } … … 1854 1947 1855 1948 /** @todo implement this. */ 1856 Log (("UsbNet: Implement standard request: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",1949 LogFunc(("/#%u/ Implement standard request: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n", pThis->pUsbIns->iInstance, 1857 1950 pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, pSetup->wIndex, pSetup->wLength)); 1858 1951 … … 1867 1960 if (pSetup->bmRequestType != (VUSB_TO_INTERFACE | VUSB_REQ_CLASS | VUSB_DIR_TO_HOST)) 1868 1961 { 1869 Log (("UsbNet: Bad GET_NTB_PARAMETERS req: bmRequestType=%#x\n", pSetup->bmRequestType));1962 LogFunc(("/#%u/ Bad GET_NTB_PARAMETERS req: bmRequestType=%#x\n", pThis->pUsbIns->iInstance, pSetup->bmRequestType)); 1870 1963 return usbNetCompleteStall(pThis, pEp, pUrb, "Bad GET_NTB_PARAMETERS"); 1871 1964 } … … 1900 1993 else 1901 1994 { 1902 Log (("UsbNet: Unknown control msg: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",1995 LogFunc(("/#%u/ Unknown control msg: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n", pThis->pUsbIns->iInstance, 1903 1996 pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, pSetup->wIndex, pSetup->wLength)); 1904 1997 return usbNetCompleteStall(pThis, pEp, pUrb, "Unknown control msg"); … … 2216 2309 LogFlowFunc(("/#%u/\n", iInstance)); 2217 2310 2311 pThis->u32PktNo = 1; 2218 2312 /* 2219 2313 * Perform the basic structure initialization first so the destructor
Note:
See TracChangeset
for help on using the changeset viewer.