1 /**
2  * @file ntddcdrm.h
3  * Copyright 2012, 2013 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 /* Created by Casper S. Hornstrup <chorns@users.sourceforge.net> */
25 #ifndef __NTDDCDRM_H
26 #define __NTDDCDRM_H
27 #pragma GCC system_header
28 #include <_mingw.h>
29 
30 /*
31  * CDROM IOCTL interface.
32  */
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include "ntddk.h"
39 #include "ntddstor.h"
40 
41 #define IOCTL_CDROM_BASE                  FILE_DEVICE_CD_ROM
42 
43 #define IOCTL_CDROM_CHECK_VERIFY \
44   CTL_CODE(IOCTL_CDROM_BASE, 0x0200, METHOD_BUFFERED, FILE_READ_ACCESS)
45 
46 #define IOCTL_CDROM_FIND_NEW_DEVICES \
47   CTL_CODE(IOCTL_CDROM_BASE, 0x0206, METHOD_BUFFERED, FILE_READ_ACCESS)
48 
49 #define IOCTL_CDROM_GET_CONTROL \
50   CTL_CODE(IOCTL_CDROM_BASE, 0x000D, METHOD_BUFFERED, FILE_READ_ACCESS)
51 
52 #define IOCTL_CDROM_GET_DRIVE_GEOMETRY \
53   CTL_CODE(IOCTL_CDROM_BASE, 0x0013, METHOD_BUFFERED, FILE_READ_ACCESS)
54 
55 #define IOCTL_CDROM_GET_LAST_SESSION \
56   CTL_CODE(IOCTL_CDROM_BASE, 0x000E, METHOD_BUFFERED, FILE_READ_ACCESS)
57 
58 #define IOCTL_CDROM_GET_VOLUME \
59   CTL_CODE(IOCTL_CDROM_BASE, 0x0005, METHOD_BUFFERED, FILE_READ_ACCESS)
60 
61 #define IOCTL_CDROM_PAUSE_AUDIO \
62   CTL_CODE(IOCTL_CDROM_BASE, 0x0003, METHOD_BUFFERED, FILE_READ_ACCESS)
63 
64 #define IOCTL_CDROM_PLAY_AUDIO_MSF \
65   CTL_CODE(IOCTL_CDROM_BASE, 0x0006, METHOD_BUFFERED, FILE_READ_ACCESS)
66 
67 #define IOCTL_CDROM_RAW_READ \
68   CTL_CODE(IOCTL_CDROM_BASE, 0x000F, METHOD_OUT_DIRECT,  FILE_READ_ACCESS)
69 
70 #define IOCTL_CDROM_READ_Q_CHANNEL \
71   CTL_CODE(IOCTL_CDROM_BASE, 0x000B, METHOD_BUFFERED, FILE_READ_ACCESS)
72 
73 #define IOCTL_CDROM_READ_TOC \
74   CTL_CODE(IOCTL_CDROM_BASE, 0x0000, METHOD_BUFFERED, FILE_READ_ACCESS)
75 
76 #define IOCTL_CDROM_READ_TOC_EX \
77   CTL_CODE(IOCTL_CDROM_BASE, 0x0015, METHOD_BUFFERED, FILE_READ_ACCESS)
78 
79 #define IOCTL_CDROM_RESUME_AUDIO \
80   CTL_CODE(IOCTL_CDROM_BASE, 0x0004, METHOD_BUFFERED, FILE_READ_ACCESS)
81 
82 #define IOCTL_CDROM_SEEK_AUDIO_MSF \
83   CTL_CODE(IOCTL_CDROM_BASE, 0x0001, METHOD_BUFFERED, FILE_READ_ACCESS)
84 
85 #define IOCTL_CDROM_SET_VOLUME \
86   CTL_CODE(IOCTL_CDROM_BASE, 0x000A, METHOD_BUFFERED, FILE_READ_ACCESS)
87 
88 #define IOCTL_CDROM_SIMBAD \
89   CTL_CODE(IOCTL_CDROM_BASE, 0x1003, METHOD_BUFFERED, FILE_READ_ACCESS)
90 
91 #define IOCTL_CDROM_STOP_AUDIO \
92   CTL_CODE(IOCTL_CDROM_BASE, 0x0002, METHOD_BUFFERED, FILE_READ_ACCESS)
93 
94 
95 #define MAXIMUM_NUMBER_TRACKS             100
96 #define MAXIMUM_CDROM_SIZE                804
97 #define MINIMUM_CDROM_READ_TOC_EX_SIZE    2
98 
99 typedef struct _TRACK_DATA {
100   UCHAR  Reserved;
101   UCHAR  Control : 4;
102   UCHAR  Adr : 4;
103   UCHAR  TrackNumber;
104   UCHAR  Reserved1;
105   UCHAR  Address[4];
106 } TRACK_DATA, *PTRACK_DATA;
107 
108 /* CDROM_DISK_DATA.DiskData flags */
109 #define CDROM_DISK_AUDIO_TRACK            0x00000001
110 #define CDROM_DISK_DATA_TRACK             0x00000002
111 
112 typedef struct _CDROM_DISK_DATA {
113   ULONG  DiskData;
114 } CDROM_DISK_DATA, *PCDROM_DISK_DATA;
115 
116 typedef struct _CDROM_PLAY_AUDIO_MSF {
117   UCHAR  StartingM;
118   UCHAR  StartingS;
119   UCHAR  StartingF;
120   UCHAR  EndingM;
121   UCHAR  EndingS;
122   UCHAR  EndingF;
123 } CDROM_PLAY_AUDIO_MSF, *PCDROM_PLAY_AUDIO_MSF;
124 
125 /* CDROM_READ_TOC_EX.Format constants */
126 #define CDROM_READ_TOC_EX_FORMAT_TOC      0x00
127 #define CDROM_READ_TOC_EX_FORMAT_SESSION  0x01
128 #define CDROM_READ_TOC_EX_FORMAT_FULL_TOC 0x02
129 #define CDROM_READ_TOC_EX_FORMAT_PMA      0x03
130 #define CDROM_READ_TOC_EX_FORMAT_ATIP     0x04
131 #define CDROM_READ_TOC_EX_FORMAT_CDTEXT   0x05
132 
133 typedef struct _CDROM_READ_TOC_EX {
134   UCHAR  Format : 4;
135   UCHAR  Reserved1 : 3;
136   UCHAR  Msf : 1;
137   UCHAR  SessionTrack;
138   UCHAR  Reserved2;
139   UCHAR  Reserved3;
140 } CDROM_READ_TOC_EX, *PCDROM_READ_TOC_EX;
141 
142 typedef struct _CDROM_SEEK_AUDIO_MSF {
143   UCHAR  M;
144   UCHAR  S;
145   UCHAR  F;
146 } CDROM_SEEK_AUDIO_MSF, *PCDROM_SEEK_AUDIO_MSF;
147 
148 /* CDROM_SUB_Q_DATA_FORMAT.Format constants */
149 #define IOCTL_CDROM_SUB_Q_CHANNEL         0x00
150 #define IOCTL_CDROM_CURRENT_POSITION      0x01
151 #define IOCTL_CDROM_MEDIA_CATALOG         0x02
152 #define IOCTL_CDROM_TRACK_ISRC            0x03
153 
154 typedef struct _CDROM_SUB_Q_DATA_FORMAT {
155   UCHAR Format;
156   UCHAR Track;
157 } CDROM_SUB_Q_DATA_FORMAT, *PCDROM_SUB_Q_DATA_FORMAT;
158 
159 typedef struct _CDROM_TOC {
160   UCHAR  Length[2];
161   UCHAR  FirstTrack;
162   UCHAR  LastTrack;
163   TRACK_DATA  TrackData[MAXIMUM_NUMBER_TRACKS];
164 } CDROM_TOC, *PCDROM_TOC;
165 
166 #define CDROM_TOC_SIZE sizeof(CDROM_TOC)
167 
168 typedef struct _CDROM_TOC_ATIP_DATA_BLOCK {
169   UCHAR  CdrwReferenceSpeed : 3;
170   UCHAR  Reserved3 : 1;
171   UCHAR  WritePower : 3;
172   UCHAR  True1 : 1;
173   UCHAR  Reserved4 : 6;
174   UCHAR  UnrestrictedUse : 1;
175   UCHAR  Reserved5 : 1;
176   UCHAR  A3Valid : 1;
177   UCHAR  A2Valid : 1;
178   UCHAR  A1Valid : 1;
179   UCHAR  Reserved6 : 3;
180   UCHAR  IsCdrw : 1;
181   UCHAR  True2 : 1;
182   UCHAR  Reserved7;
183   UCHAR  LeadInMsf[3];
184   UCHAR  Reserved8;
185   UCHAR  LeadOutMsf[3];
186   UCHAR  Reserved9;
187   UCHAR  A1Values[3];
188   UCHAR  Reserved10;
189   UCHAR  A2Values[3];
190   UCHAR  Reserved11;
191   UCHAR  A3Values[3];
192   UCHAR  Reserved12;
193 } CDROM_TOC_ATIP_DATA_BLOCK, *PCDROM_TOC_ATIP_DATA_BLOCK;
194 
195 typedef struct _CDROM_TOC_ATIP_DATA {
196   UCHAR  Length[2];
197   UCHAR  Reserved1;
198   UCHAR  Reserved2;
199   CDROM_TOC_ATIP_DATA_BLOCK  Descriptors[0];
200 } CDROM_TOC_ATIP_DATA, *PCDROM_TOC_ATIP_DATA;
201 
202 /* CDROM_TOC_CD_TEXT_DATA_BLOCK.PackType constants */
203 #define CDROM_CD_TEXT_PACK_ALBUM_NAME 0x80
204 #define CDROM_CD_TEXT_PACK_PERFORMER  0x81
205 #define CDROM_CD_TEXT_PACK_SONGWRITER 0x82
206 #define CDROM_CD_TEXT_PACK_COMPOSER   0x83
207 #define CDROM_CD_TEXT_PACK_ARRANGER   0x84
208 #define CDROM_CD_TEXT_PACK_MESSAGES   0x85
209 #define CDROM_CD_TEXT_PACK_DISC_ID    0x86
210 #define CDROM_CD_TEXT_PACK_GENRE      0x87
211 #define CDROM_CD_TEXT_PACK_TOC_INFO   0x88
212 #define CDROM_CD_TEXT_PACK_TOC_INFO2  0x89
213 #define CDROM_CD_TEXT_PACK_UPC_EAN    0x8e
214 #define CDROM_CD_TEXT_PACK_SIZE_INFO  0x8f
215 
216 typedef struct _CDROM_TOC_CD_TEXT_DATA_BLOCK {
217   UCHAR  PackType;
218   UCHAR  TrackNumber : 7;
219   UCHAR  ExtensionFlag : 1;
220   UCHAR  SequenceNumber;
221   UCHAR  CharacterPosition : 4;
222   UCHAR  BlockNumber : 3;
223   UCHAR  Unicode : 1;
224   _ANONYMOUS_UNION union {
225     UCHAR  Text[12];
226     WCHAR  WText[6];
227   } DUMMYUNIONNAME;
228   UCHAR  CRC[2];
229 } CDROM_TOC_CD_TEXT_DATA_BLOCK, *PCDROM_TOC_CD_TEXT_DATA_BLOCK;
230 
231 typedef struct _CDROM_TOC_CD_TEXT_DATA {
232   UCHAR  Length[2];
233   UCHAR  Reserved1;
234   UCHAR  Reserved2;
235   CDROM_TOC_CD_TEXT_DATA_BLOCK  Descriptors[0];
236 } CDROM_TOC_CD_TEXT_DATA, *PCDROM_TOC_CD_TEXT_DATA;
237 
238 /* CDROM_TOC_FULL_TOC_DATA_BLOCK.Adr constants */
239 #define ADR_NO_MODE_INFORMATION           0x0
240 #define ADR_ENCODES_CURRENT_POSITION      0x1
241 #define ADR_ENCODES_MEDIA_CATALOG         0x2
242 #define ADR_ENCODES_ISRC                  0x3
243 
244 typedef struct _CDROM_TOC_FULL_TOC_DATA_BLOCK {
245   UCHAR  SessionNumber;
246   UCHAR  Control : 4;
247   UCHAR  Adr : 4;
248   UCHAR  Reserved1;
249   UCHAR  Point;
250   UCHAR  MsfExtra[3];
251   UCHAR  Zero;
252   UCHAR  Msf[3];
253 } CDROM_TOC_FULL_TOC_DATA_BLOCK, *PCDROM_TOC_FULL_TOC_DATA_BLOCK;
254 
255 typedef struct _CDROM_TOC_FULL_TOC_DATA {
256   UCHAR  Length[2];
257   UCHAR  FirstCompleteSession;
258   UCHAR  LastCompleteSession;
259   CDROM_TOC_FULL_TOC_DATA_BLOCK  Descriptors[0];
260 } CDROM_TOC_FULL_TOC_DATA, *PCDROM_TOC_FULL_TOC_DATA;
261 
262 typedef struct _CDROM_TOC_PMA_DATA {
263   UCHAR  Length[2];
264   UCHAR  Reserved1;
265   UCHAR  Reserved2;
266   CDROM_TOC_FULL_TOC_DATA_BLOCK  Descriptors[0];
267 } CDROM_TOC_PMA_DATA, *PCDROM_TOC_PMA_DATA;
268 
269 /* SUB_Q_HEADER.AudioStatus constants */
270 #define AUDIO_STATUS_NOT_SUPPORTED  0x00
271 #define AUDIO_STATUS_IN_PROGRESS    0x11
272 #define AUDIO_STATUS_PAUSED         0x12
273 #define AUDIO_STATUS_PLAY_COMPLETE  0x13
274 #define AUDIO_STATUS_PLAY_ERROR     0x14
275 #define AUDIO_STATUS_NO_STATUS      0x15
276 
277 typedef struct _SUB_Q_HEADER {
278   UCHAR  Reserved;
279   UCHAR  AudioStatus;
280   UCHAR  DataLength[2];
281 } SUB_Q_HEADER, *PSUB_Q_HEADER;
282 
283 typedef struct _SUB_Q_MEDIA_CATALOG_NUMBER {
284   SUB_Q_HEADER  Header;
285   UCHAR  FormatCode;
286   UCHAR  Reserved[3];
287   UCHAR  Reserved1 : 7;
288   UCHAR  Mcval :1;
289   UCHAR  MediaCatalog[15];
290 } SUB_Q_MEDIA_CATALOG_NUMBER, *PSUB_Q_MEDIA_CATALOG_NUMBER;
291 
292 typedef struct _SUB_Q_TRACK_ISRC {
293   SUB_Q_HEADER  Header;
294   UCHAR  FormatCode;
295   UCHAR  Reserved0;
296   UCHAR  Track;
297   UCHAR  Reserved1;
298   UCHAR  Reserved2 : 7;
299   UCHAR  Tcval : 1;
300   UCHAR  TrackIsrc[15];
301 } SUB_Q_TRACK_ISRC, *PSUB_Q_TRACK_ISRC;
302 
303 typedef struct _SUB_Q_CURRENT_POSITION {
304   SUB_Q_HEADER  Header;
305   UCHAR  FormatCode;
306   UCHAR  Control : 4;
307   UCHAR  ADR : 4;
308   UCHAR  TrackNumber;
309   UCHAR  IndexNumber;
310   UCHAR  AbsoluteAddress[4];
311   UCHAR  TrackRelativeAddress[4];
312 } SUB_Q_CURRENT_POSITION, *PSUB_Q_CURRENT_POSITION;
313 
314 typedef union _SUB_Q_CHANNEL_DATA {
315   SUB_Q_CURRENT_POSITION  CurrentPosition;
316   SUB_Q_MEDIA_CATALOG_NUMBER  MediaCatalog;
317   SUB_Q_TRACK_ISRC  TrackIsrc;
318 } SUB_Q_CHANNEL_DATA, *PSUB_Q_CHANNEL_DATA;
319 
320 /* CDROM_AUDIO_CONTROL.LbaFormat constants */
321 #define AUDIO_WITH_PREEMPHASIS            0x1
322 #define DIGITAL_COPY_PERMITTED            0x2
323 #define AUDIO_DATA_TRACK                  0x4
324 #define TWO_FOUR_CHANNEL_AUDIO            0x8
325 
326 typedef struct _CDROM_AUDIO_CONTROL {
327 	UCHAR  LbaFormat;
328 	USHORT  LogicalBlocksPerSecond;
329 } CDROM_AUDIO_CONTROL, *PCDROM_AUDIO_CONTROL;
330 
331 typedef struct _VOLUME_CONTROL {
332   UCHAR  PortVolume[4];
333 } VOLUME_CONTROL, *PVOLUME_CONTROL;
334 
335 typedef enum _TRACK_MODE_TYPE {
336 	YellowMode2,
337 	XAForm2,
338 	CDDA
339 } TRACK_MODE_TYPE, *PTRACK_MODE_TYPE;
340 
341 typedef struct __RAW_READ_INFO {
342 	LARGE_INTEGER  DiskOffset;
343 	ULONG  SectorCount;
344 	TRACK_MODE_TYPE  TrackMode;
345 } RAW_READ_INFO, *PRAW_READ_INFO;
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 #endif /* __NTDDCDRM_H */
352