1 #ifndef _LWIP_GLUE_H_ 2 #define _LWIP_GLUE_H_ 3 4 #include <lwip/tcp.h> 5 #include <lwip/pbuf.h> 6 #include <lwip/ip_addr.h> 7 #include <tcpip.h> 8 9 #ifndef LWIP_TAG 10 #define LWIP_TAG 'PIwl' 11 #define LWIP_MESSAGE_TAG 'sMwl' 12 #define LWIP_QUEUE_TAG 'uQwl' 13 #endif 14 15 typedef struct tcp_pcb* PTCP_PCB; 16 17 typedef struct _QUEUE_ENTRY 18 { 19 struct pbuf *p; 20 ULONG Offset; 21 LIST_ENTRY ListEntry; 22 } QUEUE_ENTRY, *PQUEUE_ENTRY; 23 24 struct lwip_callback_msg 25 { 26 /* Synchronization */ 27 KEVENT Event; 28 29 /* Input */ 30 union { 31 struct { 32 PVOID Arg; 33 } Socket; 34 struct { 35 struct tcp_pcb* pcb; 36 } FreeSocket; 37 struct { 38 PCONNECTION_ENDPOINT Connection; 39 ip_addr_t *IpAddress; 40 u16_t Port; 41 } Bind; 42 struct { 43 PCONNECTION_ENDPOINT Connection; 44 u8_t Backlog; 45 } Listen; 46 struct { 47 PCONNECTION_ENDPOINT Connection; 48 void *Data; 49 u16_t DataLength; 50 } Send; 51 struct { 52 PCONNECTION_ENDPOINT Connection; 53 ip_addr_t *IpAddress; 54 u16_t Port; 55 } Connect; 56 struct { 57 PCONNECTION_ENDPOINT Connection; 58 int shut_rx; 59 int shut_tx; 60 } Shutdown; 61 struct { 62 PCONNECTION_ENDPOINT Connection; 63 int Callback; 64 } Close; 65 } Input; 66 67 /* Output */ 68 union { 69 struct { 70 struct tcp_pcb *NewPcb; 71 } Socket; 72 struct { 73 err_t Error; 74 } Bind; 75 struct { 76 struct tcp_pcb *NewPcb; 77 } Listen; 78 struct { 79 err_t Error; 80 u32_t Information; 81 } Send; 82 struct { 83 err_t Error; 84 } Connect; 85 struct { 86 err_t Error; 87 } Shutdown; 88 struct { 89 err_t Error; 90 } Close; 91 } Output; 92 }; 93 94 NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received); 95 96 /* External TCP event handlers */ 97 extern void TCPConnectEventHandler(void *arg, const err_t err); 98 extern void TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb); 99 extern void TCPSendEventHandler(void *arg, const u16_t space); 100 extern void TCPFinEventHandler(void *arg, const err_t err); 101 extern void TCPRecvEventHandler(void *arg); 102 103 /* TCP functions */ 104 PTCP_PCB LibTCPSocket(void *arg); 105 VOID LibTCPFreeSocket(PTCP_PCB pcb); 106 err_t LibTCPBind(PCONNECTION_ENDPOINT Connection, ip4_addr_t *const ipaddr, const u16_t port); 107 PTCP_PCB LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog); 108 err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, ULONG *sent, const int safe); 109 err_t LibTCPConnect(PCONNECTION_ENDPOINT Connection, ip4_addr_t *const ipaddr, const u16_t port); 110 err_t LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx); 111 err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback); 112 113 err_t LibTCPGetPeerName(PTCP_PCB pcb, ip4_addr_t *const ipaddr, u16_t *const port); 114 err_t LibTCPGetHostName(PTCP_PCB pcb, ip4_addr_t *const ipaddr, u16_t *const port); 115 void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg); 116 void LibTCPSetNoDelay(PTCP_PCB pcb, BOOLEAN Set); 117 void LibTCPGetSocketStatus(PTCP_PCB pcb, PULONG State); 118 119 /* IP functions */ 120 void LibIPInsertPacket(void *ifarg, const void *const data, const u32_t size); 121 void LibIPInitialize(void); 122 void LibIPShutdown(void); 123 124 #endif 125