ReactOS  0.4.14-dev-1252-g782ff23
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 dependency graph for if.c:

Go to the source code of this file.

Functions

err_t TCPSendDataCallback (struct netif *netif, struct pbuf *p, struct ip_addr *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 96 of file if.c.

97 {
99 
102 
104  netif->mtu = IF->MTU;
105 
106  netif->name[0] = 'e';
107  netif->name[1] = 'n';
108 
110 
112 
114 
115  return 0;
116 }
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:190
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF)
Definition: if.c:145
VOID TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF)
Definition: if.c:81
netif_output_fn output
Definition: netif.h:151
UINT AddressLength
Definition: ip.h:166
u8_t hwaddr_len
Definition: netif.h:188
err_t TCPSendDataCallback(struct netif *netif, struct pbuf *p, struct ip_addr *dest)
Definition: if.c:11
UINT MTU
Definition: ip.h:157
PUCHAR Address
Definition: ip.h:165
u8_t flags
Definition: netif.h:192
#define NETIF_FLAG_BROADCAST
Definition: netif.h:72
Definition: netif.h:136
u16_t mtu
Definition: netif.h:186
void * state
Definition: netif.h:172
char name[2]
Definition: netif.h:194

Referenced by TCPRegisterInterface().

◆ TCPRegisterInterface()

VOID TCPRegisterInterface ( PIP_INTERFACE  IF)

Definition at line 119 of file if.c.

120 {
121  struct ip_addr ipaddr;
122  struct ip_addr netmask;
123  struct ip_addr gw;
124 
125  gw.addr = 0;
126  ipaddr.addr = 0;
127  netmask.addr = 0;
128 
129  IF->TCPContext = netif_add(IF->TCPContext,
130  &ipaddr,
131  &netmask,
132  &gw,
133  IF,
135  tcpip_input);
136 }
PVOID TCPContext
Definition: ip.h:169
struct netif * netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:139
err_t tcpip_input(struct pbuf *p, struct netif *inp)
Definition: tcpip.c:162
err_t TCPInterfaceInit(struct netif *netif)
Definition: if.c:96
u32_t addr
Definition: ip_addr.h:45

Referenced by IPCreateInterface().

◆ TCPSendDataCallback()

err_t TCPSendDataCallback ( struct netif netif,
struct pbuf p,
struct ip_addr dest 
)

Definition at line 11 of file if.c.

12 {
13  NDIS_STATUS NdisStatus;
18  ULONG Length;
20 
21  /* The caller frees the pbuf struct */
22 
23  if (((*(u8_t*)p->payload) & 0xF0) == 0x40)
24  {
25  Header = p->payload;
26 
28  LocalAddress.Address.IPv4Address = Header->SrcAddr;
29 
31  RemoteAddress.Address.IPv4Address = Header->DstAddr;
32  }
33  else
34  {
35  return ERR_IF;
36  }
37 
39 
41  {
42  return ERR_RTE;
43  }
44 
45  NdisStatus = AllocatePacketWithBuffer(&Packet.NdisPacket, NULL, p->tot_len);
46  if (NdisStatus != NDIS_STATUS_SUCCESS)
47  {
48  return ERR_MEM;
49  }
50 
51  GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.TotalSize);
52  Packet.MappedHeader = TRUE;
53 
54  ASSERT(Packet.TotalSize == p->tot_len);
55 
56  TotalLength = p->tot_len;
57  Length = 0;
58  while (Length < TotalLength)
59  {
60  ASSERT(p->len <= TotalLength - Length);
61  ASSERT(p->tot_len == TotalLength - Length);
62  RtlCopyMemory((PCHAR)Packet.Header + Length, p->payload, p->len);
63  Length += p->len;
64  p = p->next;
65  }
67 
68  Packet.HeaderSize = sizeof(IPv4_HEADER);
69  Packet.TotalSize = TotalLength;
70  Packet.SrcAddr = LocalAddress;
71  Packet.DstAddr = RemoteAddress;
72 
73  NdisStatus = IPSendDatagram(&Packet, NCE);
74  if (!NT_SUCCESS(NdisStatus))
75  return ERR_RTE;
76 
77  return 0;
78 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define ERR_RTE
Definition: err.h:56
Definition: neighbor.h:28
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
_In_ ULONG TotalLength
Definition: usbdlib.h:145
int NDIS_STATUS
Definition: ntddndis.h:471
Definition: ip.h:23
#define IP_ADDRESS_V4
Definition: ip.h:32
Definition: Header.h:8
PIP_PACKET IPInitializePacket(PIP_PACKET IPPacket, ULONG Type)
Definition: ip.c:92
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
smooth NULL
Definition: ftsmooth.c:416
struct IPv4_HEADER IPv4_HEADER
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define ERR_MEM
Definition: fontsub.h:52
unsigned char u8_t
Definition: cc.h:23
Definition: ip.h:37
unsigned int ULONG
Definition: retypes.h:1
Definition: ip.h:77
#define ERR_IF
Definition: err.h:72
GLfloat GLfloat p
Definition: glext.h:8902
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

