diff sip-in/invite.c @ 108:0d6435808bcd

sip-in: implement 100rel for 180 Ringing response
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 14:29:10 -0800
parents 372209628038
children 9b87894704eb
line wrap: on
line diff
--- a/sip-in/invite.c	Tue Sep 27 23:45:40 2022 -0800
+++ b/sip-in/invite.c	Wed Sep 28 14:29:10 2022 -0800
@@ -347,12 +347,19 @@
 		sip_tx_packet(&resp, sin);
 		return;
 	case SIP_STATE_RINGING:
-	case SIP_STATE_RINGING_PRACK:
 		start_response_out_msg(&resp, "180 Ringing");
 		fill_invite_resp_from_call(&resp, call);
 		out_msg_finish(&resp);
 		sip_tx_packet(&resp, sin);
 		return;
+	case SIP_STATE_RINGING_REL:
+		start_response_out_msg(&resp, "180 Ringing");
+		fill_invite_resp_from_call(&resp, call);
+		out_msg_add_header(&resp, "Require", "100rel");
+		out_msg_add_header(&resp, "RSeq", "1");
+		out_msg_finish(&resp);
+		sip_tx_packet(&resp, sin);
+		return;
 	case SIP_STATE_INVITE_200:
 	case SIP_STATE_CONNECTED:
 		fill_invite_200_resp(&resp, call);
@@ -390,12 +397,35 @@
 	struct call *call;
 {
 	struct sip_msg_out resp;
+	int rc;
 
 	start_response_out_msg(&resp, "180 Ringing");
-	fill_invite_resp_from_call(&resp, call);
+	rc = fill_invite_resp_from_call(&resp, call);
+	if (rc < 0) {
+msg_size_err:	syslog(LOG_ERR, "INVITE 180 response length exceeded");
+		call->sip_state = SIP_STATE_MSG_SIZE_ERR;
+		call->overall_state = OVERALL_STATE_TEARDOWN;
+		disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
+				GSM48_CC_CAUSE_INTERWORKING);
+		disconnect_tmgw(call);
+		/* TODO: transition from TEARDOWN to DEAD_SIP */
+		return;
+	}
+	if (call->use_100rel) {
+		rc = out_msg_add_header(&resp, "Require", "100rel");
+		if (rc < 0)
+			goto msg_size_err;
+		rc = out_msg_add_header(&resp, "RSeq", "1");
+		if (rc < 0)
+			goto msg_size_err;
+	}
 	out_msg_finish(&resp);
 	sip_tx_packet(&resp, &call->udp_sin);
-	call->sip_state = SIP_STATE_RINGING;
+	if (call->use_100rel) {
+		call->sip_state = SIP_STATE_RINGING_REL;
+		call->sip_tx_count = 1;
+	} else
+		call->sip_state = SIP_STATE_RINGING;
 }
 
 void