ReactOS  0.4.14-dev-552-g2fad488
rosip.h File Reference
#include "lwip/tcp.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
#include "tcpip.h"
Include dependency graph for rosip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _QUEUE_ENTRY
 
struct  lwip_callback_msg
 

Macros

#define LWIP_TAG   'PIwl'
 
#define LWIP_MESSAGE_TAG   'sMwl'
 
#define LWIP_QUEUE_TAG   'uQwl'
 

Typedefs

typedef struct tcp_pcb * PTCP_PCB
 
typedef struct _QUEUE_ENTRY QUEUE_ENTRY
 
typedef struct _QUEUE_ENTRYPQUEUE_ENTRY
 

Functions

NTSTATUS LibTCPGetDataFromConnectionQueue (PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
 
void TCPConnectEventHandler (void *arg, const err_t err)
 
void TCPAcceptEventHandler (void *arg, PTCP_PCB newpcb)
 
void TCPSendEventHandler (void *arg, const u16_t space)
 
void TCPFinEventHandler (void *arg, const err_t err)
 
void TCPRecvEventHandler (void *arg)
 
PTCP_PCB LibTCPSocket (void *arg)
 
err_t LibTCPBind (PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
 
PTCP_PCB LibTCPListen (PCONNECTION_ENDPOINT Connection, const u8_t backlog)
 
err_t LibTCPSend (PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
 
err_t LibTCPConnect (PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
 
err_t LibTCPShutdown (PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
 
err_t LibTCPClose (PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
 
err_t LibTCPGetPeerName (PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
 
err_t LibTCPGetHostName (PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
 
void LibTCPAccept (PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
 
void LibTCPSetNoDelay (PTCP_PCB pcb, BOOLEAN Set)
 
void LibTCPGetSocketStatus (PTCP_PCB pcb, PULONG State)
 
void LibIPInsertPacket (void *ifarg, const void *const data, const u32_t size)
 
void LibIPInitialize (void)
 
void LibIPShutdown (void)
 

Macro Definition Documentation

◆ LWIP_MESSAGE_TAG

#define LWIP_MESSAGE_TAG   'sMwl'

Definition at line 11 of file rosip.h.

◆ LWIP_QUEUE_TAG

#define LWIP_QUEUE_TAG   'uQwl'

Definition at line 12 of file rosip.h.

◆ LWIP_TAG

#define LWIP_TAG   'PIwl'

Definition at line 10 of file rosip.h.

Typedef Documentation

◆ PQUEUE_ENTRY

◆ PTCP_PCB

typedef struct tcp_pcb* PTCP_PCB

Definition at line 15 of file rosip.h.

◆ QUEUE_ENTRY

Function Documentation

◆ LibIPInitialize()

void LibIPInitialize ( void  )

Definition at line 35 of file rosip.c.

36 {
37  /* This completes asynchronously */
39 }
smooth NULL
Definition: ftsmooth.c:416
void tcpip_init(tcpip_init_done_fn initfunc, void *arg)
Definition: tcpip.c:456

Referenced by TCPStartup().

◆ LibIPInsertPacket()

void LibIPInsertPacket ( void ifarg,
const void *const  data,
const u32_t  size 
)

Definition at line 12 of file rosip.c.

15 {
16  struct pbuf *p;
17 
18  ASSERT(ifarg);
19  ASSERT(data);
20  ASSERT(size > 0);
21 
23  if (p)
24  {
25  ASSERT(p->tot_len == p->len);
26  ASSERT(p->len == size);
27 
28  RtlCopyMemory(p->payload, data, p->len);
29 
30  ((PNETIF)ifarg)->input(p, (PNETIF)ifarg);
31  }
32 }
struct netif * PNETIF
Definition: rosip.c:9
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:207
Definition: pbuf.h:58
Definition: pbuf.h:54
GLsizeiptr size
Definition: glext.h:5919
Definition: pbuf.h:79
Definition: netif.h:136
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by TCPReceive().

◆ LibIPShutdown()

void LibIPShutdown ( void  )

Definition at line 42 of file rosip.c.

43 {
44  /* This is synchronous */
45  sys_shutdown();
46 }
void sys_shutdown(void)
Definition: sys_arch.c:337

Referenced by TCPShutdown().

◆ LibTCPAccept()

void LibTCPAccept ( PTCP_PCB  pcb,
struct tcp_pcb *  listen_pcb,
void arg 
)

Definition at line 796 of file rostcp.c.

797 {
798  ASSERT(arg);
799 
800  tcp_arg(pcb, NULL);
802  tcp_sent(pcb, InternalSendEventHandler);
803  tcp_err(pcb, InternalErrorEventHandler);
804  tcp_arg(pcb, arg);
805 
806  tcp_accepted(listen_pcb);
807 }
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
Definition: rostcp.c:219
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
smooth NULL
Definition: ftsmooth.c:416
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
Definition: rostcp.c:207
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static void InternalErrorEventHandler(void *arg, const err_t err)
Definition: rostcp.c:303

Referenced by TCPAcceptEventHandler().

◆ LibTCPBind()

err_t LibTCPBind ( PCONNECTION_ENDPOINT  Connection,
struct ip_addr *const  ipaddr,
const u16_t  port 
)

Definition at line 394 of file rostcp.c.

395 {
396  struct lwip_callback_msg *msg;
397  err_t ret;
398 
399  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
400  if (msg)
401  {
403  msg->Input.Bind.Connection = Connection;
404  msg->Input.Bind.IpAddress = ipaddr;
405  msg->Input.Bind.Port = port;
406 
408 
409  if (WaitForEventSafely(&msg->Event))
410  ret = msg->Output.Bind.Error;
411  else
412  ret = ERR_CLSD;
413 
414  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
415 
416  return ret;
417  }
418 
419  return ERR_MEM;
420 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
static void LibTCPBindCallback(void *arg)
Definition: rostcp.c:369
USHORT port
Definition: uri.c:228
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPConnect(), and TCPListen().

◆ LibTCPClose()

err_t LibTCPClose ( PCONNECTION_ENDPOINT  Connection,
const int  safe,
const int  callback 
)

Definition at line 764 of file rostcp.c.

765 {
766  err_t ret;
767  struct lwip_callback_msg *msg;
768 
769  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
770  if (msg)
771  {
773 
774  msg->Input.Close.Connection = Connection;
775  msg->Input.Close.Callback = callback;
776 
777  if (safe)
779  else
781 
782  if (WaitForEventSafely(&msg->Event))
783  ret = msg->Output.Close.Error;
784  else
785  ret = ERR_CLSD;
786 
787  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
788 
789  return ret;
790  }
791 
792  return ERR_MEM;
793 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
MmuTrapHandler callback[0x30]
Definition: mmuobject.c:44
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
static void LibTCPCloseCallback(void *arg)
Definition: rostcp.c:714
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPAcceptEventHandler(), and TCPClose().

◆ LibTCPConnect()

err_t LibTCPConnect ( PCONNECTION_ENDPOINT  Connection,
struct ip_addr *const  ipaddr,
const u16_t  port 
)

Definition at line 601 of file rostcp.c.

602 {
603  struct lwip_callback_msg *msg;
604  err_t ret;
605 
606  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
607  if (msg)
608  {
610  msg->Input.Connect.Connection = Connection;
611  msg->Input.Connect.IpAddress = ipaddr;
612  msg->Input.Connect.Port = port;
613 
615 
616  if (WaitForEventSafely(&msg->Event))
617  {
618  ret = msg->Output.Connect.Error;
619  }
620  else
621  ret = ERR_CLSD;
622 
623  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
624 
625  return ret;
626  }
627 
628  return ERR_MEM;
629 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
static void LibTCPConnectCallback(void *arg)
Definition: rostcp.c:574
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
USHORT port
Definition: uri.c:228
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPConnect().

◆ LibTCPGetDataFromConnectionQueue()

NTSTATUS LibTCPGetDataFromConnectionQueue ( PCONNECTION_ENDPOINT  Connection,
PUCHAR  RecvBuffer,
UINT  RecvLen,
UINT Received 
)

Definition at line 101 of file rostcp.c.

102 {
103  PQUEUE_ENTRY qp;
104  struct pbuf* p;
106  UINT ReadLength, PayloadLength, Offset, Copied;
107  KIRQL OldIrql;
108 
109  (*Received) = 0;
110 
111  LockObject(Connection, &OldIrql);
112 
113  if (!IsListEmpty(&Connection->PacketQueue))
114  {
115  while ((qp = LibTCPDequeuePacket(Connection)) != NULL)
116  {
117  p = qp->p;
118 
119  /* Calculate the payload length first */
120  PayloadLength = p->tot_len;
121  PayloadLength -= qp->Offset;
122  Offset = qp->Offset;
123 
124  /* Check if we're reading the whole buffer */
125  ReadLength = MIN(PayloadLength, RecvLen);
126  ASSERT(ReadLength != 0);
127  if (ReadLength != PayloadLength)
128  {
129  /* Save this one for later */
130  qp->Offset += ReadLength;
131  InsertHeadList(&Connection->PacketQueue, &qp->ListEntry);
132  qp = NULL;
133  }
134 
135  UnlockObject(Connection, OldIrql);
136 
137  Copied = pbuf_copy_partial(p, RecvBuffer, ReadLength, Offset);
138  ASSERT(Copied == ReadLength);
139 
140  LockObject(Connection, &OldIrql);
141 
142  /* Update trackers */
143  RecvLen -= ReadLength;
144  RecvBuffer += ReadLength;
145  (*Received) += ReadLength;
146 
147  if (qp != NULL)
148  {
149  /* Use this special pbuf free callback function because we're outside tcpip thread */
150  pbuf_free_callback(qp->p);
151 
152  ExFreeToNPagedLookasideList(&QueueEntryLookasideList, qp);
153  }
154  else
155  {
156  /* If we get here, it means we've filled the buffer */
157  ASSERT(RecvLen == 0);
158  }
159 
160  ASSERT((*Received) != 0);
162 
163  if (!RecvLen)
164  break;
165  }
166  }
167  else
168  {
169  if (Connection->ReceiveShutdown)
170  Status = Connection->ReceiveShutdownStatus;
171  else
173  }
174 
175  UnlockObject(Connection, OldIrql);
176 
177  return Status;
178 }
struct pbuf * p
Definition: rosip.h:19
ULONG Offset
Definition: rosip.h:20
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LIST_ENTRY ListEntry
Definition: rosip.h:21
LONG NTSTATUS
Definition: precomp.h:26
_In_ PVOID _In_ ULONG _In_ PVOID _In_ ULONG PayloadLength
Definition: iotypes.h:439
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:286
err_t pbuf_free_callback(struct pbuf *p)
Definition: tcpip.c:494
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY PacketQueue
Definition: titypes.h:277
T MIN(T a, T b)
Definition: polytest.cpp:79
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: rosip.h:17
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
PQUEUE_ENTRY LibTCPDequeuePacket(PCONNECTION_ENDPOINT Connection)
Definition: rostcp.c:87
smooth NULL
Definition: ftsmooth.c:416
Definition: pbuf.h:79
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:918
BOOLEAN ReceiveShutdown
Definition: titypes.h:285
unsigned int UINT
Definition: ndis.h:50
GLfloat GLfloat p
Definition: glext.h:8902
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
return STATUS_SUCCESS
Definition: btrfs.c:2938
UINT Received
Definition: arping.c:40

Referenced by TCPReceiveData(), and TCPRecvEventHandler().

◆ LibTCPGetHostName()

err_t LibTCPGetHostName ( PTCP_PCB  pcb,
struct ip_addr *const  ipaddr,
u16_t *const  port 
)

Definition at line 810 of file rostcp.c.

811 {
812  if (!pcb)
813  return ERR_CLSD;
814 
815  *ipaddr = pcb->local_ip;
816  *port = pcb->local_port;
817 
818  return ERR_OK;
819 }
#define ERR_CLSD
Definition: err.h:67
#define ERR_OK
Definition: err.h:52
USHORT port
Definition: uri.c:228

Referenced by TCPGetSockAddress().

◆ LibTCPGetPeerName()

err_t LibTCPGetPeerName ( PTCP_PCB  pcb,
struct ip_addr *const  ipaddr,
u16_t *const  port 
)

Definition at line 822 of file rostcp.c.

823 {
824  if (!pcb)
825  return ERR_CLSD;
826 
827  *ipaddr = pcb->remote_ip;
828  *port = pcb->remote_port;
829 
830  return ERR_OK;
831 }
#define ERR_CLSD
Definition: err.h:67
#define ERR_OK
Definition: err.h:52
USHORT port
Definition: uri.c:228

Referenced by TCPCheckPeerForAccept(), and TCPGetSockAddress().

◆ LibTCPGetSocketStatus()

void LibTCPGetSocketStatus ( PTCP_PCB  pcb,
PULONG  State 
)

Definition at line 845 of file rostcp.c.

848 {
849  /* Translate state from enum tcp_state -> MIB_TCP_STATE */
850  *State = pcb->state + 1;
851 }

Referenced by TCPGetSocketStatus().

◆ LibTCPListen()

PTCP_PCB LibTCPListen ( PCONNECTION_ENDPOINT  Connection,
const u8_t  backlog 
)

Definition at line 448 of file rostcp.c.

449 {
450  struct lwip_callback_msg *msg;
451  PTCP_PCB ret;
452 
453  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
454  if (msg)
455  {
457  msg->Input.Listen.Connection = Connection;
458  msg->Input.Listen.Backlog = backlog;
459 
461 
462  if (WaitForEventSafely(&msg->Event))
463  ret = msg->Output.Listen.NewPcb;
464  else
465  ret = NULL;
466 
467  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
468 
469  return ret;
470  }
471 
472  return NULL;
473 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
smooth NULL
Definition: ftsmooth.c:416
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static void LibTCPListenCallback(void *arg)
Definition: rostcp.c:424
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPListen().

◆ LibTCPSend()

err_t LibTCPSend ( PCONNECTION_ENDPOINT  Connection,
void *const  dataptr,
const u16_t  len,
u32_t sent,
const int  safe 
)

Definition at line 536 of file rostcp.c.

537 {
538  err_t ret;
539  struct lwip_callback_msg *msg;
540 
541  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
542  if (msg)
543  {
545  msg->Input.Send.Connection = Connection;
546  msg->Input.Send.Data = dataptr;
547  msg->Input.Send.DataLength = len;
548 
549  if (safe)
551  else
553 
554  if (WaitForEventSafely(&msg->Event))
555  ret = msg->Output.Send.Error;
556  else
557  ret = ERR_CLSD;
558 
559  if (ret == ERR_OK)
560  *sent = msg->Output.Send.Information;
561  else
562  *sent = 0;
563 
564  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
565 
566  return ret;
567  }
568 
569  return ERR_MEM;
570 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
#define ERR_OK
Definition: err.h:52
int ret
Definition: msg.h:34
GLenum GLsizei len
Definition: glext.h:6722
static void LibTCPSendCallback(void *arg)
Definition: rostcp.c:477
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
int const JOCTET * dataptr
Definition: jpeglib.h:1027
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPSendData(), and TCPSendEventHandler().

◆ LibTCPSetNoDelay()

void LibTCPSetNoDelay ( PTCP_PCB  pcb,
BOOLEAN  Set 
)

Definition at line 834 of file rostcp.c.

837 {
838  if (Set)
839  pcb->flags |= TF_NODELAY;
840  else
841  pcb->flags &= ~TF_NODELAY;
842 }
static BOOL Set
Definition: pageheap.c:10

Referenced by TCPSetNoDelay().

◆ LibTCPShutdown()

err_t LibTCPShutdown ( PCONNECTION_ENDPOINT  Connection,
const int  shut_rx,
const int  shut_tx 
)

Definition at line 683 of file rostcp.c.

684 {
685  struct lwip_callback_msg *msg;
686  err_t ret;
687 
688  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
689  if (msg)
690  {
692 
693  msg->Input.Shutdown.Connection = Connection;
694  msg->Input.Shutdown.shut_rx = shut_rx;
695  msg->Input.Shutdown.shut_tx = shut_tx;
696 
698 
699  if (WaitForEventSafely(&msg->Event))
700  ret = msg->Output.Shutdown.Error;
701  else
702  ret = ERR_CLSD;
703 
704  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
705 
706  return ret;
707  }
708 
709  return ERR_MEM;
710 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:35
s8_t err_t
Definition: err.h:47
static void LibTCPShutdownCallback(void *arg)
Definition: rostcp.c:633
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ERR_MEM
Definition: fontsub.h:52
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by DisconnectTimeoutDpc(), and TCPDisconnect().

◆ LibTCPSocket()

PTCP_PCB LibTCPSocket ( void arg)

Definition at line 342 of file rostcp.c.

343 {
344  struct lwip_callback_msg *msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
345  struct tcp_pcb *ret;
346 
347  if (msg)
348  {
350  msg->Input.Socket.Arg = arg;
351 
353 
354  if (WaitForEventSafely(&msg->Event))
355  ret = msg->Output.Socket.NewPcb;
356  else
357  ret = NULL;
358 
359  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
360 
361  return ret;
362  }
363 
364  return NULL;
365 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:182
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
void * arg
Definition: msvc.h:12
smooth NULL
Definition: ftsmooth.c:416
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static void LibTCPSocketCallback(void *arg)
Definition: rostcp.c:324
#define msg(x)
Definition: auth_time.c:54
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15

Referenced by TCPSocket().

◆ TCPAcceptEventHandler()

void TCPAcceptEventHandler ( void arg,
PTCP_PCB  newpcb 
)

Definition at line 297 of file event.c.

298 {
300  PTDI_BUCKET Bucket;
302  PIRP Irp;
304  KIRQL OldIrql;
305 
306  ReferenceObject(Connection);
307 
308  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ListenRequest, &Connection->Lock)))
309  {
311 
312  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
313 
314  Irp = Bucket->Request.RequestContext;
316 
317  TI_DbgPrint(DEBUG_TCP,("[IP, TCPAcceptEventHandler] Getting the socket\n"));
318 
319  Status = TCPCheckPeerForAccept(newpcb,
321 
322  TI_DbgPrint(DEBUG_TCP,("Socket: Status: %x\n", Status));
323 
324  Bucket->Status = Status;
325  Bucket->Information = 0;
326 
327  if (Status == STATUS_SUCCESS)
328  {
330 
331  /* sanity assert...this should never be in anything else but a CLOSED state */
332  ASSERT( ((PTCP_PCB)Bucket->AssociatedEndpoint->SocketContext)->state == CLOSED );
333 
334  /* free socket context created in FileOpenConnection, as we're using a new one */
336 
337  /* free previously created socket context (we don't use it, we use newpcb) */
338  Bucket->AssociatedEndpoint->SocketContext = newpcb;
339 
340  LibTCPAccept(newpcb, (PTCP_PCB)Connection->SocketContext, Bucket->AssociatedEndpoint);
341 
343  }
344 
346 
347  CompleteBucket(Connection, Bucket, FALSE);
348 
349  if (Status == STATUS_SUCCESS)
350  {
351  break;
352  }
353  }
354 
355  DereferenceObject(Connection);
356 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define TRUE
Definition: types.h:120
PVOID RequestContext
Definition: tdi.h:55
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
NTSTATUS TCPCheckPeerForAccept(PVOID Context, PTDI_REQUEST_KERNEL Request)
Definition: accept.c:17
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: rostcp.c:764
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:251
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
LIST_ENTRY ListenRequest
Definition: titypes.h:272
NTSTATUS Status
Definition: titypes.h:253
void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
Definition: rostcp.c:796
TDI_REQUEST Request
Definition: titypes.h:252
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by InternalAcceptEventHandler().

◆ TCPConnectEventHandler()

void TCPConnectEventHandler ( void arg,
const err_t  err 
)

Definition at line 479 of file event.c.

480 {
482  PTDI_BUCKET Bucket;
484 
485  ReferenceObject(Connection);
486 
487  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ConnectRequest, &Connection->Lock)))
488  {
489 
490  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
491 
492  Bucket->Status = TCPTranslateError(err);
493  Bucket->Information = 0;
494 
495  CompleteBucket(Connection, Bucket, FALSE);
496  }
497 
498  DereferenceObject(Connection);
499 }
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
#define err(...)
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:242
LIST_ENTRY ConnectRequest
Definition: titypes.h:271
NTSTATUS Status
Definition: titypes.h:253
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by InternalConnectEventHandler().

◆ TCPFinEventHandler()

void TCPFinEventHandler ( void arg,
const err_t  err 
)

Definition at line 247 of file event.c.

248 {
249  PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg, LastConnection;
251  KIRQL OldIrql;
252 
253  ASSERT(Connection->SocketContext == NULL);
254  ASSERT(Connection->AddressFile);
255  ASSERT(err != ERR_OK);
256 
257  /* Complete all outstanding requests now */
258  FlushAllQueues(Connection, Status);
259 
260  LockObject(Connection, &OldIrql);
261 
262  LockObjectAtDpcLevel(Connection->AddressFile);
263 
264  /* Unlink this connection from the address file */
265  if (Connection->AddressFile->Connection == Connection)
266  {
267  Connection->AddressFile->Connection = Connection->Next;
268  DereferenceObject(Connection);
269  }
270  else if (Connection->AddressFile->Listener == Connection)
271  {
272  Connection->AddressFile->Listener = NULL;
273  DereferenceObject(Connection);
274  }
275  else
276  {
277  LastConnection = Connection->AddressFile->Connection;
278  while (LastConnection->Next != Connection && LastConnection->Next != NULL)
279  LastConnection = LastConnection->Next;
280  if (LastConnection->Next == Connection)
281  {
282  LastConnection->Next = Connection->Next;
283  DereferenceObject(Connection);
284  }
285  }
286 
288 
289  /* Remove the address file from this connection */
290  DereferenceObject(Connection->AddressFile);
291  Connection->AddressFile = NULL;
292 
293  UnlockObject(Connection, OldIrql);
294 }
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define LockObjectAtDpcLevel(Object)
Definition: titypes.h:44
#define DereferenceObject(Object)
Definition: titypes.h:24
struct _CONNECTION_ENDPOINT * Next
Definition: titypes.h:289
#define LockObject(Object, Irql)
Definition: titypes.h:34
PADDRESS_FILE AddressFile
Definition: titypes.h:268
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
smooth NULL
Definition: ftsmooth.c:416
#define ERR_OK
Definition: err.h:52
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define UnlockObjectFromDpcLevel(Object)
Definition: titypes.h:63
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define err(...)
struct _CONNECTION_ENDPOINT * Listener
Definition: titypes.h:153
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:218
Status
Definition: gdiplustypes.h:24
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:242
struct _CONNECTION_ENDPOINT * Connection
Definition: titypes.h:151

Referenced by InternalErrorEventHandler(), InternalRecvEventHandler(), LibTCPCloseCallback(), and LibTCPShutdownCallback().

◆ TCPRecvEventHandler()

void TCPRecvEventHandler ( void arg)

Definition at line 437 of file event.c.

438 {
440  PTDI_BUCKET Bucket;
442  PIRP Irp;
443  PMDL Mdl;
444  UINT Received;
445  UINT RecvLen;
446  PUCHAR RecvBuffer;
448 
449  ReferenceObject(Connection);
450 
451  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ReceiveRequest, &Connection->Lock)))
452  {
453  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
454 
455  Irp = Bucket->Request.RequestContext;
456  Mdl = Irp->MdlAddress;
457 
458  NdisQueryBuffer( Mdl, &RecvBuffer, &RecvLen );
459 
460  Status = LibTCPGetDataFromConnectionQueue(Connection, RecvBuffer, RecvLen, &Received);
461  if (Status == STATUS_PENDING)
462  {
464  &Bucket->Entry,
465  &Connection->Lock);
466  break;
467  }
468 
469  Bucket->Status = Status;
470  Bucket->Information = Received;
471 
472  CompleteBucket(Connection, Bucket, FALSE);
473  }
474 
475  DereferenceObject(Connection);
476 }
PVOID RequestContext
Definition: tdi.h:55
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define STATUS_PENDING
Definition: ntstatus.h:82
LIST_ENTRY ReceiveRequest
Definition: titypes.h:273
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: rostcp.c:101
unsigned int UINT
Definition: ndis.h:50
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
NTSTATUS Status
Definition: titypes.h:253
TDI_REQUEST Request
Definition: titypes.h:252
UINT Received
Definition: arping.c:40
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by InternalErrorEventHandler(), and InternalRecvEventHandler().

◆ TCPSendEventHandler()

void TCPSendEventHandler ( void arg,
const u16_t  space 
)

Definition at line 359 of file event.c.

360 {
362  PTDI_BUCKET Bucket;
364  PIRP Irp;
366  PMDL Mdl;
367  ULONG BytesSent;
368 
369  ReferenceObject(Connection);
370 
371  while ((Entry = ExInterlockedRemoveHeadList(&Connection->SendRequest, &Connection->Lock)))
372  {
373  UINT SendLen = 0;
374  PVOID SendBuffer = 0;
375 
376  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
377 
378  Irp = Bucket->Request.RequestContext;
379  Mdl = Irp->MdlAddress;
380 
382  ("Getting the user buffer from %x\n", Mdl));
383 
384  NdisQueryBuffer( Mdl, &SendBuffer, &SendLen );
385 
387  ("Writing %d bytes to %x\n", SendLen, SendBuffer));
388 
389  TI_DbgPrint(DEBUG_TCP, ("Connection: %x\n", Connection));
391  (DEBUG_TCP,
392  ("Connection->SocketContext: %x\n",
393  Connection->SocketContext));
394 
395  Status = TCPTranslateError(LibTCPSend(Connection,
396  SendBuffer,
397  SendLen, &BytesSent, TRUE));
398 
399  TI_DbgPrint(DEBUG_TCP,("TCP Bytes: %d\n", BytesSent));
400 
401  if( Status == STATUS_PENDING )
402  {
404  &Bucket->Entry,
405  &Connection->Lock);
406  break;
407  }
408  else
409  {
411  ("Completing Send request: %x %x\n",
412  Bucket->Request, Status));
413 
414  Bucket->Status = Status;
415  Bucket->Information = (Bucket->Status == STATUS_SUCCESS) ? BytesSent : 0;
416 
417  CompleteBucket(Connection, Bucket, FALSE);
418  }
419  }
420 
421  // If we completed all outstanding send requests then finish all pending shutdown requests,
422  // cancel the timer and dereference the connection
423  if (IsListEmpty(&Connection->SendRequest))
424  {
426 
427  if (KeCancelTimer(&Connection->DisconnectTimer))
428  {
429  DereferenceObject(Connection);
430  }
431  }
432 
433  DereferenceObject(Connection);
434 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define TRUE
Definition: types.h:120
PVOID RequestContext
Definition: tdi.h:55
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: rostcp.c:536
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:137
KTIMER DisconnectTimer
Definition: titypes.h:280
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:242
unsigned int UINT
Definition: ndis.h:50
LIST_ENTRY SendRequest
Definition: titypes.h:274
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
NTSTATUS Status
Definition: titypes.h:253
unsigned int ULONG
Definition: retypes.h:1
TDI_REQUEST Request
Definition: titypes.h:252
return STATUS_SUCCESS
Definition: btrfs.c:2938
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by InternalSendEventHandler().