FreeCalypso > hg > gsm-codec-lib
view miscutil/tw5a-dump.c @ 585:3c6bf0d26ee7 default tip
TW-TS-005 reader: fix maximum line length bug
TW-TS-005 section 4.1 states:
The maximum allowed length of each line is 80 characters, not
including the OS-specific newline encoding.
The implementation of this line length limit in the TW-TS-005 hex file
reader function in the present suite was wrong, such that lines of
the full maximum length could not be read. Fix it.
Note that this bug affects comment lines too, not just actual RTP
payloads. Neither Annex A nor Annex B features an RTP payload format
that goes to the maximum of 40 bytes, but if a comment line goes to
the maximum allowed length of 80 characters not including the
terminating newline, the bug will be triggered, necessitating
the present fix.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 25 Feb 2025 07:49:28 +0000 |
parents | 86d4ec69b36c |
children |
line wrap: on
line source
/* * This program reads a TW-TS-005 Annex A hexadecimal file * and dumps all frames in human-readable form. */ #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "../libgsmfr2/tw_gsmfr.h" #include "../libgsmefr/gsm_efr.h" #include "../libtest/tw5reader.h" static void dump_fr_frame(frame) uint8_t *frame; { int16_t params[GSMFR_NUM_PARAMS]; int i, j, n; printf(" SID=%d LARc", gsmfr_preproc_sid_classify(frame)); gsmfr_unpack_to_array(frame, params); n = 0; for (i = 0; i < 8; i++) printf(" %d", params[n++]); if (!bcmp(frame, gsmfr_decoder_homing_frame, GSMFR_RTP_FRAME_LEN)) fputs(" (DHF)", stdout); putchar('\n'); for (i = 0; i < 4; i++) { putchar(' '); for (j = 0; j < 17; j++) printf(" %d", params[n++]); putchar('\n'); } } static void dump_efr_frame(frame) uint8_t *frame; { int16_t params[EFR_NUM_PARAMS]; int i, j, n; printf(" SID=%d LPC", EFR_sid_classify(frame)); EFR_frame2params(frame, params); n = 0; for (i = 0; i < 5; i++) printf(" %d", params[n++]); if (!bcmp(frame, EFR_decoder_homing_frame, EFR_RTP_FRAME_LEN)) fputs(" (DHF)", stdout); putchar('\n'); for (i = 0; i < 4; i++) { putchar(' '); for (j = 0; j < 13; j++) printf(" %d", params[n++]); putchar('\n'); } } main(argc, argv) char **argv; { FILE *hexf; unsigned lineno; uint8_t frame[TWTS005_MAX_FRAME]; unsigned frame_len, bfi; int rc; if (argc != 2) { fprintf(stderr, "usage: %s hex-file\n", argv[0]); exit(1); } hexf = fopen(argv[1], "r"); if (!hexf) { perror(argv[1]); exit(1); } lineno = 0; for (;;) { rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); if (rc < 0) { fprintf(stderr, "%s line %u: not valid TW-TS-005\n", argv[1], lineno); exit(1); } if (!rc) break; switch (frame_len) { case 0: printf("line %u: NULL frame\n", lineno); break; case 1: if ((frame[0] & 0xF6) != 0xE6) goto invalid; printf("line %u: No_Data frame\n", lineno); printf(" TEH=%02X (DTXd=%u TAF=%u)\n", frame[0], (frame[0] >> 3) & 1, frame[0] & 1); break; case GSMFR_RTP_FRAME_LEN: if ((frame[0] & 0xF0) != 0xD0) goto invalid; printf("line %u: FR basic frame\n", lineno); dump_fr_frame(frame); break; case GSMFR_RTP_FRAME_LEN+1: if ((frame[0] & 0xF4) != 0xE0) goto invalid; if ((frame[1] & 0xF0) != 0xD0) goto invalid; bfi = (frame[0] >> 1) & 1; printf("line %u: FR %s frame\n", lineno, bfi ? "bad" : "extended"); printf(" TEH=%02X (DTXd=%u BFI=%u TAF=%u)\n", frame[0], (frame[0] >> 3) & 1, bfi, frame[0] & 1); dump_fr_frame(frame + 1); break; case EFR_RTP_FRAME_LEN: if ((frame[0] & 0xF0) != 0xC0) goto invalid; printf("line %u: EFR basic frame\n", lineno); dump_efr_frame(frame); break; case EFR_RTP_FRAME_LEN+1: if ((frame[0] & 0xF4) != 0xE0) goto invalid; if ((frame[1] & 0xF0) != 0xC0) goto invalid; bfi = (frame[0] >> 1) & 1; printf("line %u: EFR %s frame\n", lineno, bfi ? "bad" : "extended"); printf(" TEH=%02X (DTXd=%u BFI=%u TAF=%u)\n", frame[0], (frame[0] >> 3) & 1, bfi, frame[0] & 1); dump_efr_frame(frame + 1); break; default: invalid: fprintf(stderr, "%s line %u: not a valid FR or EFR frame\n", argv[1], lineno); exit(1); } } exit(0); }