win-pvdrivers

changeset 109:f45e6538a5e2

Merged with head.
Beginnings of support for driver checksumming of received packets
author James Harper <james.harper@bendigoit.com.au>
date Fri Jan 11 20:58:56 2008 +1100 (2008-01-11)
parents fb19fc778b9d
children ae2b8983f881
files xennet/sources xennet/xennet.c
line diff
     1.1 --- a/xennet/sources	Thu Jan 10 20:45:16 2008 -0800
     1.2 +++ b/xennet/sources	Fri Jan 11 20:58:56 2008 +1100
     1.3 @@ -1,7 +1,7 @@
     1.4  TARGETNAME=XENNET
     1.5  TARGETTYPE=DRIVER
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7 -VERSION=0.5.0.66
     1.8 +VERSION=0.5.0.69
     1.9  KMDF_VERSION=1
    1.10  MSC_WARNING_LEVEL=/W4
    1.11  INF_NAME=xennet
     2.1 --- a/xennet/xennet.c	Thu Jan 10 20:45:16 2008 -0800
     2.2 +++ b/xennet/xennet.c	Fri Jan 11 20:58:56 2008 +1100
     2.3 @@ -379,6 +379,88 @@ XenNet_RxBufferFree(struct xennet_info *
     2.4    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
     2.5  }
     2.6  
     2.7 +static VOID
     2.8 +XenNet_ProcessReceivedTcpPacket(PNDIS_PACKET packet, PUCHAR buf, ULONG len)
     2.9 +{
    2.10 +  USHORT checksum = (buf[28] << 8) | buf[29];
    2.11 +}
    2.12 +
    2.13 +static VOID
    2.14 +XenNet_ProcessReceivedIpPacket(PNDIS_PACKET packet, PUCHAR buf, ULONG len)
    2.15 +{
    2.16 +  UCHAR version;
    2.17 +  UCHAR header_len;
    2.18 +  UCHAR proto;
    2.19 +  USHORT total_len;
    2.20 +
    2.21 +  if (len < 20)
    2.22 +  {
    2.23 +    KdPrint((__DRIVER_NAME "     IP packet too small\n"));
    2.24 +    return;
    2.25 +  }
    2.26 +  version = buf[0] >> 4;
    2.27 +  if (version != 4)
    2.28 +  {
    2.29 +    KdPrint((__DRIVER_NAME "     IP version not IPv4 (version = %d)\n", version));
    2.30 +    return;
    2.31 +  }
    2.32 +
    2.33 +  header_len = (buf[0] & 15) * 4;
    2.34 +  total_len = (buf[2] << 8) | buf[3];
    2.35 +
    2.36 +  if (total_len != len)
    2.37 +  {
    2.38 +    KdPrint((__DRIVER_NAME "     IP packet probably fragmented.\n"));
    2.39 +    return;
    2.40 +  }
    2.41 +
    2.42 +  // todo: check header checksum & fix if wrong
    2.43 +
    2.44 +  proto = buf[9];
    2.45 +
    2.46 +  switch (proto)
    2.47 +  {
    2.48 +  case 0x06: //tcp
    2.49 +    KdPrint((__DRIVER_NAME "     IP Proto = TCP\n"));
    2.50 +    XenNet_ProcessReceivedTcpPacket(packet, buf + header_len, len - header_len);
    2.51 +    break;
    2.52 +  case 0x17: //udp
    2.53 +    KdPrint((__DRIVER_NAME "     IP Proto = UDP\n"));
    2.54 +    break;
    2.55 +  default:
    2.56 +    KdPrint((__DRIVER_NAME "     IP Proto = %d\n", proto));
    2.57 +    break;
    2.58 +  }
    2.59 +}
    2.60 +
    2.61 +static VOID
    2.62 +XenNet_ProcessReceivedEthernetPacket(PNDIS_PACKET packet, PUCHAR buf, ULONG len)
    2.63 +{
    2.64 +  USHORT ethertype = (buf[12]) << 8 | buf[13];
    2.65 +
    2.66 +  if (len < 14)
    2.67 +  {
    2.68 +    KdPrint((__DRIVER_NAME "     Ethernet packet header too small.\n"));
    2.69 +    return;
    2.70 +  }
    2.71 +  switch (ethertype)
    2.72 +  {
    2.73 +  case 0x0800:
    2.74 +    KdPrint((__DRIVER_NAME "     EtherType = IP\n"));
    2.75 +    XenNet_ProcessReceivedIpPacket(packet, buf + 14, len - 14);
    2.76 +    break;
    2.77 +  case 0x0806:
    2.78 +    KdPrint((__DRIVER_NAME "     EtherType = ARP\n"));
    2.79 +    break;
    2.80 +  case 0x8100:
    2.81 +    KdPrint((__DRIVER_NAME "     EtherType = VLAN\n"));
    2.82 +    break;
    2.83 +  default:
    2.84 +    KdPrint((__DRIVER_NAME "     EtherType = %04x\n", ethertype));
    2.85 +    break;
    2.86 +  }
    2.87 +}
    2.88 +
    2.89  // Called at DISPATCH_LEVEL
    2.90  static NDIS_STATUS
    2.91  XenNet_RxBufferCheck(struct xennet_info *xi)
    2.92 @@ -432,13 +514,14 @@ XenNet_RxBufferCheck(struct xennet_info 
    2.93          (rxrsp->flags&NETRXF_more_data)?"":"!",
    2.94          (rxrsp->flags&NETRXF_extra_info)?"":"!"));
    2.95  #endif
    2.96 +      XenNet_ProcessReceivedEthernetPacket(packet, buff_va, rxrsp->status);
    2.97  
    2.98        if (NDIS_GET_PACKET_PROTOCOL_TYPE(packet) == NDIS_PROTOCOL_ID_TCP_IP
    2.99          && (rxrsp->flags & (NETRXF_csum_blank|NETRXF_data_validated)))
   2.100        {
   2.101          csum_info = (PNDIS_TCP_IP_CHECKSUM_PACKET_INFO)&NDIS_PER_PACKET_INFO_FROM_PACKET(packet, TcpIpChecksumPacketInfo);
   2.102          csum_info->Receive.NdisPacketTcpChecksumSucceeded = 1;
   2.103 -        csum_info->Receive.NdisPacketUdpChecksumSucceeded = 0;
   2.104 +        csum_info->Receive.NdisPacketUdpChecksumSucceeded = 1;
   2.105          csum_info->Receive.NdisPacketIpChecksumSucceeded = 1;
   2.106  //        KdPrint((__DRIVER_NAME "     Offload = %08x\n", NDIS_PER_PACKET_INFO_FROM_PACKET(packet, TcpIpChecksumPacketInfo)));
   2.107        }