5 #include "lwip/netifapi.h"
8 #include "lwip/tcpip.h"
11 TCPSendDataCallback(struct netif
*netif
, struct pbuf
*p
, struct ip_addr
*dest
)
13 NDIS_STATUS NdisStatus
;
14 PNEIGHBOR_CACHE_ENTRY NCE
;
15 IP_PACKET Packet
= { 0 };
16 IP_ADDRESS RemoteAddress
, LocalAddress
;
21 /* The caller frees the pbuf struct */
23 if (((*(u8_t
*)p
->payload
) & 0xF0) == 0x40)
27 LocalAddress
.Type
= IP_ADDRESS_V4
;
28 LocalAddress
.Address
.IPv4Address
= Header
->SrcAddr
;
30 RemoteAddress
.Type
= IP_ADDRESS_V4
;
31 RemoteAddress
.Address
.IPv4Address
= Header
->DstAddr
;
38 if (!(NCE
= RouteGetRouteToDestination(&RemoteAddress
)))
43 NdisStatus
= AllocatePacketWithBuffer(&Packet
.NdisPacket
, NULL
, p
->tot_len
);
44 if (NdisStatus
!= NDIS_STATUS_SUCCESS
)
49 GetDataPtr(Packet
.NdisPacket
, 0, (PCHAR
*)&Packet
.Header
, &Packet
.ContigSize
);
51 for (i
= 0, p1
= p
; i
< p
->tot_len
; i
+= p1
->len
, p1
= p1
->next
)
54 RtlCopyMemory(((PUCHAR
)Packet
.Header
) + i
, p1
->payload
, p1
->len
);
57 Packet
.HeaderSize
= sizeof(IPv4_HEADER
);
58 Packet
.TotalSize
= p
->tot_len
;
59 Packet
.SrcAddr
= LocalAddress
;
60 Packet
.DstAddr
= RemoteAddress
;
62 NdisStatus
= IPSendDatagram(&Packet
, NCE
);
63 FreeNdisPacket(Packet
.NdisPacket
);
64 if (!NT_SUCCESS(NdisStatus
))
73 TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF
)
76 ULONG OperationalStatus
;
78 GetInterfaceConnectionStatus(IF
, &OperationalStatus
);
80 if (OperationalStatus
== MIB_IF_OPER_STATUS_OPERATIONAL
)
81 netif_set_link_up(IF
->TCPContext
);
83 netif_set_link_down(IF
->TCPContext
);
88 TCPInterfaceInit(struct netif
*netif
)
90 PIP_INTERFACE IF
= netif
->state
;
92 netif
->hwaddr_len
= IF
->AddressLength
;
93 RtlCopyMemory(netif
->hwaddr
, IF
->Address
, netif
->hwaddr_len
);
95 netif
->output
= TCPSendDataCallback
;
101 netif
->flags
|= NETIF_FLAG_BROADCAST
;
103 TCPUpdateInterfaceLinkStatus(IF
);
105 TCPUpdateInterfaceIPInformation(IF
);
111 TCPRegisterInterface(PIP_INTERFACE IF
)
113 struct ip_addr ipaddr
;
114 struct ip_addr netmask
;
121 IF
->TCPContext
= netif_add(IF
->TCPContext
,
131 TCPUnregisterInterface(PIP_INTERFACE IF
)
133 netif_remove(IF
->TCPContext
);
137 TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF
)
139 struct ip_addr ipaddr
;
140 struct ip_addr netmask
;
145 GetInterfaceIPv4Address(IF
,
147 (PULONG
)&ipaddr
.addr
);
149 GetInterfaceIPv4Address(IF
,
151 (PULONG
)&netmask
.addr
);
153 netif_set_addr(IF
->TCPContext
, &ipaddr
, &netmask
, &gw
);
155 if (ipaddr
.addr
!= 0)
157 netif_set_up(IF
->TCPContext
);
158 netif_set_default(IF
->TCPContext
);
162 netif_set_down(IF
->TCPContext
);