1 /*****************************************************************************\
2 
3   hpmud.h - public definitions for multi-point transport driver
4 
5   (c) 2004-2015 Copyright HP Development Company, LP
6 
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:
13 
14   The above copyright notice and this permission notice shall be included in all
15   copies or substantial portions of the Software.
16 
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.
23 
24   Author: Naga Samrat Chowdary Narla, Yashwant Sahu, Sarbeswar Meher
25 \*****************************************************************************/
26 
27 #ifndef _HPMUD_H
28 #define _HPMUD_H
29 
30 enum HPMUD_RESULT
31 {
32    HPMUD_R_OK = 0,
33    HPMUD_R_INVALID_DEVICE = 2,
34    HPMUD_R_INVALID_DESCRIPTOR = 3,
35    HPMUD_R_INVALID_URI = 4,
36    HPMUD_R_INVALID_LENGTH = 8,
37    HPMUD_R_IO_ERROR = 12,
38    HPMUD_R_DEVICE_BUSY = 21,
39    HPMUD_R_INVALID_SN = 28,
40    HPMUD_R_INVALID_CHANNEL_ID = 30,
41    HPMUD_R_INVALID_STATE = 31,
42    HPMUD_R_INVALID_DEVICE_OPEN = 37,
43    HPMUD_R_INVALID_DEVICE_NODE = 38,
44    HPMUD_R_INVALID_IP = 45,
45    HPMUD_R_INVALID_IP_PORT = 46,
46    HPMUD_R_INVALID_TIMEOUT = 47,
47    HPMUD_R_DATFILE_ERROR = 48,
48    HPMUD_R_IO_TIMEOUT = 49,
49    HPMUD_R_INVALID_MDNS = 50,
50 };
51 
52 enum HPMUD_IO_MODE
53 {
54    HPMUD_UNI_MODE=0, /* uni-di */
55    HPMUD_RAW_MODE=1,   /* bi-di */
56    HPMUD_DOT4_MODE=3,
57    HPMUD_DOT4_PHOENIX_MODE=4,  /* (ie: clj2550, clj2840, lj3050, lj3055, clj4730mfp) */
58    HPMUD_DOT4_BRIDGE_MODE=5,  /* (ie: clj2500) not USB compatable, use HPMUD_RAW_MODE, tested on F10 12/10/08 DES */
59    HPMUD_MLC_GUSHER_MODE=6,   /* most new devices */
60    HPMUD_MLC_MISER_MODE=7,  /* old stuff */
61 };
62 
63 enum HPMUD_BUS_ID
64 {
65    HPMUD_BUS_NA=0,
66    HPMUD_BUS_USB=1,
67    HPMUD_BUS_PARALLEL,
68    HPMUD_BUS_ALL
69 };
70 
71 enum HPMUD_DEVICE_TYPE
72 {
73    HPMUD_AIO=0,
74    HPMUD_PRINTER=1,
75    HPMUD_SCANNER=2,
76 };
77 
78 enum HPMUD_SCANTYPE
79 {
80    HPMUD_SCANTYPE_NA = 0,
81    HPMUD_SCANTYPE_SCL = 1,
82    HPMUD_SCANTYPE_PML = 2,
83    HPMUD_SCANTYPE_SOAP = 3,    /* Wookie (ie:ljcm1017) */
84    HPMUD_SCANTYPE_MARVELL = 4,     /* (ie: ljm1005) */
85    HPMUD_SCANTYPE_SOAPHT = 5,   /* HorseThief (ie: ljm1522) */
86    HPMUD_SCANTYPE_SCL_DUPLEX = 6,
87    HPMUD_SCANTYPE_LEDM = 7,
88    HPMUD_SCANTYPE_MARVELL2 = 8,     /* (Tsunami lj 1212  and series) */
89    HPMUD_SCANTYPE_ESCL=9,
90    HPMUD_SCANTYPE_ORBLITE=10
91 };
92 
93 enum HPMUD_SCANSRC
94 {
95    HPMUD_SCANSRC_NA = 0,
96    HPMUD_SCANSRC_FLATBED = 0x1,
97    HPMUD_SCANSRC_ADF= 0x2,
98    HPMUD_SCANSRC_CAMERA = 0x4,
99 };
100 
101 enum HPMUD_STATUSTYPE
102 {
103    HPMUD_STATUSTYPE_NA = 0,
104    HPMUD_STATUSTYPE_VSTATUS = 1,  /* device-id vstatus */
105    HPMUD_STATUSTYPE_SFIELD = 2,   /* device-id s-field */
106    HPMUD_STATUSTYPE_PML = 3,      /* laserjet pml */
107    HPMUD_STATUSTYPE_EWS = 6,      /* laserjet hp ews */
108    HPMUD_STATUSTYPE_PJL = 8,      /* laserjet pjl */
109    HPMUD_STATUSTYPE_PJLPML = 9,   /* laserjet pjl and pml */
110 };
111 
112 enum HPMUD_SUPPORT_TYPE
113 {
114    HPMUD_SUPPORT_TYPE_NONE = 0,   /* not supported */
115    HPMUD_SUPPORT_TYPE_HPIJS = 1,  /* supported by hpijs only */
116    HPMUD_SUPPORT_TYPE_HPLIP = 2,   /* supported by hpijs and "hp" backend */
117 };
118 
119 enum HPMUD_PLUGIN_TYPE
120 {
121    HPMUD_PLUGIN_TYPE_NONE = 0,
122    HPMUD_PLUGIN_TYPE_REQUIRED = 1,
123    HPMUD_PLUGIN_TYPE_OPTIONAL = 2,
124 };
125 
126 
127 
128 #define HPMUD_S_PRINT_CHANNEL "PRINT"
129 #define HPMUD_S_PML_CHANNEL "HP-MESSAGE"
130 #define HPMUD_S_SCAN_CHANNEL "HP-SCAN"
131 #define HPMUD_S_FAX_SEND_CHANNEL "HP-FAX-SEND"
132 #define HPMUD_S_CONFIG_UPLOAD_CHANNEL "HP-CONFIGURATION-UPLOAD"
133 #define HPMUD_S_CONFIG_DOWNLOAD_CHANNEL "HP-CONFIGURATION-DOWNLOAD"
134 #define HPMUD_S_MEMORY_CARD_CHANNEL "HP-CARD-ACCESS"
135 #define HPMUD_S_EWS_CHANNEL "HP-EWS"
136 #define HPMUD_S_EWS_LEDM_CHANNEL "HP-EWS-LEDM"
137 #define HPMUD_S_SOAP_SCAN "HP-SOAP-SCAN"
138 #define HPMUD_S_SOAP_FAX "HP-SOAP-FAX"
139 #define HPMUD_S_DEVMGMT_CHANNEL "HP-DEVMGMT"
140 #define HPMUD_S_MARVELL_SCAN_CHANNEL "HP-MARVELL-SCAN"
141 #define HPMUD_S_MARVELL_FAX_CHANNEL "HP-MARVELL-FAX"
142 #define HPMUD_S_LEDM_SCAN "HP-LEDM-SCAN"
143 #define HPMUD_S_WIFI_CHANNEL "HP-WIFICONFIG"
144 #define HPMUD_S_MARVELL_EWS_CHANNEL "HP-MARVELL-EWS"
145 #define HPMUD_S_IPP_CHANNEL "HP-IPP"
146 #define HPMUD_S_IPP_CHANNEL2 "HP-IPP2"
147 #define HPMUD_S_ESCL_SCAN "HP-ESCL-SCAN"
148 
149 typedef int HPMUD_DEVICE;       /* usb, parallel or jetdirect */
150 #define HPMUD_DEVICE_MAX 2      /* zero is not used */
151 
152 typedef int HPMUD_CHANNEL;
153 #define HPMUD_CHANNEL_MAX HPMUD_MAX_CHANNEL_ID
154 
155 #define HPMUD_LINE_SIZE 256     /* Length of a line. */
156 #define HPMUD_BUFFER_SIZE 16384  /* General Read/Write buffer. */
157 
158 struct hpmud_dstat
159 {
160    char uri[HPMUD_LINE_SIZE];
161    int client_cnt;                  /* number of clients that have this device opend */
162    enum HPMUD_IO_MODE io_mode;
163    int channel_cnt;                 /* number of open channels */
164    int mlc_up;                      /* 0 = MLC/1284.4 transport up, 1 = MLD/1284.4 transport down */
165 };
166 
167 struct hpmud_model_attributes
168 {
169    enum HPMUD_IO_MODE prt_mode;        /* print only (io_mode) */
170    enum HPMUD_IO_MODE mfp_mode;        /* pml | scan | fax (io_mode) */
171    enum HPMUD_SCANTYPE scantype;       /* scan protocol i.e. SCL, PML, SOAP, MARVELL, LEDM */
172    enum HPMUD_STATUSTYPE statustype;
173    enum HPMUD_SUPPORT_TYPE support;
174    enum HPMUD_PLUGIN_TYPE plugin;
175    enum HPMUD_SUPPORT_TYPE reserved[5];
176    enum HPMUD_SCANSRC scansrc; /*Flatbed, ADF, Camera or combination of these*/
177 };
178 
179 #ifdef __cplusplus
180 extern "C" {
181 #endif
182 
183 /*
184  * hpmud_device_open - open specified device, call normally does not block
185  *
186  * inputs:
187  *  uri - specifies device to open
188  *  io_mode - see enum definition
189  *
190  * outputs:
191  *  dd - device descriptor
192  *  return value - see enum definition
193  */
194 enum HPMUD_RESULT hpmud_open_device(const char *uri, enum HPMUD_IO_MODE io_mode, HPMUD_DEVICE *dd);
195 
196 /*
197  * hpmud_device_close - close specified device, call does not block
198  *
199  * inputs:
200  *  dd - device descriptor
201  *
202  * outputs:
203  *  return value - see enum definition
204  */
205 enum HPMUD_RESULT hpmud_close_device(HPMUD_DEVICE dd);
206 
207 /*
208  * hpmud_get_device_id - read IEEE 1284 device ID string, call normally does not block
209  *
210  * If the device is busy, a cached copy may be returned.
211  *
212  * inputs:
213  *  dd - device descriptor
214  *  buf_size - maximum size of buf
215  *
216  * outputs:
217  *  buf - zero terminated device ID string
218  *  bytes_read - size of device ID string, does not include zero termination
219  *  return value - see enum definition
220  */
221 enum HPMUD_RESULT hpmud_get_device_id(HPMUD_DEVICE dd, char *buf, int buf_size, int *bytes_read);
222 
223 /*
224  * hpmud_get_device_status - read 8-bit device status, call normally does not block
225  *
226  * inputs:
227  *  dd - device descriptor
228  *
229  * outputs:
230  *  status - 3-bit status, supported by inkjets only
231  *  return value - see enum definition
232  */
233 enum HPMUD_RESULT hpmud_get_device_status(HPMUD_DEVICE dd, unsigned int *status);
234 
235 /*
236  * hpmud_probe_devices - probe local buses for HP supported devices, call normally does not block
237  *
238  * inputs:
239  *  bus - see enum definiton
240  *  buf_size - size of read buffer
241  *
242  * outputs:
243  *  buf - zero terminated CUPS backend formatted data
244  *  cnt - number of HP devices found
245  *  bytes_read - number of bytes actually read
246  *  return value - see enum definition
247  */
248 enum HPMUD_RESULT hpmud_probe_devices(enum HPMUD_BUS_ID bus, char *buf, int buf_size, int *cnt, int *bytes_read);
249 
250 /*
251  * hpmud_probe_printers - probe local buses for HP supported printers, call normally does not block
252  *
253  * inputs:
254  *  bus - see enum definiton
255  *  buf_size - size of read buffer
256  *
257  * outputs:
258  *  buf - zero terminated CUPS backend formatted data
259  *  cnt - number of HP devices found
260  *  bytes_read - number of bytes actually read
261  *  return value - see enum definition
262  */
263 enum HPMUD_RESULT hpmud_probe_printers(enum HPMUD_BUS_ID bus, char *buf, int buf_size, int *cnt, int *bytes_read);
264 
265 /*
266  * hpmud_channel_open - open specified channel, call will block
267  *
268  * Only EWS channel can be opened by more than one process.
269  *
270  * inputs:
271  *  dd - device descriptor
272  *  channel_name - requested service name
273  *
274  * outputs:
275  *  cd - channel descriptor
276  *  return value - see enum definition
277  */
278 enum HPMUD_RESULT hpmud_open_channel(HPMUD_DEVICE dd, const char *channel_name, HPMUD_CHANNEL *cd);
279 
280 /*
281  * hpmud_channel_close - close specified channel, call will block
282  *
283  * inputs:
284  *  dd - device descriptor
285  *  cd - channel descriptor
286  *
287  * outputs:
288  *  return value - see enum definition
289  */
290 enum HPMUD_RESULT hpmud_close_channel(HPMUD_DEVICE dd, HPMUD_CHANNEL cd);
291 
292 /*
293  * hpmud_channel_write - write data to specified channel, call will block
294  *
295  * May return with partial bytes written (ie: bytes_wrote < size) with or with-out a timeout.
296  *
297  * inputs:
298  *  dd - device descriptor
299  *  cd - channel descriptor
300  *  buf - data to write
301  *  size - number of bytes to write
302  *  timeout - in seconds
303  *
304  * outputs:
305  *  bytes_wrote - number of bytes actually wrote
306  *  return value - see enum definition
307  */
308 enum HPMUD_RESULT hpmud_write_channel(HPMUD_DEVICE dd, HPMUD_CHANNEL cd, const void *buf, int size, int timeout, int *bytes_written);
309 
310 /*
311  * hpmud_channel_read - read data from specified channel, call will block
312  *
313  * May return with partial bytes read (ie: bytes_read < size) or zero if timeout occured.
314  *
315  * inputs:
316  *  dd - device descriptor
317  *  cd - channel descriptor
318  *  size - number of bytes to read
319  *  timeout - in seconds
320  *
321  * outputs:
322  *  buf - read data buffer
323  *  bytes_read - number of bytes actually read
324  *  return value - see enum definition
325  */
326 enum HPMUD_RESULT hpmud_read_channel(HPMUD_DEVICE dd, HPMUD_CHANNEL cd, void *buf, int size, int timeout, int *bytes_read);
327 
328 /*
329  * hpmud_dstat - get device information
330  *
331  * inputs:
332  *  dd - device descriptor
333  *
334  * outputs:
335  *  ds - see dstat definition
336  *  return value - see enum definition
337  */
338 enum HPMUD_RESULT hpmud_get_dstat(HPMUD_DEVICE dd, struct hpmud_dstat *ds);
339 
340 /*
341  * hpmud_set_pml - set pml object
342  *
343  * Set_pml is a high level interface to hpmud. This command calls the hpmud core interface.
344  * This command can be used with local or jetdirect connections. Jetdirect connection will
345  * use snmp.
346  *
347  * inputs:
348  *  dd - device descriptor
349  *  cc - channel descriptor
350  *  snmp_oid - snmp encoded pml oid
351  *  type - oid data type
352  *  data - data payload
353  *  data_size - number of bytes to write
354  *
355  * outputs:
356  *  pml_result
357  *  return value - see enum definition
358  */
359 enum HPMUD_RESULT hpmud_set_pml(HPMUD_DEVICE device, HPMUD_CHANNEL channel, const char *snmp_oid, int type, void *data, int data_size, int *pml_result);
360 
361 /*
362  * hpmud_get_pml - get pml object
363  *
364  * Get_pml is a high level interface to hpmud. This command calls the hpmud core interface.
365  * This command can be used with local or jetdirect connections. Jetdirect connection will
366  * use snmp.
367  *
368  * inputs:
369  *  dd - device descriptor
370  *  cc - channel descriptor
371  *  snmp_oid - snmp encoded pml oid
372  *  data_size - data buffer size in bytes
373  *
374  * outputs:
375  *  data - data payload
376  *  type - pml data type
377  *  pml_result
378  *  return value - see enum definition
379  */
380 enum HPMUD_RESULT hpmud_get_pml(HPMUD_DEVICE device, HPMUD_CHANNEL channel, const char *snmp_oid, void *buf, int buf_size, int *bytes_read, int *type, int *pml_result);
381 
382 /*
383  * hpmud_get_model - parse device model from the IEEE 1284 device id string.
384  *
385  * This function is a stateless hpmud helper function.
386  *
387  * inputs:
388  *  id - IEEE 1284 device id string
389  *  buf_size - size of buf in bytes
390  *
391  * outputs:
392  *  buf - device model string (generalized)
393  *  return value - length of string in bytes, does not include zero termination
394  */
395 int hpmud_get_model(const char *id, char *buf, int buf_size);
396 
397 /*
398  * hpmud_get_raw_model - parse device model from the IEEE 1284 device id string.
399  *
400  * This function is a stateless hpmud helper function.
401  *
402  * inputs:
403  *  id - IEEE 1284 device id string
404  *  buf_size - size of buf in bytes
405  *
406  * outputs:
407  *  buf - device model string (raw)
408  *  return value - length of string in bytes, does not include zero termination
409  */
410 int hpmud_get_raw_model(char *id, char *raw, int rawSize);
411 
412 /*
413  * hpmud_get_uri_model - parse device model from uri
414  *
415  * This function is a stateless hpmud helper function.
416  *
417  * inputs:
418  *  uri
419  *  buf_size - size of buf in bytes
420  *
421  * outputs:
422  *  buf - device model string
423  *  return value - length of string in bytes, does not include zero termination
424  */
425 int hpmud_get_uri_model(const char *uri, char *buf, int buf_size);
426 
427 /*
428  * hpmud_get_uri_datalink - parse the data link from uri
429  *
430  * This function is a stateless hpmud helper function.
431  *
432  * inputs:
433  *  uri
434  *  buf_size - size of buf in bytes
435  *
436  * outputs:
437  *  buf - device model string
438  *  return value - length of string in bytes, does not include zero termination
439  */
440 int hpmud_get_uri_datalink(const char *uri, char *buf, int buf_size);
441 
442 /*
443  * hpmud_get_model_attributes - get all model attributes for specified device
444  *
445  * Reads device model attributes from models.dat file. This function is a
446  * stateless hpmud helper function.
447  *
448  * inputs:
449  *  uri - specifies device
450  *  buf_size - size of buf in bytes
451  *
452  * outputs:
453  *  buf - buffer for all model attributes, key/value pair, one per line
454  *  bytes_read - number of bytes actually read
455  *  return value - see enum definition
456  */
457 enum HPMUD_RESULT hpmud_get_model_attributes(char *uri, char *attr, int attrSize, int *bytes_read);
458 
459 /*
460  * hpmud_model_query - get model attributes structure for specified device
461  *
462  * Reads device model attributes from models.dat file. This function is a
463  * stateless hpmud helper function.
464  *
465  * inputs:
466  *  uri - specifies device
467  *
468  * outputs:
469  *  ma - see structure definition
470  *  return value - see enum definition
471  */
472 enum HPMUD_RESULT hpmud_query_model(char *uri, struct hpmud_model_attributes *ma);
473 
474 /*
475  * hpmud_make_usb_uri - make a usb uri from bus:dev pair
476  *
477  * This function is a stateless hpmud helper function. The lsusb command can be used
478  * determine the bus:dev pair.
479  *
480  * inputs:
481  *  busnum - specifies usbfs bus number
482  *  devnum - specifies usbfs device number
483  *  uri_size - size of uri buffer in bytes
484  *
485  * outputs:
486  *  uri - zero terminated string
487  *  bytes_read - size of uri
488  *  return value - see enum definition
489  */
490 enum HPMUD_RESULT hpmud_make_usb_uri(const char *busnum, const char *devnum, char *uri, int uri_size, int *bytes_read);
491 
492 /*
493  * hpmud_make_usb_serial_uri - make a usb uri from product serial number
494  *
495  * This function is a stateless hpmud helper function. The lsusb command can be used
496  * determine the product serial number.
497  *
498  * inputs:
499  *  sn - specifies product serial number
500  *  uri_size - size of uri buffer in bytes
501  *
502  * outputs:
503  *  uri - zero terminated string
504  *  bytes_read - size of uri
505  *  return value - see enum definition
506  */
507 enum HPMUD_RESULT hpmud_make_usb_serial_uri(const char *sn, char *uri, int uri_size, int *bytes_read);
508 
509 /*
510  * hpmud_make_net_uri - make a net uri from IP
511  *
512  * This function is a stateless hpmud helper function.
513  *
514  * inputs:
515  *  ip - internet address
516  *  port - 1-4
517  *  uri_size - size of uri buffer in bytes
518  *
519  * outputs:
520  *  uri - zero terminated string
521  *  bytes_read - size of uri
522  *  return value - see enum definition
523  */
524 enum HPMUD_RESULT hpmud_make_net_uri(const char *ip, int port, char *uri, int uri_size, int *bytes_read);
525 
526 /*
527  * hpmud_make_par_uri - make a par uri from parallel port
528  *
529  * This function is a stateless hpmud helper function.
530  *
531  * inputs:
532  *  dnode - device node
533  *  uri_size - size of uri buffer in bytes
534  *
535  * outputs:
536  *  uri - zero terminated string
537  *  bytes_read - size of uri
538  *  return value - see enum definition
539  */
540 enum HPMUD_RESULT hpmud_make_par_uri(const char *dnode, char *uri, int uri_size, int *bytes_read);
541 
542 
543 /*
544  * hpmud_make_mdns_uri - make a network uri from host name
545  *
546  * This function is a stateless hpmud helper function. Requires UDP port 5353 to be open.
547  *
548  * inputs:
549  *  host - zero terminated string (ie: "npi7c8a3e")
550  *  uri_size - size of uri buffer in bytes
551  *
552  * outputs:
553  *  uri - zero terminated string
554  *  bytes_read - size of uri
555  *  return value - see enum definition
556  */
557 enum HPMUD_RESULT hpmud_make_mdns_uri(const char *host, int port, char *uri, int uri_size, int *bytes_read);
558 
559 #ifdef __cplusplus
560 }
561 #endif
562 
563 #endif // _HPMUD_H
564 
565 /*********************** For Python 2.X and 3.X support ***************************/
566 
567 
568 #if PY_MAJOR_VERSION >= 3
569   #define MOD_ERROR_VAL NULL
570   #define MOD_SUCCESS_VAL(val) val
571   #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
572   #define MOD_DEF(ob, name, doc, methods) \
573           static struct PyModuleDef moduledef = { \
574             PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
575           ob = PyModule_Create(&moduledef);
576   #define FORMAT_STRING "(iy#ii)"
577   #define FORMAT_STRING1 "(iy#)"
578 #else
579   #define MOD_ERROR_VAL
580   #define MOD_SUCCESS_VAL(val)
581   #define MOD_INIT(name) void init##name(void)
582   #define MOD_DEF(ob, name, doc, methods) \
583           ob = Py_InitModule3(name, methods, doc);
584   #define FORMAT_STRING "(is#ii)"
585   #define FORMAT_STRING1 "(is#)"
586 #endif
587