Author: jgardou
Date: Wed Nov 12 11:38:53 2014
New Revision: 65384
URL:
http://svn.reactos.org/svn/reactos?rev=65384&view=rev
Log:
[TCPIP]
- Implement sending data to the NIC from what lwip passes to us.
Modified:
branches/tcpip_revolution/drivers/network/tcpip/interface.h
branches/tcpip_revolution/drivers/network/tcpip/ndis_lwip.c
Modified: branches/tcpip_revolution/drivers/network/tcpip/interface.h
URL:
http://svn.reactos.org/svn/reactos/branches/tcpip_revolution/drivers/networ…
==============================================================================
--- branches/tcpip_revolution/drivers/network/tcpip/interface.h [iso-8859-1] (original)
+++ branches/tcpip_revolution/drivers/network/tcpip/interface.h [iso-8859-1] Wed Nov 12
11:38:53 2014
@@ -2,6 +2,9 @@
#pragma once
#define TAG_INTERFACE 'fIpI'
+
+#define TCPIP_PACKETPOOL_SIZE 200
+#define TCPIP_BUFFERPOOL_SIZE 800
typedef struct
{
@@ -11,6 +14,8 @@
TCPIP_INSTANCE ClNlInstance;
UNICODE_STRING DeviceName;
NDIS_HANDLE NdisContext;
+ NDIS_HANDLE PacketPool;
+ NDIS_HANDLE BufferPool;
UINT MediumIndex;
ULONG Speed;
} TCPIP_INTERFACE;
Modified: branches/tcpip_revolution/drivers/network/tcpip/ndis_lwip.c
URL:
http://svn.reactos.org/svn/reactos/branches/tcpip_revolution/drivers/networ…
==============================================================================
--- branches/tcpip_revolution/drivers/network/tcpip/ndis_lwip.c [iso-8859-1] (original)
+++ branches/tcpip_revolution/drivers/network/tcpip/ndis_lwip.c [iso-8859-1] Wed Nov 12
11:38:53 2014
@@ -24,7 +24,7 @@
{
NDIS_STATUS Status;
NDIS_REQUEST Request;
- UINT MTU;
+ UINT MTU, Speed;
NDIS_OID QueryAddrOid;
UINT PacketFilter;
@@ -76,17 +76,20 @@
/* Get the link speed */
Request.RequestType = NdisRequestQueryInformation;
Request.DATA.QUERY_INFORMATION.Oid = OID_GEN_LINK_SPEED;
- Request.DATA.QUERY_INFORMATION.InformationBuffer = &Interface->Speed;
- Request.DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(ULONG);
+ Request.DATA.QUERY_INFORMATION.InformationBuffer = &Speed;
+ Request.DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(UINT);
NdisRequest(&Status, Interface->NdisContext, &Request);
if (!NT_SUCCESS(Status))
{
DPRINT1("Could not get link speed NIC driver!\n");
/* Good old 10Mb/s as default */
- Interface->Speed = 100000;
+ Speed = 100000;
}
/* NDIS drivers give it in 100bps unit */
- Interface->Speed *= 100;
+ Speed *= 100;
+
+ /* Initialize lwip SNMP module */
+ NETIF_INIT_SNMP(&Interface->lwip_netif, snmp_ifType_ethernet_csmacd, Speed);
/* Set the packet filter */
Request.RequestType = NdisRequestSetInformation;
@@ -100,6 +103,22 @@
return Status;
}
+ /* Initialize the packet pool */
+ NdisAllocatePacketPool(&Status, &Interface->PacketPool,
TCPIP_PACKETPOOL_SIZE, 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Could not allocate a packet pool.\n");
+ return Status;
+ }
+
+ /* Initialize the buffer pool */
+ NdisAllocateBufferPool(&Status, &Interface->BufferPool,
TCPIP_BUFFERPOOL_SIZE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Could not allocate a buffer pool.\n");
+ return Status;
+ }
+
return NDIS_STATUS_SUCCESS;
}
@@ -160,6 +179,22 @@
}
static
+NDIS_STATUS
+NTAPI
+ProtocolReceive(
+ _In_ NDIS_HANDLE ProtocolBindingContext,
+ _In_ NDIS_HANDLE MacReceiveContext,
+ _In_ PVOID HeaderBuffer,
+ _In_ UINT HeaderBufferSize,
+ _In_ PVOID LookAheadBuffer,
+ _In_ UINT LookaheadBufferSize,
+ _In_ UINT PacketSize)
+{
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+static
VOID
NTAPI
ProtocolReceiveComplete(
@@ -175,6 +210,17 @@
_In_ NDIS_HANDLE ProtocolBindingContext)
{
UNIMPLEMENTED
+}
+
+static
+INT
+NTAPI
+ProtocolReceivePacket(
+ _In_ NDIS_HANDLE ProtocolBindingContext,
+ _In_ PNDIS_PACKET Packet)
+{
+ UNIMPLEMENTED
+ return 0;
}
/* bridge between NDIS and lwip: send data to the adapter */
@@ -184,7 +230,80 @@
struct netif *netif,
struct pbuf *p)
{
- UNIMPLEMENTED
+ TCPIP_INTERFACE* Interface = CONTAINING_RECORD(netif, TCPIP_INTERFACE, lwip_netif);
+ NDIS_STATUS Status;
+ PNDIS_PACKET Packet;
+ PNDIS_BUFFER Buffer;
+ PVOID PayloadCopy = NULL;
+
+ NT_ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
+
+ /* Allocate a packet */
+ NdisAllocatePacket(&Status, &Packet, Interface->PacketPool);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Could not allocate a packet from packet pool!\n");
+ return ERR_MEM;
+ }
+
+ /* Map pbuf to a NDIS buffer chain, if possible (== allocated from non paged pool).
*/
+ if ((p->type == PBUF_POOL) || (p->type == PBUF_RAM))
+ {
+ while (p)
+ {
+ NdisAllocateBuffer(&Status, &Buffer, Interface->BufferPool,
p->payload, p->len);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Could not allocate a buffer!\n");
+ return ERR_MEM;
+ }
+ NdisChainBufferAtBack(Packet, Buffer);
+ p = p->next;
+ if (p)
+ {
+ DPRINT1("More than one buffer in the chain!\n");
+ }
+ }
+ }
+ else
+ {
+ PayloadCopy = ExAllocatePoolWithTag(NonPagedPool, p->tot_len, TAG_INTERFACE);
+ if (!PayloadCopy)
+ {
+ NdisFreePacket(Packet);
+ return ERR_MEM;
+ }
+ pbuf_copy_partial(p, PayloadCopy, p->tot_len, 0);
+ NdisAllocateBuffer(&Status, &Buffer, Interface->BufferPool,
p->payload, p->len);
+ NdisChainBufferAtFront(Packet, Buffer);
+ }
+
+ /* Call ndis */
+ NdisSend(&Status, Interface->NdisContext, Packet);
+
+ DPRINT1("NdisSend: got status 0x%08x.\n", Status);
+
+ /* Free the buffer chain */
+ if (Status != NDIS_STATUS_PENDING)
+ {
+ NdisUnchainBufferAtFront(Packet, &Buffer);
+ while (Buffer)
+ {
+ NdisFreeBuffer(Buffer);
+ NdisUnchainBufferAtFront(Packet, &Buffer);
+ }
+ NdisFreePacket(Packet);
+
+ if (PayloadCopy)
+ ExFreePoolWithTag(PayloadCopy, TAG_INTERFACE);
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NdisSend returned status 0x%08x.\n", Status);
+ return ERR_CONN;
+ }
+
return ERR_OK;
}
@@ -319,8 +438,10 @@
ProtocolCharacteristics.CloseAdapterCompleteHandler = ProtocolCloseAdapterComplete;
ProtocolCharacteristics.ResetCompleteHandler = ProtocolResetComplete;
ProtocolCharacteristics.RequestCompleteHandler = ProtocolRequestComplete;
+ ProtocolCharacteristics.ReceiveHandler = ProtocolReceive;
ProtocolCharacteristics.ReceiveCompleteHandler = ProtocolReceiveComplete;
ProtocolCharacteristics.StatusCompleteHandler = ProtocolStatusComplete;
+ ProtocolCharacteristics.ReceivePacketHandler = ProtocolReceivePacket;
ProtocolCharacteristics.BindAdapterHandler = ProtocolBindAdapter;
ProtocolCharacteristics.UnbindAdapterHandler = ProtocolUnbindAdapter;
RtlInitUnicodeString(&ProtocolCharacteristics.Name, L"TcpIp");