From 94ad6902f760c8d1b2163e1c6034966f8e59c22f Mon Sep 17 00:00:00 2001
From: Yalu Zhang <yalu.zhang@iopsys.eu>
Date: Fri, 7 Jun 2019 16:31:51 +0200
Subject: [PATCH] Re-fix Bug #705: Asterisk gives tone even if number is not
 configured

Remove voice_client.sip0.call_lines in the default config. So no voice lines
are bound to "Incoming Phone Lines" of any SIP accounts by default.

Reload FXS channel before chan_sip when voice configuration changes.
---
 voice-client/files/etc/config/voice_client |  1 -
 voice-client/files/etc/init.d/voice_client | 12 ++++++------
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/voice-client/files/etc/config/voice_client b/voice-client/files/etc/config/voice_client
index dc5816eee..d60de1e08 100644
--- a/voice-client/files/etc/config/voice_client
+++ b/voice-client/files/etc/config/voice_client
@@ -174,5 +174,4 @@ config sip_service_provider 'sip0'
 	option redial '*66'
 	option is_fax '0'
 	option transport 'udp'
-	option call_lines '0'
 
diff --git a/voice-client/files/etc/init.d/voice_client b/voice-client/files/etc/init.d/voice_client
index 6b3238a65..edcc0773a 100755
--- a/voice-client/files/etc/init.d/voice_client
+++ b/voice-client/files/etc/init.d/voice_client
@@ -259,7 +259,7 @@ read_lines()
 	local loffset=$(ubus -t 1 call voice.asterisk platform | jsonfilter -e @.lineoffset)
 	loffset=${loffset:-0}
 
-	config_get call_lines $1 call_lines "0"
+	config_get call_lines $1 call_lines
 
 	for line in $call_lines ; do
 
@@ -1844,7 +1844,6 @@ configure_tel()
 #
 configure_tel_line()
 {
-	echo "Configuring $CHANNELNAME line $1"
 	local extension
 	local sip_provider
 	local codecs
@@ -2240,16 +2239,17 @@ stop_service() {
 
 reload_service() {
 	start
-	#stop
-	# turn off voice led; asterisk will turn it on
-	# if there is a registered account
+	# turn off voice led; asterisk will turn it on if there is a registered account
 	ubus call led.voice1 set '{"state":"off"}'
 
+	# FXS channel module must be reloaded before sip module. Otherwise some attributes like
+	# line's registration state which is updated by SIP module through callback might be
+	# reset.
+	asterisk -rx "$(getChipVendor) reload"
 	asterisk -rx "config reload $ASTERISKDIR/sip.conf"
 	sleep 1
 	asterisk -rx "core reload"
 	asterisk -rx "dialplan reload"
-	asterisk -rx "$(getChipVendor) reload"
 }
 
 service_triggers() {
-- 
GitLab