[Asterisk-code-review] res_fax: gateway sends T.38 request to both endpoints if V.21 detected (...asterisk[16])

Alexei Gradinari asteriskteam at digium.com
Wed May 29 17:55:17 CDT 2019


Alexei Gradinari has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11422


Change subject: res_fax: gateway sends T.38 request to both endpoints if V.21 detected
......................................................................

res_fax: gateway sends T.38 request to both endpoints if V.21 detected

According T.38 Gateway 'Use case 3'
https://wiki.asterisk.org/wiki/display/AST/T.38+Gateway
T.38 Gateway should send T.38 negotiation request to called endpoint
if FAX preamble (using V.21 detector) generated by called endpoint.
But it does not, because fax_gateway_detect_v21 constructs T.38
negotiation request, but forwards it only to other channel,
not to the channel on which FAX preamble is detected.

Some SIP endpoints could be improperly configured to rely on the other side
to initiate T.38 re-INVITEs.

With this patch the T.38 Gateway tries to negotiate with both sides
by sending T.38 negotiation request to both endpoints supported T.38.

Change-Id: I73bb24799bfe1a48adae9c034a2edbae54cc2a39
---
M res/res_fax.c
1 file changed, 29 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/22/11422/1

diff --git a/res/res_fax.c b/res/res_fax.c
index 7338507..42ad27d 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -2979,7 +2979,7 @@
 	if (!details) {
 		ast_log(LOG_ERROR, "no FAX session details found on chan %s for T.38 gateway session, odd\n", ast_channel_name(chan));
 		ast_framehook_detach(chan, gateway->framehook);
-		return f;
+		return NULL;
 	}
 
 	t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
@@ -2987,7 +2987,7 @@
 
 	if (!(fp = ast_frisolate(&control_frame))) {
 		ast_log(LOG_ERROR, "error generating T.38 request control frame on chan %s for T.38 gateway session\n", ast_channel_name(chan));
-		return f;
+		return NULL;
 	}
 
 	gateway->t38_state = T38_STATE_NEGOTIATING;
@@ -3016,17 +3016,40 @@
 
 	if (gateway->detected_v21) {
 		enum ast_t38_state state_other;
+		enum ast_t38_state state_active;
+		struct ast_frame *fp;
 
 		destroy_v21_sessions(gateway);
 
 		ast_channel_unlock(chan);
+		state_active = ast_channel_get_t38_state(active);
 		state_other = ast_channel_get_t38_state(other);
 		ast_channel_lock(chan);
-		if (state_other == T38_STATE_UNKNOWN) {
-			ast_debug(1, "detected v21 preamble from %s\n", ast_channel_name(active));
-			return fax_gateway_request_t38(gateway, chan, f);
+
+		ast_debug(1, "detected v21 preamble from %s\n", ast_channel_name(active));
+
+		if (state_active == T38_STATE_UNKNOWN || state_other == T38_STATE_UNKNOWN) {
+			if (!(fp = fax_gateway_request_t38(gateway, chan, f))) {
+				return f;
+			}
+			/* May be called endpoint is improperly configured to rely on the calling endpoint
+			 * to initiate T.38 re-INVITEs, send T.38 negotiation request to called endpoint */
+			if (state_active == T38_STATE_UNKNOWN) {
+				ast_debug(1, "sending T.38 negotiation request to %s\n", ast_channel_name(active));
+				if (active == chan) {
+					ast_channel_unlock(chan);
+				}
+				ast_write(active, fp);
+				if (active == chan) {
+					ast_channel_lock(chan);
+				}
+			}
+			if (state_other == T38_STATE_UNKNOWN) {
+				ast_debug(1, "sending T.38 negotiation request to %s\n", ast_channel_name(other));
+				return fp;
+			}
 		} else {
-			ast_debug(1, "detected v21 preamble on %s, but %s does not support T.38 for T.38 gateway session\n", ast_channel_name(active), ast_channel_name(other));
+			ast_debug(1, "neither %s nor %s support T.38 for T.38 gateway session\n", ast_channel_name(active), ast_channel_name(other));
 		}
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11422
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I73bb24799bfe1a48adae9c034a2edbae54cc2a39
Gerrit-Change-Number: 11422
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190529/12b7365b/attachment-0001.html>


More information about the asterisk-code-review mailing list