1 /* sane - Scanner Access Now Easy. 2 3 Copyright (C) 2000 Kazuya Fukuda 4 5 This file is part of the SANE package. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20 As a special exception, the authors of SANE give permission for 21 additional uses of the libraries contained in this release of SANE. 22 23 The exception is that, if you link a SANE library with other files 24 to produce an executable, this does not by itself cause the 25 resulting executable to be covered by the GNU General Public 26 License. Your use of that executable is in no way restricted on 27 account of linking the SANE library code into it. 28 29 This exception does not, however, invalidate any other reasons why 30 the executable file might be covered by the GNU General Public 31 License. 32 33 If you submit changes to SANE to the maintainers to be included in 34 a subsequent release, you agree by submitting the changes that 35 those changes may be distributed with this exception intact. 36 37 If you write modifications of your own for SANE, it is your choice 38 whether to permit this exception to apply to your modifications. 39 If you do not wish that, delete this exception notice. */ 40 41 #ifndef nec_h 42 #define nec_h 1 43 44 #include <sys/types.h> 45 46 /* default values for configurable options. 47 Though these options are only meaningful if USE_FORK is defined, 48 they are 49 DEFAULT_BUFFERS: number of buffers allocated as shared memory 50 for the data transfer from reader_process to 51 read_data. The minimum value is 2 52 DEFAULT_BUFSIZE: default size of one buffer. Must be greater 53 than zero. 54 DEFAULT_QUEUED_READS: number of read requests queued by 55 sanei_scsi_req_enter. Since queued read requests 56 are currently only supported for Linux and 57 DomainOS, this value should automatically be set 58 dependent on the target OS... 59 For Linux, 2 is the optimum; for DomainOS, I 60 don't have any recommendation; other OS 61 should use the value zero. 62 63 The value for DEFAULT_BUFSIZE is probably too Linux-oriented... 64 */ 65 66 #define DEFAULT_BUFFERS 12 67 #define DEFAULT_BUFSIZE 128 * 1024 68 #define DEFAULT_QUEUED_READS 2 69 70 #define NEC_MAJOR 0 71 #define NEC_MINOR 12 72 73 typedef enum 74 { 75 OPT_NUM_OPTS = 0, 76 77 OPT_MODE_GROUP, 78 OPT_MODE, 79 OPT_HALFTONE, 80 OPT_PAPER, 81 OPT_SCANSOURCE, 82 OPT_GAMMA, 83 #ifdef USE_CUSTOM_GAMMA 84 OPT_CUSTOM_GAMMA, 85 #endif 86 OPT_RESOLUTION_GROUP, 87 #ifdef USE_RESOLUTION_LIST 88 OPT_RESOLUTION_LIST, 89 #endif 90 OPT_RESOLUTION, 91 92 OPT_GEOMETRY_GROUP, 93 OPT_TL_X, /* top-left x */ 94 OPT_TL_Y, /* top-left y */ 95 OPT_BR_X, /* bottom-right x */ 96 OPT_BR_Y, /* bottom-right y */ 97 98 OPT_ENHANCEMENT_GROUP, 99 OPT_EDGE_EMPHASIS, 100 OPT_OR, 101 OPT_NR, 102 OPT_EDGE, 103 OPT_THRESHOLD, 104 #ifdef USE_COLOR_THRESHOLD 105 OPT_THRESHOLD_R, 106 OPT_THRESHOLD_G, 107 OPT_THRESHOLD_B, 108 #endif 109 OPT_LIGHTCOLOR, 110 OPT_TINT, 111 OPT_COLOR, 112 OPT_PREVIEW, 113 114 #ifdef USE_CUSTOM_GAMMA 115 OPT_GAMMA_VECTOR, 116 OPT_GAMMA_VECTOR_R, 117 OPT_GAMMA_VECTOR_G, 118 OPT_GAMMA_VECTOR_B, 119 #endif 120 /* must come last: */ 121 NUM_OPTIONS 122 } 123 NEC_Option; 124 125 #ifdef USE_FORK 126 127 /* status defines for a buffer: 128 buffer not used / read request queued / buffer contains data 129 */ 130 #define SHM_EMPTY 0 131 #define SHM_BUSY 1 132 #define SHM_FULL 2 133 typedef struct NEC_shmem_ctl 134 { 135 int shm_status; /* can be SHM_EMPTY, SHM_BUSY, SHM_FULL */ 136 size_t used; /* number of bytes successfully read from scanner */ 137 size_t nreq; /* number of bytes requested from scanner */ 138 size_t start; /* index of the begin of used area of the buffer */ 139 void *qid; 140 SANE_Byte *buffer; 141 } 142 NEC_shmem_ctl; 143 144 typedef struct NEC_rdr_ctl 145 { 146 int cancel; /* 1 = flag for the reader process to cancel */ 147 int running; /* 1 indicates that the reader process is alive */ 148 SANE_Status status; /* return status of the reader process */ 149 NEC_shmem_ctl *buf_ctl; 150 } 151 NEC_rdr_ctl; 152 #endif /* USE_FORK */ 153 154 typedef enum 155 { 156 /* PCIN500, PCINXXX are used as array indices, so the corresponding 157 numbers should start at 0 158 */ 159 unknown = -1, 160 PCIN500, 161 PCINXXX 162 } 163 NEC_Model; 164 165 typedef struct NEC_Info 166 { 167 SANE_Range res_range; 168 SANE_Range tl_x_ranges[3]; /* normal / FSU / ADF */ 169 SANE_Range br_x_ranges[3]; /* normal / FSU / ADF */ 170 SANE_Range tl_y_ranges[3]; /* normal / FSU / ADF */ 171 SANE_Range br_y_ranges[3]; /* normal / FSU / ADF */ 172 SANE_Range threshold_range; 173 SANE_Range tint_range; 174 SANE_Range color_range; 175 176 SANE_Int res_default; 177 SANE_Int x_default; 178 SANE_Int y_default; 179 SANE_Int bmu; 180 SANE_Int mud; 181 SANE_Int adf_fsu_installed; 182 SANE_String_Const scansources[5]; 183 size_t buffers; 184 size_t bufsize; 185 int wanted_bufsize; 186 size_t queued_reads; 187 } 188 NEC_Info; 189 190 typedef struct NEC_Sense_Data 191 { 192 NEC_Model model; 193 /* flag, if conditions like "paper jam" or "cover open" 194 are considered as an error. Should be 0 for attach, else 195 a frontend might refuse to start, if the scanner returns 196 these errors. 197 */ 198 int complain_on_adf_error; 199 /* Linux returns only 16 bytes of sense data... */ 200 u_char sb[16]; 201 } 202 NEC_Sense_Data; 203 204 typedef struct NEC_Device 205 { 206 struct NEC_Device *next; 207 SANE_Device sane; 208 NEC_Info info; 209 /* xxx now part of sense data NEC_Model model; */ 210 NEC_Sense_Data sensedat; 211 } 212 NEC_Device; 213 214 typedef struct NEC_New_Device 215 { 216 struct NEC_Device *dev; 217 struct NEC_New_Device *next; 218 } 219 NEC_New_Device; 220 221 typedef struct NEC_Scanner 222 { 223 struct NEC_Scanner *next; 224 int fd; 225 NEC_Device *dev; 226 SANE_Option_Descriptor opt[NUM_OPTIONS]; 227 Option_Value val[NUM_OPTIONS]; 228 SANE_Parameters params; 229 230 int get_params_called; 231 SANE_Byte *buffer; /* for color data re-ordering */ 232 SANE_Int buf_used; 233 SANE_Int buf_pos; 234 SANE_Int modes; 235 SANE_Int res; 236 SANE_Int ulx; 237 SANE_Int uly; 238 SANE_Int width; 239 SANE_Int length; 240 SANE_Int threshold; 241 SANE_Int image_composition; 242 SANE_Int bpp; 243 SANE_Int halftone; 244 SANE_Bool reverse; 245 SANE_Bool or; 246 SANE_Bool nr; 247 SANE_Int gamma; 248 SANE_Int edge; 249 SANE_Int lightcolor; 250 SANE_Int adf_fsu_mode; /* mode selected by user */ 251 SANE_Int adf_scan; /* flag, if the actual scan is an ADF scan */ 252 253 SANE_Int tint; 254 SANE_Int color; 255 256 size_t bytes_to_read; 257 size_t max_lines_to_read; 258 size_t unscanned_lines; 259 SANE_Bool scanning; 260 SANE_Bool busy; 261 SANE_Bool cancel; 262 #ifdef USE_CUSTOM_GAMMA 263 SANE_Int gamma_table[4][256]; 264 #endif 265 #ifdef USE_FORK 266 pid_t reader_pid; 267 NEC_rdr_ctl *rdr_ctl; 268 int shmid; 269 size_t read_buff; /* index of the buffer actually used by read_data */ 270 #endif /* USE_FORK */ 271 } 272 NEC_Scanner; 273 274 typedef struct NEC_Send 275 { 276 SANE_Int dtc; 277 SANE_Int dtq; 278 SANE_Int length; 279 SANE_Byte *data; 280 } 281 NEC_Send; 282 283 typedef struct WPDH 284 { 285 u_char wpdh[6]; 286 u_char wdl[2]; 287 } 288 WPDH; 289 290 typedef struct WDB 291 { 292 SANE_Byte wid; 293 SANE_Byte autobit; 294 SANE_Byte x_res[2]; 295 SANE_Byte y_res[2]; 296 297 SANE_Byte x_ul[4]; 298 SANE_Byte y_ul[4]; 299 SANE_Byte width[4]; 300 SANE_Byte length[4]; 301 302 SANE_Byte brightness; 303 SANE_Byte threshold; 304 SANE_Byte contrast; 305 SANE_Byte image_composition; 306 SANE_Byte bpp; 307 308 SANE_Byte ht_pattern[2]; 309 SANE_Byte rif_padding; 310 SANE_Byte bit_ordering[2]; 311 SANE_Byte compression_type; 312 SANE_Byte compression_argument; 313 SANE_Byte reserved[6]; 314 } 315 WDB; 316 317 /* "extension" of the window descriptor block for the PC-IN500 */ 318 typedef struct XWDBX500 319 { 320 SANE_Byte data_length; 321 SANE_Byte control; 322 SANE_Byte format; 323 SANE_Byte gamma; 324 SANE_Byte tint; 325 SANE_Byte color; 326 SANE_Byte reserved1; 327 SANE_Byte reserved2; 328 } 329 WDBX500; 330 331 typedef struct window_param 332 { 333 WPDH wpdh; 334 WDB wdb; 335 WDBX500 wdbx500; 336 } 337 window_param; 338 339 typedef struct mode_sense_param 340 { 341 SANE_Byte mode_data_length; 342 SANE_Byte mode_param_header2; 343 SANE_Byte mode_param_header3; 344 SANE_Byte mode_desciptor_length; 345 SANE_Byte page_code; 346 SANE_Byte page_length; /* 6 */ 347 SANE_Byte bmu; 348 SANE_Byte res2; 349 SANE_Byte mud[2]; 350 SANE_Byte res3; 351 SANE_Byte res4; 352 } 353 mode_sense_param; 354 355 typedef struct mode_sense_subdevice 356 { 357 SANE_Byte mode_data_length; 358 SANE_Byte mode_param_header2; 359 SANE_Byte mode_param_header3; 360 SANE_Byte mode_desciptor_length; 361 SANE_Byte res1[5]; 362 SANE_Byte blocklength[3]; 363 SANE_Byte page_code; 364 SANE_Byte page_length; /* 0x1a */ 365 SANE_Byte a_mode_type; 366 SANE_Byte f_mode_type; 367 SANE_Byte res2; 368 SANE_Byte max_x[4]; 369 SANE_Byte max_y[4]; 370 SANE_Byte res3[2]; 371 SANE_Byte x_basic_resolution[2]; 372 SANE_Byte y_basic_resolution[2]; 373 SANE_Byte x_max_resolution[2]; 374 SANE_Byte y_max_resolution[2]; 375 SANE_Byte x_min_resolution[2]; 376 SANE_Byte y_min_resolution[2]; 377 SANE_Byte res4; 378 } 379 mode_sense_subdevice; 380 381 typedef struct mode_select_param 382 { 383 SANE_Byte mode_param_header1; 384 SANE_Byte mode_param_header2; 385 SANE_Byte mode_param_header3; 386 SANE_Byte mode_param_header4; 387 SANE_Byte page_code; 388 SANE_Byte page_length; /* 6 */ 389 SANE_Byte res1; 390 SANE_Byte res2; 391 SANE_Byte mud[2]; 392 SANE_Byte res3; 393 SANE_Byte res4; 394 } 395 mode_select_param; 396 397 typedef struct mode_select_subdevice 398 { 399 SANE_Byte mode_param_header1; 400 SANE_Byte mode_param_header2; 401 SANE_Byte mode_param_header3; 402 SANE_Byte mode_param_header4; 403 SANE_Byte page_code; 404 SANE_Byte page_length; /* 0x1A */ 405 SANE_Byte a_mode; 406 SANE_Byte f_mode; 407 SANE_Byte res[24]; 408 } 409 mode_select_subdevice; 410 411 typedef struct buffer_status 412 { 413 SANE_Byte data_length[3]; 414 SANE_Byte block; 415 SANE_Byte window_id; 416 SANE_Byte reserved; 417 SANE_Byte bsa[3]; /* buffer space available */ 418 SANE_Byte fdb[3]; /* filled data buffer */ 419 } 420 buffer_status; 421 422 /* SCSI commands */ 423 #define TEST_UNIT_READY 0x00 424 #define REQUEST_SENSE 0x03 425 #define INQUIRY 0x12 426 #define MODE_SELECT6 0x15 427 #define RESERVE_UNIT 0x16 428 #define RELEASE_UNIT 0x17 429 #define MODE_SENSE6 0x1a 430 #define SCAN 0x1b 431 #define SEND_DIAGNOSTIC 0x1d 432 #define SET_WINDOW 0x24 433 #define GET_WINDOW 0x25 434 #define READ 0x28 435 #define SEND 0x2a 436 #define GET_DATA_BUFFER_STATUS 0x34 437 438 #define SENSE_LEN 18 439 #define INQUIRY_LEN 36 440 #define MODEPARAM_LEN 12 441 #define MODE_SUBDEV_LEN 32 442 #define WINDOW_LEN 76 443 #define BUFFERSTATUS_LEN 12 444 445 #endif /* not nec_h */ 446