1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * t30_logging.c - ITU T.30 FAX transfer processing
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 /*! \file */
27
28 #if defined(HAVE_CONFIG_H)
29 #include "config.h"
30 #endif
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <inttypes.h>
35 #include <string.h>
36 #include <fcntl.h>
37 #include <time.h>
38 #if defined(HAVE_TGMATH_H)
39 #include <tgmath.h>
40 #endif
41 #if defined(HAVE_MATH_H)
42 #include <math.h>
43 #endif
44 #if defined(HAVE_STDBOOL_H)
45 #include <stdbool.h>
46 #else
47 #include "spandsp/stdbool.h"
48 #endif
49 #include "floating_fudge.h"
50 #include <tiffio.h>
51
52 #include "spandsp/telephony.h"
53 #include "spandsp/logging.h"
54 #include "spandsp/bit_operations.h"
55 #include "spandsp/queue.h"
56 #include "spandsp/power_meter.h"
57 #include "spandsp/complex.h"
58 #include "spandsp/tone_generate.h"
59 #include "spandsp/async.h"
60 #include "spandsp/hdlc.h"
61 #include "spandsp/fsk.h"
62 #include "spandsp/v29rx.h"
63 #include "spandsp/v29tx.h"
64 #include "spandsp/v27ter_rx.h"
65 #include "spandsp/v27ter_tx.h"
66 #include "spandsp/timezone.h"
67 #include "spandsp/t4_rx.h"
68 #include "spandsp/t4_tx.h"
69 #include "spandsp/image_translate.h"
70 #include "spandsp/t81_t82_arith_coding.h"
71 #include "spandsp/t85.h"
72 #include "spandsp/t42.h"
73 #include "spandsp/t43.h"
74 #include "spandsp/t4_t6_decode.h"
75 #include "spandsp/t4_t6_encode.h"
76 #include "spandsp/t30_fcf.h"
77 #include "spandsp/t35.h"
78 #include "spandsp/t30.h"
79 #include "spandsp/t30_logging.h"
80
81 #include "spandsp/private/logging.h"
82 #include "spandsp/private/timezone.h"
83 #include "spandsp/private/t81_t82_arith_coding.h"
84 #include "spandsp/private/t85.h"
85 #include "spandsp/private/t42.h"
86 #include "spandsp/private/t43.h"
87 #include "spandsp/private/t4_t6_decode.h"
88 #include "spandsp/private/t4_t6_encode.h"
89 #include "spandsp/private/image_translate.h"
90 #include "spandsp/private/t4_rx.h"
91 #include "spandsp/private/t4_tx.h"
92 #include "spandsp/private/t30.h"
93
94 #include "t30_local.h"
95
96 /*! Value string pair structure */
97 typedef struct
98 {
99 int val;
100 const char *str;
101 } value_string_t;
102
103 enum
104 {
105 DISBIT1 = 0x01,
106 DISBIT2 = 0x02,
107 DISBIT3 = 0x04,
108 DISBIT4 = 0x08,
109 DISBIT5 = 0x10,
110 DISBIT6 = 0x20,
111 DISBIT7 = 0x40,
112 DISBIT8 = 0x80
113 };
114
t30_completion_code_to_str(int result)115 SPAN_DECLARE(const char *) t30_completion_code_to_str(int result)
116 {
117 switch (result)
118 {
119 case T30_ERR_OK:
120 return "OK";
121 case T30_ERR_CEDTONE:
122 return "The CED tone exceeded 5s";
123 case T30_ERR_T0_EXPIRED:
124 return "Timed out waiting for initial communication";
125 case T30_ERR_T1_EXPIRED:
126 return "Timed out waiting for the first message";
127 case T30_ERR_T3_EXPIRED:
128 return "Timed out waiting for procedural interrupt";
129 case T30_ERR_HDLC_CARRIER:
130 return "The HDLC carrier did not stop in a timely manner";
131 case T30_ERR_CANNOT_TRAIN:
132 return "Failed to train with any of the compatible modems";
133 case T30_ERR_OPER_INT_FAIL:
134 return "Operator intervention failed";
135 case T30_ERR_INCOMPATIBLE:
136 return "Far end is not compatible";
137 case T30_ERR_RX_INCAPABLE:
138 return "Far end is not able to receive";
139 case T30_ERR_TX_INCAPABLE:
140 return "Far end is not able to transmit";
141 case T30_ERR_NORESSUPPORT:
142 return "Far end cannot receive at the resolution of the image";
143 case T30_ERR_NOSIZESUPPORT:
144 return "Far end cannot receive at the size of image";
145 case T30_ERR_UNEXPECTED:
146 return "Unexpected message received";
147 case T30_ERR_TX_BADDCS:
148 return "Received bad response to DCS or training";
149 case T30_ERR_TX_BADPG:
150 return "Received a DCN from remote after sending a page";
151 case T30_ERR_TX_ECMPHD:
152 return "Invalid ECM response received from receiver";
153 case T30_ERR_TX_GOTDCN:
154 return "Received a DCN while waiting for a DIS";
155 case T30_ERR_TX_INVALRSP:
156 return "Invalid response after sending a page";
157 case T30_ERR_TX_NODIS:
158 return "Received other than DIS while waiting for DIS";
159 case T30_ERR_TX_PHBDEAD:
160 return "Received no response to DCS or TCF";
161 case T30_ERR_TX_PHDDEAD:
162 return "No response after sending a page";
163 case T30_ERR_TX_T5EXP:
164 return "Timed out waiting for receiver ready (ECM mode)";
165 case T30_ERR_RX_ECMPHD:
166 return "Invalid ECM response received from transmitter";
167 case T30_ERR_RX_GOTDCS:
168 return "DCS received while waiting for DTC";
169 case T30_ERR_RX_INVALCMD:
170 return "Unexpected command after page received";
171 case T30_ERR_RX_NOCARRIER:
172 return "Carrier lost during fax receive";
173 case T30_ERR_RX_NOEOL:
174 return "Timed out while waiting for EOL (end Of line)";
175 case T30_ERR_RX_NOFAX:
176 return "Timed out while waiting for first line";
177 case T30_ERR_RX_T2EXPDCN:
178 return "Timer T2 expired while waiting for DCN";
179 case T30_ERR_RX_T2EXPD:
180 return "Timer T2 expired while waiting for phase D";
181 case T30_ERR_RX_T2EXPFAX:
182 return "Timer T2 expired while waiting for fax page";
183 case T30_ERR_RX_T2EXPMPS:
184 return "Timer T2 expired while waiting for next fax page";
185 case T30_ERR_RX_T2EXPRR:
186 return "Timer T2 expired while waiting for RR command";
187 case T30_ERR_RX_T2EXP:
188 return "Timer T2 expired while waiting for NSS, DCS or MCF";
189 case T30_ERR_RX_DCNWHY:
190 return "Unexpected DCN while waiting for DCS or DIS";
191 case T30_ERR_RX_DCNDATA:
192 return "Unexpected DCN while waiting for image data";
193 case T30_ERR_RX_DCNFAX:
194 return "Unexpected DCN while waiting for EOM, EOP or MPS";
195 case T30_ERR_RX_DCNPHD:
196 return "Unexpected DCN after EOM or MPS sequence";
197 case T30_ERR_RX_DCNRRD:
198 return "Unexpected DCN after RR/RNR sequence";
199 case T30_ERR_RX_DCNNORTN:
200 return "Unexpected DCN after requested retransmission";
201 case T30_ERR_FILEERROR:
202 return "TIFF/F file cannot be opened";
203 case T30_ERR_NOPAGE:
204 return "TIFF/F page not found";
205 case T30_ERR_BADTIFF:
206 return "TIFF/F format is not compatible";
207 case T30_ERR_BADPAGE:
208 return "TIFF/F page number tag missing";
209 case T30_ERR_BADTAG:
210 return "Incorrect values for TIFF/F tags";
211 case T30_ERR_BADTIFFHDR:
212 return "Bad TIFF/F header - incorrect values in fields";
213 case T30_ERR_NOMEM:
214 return "Cannot allocate memory for more pages";
215 case T30_ERR_RETRYDCN:
216 return "Disconnected after permitted retries";
217 case T30_ERR_CALLDROPPED:
218 return "The call dropped prematurely";
219 case T30_ERR_NOPOLL:
220 return "Poll not accepted";
221 case T30_ERR_IDENT_UNACCEPTABLE:
222 return "Ident not accepted";
223 case T30_ERR_PSA_UNACCEPTABLE:
224 return "Polled sub-address not accepted";
225 case T30_ERR_SEP_UNACCEPTABLE:
226 return "Selective polling address not accepted";
227 case T30_ERR_SID_UNACCEPTABLE:
228 return "Sender identification not accepted";
229 case T30_ERR_PWD_UNACCEPTABLE:
230 return "Password not accepted";
231 case T30_ERR_SUB_UNACCEPTABLE:
232 return "Sub-address not accepted";
233 case T30_ERR_TSA_UNACCEPTABLE:
234 return "Transmitting subscriber internet address not accepted";
235 case T30_ERR_IRA_UNACCEPTABLE:
236 return "Internet routing address not accepted";
237 case T30_ERR_CIA_UNACCEPTABLE:
238 return "Calling subscriber internet address not accepted";
239 case T30_ERR_ISP_UNACCEPTABLE:
240 return "Internet selective polling address not accepted";
241 case T30_ERR_CSA_UNACCEPTABLE:
242 return "Called subscriber internet address not accepted";
243 }
244 /*endswitch*/
245 return "???";
246 }
247 /*- End of function --------------------------------------------------------*/
248
t30_modem_to_str(int modem)249 SPAN_DECLARE(const char *) t30_modem_to_str(int modem)
250 {
251 switch (modem)
252 {
253 case T30_MODEM_NONE:
254 return "None";
255 case T30_MODEM_PAUSE:
256 return "Pause";
257 case T30_MODEM_CED:
258 return "CED";
259 case T30_MODEM_CNG:
260 return "CNG";
261 case T30_MODEM_V21:
262 return "V.21";
263 case T30_MODEM_V27TER:
264 return "V.27ter";
265 case T30_MODEM_V29:
266 return "V.29";
267 case T30_MODEM_V17:
268 return "V.17";
269 case T30_MODEM_V34HDX:
270 return "V.34HDX";
271 case T30_MODEM_DONE:
272 return "Done";
273 }
274 /*endswitch*/
275 return "???";
276 }
277 /*- End of function --------------------------------------------------------*/
278
t30_frametype(uint8_t x)279 SPAN_DECLARE(const char *) t30_frametype(uint8_t x)
280 {
281 switch (x)
282 {
283 case T30_DIS:
284 return "DIS";
285 case T30_CSI:
286 return "CSI";
287 case T30_NSF:
288 return "NSF";
289 case T30_DTC:
290 return "DTC";
291 case T30_CIG:
292 return "CIG";
293 case T30_NSC:
294 return "NSC";
295 case T30_PWD:
296 return "PWD";
297 case T30_SEP:
298 return "SEP";
299 case T30_PSA:
300 return "PSA";
301 case T30_CIA:
302 return "CIA";
303 case T30_ISP:
304 return "ISP";
305 case T30_DCS:
306 case T30_DCS | 0x01:
307 return "DCS";
308 case T30_TSI:
309 case T30_TSI | 0x01:
310 return "TSI";
311 case T30_NSS:
312 case T30_NSS | 0x01:
313 return "NSS";
314 case T30_SUB:
315 case T30_SUB | 0x01:
316 return "SUB";
317 case T30_SID:
318 case T30_SID | 0x01:
319 return "SID";
320 case T30_CTC:
321 case T30_CTC | 0x01:
322 return "CTC";
323 case T30_TSA:
324 case T30_TSA | 0x01:
325 return "TSA";
326 case T30_IRA:
327 case T30_IRA | 0x01:
328 return "IRA";
329 case T30_CFR:
330 case T30_CFR | 0x01:
331 return "CFR";
332 case T30_FTT:
333 case T30_FTT | 0x01:
334 return "FTT";
335 case T30_CTR:
336 case T30_CTR | 0x01:
337 return "CTR";
338 case T30_CSA:
339 case T30_CSA | 0x01:
340 return "CSA";
341 case T30_EOM:
342 case T30_EOM | 0x01:
343 return "EOM";
344 case T30_MPS:
345 case T30_MPS | 0x01:
346 return "MPS";
347 case T30_EOP:
348 case T30_EOP | 0x01:
349 return "EOP";
350 case T30_PRI_EOM:
351 case T30_PRI_EOM | 0x01:
352 return "PRI-EOM";
353 case T30_PRI_MPS:
354 case T30_PRI_MPS | 0x01:
355 return "PRI-MPS";
356 case T30_PRI_EOP:
357 case T30_PRI_EOP | 0x01:
358 return "PRI-EOP";
359 case T30_EOS:
360 case T30_EOS | 0x01:
361 return "EOS";
362 case T30_PPS:
363 case T30_PPS | 0x01:
364 return "PPS";
365 case T30_EOR:
366 case T30_EOR | 0x01:
367 return "EOR";
368 case T30_RR:
369 case T30_RR | 0x01:
370 return "RR";
371 case T30_MCF:
372 case T30_MCF | 0x01:
373 return "MCF";
374 case T30_RTP:
375 case T30_RTP | 0x01:
376 return "RTP";
377 case T30_RTN:
378 case T30_RTN | 0x01:
379 return "RTN";
380 case T30_PIP:
381 case T30_PIP | 0x01:
382 return "PIP";
383 case T30_PIN:
384 case T30_PIN | 0x01:
385 return "PIN";
386 case T30_PPR:
387 case T30_PPR | 0x01:
388 return "PPR";
389 case T30_RNR:
390 case T30_RNR | 0x01:
391 return "RNR";
392 case T30_ERR:
393 case T30_ERR | 0x01:
394 return "ERR";
395 case T30_FDM:
396 case T30_FDM | 0x01:
397 return "FDM";
398 case T30_DCN:
399 case T30_DCN | 0x01:
400 return "DCN";
401 case T30_CRP:
402 case T30_CRP | 0x01:
403 return "CRP";
404 case T30_FNV:
405 case T30_FNV | 0x01:
406 return "FNV";
407 case T30_TNR:
408 case T30_TNR | 0x01:
409 return "TNR";
410 case T30_TR:
411 case T30_TR | 0x01:
412 return "TR";
413 case T30_TK:
414 return "TK";
415 case T30_RK:
416 return "RK";
417 #if 0
418 case T30_PSS:
419 return "PSS";
420 #endif
421 case T30_DES:
422 return "DES";
423 case T30_DEC:
424 return "DEC";
425 case T30_DER:
426 return "DER";
427 #if 0
428 case T30_DTR:
429 return "DTR";
430 #endif
431 case T30_DNK:
432 case T30_DNK | 0x01:
433 return "DNK";
434 case T30_PID:
435 case T30_PID | 0x01:
436 return "PID";
437 case T30_NULL:
438 return "NULL";
439 case T4_FCD:
440 return "FCD";
441 case T4_CCD:
442 return "CCD";
443 case T4_RCP:
444 return "RCP";
445 }
446 /*endswitch*/
447 return "???";
448 }
449 /*- End of function --------------------------------------------------------*/
450
octet_reserved_bit(logging_state_t * log,const uint8_t * msg,int bit_no,int expected)451 static void octet_reserved_bit(logging_state_t *log,
452 const uint8_t *msg,
453 int bit_no,
454 int expected)
455 {
456 char s[10] = ".... ....";
457 int bit;
458 uint8_t octet;
459
460 /* Break out the octet and the bit number within it. */
461 octet = msg[((bit_no - 1) >> 3) + 3];
462 bit_no = (bit_no - 1) & 7;
463 /* Now get the actual bit. */
464 bit = (octet >> bit_no) & 1;
465 /* Is it what it should be. */
466 if (bit ^ expected)
467 {
468 /* Only log unexpected values. */
469 s[7 - bit_no + ((bit_no < 4) ? 1 : 0)] = (uint8_t) (bit + '0');
470 span_log(log, SPAN_LOG_FLOW, " %s= Unexpected state for reserved bit: %d\n", s, bit);
471 }
472 /*endif*/
473 }
474 /*- End of function --------------------------------------------------------*/
475
octet_bit_field(logging_state_t * log,const uint8_t * msg,int bit_no,const char * desc,const char * yeah,const char * neigh)476 static void octet_bit_field(logging_state_t *log,
477 const uint8_t *msg,
478 int bit_no,
479 const char *desc,
480 const char *yeah,
481 const char *neigh)
482 {
483 char s[10] = ".... ....";
484 int bit;
485 uint8_t octet;
486 const char *tag;
487
488 /* Break out the octet and the bit number within it. */
489 octet = msg[((bit_no - 1) >> 3) + 3];
490 bit_no = (bit_no - 1) & 7;
491 /* Now get the actual bit. */
492 bit = (octet >> bit_no) & 1;
493 /* Edit the bit string for display. */
494 s[7 - bit_no + ((bit_no < 4) ? 1 : 0)] = (uint8_t) (bit + '0');
495 /* Find the right tag to display. */
496 if (bit)
497 {
498 if ((tag = yeah) == NULL)
499 tag = "Set";
500 /*endif*/
501 }
502 else
503 {
504 if ((tag = neigh) == NULL)
505 tag = "Not set";
506 /*endif*/
507 }
508 /*endif*/
509 /* Eh, voila! */
510 span_log(log, SPAN_LOG_FLOW, " %s= %s: %s\n", s, desc, tag);
511 }
512 /*- End of function --------------------------------------------------------*/
513
octet_field(logging_state_t * log,const uint8_t * msg,int start,int end,const char * desc,const value_string_t tags[])514 static void octet_field(logging_state_t *log,
515 const uint8_t *msg,
516 int start,
517 int end,
518 const char *desc,
519 const value_string_t tags[])
520 {
521 char s[10] = ".... ....";
522 int i;
523 uint8_t octet;
524 const char *tag;
525
526 /* Break out the octet and the bit number range within it. */
527 octet = msg[((start - 1) >> 3) + 3];
528 start = (start - 1) & 7;
529 end = ((end - 1) & 7) + 1;
530
531 /* Edit the bit string for display. */
532 for (i = start; i < end; i++)
533 s[7 - i + ((i < 4) ? 1 : 0)] = (uint8_t) ((octet >> i) & 1) + '0';
534 /*endfor*/
535
536 /* Find the right tag to display. */
537 octet = (uint8_t) ((octet >> start) & ((0xFF + (1 << (end - start))) & 0xFF));
538 tag = "Invalid";
539 for (i = 0; tags[i].str; i++)
540 {
541 if (octet == tags[i].val)
542 {
543 tag = tags[i].str;
544 break;
545 }
546 /*endif*/
547 }
548 /*endfor*/
549 /* Eh, voila! */
550 span_log(log, SPAN_LOG_FLOW, " %s= %s: %s\n", s, desc, tag);
551 }
552 /*- End of function --------------------------------------------------------*/
553
t30_decode_dis_dtc_dcs(t30_state_t * s,const uint8_t * pkt,int len)554 SPAN_DECLARE(void) t30_decode_dis_dtc_dcs(t30_state_t *s, const uint8_t *pkt, int len)
555 {
556 logging_state_t *log;
557 uint8_t frame_type;
558 static const value_string_t available_signalling_rate_tags[] =
559 {
560 { 0x00, "V.27 ter fall-back mode" },
561 { 0x01, "V.29" },
562 { 0x02, "V.27 ter" },
563 { 0x03, "V.27 ter and V.29" },
564 { 0x0B, "V.27 ter, V.29, and V.17" },
565 { 0x06, "Reserved" },
566 { 0x0A, "Reserved" },
567 { 0x0E, "Reserved" },
568 { 0x0F, "Reserved" },
569 { 0x04, "Not used" },
570 { 0x05, "Not used" },
571 { 0x08, "Not used" },
572 { 0x09, "Not used" },
573 { 0x0C, "Not used" },
574 { 0x0D, "Not used" },
575 { 0x00, NULL }
576 };
577 static const value_string_t selected_signalling_rate_tags[] =
578 {
579 { 0x00, "V.27ter 2400bps" },
580 { 0x01, "V.29, 9600bps" },
581 { 0x02, "V.27ter 4800bps" },
582 { 0x03, "V.29 7200bps" },
583 { 0x08, "V.17 14400bps" },
584 { 0x09, "V.17 9600bps" },
585 { 0x0A, "V.17 12000bps" },
586 { 0x0B, "V.17 7200bps" },
587 { 0x05, "Reserved" },
588 { 0x07, "Reserved" },
589 { 0x0C, "Reserved" },
590 { 0x0D, "Reserved" },
591 { 0x0E, "Reserved" },
592 { 0x0F, "Reserved" },
593 { 0x00, NULL }
594 };
595 static const value_string_t available_scan_line_length_tags[] =
596 {
597 { 0x00, "215mm +- 1%" },
598 { 0x01, "215mm +- 1% and 255mm +- 1%" },
599 { 0x02, "215mm +- 1%, 255mm +- 1% and 303mm +- 1%" },
600 { 0x00, NULL }
601 };
602 static const value_string_t selected_scan_line_length_tags[] =
603 {
604 { 0x00, "215mm +- 1%" },
605 { 0x01, "255mm +- 1%" },
606 { 0x02, "303mm +- 1%" },
607 { 0x00, NULL }
608 };
609 static const value_string_t available_recording_length_tags[] =
610 {
611 { 0x00, "A4 (297mm)" },
612 { 0x01, "A4 (297mm) and B4 (364mm)" },
613 { 0x02, "Unlimited" },
614 { 0x00, NULL }
615 };
616 static const value_string_t selected_recording_length_tags[] =
617 {
618 { 0x00, "A4 (297mm)" },
619 { 0x01, "B4 (364mm)" },
620 { 0x02, "Unlimited" },
621 { 0x00, NULL }
622 };
623 static const value_string_t available_minimum_scan_line_time_tags[] =
624 {
625 { 0x00, "20ms at 3.85 l/mm; T7.7 = T3.85" },
626 { 0x01, "5ms at 3.85 l/mm; T7.7 = T3.85" },
627 { 0x02, "10ms at 3.85 l/mm; T7.7 = T3.85" },
628 { 0x03, "20ms at 3.85 l/mm; T7.7 = 1/2 T3.85" },
629 { 0x04, "40ms at 3.85 l/mm; T7.7 = T3.85" },
630 { 0x05, "40ms at 3.85 l/mm; T7.7 = 1/2 T3.85" },
631 { 0x06, "10ms at 3.85 l/mm; T7.7 = 1/2 T3.85" },
632 { 0x07, "0ms at 3.85 l/mm; T7.7 = T3.85" },
633 { 0x00, NULL }
634 };
635 static const value_string_t selected_minimum_scan_line_time_tags[] =
636 {
637 { 0x00, "20ms" },
638 { 0x01, "5ms" },
639 { 0x02, "10ms" },
640 { 0x04, "40ms" },
641 { 0x07, "0ms" },
642 { 0x00, NULL }
643 };
644 static const value_string_t shared_data_memory_capacity_tags[] =
645 {
646 { 0x00, "Not available" },
647 { 0x01, "Level 2 = 2.0 Mbytes" },
648 { 0x02, "Level 1 = 1.0 Mbytes" },
649 { 0x03, "Level 3 = unlimited (i.e. >= 32 Mbytes)" },
650 { 0x00, NULL }
651 };
652 static const value_string_t t89_profile_tags[] =
653 {
654 { 0x00, "Not used" },
655 { 0x01, "Profiles 2 and 3" },
656 { 0x02, "Profile 2" },
657 { 0x04, "Profile 1" },
658 { 0x06, "Profile 3" },
659 { 0x03, "Reserved" },
660 { 0x05, "Reserved" },
661 { 0x07, "Reserved" },
662 { 0x00, NULL }
663 };
664 static const value_string_t t44_mixed_raster_content_tags[] =
665 {
666 { 0x00, "0" },
667 { 0x01, "1" },
668 { 0x02, "2" },
669 { 0x32, "3" },
670 { 0x04, "4" },
671 { 0x05, "5" },
672 { 0x06, "6" },
673 { 0x07, "7" },
674 { 0x00, NULL }
675 };
676
677 if (!span_log_test(&s->logging, SPAN_LOG_FLOW))
678 return;
679 /*endif*/
680 frame_type = pkt[2] & 0xFE;
681 log = &s->logging;
682 if (len <= 2)
683 {
684 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
685 return;
686 }
687 /*endif*/
688
689 span_log(log, SPAN_LOG_FLOW, "%s:\n", t30_frametype(pkt[2]));
690 if (len <= 3)
691 {
692 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
693 return;
694 }
695 /*endif*/
696 octet_bit_field(log, pkt, 1, "Store and forward Internet fax (T.37)", NULL, NULL);
697 octet_reserved_bit(log, pkt, 2, 0);
698 octet_bit_field(log, pkt, 3, "Real-time Internet fax (T.38)", NULL, NULL);
699 octet_bit_field(log, pkt, 4, "3G mobile network", NULL, NULL);
700 octet_reserved_bit(log, pkt, 5, 0);
701 if (frame_type == T30_DCS)
702 {
703 octet_reserved_bit(log, pkt, 6, 0);
704 octet_reserved_bit(log, pkt, 7, 0);
705 }
706 else
707 {
708 octet_bit_field(log, pkt, 6, "V.8 capabilities", NULL, NULL);
709 octet_bit_field(log, pkt, 7, "Preferred octets", "64 octets", "256 octets");
710 }
711 /*endif*/
712 octet_reserved_bit(log, pkt, 8, 0);
713 if (len <= 4)
714 {
715 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
716 return;
717 }
718 /*endif*/
719
720 if (frame_type == T30_DCS)
721 {
722 octet_reserved_bit(log, pkt, 9, 0);
723 octet_bit_field(log, pkt, 10, "Receive fax", NULL, NULL);
724 octet_field(log, pkt, 11, 14, "Selected data signalling rate", selected_signalling_rate_tags);
725 }
726 else
727 {
728 octet_bit_field(log, pkt, 9, "Ready to transmit a fax document (polling)", NULL, NULL);
729 octet_bit_field(log, pkt, 10, "Can receive fax", NULL, NULL);
730 octet_field(log, pkt, 11, 14, "Supported data signalling rates", available_signalling_rate_tags);
731 }
732 /*endif*/
733 octet_bit_field(log, pkt, 15, "R8x7.7lines/mm and/or 200x200pels/25.4mm", NULL, NULL);
734 octet_bit_field(log, pkt, 16, "2-D coding", NULL, NULL);
735 if (len <= 5)
736 {
737 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
738 return;
739 }
740 /*endif*/
741
742 if (frame_type == T30_DCS)
743 {
744 octet_field(log, pkt, 17, 18, "Recording width", selected_scan_line_length_tags);
745 octet_field(log, pkt, 19, 20, "Recording length", selected_recording_length_tags);
746 octet_field(log, pkt, 21, 23, "Minimum scan line time", selected_minimum_scan_line_time_tags);
747 }
748 else
749 {
750 octet_field(log, pkt, 17, 18, "Recording width", available_scan_line_length_tags);
751 octet_field(log, pkt, 19, 20, "Recording length", available_recording_length_tags);
752 octet_field(log, pkt, 21, 23, "Receiver's minimum scan line time", available_minimum_scan_line_time_tags);
753 }
754 /*endif*/
755 octet_bit_field(log, pkt, 24, "Extension indicator", NULL, NULL);
756 if (!(pkt[5] & DISBIT8))
757 return;
758 /*endif*/
759 if (len <= 6)
760 {
761 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
762 return;
763 }
764 /*endif*/
765
766 octet_reserved_bit(log, pkt, 25, 0);
767 octet_bit_field(log, pkt, 26, "Compressed/uncompressed mode", "Uncompressed", "Compressed");
768 octet_bit_field(log, pkt, 27, "Error correction mode (ECM)", "ECM", "Non-ECM");
769 if (frame_type == T30_DCS)
770 octet_bit_field(log, pkt, 28, "Frame size", "64 octets", "256 octets");
771 else
772 octet_reserved_bit(log, pkt, 28, 0);
773 /*endif*/
774 octet_reserved_bit(log, pkt, 29, 0);
775 octet_reserved_bit(log, pkt, 30, 0);
776 octet_bit_field(log, pkt, 31, "T.6 coding", NULL, NULL);
777 octet_bit_field(log, pkt, 32, "Extension indicator", NULL, NULL);
778 if (!(pkt[6] & DISBIT8))
779 return;
780 /*endif*/
781 if (len <= 7)
782 {
783 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
784 return;
785 }
786 /*endif*/
787
788 octet_bit_field(log, pkt, 33, "\"Field not valid\" supported", NULL, NULL);
789 if (frame_type == T30_DCS)
790 {
791 octet_reserved_bit(log, pkt, 34, 0);
792 octet_reserved_bit(log, pkt, 35, 0);
793 }
794 else
795 {
796 octet_bit_field(log, pkt, 34, "Multiple selective polling", NULL, NULL);
797 octet_bit_field(log, pkt, 35, "Polled sub-address", NULL, NULL);
798 }
799 /*endif*/
800 octet_bit_field(log, pkt, 36, "T.43 coding", NULL, NULL);
801 octet_bit_field(log, pkt, 37, "Plane interleave", NULL, NULL);
802 octet_bit_field(log, pkt, 38, "Voice coding with 32kbit/s ADPCM (Rec. G.726)", NULL, NULL);
803 octet_bit_field(log, pkt, 39, "Reserved for the use of extended voice coding set", NULL, NULL);
804 octet_bit_field(log, pkt, 40, "Extension indicator", NULL, NULL);
805 if (!(pkt[7] & DISBIT8))
806 return;
807 /*endif*/
808 if (len <= 8)
809 {
810 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
811 return;
812 }
813 /*endif*/
814 octet_bit_field(log, pkt, 41, "R8x15.4lines/mm", NULL, NULL);
815 octet_bit_field(log, pkt, 42, "300x300pels/25.4mm", NULL, NULL);
816 octet_bit_field(log, pkt, 43, "R16x15.4lines/mm and/or 400x400pels/25.4mm", NULL, NULL);
817 if (frame_type == T30_DCS)
818 {
819 octet_bit_field(log, pkt, 44, "Resolution type selection", "Inch", "Metric");
820 octet_reserved_bit(log, pkt, 45, 0);
821 octet_reserved_bit(log, pkt, 46, 0);
822 octet_reserved_bit(log, pkt, 47, 0);
823 }
824 else
825 {
826 octet_bit_field(log, pkt, 44, "Inch-based resolution preferred", NULL, NULL);
827 octet_bit_field(log, pkt, 45, "Metric-based resolution preferred", NULL, NULL);
828 octet_bit_field(log, pkt, 46, "Minimum scan line time for higher resolutions", "T15.4 = 1/2 T7.7", "T15.4 = T7.7");
829 octet_bit_field(log, pkt, 47, "Selective polling", NULL, NULL);
830 }
831 /*endif*/
832 octet_bit_field(log, pkt, 48, "Extension indicator", NULL, NULL);
833 if (!(pkt[8] & DISBIT8))
834 return;
835 /*endif*/
836 if (len <= 9)
837 {
838 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
839 return;
840 }
841 /*endif*/
842
843 octet_bit_field(log, pkt, 49, "Sub-addressing", NULL, NULL);
844 if (frame_type == T30_DCS)
845 {
846 octet_bit_field(log, pkt, 50, "Sender identification transmission", NULL, NULL);
847 octet_reserved_bit(log, pkt, 51, 0);
848 }
849 else
850 {
851 octet_bit_field(log, pkt, 50, "Password", NULL, NULL);
852 octet_bit_field(log, pkt, 51, "Ready to transmit a data file (polling)", NULL, NULL);
853 }
854 /*endif*/
855 octet_reserved_bit(log, pkt, 52, 0);
856 octet_bit_field(log, pkt, 53, "Binary file transfer (BFT)", NULL, NULL);
857 octet_bit_field(log, pkt, 54, "Document transfer mode (DTM)", NULL, NULL);
858 octet_bit_field(log, pkt, 55, "Electronic data interchange (EDI)", NULL, NULL);
859 octet_bit_field(log, pkt, 56, "Extension indicator", NULL, NULL);
860 if (!(pkt[9] & DISBIT8))
861 return;
862 /*endif*/
863 if (len <= 10)
864 {
865 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
866 return;
867 }
868 /*endif*/
869
870 octet_bit_field(log, pkt, 57, "Basic transfer mode (BTM)", NULL, NULL);
871 octet_reserved_bit(log, pkt, 58, 0);
872 if (frame_type == T30_DCS)
873 octet_reserved_bit(log, pkt, 59, 0);
874 else
875 octet_bit_field(log, pkt, 59, "Ready to transfer a character or mixed mode document (polling)", NULL, NULL);
876 /*endif*/
877 octet_bit_field(log, pkt, 60, "Character mode", NULL, NULL);
878 octet_reserved_bit(log, pkt, 61, 0);
879 octet_bit_field(log, pkt, 62, "Mixed mode (Annex E/T.4)", NULL, NULL);
880 octet_reserved_bit(log, pkt, 63, 0);
881 octet_bit_field(log, pkt, 64, "Extension indicator", NULL, NULL);
882 if (!(pkt[10] & DISBIT8))
883 return;
884 /*endif*/
885 if (len <= 11)
886 {
887 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
888 return;
889 }
890 /*endif*/
891
892 octet_bit_field(log, pkt, 65, "Processable mode 26 (Rec. T.505)", NULL, NULL);
893 octet_bit_field(log, pkt, 66, "Digital network capability", NULL, NULL);
894 octet_bit_field(log, pkt, 67, "Duplex capability", "Full", "Half only");
895 if (frame_type == T30_DCS)
896 octet_bit_field(log, pkt, 68, "Full colour mode", NULL, NULL);
897 else
898 octet_bit_field(log, pkt, 68, "JPEG coding", NULL, NULL);
899 /*endif*/
900 octet_bit_field(log, pkt, 69, "Full colour mode", NULL, NULL);
901 if (frame_type == T30_DCS)
902 octet_bit_field(log, pkt, 70, "Preferred Huffman tables", NULL, NULL);
903 else
904 octet_reserved_bit(log, pkt, 70, 0);
905 /*endif*/
906 octet_bit_field(log, pkt, 71, "12bits/pel component", NULL, NULL);
907 octet_bit_field(log, pkt, 72, "Extension indicator", NULL, NULL);
908 if (!(pkt[11] & DISBIT8))
909 return;
910 /*endif*/
911 if (len <= 12)
912 {
913 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
914 return;
915 }
916 /*endif*/
917
918 octet_bit_field(log, pkt, 73, "No subsampling (1:1:1)", NULL, NULL);
919 octet_bit_field(log, pkt, 74, "Custom illuminant", NULL, NULL);
920 octet_bit_field(log, pkt, 75, "Custom gamut range", NULL, NULL);
921 octet_bit_field(log, pkt, 76, "North American Letter (215.9mm x 279.4mm)", NULL, NULL);
922 octet_bit_field(log, pkt, 77, "North American Legal (215.9mm x 355.6mm)", NULL, NULL);
923 octet_bit_field(log, pkt, 78, "Single-progression sequential coding (Rec. T.85) basic", NULL, NULL);
924 octet_bit_field(log, pkt, 79, "Single-progression sequential coding (Rec. T.85) optional L0", NULL, NULL);
925 octet_bit_field(log, pkt, 80, "Extension indicator", NULL, NULL);
926 if (!(pkt[12] & DISBIT8))
927 return;
928 /*endif*/
929 if (len <= 13)
930 {
931 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
932 return;
933 }
934 /*endif*/
935
936 octet_bit_field(log, pkt, 81, "HKM key management", NULL, NULL);
937 octet_bit_field(log, pkt, 82, "RSA key management", NULL, NULL);
938 octet_bit_field(log, pkt, 83, "Override", NULL, NULL);
939 octet_bit_field(log, pkt, 84, "HFX40 cipher", NULL, NULL);
940 octet_bit_field(log, pkt, 85, "Alternative cipher number 2", NULL, NULL);
941 octet_bit_field(log, pkt, 86, "Alternative cipher number 3", NULL, NULL);
942 octet_bit_field(log, pkt, 87, "HFX40-I hashing", NULL, NULL);
943 octet_bit_field(log, pkt, 88, "Extension indicator", NULL, NULL);
944 if (!(pkt[13] & DISBIT8))
945 return;
946 /*endif*/
947 if (len <= 14)
948 {
949 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
950 return;
951 }
952 /*endif*/
953
954 octet_bit_field(log, pkt, 89, "Alternative hashing system 2", NULL, NULL);
955 octet_bit_field(log, pkt, 90, "Alternative hashing system 3", NULL, NULL);
956 octet_bit_field(log, pkt, 91, "Reserved for future security features", NULL, NULL);
957 octet_field(log, pkt, 92, 94, "T.44 (Mixed Raster Content)", t44_mixed_raster_content_tags);
958 octet_bit_field(log, pkt, 95, "Page length maximum stripe size for T.44 (Mixed Raster Content)", NULL, NULL);
959 octet_bit_field(log, pkt, 96, "Extension indicator", NULL, NULL);
960 if (!(pkt[14] & DISBIT8))
961 return;
962 /*endif*/
963 if (len <= 15)
964 {
965 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
966 return;
967 }
968 /*endif*/
969
970 octet_bit_field(log, pkt, 97, "Colour/gray-scale 300pels/25.4mm x 300lines/25.4mm or 400pels/25.4mm x 400lines/25.4mm resolution", NULL, NULL);
971 octet_bit_field(log, pkt, 98, "100pels/25.4mm x 100lines/25.4mm for colour/gray scale", NULL, NULL);
972 octet_bit_field(log, pkt, 99, "Simple phase C BFT negotiations", NULL, NULL);
973 if (frame_type == T30_DCS)
974 {
975 octet_reserved_bit(log, pkt, 100, 0);
976 octet_reserved_bit(log, pkt, 101, 0);
977 }
978 else
979 {
980 octet_bit_field(log, pkt, 100, "Extended BFT Negotiations capable", NULL, NULL);
981 octet_bit_field(log, pkt, 101, "Internet Selective Polling address (ISP)", NULL, NULL);
982 }
983 /*endif*/
984 octet_bit_field(log, pkt, 102, "Internet Routing Address (IRA)", NULL, NULL);
985 octet_reserved_bit(log, pkt, 103, 0);
986 octet_bit_field(log, pkt, 104, "Extension indicator", NULL, NULL);
987 if (!(pkt[15] & DISBIT8))
988 return;
989 /*endif*/
990 if (len <= 16)
991 {
992 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
993 return;
994 }
995 /*endif*/
996
997 octet_bit_field(log, pkt, 105, "600pels/25.4mm x 600lines/25.4mm", NULL, NULL);
998 octet_bit_field(log, pkt, 106, "1200pels/25.4mm x 1200lines/25.4mm", NULL, NULL);
999 octet_bit_field(log, pkt, 107, "300pels/25.4mm x 600lines/25.4mm", NULL, NULL);
1000 octet_bit_field(log, pkt, 108, "400pels/25.4mm x 800lines/25.4mm", NULL, NULL);
1001 octet_bit_field(log, pkt, 109, "600pels/25.4mm x 1200lines/25.4mm", NULL, NULL);
1002 octet_bit_field(log, pkt, 110, "Colour/gray scale 600pels/25.4mm x 600lines/25.4mm", NULL, NULL);
1003 octet_bit_field(log, pkt, 111, "Colour/gray scale 1200pels/25.4mm x 1200lines/25.4mm", NULL, NULL);
1004 octet_bit_field(log, pkt, 112, "Extension indicator", NULL, NULL);
1005 if (!(pkt[16] & DISBIT8))
1006 return;
1007 /*endif*/
1008 if (len <= 17)
1009 {
1010 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
1011 return;
1012 }
1013 /*endif*/
1014
1015 octet_bit_field(log, pkt, 113, "Double sided printing capability (alternate mode)", NULL, NULL);
1016 octet_bit_field(log, pkt, 114, "Double sided printing capability (continuous mode)", NULL, NULL);
1017 if (frame_type == T30_DCS)
1018 octet_bit_field(log, pkt, 115, "Black and white mixed raster content profile (MRCbw)", NULL, NULL);
1019 else
1020 octet_reserved_bit(log, pkt, 115, 0);
1021 /*endif*/
1022 octet_bit_field(log, pkt, 116, "T.45 (run length colour encoded)", NULL, NULL);
1023 octet_field(log, pkt, 117, 118, "Shared memory", shared_data_memory_capacity_tags);
1024 octet_bit_field(log, pkt, 119, "T.44 colour space", NULL, NULL);
1025 octet_bit_field(log, pkt, 120, "Extension indicator", NULL, NULL);
1026 if (!(pkt[17] & DISBIT8))
1027 return;
1028 /*endif*/
1029 if (len <= 18)
1030 {
1031 span_log(log, SPAN_LOG_FLOW, " Frame is short\n");
1032 return;
1033 }
1034 /*endif*/
1035
1036 octet_bit_field(log, pkt, 121, "Flow control capability for T.38 communication", NULL, NULL);
1037 octet_bit_field(log, pkt, 122, "K>4", NULL, NULL);
1038 octet_bit_field(log, pkt, 123, "Internet aware T.38 mode fax (not affected by data signal rate bits)", NULL, NULL);
1039 octet_field(log, pkt, 124, 126, "T.89 (Application profiles for ITU-T Rec T.88)", t89_profile_tags);
1040 octet_bit_field(log, pkt, 127, "sYCC-JPEG coding", NULL, NULL);
1041 octet_bit_field(log, pkt, 128, "Extension indicator", NULL, NULL);
1042 if (!(pkt[18] & DISBIT8))
1043 return;
1044 /*endif*/
1045
1046 span_log(log, SPAN_LOG_FLOW, " Extended beyond the current T.30 specification!\n");
1047 }
1048 /*- End of function --------------------------------------------------------*/
1049 /*- End of file ------------------------------------------------------------*/
1050