ReactOS 0.4.16-dev-258-g81860b4
if.c File Reference
#include "precomp.h"
#include "lwip/pbuf.h"
#include "lwip/netifapi.h"
#include "lwip/ip.h"
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include <ipifcons.h>
Include dependency graph for if.c:

Go to the source code of this file.

Functions

err_t TCPSendDataCallback (struct netif *netif, struct pbuf *p, const ip4_addr_t *dest)
 
VOID TCPUpdateInterfaceLinkStatus (PIP_INTERFACE IF)
 
err_t TCPInterfaceInit (struct netif *netif)
 
VOID TCPRegisterInterface (PIP_INTERFACE IF)
 
VOID TCPUnregisterInterface (PIP_INTERFACE IF)
 
VOID TCPUpdateInterfaceIPInformation (PIP_INTERFACE IF)
 

Function Documentation

◆ TCPInterfaceInit()

err_t TCPInterfaceInit ( struct netif netif)

Definition at line 95 of file if.c.

96{
98
101
102 netif->output = TCPSendDataCallback;
103 netif->mtu = IF->MTU;
104
105 netif->name[0] = 'e';
106 netif->name[1] = 'n';
107
109
111
113
114 return 0;
115}
err_t TCPSendDataCallback(struct netif *netif, struct pbuf *p, const ip4_addr_t *dest)
Definition: if.c:12
VOID TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF)
Definition: if.c:144
VOID TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF)
Definition: if.c:82
#define NETIF_FLAG_BROADCAST
Definition: netif.h:87
PUCHAR Address
Definition: ip.h:165
UINT AddressLength
Definition: ip.h:166
UINT MTU
Definition: ip.h:157
Definition: netif.h:269
u8_t flags
Definition: netif.h:354
char name[2]
Definition: netif.h:356
void * state
Definition: netif.h:332
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:350
u16_t mtu
Definition: netif.h:344
u8_t hwaddr_len
Definition: netif.h:352
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by TCPRegisterInterface().

◆ TCPRegisterInterface()

VOID TCPRegisterInterface ( PIP_INTERFACE  IF)

Definition at line 118 of file if.c.

119{
120 ip_addr_t ipaddr;
121 ip_addr_t netmask;
122 ip_addr_t gw;
123
124 gw.addr = 0;
125 ipaddr.addr = 0;
126 netmask.addr = 0;
127
129 &ipaddr,
130 &netmask,
131 &gw,
132 IF,
135}
err_t TCPInterfaceInit(struct netif *netif)
Definition: if.c:95
err_t tcpip_input(struct pbuf *p, struct netif *inp)
Definition: tcpip.c:288
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:287
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
PVOID TCPContext
Definition: ip.h:169

Referenced by IPCreateInterface().

◆ TCPSendDataCallback()

err_t TCPSendDataCallback ( struct netif netif,
struct pbuf p,
const ip4_addr_t *  dest 
)

Definition at line 12 of file if.c.

