comparison sip-in/mncc_handle.c @ 63:e5aee661e3b2

sip-in: beginning to handle incoming MNCC messages from themwi-mncc
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Sep 2022 15:01:11 -0800
parents
children 7c0309df59f8
comparison
equal deleted inserted replaced
62:75b7a7b61824 63:e5aee661e3b2
1 /*
2 * In this module we implement our handling of call control messages
3 * from OsmoMSC relayed to us via themwi-mncc.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <netinet/in.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include <syslog.h>
15 #include "../include/mncc.h"
16 #include "../include/gsm48_const.h"
17 #include "call.h"
18
19 extern struct call *find_call_by_mncc_callref();
20
21 static void
22 handle_alerting(call, msg)
23 struct call *call;
24 struct gsm_mncc *msg;
25 {
26 /* handling to be implemented */
27 }
28
29 static void
30 handle_answer(call, msg)
31 struct call *call;
32 struct gsm_mncc *msg;
33 {
34 /* handling to be implemented */
35 }
36
37 static void
38 handle_disconnect_ind(call, msg)
39 struct call *call;
40 struct gsm_mncc *msg;
41 {
42 /* handling to be implemented */
43 }
44
45 static void
46 handle_final_release(call, msg)
47 struct call *call;
48 struct gsm_mncc *msg;
49 {
50 /* handling to be implemented */
51 }
52
53 static void
54 handle_signaling_msg(msg, msglen)
55 struct gsm_mncc *msg;
56 unsigned msglen;
57 {
58 struct call *call;
59
60 if (msglen != sizeof(struct gsm_mncc)) {
61 syslog(LOG_CRIT,
62 "FATAL: Rx MNCC message type 0x%x has wrong length",
63 msg->msg_type);
64 exit(1);
65 }
66 call = find_call_by_mncc_callref(msg->callref);
67 if (!call) {
68 syslog(LOG_CRIT,
69 "error: Rx MNCC message type 0x%x has invalid callref 0x%x",
70 msg->msg_type, msg->callref);
71 exit(1);
72 }
73 switch (msg->msg_type) {
74 case MNCC_SETUP_CNF:
75 handle_answer(call, msg);
76 return;
77 case MNCC_ALERT_IND:
78 handle_alerting(call, msg);
79 return;
80 case MNCC_DISC_IND:
81 handle_disconnect_ind(call, msg);
82 return;
83 case MNCC_REL_IND:
84 case MNCC_REL_CNF:
85 case MNCC_REJ_IND:
86 handle_final_release(call, msg);
87 return;
88 case MNCC_START_DTMF_IND:
89 msg->msg_type = MNCC_START_DTMF_REJ;
90 mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
91 GSM48_CC_CAUSE_SERV_OPT_UNIMPL);
92 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
93 return;
94 case MNCC_STOP_DTMF_IND:
95 msg->msg_type = MNCC_STOP_DTMF_RSP;
96 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
97 return;
98 case MNCC_MODIFY_IND:
99 msg->msg_type = MNCC_MODIFY_REJ;
100 mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
101 GSM48_CC_CAUSE_SERV_OPT_UNIMPL);
102 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
103 return;
104 case MNCC_HOLD_IND:
105 msg->msg_type = MNCC_HOLD_REJ;
106 mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
107 GSM48_CC_CAUSE_SERV_OPT_UNIMPL);
108 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
109 return;
110 case MNCC_RETRIEVE_IND:
111 msg->msg_type = MNCC_RETRIEVE_REJ;
112 mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
113 GSM48_CC_CAUSE_SERV_OPT_UNIMPL);
114 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
115 return;
116 }
117 }
118
119 static void
120 handle_rtp_create(msg, msglen)
121 struct gsm_mncc_rtp *msg;
122 unsigned msglen;
123 {
124 struct call *call;
125
126 if (msglen != sizeof(struct gsm_mncc_rtp)) {
127 syslog(LOG_CRIT,
128 "FATAL: Rx MNCC message type 0x%x has wrong length",
129 msg->msg_type);
130 exit(1);
131 }
132 call = find_call_by_mncc_callref(msg->callref);
133 if (!call) {
134 syslog(LOG_CRIT,
135 "error: Rx MNCC message type 0x%x has invalid callref 0x%x",
136 msg->msg_type, msg->callref);
137 exit(1);
138 }
139 /* handling to be implemented */
140 }
141
142 void
143 msg_from_mncc(msg, msglen)
144 union mncc_msg *msg;
145 unsigned msglen;
146 {
147 switch (msg->msg_type) {
148 case MNCC_SETUP_CNF:
149 case MNCC_CALL_CONF_IND:
150 case MNCC_ALERT_IND:
151 case MNCC_NOTIFY_IND:
152 case MNCC_DISC_IND:
153 case MNCC_FACILITY_IND:
154 case MNCC_START_DTMF_IND:
155 case MNCC_STOP_DTMF_IND:
156 case MNCC_MODIFY_IND:
157 case MNCC_HOLD_IND:
158 case MNCC_RETRIEVE_IND:
159 case MNCC_USERINFO_IND:
160 case MNCC_REL_IND:
161 case MNCC_REL_CNF:
162 case MNCC_REJ_IND:
163 handle_signaling_msg(msg, msglen);
164 return;
165 case MNCC_RTP_CREATE:
166 handle_rtp_create(msg, msglen);
167 return;
168 default:
169 syslog(LOG_CRIT,
170 "FATAL: received unexpected MNCC message type 0x%x",
171 msg->msg_type);
172 exit(1);
173 }
174 }