FreeCalypso > hg > themwi-system-sw
comparison mtctest/sig_handler.c @ 159:c8e9b295e88f
mtctest: add time reporting for DTMF events
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Oct 2022 12:11:06 -0800 |
parents | c731ec342ba0 |
children | 55ad0f4bb33c |
comparison
equal
deleted
inserted
replaced
158:51cf5ea7f320 | 159:c8e9b295e88f |
---|---|
3 * printing all of them and generating protocol-required responses | 3 * printing all of them and generating protocol-required responses |
4 * for some. | 4 * for some. |
5 */ | 5 */ |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/time.h> | |
8 #include <sys/socket.h> | 9 #include <sys/socket.h> |
9 #include <stdio.h> | 10 #include <stdio.h> |
10 #include <stdint.h> | 11 #include <stdint.h> |
11 #include <stdlib.h> | 12 #include <stdlib.h> |
12 #include <string.h> | 13 #include <string.h> |
14 #include "../include/mncc.h" | 15 #include "../include/mncc.h" |
15 #include "../include/gsm48_const.h" | 16 #include "../include/gsm48_const.h" |
16 | 17 |
17 extern int disconnect_mode; | 18 extern int disconnect_mode; |
18 extern struct sockaddr_storage dummy_rtp_endp; | 19 extern struct sockaddr_storage dummy_rtp_endp; |
20 extern struct timeval cur_event_time; | |
19 | 21 |
20 static void | 22 static void |
21 print_bearer_cap(bcap) | 23 print_bearer_cap(bcap) |
22 struct gsm_mncc_bearer_cap *bcap; | 24 struct gsm_mncc_bearer_cap *bcap; |
23 { | 25 { |
178 bcopy(&dummy_rtp_endp, &rtp.addr, sizeof(struct sockaddr_storage)); | 180 bcopy(&dummy_rtp_endp, &rtp.addr, sizeof(struct sockaddr_storage)); |
179 send_mncc_to_gsm(&rtp, sizeof(struct gsm_mncc_rtp)); | 181 send_mncc_to_gsm(&rtp, sizeof(struct gsm_mncc_rtp)); |
180 } | 182 } |
181 | 183 |
182 static void | 184 static void |
185 handle_dtmf_time() | |
186 { | |
187 static struct timeval last_dtmf_time; | |
188 struct timeval delta; | |
189 unsigned ms; | |
190 | |
191 if (timerisset(&last_dtmf_time) && | |
192 timercmp(&cur_event_time, &last_dtmf_time, >)) { | |
193 timersub(&cur_event_time, &last_dtmf_time, &delta); | |
194 if (delta.tv_sec >= 2) | |
195 printf("Time since last DTMF event: %u s\n", | |
196 (unsigned) delta.tv_sec); | |
197 else { | |
198 ms = delta.tv_sec * 1000 + delta.tv_usec / 1000; | |
199 printf("Time since last DTMF event: %u ms\n", ms); | |
200 } | |
201 } | |
202 bcopy(&cur_event_time, &last_dtmf_time, sizeof(struct timeval)); | |
203 } | |
204 | |
205 static void | |
183 handle_signaling_msg(msg, msglen) | 206 handle_signaling_msg(msg, msglen) |
184 struct gsm_mncc *msg; | 207 struct gsm_mncc *msg; |
185 unsigned msglen; | 208 unsigned msglen; |
186 { | 209 { |
187 if (msglen != sizeof(struct gsm_mncc)) { | 210 if (msglen != sizeof(struct gsm_mncc)) { |
228 print_fields(msg); | 251 print_fields(msg); |
229 return; | 252 return; |
230 case MNCC_START_DTMF_IND: | 253 case MNCC_START_DTMF_IND: |
231 printf("MNCC_START_DTMF_IND: MS sending DTMF start\n"); | 254 printf("MNCC_START_DTMF_IND: MS sending DTMF start\n"); |
232 print_fields(msg); | 255 print_fields(msg); |
256 handle_dtmf_time(); | |
233 if (msg->fields & MNCC_F_KEYPAD && | 257 if (msg->fields & MNCC_F_KEYPAD && |
234 is_valid_dtmf_digit(msg->keypad)) { | 258 is_valid_dtmf_digit(msg->keypad)) { |
235 printf("Responding with ACK\n"); | 259 printf("Responding with ACK\n"); |
236 msg->msg_type = MNCC_START_DTMF_RSP; | 260 msg->msg_type = MNCC_START_DTMF_RSP; |
237 } else { | 261 } else { |
242 } | 266 } |
243 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc)); | 267 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc)); |
244 return; | 268 return; |
245 case MNCC_STOP_DTMF_IND: | 269 case MNCC_STOP_DTMF_IND: |
246 printf("MNCC_STOP_DTMF_IND: MS sending DTMF stop\n"); | 270 printf("MNCC_STOP_DTMF_IND: MS sending DTMF stop\n"); |
271 handle_dtmf_time(); | |
247 msg->msg_type = MNCC_STOP_DTMF_RSP; | 272 msg->msg_type = MNCC_STOP_DTMF_RSP; |
248 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc)); | 273 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc)); |
249 return; | 274 return; |
250 case MNCC_MODIFY_IND: | 275 case MNCC_MODIFY_IND: |
251 printf("MNCC_MODIFY_IND: MS requests call modification\n"); | 276 printf("MNCC_MODIFY_IND: MS requests call modification\n"); |