1 /*****************************************************************************\
3 hpmudi.h - internal definitions for multi-point transport driver
5 (c) 2004-2007 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 Author: Naga Samrat Chowdary Narla,
25 \*****************************************************************************/
34 #include <sys/types.h>
46 #include <arpa/inet.h>
52 #ifdef HAVE_LIBNETSNMP
59 // Don DO NOT commit with HPMUD_DEBUG enabled :(
62 #define _STRINGIZE(x) #x
63 #define STRINGIZE(x) _STRINGIZE(x)
65 #define BUG(args...) syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args)
66 //#define BUG(args...) fprintf(stderr, __FILE__ " " STRINGIZE(__LINE__) ": " args)
69 #define DBG(args...) syslog(LOG_INFO, __FILE__ " " STRINGIZE(__LINE__) ": " args)
70 // #define DBG(args...) fprintf(stderr, __FILE__ " " STRINGIZE(__LINE__) ": " args)
71 #define DBG_DUMP(data, size) sysdump((data), (size))
72 #define DBG_SZ(args...) syslog(LOG_INFO, args)
75 #define DBG_DUMP(data, size)
76 #define DBG_SZ(args...)
79 #define HEX2INT(x, i) if (x >= '0' && x <= '9') i |= x - '0'; \
80 else if (x >= 'A' && x <= 'F') i |= 0xA + x - 'A'; \
81 else if (x >= 'a' && x <= 'f') i |= 0xA + x - 'a'
83 /* offset_of returns the number of bytes that the fieldname MEMBER is offset from the beginning of the structure TYPE */
84 #define offset_of(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
86 #define HPMUD_EXCEPTION_TIMEOUT 45000000 /* microseconds */
87 #define HPMUD_EXCEPTION_SEC_TIMEOUT 45 /* seconds */
88 #define HPMUD_MDNS_TIMEOUT 10 /* seconds */
90 #define NFAULT_BIT 0x08
91 #define PERROR_BIT 0x20
95 HPMUD_PML_CHANNEL = 1,
96 HPMUD_PRINT_CHANNEL = 2,
97 HPMUD_SCAN_CHANNEL = 4,
98 HPMUD_FAX_SEND_CHANNEL = 7,
99 HPMUD_CONFIG_UPLOAD_CHANNEL = 0xe,
100 HPMUD_CONFIG_DOWNLOAD_CHANNEL = 0xf,
101 HPMUD_MEMORY_CARD_CHANNEL = 0x11,
102 HPMUD_EWS_CHANNEL = 0x12, /* Embeded Web Server interface ff/1/1, any unused socket id */
103 HPMUD_SOAPSCAN_CHANNEL = 0x13, /* Soap Scan interface ff/2/1, any unused socket id */
104 HPMUD_SOAPFAX_CHANNEL = 0x14, /* Soap Fax interface ff/3/1, any unused socket id */
105 HPMUD_MARVELL_SCAN_CHANNEL = 0x15, /* Marvell scan interface ff/ff/ff, any unused socket id */
106 HPMUD_MARVELL_FAX_CHANNEL = 0x16, /* Marvell fax interface ff/ff/ff, any unused socket id */
107 HPMUD_EWS_LEDM_CHANNEL = 0x17, /* Embeded Web Server interface ff/4/1, any unused socket id */
108 HPMUD_LEDM_SCAN_CHANNEL = 0x18, /* LEDM scan interface ff/cc/0, any unused socket id */
109 HPMUD_WIFI_CHANNEL = 0x2b, /* WIFI config */
110 HPMUD_DEVMGMT_CHANNEL = 0x2c, /* decimal 44 */
114 #define HPMUD_DEVICE_MAX 2 /* zero is not used */
115 #define HPMUD_CHANNEL_MAX HPMUD_MAX_CHANNEL_ID
117 /* MLC/1284.4 attributes. Note for MLC, attributes must remain persistant while transport is up. */
120 unsigned short h2pcredit; /* host to peripheral credit (dot4: primary socket id credit for sending) */
121 unsigned short p2hcredit; /* peripheral to host credit (dot4: secondary socket id credit for sending) */
122 unsigned short h2psize; /* host to peripheral packet size in bytes (dot4: primary max packet size for sending) */
123 unsigned short p2hsize; /* peripheral to host packet size in bytes (dot4: secondary max packet size for sending) */
124 } transport_attributes;
126 typedef struct _mud_channel_vf
128 enum HPMUD_RESULT (*open)(struct _mud_channel *pc); /* transport specific open */
129 enum HPMUD_RESULT (*close)(struct _mud_channel *pc); /* transport specific close */
130 enum HPMUD_RESULT (*channel_write)(struct _mud_channel *pc, const void *buf, int size, int timeout, int *bytes_wrote); /* tranport specific write */
131 enum HPMUD_RESULT (*channel_read)(struct _mud_channel *pc, void *buf, int size, int timeout, int *bytes_read); /* transport specific read */
134 typedef struct _mud_device_vf
136 int (*write)(int fd, const void *buf, int size, int usec_timeout); /* low level device write */
137 int (*read)(int fd, void *buf, int size, int usec_timout); /* low level device read */
138 enum HPMUD_RESULT (*open)(struct _mud_device *pd); /* device specific open */
139 enum HPMUD_RESULT (*close)(struct _mud_device *pd); /* device specific close */
140 enum HPMUD_RESULT (*get_device_id)(struct _mud_device *pd, char *id, int size, int *bytes_read); /* IEEE 1284 device id string */
141 enum HPMUD_RESULT (*get_device_status)(struct _mud_device *pd, unsigned int *status); /* device 8-bit status */
142 enum HPMUD_RESULT (*channel_open)(struct _mud_device *pd, const char *channel_name, HPMUD_CHANNEL *cd); /* channel specific open */
143 enum HPMUD_RESULT (*channel_close)(struct _mud_device *pd, struct _mud_channel *pc); /* channel specific close */
144 enum HPMUD_RESULT (*channel_write)(struct _mud_device *pd, struct _mud_channel *pc, const void *buf, int size, int sec_timeout, int *bytes_wrote);
145 enum HPMUD_RESULT (*channel_read)(struct _mud_device *pd, struct _mud_channel *pc, void *buf, int size, int sec_timeout, int *bytes_read);
148 typedef struct _mud_channel
150 char sn[HPMUD_LINE_SIZE]; /* service name */
151 unsigned char sockid; /* socket id */
152 int client_cnt; /* number of clients using this channel */
153 int index; /* channel[index] of this object */
154 int fd; /* file descriptor for this channel */
155 pid_t pid; /* process owner */
156 int dindex; /* device[dindex] parent device */
158 /* MLC/1284.4 specific variables. */
159 transport_attributes ta;
160 unsigned char rbuf[HPMUD_BUFFER_SIZE]; /* read packet buffer */
164 /* JetDirect specific data. */
170 typedef struct _mud_device
172 char uri[HPMUD_LINE_SIZE];
173 char id[1024]; /* device id */
174 int index; /* device[index] of this object */
175 enum HPMUD_IO_MODE io_mode;
176 mud_channel channel[HPMUD_CHANNEL_MAX];
177 int channel_cnt; /* number of open channels */
178 int open_fd; /* file descriptor used by device_open */
180 /* MLC/1284.4 specific variables. */
181 int mlc_up; /* 0=transport down, 1=transport up */
182 int mlc_fd; /* file descriptor used by 1284.4/MLC transport */
184 /* JetDirect specific data. */
185 char ip[HPMUD_LINE_SIZE]; /* internet address */
188 mud_device_vf vf; /* virtual function table */
189 pthread_mutex_t mutex;
194 mud_device device[HPMUD_DEVICE_MAX];
195 pthread_mutex_t mutex;
198 extern mud_session *msp __attribute__ ((visibility ("hidden")));
200 void __attribute__ ((visibility ("hidden"))) sysdump(const void *data, int size);
201 int __attribute__ ((visibility ("hidden"))) mm_device_lock(int fd, HPMUD_DEVICE index);
202 int __attribute__ ((visibility ("hidden"))) mm_device_unlock(int fd, HPMUD_DEVICE index);
203 int __attribute__ ((visibility ("hidden"))) mm_device_trylock(int fd, HPMUD_DEVICE index);
204 int __attribute__ ((visibility ("hidden"))) is_hp(const char *id);
205 int __attribute__ ((visibility ("hidden"))) generalize_model(const char *sz, char *buf, int bufSize);
206 int __attribute__ ((visibility ("hidden"))) generalize_serial(const char *sz, char *buf, int bufSize);
207 int __attribute__ ((visibility ("hidden"))) get_uri_model(const char *uri, char *buf, int bufSize);
208 int __attribute__ ((visibility ("hidden"))) get_uri_serial(const char *uri, char *buf, int bufSize);
209 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) service_to_channel(mud_device *pd, const char *sn, HPMUD_CHANNEL *index);