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
;
16 IP_ADDRESS RemoteAddress
, LocalAddress
;
19 /* The caller frees the pbuf struct */
21 if (((*(u8_t
*)p
->payload
) & 0xF0) == 0x40)
25 LocalAddress
.Type
= IP_ADDRESS_V4
;
26 LocalAddress
.Address
.IPv4Address
= Header
->SrcAddr
;
28 RemoteAddress
.Type
= IP_ADDRESS_V4
;
29 RemoteAddress
.Address
.IPv4Address
= Header
->DstAddr
;
36 IPInitializePacket(&Packet
, LocalAddress
.Type
);
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
.TotalSize
);
50 Packet
.MappedHeader
= TRUE
;
52 if (p
->tot_len
!= p
->len
||
53 Packet
.TotalSize
!= p
->len
)
55 TI_DbgPrint(MIN_TRACE
,
56 ("TCPSendDataCallback tot_len = %u, len = %u, TotalSize = %u\n",
57 p
->tot_len
, p
->len
, Packet
.TotalSize
));
58 ASSERT(p
->tot_len
== p
->len
);
59 ASSERT(Packet
.TotalSize
== p
->len
);
62 RtlCopyMemory(Packet
.Header
, p
->payload
, p
->len
);
64 Packet
.HeaderSize
= sizeof(IPv4_HEADER
);
65 Packet
.TotalSize
= p
->tot_len
;
66 Packet
.SrcAddr
= LocalAddress
;
67 Packet
.DstAddr
= RemoteAddress
;
69 NdisStatus
= IPSendDatagram(&Packet
, NCE
);
70 if (!NT_SUCCESS(NdisStatus
))
77 TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF
)
80 ULONG OperationalStatus
;
82 GetInterfaceConnectionStatus(IF
, &OperationalStatus
);
84 if (OperationalStatus
== MIB_IF_OPER_STATUS_OPERATIONAL
)
85 netif_set_link_up(IF
->TCPContext
);
87 netif_set_link_down(IF
->TCPContext
);
92 TCPInterfaceInit(struct netif
*netif
)
94 PIP_INTERFACE IF
= netif
->state
;
96 netif
->hwaddr_len
= IF
->AddressLength
;
97 RtlCopyMemory(netif
->hwaddr
, IF
->Address
, netif
->hwaddr_len
);
99 netif
->output
= TCPSendDataCallback
;
100 netif
->mtu
= IF
->MTU
;
102 netif
->name
[0] = 'e';
103 netif
->name
[1] = 'n';
105 netif
->flags
|= NETIF_FLAG_BROADCAST
;
107 TCPUpdateInterfaceLinkStatus(IF
);
109 TCPUpdateInterfaceIPInformation(IF
);
115 TCPRegisterInterface(PIP_INTERFACE IF
)
117 struct ip_addr ipaddr
;
118 struct ip_addr netmask
;
125 IF
->TCPContext
= netif_add(IF
->TCPContext
,
135 TCPUnregisterInterface(PIP_INTERFACE IF
)
137 netif_remove(IF
->TCPContext
);
141 TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF
)
143 struct ip_addr ipaddr
;
144 struct ip_addr netmask
;
149 GetInterfaceIPv4Address(IF
,
151 (PULONG
)&ipaddr
.addr
);
153 GetInterfaceIPv4Address(IF
,
155 (PULONG
)&netmask
.addr
);
157 netif_set_addr(IF
->TCPContext
, &ipaddr
, &netmask
, &gw
);
159 if (ipaddr
.addr
!= 0)
161 netif_set_up(IF
->TCPContext
);
162 netif_set_default(IF
->TCPContext
);
166 netif_set_down(IF
->TCPContext
);