FreeCalypso > hg > themwi-system-sw
annotate mtctest/dummy_rtp.c @ 118:a4450ae8fd09
sip-manual-out UAC: use the new CSeq parsing function
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 29 Sep 2022 13:03:27 -0800 |
parents | e8e82a4bf12b |
children |
rev | line source |
---|---|
36
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement the code that connects to themwi-mgw |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * and obtains a dummy GSM-side RTP endpoint. |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/un.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "../include/tmgw_ctrl.h" |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "../include/tmgw_const.h" |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 struct sockaddr_storage dummy_rtp_endp; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket"; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 obtain_dummy_rtp() |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 struct sockaddr_un sa; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned sa_len; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int fd, rc; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct tmgw_ctrl_req req; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 struct tmgw_ctrl_resp resp; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (fd < 0) { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)"); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(1); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 rc = connect(fd, (struct sockaddr *) &sa, sa_len); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (rc < 0) { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 perror(tmgw_socket_pathname); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 bzero(&req, sizeof req); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 req.opcode = TMGW_CTRL_OP_CRCX; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 req.ep_id = TMGW_EP_TYPE_DUMMY_GSM; |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 rc = send(fd, &req, sizeof req, 0); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 perror("send to TMGW socket"); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 exit(1); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 rc = recv(fd, &resp, sizeof resp, 0); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (rc < 0) { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 perror("recv from TMGW socket"); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (rc != sizeof resp) { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 "error: response packet from TMGW has wrong length (%d bytes)\n", |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 rc); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 exit(1); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (resp.res != TMGW_RESP_OK) { |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fprintf(stderr, "TMGW CRCX returned error %u\n", resp.res); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 bcopy(&resp.gsm_addr, &dummy_rtp_endp, sizeof(struct sockaddr_storage)); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return(0); |
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |