FreeCalypso > hg > gsm-codec-lib
comparison frtest/cvt-dlcap.c @ 139:be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Tue, 13 Dec 2022 07:03:55 +0000 |
| parents | b7ea278390eb |
| children |
comparison
equal
deleted
inserted
replaced
| 138:68215020852b | 139:be57e06bed84 |
|---|---|
| 1 /* | 1 /* |
| 2 * This program reads a TCH downlink capture produced with FreeCalypso tools | 2 * This program reads a TCH/FS downlink capture produced with FreeCalypso tools |
| 3 * (fw version with TCH downlink sniffing feature and fc-shell tch record) | 3 * (fw version with TCH downlink sniffing feature and fc-shell tch record) |
| 4 * and converts it into our extended-libgsm binary format, to be further | 4 * and converts it into our extended-libgsm binary format, to be further |
| 5 * fed to gsmfr-decode. | 5 * fed to gsmfr-decode. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <sys/types.h> | |
| 9 #include <ctype.h> | 8 #include <ctype.h> |
| 10 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stdint.h> | |
| 11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <string.h> | 12 #include <string.h> |
| 13 #include <strings.h> | 13 #include <strings.h> |
| 14 | |
| 15 static | |
| 16 decode_hex_digit(ch) | |
| 17 { | |
| 18 if (isdigit(ch)) | |
| 19 return(ch - '0'); | |
| 20 else if (isupper(ch)) | |
| 21 return(ch - 'A' + 10); | |
| 22 else | |
| 23 return(ch - 'a' + 10); | |
| 24 } | |
| 25 | |
| 26 static | |
| 27 parse_classic_part(line, status_words, tidsp_bytes) | |
| 28 char *line; | |
| 29 u_short *status_words; | |
| 30 u_char *tidsp_bytes; | |
| 31 { | |
| 32 char *cp; | |
| 33 int i; | |
| 34 | |
| 35 /* grok DSP status words */ | |
| 36 cp = line; | |
| 37 for (i = 0; i < 3; i++) { | |
| 38 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || | |
| 39 !isxdigit(cp[2]) || !isxdigit(cp[3])) | |
| 40 return -1; | |
| 41 status_words[i] = (decode_hex_digit(cp[0]) << 12) | | |
| 42 (decode_hex_digit(cp[1]) << 8) | | |
| 43 (decode_hex_digit(cp[2]) << 4) | | |
| 44 decode_hex_digit(cp[3]); | |
| 45 cp += 4; | |
| 46 if (*cp++ != ' ') | |
| 47 return -1; | |
| 48 } | |
| 49 /* read the frame bits */ | |
| 50 for (i = 0; i < 33; i++) { | |
| 51 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) | |
| 52 return -1; | |
| 53 tidsp_bytes[i] = (decode_hex_digit(cp[0]) << 4) | | |
| 54 decode_hex_digit(cp[1]); | |
| 55 cp += 2; | |
| 56 } | |
| 57 return 0; | |
| 58 } | |
| 59 | 14 |
| 60 main(argc, argv) | 15 main(argc, argv) |
| 61 char **argv; | 16 char **argv; |
| 62 { | 17 { |
| 63 FILE *inf, *outf; | 18 FILE *inf, *outf; |
| 64 char linebuf[128]; | 19 char linebuf[128]; |
| 65 int lineno, rc; | 20 int lineno, rc; |
| 66 u_short status_words[3]; | 21 uint16_t status_words[3]; |
| 67 u_char tidsp_bytes[33], libgsm_bytes[33], bfi[2]; | 22 uint8_t tidsp_bytes[33], libgsm_bytes[33], bfi[2]; |
| 68 unsigned fn_mod_104; | 23 unsigned fn_mod_104; |
| 69 | 24 |
| 70 if (argc != 3) { | 25 if (argc != 3) { |
| 71 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); | 26 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); |
| 72 exit(1); | 27 exit(1); |
| 83 } | 38 } |
| 84 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | 39 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
| 85 /* support both old and new formats */ | 40 /* support both old and new formats */ |
| 86 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && | 41 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && |
| 87 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { | 42 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { |
| 88 rc = parse_classic_part(linebuf, status_words, | 43 rc = parse_dlcap_common(linebuf, status_words, |
| 89 tidsp_bytes); | 44 tidsp_bytes); |
| 90 if (rc < 0) { | 45 if (rc < 0) { |
| 91 invalid: fprintf(stderr, | 46 invalid: fprintf(stderr, |
| 92 "error: %s is not in the expected format\n", | 47 "error: %s is not in the expected format\n", |
| 93 argv[1]); | 48 argv[1]); |
| 94 exit(1); | 49 exit(1); |
| 95 } | 50 } |
| 96 fn_mod_104 = 0; /* won't have TAF */ | 51 fn_mod_104 = 0; /* won't have TAF */ |
| 97 } else if (!strncmp(linebuf, "FR ", 3)) { | 52 } else if (!strncmp(linebuf, "FR ", 3)) { |
| 98 rc = parse_classic_part(linebuf + 3, status_words, | 53 rc = parse_dlcap_common(linebuf + 3, status_words, |
| 99 tidsp_bytes); | 54 tidsp_bytes); |
| 100 if (rc < 0) | 55 if (rc < 0) |
| 101 goto invalid; | 56 goto invalid; |
| 102 if (linebuf[84] != ' ') | 57 if (linebuf[84] != ' ') |
| 103 goto invalid; | 58 goto invalid; |
