comparison mgw/mdcx.c @ 32:b3f74df7b808

beginning of themwi-mgw
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Jul 2022 22:51:44 -0800
parents
children 7dae2bae56a1
comparison
equal deleted inserted replaced
31:08d7794cdd0a 32:b3f74df7b808
1 /*
2 * In this module we implement our MDCX operation.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <syslog.h>
13 #include "../include/tmgw_ctrl.h"
14 #include "../include/tmgw_const.h"
15 #include "struct.h"
16
17 extern struct endpoint *find_ep_by_id();
18
19 mdcx_operation(ep, req, resp)
20 struct endpoint *ep;
21 struct tmgw_ctrl_req *req;
22 struct tmgw_ctrl_resp *resp;
23 {
24 if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
25 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
26 resp->res = TMGW_RESP_ERR_PROT;
27 return(-1);
28 }
29 bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
30 sizeof(struct sockaddr_in));
31 ep->gsm_payload_type = req->gsm_payload_type;
32 ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
33 }
34 if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
35 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
36 resp->res = TMGW_RESP_ERR_PROT;
37 return(-1);
38 }
39 bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
40 sizeof(struct sockaddr_in));
41 ep->pstn_payload_type = req->pstn_payload_type;
42 }
43 if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
44 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
45 ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
46 ep->rtp_pstn.remote_addr.sin_family != AF_INET) {
47 resp->res = TMGW_RESP_ERR_PROT;
48 return(-1);
49 }
50 ep->fwd_mode = req->fwd_mode;
51 }
52 return(0);
53 }
54
55 void
56 process_mdcx(conn, req, resp)
57 struct ctrl_conn *conn;
58 struct tmgw_ctrl_req *req;
59 struct tmgw_ctrl_resp *resp;
60 {
61 struct endpoint *ep;
62 int rc;
63
64 ep = find_ep_by_id(conn, req->ep_id);
65 if (!ep) {
66 resp->res = TMGW_RESP_ERR_PROT;
67 return;
68 }
69 rc = mdcx_operation(ep, req, resp);
70 if (rc == 0)
71 resp->res = TMGW_RESP_OK;
72 }