Referenced by TCPInterfaceInit().

◆ TCPUnregisterInterface()

VOID TCPUnregisterInterface ( PIP_INTERFACE  IF)

Definition at line 139 of file if.c.

140 {
142 }
PVOID TCPContext
Definition: ip.h:169
void netif_remove(struct netif *netif)
Definition: netif.c:235

Referenced by IPDestroyInterface().

◆ TCPUpdateInterfaceIPInformation()

VOID TCPUpdateInterfaceIPInformation ( PIP_INTERFACE  IF)

Definition at line 145 of file if.c.

146 {
147  struct ip_addr ipaddr;
148  struct ip_addr netmask;
149  struct ip_addr gw;
150 
151  gw.addr = 0;
152 
154  ADE_UNICAST,
155  (PULONG)&ipaddr.addr);
156 
158  ADE_ADDRMASK,
159  (PULONG)&netmask.addr);
160 
161  netif_set_addr(IF->TCPContext, &ipaddr, &netmask, &gw);
162 
163  if (ipaddr.addr != 0)
164  {
167  }
168  else
169  {
171  }
172 }
PVOID TCPContext
Definition: ip.h:169
void netif_set_default(struct netif *netif)
Definition: netif.c:430
void netif_set_up(struct netif *netif)
Definition: netif.c:453
#define ADE_ADDRMASK
Definition: ip.h:112
void netif_set_down(struct netif *netif)
Definition: netif.c:490
NTSTATUS GetInterfaceIPv4Address(PIP_INTERFACE Interface, ULONG Type, PULONG Address)
Definition: interface.c:19
unsigned int * PULONG
Definition: retypes.h:1
#define ADE_UNICAST
Definition: ip.h:110
u32_t addr
Definition: ip_addr.h:45
void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
Definition: netif.c:221

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

◆ TCPUpdateInterfaceLinkStatus()

VOID TCPUpdateInterfaceLinkStatus ( PIP_INTERFACE  IF)

Definition at line 81 of file if.c.

82 {
83 #if 0
84  ULONG OperationalStatus;
85 
86  GetInterfaceConnectionStatus(IF, &OperationalStatus);
87 
88  if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
90  else
92 #endif
93 }
PVOID TCPContext
Definition: ip.h:169
void netif_set_link_down(struct netif *netif)
Definition: netif.c:574
VOID GetInterfaceConnectionStatus(PIP_INTERFACE Interface, PULONG OperStatus)
Definition: interface.c:254
void netif_set_link_up(struct netif *netif)
Definition: netif.c:535
unsigned int ULONG
Definition: retypes.h:1
#define MIB_IF_OPER_STATUS_OPERATIONAL
Definition: ipifcons.h:251

Referenced by ReconfigureAdapter(), and TCPInterfaceInit().