From 8468314d2a801bdc1d6935cfb20691a866fa0f8d Mon Sep 17 00:00:00 2001
From: Grzegorz Sluja <grzegorz.sluja@iopsys.eu>
Date: Thu, 17 Nov 2022 13:46:40 +0000
Subject: [PATCH] Fix two issues found in flash_spec 'etsi' tests

- R0. If more than one account is registered, and there has another incoming call(ringing) to other accounts,
  it will be rejected as well when the ongoing one doing R0. (A, B registered on DUT; A<=>C(ongoing call);
  D=>B(ringing); E=>A(ringing,cw); A press R0 then both D and E be rejected)
- 3-way conference back to 2-way call, then performing R1 will lead to a crash
---
 channels/chan_brcm.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c
index 3caba49170..be8fa3fc19 100644
--- a/channels/chan_brcm.c
+++ b/channels/chan_brcm.c
@@ -673,6 +673,10 @@ static int brcm_indicate(struct ast_channel *ast, int condition, const void *dat
 						}
 					}
 				}
+				sub->conference_initiator = 0;
+				free(sub->conference_id);
+				sub->conference_id = NULL;
+
 				res = 0;
 			}
 		}
@@ -2113,32 +2117,6 @@ void handle_dtmf_calling(struct brcm_subchannel *sub)
 	}
 }
 
-// Hangup ALL brcm lines currently ringing with busy casue.
-static int brcm_busy_all_ringers(void)
-{
-	struct brcm_pvt *pvt;
-	int i;
-
-	brcm_lock_pvts();
-	pvt = iflist;
-
-	while(pvt) {
-		for (i=0; i<NUM_SUBCHANNELS; i++) {
-			if (pvt->sub[i] && pvt->sub[i]->owner && pvt->sub[i]->channel_state == RINGING) {
-				ast_debug(4, "Hangup BUSY on %s\n", ast_channel_name(pvt->sub[i]->owner));
-				ast_queue_control(pvt->sub[i]->owner, AST_CONTROL_BUSY);
-				ast_queue_hangup_with_cause(pvt->sub[i]->owner, AST_CAUSE_USER_BUSY);
-			}
-		}
-
-		pvt = brcm_get_next_pvt(pvt);
-	}
-
-	brcm_unlock_pvts();
-
-	return 0;
-}
-
 static void handle_Rnumber_etsi(struct brcm_subchannel *sub, struct brcm_subchannel *sub_peer,
 		struct ast_channel *owner, struct ast_channel *peer_owner)
 {
@@ -2159,7 +2137,6 @@ static void handle_Rnumber_etsi(struct brcm_subchannel *sub, struct brcm_subchan
 				sub_peer->cw_timer_id = -1;
 
 				ast_queue_control(peer_owner, AST_CONTROL_BUSY);
-				brcm_busy_all_ringers();
 				ast_indicate(owner, AST_CONTROL_UNHOLD);
 			} else if (sub->channel_state == INCALL && sub_peer->channel_state == ONHOLD) {
 				ast_debug(2, "Hanging up call on hold\n");
-- 
GitLab