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.

385 lines
14 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. bmbuild.w
  5. Abstract:
  6. BMBuilder protocol.
  7. Author:
  8. Bassam Tabbara (bassamt) 03-December-2000
  9. Revision History:
  10. Bassam Tabbara (bassamt) 08-August-2001 Created from bmpkt.w
  11. Brian Moore (brimo) 14-May-2002 Updated to fix alignment issues and general cleanup
  12. --*/
  13. #ifndef _BMBUILD_
  14. #define _BMBUILD_
  15. //
  16. // common macros
  17. //
  18. #define BMBUILD_FIELD_OFFSET(type, field) ((ULONG_PTR)&(((type *)0)->field))
  19. //
  20. // Ports
  21. //
  22. #define BMBUILD_SERVER_PORT_DEFAULT 0xAC0F // hex value in network byte order. 4012
  23. #define BMBUILD_SERVER_PORT_STRING L"4012"
  24. //
  25. // Error Codes
  26. //
  27. #define BMBUILD_E(d) (USHORT)((d) | 0x8000)
  28. #define BMBUILD_S(d) (USHORT)(d)
  29. #define BMBUILD_IS_E(d) ((d) & 0x8000)
  30. #define BMBUILD_S_REQUEST_COMPLETE BMBUILD_S(1) // Request is complete.
  31. #define BMBUILD_S_REQUEST_PENDING BMBUILD_S(2) // Request was accepted and is pending.
  32. #define BMBUILD_E_WRONGVERSION BMBUILD_E(1) // unsupported BMBUILD packet version
  33. #define BMBUILD_E_BUSY BMBUILD_E(2) // Server is busy
  34. #define BMBUILD_E_ACCESSDENIED BMBUILD_E(3) // authentication failed
  35. #define BMBUILD_E_ILLEGAL_OPCODE BMBUILD_E(4) // unsupported packet type
  36. #define BMBUILD_E_PRODUCT_NOT_FOUND BMBUILD_E(5) // product not found on server
  37. #define BMBUILD_E_BUILD_FAILED BMBUILD_E(6) // Image building failed.
  38. #define BMBUILD_E_INVALID_PACKET BMBUILD_E(7) // Invalid packet.
  39. //
  40. // Device information
  41. //
  42. //
  43. // Helper macros to help parse and build a busdevfunc
  44. //
  45. #define PCI_TO_BUSDEVFUNC(_b, _d, _f) ((USHORT)(((_b) << 8) | ((_d) << 3) | (_f)))
  46. #define BUSDEVFUNC_TO_BUS(_bdf) ((UCHAR)(((_bdf) >> 8) & 0xFF))
  47. #define BUSDEVFUNC_TO_DEVICE(_bdf) ((UCHAR)(((_bdf) >> 3) & 0x1F))
  48. #define BUSDEVFUNC_TO_FUNCTION(_bdf) ((UCHAR)((_bdf) & 0x07))
  49. #define BMBUILD_DEVICE_TYPE_PCI 0x02
  50. #define BMBUILD_DEVICE_TYPE_PNP 0x03
  51. #define BMBUILD_DEVICE_TYPE_CARDBUS 0x04
  52. #define BMBUILD_DEVICE_TYPE_PCI_BRIDGE 0x05
  53. #include <pshpack1.h>
  54. typedef struct _DEVICE_INFO {
  55. UCHAR DeviceType;
  56. UCHAR Reserved;
  57. union {
  58. struct {
  59. USHORT BusDevFunc;
  60. USHORT VendorID;
  61. USHORT DeviceID;
  62. UCHAR BaseClass;
  63. UCHAR SubClass;
  64. UCHAR ProgIntf;
  65. UCHAR RevisionID;
  66. USHORT SubVendorID;
  67. USHORT SubDeviceID;
  68. } pci;
  69. struct {
  70. USHORT BusDevFunc;
  71. USHORT VendorID;
  72. USHORT DeviceID;
  73. UCHAR BaseClass;
  74. UCHAR SubClass;
  75. UCHAR ProgIntf;
  76. UCHAR RevisionID;
  77. UCHAR PrimaryBus;
  78. UCHAR SecondaryBus;
  79. UCHAR SubordinateBus;
  80. UCHAR Reserved;
  81. } pci_bridge;
  82. struct {
  83. USHORT Reserved1;
  84. ULONG EISADevID;
  85. UCHAR BaseClass;
  86. UCHAR SubClass;
  87. UCHAR ProgIntf;
  88. UCHAR CardSelNum;
  89. ULONG Reserved2;
  90. } pnp;
  91. } info;
  92. } DEVICE_INFO, * PDEVICE_INFO;
  93. //
  94. // IP Address
  95. //
  96. typedef union {
  97. ULONG Address;
  98. UCHAR IPv4Addr[4];
  99. UCHAR IPv6Addr[16];
  100. } IP_ADDRESS;
  101. //
  102. // BM Request / Response Packets.
  103. //
  104. #define BMBUILD_OPCODE_DISCOVER 0x01
  105. #define BMBUILD_OPCODE_ACCEPT 0x02
  106. #define BMBUILD_OPCODE_REQUEST 0x03
  107. #define BMBUILD_OPCODE_RESPONSE 0x04
  108. //
  109. // Flags
  110. //
  111. #define BMBUILD_FLAG_IPV6 0x00000001 // All ip addresses are IPv6 (IPv4 is default)
  112. //
  113. // Version info
  114. //
  115. #define BMBUILD_PACKET_VERSION 1
  116. //
  117. // common packet sizes
  118. //
  119. #define BMBUILD_COMMON_PACKET_LENGTH (sizeof(BMBUILD_COMMON_PACKET))
  120. //
  121. // The common packet structure shared among all the packets
  122. //
  123. typedef struct _BMBUILD_COMMON_PACKET {
  124. UCHAR Version; // Must be set to BMBUILD_PACKET_VERSION
  125. UCHAR OpCode; // Must be set to BMBUILD_OPCODE_XXXXXXXX
  126. USHORT Reserved; // Unused. Must be zero.
  127. ULONG XID; // Transaction ID. Unique for a request / response session.
  128. } BMBUILD_COMMON_PACKET, * PBMBUILD_COMMON_PACKET;
  129. //
  130. // DISCOVER packet. This is sent to the build server from
  131. // a client using either broadcast, multicast or unicast.
  132. //
  133. typedef struct _BMBUILD_DISCOVER_PACKET {
  134. UCHAR Version; // Must be set to BMBUILD_PACKET_VERSION
  135. UCHAR OpCode; // Must be set to BMBUILD_OPCODE_DISCOVER
  136. USHORT Reserved; // Unused. Must be zero.
  137. ULONG XID; // Transaction ID. Unique for a request / response session.
  138. GUID MachineGuid; // Unique machine identity. Usually SMBIOS UUID.
  139. GUID ProductGuid; // GUID of the product requested for building
  140. } BMBUILD_DISCOVER_PACKET, * PBMBUILD_DISCOVER_PACKET;
  141. //
  142. // ACCEPT packet. This is sent from the build server
  143. // to a client in response to a DISCOVER packet. The accept
  144. // acknowledges that the boot server is capable of building the
  145. // product requested in the DISCOVER packet.
  146. //
  147. typedef struct _BMBUILD_ACCEPT_PACKET {
  148. UCHAR Version; // Must be set to BMBUILD_PACKET_VERSION
  149. UCHAR OpCode; // Must be set to BMBUILD_OPCODE_ACCEPT
  150. USHORT Reserved; // Unused. Must be zero.
  151. ULONG XID; // Transaction ID. Matchs the XID from the discover packet.
  152. ULONG BuildTime; // Approximate time (in secs) that the server expects
  153. // for building this image. If the server has
  154. // the image cached, this is set to zero.
  155. } BMBUILD_ACCEPT_PACKET, * PBMBUILD_ACCEPT_PACKET;
  156. //
  157. // REQUEST packet. This is a request to build an image that is
  158. // sent form the client to the build server.
  159. //
  160. #define BMBUILD_REQUEST_FIXED_PACKET_LENGTH (USHORT)(BMBUILD_FIELD_OFFSET(BMBUILD_REQUEST_PACKET, Data))
  161. #define BMBUILD_MAX_DEVICES(size) (USHORT)((size - BMBUILD_REQUEST_FIXED_PACKET_LENGTH) / sizeof(DEVICE_INFO))
  162. typedef struct _BMBUILD_REQUEST_PACKET {
  163. UCHAR Version; // Must be set to BMBUILD_PACKET_VERSION
  164. UCHAR OpCode; // Must be set to BMBUILD_OPCODE_REQUEST
  165. USHORT Reserved; // Unused. Must be set to zero.
  166. ULONG XID; // Transaction ID. Unique for a request / response session.
  167. //
  168. // Information about the client
  169. //
  170. GUID MachineGuid; // Unique machine identity. Usually SMBIOS UUID.
  171. GUID ProductGuid; // GUID of the product requested for building
  172. ULONG Flags; // BMBUILD_FLAG_XXXXXXXX
  173. USHORT Architecture; // See NetPc spec for definitions for x86, Alpha, etc.
  174. USHORT DeviceOffset; // Offset to start of Device information from packet start
  175. USHORT DeviceCount; // Count of devices
  176. USHORT PrimaryNicIndex; // Index into device array that is the primary NIC on the client machine
  177. USHORT HalDataOffset; // Offset into a string within the variable data section.
  178. // The string describes the HAL to be used.
  179. USHORT HalDataLength; // Length of the hal string
  180. UCHAR Data[1]; // start of variable length data
  181. } BMBUILD_REQUEST_PACKET, * PBMBUILD_REQUEST_PACKET;
  182. //
  183. // RESPONSE packet. This is a response to the REQUEST that is
  184. // sent from the build server to the client.
  185. //
  186. #define BMBUILD_RESPONSE_FIXED_PACKET_LENGTH (USHORT)(BMBUILD_FIELD_OFFSET(BMBUILD_RESPONSE_PACKET, Data))
  187. typedef struct _BMBUILD_RESPONSE_PACKET {
  188. UCHAR Version; // Must be set to BMBUILD_PACKET_VERSION
  189. UCHAR OpCode; // Must be set to BMBUILD_OPCODE_RESPONSE
  190. USHORT Reserved; // Unused. Must be zero.
  191. ULONG XID; // Transaction ID. Matches the XID from the request packet.
  192. USHORT Status; // Status code, from BMBUILD_E_XXXXXXXX or BMBUILD_S_XXXXXXXX
  193. USHORT WaitTime; // Wait time in secs
  194. ULONG Flags; // BMBUILD_FLAG_XXXXXXXX
  195. USHORT ImagePathOffset; // Offset of the name and path of the image in this packet.
  196. USHORT ImagePathLength; // Length of the image path
  197. ULONG ImageFileOffset; // Specifies the offset into the downloaded file
  198. // at which the actual disk image begins.
  199. // If not specified, 0 is used.
  200. LONGLONG ImageFileSize; // Specifies the size of the actual disk image.
  201. // If not specified, the size of the
  202. // downloaded file minus the offset to the
  203. // image (RDIMAGEOFFSET) is used.
  204. IP_ADDRESS TFTPAddr; // TFTP server address to download image from. (network byte order)
  205. //
  206. // Multicast download information
  207. //
  208. IP_ADDRESS MTFTPAddr; // MTFTP IP address. zero if TFTP is to be used. (network byte order)
  209. USHORT MTFTPCPort; // Multicast Client port (network byte order)
  210. USHORT MTFTPSPort; // Multicast Server port (network byte order)
  211. USHORT MTFTPTimeout; // Multicast Timeout before starting a new transfer
  212. USHORT MTFTPDelay; // Multicast delay before restarting a transfer
  213. LONGLONG MTFTPFileSize; // File size in bytes (required for multicast transfers)
  214. LONGLONG MTFTPChunkSize; // Size of each chunk used to assemble the bigger file.
  215. UCHAR Data[1]; // start of variable length data
  216. } BMBUILD_RESPONSE_PACKET, * PBMBUILD_RESPONSE_PACKET;
  217. #include <poppack.h>
  218. //
  219. // BMBUILD/RAMDISK Compression.
  220. //
  221. // This is a generic compression algorithm which actually has nothing
  222. // to do with either the builder or ramdisk but is being used to compress
  223. // the image sent over the wire and to expand it at the receiving end.
  224. //
  225. // The file compression format may change, the format is given in a file
  226. // header. Version 1 uses the Xpress compression/decompression code
  227. // which is already used in the osloader for hibernate files. (The file
  228. // format is not the same as hibernation files which need to describe the
  229. // page layout of data as it is read into memory).
  230. //
  231. // The (version 1) compressed file is in the form-
  232. //
  233. // ---------------------------------------------------------------------
  234. // | RAMZ |B|zzzzzzzzzzzzzzzz|B|zz|B|zzzzzzzzzzzzzzzzzzzz|B|zzzzzzz|
  235. // ---------------------------------------------------------------------
  236. //
  237. // Where
  238. // RAMZ is a 512 byte file header of type BMBUILD_COMPRESSED_HEADER.
  239. // The header contains such things as version information,
  240. // the uncompressed file size and the block size used for
  241. // compression. The header block ends with a signature 'RAMZ'
  242. // which is used by the loader (or any other decompressor)
  243. // to recognize the image. The signature is chosen to collide
  244. // with and differ from a normal disk signature 55 AA which is
  245. // located in the last two bytes of the first 512 byte block
  246. // of a disk.
  247. // B is a block header which contains the compressed and
  248. // uncompressed sizes of the data and the running checksum
  249. // of the compressed data. The block header is always aligned
  250. // on the nearest BMBUILD_COMPRESSED_BLOCK_PAD byte boundary.
  251. // BMBUILD_COMPRESSED_BLOCK_PAD should be set to allow for
  252. // natural alignment of the members of the block header.
  253. // The block header is of type BMBUILD_COMPRESSED_BLOCK.
  254. // zzz is compressed data. zzz can actually be uncompressed
  255. // data in the event that compression did not have a positive
  256. // effect.
  257. //
  258. // Note: In the event that the compressed data is no smaller than the
  259. // uncompressed data, the uncompressed data is used and the block
  260. // header fields CompressedSize and UncompressedSize will be equal.
  261. // (The checksum still applies to the data in the file, which in
  262. // this case happens to be uncompressed).
  263. //
  264. // When reading the file, blocks should be processed until the amount
  265. // of data decompressed is equal to the UncompressedSize in the file
  266. // header. (Note: There will not be more data than the UncompressedSize).
  267. //
  268. // The checksum algorithm used is compatible with tcpxsum (on a per block
  269. // basis) as long as the size of a blocks being compressed is less than 128KB.
  270. // The incompatibility exists because the sum of the carrys is not folded
  271. // into the 16 bit checksum until the entire buffer has been processed.
  272. //
  273. // The checksum is calculated as a running total. That is, the checksum
  274. // of one block is the starting value for the checksum of the next block.
  275. // This provides a checksum for each block which is order dependent and
  276. // the checksum for the last block is for all the zzz data in the image.
  277. //
  278. typedef struct _BMBUILD_COMPRESSED_BLOCK {
  279. ULONG CompressedSize;
  280. ULONG UncompressedSize;
  281. ULONG CheckSum;
  282. } BMBUILD_COMPRESSED_BLOCK, *PBMBUILD_COMPRESSED_BLOCK;
  283. typedef struct _BMBUILD_COMPRESSED_HEADER {
  284. ULONG Version;
  285. ULONG CompressionFormat;
  286. ULONGLONG UncompressedSize;
  287. ULONGLONG BlockSize;
  288. UCHAR Fill[512-24-4]; // pad so Signature is at 512-4.
  289. ULONG Signature;
  290. } BMBUILD_COMPRESSED_HEADER, *PBMBUILD_COMPRESSED_HEADER;
  291. #define BMBUILD_COMPRESSED_SIGNATURE 0x5a4d4152
  292. #define BMBUILD_COMPRESSED_VERSION 0x00000001
  293. #define BMBUILD_COMPRESSED_FMT_XPRESS 0x00000001
  294. #define BMBUILD_COMPRESSED_BLOCK_PAD 0x00000004
  295. #define BMBUILD_COMPRESSED_BLOCK_MAX 0x00010000
  296. #endif // _BMPKT_