13{
14 NDIS_STATUS NdisStatus;
21
22 /* The caller frees the pbuf struct */
23
24 if (((*(u8_t*)p->payload) & 0xF0) == 0x40)
25 {
26 Header = p->payload;
27
29 LocalAddress.Address.IPv4Address = Header->SrcAddr;
30
32 RemoteAddress.Address.IPv4Address = Header->DstAddr;
33 }
34 else
35 {
36 return ERR_IF;
37 }
38
40
42 {
43 return ERR_RTE;
44 }
45
46 NdisStatus = AllocatePacketWithBuffer(&Packet.NdisPacket, NULL, p->tot_len);
47 if (NdisStatus != NDIS_STATUS_SUCCESS)
48 {
49 return ERR_MEM;
50 }
51
52 GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.TotalSize);
53 Packet.MappedHeader = TRUE;
54
55 ASSERT(Packet.TotalSize == p->tot_len);
56
57 TotalLength = p->tot_len;
58 Length = 0;
59 while (Length < TotalLength)
60 {
61 ASSERT(p->len <= TotalLength - Length);
62 ASSERT(p->tot_len == TotalLength - Length);
63 RtlCopyMemory((PCHAR)Packet.Header + Length, p->payload, p->len);
64 Length += p->len;
65 p = p->next;
66 }
68
69 Packet.HeaderSize = sizeof(IPv4_HEADER);
70 Packet.TotalSize = TotalLength;
71 Packet.SrcAddr = LocalAddress;
72 Packet.DstAddr = RemoteAddress;
73
74 NdisStatus = IPSendDatagram(&Packet, NCE);
75 if (!NT_SUCCESS(NdisStatus))
76 return ERR_RTE;
77
78 return 0;
79}
Definition: Header.h:9
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define IP_ADDRESS_V4
Definition: ip.h:32
PIP_PACKET IPInitializePacket(PIP_PACKET IPPacket, ULONG Type)
Definition: ip.c:92
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
#define ERR_MEM
Definition: fontsub.h:52
GLfloat GLfloat p
Definition: glext.h:8902
uint8_t u8_t
Definition: arch.h:125
@ ERR_IF
Definition: err.h:79
@ ERR_RTE
Definition: err.h:63
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
#define ASSERT(a)
Definition: mode.c:44
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
int NDIS_STATUS
Definition: ntddndis.h:475
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
Definition: ip.h:23
Definition: neighbor.h:28
Definition: ip.h:77
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_In_ ULONG TotalLength
Definition: usbdlib.h:158
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:171
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:172

Referenced by TCPInterfaceInit().

◆ TCPUnregisterInterface()

VOID TCPUnregisterInterface ( PIP_INTERFACE  IF)

Definition at line 138 of file if.c.

139{
141}
void netif_remove(struct netif *netif)
Definition: netif.c:764

Referenced by IPDestroyInterface().

◆ TCPUpdateInterfaceIPInformation()

VOID TCPUpdateInterfaceIPInformation ( PIP_INTERFACE  IF)

Definition at line 144 of file if.c.

145{
146 ip_addr_t ipaddr;
147 ip_addr_t netmask;
148 ip_addr_t gw;
149
150 gw.addr = 0;
151
154 (PULONG)&ipaddr.addr);
155
158 (PULONG)&netmask.addr);
159
160 netif_set_addr(IF->TCPContext, &ipaddr, &netmask, &gw);
161
162 if (ipaddr.addr != 0)
163 {
166 }
167 else
168 {
170 }
171}
#define ADE_UNICAST
Definition: ip.h:110
#define ADE_ADDRMASK
Definition: ip.h:112
void netif_set_down(struct netif *netif)
Definition: netif.c:949
void netif_set_default(struct netif *netif)
Definition: netif.c:849
void netif_set_up(struct netif *netif)
Definition: netif.c:871
NTSTATUS GetInterfaceIPv4Address(PIP_INTERFACE Interface, ULONG Type, PULONG Address)
Definition: interface.c:19
uint32_t * PULONG
Definition: typedefs.h:59

Referenced by IPAddInterfaceRoute(), ReconfigureAdapter(), and TCPInterfaceInit().

◆ TCPUpdateInterfaceLinkStatus()

VOID TCPUpdateInterfaceLinkStatus ( PIP_INTERFACE  IF)

Definition at line 82 of file if.c.

83{
84 ULONG OperationalStatus;
85
86 GetInterfaceConnectionStatus(IF, &OperationalStatus);
87
88 if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
90 else
92}
void netif_set_link_down(struct netif *netif)
Definition: netif.c:1056
void netif_set_link_up(struct netif *netif)
Definition: netif.c:1018
#define MIB_IF_OPER_STATUS_OPERATIONAL
Definition: ipifcons.h:251
VOID GetInterfaceConnectionStatus(PIP_INTERFACE Interface, PULONG OperStatus)
Definition: interface.c:254

Referenced by ReconfigureAdapter(), and TCPInterfaceInit().