comparison sip-manual-out/rtp.c @ 190:62ecc0aa081f

sip-manual-out: add state machine for capturing full IS messages
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 10:56:43 -0800
parents 1266e024de6c
children
comparison
equal deleted inserted replaced
189:1266e024de6c 190:62ecc0aa081f
29 29
30 static const uint8_t hdr_pattern[20] = {0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 30 static const uint8_t hdr_pattern[20] = {0, 1, 0, 1, 0, 1, 1, 0, 1, 0,
31 0, 1, 1, 0, 1, 0, 1, 0, 0, 1}; 31 0, 1, 1, 0, 1, 0, 1, 0, 0, 1};
32 32
33 static uint8_t is_hunt_buf[320]; 33 static uint8_t is_hunt_buf[320];
34 static int is_state;
35 static unsigned is_offset, is_bit_count;
36 static uint32_t is_rx_word;
34 37
35 static void 38 static void
36 reset_is_hunt() 39 reset_is_hunt()
37 { 40 {
38 memset(is_hunt_buf, 0xFF, 320); 41 memset(is_hunt_buf, 0xFF, 320);
39 } 42 is_state = 0;
40 43 }
41 static void 44
42 is_hunt_proc(input, input_pos) 45 static void
43 uint8_t *input; 46 is_rx_hunt(input_pos)
44 unsigned input_pos; 47 unsigned input_pos;
45 { 48 {
46 unsigned offset, n; 49 unsigned offset, n;
47 50
48 memmove(is_hunt_buf, is_hunt_buf + 16, 304);
49 memcpy(is_hunt_buf + 304, input, 16);
50 for (offset = 0; offset < 16; offset++) { 51 for (offset = 0; offset < 16; offset++) {
51 for (n = 0; n < 20; n++) 52 for (n = 0; n < 20; n++)
52 if ((is_hunt_buf[offset + n*16] & 1) != hdr_pattern[n]) 53 if ((is_hunt_buf[offset + n*16] & 1) != hdr_pattern[n])
53 break; 54 break;
54 if (n == 20) 55 if (n == 20)
55 break; 56 break;
56 } 57 }
57 if (n == 20) 58 if (n != 20)
58 printf("Found IS_Header, last bit offset %u\n", 59 return;
59 input_pos * 16 + offset); 60 printf("Found IS_Header, last bit offset %u\n",
61 input_pos * 16 + offset);
62 is_offset = offset;
63 is_state = 1;
64 is_bit_count = 0;
65 is_rx_word = 0;
66 }
67
68 static void
69 is_process_cmd()
70 {
71 int cont;
72
73 printf("IS_Command: 0x%03X", is_rx_word);
74 switch (is_rx_word) {
75 case 0x05D:
76 printf(" (REQ)\n");
77 cont = 1;
78 break;
79 case 0x0BA:
80 printf(" (ACK)\n");
81 cont = 1;
82 break;
83 case 0x0E7:
84 printf(" (IPE)\n");
85 cont = 1;
86 break;
87 case 0x129:
88 printf(" (FILL)\n");
89 cont = 0;
90 break;
91 case 0x174:
92 printf(" (DUP)\n");
93 cont = 0;
94 break;
95 case 0x193:
96 printf(" (SYL)\n");
97 cont = 0;
98 break;
99 default:
100 printf(" (bad)\n");
101 cont = 0;
102 }
103 if (cont) {
104 is_state = 2;
105 is_bit_count = 0;
106 is_rx_word = 0;
107 } else
108 is_state = 0;
109 }
110
111 static void
112 is_process_ext()
113 {
114 printf("IS_Extension: 0x%05X", is_rx_word);
115 if (is_rx_word & 0x80200) {
116 printf(" (bad sync)\n");
117 is_state = 0;
118 return;
119 }
120 switch (is_rx_word & 3) {
121 case 0:
122 printf(" (final)\n");
123 is_state = 0;
124 return;
125 case 3:
126 printf(" (continue)\n");
127 is_state = 2;
128 is_bit_count = 0;
129 is_rx_word = 0;
130 return;
131 default:
132 printf(" (bad EX)\n");
133 is_state = 0;
134 }
135 }
136
137 static void
138 is_rx_process(input, input_pos)
139 uint8_t *input;
140 unsigned input_pos;
141 {
142 unsigned new_bit;
143
144 memmove(is_hunt_buf, is_hunt_buf + 16, 304);
145 memcpy(is_hunt_buf + 304, input, 16);
146 if (!is_state) {
147 is_rx_hunt(input_pos);
148 return;
149 }
150 new_bit = input[is_offset] & 1;
151 is_rx_word <<= 1;
152 is_rx_word |= new_bit;
153 is_bit_count++;
154 if (is_state == 1 && is_bit_count == 10)
155 is_process_cmd();
156 else if (is_state == 2 && is_bit_count == 20)
157 is_process_ext();
60 } 158 }
61 159
62 void 160 void
63 obtain_rtp_endp() 161 obtain_rtp_endp()
64 { 162 {
150 printf("Rx RTP stream begins with seq=%u ts=%u\n", 248 printf("Rx RTP stream begins with seq=%u ts=%u\n",
151 rtp_last_seq, rtp_last_ts); 249 rtp_last_seq, rtp_last_ts);
152 rtp_start_flag = 1; 250 rtp_start_flag = 1;
153 } 251 }
154 for (is_chunk = 0; is_chunk < 10; is_chunk++) 252 for (is_chunk = 0; is_chunk < 10; is_chunk++)
155 is_hunt_proc(pkt.payload + is_chunk * 16, is_chunk); 253 is_rx_process(pkt.payload + is_chunk * 16, is_chunk);
156 } 254 }
157 255
158 void 256 void
159 rtcp_rx_select() 257 rtcp_rx_select()
160 { 258 {