Debian Codegraph @

src/cups/backend_magicard.c

raw symbols SCIP
1 /*
2 * Magicard card printer family CUPS backend
3 *
4 * (c) 2017-2025 Solomon Peachy <[email protected]>
5 *
6 * The latest version of this program can be found at:
7 *
8 * https://git.shaftnet.org/gitea/slp/selphy_print.git
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
22 *
23 * SPDX-License-Identifier: GPL-2.0+
24 *
25 */
26
27 #define BACKENDcxx . . $ `src/cups/backend_magicard.c:27:9`! magicard_backend
28
29 #include "backend_common.h"cxx . . $ `<file>/src/cups/backend_common.h`/
30
31 #include <time.h>
32
33 /* Gamma tables computed with this perl program:
34
35 my $input_bpp = 8;
36 my $output_bpp = 6;
37 my $gamma = 1/1.8; # or 1/2.2 or whatever.
38
39 my $i;
40
41 for (my $i = 0 ; $i < (2 ** $input_bpp) ; $i++) {
42 my $linear = $i / (2 ** $input_bpp);
43 my $gc = ($linear ** $gamma) * (2 ** $output_bpp);
44 $gc = int($gc);
45 print "$gc, ";
46 }
47
48 */
49
50 static uint8_tcxx . . $ uint8_t# gammascxx . . $ gammas.[2][256] = {
51 /* Gamma = 2.2 */
52 {
53 0, 5, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 15, 16, 17,
54 17, 18, 18, 19, 19, 20, 20, 20, 21, 21, 22, 22, 23, 23, 23,
55 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28,
56 29, 29, 29, 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32,
57 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, 35, 36, 36,
58 36, 36, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39,
59 39, 39, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 42, 42, 42,
60 42, 42, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45,
61 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47,
62 47, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 50,
63 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 52, 52,
64 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54,
65 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56,
66 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58,
67 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 60, 60,
68 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61, 62,
69 62, 62, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63,
70 },
71 /* Gamma = 1.8 */
72 {
73 0, 2, 4, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 12,
74 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 17, 18, 18, 19,
75 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24,
76 24, 24, 24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28,
77 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 32,
78 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35,
79 35, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 38, 38, 38, 38,
80 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41,
81 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 44, 44, 44, 44,
82 44, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47,
83 47, 47, 47, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49,
84 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 52, 52, 52,
85 52, 52, 52, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54,
86 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 57, 57,
87 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59,
88 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61,
89 61, 61, 62, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63,
90 }
91 };
92
93 struct magicard_printjobcxx . . $ magicard_printjob# {
94 struct dyesub_job_commoncxx . . $ dyesub_job_common# commoncxx . . $ magicard_printjob#common.;
95
96 uint8_tcxx . . $ uint8_t# *databufcxx . . $ magicard_printjob#databuf.;
97 int datalencxx . . $ magicard_printjob#datalen.;
98
99 int hdr_lencxx . . $ magicard_printjob#hdr_len.;
100 };
101
102 /* Private data structure */
103 struct magicard_ctxcxx . . $ magicard_ctx# {
104 struct dyesub_connectioncxx . . $ dyesub_connection# *conncxx . . $ magicard_ctx#conn.;
105 struct markercxx . . $ marker# markercxx . . $ magicard_ctx#marker.;
106 };
107
108 struct magicard_cmd_headercxx . . $ magicard_cmd_header# {
109 uint8_tcxx . . $ uint8_t# guardcxx . . $ magicard_cmd_header#guard.[9]; /* 0x05 */
110 uint8_tcxx . . $ uint8_t# guard2cxx . . $ magicard_cmd_header#guard2.[1]; /* 0x01 */
111 uint8_tcxx . . $ uint8_t# cmdcxx . . $ magicard_cmd_header#cmd.[4]; /* 'REQ,' */
112 uint8_tcxx . . $ uint8_t# subcmdcxx . . $ magicard_cmd_header#subcmd.[4]; /* '???,' */
113 uint8_tcxx . . $ uint8_t# argcxx . . $ magicard_cmd_header#arg.[4]; /* '???,' */
114 uint8_tcxx . . $ uint8_t# footercxx . . $ magicard_cmd_header#footer.[2]; /* 0x1c 0x03 */
115 };
116
117 struct magicard_cmd_simple_headercxx . . $ magicard_cmd_simple_header# {
118 uint8_tcxx . . $ uint8_t# guardcxx . . $ magicard_cmd_simple_header#guard.[9]; /* 0x05 */
119 uint8_tcxx . . $ uint8_t# guard2cxx . . $ magicard_cmd_simple_header#guard2.[1]; /* 0x01 */
120 uint8_tcxx . . $ uint8_t# cmdcxx . . $ magicard_cmd_simple_header#cmd.[]; /* '???' */
121 // uint8_t footer[2]; /* 0x1c 0x03 */
122 };
123
124 struct magicard_resp_headercxx . . $ magicard_resp_header# {
125 uint8_tcxx . . $ uint8_t# guardcxx . . $ magicard_resp_header#guard.[1]; /* 0x01 */
126 uint8_tcxx . . $ uint8_t# subcmd_argcxx . . $ magicard_resp_header#subcmd_arg.[7]; /* '???,???' */
127 uint8_tcxx . . $ uint8_t# datacxx . . $ magicard_resp_header#data.[]; /* freeform resp */
128 // uint8_t term[2]; /* 0x2c 0x03 terminates! */
129 };
130
131 struct magicard_requestscxx . . $ magicard_requests# {
132 const char *keycxx . . $ magicard_requests#key.;
133 const char *desccxx . . $ magicard_requests#desc.;
134 uint8_tcxx . . $ uint8_t# typecxx . . $ magicard_requests#type.;
135 };
136
137 enumcxx . . $ $anonymous_type_8496e6908037149e_0# {
138 TYPE_UNKNOWNcxx . . $ TYPE_UNKNOWN. = 0,
139 TYPE_STRINGcxx . . $ TYPE_STRING.,
140 TYPE_STRINGINTcxx . . $ TYPE_STRINGINT.,
141 TYPE_STRINGINT_HEXcxx . . $ TYPE_STRINGINT_HEX.,
142 TYPE_IPADDRcxx . . $ TYPE_IPADDR.,
143 TYPE_YESNOcxx . . $ TYPE_YESNO.,
144 TYPE_MODELcxx . . $ TYPE_MODEL.,
145 };
146
147 /* Data definitions */
148 static struct magicard_requestscxx . . $ magicard_requests# magicard_sta_requestscxx . . $ magicard_sta_requests.[] = {
149 { "MSR", "Printer Serial Number", TYPE_STRINGcxx . . $ TYPE_STRING. },
150 { "PSR", "Print Head Serial Number", TYPE_STRINGcxx . . $ TYPE_STRING. },
151 { "BSR", "PCB Serial Number", TYPE_STRINGcxx . . $ TYPE_STRING. },
152 { "VRS", "Firmware Version", TYPE_STRINGcxx . . $ TYPE_STRING. },
153 { "FDC", "Head Density", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. }, /* 25 per step */
154 { "FSP", "Image Start", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. }, /* 8 steps per pixel */
155 { "FEP", "Image End", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. }, /* 8 steps per pixel */
156 { "FSS", "Ramp Adjust", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
157 { "FPP", "Head Position", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. }, /* L-R alignment */
158 { "MDL", "Model", TYPE_MODELcxx . . $ TYPE_MODEL. }, /* 0 == Standard. Others? */
159 { "PID", "USB PID", TYPE_STRINGINT_HEXcxx . . $ TYPE_STRINGINT_HEX. }, /* ASCII integer, but needs to be shown as hex */
160 { "VID", "USB VID", TYPE_STRINGINT_HEXcxx . . $ TYPE_STRINGINT_HEX. }, /* ASCII integer, but needs to be shown as hex */
161 { "USN", "USB Serial Number", TYPE_STRINGcxx . . $ TYPE_STRING. },
162 { "UPN", "USB Manufacturer", TYPE_STRINGcxx . . $ TYPE_STRING. },
163 { "MAC", "Ethernet MAC Address", TYPE_STRINGcxx . . $ TYPE_STRING. },
164 { "DYN", "Dynamic Address", TYPE_YESNOcxx . . $ TYPE_YESNO. }, /* 1 == yes, 0 == no */
165 { "IPA", "IP Address", TYPE_IPADDRcxx . . $ TYPE_IPADDR. }, /* ASCII signed integer */
166 { "SNM", "IP Netmask", TYPE_IPADDRcxx . . $ TYPE_IPADDR. }, /* ASCII signed integer */
167 { "GWY", "IP Gateway", TYPE_IPADDRcxx . . $ TYPE_IPADDR. }, /* ASCII signed integer */
168
169 { "TCQ", "Total Cards Printed", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
170 { "TCP", "Prints on Head", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
171 { "TCN", "Cleaning Cycles", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
172 { "CCQ", "Cards Since Last Cleaning", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
173 { "TPQ", "Total Panels Printed", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
174 { "CCP", "Cards between Cleaning Prompts", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
175 { "CPQ", "Panels Since Last Cleaning", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. },
176 { "DFR", "Panels Remaining", TYPE_STRINGINTcxx . . $ TYPE_STRINGINT. }, // cook somehow?
177 { "CLP", "Cleaning Prompt", TYPE_STRINGcxx . . $ TYPE_STRING. },
178
179 // CRQ: OFF ?? Cleaning overdue?
180 // CHK: checksum of fw? (8 chars, hex?)
181 // TES: ??? signed int? IP addr?
182 // RAMP: ??? hangs.
183
184 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0 }
185 };
186
187 // Sensors: CAM1 CAM2 TACHO FLIP DYE BARCODE LID FRONT REAR BUTTON TEMP ON OFF
188 // Languages: ENG ITA POR FRA DEU ESP SCH
189
190 /* Helper functions */
191 static int magicard_build_cmdcxx . . $ magicard_build_cmd(51b1becab758ca63).(uint8_tcxx . . $ uint8_t# *buf,
192 const char *cmd, const char *subcmd, const char *arg)
193 {
194 struct magicard_cmd_headercxx . . $ magicard_cmd_header# *hdr = (struct magicard_cmd_headercxx . . $ magicard_cmd_header# *) buf;
195
196 memsetcxx . . $ memset(d1de1e4fb215f1c6).(hdr->guardcxx . . $ magicard_cmd_header#guard., 0x05, sizeof(hdr->guardcxx . . $ magicard_cmd_header#guard.));
197 hdr->guard2cxx . . $ magicard_cmd_header#guard2.[0] = 0x01;
198 memcpycxx . . $ memcpy(cc817cb175f282d).(hdr->cmdcxx . . $ magicard_cmd_header#cmd., cmd, 3);
199 hdr->cmdcxx . . $ magicard_cmd_header#cmd.[3] = ',';
200 memcpycxx . . $ memcpy(cc817cb175f282d).(hdr->subcmdcxx . . $ magicard_cmd_header#subcmd., subcmd, 3);
201 hdr->subcmdcxx . . $ magicard_cmd_header#subcmd.[3] = ',';
202 memcpycxx . . $ memcpy(cc817cb175f282d).(hdr->argcxx . . $ magicard_cmd_header#arg., arg, 3);
203 hdr->argcxx . . $ magicard_cmd_header#arg.[3] = ',';
204 hdr->footercxx . . $ magicard_cmd_header#footer.[0] = 0x1c;
205 hdr->footercxx . . $ magicard_cmd_header#footer.[1] = 0x03;
206
207 return sizeof(*hdr);
208 }
209
210 static int magicard_build_cmd_simplecxx . . $ magicard_build_cmd_simple(dfc12e525a3d5e75).(uint8_tcxx . . $ uint8_t# *buf,
211 const char *cmd)
212 {
213 struct magicard_cmd_simple_headercxx . . $ magicard_cmd_simple_header# *hdr = (struct magicard_cmd_simple_headercxx . . $ magicard_cmd_simple_header# *) buf;
214 int len = strlencxx . . $ strlen(751346f8406fd082).(cmd);
215
216 memsetcxx . . $ memset(d1de1e4fb215f1c6).(hdr->guardcxx . . $ magicard_cmd_simple_header#guard., 0x05, sizeof(hdr->guardcxx . . $ magicard_cmd_simple_header#guard.));
217 hdr->guard2cxx . . $ magicard_cmd_simple_header#guard2.[0] = 0x01;
218 strncpycxx . . $ strncpy(255158a415b673b0).((char*)hdr->cmdcxx . . $ magicard_cmd_simple_header#cmd., cmd, len);
219 hdr->cmdcxx . . $ magicard_cmd_simple_header#cmd.[len] = 0x1c;
220 hdr->cmdcxx . . $ magicard_cmd_simple_header#cmd.[len+1] = 0x03;
221
222 return (sizeof(*hdr) + len + 2);
223 }
224
225
226 static uint8_tcxx . . $ uint8_t# * magicard_parse_respcxx . . $ magicard_parse_resp(d4114bbb698e554f).(uint8_tcxx . . $ uint8_t# *buf, uint16_tcxx . . $ uint16_t# len, uint16_tcxx . . $ uint16_t# *resplen)
227 {
228 struct magicard_resp_headercxx . . $ magicard_resp_header# *hdr = (struct magicard_resp_headercxx . . $ magicard_resp_header# *) buf;
229
230 *resplen = len - sizeof(hdr->guardcxx . . $ magicard_resp_header#guard.) - sizeof(hdr->subcmd_argcxx . . $ magicard_resp_header#subcmd_arg.) - 2;
231
232 return hdr->datacxx . . $ magicard_resp_header#data.;
233 }
234
235 static int magicard_query_sensorscxx . . $ magicard_query_sensors(c62bfcf11d7a6193).(struct magicard_ctxcxx . . $ magicard_ctx# *ctx)
236 {
237 int ret = 0;
238 int i;
239 uint8_tcxx . . $ uint8_t# buf[256];
240 char buf2[24];
241
242 for (i = 1 ; ; i++) {
243 int num = 0;
244
245 snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf2, sizeof(buf2), "SNR%d", i);
246 ret = magicard_build_cmd_simplecxx . . $ magicard_build_cmd_simple(dfc12e525a3d5e75).(buf, buf2);
247
248 if ((ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
249 buf, ret)))
250 return ret;
251
252 memsetcxx . . $ memset(d1de1e4fb215f1c6).(buf, 0, sizeof(buf));
253
254 ret = read_datacxx . . $ read_data(b488de55810172b7).(ctx->conncxx . . $ magicard_ctx#conn.,
255 buf, sizeof(buf), &num);
256
257 if (ret < 0)
258 return ret;
259
260 if (!memcmpcxx . . $ memcmp(36f949851efa3055).(buf, "END", 3))
261 break;
262
263 buf[num] = 0;
264 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s\n", buf);
265 }
266 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
267 }
268
269 static int magicard_selftest_cardcxx . . $ magicard_selftest_card(c62bfcf11d7a6193).(struct magicard_ctxcxx . . $ magicard_ctx# *ctx)
270 {
271 int ret = 0;
272 uint8_tcxx . . $ uint8_t# buf[256];
273
274 ret = magicard_build_cmd_simplecxx . . $ magicard_build_cmd_simple(dfc12e525a3d5e75).(buf, "TST,");
275
276 ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
277 buf, ret);
278 return ret;
279 }
280
281 static int magicard_resetcxx . . $ magicard_reset(c62bfcf11d7a6193).(struct magicard_ctxcxx . . $ magicard_ctx# *ctx)
282 {
283 int ret = 0;
284 uint8_tcxx . . $ uint8_t# buf[256];
285
286 ret = magicard_build_cmd_simplecxx . . $ magicard_build_cmd_simple(dfc12e525a3d5e75).(buf, "RST,");
287
288 ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
289 buf, ret);
290 return ret;
291 }
292
293 static int magicard_ejectcxx . . $ magicard_eject(c62bfcf11d7a6193).(struct magicard_ctxcxx . . $ magicard_ctx# *ctx)
294 {
295 int ret = 0;
296 uint8_tcxx . . $ uint8_t# buf[256];
297
298 ret = magicard_build_cmd_simplecxx . . $ magicard_build_cmd_simple(dfc12e525a3d5e75).(buf, "EJT,");
299
300 ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
301 buf, ret);
302 return ret;
303 }
304
305 static int magicard_query_printercxx . . $ magicard_query_printer(c62bfcf11d7a6193).(struct magicard_ctxcxx . . $ magicard_ctx# *ctx)
306 {
307 int ret = 0;
308 int i;
309 uint8_tcxx . . $ uint8_t# buf[256];
310 char buf2[24];
311
312 for (i = 1 ; ; i++) {
313 int num = 0;
314
315 snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf2, sizeof(buf2), "QPR%d", i);
316 ret = magicard_build_cmd_simplecxx . . $ magicard_build_cmd_simple(dfc12e525a3d5e75).(buf, buf2);
317
318 if ((ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
319 buf, ret)))
320 return ret;
321
322 memsetcxx . . $ memset(d1de1e4fb215f1c6).(buf, 0, sizeof(buf));
323
324 ret = read_datacxx . . $ read_data(b488de55810172b7).(ctx->conncxx . . $ magicard_ctx#conn.,
325 buf, sizeof(buf), &num);
326
327 if (ret < 0)
328 return ret;
329
330 if (!memcmpcxx . . $ memcmp(36f949851efa3055).(buf, "END", 3))
331 break;
332
333 buf[num] = 0;
334 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s\n", buf);
335 }
336 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
337 }
338
339 static int magicard_query_statuscxx . . $ magicard_query_status(c62bfcf11d7a6193).(struct magicard_ctxcxx . . $ magicard_ctx# *ctx)
340 {
341 int ret = 0;
342 int i;
343 uint8_tcxx . . $ uint8_t# buf[256];
344
345 for (i = 0 ; ; i++) {
346 uint16_tcxx . . $ uint16_t# resplen = 0;
347 uint8_tcxx . . $ uint8_t# *resp;
348 int num = 0;
349
350 if (magicard_sta_requestscxx . . $ magicard_sta_requests.[i].keycxx . . $ magicard_requests#key. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
351 break;
352
353 ret = magicard_build_cmdcxx . . $ magicard_build_cmd(51b1becab758ca63).(buf, "REQ", "STA",
354 magicard_sta_requestscxx . . $ magicard_sta_requests.[i].keycxx . . $ magicard_requests#key.);
355
356 if ((ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
357 buf, ret)))
358 return ret;
359
360 memsetcxx . . $ memset(d1de1e4fb215f1c6).(buf, 0, sizeof(buf));
361
362 ret = read_datacxx . . $ read_data(b488de55810172b7).(ctx->conncxx . . $ magicard_ctx#conn.,
363 buf, sizeof(buf), &num);
364
365 if (ret < 0)
366 return ret;
367
368 resp = magicard_parse_respcxx . . $ magicard_parse_resp(d4114bbb698e554f).(buf, num, &resplen);
369 resp[resplen] = 0;
370 switch(magicard_sta_requestscxx . . $ magicard_sta_requests.[i].typecxx . . $ magicard_requests#type.) {
371 case TYPE_IPADDRcxx . . $ TYPE_IPADDR.: {
372 int32_tcxx . . $ int32_t# ipaddr;
373 uint8_tcxx . . $ uint8_t# *addr = (uint8_tcxx . . $ uint8_t# *) &ipaddr;
374 ipaddr = atoicxx . . $ atoi(5c4306d8553b3696).((char*)resp);
375 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s:\t%d.%d.%d.%d\n",
376 magicard_sta_requests[i].desc,
377 addr[3], addr[2], addr[1], addr[0]);
378 break;
379 }
380 case TYPE_YESNOcxx . . $ TYPE_YESNO.: {
381 int val = atoicxx . . $ atoi(5c4306d8553b3696).((char*)resp);
382 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s:\t%s\n",
383 magicard_sta_requests[i].desc,
384 val? "Yes" : "No");
385 break;
386 }
387 case TYPE_MODELcxx . . $ TYPE_MODEL.: {
388 int val = atoicxx . . $ atoi(5c4306d8553b3696).((char*)resp);
389 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s:\t%s\n",
390 magicard_sta_requests[i].desc,
391 val == 0? "Standard" : "Unknown");
392 break;
393 }
394 case TYPE_STRINGINT_HEXcxx . . $ TYPE_STRINGINT_HEX.: {
395 int val = atoicxx . . $ atoi(5c4306d8553b3696).((char*)resp);
396 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s:\t%X\n",
397 magicard_sta_requests[i].desc,
398 val);
399 break;
400 }
401 case TYPE_STRINGINTcxx . . $ TYPE_STRINGINT.:
402 // treat differently?
403 case TYPE_STRINGcxx . . $ TYPE_STRING.:
404 case TYPE_UNKNOWNcxx . . $ TYPE_UNKNOWN.:
405 default:
406 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("%s:\t%s\n",
407 magicard_sta_requests[i].desc,
408 resp);
409 }
410 }
411
412 return ret;
413 }
414
415 /* Main driver */
416 static void* magicard_initcxx . . $ magicard_init(50c7df7de5344ebb).(void)
417 {
418 struct magicard_ctxcxx . . $ magicard_ctx# *ctx = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct magicard_ctxcxx . . $ magicard_ctx#));
419 if (!ctx) {
420 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Memory Allocation Failure!\n");
421 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
422 }
423 memsetcxx . . $ memset(d1de1e4fb215f1c6).(ctx, 0, sizeof(struct magicard_ctxcxx . . $ magicard_ctx#));
424 return ctx;
425 }
426
427 static int magicard_attachcxx . . $ magicard_attach(65a6cf861cd15f84).(void *vctx, struct dyesub_connectioncxx . . $ dyesub_connection# *conn, uint8_tcxx . . $ uint8_t# jobid)
428 {
429 struct magicard_ctxcxx . . $ magicard_ctx# *ctx = vctx;
430
431 UNUSEDcxx . . $ `src/cups/backend_common.h:84:9`!(jobid);
432
433 ctx->conncxx . . $ magicard_ctx#conn. = conn;
434
435 ctx->markercxx . . $ magicard_ctx#marker..colorcxx . . $ marker#color. = "#00FFFF#FF00FF#FFFF00"; // XXX YMCK too!
436 ctx->markercxx . . $ magicard_ctx#marker..namecxx . . $ marker#name. = "Unknown"; // LC1/LC3/LC6/LC8
437 ctx->markercxx . . $ magicard_ctx#marker..numtypecxx . . $ marker#numtype. = -1;
438 ctx->markercxx . . $ magicard_ctx#marker..levelmaxcxx . . $ marker#levelmax. = CUPS_MARKER_UNAVAILABLEcxx . . $ `src/cups/backend_common.h:376:9`!;
439 ctx->markercxx . . $ magicard_ctx#marker..levelnowcxx . . $ marker#levelnow. = CUPS_MARKER_UNKNOWNcxx . . $ `src/cups/backend_common.h:377:9`!;
440
441 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
442 }
443
444 static void magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(const void *vjob)
445 {
446 const struct magicard_printjobcxx . . $ magicard_printjob# *job = vjob;
447
448 if (job->databufcxx . . $ magicard_printjob#databuf.)
449 freecxx . . $ free(5d22bdacc48458e8).(job->databufcxx . . $ magicard_printjob#databuf.);
450
451 freecxx . . $ free(5d22bdacc48458e8).((void*)job);
452 }
453
454 static void downscale_and_extractcxx . . $ downscale_and_extract(1242193c69738f97).(int gamma, uint32_tcxx . . $ uint32_t# pixels,
455 uint8_tcxx . . $ uint8_t# *y_i, uint8_tcxx . . $ uint8_t# *m_i, uint8_tcxx . . $ uint8_t# *c_i,
456 uint8_tcxx . . $ uint8_t# *y_o, uint8_tcxx . . $ uint8_t# *m_o, uint8_tcxx . . $ uint8_t# *c_o, uint8_tcxx . . $ uint8_t# *k_o)
457 {
458 uint32_tcxx . . $ uint32_t# i;
459
460 for (i = 0 ; i < pixels; i++)
461 {
462 uint8_tcxx . . $ uint8_t# y, m, c;
463 uint8_tcxx . . $ uint8_t# k = 0;
464 uint32_tcxx . . $ uint32_t# j;
465 uint32_tcxx . . $ uint32_t# row;
466 uint32_tcxx . . $ uint32_t# col;
467 uint32_tcxx . . $ uint32_t# b_offset;
468 uint8_tcxx . . $ uint8_t# b_shift;
469
470 /* Downscale color planes from 8bpp -> 6bpp; */
471 if (gamma) {
472 if (gamma > 2)
473 gamma = 2;
474 gamma--;
475 y = gammascxx . . $ gammas.[gamma][*y_i++];
476 m = gammascxx . . $ gammas.[gamma][*m_i++];
477 c = gammascxx . . $ gammas.[gamma][*c_i++];
478 } else {
479 y = *y_i++ >> 2;
480 m = *m_i++ >> 2;
481 c = *c_i++ >> 2;
482 }
483
484 /* Extract "true black" from ymc data, if enabled */
485 if (k_o && y == 0x3f && m == 0x3f && c == 0x3f) {
486 k = 1;
487 y = m = c = 0;
488 }
489
490 /* Compute row number and offsets */
491 row = i / 672;
492 col = i - (row * 672);
493 b_offset = col / 8;
494 b_shift = 7 - (col - (b_offset * 8));
495
496 /* Now, for each row, break it down into sub-chunks */
497 for (j = 0 ; j < 6 ; j++) {
498 if (b_shift == 7) {
499 y_o[row * 504 + j * 84 + b_offset] = 0;
500 m_o[row * 504 + j * 84 + b_offset] = 0;
501 c_o[row * 504 + j * 84 + b_offset] = 0;
502 }
503 if (y & (1 << j))
504 y_o[row * 504 + j * 84 + b_offset] |= (1 << b_shift);
505 if (m & (1 << j))
506 m_o[row * 504 + j * 84 + b_offset] |= (1 << b_shift);
507 if (c & (1 << j))
508 c_o[row * 504 + j * 84 + b_offset] |= (1 << b_shift);
509 }
510
511 /* And resin black, if enabled */
512 if (k_o) {
513 if (b_shift == 7) {
514 k_o[row * 84 + b_offset] = 0;
515 }
516 if (k)
517 k_o[row * 84 + b_offset] |= (1 << b_shift);
518 }
519 }
520 }
521
522 #define MAX_HEADERS_LENcxx . . $ `src/cups/backend_magicard.c:522:9`! 2048
523 #define MAX_PRINTJOB_LENcxx . . $ `src/cups/backend_magicard.c:523:9`! (1016*672*4) + MAX_HEADERS_LENcxx . . $ `src/cups/backend_magicard.c:522:9`! /* 1016*672 * 4color */
524 #define INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`! 1024
525 static int magicard_read_parsecxx . . $ magicard_read_parse(296a7ce9eef68a26).(void *vctx, const void **vjob, int data_fd, int copies) {
526 struct magicard_ctxcxx . . $ magicard_ctx# *ctx = vctx;
527 uint8_tcxx . . $ uint8_t# initial_buf[INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`! + 1];
528 uint32_tcxx . . $ uint32_t# buf_offset = 0;
529 int i;
530
531 uint8_tcxx . . $ uint8_t# *in_y, *in_m, *in_c;
532 uint8_tcxx . . $ uint8_t# *out_y, *out_m, *out_c, *out_k;
533 uint32_tcxx . . $ uint32_t# len_y = 0, len_m = 0, len_c = 0, len_k = 0;
534 int gamma = 0;
535
536 uint8_tcxx . . $ uint8_t# x_gp_8bpp;
537 uint8_tcxx . . $ uint8_t# x_gp_rk;
538 uint8_tcxx . . $ uint8_t# k_only;
539
540 struct magicard_printjobcxx . . $ magicard_printjob# *job = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
541
542 if (!ctx)
543 return CUPS_BACKEND_FAILEDcxx . . $ `src/cups/backend_common.h:368:9`!;
544
545 job = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*job));
546 if (!job) {
547 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Memory allocation failure!\n");
548 return CUPS_BACKEND_RETRY_CURRENTcxx . . $ `src/cups/backend_common.h:374:9`!;
549 }
550 memsetcxx . . $ memset(d1de1e4fb215f1c6).(job, 0, sizeof(*job));
551 job->commoncxx . . $ magicard_printjob#common..jobsizecxx . . $ dyesub_job_common#jobsize. = sizeof(*job);
552 job->commoncxx . . $ magicard_printjob#common..copiescxx . . $ dyesub_job_common#copies. = copies;
553
554 /* Read in the first chunk */
555 i = readcxx . . $ read(7e34d0a36f355389).(data_fd, initial_buf, INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`!);
556 if (i < 0) {
557 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
558 return i;
559 } else if (i == 0) {
560 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
561 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!; /* Ie no data, we're done */
562 } else if (i < INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`!) {
563 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
564 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
565 }
566
567 /* Basic Sanity Check */
568 if (initial_buf[0] != 0x05 ||
569 initial_buf[64] != 0x01 ||
570 initial_buf[65] != 0x2c) {
571 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Unrecognized header data format @%d!\n", job->datalen);
572 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
573 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
574 }
575
576 initial_buf[INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`!] = 0;
577
578 /* We can start allocating! */
579 if (job->databufcxx . . $ magicard_printjob#databuf.) {
580 freecxx . . $ free(5d22bdacc48458e8).(job->databufcxx . . $ magicard_printjob#databuf.);
581 job->databufcxx . . $ magicard_printjob#databuf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
582 }
583 job->datalencxx . . $ magicard_printjob#datalen. = 0;
584 job->databufcxx . . $ magicard_printjob#databuf. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(MAX_PRINTJOB_LENcxx . . $ `src/cups/backend_magicard.c:523:9`!);
585 if (!job->databufcxx . . $ magicard_printjob#databuf.) {
586 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Memory allocation failure!\n");
587 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
588 return CUPS_BACKEND_RETRY_CURRENTcxx . . $ `src/cups/backend_common.h:374:9`!;
589 }
590
591 /* Copy over initial header */
592 memcpycxx . . $ memcpy(cc817cb175f282d).(job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., initial_buf + buf_offset, 65);
593 job->datalencxx . . $ magicard_printjob#datalen. += 65;
594 buf_offset += 65;
595
596 /* Start parsing headers */
597 x_gp_8bpp = x_gp_rk = k_only = job->hdr_lencxx . . $ magicard_printjob#hdr_len. = 0;
598
599 char *ptr;
600 ptr = strtokcxx . . $ strtok(b7b3a83273496486).((char*)initial_buf + ++buf_offset, ",\x1c");
601 while (ptr
602 && ((ptr - (char*)initial_buf) < INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`!)
603 && ((ptr - (char*)initial_buf) + strnlencxx . . $ strnlen(ac5a385650b4bde5).(ptr, INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`!) < INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`!)
604 && *ptr != 0x1c) {
605 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).("X-GP-8", ptr)) {
606 x_gp_8bpp = 1;
607 } else if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).("TDT", ptr, 3)) {
608 /* Strip out the timestamp, replace it with one from the backend */
609 } else if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).("IMF", ptr,3)) {
610 /* Strip out the image format, replace it with backend */
611 // } else if (!strncmp("ESS", ptr, 3)) {
612 // /* Strip out copies */
613 // XXX implement me properly.
614 copies = 1;
615 } else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).("X-GP-RK", ptr)) {
616 x_gp_rk = 1;
617 } else if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).("ICC", ptr,3)) {
618 /* Gamma curve is not handled by printer,
619 strip it out and use it! */
620 gamma = atoicxx . . $ atoi(5c4306d8553b3696).(ptr + 3);
621 } else if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).("SZ", ptr, 2)) {
622 if (ptr[2] == 'B') {
623 len_y = atoicxx . . $ atoi(5c4306d8553b3696).(ptr + 3);
624 } else if (ptr[2] == 'G') {
625 len_m = atoicxx . . $ atoi(5c4306d8553b3696).(ptr + 3);
626 } else if (ptr[2] == 'R') {
627 len_c = atoicxx . . $ atoi(5c4306d8553b3696).(ptr + 3);
628 } else if (ptr[2] == 'K') {
629 len_k = atoicxx . . $ atoi(5c4306d8553b3696).(ptr + 3);
630 }
631 } else {
632 /* Safety valve */
633 if (strlencxx . . $ strlen(751346f8406fd082).(ptr) + job->datalencxx . . $ magicard_printjob#datalen. > MAX_HEADERS_LENcxx . . $ `src/cups/backend_magicard.c:522:9`!) {
634 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("headers too long, bogus job!\n");
635 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
636 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
637 }
638
639 /* Everything else goes in */
640 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",%s", ptr);
641 }
642
643 /* Keep going */
644 buf_offset += strlencxx . . $ strlen(751346f8406fd082).(ptr) + 1;
645 /* Peek ahead to see if this is it */
646 if (initial_buf[buf_offset + 1] == 0x1c)
647 break;
648 /* Otherwise continue to the next token */
649 ptr = strtokcxx . . $ strtok(b7b3a83273496486).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, ",\x1c");
650 }
651
652 /* Sanity checks */
653 if (!len_y || !len_m || !len_c) {
654 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Plane lengths missing? %u/%u/%u!\n", len_y, len_m, len_c);
655 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
656 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
657 }
658 if (len_y != len_m || len_y != len_c) {
659 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Inconsistent data plane lengths! %u/%u/%u!\n", len_y, len_m, len_c);
660 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
661 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
662 }
663 if (x_gp_rk && len_k) {
664 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Data stream already has a K layer!\n");
665 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
666 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
667 }
668
669 /* Generate a timestamp */
670 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",TDT%08X", (uint32_tcxx . . $ uint32_t#) timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!));
671
672 /* Generate image format tag */
673 if (k_only == 1) {
674 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",IMFK");
675 } else if (x_gp_rk || len_k) {
676 /* We're adding K, so make this BGRK */
677 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",IMFBGRK");
678 } else {
679 /* Just BGR */
680 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",IMFBGR");
681 }
682
683 /* Insert SZB/G/R/K length descriptors */
684 if (x_gp_8bpp) {
685 if (k_only == 1) {
686 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZK%u", len_c / 8);
687 } else {
688 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZB%u", len_y * 6 / 8);
689 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZG%u", len_m * 6 / 8);
690 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZR%u", len_c * 6 / 8);
691 /* Add in a SZK length indication if requested */
692 if (x_gp_rk == 1) {
693 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZK%u", len_c / 8);
694 }
695 }
696 } else {
697 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZB%u", len_y);
698 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZG%u", len_m);
699 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZR%u", len_c);
700 /* Add in a SZK length indication if requested */
701 if (len_k) {
702 job->datalencxx . . $ magicard_printjob#datalen. += sprintfcxx . . $ sprintf(26c8642d26409d6d).((char*)job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., ",SZK%u", len_k);
703 }
704 }
705
706 /* Terminate command stream */
707 job->databufcxx . . $ magicard_printjob#databuf.[job->datalencxx . . $ magicard_printjob#datalen.++] = 0x1c;
708
709 /* Let's figure out how long the image data stream is supposed to be. */
710 uint32_tcxx . . $ uint32_t# remain;
711 if (k_only) {
712 remain = len_k + 3;
713 } else {
714 remain = len_y + len_m + len_c + 3 * 3;
715 if (len_k)
716 remain += len_k + 3;
717 }
718 /* Offset the stuff we already read in. */
719 remain -= INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`! - buf_offset;
720 remain++; /* Add in a byte for the end of job marker. This is our final value. */
721
722 /* This is how much of the initial buffer is the header length. */
723 job->hdr_lencxx . . $ magicard_printjob#hdr_len. = job->datalencxx . . $ magicard_printjob#datalen.;
724
725 if (job->datalencxx . . $ magicard_printjob#datalen. + remain > MAX_PRINTJOB_LENcxx . . $ `src/cups/backend_magicard.c:523:9`!) {
726 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Buffer overflow when parsing printjob! (%d+%d)\n",
727 job->datalen, remain);
728 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
729 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
730 }
731
732 if (x_gp_8bpp) {
733 uint32_tcxx . . $ uint32_t# srcbuf_offset = INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`! - buf_offset;
734 uint8_tcxx . . $ uint8_t# *srcbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(MAX_PRINTJOB_LENcxx . . $ `src/cups/backend_magicard.c:523:9`!);
735 if (!srcbuf) {
736 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
737 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Memory allocation failure!\n");
738 return CUPS_BACKEND_RETRY_CURRENTcxx . . $ `src/cups/backend_common.h:374:9`!;
739 }
740
741 memcpycxx . . $ memcpy(cc817cb175f282d).(srcbuf, initial_buf + buf_offset, srcbuf_offset);
742
743 /* Finish loading the data */
744 while (remain > 0) {
745 i = readcxx . . $ read(7e34d0a36f355389).(data_fd, srcbuf + srcbuf_offset, remain);
746 if (i < 0) {
747 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Data Read Error: %d (%u) @%u)\n", i, remain, srcbuf_offset);
748 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
749 freecxx . . $ free(5d22bdacc48458e8).(srcbuf);
750 return i;
751 }
752 if (i == 0) {
753 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Short read! (%d/%u)\n", i, remain);
754 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
755 freecxx . . $ free(5d22bdacc48458e8).(srcbuf);
756 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
757 }
758 srcbuf_offset += i;
759 remain -= i;
760 }
761
762 // XXX handle conversion of K-only jobs. if needed.
763
764 /* set up source pointers */
765 in_y = srcbuf;
766 in_m = in_y + len_y + 3;
767 in_c = in_m + len_m + 3;
768
769 /* Set up destination pointers */
770 out_y = job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen.;
771 out_m = out_y + (len_y * 6 / 8) + 3;
772 out_c = out_m + (len_m * 6 / 8) + 3;
773 out_k = out_c + (len_c * 6 / 8) + 3;
774
775 /* Termination of each plane */
776 memcpycxx . . $ memcpy(cc817cb175f282d).(out_m - 3, in_y + len_y, 3);
777 memcpycxx . . $ memcpy(cc817cb175f282d).(out_c - 3, in_m + len_m, 3);
778 memcpycxx . . $ memcpy(cc817cb175f282d).(out_k - 3, in_c + len_c, 3);
779
780 if (!x_gp_rk)
781 out_k = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
782
783 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("Converting image data to printer's native format %s\n", x_gp_rk ? "and extracting K channel" : "");
784
785 downscale_and_extractcxx . . $ downscale_and_extract(1242193c69738f97).(gamma, len_y, in_y, in_m, in_c,
786 out_y, out_m, out_c, out_k);
787
788 /* Pad out the length appropriately. */
789 job->datalencxx . . $ magicard_printjob#datalen. += ((len_c * 6 / 8) + 3) * 3;
790
791 /* If there's a K plane, compute length.. */
792 if (out_k) {
793 job->datalencxx . . $ magicard_printjob#datalen. += (len_c / 8);
794 job->databufcxx . . $ magicard_printjob#databuf.[job->datalencxx . . $ magicard_printjob#datalen.++] = 0x1c;
795 job->databufcxx . . $ magicard_printjob#databuf.[job->datalencxx . . $ magicard_printjob#datalen.++] = 0x4b;
796 job->databufcxx . . $ magicard_printjob#databuf.[job->datalencxx . . $ magicard_printjob#datalen.++] = 0x3a;
797 }
798
799 /* Terminate the entire stream */
800 job->databufcxx . . $ magicard_printjob#databuf.[job->datalencxx . . $ magicard_printjob#datalen.++] = 0x03;
801
802 freecxx . . $ free(5d22bdacc48458e8).(srcbuf);
803 } else {
804 uint32_tcxx . . $ uint32_t# srcbuf_offset = INITIAL_BUF_LENcxx . . $ `src/cups/backend_magicard.c:524:9`! - buf_offset;
805 memcpycxx . . $ memcpy(cc817cb175f282d).(job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., initial_buf + buf_offset, srcbuf_offset);
806 job->datalencxx . . $ magicard_printjob#datalen. += srcbuf_offset;
807
808 /* Finish loading the data */
809 while (remain > 0) {
810 i = readcxx . . $ read(7e34d0a36f355389).(data_fd, job->databufcxx . . $ magicard_printjob#databuf. + job->datalencxx . . $ magicard_printjob#datalen., remain);
811 if (i < 0) {
812 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Data Read Error: %d (%u) @%d)\n", i, remain, job->datalen);
813 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
814 return i;
815 }
816 if (i == 0) {
817 magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).(job);
818 ERRORcxx . . $ `src/cups/backend_common.h:63:9`!("Short read! (%d/%u)\n", i, remain);
819 return CUPS_BACKEND_CANCELcxx . . $ `src/cups/backend_common.h:372:9`!;
820 }
821 job->datalencxx . . $ magicard_printjob#datalen. += i;
822 remain -= i;
823 }
824 }
825
826 *vjob = job;
827
828 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
829 }
830
831 static int magicard_main_loopcxx . . $ magicard_main_loop(91e54fd90adbb21).(void *vctx, const void *vjob, int wait_for_return) {
832 struct magicard_ctxcxx . . $ magicard_ctx# *ctx = vctx;
833 int ret;
834 int copies;
835 (void)wait_for_return;
836
837 const struct magicard_printjobcxx . . $ magicard_printjob# *job = vjob;
838
839 // XXX printer handles copy generation..
840 // but it's a numeric parameter. Bleh.
841 if (!ctx)
842 return CUPS_BACKEND_FAILEDcxx . . $ `src/cups/backend_common.h:368:9`!;
843 if (!job)
844 return CUPS_BACKEND_FAILEDcxx . . $ `src/cups/backend_common.h:368:9`!;
845
846 copies = job->commoncxx . . $ magicard_printjob#common..copiescxx . . $ dyesub_job_common#copies.;
847 top:
848 if ((ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
849 job->databufcxx . . $ magicard_printjob#databuf., job->hdr_lencxx . . $ magicard_printjob#hdr_len.)))
850 return CUPS_BACKEND_FAILEDcxx . . $ `src/cups/backend_common.h:368:9`!;
851
852 if ((ret = send_datacxx . . $ send_data(b2b51896d93e30f1).(ctx->conncxx . . $ magicard_ctx#conn.,
853 job->databufcxx . . $ magicard_printjob#databuf. + job->hdr_lencxx . . $ magicard_printjob#hdr_len., job->datalencxx . . $ magicard_printjob#datalen. - job->hdr_lencxx . . $ magicard_printjob#hdr_len.)))
854 return CUPS_BACKEND_FAILEDcxx . . $ `src/cups/backend_common.h:368:9`!;
855
856 /* Clean up */
857 if (terminatecxx . . $ terminate.)
858 copies = 1;
859
860 INFOcxx . . $ `src/cups/backend_common.h:61:9`!("Print complete (%d copies remaining)\n", copies - 1);
861
862 if (copies && --copies) {
863 goto top;
864 }
865
866 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
867 }
868
869 static void magicard_cmdlinecxx . . $ magicard_cmdline(49f6e7a06ebc5aa8).(void)
870 {
871 DEBUGcxx . . $ `src/cups/backend_common.h:59:9`!("\t\t[ -s ] # Query status\n");
872 DEBUGcxx . . $ `src/cups/backend_common.h:59:9`!("\t\t[ -q ] # Query information\n");
873 DEBUGcxx . . $ `src/cups/backend_common.h:59:9`!("\t\t[ -I ] # Query printer sensors\n");
874 DEBUGcxx . . $ `src/cups/backend_common.h:59:9`!("\t\t[ -E ] # Eject card\n");
875 DEBUGcxx . . $ `src/cups/backend_common.h:59:9`!("\t\t[ -T ] # Print self-test card\n");
876 DEBUGcxx . . $ `src/cups/backend_common.h:59:9`!("\t\t[ -R ] # Reset printer\n");
877 }
878
879 static int magicard_cmdline_argcxx . . $ magicard_cmdline_arg(bd8af97f5fa850e1).(void *vctx, int argc, char **argv)
880 {
881 struct magicard_ctxcxx . . $ magicard_ctx# *ctx = vctx;
882 int i, j = 0;
883
884 if (!ctx)
885 return -1;
886
887 while ((i = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, GETOPT_LIST_GLOBALcxx . . $ `src/cups/backend_common.h:381:9`! "sqEIRT")) >= 0) {
888 switch(i) {
889 GETOPT_PROCESS_GLOBALcxx . . $ `src/cups/backend_common.h:382:9`!
890 case 's':
891 j = magicard_query_statuscxx . . $ magicard_query_status(c62bfcf11d7a6193).(ctx);
892 break;
893 case 'q':
894 j = magicard_query_printercxx . . $ magicard_query_printer(c62bfcf11d7a6193).(ctx);
895 break;
896 case 'E':
897 j = magicard_ejectcxx . . $ magicard_eject(c62bfcf11d7a6193).(ctx);
898 break;
899 case 'I':
900 j = magicard_query_sensorscxx . . $ magicard_query_sensors(c62bfcf11d7a6193).(ctx);
901 break;
902 case 'R':
903 j = magicard_resetcxx . . $ magicard_reset(c62bfcf11d7a6193).(ctx);
904 break;
905 case 'T':
906 j = magicard_selftest_cardcxx . . $ magicard_selftest_card(c62bfcf11d7a6193).(ctx);
907 break;
908 }
909
910 if (j) return j;
911 }
912
913 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
914 }
915
916 static int magicard_query_markerscxx . . $ magicard_query_markers(5f0c51117cc67eb5).(void *vctx, struct markercxx . . $ marker# **markers, int *count)
917 {
918 struct magicard_ctxcxx . . $ magicard_ctx# *ctx = vctx;
919
920 *markers = &ctx->markercxx . . $ magicard_ctx#marker.;
921 *count = 1;
922
923 return CUPS_BACKEND_OKcxx . . $ `src/cups/backend_common.h:367:9`!;
924 }
925
926 static const char *magicard_prefixescxx . . $ magicard_prefixes.[] = {
927 "magicard", // Family name
928 // backwards compatibility
929 "tango2e", "enduro", "enduroplus",
930 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!
931 };
932
933 static const struct device_idcxx . . $ device_id# magicard_devicescxx . . $ magicard_devices.[] = {
934 { 0x0c1f, 0x1800, P_MAGICARDcxx . . $ P_MAGICARD., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "magicard-tango2e"},
935 // { 0x0c1f, 0x1800, P_MAGICARD, NULL, "magicard-rio2e"},
936 { 0x0c1f, 0x4800, P_MAGICARDcxx . . $ P_MAGICARD., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "magicard-enduro"}, // ??
937 { 0x0c1f, 0x880a, P_MAGICARDcxx . . $ P_MAGICARD., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "magicard-enduroplus"}, // ??
938 { 0x0c1f, 0xFFFF, P_MAGICARDcxx . . $ P_MAGICARD., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "magicard"},
939 { 0, 0, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!}
940 };
941
942 const struct dyesub_backendcxx . . $ dyesub_backend# magicard_backendcxx . . $ magicard_backend. = {
943 .name = "Magicard family",
944 .version = "0.21",
945 .uri_prefixes = magicard_prefixescxx . . $ magicard_prefixes.,
946 .devices = magicard_devicescxx . . $ magicard_devices.,
947 .cmdline_arg = magicard_cmdline_argcxx . . $ magicard_cmdline_arg(bd8af97f5fa850e1).,
948 .cmdline_usage = magicard_cmdlinecxx . . $ magicard_cmdline(49f6e7a06ebc5aa8).,
949 .init = magicard_initcxx . . $ magicard_init(50c7df7de5344ebb).,
950 .attach = magicard_attachcxx . . $ magicard_attach(65a6cf861cd15f84).,
951 .cleanup_job = magicard_cleanup_jobcxx . . $ magicard_cleanup_job(e4289f82fef2c2f9).,
952 .read_parse = magicard_read_parsecxx . . $ magicard_read_parse(296a7ce9eef68a26).,
953 .main_loop = magicard_main_loopcxx . . $ magicard_main_loop(91e54fd90adbb21).,
954 .query_markers = magicard_query_markerscxx . . $ magicard_query_markers(5f0c51117cc67eb5).,
955 };
956
957 /* Magicard family Spool file format (Tango2e/Rio2e/AvalonE family)
958
959 This one was rather fun to figure out.
960
961 * Job starts with a sequence of 64 '0x05'
962 * Command sequence starts with 0x01
963 * Commands are textual and comma-separated.
964 * Most are passed through ignored, except for:
965 * SZB, SZG, SZR, SZK -- indicate length of respective data plane
966 * IMF -- Image format (BGR/BGRK/K)
967 * X-GP-8 -- Tells backend to convert from Gutenprint's 8bpp data
968 * X-GP-RK -- Tells backend to extract K channel from color data
969 * Command sequence ends with 0x1c
970 * Image plane data follows, in the order of the SZ# entries
971 * Plane lengths are specified by the SZ# entry.
972 * Color planes are actually Y/M/C rather than B/G/R!
973 * Each plane terminates with 0x1c __ 0x3a, where __ is 0x42, 0x47, 0x52,
974 and 0x4b for B/G/R/K respectively. Terminator is _not_ part of length.
975 * Image data is 6bpp for B/G/R and 1bpp for K, 672*1016 pixels
976 * Organized in a series of 84-byte rows.
977 * Byte data is LSB first.
978 * Each row is a single stripe of a single bit of a pixel, so
979 color data is b0b0b0b0.. b1b1b1b1.. .. b5b5b5b5.
980 * Job ends with 0x03
981
982 ** ** ** ** ** **
983
984 Firmware updates:
985
986 0x05 (x9) 0x01 REQ,FRM###### 0x1c
987
988 Where ###### is the length of the firmware image.
989
990 Then send over 64 bytes at a time until it's done.
991
992 Then send 0x03 to mark end of job.
993
994 Follow it with:
995
996 0x01 STA,CHK########, 0x03 (8-digit checksum?)
997
998 0x05 (x9) 0x01 REQ,UPG, 0x1c 0x03
999
1000 ** ** ** ** ** **
1001
1002 Known commands seen in print jobs:
1003
1004 BAC%s Backside format (CKO, KO, C, CO, K) -- Only used with Duplex.
1005 CKI%s Custom Holokote (ON or OFF)
1006 CPW%s Color power level (0-100, default 50)
1007 DPX%s Duplex (ON or OFF)
1008 EOI%d Card alignment end (0-100, default 50)
1009 ESS%d Number of copies (1-?)
1010 HGT%d Image Height (always seems to be 1016)
1011 HKM%06X Holokote hole. bitwise number, each bit corresponds to an area.
1012 HKT%d Holokote type (1 is "ultra secure, 2 is "interlocking rings", etc)
1013 HPH%s Holopatch (ON or OFF)
1014 IMF%s Image Data Format (BGR, BGRK, K)
1015 KPW%s Black power level (0-100, default 50)
1016 LAN%s Printer display lanaguage (ENG, ITA, POR, FRA, DEU, ESP, SCH)
1017 LC%d Force media type (LC1, LC3, LC6, LC8 for YMCKO/MONO/KO/YMCKOK)
1018 NCT%d,%d,%d,%d Overcoat hole
1019 OPW%s Overcoat power level (0-100, default 50)
1020 OVR%s Overcoat (ON or OFF)
1021 PAG%d Page number (always 1, except 2 if printing duplex backside)
1022 PAT%d Holopatch area (0-24)
1023 REJ%s Reject faulty cards (ON or OFF)
1024 SOI%d Card alignment start (0-100, default 50)
1025 SLW%s Colorsure (ON or OFF)
1026 SZB%d Blue data length
1027 SZG%d Green data length
1028 SZK%d Black data length
1029 SZR%d Red data length
1030 TDT%08X Driver-supplied timestamp of print job.
1031 USF%s Holokote (ON or OFF)
1032 VER%s Inform the printer of the driver version (seems to be ignored)
1033 WID%d Image Width (always seems to be 642)
1034
1035 Mag-stripe encoding:
1036
1037 MAG%d Magstripe position (1, 2, or 3)
1038 BPI%d Bits per Inch (75 or 210)
1039 MPC%d Character encoding (5 or 7)
1040 COE%s 'H'igh or 'L'ow coercivity
1041
1042 Unknown commands seen in print jobs:
1043
1044 DDD%s ? (only seen '50') -- Could it be K alignment?
1045 KEE ?
1046 NNN%s ? (Seen 'OFF')
1047 NOC%d ? (Seen '1') (Seems to start a job)
1048 PCT%d,%d,%d,%d ? Print area, seems fixed @ 0,0, 1025, 641)
1049 RT2 ?
1050 TRO%d ? (Seen '0', appears with Holokote)
1051 XCO%d ? X start offset (always seems to be 0)
1052 YCO%d ? Y start offset (always seems to be 0)
1053
1054 Unknown commands: (Seen in firmware guts)
1055
1056 AAA
1057 AMS
1058 BBB%d Numeric parameter
1059 CLR
1060 FBF
1061 FTC
1062 HFD%s String parameter
1063 IPM
1064 KKK
1065 LBL
1066 LLL
1067 LRC
1068 MGV%s "ON" or "OFF" but no idea
1069 MMM
1070 PAR
1071 RDM
1072 SNR
1073 SSP
1074
1075 Unknown commands unique to Tango +L (ie w/ Laminator support)
1076
1077 FRN
1078 LAM
1079 LAM_DLY
1080 LAM_SPD
1081 LAM_LEN
1082 LAM_END
1083 LAM_STA
1084 LAM_DEG
1085 LAM_FLM
1086 LAM_KBD
1087 LAM_MOD
1088
1089 Commands consumed by backend:
1090
1091 ICC%d Gamma curve (0, 1, 2) -- off, 2.2, or 1.8 respectively.
1092 X-GP-8 Raw data is 8bpp. needs to be converted.
1093 X-GP-RK Extract K channel from color data.
1094
1095 Open questions:
1096
1097 * How to query/read magstripe
1098 * How to set IP address (etc)
1099 * How to set other parameters
1100
1101 "Simple Commands" (REQ,....,)
1102
1103 RST Reset printer
1104 TST Generate self-test page
1105 EJT Eject card
1106
1107 Other "Simple commands" referenced in Rio Pro/Enduro+ docs
1108
1109 DEALERSERVICE%s ON/OFF (enter/exit dealer service mode)
1110 CAM Reset print head cam position
1111 CHP%s UP/DOWN Feed card into smart encoder
1112 CLN Cleaning cycle
1113 DYE Re-init dye film
1114 ENC Test encoding cycle
1115 FEED%d 0/1,+ 0/1, load card into standby, >1 feed N cards.
1116 FLIP Flip card in printer
1117 FRN%s ON/OFF -- Film saving
1118 HEAD%s UP/DOWN -- Raise or lower print head.
1119 RAMP%d 0-100 Density ramp, 50 default
1120 SET Saves settings into NVDATA
1121 STN Re-init Holokote
1122 SNS Soak cycle, test all sensors
1123 SHW%s CAM, TACHO, FLIP, DYE, LID, FRONT, MID, READ, BUTTON1, BUTTON2,
1124 SMART, TEMP, ON, OFF
1125 LNG%d 0/1/2/3/4/5 == ENG/POR/FRE/GER/SPA/ITA
1126 RUN%s CAM, FEED, DYE, MAIN, FLIPPER, FLIPROLL, FAN, PANEL, POUT, CAL, LCD,
1127 OFF
1128 FLM%s Y/M/C/K/O Align ribbon at corresponding panel
1129 FCL Init dye calibration routine
1130 FCL###### Set dye color to ###### (RGB hex)
1131
1132 */