1 /************************************************************************************\
3 mfpdtf.h - HP Multi-Function Peripheral Data Transfer Format filter.
5 (c) 2001-2005 Copyright Hewlett-Packard Development Company, LP
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11 of the Software, and to permit persons to whom the Software is furnished to do
12 so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Contributing Author(s): David Paschal, Don Welch, David Suffield
26 \************************************************************************************/
28 #if !defined(_MFPDTF_H )
32 #include <sys/types.h>
40 enum MfpdtfImageRecordID_e { MFPDTF_ID_START_PAGE = 0,
41 MFPDTF_ID_RASTER_DATA = 1,
42 MFPDTF_ID_END_PAGE = 2 };
44 struct MfpdtfFixedHeader_s
46 unsigned char blockLength[4]; /* Includes header(s). */
47 unsigned char headerLength[2]; /* Just header(s). */
48 unsigned char dataType;
49 unsigned char pageFlags;
50 } __attribute__(( packed) );
52 struct MfpdtfImageRasterDataHeader_s
54 unsigned char traits; /* Unused. */
55 unsigned char byteCount[2];
56 } __attribute__(( packed) );
58 struct MfpdtfImageStartPageRecord_s
60 unsigned char encoding;
61 unsigned char pageNumber[2];
64 unsigned char pixelsPerRow[2];
65 unsigned char bitsPerPixel[2];
66 unsigned char rowsThisPage[4];
67 unsigned char xres[4];
68 unsigned char yres[4];
70 } __attribute__(( packed) );
72 struct MfpdtfImageEndPageRecord_s
74 unsigned char unused[3];
77 unsigned char numberOfRows[4];
79 } __attribute__(( packed) );
86 int fdLog; /* <0 means not (yet) open. */
91 struct timeval timeout;
92 int simulateImageHeaders;
94 int lastServiceResult;
95 int dataType; /* <0 means not (yet) valid. */
98 int fixedBlockBytesRemaining; /* Also generic data. */
99 int innerBlockBytesRemaining; /* Image or array data. */
100 int dontDecrementInnerBlock;
102 struct MfpdtfFixedHeader_s fixedHeader;
103 int lenVariantHeader;
104 union MfpdtfVariantHeader_u * pVariantHeader;
105 struct MfpdtfImageStartPageRecord_s imageStartPageRecord;
106 struct MfpdtfImageRasterDataHeader_s imageRasterDataHeader;
107 struct MfpdtfImageEndPageRecord_s imageEndPageRecord;
111 typedef struct Mfpdtf_s * Mfpdtf_t;
113 #define MFPDTF_RESULT_NEW_PAGE 0x00000001
114 #define MFPDTF_RESULT_END_PAGE 0x00000002
115 #define MFPDTF_RESULT_NEW_DOCUMENT 0x00000004
116 #define MFPDTF_RESULT_END_DOCUMENT 0x00000008
118 #define MFPDTF_RESULT_END_STREAM 0x00000010
119 #define MFPDTF_RESULT_RESERVED_20 0x00000020
120 #define MFPDTF_RESULT_RESERVED_40 0x00000040
121 #define MFPDTF_RESULT_RESERVED_80 0x00000080
123 #define MFPDTF_RESULT_00000100 0x00000100
124 #define MFPDTF_RESULT_READ_TIMEOUT 0x00000200
125 #define MFPDTF_RESULT_READ_ERROR 0x00000400
126 #define MFPDTF_RESULT_OTHER_ERROR 0x00000800
128 #define MFPDTF_RESULT_ERROR_MASK 0x00000E00
130 #define MFPDTF_RESULT_NEW_DATA_TYPE 0x00001000
131 #define MFPDTF_RESULT_NEW_VARIANT_HEADER 0x00002000
132 #define MFPDTF_RESULT_GENERIC_DATA_PENDING 0x00004000
133 #define MFPDTF_RESULT_ARRAY_DATA_PENDING 0x00008000
135 #define MFPDTF_RESULT_NEW_START_OF_PAGE_RECORD 0x00010000
136 #define MFPDTF_RESULT_IMAGE_DATA_PENDING 0x00020000
137 #define MFPDTF_RESULT_NEW_END_OF_PAGE_RECORD 0x00040000
138 #define MFPDTF_RESULT_00080000 0x00080000
140 #define MFPDTF_RESULT_INNER_DATA_PENDING 0x00028000
142 enum MfpdtfDataType_e { MFPDTF_DT_UNKNOWN = 0,
143 MFPDTF_DT_FAX_IMAGES = 1,
144 MFPDTF_DT_SCANNED_IMAGES = 2,
145 MFPDTF_DT_DIAL_STRINGS = 3,
146 MFPDTF_DT_DEMO_PAGES = 4,
147 MFPDTF_DT_SPEED_DIALS = 5,
148 MFPDTF_DT_FAX_LOGS = 6,
149 MFPDTF_DT_CFG_PARMS = 7,
150 MFPDTF_DT_LANG_STRS = 8,
151 MFPDTF_DT_JUNK_FAX_CSIDS = 9, /* MFPDTF_DT_DIAL_STRINGS */
152 MFPDTF_DT_REPORT_STRS = 10, /* MFPDTF_DT_LANG_STRS */
153 MFPDTF_DT_FONTS = 11,
154 MFPDTF_DT_TTI_BITMAP = 12,
155 MFPDTF_DT_COUNTERS = 13,
156 MFPDTF_DT_DEF_PARMS = 14, /* MFPDTF_DT_CFG_PARMS */
157 MFPDTF_DT_SCAN_OPTIONS = 15,
158 MFPDTF_DT_FW_JOB_TABLE = 17 };
159 #define MFPDTF_DT_MASK_IMAGE \
160 ((1<<MFPDTF_DT_FAX_IMAGES) | \
161 (1<<MFPDTF_DT_SCANNED_IMAGES) | \
162 (1<<MFPDTF_DT_DEMO_PAGES))
164 enum MfpdtfImageEncoding_e { MFPDTF_RASTER_BITMAP = 0,
165 MFPDTF_RASTER_GRAYMAP = 1,
166 MFPDTF_RASTER_MH = 2,
167 MFPDTF_RASTER_MR = 3,
168 MFPDTF_RASTER_MMR = 4,
169 MFPDTF_RASTER_RGB = 5,
170 MFPDTF_RASTER_YCC411 = 6,
171 MFPDTF_RASTER_JPEG = 7,
172 MFPDTF_RASTER_PCL = 8,
173 MFPDTF_RASTER_NOT = 9 };
176 union MfpdtfVariantHeader_u
178 struct MfpdtfVariantHeaderFaxDataArtoo_s
180 unsigned char majorVersion; /* 1 */
181 unsigned char minorVersion; /* 0 */
182 unsigned char dataSource; /* unknown=0,prev,host,fax,pollfax,scanner */
183 unsigned char dataFormat; /* unknown=0,ASCII=3,CCITT_G3=10 */
184 unsigned char dataCompression; /* native=1,MH,MR,MMR */
185 unsigned char pageResolution; /* fine=0,std,CCITT300,CCITT400 */
186 unsigned char pageSize; /* unknown=0 */
187 unsigned char pixelsPerRow[2];
192 unsigned char minute;
193 unsigned char second;
194 unsigned char T30_CSI[20];
195 unsigned char T30_SUB[20];
196 } __attribute__(( packed) ) faxArtoo;
198 struct MfpdtfVariantHeaderFaxDataSolo_s
200 unsigned char majorVersion; /* 1 */
201 unsigned char minorVersion; /* 1 */
202 unsigned char dataSource;
203 unsigned char dataFormat;
204 unsigned char dataCompression;
205 unsigned char pageResolution;
206 unsigned char pageSize;
207 unsigned char pixelsPerRow[2];
212 unsigned char minute;
213 unsigned char second;
214 unsigned char suppressTTI;
215 unsigned char T30_CSI[20];
216 unsigned char T30_SUB[20];
217 unsigned char T30_PWD[20];
218 } __attribute__(( packed) ) faxSolo;
220 struct MfpdtfVariantHeaderFaxData_s
222 unsigned char majorVersion;
223 unsigned char minorVersion;
225 } __attribute__(( packed) ) fax;
227 struct MfpdtfVariantHeaderImageData_s
229 unsigned char majorVersion;
230 unsigned char minorVersion;
231 unsigned char sourcePages[2];
232 unsigned char copiesPerPage[2];
233 unsigned char zoomFactor[2];
234 unsigned char jpegQualityFactor[2];
235 } __attribute__(( packed) ) image;
237 struct MfpdtfVariantHeaderArrayData_s
239 unsigned char majorVersion;
240 unsigned char minorVersion;
241 unsigned char recordCount[2];
242 unsigned char recordSize[2];
243 } __attribute__(( packed) ) array;
244 } __attribute__(( packed) );
246 Mfpdtf_t __attribute__ ((visibility ("hidden"))) MfpdtfAllocate(int deviceid, int channelid);
247 int __attribute__ ((visibility ("hidden"))) MfpdtfDeallocate(Mfpdtf_t mfpdtf);
248 int __attribute__ ((visibility ("hidden"))) MfpdtfSetChannel(Mfpdtf_t mfpdtf, int channelid);
249 int __attribute__ ((visibility ("hidden"))) MfpdtfLogToFile(Mfpdtf_t mfpdtf, char * filename);
250 int __attribute__ ((visibility ("hidden"))) MfpdtfReadGetSimulateImageHeaders(Mfpdtf_t mfpdtf);
251 int __attribute__ ((visibility ("hidden"))) MfpdtfReadSetSimulateImageHeaders(Mfpdtf_t mfpdtf, int simulateImageHeaders);
252 int __attribute__ ((visibility ("hidden"))) MfpdtfReadStart(Mfpdtf_t mfpdtf);
253 int __attribute__ ((visibility ("hidden"))) MfpdtfReadService(Mfpdtf_t mfpdtf);
254 int __attribute__ ((visibility ("hidden"))) MfpdtfReadGetLastServiceResult(Mfpdtf_t mfpdtf);
255 int __attribute__ ((visibility ("hidden"))) MfpdtfReadGetVariantHeader(Mfpdtf_t mfpdtf, union MfpdtfVariantHeader_u * buffer, int maxlen);
256 int __attribute__ ((visibility ("hidden"))) MfpdtfReadGetStartPageRecord(Mfpdtf_t mfpdtf, struct MfpdtfImageStartPageRecord_s * buffer, int maxlen);
257 int __attribute__ ((visibility ("hidden"))) MfpdtfReadInnerBlock(Mfpdtf_t mfpdtf, unsigned char * buffer, int countdown);
260 * Phase 2 rewrite. des
263 enum MFPDTF_DATA_TYPE
269 /* MFPDTF page flag bit fields. */
270 #define PF_NEW_PAGE 1
271 #define PF_END_PAGE 2
275 enum MFPDTF_RECORD_ID
282 /* All words are stored little endian. */
286 uint32_t BlockLength; /* includes header in bytes */
287 uint16_t HeaderLength; /* in bytes */
290 } __attribute__((packed)) MFPDTF_FIXED_HEADER;
297 uint16_t BlackPixelsPerRow;
298 uint16_t BlackBitsPerPixel;
300 uint32_t BlackHorzDPI;
301 uint32_t BlackVertDPI;
302 uint16_t CMYPixelsPerRow;
303 uint16_t CMYBitsPerPixel;
307 } __attribute__((packed)) MFPDTF_START_PAGE;
313 uint16_t Size; /* in bytes */
314 } __attribute__((packed)) MFPDTF_RASTER;
322 } __attribute__((packed)) MFPDTF_END_PAGE;
324 /* Folloing macros are now in gcc 4.3.2 endian.h */
325 #if !defined(htole16)
326 #if defined(WORDS_BIGENDIAN)
327 #define htole16(A) ((((uint16_t)(A) & 0xff00) >> 8) | (((uint16_t)(A) & 0x00ff) << 8)) /* host to little-endian 16-bit value */
328 #define le16toh htole16 /* little-endian to host 16-bit value */
329 #define htole32(A) ((((uint32_t)(A) & (uint32_t)0x000000ff) << 24) | (((uint32_t)(A) & (uint32_t)0x0000ff00) << 8) | \
330 (((uint32_t)(A) & (uint32_t)0x00ff0000) >> 8) | (((uint32_t)(A) & (uint32_t)0xff000000) >> 24))
331 #define le32toh htole32
333 #define htole16(A) (A)
334 #define le16toh(A) (A)
335 #define le32toh(A) (A)
336 #define htole32(A) (A)
337 #endif // #if defined(WORDS_BIGENDIAN)
338 #endif // #if !defined(htole16)
340 int __attribute__ ((visibility ("hidden"))) read_mfpdtf_block(int device, int channel, char *buf, int bufSize, int timeout);