Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

461 lines
11 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. netfs.h
  5. Abstract:
  6. This module defines globally used procedure and data structures used
  7. by net boot.
  8. Author:
  9. Chuck Lenzmeier (chuckl) 09-Jan-1997
  10. Revision History:
  11. --*/
  12. #ifndef _NETFS_
  13. #define _NETFS_
  14. #include <undi_api.h>
  15. //
  16. // Progress bar update function
  17. //
  18. VOID
  19. BlUpdateProgressBar(
  20. ULONG fPercentage
  21. );
  22. //////////////////////////////////////////////////////////////////////////////
  23. //
  24. // ROM layer definitions.
  25. //
  26. //////////////////////////////////////////////////////////////////////////////
  27. extern UCHAR NetLocalHardwareAddress[16];
  28. extern USHORT NetUnicastUdpDestinationPort;
  29. #if 0
  30. extern USHORT NetMulticastUdpDestinationPort;
  31. extern ULONG NetMulticastUdpDestinationAddress;
  32. extern USHORT NetMulticastUdpSourcePort;
  33. extern ULONG NetMulticastUdpSourceAddress;
  34. #endif
  35. VOID
  36. RomSetBroadcastStatus(
  37. BOOLEAN Enable
  38. );
  39. VOID
  40. RomSetReceiveStatus (
  41. IN USHORT UnicastUdpDestinationPort
  42. #if 0
  43. ,
  44. IN USHORT MulticastUdpDestinationPort,
  45. IN ULONG MulticastUdpDestinationAddress,
  46. IN USHORT MulticastUdpSourcePort,
  47. IN ULONG MulticastUdpSourceAddress
  48. #endif
  49. );
  50. ULONG
  51. RomSendUdpPacket (
  52. IN PVOID Buffer,
  53. IN ULONG Length,
  54. IN ULONG RemoteHost,
  55. IN USHORT RemotePort
  56. );
  57. ULONG
  58. RomReceiveUdpPacket (
  59. IN PVOID Buffer,
  60. IN ULONG Length,
  61. IN ULONG Timeout,
  62. OUT PULONG RemoteHost,
  63. OUT PUSHORT RemotePort
  64. );
  65. ULONG
  66. RomGetNicType (
  67. OUT t_PXENV_UNDI_GET_NIC_TYPE *NicType
  68. );
  69. ULONG
  70. RomMtftpReadFile (
  71. IN PUCHAR FileName,
  72. IN PVOID Buffer,
  73. IN ULONG BufferLength,
  74. IN ULONG ServerIPAddress, // network byte order
  75. IN ULONG MCastIPAddress, // network byte order
  76. IN USHORT MCastCPort, // network byte order
  77. IN USHORT MCastSPort, // network byte order
  78. IN USHORT Timeout,
  79. IN USHORT Delay,
  80. OUT PULONG DownloadSize
  81. );
  82. //////////////////////////////////////////////////////////////////////////////
  83. //
  84. // TFTP layer definitions.
  85. //
  86. //////////////////////////////////////////////////////////////////////////////
  87. typedef struct _TFTP_REQUEST {
  88. PUCHAR RemoteFileName;
  89. ULONG ServerIpAddress;
  90. PUCHAR MemoryAddress;
  91. ULONG MaximumLength;
  92. ULONG BytesTransferred;
  93. USHORT Operation;
  94. #if defined(REMOTE_BOOT_SECURITY)
  95. ULONG SecurityHandle;
  96. #endif // defined(REMOTE_BOOT_SECURITY)
  97. TYPE_OF_MEMORY MemoryType;
  98. // If TRUE will update the progress bar
  99. BOOLEAN ShowProgress;
  100. } TFTP_REQUEST, *PTFTP_REQUEST;
  101. NTSTATUS
  102. TftpInit (
  103. VOID
  104. );
  105. NTSTATUS
  106. TftpGetPut (
  107. IN PTFTP_REQUEST Request
  108. );
  109. #if defined(REMOTE_BOOT_SECURITY)
  110. NTSTATUS
  111. TftpLogin (
  112. IN PUCHAR Domain,
  113. IN PUCHAR Name,
  114. IN PUCHAR OwfPassword,
  115. IN ULONG ServerIpAddress,
  116. OUT PULONG LoginHandle
  117. );
  118. NTSTATUS
  119. TftpLogoff (
  120. IN ULONG ServerIpAddress,
  121. IN ULONG LoginHandle
  122. );
  123. NTSTATUS
  124. TftpSignString (
  125. IN PUCHAR String,
  126. OUT PUCHAR * Sign,
  127. OUT ULONG * SignLength
  128. );
  129. #endif // defined(REMOTE_BOOT_SECURITY)
  130. //
  131. // This file contains the definitions for the TFTP connection control
  132. // block, which contains all the information pertaining to a connection.
  133. // A conn structure is allocated at connection open time and retained
  134. // until the connection is closed. The routines in the file conn.c
  135. // are sufficient for dealing with connections.
  136. // It also contains the structure definition for tftp packets.
  137. //
  138. //
  139. // Connection control block.
  140. //
  141. typedef struct _CONNECTION {
  142. ULONG BlockSize; // block size for transfer
  143. PVOID LastSentPacket; // previous packet sent
  144. ULONG LastSentLength; // size of previous packet
  145. ULONG NextRetransmit; // when to retransmit
  146. ULONG Retransmissions; // number of retransmits
  147. ULONG Timeout; // retransmit timeout
  148. PVOID CurrentPacket; // current packet (send or rcv)
  149. ULONG CurrentLength; // current packet len
  150. PVOID LastReceivedPacket; // last received packet
  151. ULONG LastReceivedLength; // size of last rcvd. packet
  152. ULONG RemoteHost; // remote host IP address
  153. USHORT RemotePort; // remote port for connection
  154. USHORT LocalPort; // local port for connection
  155. USHORT Operation; // direction of transfer
  156. USHORT BlockNumber; // next block number
  157. BOOLEAN Synced; // conn synchronized flag
  158. } CONNECTION, *PCONNECTION;
  159. #include <packon.h>
  160. #define ETHERNET_ADDRESS_LENGTH 6
  161. #define COPY_ETHERNET_ADDRESS(_d,_s) RtlCopyMemory( (_d), (_s), ETHERNET_ADDRESS_LENGTH );
  162. #define COPY_IP_ADDRESS(_d,_s) RtlCopyMemory( (_d), (_s), sizeof(ULONG) )
  163. #define COMPARE_IP_ADDRESSES(_a,_b) RtlEqualMemory( (_a), (_b), sizeof(ULONG) )
  164. typedef struct _TFTP_HEADER {
  165. USHORT Opcode; // packet type
  166. USHORT BlockNumber; // block number
  167. } TFTP_HEADER, *PTFTP_HEADER;
  168. typedef struct _TFTP_PACKET {
  169. TFTP_HEADER ;
  170. UCHAR Data[1];
  171. } TFTP_PACKET, *PTFTP_PACKET;
  172. #include <packoff.h>
  173. //
  174. // Connection constants.
  175. //
  176. #define TFTP_PORT 0x4500 // big-endian 69
  177. #define TIMEOUT 1 // initial retransmit timeout
  178. #define INITIAL_TIMEOUT 1 // initial connection timeout
  179. #define MAX_TIMEOUT 8 // max. retransmit timeout
  180. #define MAX_RETRANS 8 // max. no. of retransmits
  181. #define DEFAULT_BLOCK_SIZE 1432 // size of data portion of tftp pkt
  182. //
  183. // ideally this should be the commented out size. But we overload the
  184. // use of this constant to also be the size we use for udp receives.
  185. // Since we can receive larger packets than this when we get the driver
  186. // info packet, we need to bump up this buffer size. ideally we would
  187. // allocate enough space at runtime, but this is a safer fix at this point
  188. // in the product.
  189. //
  190. //#define MAXIMUM_TFTP_PACKET_LENGTH (sizeof(TFTP_HEADER) + DEFAULT_BLOCK_SIZE)
  191. #define MAXIMUM_TFTP_PACKET_LENGTH (4096)
  192. #define SWAP_WORD(_w) (USHORT)((((_w) << 8) & 0xff00) | (((_w) >> 8) & 0x00ff))
  193. #define SWAP_DWORD(_dw) (ULONG)((((_dw) << 24) & 0xff000000) | \
  194. (((_dw) << 8) & 0x00ff0000) | \
  195. (((_dw) >> 8) & 0x0000ff00) | \
  196. (((_dw) >> 24) & 0x000000ff))
  197. //
  198. // Packet types.
  199. //
  200. // N.B. The constants below are defined as big-endian USHORTs.
  201. //
  202. #define TFTP_RRQ 0x0100 // Read Request
  203. #define TFTP_WRQ 0x0200 // Write Request
  204. #define TFTP_DATA 0x0300 // Data block
  205. #define TFTP_DACK 0x0400 // Data Acknowledge
  206. #define TFTP_ERROR 0x0500 // Error
  207. #define TFTP_OACK 0x0600 // Options Acknowledge
  208. //
  209. // Values for error codes in ERROR packets.
  210. //
  211. // N.B. The constants below are defined as big-endian USHORTs.
  212. //
  213. #define TFTP_ERROR_UNDEFINED 0x0000
  214. #define TFTP_ERROR_FILE_NOT_FOUND 0x0100
  215. #define TFTP_ERROR_ACCESS_VIOLATION 0x0200
  216. #define TFTP_ERROR_DISK_FULL 0x0300
  217. #define TFTP_ERROR_ILLEGAL_OPERATION 0x0400
  218. #define TFTP_ERROR_UNKNOWN_TRANSFER_ID 0x0500
  219. #define TFTP_ERROR_FILE_EXISTS 0x0600
  220. #define TFTP_ERROR_NO_SUCH_USER 0x0700
  221. #define TFTP_ERROR_OPTION_NEGOT_FAILED 0x0800
  222. //
  223. // Global variables.
  224. //
  225. extern CONNECTION NetTftpConnection;
  226. extern UCHAR NetTftpPacket[3][MAXIMUM_TFTP_PACKET_LENGTH];
  227. //
  228. // External declarations.
  229. //
  230. NTSTATUS
  231. ConnInitialize (
  232. OUT PCONNECTION *Connection,
  233. IN USHORT Operation,
  234. IN ULONG RemoteHost,
  235. IN USHORT RemotePort,
  236. IN PUCHAR Filename,
  237. IN ULONG BlockSize,
  238. #if defined(REMOTE_BOOT_SECURITY)
  239. IN OUT PULONG SecurityHandle,
  240. #endif // defined(REMOTE_BOOT_SECURITY)
  241. IN OUT PULONG FileSize
  242. );
  243. NTSTATUS
  244. ConnReceive (
  245. IN PCONNECTION Connection,
  246. OUT PTFTP_PACKET *Packet
  247. );
  248. PTFTP_PACKET
  249. ConnPrepareSend (
  250. IN PCONNECTION Connection
  251. );
  252. VOID
  253. ConnAck (
  254. IN PCONNECTION Connection
  255. );
  256. VOID
  257. ConnSendPacket (
  258. IN PCONNECTION Connection,
  259. IN PVOID Packet,
  260. IN ULONG Length
  261. );
  262. NTSTATUS
  263. ConnWait (
  264. IN PCONNECTION Connection,
  265. IN USHORT Opcode,
  266. OUT PTFTP_PACKET *Packet OPTIONAL
  267. );
  268. BOOLEAN
  269. ConnRetransmit (
  270. IN PCONNECTION Connection,
  271. IN BOOLEAN Timeout
  272. );
  273. NTSTATUS
  274. ConnSend (
  275. IN PCONNECTION Connection,
  276. IN ULONG Length
  277. );
  278. NTSTATUS
  279. ConnWaitForFinalAck (
  280. IN PCONNECTION Connection
  281. );
  282. VOID
  283. ConnError (
  284. PCONNECTION Connection,
  285. ULONG RemoteHost,
  286. USHORT RemotePort,
  287. USHORT ErrorCode,
  288. PUCHAR ErrorMessage
  289. );
  290. ULONG
  291. ConnSafeAtol (
  292. IN PUCHAR Buffer,
  293. IN PUCHAR BufferEnd
  294. );
  295. ULONG
  296. ConnItoa (
  297. IN ULONG Value,
  298. OUT PUCHAR Buffer
  299. );
  300. //
  301. // UDP definitions.
  302. //
  303. extern USHORT UdpUnicastDestinationPort;
  304. USHORT
  305. UdpAssignUnicastPort (
  306. VOID
  307. );
  308. #if 0
  309. VOID
  310. UdpSetMulticastPort (
  311. IN USHORT DestinationPort,
  312. IN ULONG DestinationAddress,
  313. IN USHORT SourcePort,
  314. IN ULONG SourceAddress
  315. );
  316. #endif
  317. ULONG
  318. UdpReceive (
  319. IN PVOID Buffer,
  320. IN ULONG BufferLength,
  321. OUT PULONG RemoteHost,
  322. OUT PUSHORT RemotePort,
  323. IN ULONG Timeout
  324. );
  325. ULONG
  326. UdpSend (
  327. IN PVOID Buffer,
  328. IN ULONG BufferLength,
  329. IN ULONG RemoteHost,
  330. IN USHORT RemotePort
  331. );
  332. ULONG
  333. tcpxsum (
  334. IN ULONG cksum,
  335. IN PUCHAR buf,
  336. IN ULONG len
  337. );
  338. #define SysGetRelativeTime ArcGetRelativeTime
  339. //////////////////////////////////////////////////////////////////////////////
  340. //
  341. // Debugging package definitions.
  342. //
  343. //////////////////////////////////////////////////////////////////////////////
  344. #if DBG
  345. extern ULONG NetDebugFlag;
  346. #define DEBUG_ERROR 0x00000001
  347. #define DEBUG_CONN_ERROR 0x00000002
  348. #define DEBUG_LOUD 0x00000004
  349. #define DEBUG_REAL_LOUD 0x00000008
  350. #define DEBUG_STATISTICS 0x00000010
  351. #define DEBUG_SEND_RECEIVE 0x00000020
  352. #define DEBUG_TRACE 0x00000040
  353. #define DEBUG_ARP 0x00000080
  354. #define DEBUG_OSC 0x00000100
  355. #define DEBUG_INITIAL_BREAK 0x80000000
  356. #undef IF_DEBUG
  357. #define IF_DEBUG(_f) if ( (NetDebugFlag & DEBUG_ ## _f) != 0 )
  358. #define DPRINT(_f,_a) IF_DEBUG(_f) DbgPrint _a
  359. #define DEBUG if ( TRUE )
  360. #else // DBG
  361. #undef IF_DEBUG
  362. #define IF_DEBUG(_f) if ( FALSE )
  363. #define DPRINT(_f,_a)
  364. #define DEBUG if ( FALSE )
  365. #endif // else DBG
  366. #endif // _NETFS_