ReactOS  0.4.15-dev-3181-g4acf100
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)
 
VOID LibTCPFreeSocket (PTCP_PCB pcb)
 
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 }
void tcpip_init(tcpip_init_done_fn initfunc, void *arg)
Definition: tcpip.c:456
#define NULL
Definition: types.h:112

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
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
#define ASSERT(a)
Definition: mode.c:44
Definition: pbuf.h:79
Definition: netif.h:136
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
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 833 of file rostcp.c.

834 {
835  ASSERT(arg);
836 
837  tcp_arg(pcb, NULL);
839  tcp_sent(pcb, InternalSendEventHandler);
840  tcp_err(pcb, InternalErrorEventHandler);
841  tcp_arg(pcb, arg);
842 
843  tcp_accepted(listen_pcb);
844 }
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
Definition: rostcp.c:216
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
Definition: rostcp.c:204
#define ASSERT(a)
Definition: mode.c:44
#define NULL
Definition: types.h:112
static void InternalErrorEventHandler(void *arg, const err_t err)
Definition: rostcp.c:300

Referenced by TCPAcceptEventHandler().

◆ LibTCPBind()

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

Definition at line 418 of file rostcp.c.

419 {
420  struct lwip_callback_msg *msg;
421  err_t ret;
422 
423  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
424  if (msg)
425  {
427  msg->Input.Bind.Connection = Connection;
428  msg->Input.Bind.IpAddress = ipaddr;
429  msg->Input.Bind.Port = port;
430 
432 
433  if (WaitForEventSafely(&msg->Event))
434  ret = msg->Output.Bind.Error;
435  else
436  ret = ERR_CLSD;
437 
438  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
439 
440  return ret;
441  }
442 
443  return ERR_MEM;
444 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
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:38
#define FALSE
Definition: types.h:117
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:393
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 801 of file rostcp.c.

802 {
803  err_t ret;
804  struct lwip_callback_msg *msg;
805 
806  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
807  if (msg)
808  {
810 
811  msg->Input.Close.Connection = Connection;
812  msg->Input.Close.Callback = callback;
813 
814  if (safe)
816  else
818 
819  if (WaitForEventSafely(&msg->Event))
820  ret = msg->Output.Close.Error;
821  else
822  ret = ERR_CLSD;
823 
824  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
825 
826  return ret;
827  }
828 
829  return ERR_MEM;
830 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
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:38
#define FALSE
Definition: types.h:117
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
static void LibTCPCloseCallback(void *arg)
Definition: rostcp.c:751
#define msg(x)
Definition: auth_time.c:54
static IPrintDialogCallback callback
Definition: printdlg.c:326
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 625 of file rostcp.c.

626 {
627  struct lwip_callback_msg *msg;
628  err_t ret;
629 
630  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
631  if (msg)
632  {
634  msg->Input.Connect.Connection = Connection;
635  msg->Input.Connect.IpAddress = ipaddr;
636  msg->Input.Connect.Port = port;
637 
639 
640  if (WaitForEventSafely(&msg->Event))
641  {
642  ret = msg->Output.Connect.Error;
643  }
644  else
645  ret = ERR_CLSD;
646 
647  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
648 
649  return ret;
650  }
651 
652  return ERR_MEM;
653 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
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:598
PCONNECTION_ENDPOINT Connection
Definition: rosip.h:38
#define FALSE
Definition: types.h:117
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().

◆ LibTCPFreeSocket()

VOID LibTCPFreeSocket ( PTCP_PCB  pcb)

Definition at line 378 of file rostcp.c.

379 {
380  struct lwip_callback_msg msg;
381 
383  msg.Input.FreeSocket.pcb = pcb;
384 
386 
387  WaitForEventSafely(&msg.Event);
388 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
#define FALSE
Definition: types.h:117
static void LibTCPFreeSocketCallback(void *arg)
Definition: rostcp.c:366
struct tcp_pcb * pcb
Definition: rosip.h:35
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define msg(x)
Definition: auth_time.c:54

◆ LibTCPGetDataFromConnectionQueue()

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

Definition at line 103 of file rostcp.c.

104 {
105  PQUEUE_ENTRY qp;
106  struct pbuf* p;
109 
110  (*Received) = 0;
111 
112  LockObject(Connection);
113 
114  if (!IsListEmpty(&Connection->PacketQueue))
115  {
116  while ((qp = LibTCPDequeuePacket(Connection)) != NULL)
117  {
118  p = qp->p;
119 
120  /* Calculate the payload length first */
121  PayloadLength = p->tot_len;
122  PayloadLength -= qp->Offset;
123  Offset = qp->Offset;
124 
125  /* Check if we're reading the whole buffer */
126  ReadLength = MIN(PayloadLength, RecvLen);
127  ASSERT(ReadLength != 0);
128  if (ReadLength != PayloadLength)
129  {
130  /* Save this one for later */
131  qp->Offset += ReadLength;
132  InsertHeadList(&Connection->PacketQueue, &qp->ListEntry);
133  qp = NULL;
134  }
135 
136  Copied = pbuf_copy_partial(p, RecvBuffer, ReadLength, Offset);
137  ASSERT(Copied == ReadLength);
138 
139  /* Update trackers */
140  RecvLen -= ReadLength;
141  RecvBuffer += ReadLength;
142  (*Received) += ReadLength;
143 
144  if (qp != NULL)
145  {
146  /* Use this special pbuf free callback function because we're outside tcpip thread */
147  pbuf_free_callback(qp->p);
148 
149  ExFreeToNPagedLookasideList(&QueueEntryLookasideList, qp);
150  }
151  else
152  {
153  /* If we get here, it means we've filled the buffer */
154  ASSERT(RecvLen == 0);
155  }
156 
157  ASSERT((*Received) != 0);
159 
160  if (!RecvLen)
161  break;
162  }
163  }
164  else
165  {
166  if (Connection->ReceiveShutdown)
167  Status = Connection->ReceiveShutdownStatus;
168  else
170  }
171 
172  UnlockObject(Connection);
173 
174  return Status;
175 }
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:471
NTSTATUS ReceiveShutdownStatus
Definition: titypes.h:266
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:256
T MIN(T a, T b)
Definition: polytest.cpp:79
Definition: rosip.h:17
PQUEUE_ENTRY LibTCPDequeuePacket(PCONNECTION_ENDPOINT Connection)
Definition: rostcp.c:89
ULONG ReadLength
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
Definition: pbuf.h:79
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:918
#define UnlockObject(Object)
Definition: titypes.h:44
BOOLEAN ReceiveShutdown
Definition: titypes.h:265
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
GLfloat GLfloat p
Definition: glext.h:8902
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
UINT Received
Definition: arping.c:40
#define LockObject(Object)
Definition: titypes.h:34

Referenced by TCPReceiveData(), and TCPRecvEventHandler().

◆ LibTCPGetHostName()

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

Definition at line 847 of file rostcp.c.

848 {
849  if (!pcb)
850  return ERR_CLSD;
851 
852  *ipaddr = pcb->local_ip;
853  *port = pcb->local_port;
854 
855  return ERR_OK;
856 }
#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 859 of file rostcp.c.

860 {
861  if (!pcb)
862  return ERR_CLSD;
863 
864  *ipaddr = pcb->remote_ip;
865  *port = pcb->remote_port;
866 
867  return ERR_OK;
868 }
#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 882 of file rostcp.c.

885 {
886  /* Translate state from enum tcp_state -> MIB_TCP_STATE */
887  *State = pcb->state + 1;
888 }

Referenced by TCPGetSocketStatus().

◆ LibTCPListen()

PTCP_PCB LibTCPListen ( PCONNECTION_ENDPOINT  Connection,
const u8_t  backlog 
)

Definition at line 472 of file rostcp.c.

473 {
474  struct lwip_callback_msg *msg;
475  PTCP_PCB ret;
476 
477  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
478  if (msg)
479  {
481  msg->Input.Listen.Connection = Connection;
482  msg->Input.Listen.Backlog = backlog;
483 
485 
486  if (WaitForEventSafely(&msg->Event))
487  ret = msg->Output.Listen.NewPcb;
488  else
489  ret = NULL;
490 
491  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
492 
493  return ret;
494  }
495 
496  return NULL;
497 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
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:38
#define FALSE
Definition: types.h:117
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
static void LibTCPListenCallback(void *arg)
Definition: rostcp.c:448
#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 560 of file rostcp.c.

561 {
562  err_t ret;
563  struct lwip_callback_msg *msg;
564 
565  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
566  if (msg)
567  {
569  msg->Input.Send.Connection = Connection;
570  msg->Input.Send.Data = dataptr;
571  msg->Input.Send.DataLength = len;
572 
573  if (safe)
575  else
577 
578  if (WaitForEventSafely(&msg->Event))
579  ret = msg->Output.Send.Error;
580  else
581  ret = ERR_CLSD;
582 
583  if (ret == ERR_OK)
584  *sent = msg->Output.Send.Information;
585  else
586  *sent = 0;
587 
588  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
589 
590  return ret;
591  }
592 
593  return ERR_MEM;
594 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
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:38
#define FALSE
Definition: types.h:117
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:501
#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:1030
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 871 of file rostcp.c.

874 {
875  if (Set)
876  pcb->flags |= TF_NODELAY;
877  else
878  pcb->flags &= ~TF_NODELAY;
879 }
static BOOL Set
Definition: pageheap.c:10
struct tcp_pcb * pcb
Definition: rosip.h:35

Referenced by TCPSetNoDelay().

◆ LibTCPShutdown()

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

Definition at line 720 of file rostcp.c.

721 {
722  struct lwip_callback_msg *msg;
723  err_t ret;
724 
725  msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
726  if (msg)
727  {
729 
730  msg->Input.Shutdown.Connection = Connection;
731  msg->Input.Shutdown.shut_rx = shut_rx;
732  msg->Input.Shutdown.shut_tx = shut_tx;
733 
735 
736  if (WaitForEventSafely(&msg->Event))
737  ret = msg->Output.Shutdown.Error;
738  else
739  ret = ERR_CLSD;
740 
741  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
742 
743  return ret;
744  }
745 
746  return ERR_MEM;
747 }
#define ERR_CLSD
Definition: err.h:67
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
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:38
#define FALSE
Definition: types.h:117
s8_t err_t
Definition: err.h:47
static void LibTCPShutdownCallback(void *arg)
Definition: rostcp.c:657
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 DisconnectWorker(), and TCPDisconnect().

◆ LibTCPSocket()

PTCP_PCB LibTCPSocket ( void arg)

Definition at line 339 of file rostcp.c.

340 {
341  struct lwip_callback_msg *msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
342  struct tcp_pcb *ret;
343 
344  if (msg)
345  {
347  msg->Input.Socket.Arg = arg;
348 
350 
351  if (WaitForEventSafely(&msg->Event))
352  ret = msg->Output.Socket.NewPcb;
353  else
354  ret = NULL;
355 
356  ExFreeToNPagedLookasideList(&MessageLookasideList, msg);
357 
358  return ret;
359  }
360 
361  return NULL;
362 }
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
Definition: rostcp.c:179
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:212
void * arg
Definition: msvc.h:10
#define FALSE
Definition: types.h:117
int ret
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static void LibTCPSocketCallback(void *arg)
Definition: rostcp.c:321
#define NULL
Definition: types.h:112
#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 231 of file event.c.

232 {
234  PTDI_BUCKET Bucket;
236  PIRP Irp;
238 
239  LockObject(Connection);
240 
241  while (!IsListEmpty(&Connection->ListenRequest))
242  {
244 
245  Entry = RemoveHeadList(&Connection->ListenRequest);
246 
247  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
248 
249  Irp = Bucket->Request.RequestContext;
251 
252  TI_DbgPrint(DEBUG_TCP,("[IP, TCPAcceptEventHandler] Getting the socket\n"));
253 
254  Status = TCPCheckPeerForAccept(newpcb,
256 
257  TI_DbgPrint(DEBUG_TCP,("Socket: Status: %x\n", Status));
258 
259  Bucket->Status = Status;
260  Bucket->Information = 0;
261 
262  if (Status == STATUS_SUCCESS)
263  {
265 
266  /* sanity assert...this should never be in anything else but a CLOSED state */
267  ASSERT( ((PTCP_PCB)Bucket->AssociatedEndpoint->SocketContext)->state == CLOSED );
268 
269  /* free socket context created in FileOpenConnection, as we're using a new one */
271 
272  /* free previously created socket context (we don't use it, we use newpcb) */
273  Bucket->AssociatedEndpoint->SocketContext = newpcb;
274 
276 
277  LibTCPAccept(newpcb, (PTCP_PCB)Connection->SocketContext, Bucket->AssociatedEndpoint);
278  }
279 
281 
282  CompleteBucket(Connection, Bucket, FALSE);
283 
284  if (Status == STATUS_SUCCESS)
285  {
286  break;
287  }
288  }
289 
290  UnlockObject(Connection);
291 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
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
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 FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: rostcp.c:801
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
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
struct tcp_pcb * PTCP_PCB
Definition: rosip.h:15
Definition: typedefs.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define UnlockObject(Object)
Definition: titypes.h:44
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
LIST_ENTRY ListenRequest
Definition: titypes.h:251
NTSTATUS Status
Definition: titypes.h:233
void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
Definition: rostcp.c:833
TDI_REQUEST Request
Definition: titypes.h:232
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
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:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalAcceptEventHandler().

◆ TCPConnectEventHandler()

void TCPConnectEventHandler ( void arg,
const err_t  err 
)

Definition at line 420 of file event.c.

421 {
423  PTDI_BUCKET Bucket;
425 
426  LockObject(Connection);
427 
428  while (!IsListEmpty(&Connection->ConnectRequest))
429  {
430  Entry = RemoveHeadList(&Connection->ConnectRequest);
431 
432  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
433 
434  Bucket->Status = TCPTranslateError(err);
435  Bucket->Information = 0;
436 
437  CompleteBucket(Connection, Bucket, FALSE);
438  }
439 
440  UnlockObject(Connection);
441 }
struct _Entry Entry
Definition: kefuncs.h:627
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Definition: typedefs.h:119
#define err(...)
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define UnlockObject(Object)
Definition: titypes.h:44
LIST_ENTRY ConnectRequest
Definition: titypes.h:250
NTSTATUS Status
Definition: titypes.h:233
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:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalConnectEventHandler().

◆ TCPFinEventHandler()

void TCPFinEventHandler ( void arg,
const err_t  err 
)

Definition at line 182 of file event.c.

183 {
184  PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg, LastConnection;
186 
187  ASSERT(Connection->SocketContext == NULL);
188  ASSERT(Connection->AddressFile);
189  ASSERT(err != ERR_OK);
190 
191  LockObject(Connection);
192 
193  /* Complete all outstanding requests now */
194  FlushAllQueues(Connection, Status);
195 
196  LockObject(Connection->AddressFile);
197 
198  /* Unlink this connection from the address file */
199  if (Connection->AddressFile->Connection == Connection)
200  {
201  Connection->AddressFile->Connection = Connection->Next;
202  DereferenceObject(Connection);
203  }
204  else if (Connection->AddressFile->Listener == Connection)
205  {
206  Connection->AddressFile->Listener = NULL;
207  DereferenceObject(Connection);
208  }
209  else
210  {
211  LastConnection = Connection->AddressFile->Connection;
212  while (LastConnection->Next != Connection && LastConnection->Next != NULL)
213  LastConnection = LastConnection->Next;
214  if (LastConnection->Next == Connection)
215  {
216  LastConnection->Next = Connection->Next;
217  DereferenceObject(Connection);
218  }
219  }
220 
221  UnlockObject(Connection->AddressFile);
222 
223  /* Remove the address file from this connection */
224  DereferenceObject(Connection->AddressFile);
225  Connection->AddressFile = NULL;
226 
227  UnlockObject(Connection);
228 }
LONG NTSTATUS
Definition: precomp.h:26
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define DereferenceObject(Object)
Definition: titypes.h:24
struct _CONNECTION_ENDPOINT * Next
Definition: titypes.h:269
PADDRESS_FILE AddressFile
Definition: titypes.h:247
#define ERR_OK
Definition: err.h:52
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
#define err(...)
struct _CONNECTION_ENDPOINT * Listener
Definition: titypes.h:133
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:157
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define UnlockObject(Object)
Definition: titypes.h:44
#define NULL
Definition: types.h:112
struct _CONNECTION_ENDPOINT * Connection
Definition: titypes.h:131
#define LockObject(Object)
Definition: titypes.h:34

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

◆ TCPRecvEventHandler()

void TCPRecvEventHandler ( void arg)

Definition at line 380 of file event.c.

381 {
383  PTDI_BUCKET Bucket;
385  PIRP Irp;
386  PMDL Mdl;
387  UINT Received;
388  UINT RecvLen;
389  PUCHAR RecvBuffer;
391 
392  LockObject(Connection);
393 
394  while(!IsListEmpty(&Connection->ReceiveRequest))
395  {
396  Entry = RemoveHeadList(&Connection->ReceiveRequest);
397  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
398 
399  Irp = Bucket->Request.RequestContext;
400  Mdl = Irp->MdlAddress;
401 
402  NdisQueryBuffer( Mdl, &RecvBuffer, &RecvLen );
403 
404  Status = LibTCPGetDataFromConnectionQueue(Connection, RecvBuffer, RecvLen, &Received);
405  if (Status == STATUS_PENDING)
406  {
407  InsertHeadList(&Connection->ReceiveRequest, &Bucket->Entry);
408  break;
409  }
410 
411  Bucket->Status = Status;
412  Bucket->Information = Received;
413 
414  CompleteBucket(Connection, Bucket, FALSE);
415  }
416  UnlockObject(Connection);
417 }
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:627
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
unsigned char * PUCHAR
Definition: retypes.h:3
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 FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
LIST_ENTRY ReceiveRequest
Definition: titypes.h:252
Definition: typedefs.h:119
LIST_ENTRY Entry
Definition: titypes.h:230
#define UnlockObject(Object)
Definition: titypes.h:44
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: rostcp.c:103
unsigned int UINT
Definition: ndis.h:50
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955
NTSTATUS Status
Definition: titypes.h:233
TDI_REQUEST Request
Definition: titypes.h:232
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:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalErrorEventHandler(), and InternalRecvEventHandler().

◆ TCPSendEventHandler()

void TCPSendEventHandler ( void arg,
const u16_t  space 
)

Definition at line 294 of file event.c.

295 {
297  PTDI_BUCKET Bucket;
299  PIRP Irp;
301  PMDL Mdl;
302  ULONG BytesSent;
303 
304  ReferenceObject(Connection);
305  LockObject(Connection);
306 
307  while (!IsListEmpty(&Connection->SendRequest))
308  {
309  UINT SendLen = 0;
310  PVOID SendBuffer = 0;
311 
312  Entry = RemoveHeadList(&Connection->SendRequest);
313 
314  UnlockObject(Connection);
315 
316  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
317 
318  Irp = Bucket->Request.RequestContext;
319  Mdl = Irp->MdlAddress;
320 
322  ("Getting the user buffer from %x\n", Mdl));
323 
324  NdisQueryBuffer( Mdl, &SendBuffer, &SendLen );
325 
327  ("Writing %d bytes to %x\n", SendLen, SendBuffer));
328 
329  TI_DbgPrint(DEBUG_TCP, ("Connection: %x\n", Connection));
331  (DEBUG_TCP,
332  ("Connection->SocketContext: %x\n",
333  Connection->SocketContext));
334 
335  Status = TCPTranslateError(LibTCPSend(Connection,
336  SendBuffer,
337  SendLen, &BytesSent, TRUE));
338 
339  TI_DbgPrint(DEBUG_TCP,("TCP Bytes: %d\n", BytesSent));
340 
341  if( Status == STATUS_PENDING )
342  {
343  LockObject(Connection);
344  InsertHeadList(&Connection->SendRequest, &Bucket->Entry);
345  break;
346  }
347  else
348  {
350  ("Completing Send request: %x %x\n",
351  Bucket->Request, Status));
352 
353  Bucket->Status = Status;
354  Bucket->Information = (Bucket->Status == STATUS_SUCCESS) ? BytesSent : 0;
355 
356  CompleteBucket(Connection, Bucket, FALSE);
357  }
358 
359  LockObject(Connection);
360  }
361 
362  // If we completed all outstanding send requests then finish all pending shutdown requests,
363  // cancel the timer and dereference the connection
364  if (IsListEmpty(&Connection->SendRequest))
365  {
366  FlushShutdownQueue(Connection, STATUS_SUCCESS);
367 
368  if (KeCancelTimer(&Connection->DisconnectTimer))
369  {
370  DereferenceObject(Connection);
371  }
372  }
373 
374  UnlockObject(Connection);
375 
376  DereferenceObject(Connection);
377 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: rostcp.c:560
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
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Status
Definition: gdiplustypes.h:24
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)
Definition: event.c:95
KTIMER DisconnectTimer
Definition: titypes.h:259
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:119
LIST_ENTRY Entry
Definition: titypes.h:230
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define UnlockObject(Object)
Definition: titypes.h:44
unsigned int UINT
Definition: ndis.h:50
LIST_ENTRY SendRequest
Definition: titypes.h:253
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955
NTSTATUS Status
Definition: titypes.h:233
unsigned int ULONG
Definition: retypes.h:1
TDI_REQUEST Request
Definition: titypes.h:232
#define STATUS_SUCCESS
Definition: shellext.h:65
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:234
#define LockObject(Object)
Definition: titypes.h:34

Referenced by InternalSendEventHandler().