diff sip-in/mncc_handle.c @ 128:5685412bd6aa

sip-in: pass DTMF start & stop to themwi-mgw
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2022 23:07:01 -0800
parents c1c94b7fc2e2
children 01fe81914bd6
line wrap: on
line diff
--- a/sip-in/mncc_handle.c	Sat Oct 01 20:31:15 2022 -0800
+++ b/sip-in/mncc_handle.c	Sat Oct 01 23:07:01 2022 -0800
@@ -39,6 +39,46 @@
 	call->overall_state = OVERALL_STATE_CONNECTED;
 }
 
+void
+mncc_dtmf_start_ok(call)
+	struct call *call;
+{
+	struct gsm_mncc msg;
+
+	bzero(&msg, sizeof(struct gsm_mncc));
+	msg.msg_type = MNCC_START_DTMF_RSP;
+	msg.callref = call->mncc_callref;
+	msg.fields |= MNCC_F_KEYPAD;
+	msg.keypad = call->dtmf_digit;
+	send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc));
+}
+
+void
+mncc_dtmf_start_err(call)
+	struct call *call;
+{
+	struct gsm_mncc msg;
+
+	bzero(&msg, sizeof(struct gsm_mncc));
+	msg.msg_type = MNCC_START_DTMF_REJ;
+	msg.callref = call->mncc_callref;
+	mncc_set_cause(&msg, GSM48_CAUSE_LOC_PRN_S_LU,
+			GSM48_CC_CAUSE_PROTO_ERR);
+	send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc));
+}
+
+void
+mncc_dtmf_stop_ok(call)
+	struct call *call;
+{
+	struct gsm_mncc msg;
+
+	bzero(&msg, sizeof(struct gsm_mncc));
+	msg.msg_type = MNCC_STOP_DTMF_RSP;
+	msg.callref = call->mncc_callref;
+	send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc));
+}
+
 static void
 handle_alerting(call, msg)
 	struct call *call;
@@ -122,6 +162,43 @@
 }
 
 static void
+handle_dtmf_start(call, msg)
+	struct call *call;
+	struct gsm_mncc *msg;
+{
+	if (!(msg->fields & MNCC_F_KEYPAD) ||
+	    !is_valid_dtmf_digit(msg->keypad)) {
+		msg->msg_type = MNCC_START_DTMF_REJ;
+		mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
+				GSM48_CC_CAUSE_INVAL_MAND_INF);
+		send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
+		return;
+	}
+	if (call->overall_state != OVERALL_STATE_CONNECTED ||
+	    call->mgw_state != MGW_STATE_COMPLETE) {
+		msg->msg_type = MNCC_START_DTMF_REJ;
+		mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
+				GSM48_CC_CAUSE_MSGTYPE_INCOMPAT);
+		send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
+		return;
+	}
+	call->dtmf_digit = msg->keypad;
+	tmgw_send_dtmf_start(call);
+}
+
+static void
+handle_dtmf_stop(call, msg)
+	struct call *call;
+	struct gsm_mncc *msg;
+{
+	if (call->overall_state == OVERALL_STATE_CONNECTED &&
+	    call->mgw_state == MGW_STATE_COMPLETE)
+		tmgw_send_dtmf_stop(call);
+	else
+		call->dtmf_pending_stop = 1;
+}
+
+static void
 handle_signaling_msg(msg, msglen)
 	struct gsm_mncc *msg;
 	unsigned msglen;
@@ -157,14 +234,10 @@
 		handle_final_release(call, msg);
 		return;
 	case MNCC_START_DTMF_IND:
-		msg->msg_type = MNCC_START_DTMF_REJ;
-		mncc_set_cause(msg, GSM48_CAUSE_LOC_PRN_S_LU,
-				GSM48_CC_CAUSE_SERV_OPT_UNIMPL);
-		send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
+		handle_dtmf_start(call, msg);
 		return;
 	case MNCC_STOP_DTMF_IND:
-		msg->msg_type = MNCC_STOP_DTMF_RSP;
-		send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
+		handle_dtmf_stop(call, msg);
 		return;
 	case MNCC_MODIFY_IND:
 		msg->msg_type = MNCC_MODIFY_REJ;