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