1# -*- coding: utf-8 -*-
2#
3# (c) Copyright 2003-2015 HP Development Company, L.P.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18#
19# Author: Don Welch
20#
21
22# Std Lib
23import sys
24import struct
25
26# Local
27from .g import *
28from .utils import printable
29from .utils import unprintable
30from .sixext import to_bytes_utf8, to_unicode, to_bytes_latin, PY3, to_string_latin
31
32# Request codes
33GET_REQUEST = 0x00
34GET_NEXT_REQUEST = 0x01
35GET_BLOCK_REQUEST = 0x02
36GET_NEXT_BLOCK_REQUEST = 0x03
37SET_REQUEST = 0x04
38ENABLE_TRAP_REQUEST = 0x05
39DISABLE_TRAP_REQUEST = 0x06
40TRAP_REQUEST = 0x07
41
42# Reply codes
43GET_REPLY = 0x80
44GET_NEXT_REPLY = 0x81
45BLOCK_REPLY = 0x82
46NEXT_BLOCK_REPLY = 0x83
47SET_REPLY = 0x84
48ENABLE_TRAP_REPLY = 0x85
49DISABLE_TRAP_REPLY = 0x85
50
51# PML Reply error codes
52ERROR_OK = 0x00
53ERROR_OK_END_OF_SUPPORTED_OBJECTS = 0x01
54ERROR_OK_NEAREST_LEGAL_VALUE_SUBSITUTED = 0x02
55ERROR_MAX_OK = 0x7f
56ERROR_UNKNOWN_REQUEST = 0x80
57ERROR_BUFFER_OVERFLOW = 0x81
58ERROR_COMMAND_EXECUTION = 0x82
59ERROR_UNKNOWN_OID = 0x83
60ERROR_OBJ_DOES_NOT_SUPPORT_SPECIFIED_ACTION = 0x84
61ERROR_INVALID_OR_UNSUPPORTED_VALUE = 0x85
62ERROR_PAST_END_OF_SUPPORTED_OBJS = 0x86
63ERROR_ACTION_CANNOT_BE_PERFORMED_NOW = 0x87
64ERROR_SYNTAX = 0x88
65
66# Data types
67TYPE_MASK = 0xfc
68TYPE_OBJECT_IDENTIFIER = 0x00
69TYPE_ENUMERATION = 0x04
70TYPE_SIGNED_INTEGER = 0x08
71TYPE_REAL = 0x0C
72TYPE_STRING = 0x10
73TYPE_BINARY = 0x14
74TYPE_ERROR_CODE = 0x18
75TYPE_NULL_VALUE = 0x1c
76TYPE_COLLECTION = 0x20
77TYPE_UNKNOWN = 0xff
78
79# Misc. constants
80MAX_VALUE_LEN = 1023
81MAX_OID_LEN = 32
82MAX_DATALEN = 4096
83
84# desired_int_sizes
85INT_SIZE_BYTE = struct.calcsize('b')
86INT_SIZE_WORD = struct.calcsize('h')
87INT_SIZE_INT = struct.calcsize('i')
88
89
90def buildPMLGetPacket(oid): # String dotted notation
91    oid = ''.join([chr(int(b.strip())) for b in oid.split('.')])
92    return struct.pack('>BBB%ss' % len(oid),
93                        GET_REQUEST,
94                        TYPE_OBJECT_IDENTIFIER,
95                        len(oid), oid)
96
97def buildPMLGetPacketEx(oid): # OID identifier dict
98    return buildPMLGetPacket(oid['oid'])
99
100def buildEmbeddedPMLSetPacket(oid, value, data_type):
101    return to_bytes_utf8('').join([to_bytes_utf8('PML\x20'), buildPMLSetPacket(oid, value, data_type)])
102
103def buildPMLSetPacket(oid, value, data_type): # String dotted notation
104    oid = ''.join([chr(int(b.strip())) for b in oid.split('.')])
105
106    if data_type in (TYPE_ENUMERATION, TYPE_SIGNED_INTEGER, TYPE_COLLECTION):
107        data = struct.pack(">i", int(value))
108
109        if value > 0:
110            while len(data) > 0 and data[0] == '\x00':
111                data = data[1:]
112        else:
113            while len(data) > 1 and data[0] == '\xff' and data[1] == '\xff':
114                data = data[1:]
115
116        data = struct.pack(">BB%ds" % len(data), data_type, len(data), data)
117
118    elif data_type == TYPE_REAL:
119        data = struct.pack(">BBf", data_type, struct.calcsize("f"), float(value))
120
121    elif data_type == TYPE_STRING:
122        data = struct.pack(">BBBB%ss" % len(value), data_type, len(value) + 2, 0x01, 0x15, value)
123
124    elif data_type == TYPE_BINARY:
125        data = struct.pack(">BB%ss" % len(value), data_type, len(value), ''.join([chr(x) for x in value]))
126
127    p = struct.pack('>BBB%ss%ss' % (len(oid), len(data)),
128                    SET_REQUEST,
129                    TYPE_OBJECT_IDENTIFIER,
130                    len(oid), to_bytes_utf8(oid),
131                    data)
132    return p
133
134def ConvertToPMLDataFormat(value, data_type):
135    if data_type in (TYPE_ENUMERATION, TYPE_SIGNED_INTEGER, TYPE_COLLECTION):
136        data = struct.pack(">i", int(value))
137
138        if value > 0:
139            while len(data) > 0 and data[0] == '\x00':
140                data = data[1:]
141        else:
142            while len(data) > 1 and data[0] == '\xff' and data[1] == '\xff':
143                data = data[1:]
144
145        data = struct.pack(">%ds" % len(data), data)
146
147    elif data_type == TYPE_REAL:
148        data = struct.pack(">f", float(value))
149
150    elif data_type == TYPE_STRING:
151        #For PY2: If data is in unicode, converting to string (e.g Fax Name)
152        #For PY3: If data is in string, converting to bytes
153        try:
154            value = value.encode('utf-8')
155        except (UnicodeEncodeError, UnicodeDecodeError) as e:
156            value = value
157
158        data = struct.pack(">BB%ss" % len(value), 0x00, 0x0e, value) # changed for K80, seems to work on others...
159
160    elif data_type == TYPE_BINARY:
161        if type(value) == type(''):
162            data = value
163        elif type(value) == type([]):
164            data = struct.pack(">%ds" % len(value), ''.join([chr(x) for x in value]))
165        else:
166            log.error("Value type error.")
167
168    return data
169
170def ConvertFromPMLDataFormat(data, data_type, desired_int_size=INT_SIZE_INT):
171    if data_type in (TYPE_ENUMERATION, TYPE_SIGNED_INTEGER, TYPE_COLLECTION):
172        if len(data):
173            if data[0] == b'\xff':
174                while len(data) < 4:
175                    data = b'\xff' + data
176
177            else:
178                while len(data) < 4:
179                    data = b'\x00' + data
180
181            if desired_int_size == INT_SIZE_INT:
182                return struct.unpack(">i", data)[0]
183
184            elif desired_int_size == INT_SIZE_WORD:
185                return struct.unpack(">h", data[len(INT_SIZE_WORD)-INT_SIZE_WORD:len(INT_SIZE_WORD)])[0]
186
187            elif desired_int_size == INT_SIZE_BYTE:
188                return struct.unpack(">b", data[len(data)-INT_SIZE_BYTE:len(data)])[0]
189
190            else:
191                raise Error(ERROR_INTERNAL)
192
193        else:
194            return 0
195
196    elif data_type == TYPE_REAL:
197        if len(data) == struct.calcsize("f"):
198            return struct.unpack(">f", data)[0]
199        else:
200            return 0.0
201
202    elif data_type == TYPE_STRING:
203        if PY3:
204            return to_string_latin(b''.join([to_bytes_latin(chr(c)) for c in data if to_bytes_latin(chr(c)) not in unprintable]))
205        else:
206            return ''.join([c for c in data if c not in unprintable])
207
208    elif data_type == TYPE_BINARY:
209        return to_string_latin(data)
210
211    return None
212
213
214def parsePMLPacket(p, expected_data_type=TYPE_UNKNOWN):
215    pos, state = 0, 1
216
217    data_type = TYPE_UNKNOWN
218    error_state = False
219    while state:
220
221        if state == 1: # reply and error code
222            reply, error_code = struct.unpack(">BB", p[pos : pos + 2])
223            state, pos = 2, pos + 2
224
225            if error_code > ERROR_MAX_OK:
226                error_state = True
227
228        elif state == 2: # data type and length
229            data_type, length = struct.unpack(">BB", p[pos : pos + 2])
230            state, pos = 3, pos + 2
231
232            if error_state:
233
234                if expected_data_type in (TYPE_COLLECTION, TYPE_ENUMERATION,
235                                    TYPE_SIGNED_INTEGER, TYPE_BINARY):
236                    data = 0
237
238                elif expected_data_type == TYPE_REAL:
239                    data = 0.0
240
241                else:
242                    data = ''
243
244                break
245
246        elif state == 3: # data
247            data = p[pos : pos + length]
248            state, pos = 0, pos + length
249
250            if data_type == TYPE_OBJECT_IDENTIFIER:
251                state = 2
252                continue
253
254            elif data_type == TYPE_STRING:
255                if length > 0:
256                    symbol_set, data = struct.unpack(">H%ss" % (length - 2), data)
257                else:
258                    data = ''
259
260            elif data_type == TYPE_BINARY:
261                data = [ord(b) for b in data]
262
263            elif data_type == TYPE_ENUMERATION:
264                if length > 0:
265                    data = struct.unpack(">i", "%s%s" % ('\x00' * (4 - length), data))[0]
266                else:
267                    data = 0
268
269            elif data_type == TYPE_REAL:
270                if length > 0:
271                    data = struct.unpack(">f", data)[0]
272                else:
273                    data = 0.0
274
275            elif data_type ==  TYPE_SIGNED_INTEGER:
276                if length > 0:
277                    pad = '\x00'
278                    if ord(data[0]) & 0x80: pad = '\xff' # negative number
279                    data = struct.unpack(">i", "%s%s" % (pad * (4 - length), data))[0]
280                else:
281                    data = 0
282
283            elif data_type == TYPE_COLLECTION:
284                if length > 0:
285                    data = struct.unpack(">i", "%s%s" % ('\x00' * (4 - length), data))[0]
286                else:
287                    data = 0
288
289            elif data_type == TYPE_ERROR_CODE:
290                data = struct.unpack(">B", data)[0]
291
292            elif data_type == TYPE_NULL_VALUE:
293                data = None
294
295            break
296
297    return data, data_type, error_code
298
299
300
301def HPToSNMP(oid): # 1.
302    return '.'.join(['1.3.6.1.4.1.11.2.3.9.4.2', oid, '0'])
303
304def StdToSNMP(oid): # 2.
305    return '.'.join(['1.3.6.1.2.1.43', oid[2:]])
306
307def HRToSNMP(oid): # 3.
308    return '.'.join(['1.3.6.1.2.1.25', oid[2:]])
309
310def PMLToSNMP(oid):
311    assert len(oid) > 2
312
313    if oid[0] == '0': # 0. means its already in SNMP format (will fail for PML)
314        return oid[2:]
315
316    elif oid[0] == '1': # HP MIB
317        return HPToSNMP(oid)
318
319    elif oid[0] == '2': # Std MIB
320        return StdToSNMP(oid)
321
322    elif oid[0] == '3': # Host Resources MIB
323        return HRToSNMP(oid)
324
325    assert False
326
327
328#
329# OIDs
330#
331
332OID_DEVICE_ID = ('0.1.3.6.1.4.1.11.2.3.9.1.1.7.0', TYPE_STRING) # network/SNMP only (undocumented)
333
334OID_DEVICE_SUPPORTED_FUNCTIONS = ('1.1.2.67', TYPE_COLLECTION)
335DEVICE_SUPPORTED_FUNCTIONS_SCAN =                 0x00002
336DEVICE_SUPPORTED_FUNCTIONS_SCAN_SIMPLEX =         0x00004
337DEVICE_SUPPORTED_FUNCTIONS_SCAN_DUPLEX =          0x00008
338DEVICE_SUPPORTED_FUNCTIONS_COPY =                 0x00010
339DEVICE_SUPPORTED_FUNCTIONS_COPY_SIMPLEX_SIMPLEX = 0x00020
340DEVICE_SUPPORTED_FUNCTIONS_COPY_SIMPLEX_DUPLEX =  0x00040
341DEVICE_SUPPORTED_FUNCTIONS_COPY_DUPLEX_SIMPLEX =  0x00080
342DEVICE_SUPPORTED_FUNCTIONS_COPY_DUPLEX_DUPLEX =   0x00100
343DEVICE_SUPPORTED_FUNCTIONS_COPY_COLLATION =       0x00200
344DEVICE_SUPPORTED_FUNCTIONS_PRINT =                0x00400
345DEVICE_SUPPORTED_FUNCTIONS_AUTO_FEED_SIMPLEX =    0x00800
346DEVICE_SUPPORTED_FUNCTIONS_AUTO_FEED_DUPLEX =     0x01000
347DEVICE_SUPPORTED_FUNCTIONS_FAX_SEND =             0x02000
348DEVICE_SUPPORTED_FUNCTIONS_FAX_RECV =             0x04000
349DEVICE_SUPPORTED_FUNCTIONS_MASS_STORAGE =         0x08000
350DEVICE_SUPPORTED_FUNCTIONS_STREAMING_SAVE =       0x10000
351DEVICE_SUPPORTED_FUNCTIONS_FAX_CONFIG =           0x20000
352DEVICE_SUPPORTED_FUNCTIONS_FAX_CFG_SPEEDDIAL =    0x40000
353DEVICE_SUPPORTED_FUNCTIONS_FAX_CFG_GROUPDIAL =    0x80000
354
355OID_CLEAN = ('1.4.1.5.1.1', TYPE_ENUMERATION)
356CLEAN_CLEAN = 100
357CLEAN_PRIME = 200
358CLEAN_WIPE_AND_SPIT = 300
359
360OID_SERIAL_NUMBER = ('1.1.3.3', TYPE_STRING)
361OID_R_SETTING = ('1.1.1.35', TYPE_SIGNED_INTEGER)
362
363OID_PRINT_INTERNAL_PAGE = ('1.1.5.2', TYPE_ENUMERATION)
364PRINT_INTERNAL_PAGE_SUPPLIES_PAGE = 101
365PRINT_INTERNAL_PAGE_COLOR_PALETTE_CMYK_PAGE = 259
366PRINT_INTERNAL_PAGE_COLOR_CAL = 1102
367PRINT_INTERNAL_PAGE_COLOR_CAL_VERIFICATION = 1104
368PRINT_INTERNAL_PAGE_ALIGNMENT_PAGE = 1100 # LBOW/OJ Pro L7xxx
369PRINT_INTERNAL_PAGE_ALIGNMENT_PAGE_VERIFICATION = 1150 # LBOW
370PRINT_INTERNAL_PAGE_LINEFEED_CALIBRATION = 1407 # OJ Pro
371PRINT_INTERNAL_PAGE_AUTOMATIC_COLOR_CALIBRATION = 1408 # PS Pro B8800
372PRINT_INTERNAL_PAGE_PRINT_QUALITY_DIAGNOSTIC = 1409 # OJ Pro
373
374# From xojpanel
375OID_SPM_LINE1 = ('2.16.5.1.2.1.1', TYPE_STRING)
376OID_SPM_LINE2 = ('2.16.5.1.2.1.2', TYPE_STRING)
377
378OID_HP_LINE1 = ('1.1.2.20.2.1.1', TYPE_STRING)
379OID_HP_LINE2 = ('1.1.2.20.2.2.1', TYPE_STRING)
380
381
382# LaserJet Status (status type 3)
383OID_ON_OFF_LINE = ('1.1.2.5', TYPE_SIGNED_INTEGER)
384ON_OFF_LINE_ONLINE = 1
385ON_OFF_LINE_OFFLINE = 2
386ON_OFF_LINE_OFFLINE_AT_END_OF_JOB = 3
387
388OID_SLEEP_MODE = ('1.1.1.2', TYPE_SIGNED_INTEGER)
389SLEEP_MODE_FALSE = 1
390SLEEP_MODE_TRUE = 2
391
392OID_PRINTER_STATUS = ('3.3.5.1.1.1', TYPE_SIGNED_INTEGER)
393PRINTER_STATUS_OTHER = 1
394PRINTER_STATUS_UNKNOWN = 2
395PRINTER_STATUS_IDLE = 3
396PRINTER_STATUS_PRINTING = 4
397PRINTER_STATUS_WARMUP = 5
398
399OID_COVER_STATUS = ('2.6.1.1.3.1.1', TYPE_SIGNED_INTEGER)
400COVER_STATUS_OPEN = 3
401COVER_STATUS_CLOSED = 4
402
403OID_DETECTED_ERROR_STATE = ('3.3.5.1.2.1', TYPE_BINARY)
404DETECTED_ERROR_STATE_LOW_PAPER_MASK = 0x80
405DETECTED_ERROR_STATE_NO_PAPER_MASK = 0x40
406DETECTED_ERROR_STATE_LOW_CART_MASK = 0x20
407DETECTED_ERROR_STATE_OUT_CART_MASK = 0x10
408DETECTED_ERROR_STATE_DOOR_OPEN_MASK = 0x08
409DETECTED_ERROR_STATE_JAMMED_MASK = 0x04
410DETECTED_ERROR_STATE_OFFLINE_MASK = 0x02
411DETECTED_ERROR_STATE_SERVICE_REQUEST_MASK = 0x01
412DETECTED_ERROR_STATE_NO_ERROR = 0x00
413
414OID_MARKER_SUPPLIES_TYPE_x = '2.11.1.1.5.1.%d'
415OID_MARKER_SUPPLIES_TYPE_x_TYPE = TYPE_ENUMERATION
416OID_MARKER_SUPPLIES_TYPE_OTHER = 1
417OID_MARKER_SUPPLIES_TYPE_UNKNOWN = 2
418OID_MARKER_SUPPLIES_TYPE_TONER = 3
419OID_MARKER_SUPPLIES_TYPE_WASTE_TONER = 4
420OID_MARKER_SUPPLIES_TYPE_INK = 5
421OID_MARKER_SUPPLIES_TYPE_INK_CART = 6
422OID_MARKER_SUPPLIES_TYPE_INK_RIBBON = 7
423OID_MARKER_SUPPLIES_TYPE_WASTE_INK = 8
424OID_MARKER_SUPPLIES_TYPE_OPC = 9
425OID_MARKER_SUPPLIES_TYPE_DEVELOPER = 10
426OID_MARKER_SUPPLIES_TYPE_FUSER_OIL = 11
427OID_MARKER_SUPPLIES_TYPE_SOLID_WAX = 12
428OID_MARKER_SUPPLIES_TYPE_RIBBON_WAX = 13
429OID_MARKER_SUPPLIES_TYPE_WASTE_WAX = 14
430OID_MARKER_SUPPLIES_TYPE_FUSER = 15
431OID_MARKER_SUPPLIES_TYPE_CORONA_WIRE = 16
432OID_MARKER_SUPPLIES_TYPE_FUSER_OIL_WICK = 17
433OID_MARKER_SUPPLIES_TYPE_CLEANER_UNIT = 18
434OID_MARKER_SUPPLIES_TYPE_FUSER_CLEANING_PAD = 19
435OID_MARKER_SUPPLIES_TYPE_TRANSFER_UNIT = 20
436OID_MARKER_SUPPLIES_TYPE_TONER_CART = 21
437OID_MARKER_SUPPLIES_TYPE_FUSER_OILER = 22
438OID_MARKER_SUPPLIES_TYPE_ADF_MAINT_KIT = 23
439
440OID_MARKER_SUPPLIES_COLORANT_INDEX_x = '2.11.1.1.3.1.%d'
441OID_MARKER_SUPPLIES_COLORANT_INDEX_x_TYPE = TYPE_SIGNED_INTEGER
442
443OID_MARKER_SUPPLIES_MAX_x = '2.11.1.1.8.1.%d'
444OID_MARKER_SUPPLIES_MAX_x_TYPE = TYPE_SIGNED_INTEGER
445
446OID_MARKER_SUPPLIES_LEVEL_x = '2.11.1.1.9.1.%d'
447OID_MARKER_SUPPLIES_LEVEL_x_TYPE = TYPE_SIGNED_INTEGER
448
449OID_MARKER_COLORANT_VALUE_x = '2.12.1.1.4.1.%d'
450OID_MARKER_COLORANT_VALUE_x_TYPE = TYPE_STRING
451
452OID_MARKER_STATUS_x = '2.10.2.1.15.1.%d'
453OID_MARKER_STATUS_x_TYPE = TYPE_SIGNED_INTEGER
454OID_MARKER_STATUS_OK = 0
455OID_MARKER_STATUS_LOW_TONER_CONT = 8
456OID_MARKER_STATUS_LOW_TONER_STOP = 49
457OID_MARKER_STATUS_MISINSTALLED = 51
458
459OID_MARKER_SUPPLIES_DESCRIPTION_x = '2.11.1.1.6.1.%d'
460OID_MARKER_SUPPLIES_DESCRIPTION_x_TYPE = TYPE_BINARY
461
462OID_DEVICE_STATUS = ('3.3.2.1.5.1', TYPE_ENUMERATION)
463DEVICE_STATUS_UNKNOWN = 1
464DEVICE_STATUS_RUNNING = 2
465DEVICE_STATUS_WARNING = 3
466DEVICE_STATUS_TESTING = 4
467DEVICE_STATUS_DOWN = 5
468#end
469
470# alignment, cleaning, etc.
471OID_AUTO_ALIGNMENT = ('1.1.5.2', TYPE_ENUMERATION)
472AUTO_ALIGNMENT = 1100
473OID_ZCA = ('1.4.1.8.5.4.1', TYPE_SIGNED_INTEGER)
474OID_AGENT2_VERTICAL_ALIGNMENT = ('1.4.1.5.3.2.5', TYPE_SIGNED_INTEGER)
475OID_AGENT2_HORIZONTAL_ALIGNMENT = ('1.4.1.5.3.2.6', TYPE_SIGNED_INTEGER)
476OID_AGENT1_BIDIR_ADJUSTMENT = ('1.4.1.5.3.1.7', TYPE_SIGNED_INTEGER)
477OID_AGENT2_BIDIR_ADJUSTMENT = ('1.4.1.5.3.2.7', TYPE_SIGNED_INTEGER)
478OID_MARKING_AGENTS_INITIALIZED = ('1.4.1.5.1.4', TYPE_COLLECTION)
479OID_AGENT3_VERTICAL_ALIGNMENT = ("1.4.1.5.3.3.5", TYPE_SIGNED_INTEGER)
480OID_AGENT3_HORIZONTAL_ALIGNMENT = ("1.4.1.5.3.3.6", TYPE_SIGNED_INTEGER)
481OID_AGENT3_BIDIR_ADJUSTMENT = ("1.4.1.5.3.3.7", TYPE_SIGNED_INTEGER)
482OID_COLOR_CALIBRATION_SELECTION = ("1.4.1.5.1.9", TYPE_SIGNED_INTEGER)
483
484# Type 4 color cal
485OID_COLOR_CALIBRATION_ARRAY_1 = ("1.4.1.1.30.1.1", TYPE_SIGNED_INTEGER) # K
486OID_COLOR_CALIBRATION_ARRAY_2 = ("1.4.1.1.30.1.2", TYPE_SIGNED_INTEGER) # C
487OID_COLOR_CALIBRATION_ARRAY_3 = ("1.4.1.1.30.1.3", TYPE_SIGNED_INTEGER) # M
488OID_COLOR_CALIBRATION_ARRAY_4 = ("1.4.1.1.30.1.4", TYPE_SIGNED_INTEGER) # Y
489OID_COLOR_CALIBRATION_ARRAY_5 = ("1.4.1.1.30.1.5", TYPE_SIGNED_INTEGER) # c
490OID_COLOR_CALIBRATION_ARRAY_6 = ("1.4.1.1.30.1.6", TYPE_SIGNED_INTEGER) # m
491
492# Supported funcs
493OID_DEVICE_SUPPORTED_FUNCTIONS = ('1.1.2.67', TYPE_COLLECTION)
494DEVICE_SUPPORTED_FUNCTIONS_SCAN =                 0x00002
495DEVICE_SUPPORTED_FUNCTIONS_SCAN_SIMPLEX =         0x00004
496DEVICE_SUPPORTED_FUNCTIONS_SCAN_DUPLEX =          0x00008
497DEVICE_SUPPORTED_FUNCTIONS_COPY =                 0x00010
498DEVICE_SUPPORTED_FUNCTIONS_COPY_SIMPLEX_SIMPLEX = 0x00020
499DEVICE_SUPPORTED_FUNCTIONS_COPY_SIMPLEX_DUPLEX =  0x00040
500DEVICE_SUPPORTED_FUNCTIONS_COPY_DUPLEX_SIMPLEX =  0x00080
501DEVICE_SUPPORTED_FUNCTIONS_COPY_DUPLEX_DUPLEX =   0x00100
502DEVICE_SUPPORTED_FUNCTIONS_COPY_COLLATION =       0x00200
503DEVICE_SUPPORTED_FUNCTIONS_PRINT =                0x00400
504DEVICE_SUPPORTED_FUNCTIONS_AUTO_FEED_SIMPLEX =    0x00800
505DEVICE_SUPPORTED_FUNCTIONS_AUTO_FEED_DUPLEX =     0x01000
506DEVICE_SUPPORTED_FUNCTIONS_FAX_SEND =             0x02000
507DEVICE_SUPPORTED_FUNCTIONS_FAX_RECV =             0x04000
508DEVICE_SUPPORTED_FUNCTIONS_MASS_STORAGE =         0x08000
509DEVICE_SUPPORTED_FUNCTIONS_STREAMING_SAVE =       0x10000
510DEVICE_SUPPORTED_FUNCTIONS_FAX_CONFIG =           0x20000
511DEVICE_SUPPORTED_FUNCTIONS_FAX_CFG_SPEEDDIAL =    0x40000
512DEVICE_SUPPORTED_FUNCTIONS_FAX_CFG_GROUPDIAL =    0x80000
513
514
515OID_BATTERY_LEVEL = ('1.1.2.13', TYPE_SIGNED_INTEGER)
516OID_POWER_MODE = ('1.1.2.14', TYPE_ENUMERATION)
517POWER_MODE_ADPATER = 0x01
518POWER_MODE_BATTERY = 0x02
519POWER_MODE_CHARGING = 0x04
520POWER_MODE_DISCHARGING = 0x08
521POWER_MODE_BATTERY_LEVEL_KNOWN = 0x10
522
523OID_BATTERY_LEVEL_2 = ('1.1.2.61', TYPE_SIGNED_INTEGER)
524
525OID_POWER_SETTINGS = ('1.1.2.118', TYPE_ENUMERATION)
526OID_POWER_SETTINGS_15MIN = 1
527OID_POWER_SETTINGS_30MIN = 2
528OID_POWER_SETTINGS_45MIN = 3
529OID_POWER_SETTINGS_1HR = 4
530OID_POWER_SETTINGS_2HR = 5
531OID_POWER_SETTINGS_3HR = 6
532OID_POWER_SETTINGS_NEVER = 999
533
534#
535# Fax
536#
537
538OID_DEV_DOWNLOAD_TIMEOUT = ('1.1.1.17', TYPE_SIGNED_INTEGER)
539DEFAULT_DOWNLOAD_TIMEOUT = 600
540
541OID_FAX_DOWNLOAD_ERROR = ('1.3.7.2.6', TYPE_SIGNED_INTEGER)
542
543OID_FAXJOB_TX_TYPE = ('1.1.6.3.1.3', TYPE_ENUMERATION)
544FAXJOB_TX_TYPE_HOST_ONLY = 2
545
546OID_FAXJOB_TX_STATUS = ('1.1.6.3.3.3.1', TYPE_ENUMERATION)
547FAXJOB_TX_STATUS_IDLE = 1
548FAXJOB_TX_STATUS_DIALING = 2
549FAXJOB_TX_STATUS_CONNECTING = 3
550FAXJOB_TX_STATUS_TRANSMITTING = 4
551FAXJOB_TX_STATUS_DONE = 5
552
553FAXJOB_TX_STATUS_STR = {FAXJOB_TX_STATUS_IDLE: "Idle",
554                 FAXJOB_TX_STATUS_DIALING: "Dialing",
555                 FAXJOB_TX_STATUS_CONNECTING: "Connecting",
556                 FAXJOB_TX_STATUS_TRANSMITTING: "Transmitting",
557                 FAXJOB_TX_STATUS_DONE: "Done",}
558
559OID_FAXJOB_RX_STATUS = ('1.1.6.3.3.1.1', TYPE_ENUMERATION)
560FAXJOB_RX_STATUS_IDLE = 1
561FAXJOB_RX_STATUS_RINGING = 2
562FAXJOB_RX_STATUS_ANSWERING = 3
563FAXJOB_RX_STATUS_RECEIVING = 4
564FAXJOB_RX_STATUS_DONE = 5
565
566FAXJOB_RX_STATUS_STR = {FAXJOB_RX_STATUS_IDLE: "Idle",
567                        FAXJOB_RX_STATUS_RINGING: "Ringing",
568                        FAXJOB_RX_STATUS_ANSWERING: "Answering",
569                        FAXJOB_RX_STATUS_RECEIVING: "Receiving",
570                        FAXJOB_RX_STATUS_DONE: "Done",}
571
572OID_FAX_DOWNLOAD = ('1.3.7.1.6', TYPE_ENUMERATION)
573UPDN_STATE_IDLE = 1
574UPDN_STATE_REQSTART = 2
575UPDN_STATE_XFERACTIVE = 3
576UPDN_STATE_ERRORABORT = 4
577UPDN_STATE_XFERDONE = 5
578UPDN_STATE_NEWPAGE = 6
579UPDN_STATE_DISABLED = 7
580
581UPDN_STATE_STR = {UPDN_STATE_IDLE: "Idle",
582                  UPDN_STATE_REQSTART: "Request start",
583                  UPDN_STATE_XFERACTIVE: "Transfer active",
584                  UPDN_STATE_ERRORABORT: "Error abort",
585                  UPDN_STATE_XFERDONE: "Transfer done",
586                  UPDN_STATE_NEWPAGE: "New page",
587                  UPDN_STATE_DISABLED: "Disabled",}
588
589# Fax download errors (taken from doc/Fax/WindowsFax/sdcore/DevIO/DevIODefs.h)
590#
591DN_ERROR_NONE = 0
592DN_ERROR_HOST_ABORT = 705
593DN_ERROR_STOP_KEY_PRESSED = 706
594DN_ERROR_SESSION_FAIL = 709
595DN_ERROR_TX_ERROR = 710
596DN_ERROR_PHONE_UNAVAILABLE = 711
597DN_ERROR_OUT_OF_MEMORY = 713
598DN_ERROR_RESULT_BUSY = 714
599DN_ERROR_NO_ANSWER = 715
600DN_ERROR_NO_DIAL_TONE = 716
601DN_ERROR_DOC_JAM = 717
602DN_ERROR_DOOR_OPEN = 718
603DN_ERROR_POWER_FAILED = 719
604DN_ERROR_BLACKLIST = 720
605DN_ERROR_DOC_STORAGE_FULL = 721
606DN_ERROR_RESULT_COLOR_UNSUP = 722
607DN_ERROR_UNKNOWN = 9999
608
609DN_ERROR_STR = {DN_ERROR_NONE: "None",
610                DN_ERROR_HOST_ABORT: "Host aborted",
611                DN_ERROR_STOP_KEY_PRESSED: "Stop key pressed",
612                DN_ERROR_SESSION_FAIL: "Session failed",
613                DN_ERROR_TX_ERROR: "Transmit error",
614                DN_ERROR_PHONE_UNAVAILABLE: "Phone unavailable",
615                DN_ERROR_OUT_OF_MEMORY: "Out of memory",
616                DN_ERROR_RESULT_BUSY: "Result busy",
617                DN_ERROR_NO_ANSWER: "No answer",
618                DN_ERROR_NO_DIAL_TONE: "No dial tone",
619                DN_ERROR_DOC_JAM: "Document jammed",
620                DN_ERROR_DOOR_OPEN: "Door open",
621                DN_ERROR_POWER_FAILED: "Power failed",
622                DN_ERROR_BLACKLIST: "Blacklisted",
623                DN_ERROR_DOC_STORAGE_FULL: "Document storage full",
624                DN_ERROR_RESULT_COLOR_UNSUP: "Color unsupported",
625                DN_ERROR_UNKNOWN: "Unknown error"}
626
627OID_FAX_TOKEN = ('1.1.1.27', TYPE_BINARY)
628
629OID_FAX_TX_ID = ('1.1.6.3.2.3', TYPE_SIGNED_INTEGER)
630OID_FAXJOB_TX_ERROR = ('1.1.6.3.3.4.1', TYPE_SIGNED_INTEGER)
631
632OID_FAX_LOCAL_PHONE_NUM = ('1.1.3.8', TYPE_STRING)
633OID_FAX_STATION_NAME = ('1.1.3.9', TYPE_STRING)
634OID_FAX_LINE_TYPE = ('1.3.7.1.16', TYPE_ENUMERATION)
635OID_FAX_ANSWERMODE = ('1.1.9.2.1.1', TYPE_ENUMERATION)
636OID_FAX_RING_ENABLE = ('1.3.7.1.8', TYPE_ENUMERATION)
637OID_FAX_NUM_RINGS_PICKUP = ('1.1.9.2.1.2', TYPE_SIGNED_INTEGER)
638OID_FAX_MIN_RINGS_PICKUP = ('1.3.7.2.2', TYPE_SIGNED_INTEGER)
639OID_FAX_MAX_RINGS_PICKUP = ('1.3.7.2.3', TYPE_SIGNED_INTEGER)
640OID_FAX_RING_TYPE_PICKUP = ('1.1.9.2.1.3', TYPE_COLLECTION)
641OID_FAX_DIAL_MODE = ('1.1.9.1.1.1', TYPE_ENUMERATION)
642OID_FAX_ALLOW_REDIALS = ('1.4.2.5.3', TYPE_ENUMERATION)
643OID_FAX_REDIAL = ('1.1.9.1.1.2', TYPE_COLLECTION)
644OID_FAX_RESOLUTION = ('1.4.2.1.1', TYPE_BINARY)
645OID_FAX_CONTRAST = ('1.4.2.1.2', TYPE_SIGNED_INTEGER)
646
647#OID_FAX_UPLOAD = ('1.3.7.2.1', TYPE_ENUMERATION)
648#OID_FAX_UPLOAD_ERROR = ('1.3.7.2.7', TYPE_SIGNED_INTEGER)
649
650OID_FAX_CFG_UPLOAD_DATA_TYPE = ('1.1.1.14', TYPE_ENUMERATION)
651FAX_CFG_UPLOAD_DATA_TYPE_SPEEDDIALS = 5
652FAX_CFG_UPLOAD_DATA_TYPE_FAXLOGS = 6
653FAX_CFG_UPLOAD_DATA_TYPE_CONFIG_PARAMS = 7
654FAX_CFG_UPLOAD_DATA_TYPE_JUNK_FAX_DIAL_STRINGS = 8
655
656OID_UPLOAD_TIMEOUT = ('1.1.1.18', TYPE_SIGNED_INTEGER)
657DEFAULT_UPLOAD_TIMEOUT = 60
658
659OID_DEVICE_CFG_UPLOAD = ('1.1.1.13', TYPE_ENUMERATION)
660
661#
662# Copier
663#
664
665OID_COPIER_TOKEN = ('1.1.1.24', TYPE_BINARY)
666OID_COPY_SCANNER_DIMENSIONS = ('1.2.2.2.13', TYPE_STRING)
667
668# Sticky settings
669OID_COPIER_CONTRAST = ('1.5.1.2', TYPE_SIGNED_INTEGER) # -125, -100, -75, -50, -25, 0, 25, 50, 75, 100, 125
670OID_COPIER_REDUCTION = ('1.5.1.4', TYPE_SIGNED_INTEGER) # (100%=no scaling) (OID_COPIER_FIT_TO_PAGE overrides)
671                                                        # range: COPIER-REDUCTION-MAXIMUM (25) - COPIER-ENLARGEMENT-MAXIMUM (400)
672OID_COPIER_NUM_COPIES = ('1.5.1.6', TYPE_SIGNED_INTEGER) # 1-99
673
674OID_COPIER_COLLATION = ('1.5.1.7', TYPE_ENUMERATION)
675COPIER_COLLATION_DISABLED = 1
676COPIER_COLLATION_FORWARD = 2
677
678OID_COPIER_ENLARGEMENT_MAXIMUM = ('1.5.1.11', TYPE_SIGNED_INTEGER) # default 400
679OID_COPIER_REDUCTION_MAXIMUM = ('1.5.1.12', TYPE_SIGNED_INTEGER) # default 25
680
681OID_COPIER_QUALITY = ('1.5.1.13', TYPE_ENUMERATION)
682COPIER_QUALITY_FAST = 1
683COPIER_QUALITY_NORMAL = 2
684COPIER_QUALITY_PRESENTATION = 3
685COPIER_QUALITY_DRAFT = 4
686COPIER_QUALITY_BEST = 5
687
688OID_COPIER_ADF_PAGE_COUNT = ('1.5.1.19', TYPE_SIGNED_INTEGER)
689OID_COPIER_PRINT_PAGE_COUNT = ('1.5.1.20', TYPE_SIGNED_INTEGER)
690
691OID_COPIER_FIT_TO_PAGE = ('1.5.1.47', TYPE_ENUMERATION)
692COPIER_FIT_TO_PAGE_DISABLED = 1
693COPIER_FIT_TO_PAGE_ENABLED = 2
694
695# Job (non-sticky) settings
696OID_COPIER_JOB_QUALITY = ('1.5.1.22', TYPE_ENUMERATION)
697# use enums from OID_COPIER_QUALITY
698
699OID_COPIER_JOB_MEDIA_SIZE = ('1.5.1.21', TYPE_ENUMERATION)
700COPIER_JOB_MEDIA_SIZE_US_LETTER = 2
701COPIER_JOB_MEDIA_SIZE_US_LEGAL = 3
702COPIER_JOB_MEDIA_SIZE_A4 = 26
703
704OID_COPIER_JOB_COLLATION = ('1.5.1.23', TYPE_ENUMERATION)
705# use enums from OID_COPIER_COLLATION
706
707OID_COPIER_JOB_NUM_COPIES = ('1.5.1.24', TYPE_SIGNED_INTEGER)
708OID_COPIER_JOB_REDUCTION = ('1.5.1.25', TYPE_SIGNED_INTEGER)
709OID_COPIER_JOB_CONTRAST = ('1.5.1.26', TYPE_SIGNED_INTEGER) # -125, -100, -75, -50, -25, 0, 25, 50, 75, 100, 125
710
711OID_COPIER_JOB_FIT_TO_PAGE = ('1.5.1.48', TYPE_ENUMERATION)
712# use enums from OID_COPIER_FIT_TO_PAGE
713
714# Copy job
715
716OID_COPIER_JOB = ('1.5.1.27', TYPE_ENUMERATION)
717COPIER_JOB_IDLE = 1
718COPIER_JOB_START = 2
719COPIER_JOB_ACTIVE = 3
720COPIER_JOB_ABORTING = 4
721COPIER_JOB_SETUP = 5
722
723# AiO Specific Copy
724
725OID_COLOR_COPY_REQUEST = ('1.5.1.8', TYPE_ENUMERATION)
726OID_SCAN_TO_PRINTER = ('1.5.1.5', TYPE_SIGNED_INTEGER)
727SCAN_TO_PRINTER_IDLE         = 1
728SCAN_TO_PRINTER_START        = 2
729SCAN_TO_PRINTER_ACTIVE       = 3
730SCAN_TO_PRINTER_ABORTED      = 4
731SCAN_TO_PRINTER_SET_DEFAULTS = 5
732SCAN_TO_PRINTER_GET_DEFAULTS = 6
733
734OID_PIXEL_DATA_TYPE = ('1.5.1.3', TYPE_SIGNED_INTEGER)
735PIXEL_DATA_TYPE_GRAYSCALE_256     = 8
736PIXEL_DATA_TYPE_COLOR_24_BIT      = 24
737
738OID_COPIER_SPECIAL_FEATURES = ('1.5.1.16', TYPE_SIGNED_INTEGER)
739COPY_FEATURE_NONE     = 1
740COPY_FEATURE_CLONE    = 2
741COPY_FEATURE_POSTER   = 3
742COPY_FEATURE_MIRROR   = 4
743COPY_FEATURE_AUTOFIT  = 5
744COPY_FEATURE_TWOUP    = 6
745COPY_FEATURE_AUTOFILL = 7
746
747
748OID_COPIER_PHOTO_MODE = ('1.5.1.15', TYPE_COLLECTION)
749ENHANCE_LIGHT_COLORS  =  0x00000001  # Bit  0
750ENHANCE_TEXT          =  0x00000002  # Bit  1
751
752OID_COPIER_NUM_COPIES_AIO = ('1.5.1.6', TYPE_SIGNED_INTEGER)
753OID_COPIER_CONTRAST_AIO = ('1.5.1.2', TYPE_SIGNED_INTEGER)
754OID_COPIER_REDUCTION_AIO = ('1.5.1.4', TYPE_SIGNED_INTEGER)
755OID_COPIER_QUALITY_AIO = ('1.5.1.13', TYPE_ENUMERATION)
756
757OID_COPIER_JOB_INPUT_TRAY_SELECT = ('1.5.1.51', TYPE_SIGNED_INTEGER)
758COPIER_JOB_INPUT_TRAY_1 = 1
759COPIER_JOB_INPUT_TRAY_2 = 1
760COPIER_JOB_INPUT_TRAY_3 = 1
761
762OID_COPIER_MEDIA_TYPE = ('1.5.1.14', TYPE_SIGNED_INTEGER)
763COPIER_MEDIA_TYPE_PLAIN               = 1
764COPIER_MEDIA_TYPE_BRIGHT_WHITE        = 2
765COPIER_MEDIA_TYPE_PREMIUM_PHOTO       = 3
766COPIER_MEDIA_TYPE_SPECIAL             = 4
767COPIER_MEDIA_TYPE_TRANSPARENCY        = 5
768COPIER_MEDIA_TYPE_IRON_ON             = 6
769COPIER_MEDIA_TYPE_FAST_TRANSPARANCEY  = 7
770COPIER_MEDIA_TYPE_BROCHURE_MATTE      = 8
771COPIER_MEDIA_TYPE_BROCHURE_GLOSSY     = 9
772COPIER_MEDIA_TYPE_PHOTO_GLOSSY        = 10
773COPIER_MEDIA_TYPE_MATTE_PAPER         = 11
774COPIER_MEDIA_TYPE_EVERYDAY_PHOTO      = 12
775COPIER_MEDIA_TYPE_PHOTO_QUAL_INKJET   = 13
776COPIER_MEDIA_TYPE_PHOTO               = 14
777COPIER_MEDIA_TYPE_AUTOMATIC           = 15
778COPIER_MEDIA_TYPE_ADVANCED_PHOTO      = 16
779COPIER_MEDIA_TYPE_IRON_ON_MIRRORED    = 17
780
781
782
783# Misc
784
785OID_DATE_AND_TIME = ('1.1.2.17', TYPE_BINARY)
786
787
788
789