FreeCalypso > hg > rtp-debug-utils
comparison pcap-study/rtp-gsmfr-dump.c @ 15:96b37cef5020
rtp-gsmfr-dump: convert from old libgsm to libgsmfr2
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 19 Sep 2024 01:59:14 +0000 |
| parents | e686bc92c7d8 |
| children |
comparison
equal
deleted
inserted
replaced
| 14:e7f43262efa1 | 15:96b37cef5020 |
|---|---|
| 14 #include <sys/types.h> | 14 #include <sys/types.h> |
| 15 #include <sys/socket.h> | 15 #include <sys/socket.h> |
| 16 #include <netinet/in.h> | 16 #include <netinet/in.h> |
| 17 #include <arpa/inet.h> | 17 #include <arpa/inet.h> |
| 18 #include <stdio.h> | 18 #include <stdio.h> |
| 19 #include <stdint.h> | |
| 19 #include <stdlib.h> | 20 #include <stdlib.h> |
| 20 #include <string.h> | 21 #include <string.h> |
| 21 #include <strings.h> | 22 #include <strings.h> |
| 22 #include <pcap/pcap.h> | 23 #include <pcap/pcap.h> |
| 23 #include <gsm.h> | 24 #include <tw_gsmfr.h> |
| 24 #include <gsm_efr.h> | 25 #include <gsm_efr.h> |
| 25 | 26 |
| 26 static pcap_t *pcap; | 27 static pcap_t *pcap; |
| 27 static in_addr_t match_ip_addr; | 28 static in_addr_t match_ip_addr; |
| 28 static u_short match_udp_port; | 29 static u_short match_udp_port; |
| 29 static unsigned iphdr_addr_offset, udphdr_port_offset; | 30 static unsigned iphdr_addr_offset, udphdr_port_offset; |
| 30 static unsigned link_hdr_len, ethertype_offset; | 31 static unsigned link_hdr_len, ethertype_offset; |
| 31 static int stream_init_flag; | 32 static int stream_init_flag; |
| 32 static unsigned last_seq, last_tstamp, stream_ssrc; | 33 static unsigned last_seq, last_tstamp, stream_ssrc; |
| 33 static gsm dummy_state; | |
| 34 | 34 |
| 35 static void | 35 static void |
| 36 check_dl_type() | 36 check_dl_type() |
| 37 { | 37 { |
| 38 int dltype; | 38 int dltype; |
| 94 static void | 94 static void |
| 95 process_payload(payload, payload_len) | 95 process_payload(payload, payload_len) |
| 96 u_char *payload; | 96 u_char *payload; |
| 97 unsigned payload_len; | 97 unsigned payload_len; |
| 98 { | 98 { |
| 99 gsm_signal params[76]; | 99 int16_t params[76]; |
| 100 int i, j, n; | 100 int i, j, n; |
| 101 | 101 |
| 102 printf("seq 0x%04X ts 0x%08X: ", last_seq, last_tstamp); | 102 printf("seq 0x%04X ts 0x%08X: ", last_seq, last_tstamp); |
| 103 switch (payload_len) { | 103 switch (payload_len) { |
| 104 case 0: | 104 case 0: |
| 142 goto print_efr; | 142 goto print_efr; |
| 143 case 33: | 143 case 33: |
| 144 if ((payload[0] & 0xF0) != 0xD0) | 144 if ((payload[0] & 0xF0) != 0xD0) |
| 145 break; | 145 break; |
| 146 fputs("std FR", stdout); | 146 fputs("std FR", stdout); |
| 147 gsm_explode(dummy_state, payload, params); | 147 gsmfr_unpack_to_array(payload, params); |
| 148 print_fr: | 148 print_fr: |
| 149 n = 0; | 149 n = 0; |
| 150 for (i = 0; i < 8; i++) | 150 for (i = 0; i < 8; i++) |
| 151 printf(" %d", params[n++]); | 151 printf(" %d", params[n++]); |
| 152 putchar('\n'); | 152 putchar('\n'); |
| 161 if ((payload[0] & 0xF4) != 0xE0) | 161 if ((payload[0] & 0xF4) != 0xE0) |
| 162 break; | 162 break; |
| 163 if ((payload[1] & 0xF0) != 0xD0) | 163 if ((payload[1] & 0xF0) != 0xD0) |
| 164 break; | 164 break; |
| 165 printf("TEH 0x%02X FR", payload[0]); | 165 printf("TEH 0x%02X FR", payload[0]); |
| 166 gsm_explode(dummy_state, payload+1, params); | 166 gsmfr_unpack_to_array(payload+1, params); |
| 167 goto print_fr; | 167 goto print_fr; |
| 168 } | 168 } |
| 169 printf("unknown payload format, length=%u\n", payload_len); | 169 printf("unknown payload format, length=%u\n", payload_len); |
| 170 } | 170 } |
| 171 | 171 |
| 255 if (match_ip_addr == INADDR_NONE) { | 255 if (match_ip_addr == INADDR_NONE) { |
| 256 fprintf(stderr, "error: IP address argument is invalid\n"); | 256 fprintf(stderr, "error: IP address argument is invalid\n"); |
| 257 exit(1); | 257 exit(1); |
| 258 } | 258 } |
| 259 match_udp_port = htons(strtoul(argv[4], 0, 0)); | 259 match_udp_port = htons(strtoul(argv[4], 0, 0)); |
| 260 dummy_state = gsm_create(); | |
| 261 if (!dummy_state) { | |
| 262 fprintf(stderr, "gsm_create() failed!\n"); | |
| 263 exit(1); | |
| 264 } | |
| 265 for (pkt_idx = 0; ; pkt_idx++) { | 260 for (pkt_idx = 0; ; pkt_idx++) { |
| 266 pkt = pcap_next(pcap, &pkthdr); | 261 pkt = pcap_next(pcap, &pkthdr); |
| 267 if (!pkt) | 262 if (!pkt) |
| 268 break; | 263 break; |
| 269 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx); | 264 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx); |
