xref: /reactos/drivers/network/tcpip/include/tcpip.h (revision 4561998a)
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS TCP/IP protocol driver
4  * FILE:        include/tcpip.h
5  * PURPOSE:     TCP/IP protocol driver definitions
6  * NOTES:       Spin lock acquire order:
7  *                - Net table list lock
8  *                - Interface lock
9  *                - Interface list lock
10  *                - Prefix list lock
11  *                - Neighbor cache lock
12  *                - Route cache lock
13  */
14 
15 #pragma once
16 
17 #ifdef _MSC_VER
18 #include <basetsd.h>
19 #include <ntddk.h>
20 #include <windef.h>
21 #include <ndis.h>
22 #include <tdikrnl.h>
23 #include <tdiinfo.h>
24 #else
25 #include <ntddk.h>
26 #include <ndis.h>
27 #include <tdikrnl.h>
28 #include <tdiinfo.h>
29 #endif
30 
31 #include <debug.h>
32 
33 #define TAG_STRING	' RTS' /* string */
34 
35 /* Define _NTTEST_ to make test version. Device names are prefixed with
36    'NT' to allow the driver to run side by side with MS TCP/IP driver */
37 //#define _NTTEST_
38 
39 /* FIXME: The following should be moved to ntddk.h or tdi headers */
40 #ifndef _MSC_VER
41 
42 #ifndef IO_NETWORK_INCREMENT
43 #define IO_NETWORK_INCREMENT 2
44 #endif
45 
46 #endif
47 
48 #ifdef _MSC_VER
49 /* EXPORTED is already defined ddk/defines.h */
50 #define EXPORTED __declspec(dllexport)
51 
52 #endif
53 
54 #include <titypes.h>
55 #include <ticonsts.h>
56 
57 /* Macros */
58 
59 #define MIN(value1, value2) \
60     ((value1 < value2)? value1 : value2)
61 
62 #define MAX(value1, value2) \
63     ((value1 > value2)? value1 : value2)
64 
65 #define NDIS_BUFFER_TAG FOURCC('n','b','u','f')
66 #define NDIS_PACKET_TAG FOURCC('n','p','k','t')
67 
68 #if defined(i386) || defined(_AMD64_) || defined(_ARM_)
69 
70 /* DWORD network to host byte order conversion for i386 */
71 #define DN2H(dw) \
72     ((((dw) & 0xFF000000L) >> 24) | \
73 	 (((dw) & 0x00FF0000L) >> 8) | \
74 	 (((dw) & 0x0000FF00L) << 8) | \
75 	 (((dw) & 0x000000FFL) << 24))
76 
77 /* DWORD host to network byte order conversion for i386 */
78 #define DH2N(dw) \
79 	((((dw) & 0xFF000000L) >> 24) | \
80 	 (((dw) & 0x00FF0000L) >> 8) | \
81 	 (((dw) & 0x0000FF00L) << 8) | \
82 	 (((dw) & 0x000000FFL) << 24))
83 
84 /* WORD network to host order conversion for i386 */
85 #define WN2H(w) \
86 	((((w) & 0xFF00) >> 8) | \
87 	 (((w) & 0x00FF) << 8))
88 
89 /* WORD host to network byte order conversion for i386 */
90 #define WH2N(w) \
91 	((((w) & 0xFF00) >> 8) | \
92 	 (((w) & 0x00FF) << 8))
93 
94 #else /* defined(i386) || defined(_AMD64_) || defined(_ARM_) */
95 
96 #error Unsupported architecture
97 
98 /* DWORD network to host byte order conversion for other architectures */
99 #define DN2H(dw) \
100     (dw)
101 
102 /* DWORD host to network byte order conversion for other architectures */
103 #define DH2N(dw) \
104     (dw)
105 
106 /* WORD network to host order conversion for other architectures */
107 #define WN2H(w) \
108     (w)
109 
110 /* WORD host to network byte order conversion for other architectures */
111 #define WH2N(w) \
112     (w)
113 
114 #endif /* defined(i386) || defined(_AMD64_) || defined(_ARM_) */
115 
116 /* AF_INET and other things Arty likes to use ;) */
117 #define AF_INET 2
118 #define SOCK_STREAM 1
119 
120 /* Should use TDI structure, but Arty wants to keep BSD style */
121 typedef unsigned char u_char;
122 typedef unsigned short u_short;
123 typedef unsigned int u_int;
124 typedef unsigned long u_long;
125 struct in_addr
126 {
127     union
128     {
129         struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
130         struct { u_short s_w1,s_w2; } S_un_w;
131         u_long S_addr;
132     } S_un;
133 #define s_addr  S_un.S_addr
134 #define s_host  S_un.S_un_b.s_b2
135 #define s_net   S_un.S_un_b.s_b1
136 #define s_imp   S_un.S_un_w.s_w2
137 #define s_impno S_un.S_un_b.s_b4
138 #define s_lh    S_un.S_un_b.s_b3
139 };
140 
141 #define __LWIP_INET_H__
142 #include "lwip/sockets.h"
143 
144 /* Sufficient information to manage the entity list */
145 typedef struct {
146     UINT tei_entity;
147     UINT tei_instance;
148     PVOID context;
149     UINT flags;
150 } TDIEntityInfo;
151 
152 #ifndef htons
153 #define htons(x) WH2N(x)
154 #endif
155 
156 /* Global variable */
157 extern PDEVICE_OBJECT TCPDeviceObject;
158 extern PDEVICE_OBJECT UDPDeviceObject;
159 extern PDEVICE_OBJECT IPDeviceObject;
160 extern PDEVICE_OBJECT RawIPDeviceObject;
161 extern LIST_ENTRY InterfaceListHead;
162 extern KSPIN_LOCK InterfaceListLock;
163 extern LIST_ENTRY AddressFileListHead;
164 extern KSPIN_LOCK AddressFileListLock;
165 extern NDIS_HANDLE GlobalPacketPool;
166 extern NDIS_HANDLE GlobalBufferPool;
167 extern KSPIN_LOCK EntityListLock;
168 extern TDIEntityInfo *EntityList;
169 extern ULONG EntityCount;
170 extern ULONG EntityMax;
171 
172 extern NTSTATUS TiGetProtocolNumber( PUNICODE_STRING FileName,
173 				     PULONG Protocol );
174 
175 /* EOF */
176