comparison mtctest/dummy_rtp.c @ 36:e8e82a4bf12b

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