Skip to content

Instantly share code, notes, and snippets.

@Mason10198
Last active December 24, 2024 15:21
Show Gist options
  • Save Mason10198/89e9d7e6bbae8a321b45286c78c5783b to your computer and use it in GitHub Desktop.
Save Mason10198/89e9d7e6bbae8a321b45286c78c5783b to your computer and use it in GitHub Desktop.
ASL3 Autopatch & Reverse Autopatch

Giving Your ASL3 Node a Phone Number - Setting Up Autopatch and Reverse Autopatch using VoIP.ms

Author: N5LSN

Important

As of 8/24/24, ASL3 half-duplex (duplex=0,1) autopatch still has a few bugs to work out before it is fully functional. Incoming calls (reverse autopatch) work fine, but outgoing (autopatch) calls are unable to pass phone audio to the ASL3 node.

Important

Since you will be aquiring a new VOIP number, it is very likely that most carriers will auto-label calls from your autopatch as spam/fraud. Depending on the configuration of the carrier & receiving phone, the autopatch call may be routed straight to voicemail and hidden from the missed call history, and the receiving party may never even know you called. I am unsure how to remedy this other than reaching out to the carriers individually, explaining the legitimacy of your number, and requesting the removal of the spam/fraud label.

Introduction

This guide will walk you through setting up both Autopatch and Reverse Autopatch functionality on your ASL3 node (not HamVoIP) using VoIP.ms as the service provider. This allows your repeater to make and receive traditional phone calls. This is particularly useful for emergency contact of people outside of the repeater range or otherwise unable to directly use the repeater for communications. It also is great for allowing system administrators remote access to execute DTMF functions from any active phone line.

Steps

1. Create a VoIP.ms Account

  • Create a VoIP.ms account (use this link to get $10 added to your account balance!).
  • Create a Residential acount.
  • Add some funds to your account.

2. Order a DID Number

  • Go to DID Numbers > Order DID(s).
  • Choose your area
  • Choose from the list of available numbers

Important

Make sure you choose from a list of phone numbers, otherwise you will be placing a backorder which might take a while.

  • Scroll down and sleect the Per Minute (Inbound) rate plan
  • Choose the POP Server that is closest to you, and note the address (eg. dallas1.voip.com)
  • In Routing Settings, under Main, make sure SIP/IAX is slected, and your main account is selected in the dropdown.
  • Click Order DID and confirm your purchase.

3. Setup e911

Important

Since this is a VoIP service, 911 calls WILL NOT ROUTE unless e911 is activated. You MUST complete e911 activation to enable outgoing 911 calls from the node.

  • Go to DID Numbers > e911
  • Next to your DID Number, click Activate.
  • Enter the information that should be used to route outgoing 911 calls from your node to a local dispatch center.
  • Change/Validate the information if prompted.
  • Click Yes to update the e911 caller ID to your DID number.

4. Configure Your Account Settings

  • Go to Main Menu > Account Settings.
  • Under the Account Restrictions tab, I suggest setting Max. Call Time to 5 or 10 minutes.
  • Click Apply.
  • Under the General tab, select Use one of my DIDs and select the DID your purchased in the dropdown.
  • Under the Inbound Settings tab, set the protocol to IAX2 and the device type to IP PBX.
  • Under the Security tab, in the Main SIP/IAX Password section, click Set Random password and Send Email.
  • Check your email for the generated password.
  • Either note this password, or use it to change the password to a custom one.
  • Apply the changes.

5. Manage Your DID Number

  • Go to DID Numbers > Manage DID(s).
  • Click the Edit button on your DID.
  • In Routing Settings, ensure that Main is set to SIP/IAX and Main Account is selected in the dropdown.
  • Make sure DID Point of Presence is set to the server closest to you.
  • Apply the changes.

Tip

Optionally, you can click the Contact Card icon next to your DID on the Manage DIDs page to update the CNAM information on your DID. This is the caller ID that pops up on capable phones that do not have the number saved in their contact list.

6. Note Your SIP/IAX Main Username

  • Go to Main Menu > Home and take note of the SIP/IAX main username.

7. Configure the Asterisk Server

7.1 Edit iax.conf

Add the following lines to /etc/asterisk/iax.conf under the [general] stanza:

; ENTER YOUR VOIP.MS CREDENTIALS AND SERVER HERE
register => VOIPMS_ID:VOIPMS_PASSWORD@VOIPMS_HOST
; Example: register => 123456:supersecretpassword@dallas1.voip.ms

Add this new stanza to iax.conf:

[voipms]
username=VOIPMS_ID; ENTER YOUR 6-DIGIT VOIP.MS USERNAME HERE
type=friend
context=reverse-autopatch
host=VOIPMS_HOST; ENTER THE VOIP.MS SERVER ADDRESS YOU SELECTED FOR YOUR DID HERE
secret=VOIPMS_PASSWORD; ENTER YOUR VOIP.MS IAX PASSWORD HERE
disallow=all
allow=ulaw
allow=g726aal2
allow=gsm
codecpriority=host
insecure=port,invite
requirecalltoken=yes

7.2 Edit extensions.conf

Important

Make sure you delete or comment out any existing stanzas that use the names [autopatch] or [reverse-autopatch]

Add these stanzas to your /etc/asterisk/extensions.conf:

; AUTOPATCH - REPEATER MAKES OUTGOING CALLS
[autopatch]
; Match any 11-digit number starting with '1' (e.g., North American long-distance format).
exten => _1NXXNXXXXXX,1,Dial(IAX2/voipms/${EXTEN})
; The Dial command routes the call through the IAX2 channel to the "voipms" trunk,
; passing the dialed number (${EXTEN}) to the provider.

; After the call is completed, hang up the line.
exten => _1NXXNXXXXXX,n,Hangup()

; Match any 10-digit number (e.g., North American local format).
exten => _NXXNXXXXXX,1,Dial(IAX2/voipms/${EXTEN})
; The Dial command routes the call through the IAX2 channel to the "voipms" trunk,
; passing the dialed number (${EXTEN}) to the provider.

; After the call is completed, hang up the line.
exten => _NXXNXXXXXX,n,Hangup()

; Match 911
exten => 911,1,Dial(IAX2/voipms/${EXTEN})
; The Dial command routes the call through the IAX2 channel to the "voipms" trunk,
; passing the dialed number (${EXTEN}) to the provider.

; After the call is completed, hang up the line.
exten => 911,n,Hangup()

; Optional: Reroute 911 to another number
; Uncomment the following lines to enable this feature:
; Instead of routing 911 directly, reroute it to the specified number (e.g., 1234567890).
; This could be used to route emergency calls to a different service or internal security.
; exten => 911,1,Dial(IAX2/voipms/1234567890)
; After the rerouted call is completed, hang up the line.
; exten => 911,n,Hangup()

; REVERSE-AUTOPATCH - REPEATER RECEIVES INCOMING CALLS
[reverse-autopatch]
; Answer the incoming call.
exten => _X.,1,Answer()

; Wait for 1 second to ensure the line is stable before playing the prompt.
exten => _X.,n,Wait(1)

; Optional: Bypass PIN for trusted caller
; Uncomment the below line to enable this feature:
; If the incoming call is from a trusted number (5551234567 or 5559876543 in this example),
; skip the PIN code and go directly to the "connect" label.
; exten => _X.,n,GotoIf($["${CALLERID(num)}" = "5551234567"]?connect,1)
; Example of how to "trust" two (or more) phone numbers
; exten => _X.,n,GotoIf($["${CALLERID(num)}" = "5551234567" | "${CALLERID(num)}" = "5559876543"]?connect,1)

; Initialize an attempt counter
exten => _X.,n,Set(ATTEMPTS=0)

; Play a message that asks the caller to enter their PIN followed by the pound/hash key.
; "confbridge-pin" says: "Please enter your personal identification number followed by the pound, or hash key."
exten => _X.,n(start),Playback(confbridge-pin)

; Wait for the caller to enter a 4-digit PIN.
; - "PIN" is the variable where the entered digits will be stored.
; - "beep" will play a beep sound to prompt the user.
; - "4" specifies the PIN length (4 digits).
; - ",,5" sets a 5-second timeout for the user to start entering the PIN.
exten => _X.,n,Read(PIN,beep,4,,,5)

; SET YOUR PIN(s) HERE! THESE PIN(s) WILL BE USED TO PATCH INTO THE REPEATER
; Check if the entered PIN is one of the valid PINs.
; - If the PIN is correct, the call will go to the label "wait-for-pound".
; - If not, it will continue to the next step.
exten => _X.,n,GotoIf($["${PIN}" = "1234"]?wait-for-pound)
; Example of how to set up two (or more) PINs:
; exten => _X.,n,GotoIf($["${PIN}" = "1234" | "${PIN}" = "5678"]?wait-for-pound)

; Increment the attempt counter
exten => _X.,n,Set(ATTEMPTS=$[${ATTEMPTS}+1])

; If the PIN is invalid, play a message saying it was incorrect.
; "confbridge-invalid" says: "You have entered an invalid option."
exten => _X.,n,Playback(confbridge-invalid)

; Check if the attempt counter has reached 3
exten => _X.,n,GotoIf($[${ATTEMPTS} >= 3]?too-many-failures)

; Go back to the start and ask the user to enter the PIN again.
; This gives the user another chance to enter a valid PIN.
exten => _X.,n,Goto(start)

; If the user fails to enter a valid PIN after 3 attempts, play a message saying they have entered too many invalid PINs.
; "confbridge-pin-bad" says: "You have entered too many invalid personal identification numbers."
exten => _X.,n(too-many-failures),Playback(confbridge-pin-bad)

; Hang up the call after the failure message.
exten => _X.,n,Hangup()

; After the valid PIN is entered, wait for the user to press the "#" key.
; - This command waits for the user to press "#" to confirm the PIN entry.
; - The 5-second timeout will give the user time to press "#".
exten => _X.,n(wait-for-pound),WaitExten(5)

; If the user presses "#", go to the "connect" label.
exten => #,1,Goto(connect,1)

; If "#" is not pressed, go to the start label.
exten => _X.,99,Goto(start)

; If the correct PIN was entered and "#" was pressed, play a message confirming the connection.
; "rpt/connected" could say something like: "You are now connected."
exten => connect,1,Playback(rpt/connected)

; Connect the caller to the repeater using the "rpt" command.
; The "|P" option is used to specify "phone" mode in app_rpt.
exten => connect,n,rpt(${NODE}|P)

; Hang up the call after the connection is made.
exten => connect,n,Hangup()

Warning

Now is a good time to go back through all of your copy/pasting and make sure you made all of the required customizations! This includes usernames, passwords, server URLs and PIN codes!

8. Final Configuration Steps

8.1 Update modules.conf

Make sure that you have this line in your /etc/asterisk/modules.conf, you might have to add it:

load => bridge_simple.so

Also make sure that app_read is set to load in /etc/asterisk/modules.conf:

load => app_read.so

8.2 Create a Script to Handle Terminating Calls

Create the following script to handle terminating calls. Without this script, you will be unable to forcefully terminate incoming calls:

nano /var/lib/asterisk/hangupPhones

Paste this script into the file:

#!/bin/bash
# Target pattern to match (adjust as needed for different calls)
TARGET_PATTERN="IAX2/voipms-"
# Get the list of channels and their concise details
CHANNELS=$(asterisk -rx "core show channels concise")
echo "Checking for matching channels..."
echo "--------------------------------"
# Iterate over each line to find the target channel
while IFS= read -r line; do
    if [[ $line == $TARGET_PATTERN* ]]; then
        CHANNEL=$(echo "$line" | awk -F'!' '{print $1}')
        CALLERID=$(echo "$line" | awk -F'!' '{print $3}')
        echo "Found matching channel: $CHANNEL with Caller ID: $CALLERID"
        echo "Hanging up channel: $CHANNEL"
        asterisk -rx "channel request hangup $CHANNEL"
    fi
done <<< "$CHANNELS"

Make it executable:

chmod +x /var/lib/asterisk/hangupPhones

8.3 Update rpt.conf

In /etc/asterisk/rpt.conf, in the stanza for the node number that you are enabling autopatch on, set this:

context = autopatch

Make sure you have this in your [functions] stanza:

;;;;; Autopatch Commands ;;;;;
6 = autopatchup,noct=1,farenddisconnect=1,dialtime=2000,context=autopatch,quiet=1 ; Phone autopatch
0 = cmd,/var/lib/asterisk/hangupPhones                                            ; Hangup All phone patches
; OPTIONS FOR AUTOPATCHUP COMMAND
; context            - Override the context specified for the autopatch in rpt.conf
; dialtime           - The maximum time to wait between DTMF digits when a telephone number is being dialed. The patch will automatically disconnect if this time is exceeded. The value is specified in milliseconds.
; farenddisconnect   - When set to 1, the patch will automatically disconnect when the called party hangs up. The default is to send a circuit busy tone until the radio user brings the patch down.
; noct               - When this is set to 1, the courtesy tone during an autopatch call will be disabled. The default is to send the courtesy tone whenever the radio user unkeys.
; quiet              - When set to 1, do not send dial tone, voice responses, just try to connect the call.
; voxalways          - When set to 1, enables vox mode.
; exten              - Overrides the default autopatch extension.
; nostar             - Disables the repeater function prefix.

Conclusion

Warning

Don't forget to restart Asterisk!

You can now make and receive calls through your repeater, linking it to a traditional phone system for added functionality and convenience.

@eliggett
Copy link

Are you using the voipms IVR to handle the access code? You can also handle it within asterisk pretty easily if you want to. This has some added flexibility in case you wanted to dial other nodes or even SIP extensions you might have locally.

[call_in_menu]
exten => s,1,Verbose(1, Caller ${CALLERID(all)} has entered IVR menu)
exten => s,n,Answer()
exten => s,n,Wait(1)
exten => s,n,Playback(hello)
;exten => s,n,SayAlpha(${CALLERID(all)})
exten => s,n,Wait(1)
exten => s,n(loop),Background(press-1&T-to-reach-main-office&press-2&for&ceo-office)
exten => s,n,WaitExten()
; Now here you can set up some extensions if you wish. For example:
exten => 1,1,Playback(transfer)
exten => 1,n,Dial(SIP/101&SIP/102,60,r)
exten => 1,n,Playback(goodbye)
exten => 1,n,Wait(1)
exten => 1,n,Hangup()
; But the cool extension is here, extension 9 in my case is the repeater's reverse-autopatch:
exten => 9,1,Playback(transfer)
exten => 9,n,Goto(repeater_password,s,1)
exten => 9,n,Hangup()

[repeater_password]
exten => s,1,Verbose(1, Prompting for password)
exten => s,n(loop),Background(enter-password)
exten => s,n,WaitExten()

exten => 41751,1,Playback(transfer)
exten => 41751,n,Verbose(1, Password accepted for repeater access)
exten => 41751,n,rpt(41751|Pv)
exten => 41751,n,Hangup()

exten => i,1,Playback(carried-away-by-monkeys)
exten => i,n,Hangup()

exten => t,1,Hangup()

In this example, the node number was chosen for the password, but any number can be set.

@Mason10198
Copy link
Author

Yes, I am using the voip.ms IVR, since it seemed easy and I'm not very experienced with dialplans. Thanks for the info and example!

@jxmx
Copy link

jxmx commented Aug 25, 2024

when you are happy with this, can you open it as a pull request against AllStarLink/ASL3-Manual?

@Mason10198
Copy link
Author

when you are happy with this, can you open it as a pull request against AllStarLink/ASL3-Manual?

Certainly! I'm actually re-writing it right now.

@trebor57
Copy link

trebor57 commented Sep 5, 2024

Mason, great work.

Maybe I missed it, can this have the ability to say Autopatch Connected and Autopatch Disconnected?

Anything else changed? I see a couple of weeks ago you were re-writing this, or has it already been updated?

73

Rob - K6IRK

@coolpro313
Copy link

just a suggestion you should make a edit in the file after the order DID part to go into the account settings general and set caller ID to use your DID i had learned that the hard way where i did not set that kept getting the everyone is busy/congested error in the CLI all because in the account it's set to basically use a capable device to send the set caller ID to them and they repeat it to whoever you are calling instead of just outright 1 way use your DID caller ID i litterly contacted technical support and they had to look in my account and told me that's not set so i set it and now i can make calls with no error so you should make a edit and add that so that way no one else had to go through what i just went through

@Mason10198
Copy link
Author

just a suggestion you should make a edit in the file after the order DID part to go into the account settings general and set caller ID to use your DID i had learned that the hard way where i did not set that kept getting the everyone is busy/congested error in the CLI all because in the account it's set to basically use a capable device to send the set caller ID to them and they repeat it to whoever you are calling instead of just outright 1 way use your DID caller ID i litterly contacted technical support and they had to look in my account and told me that's not set so i set it and now i can make calls with no error so you should make a edit and add that so that way no one else had to go through what i just went through

It already says to do this in step #4, bullet #4 of the guide...

@jxmx
Copy link

jxmx commented Sep 14, 2024

Someone will let me know when this is ready for ASL3-Manual?

@kx4leo
Copy link

kx4leo commented Oct 17, 2024

I am using Hamvoip on my PI. I use it as the controller for my repeater. It works great. My AllStar node number is 577320. Although I am using Hamvoip and not AL3, I found the instructions in this forum to successfully get the outbound call from my HT. The *6 followed by the 10-digit phone number works perfrectly, as does the *0 to disconnect.

I have two questions.... the first is I need to know how to require my repeater users to enter a 4-digit PIN to access the autopatch feature.

The second question is perhaps for complicated. In reading the commented lines in the .conf file, it is my understanding that a phone user can dial my VOIP.ms DID number and utlimately connect to the repeater's PI. I am not sure how the voip.ms system knows how to send the call to my node number. Also, where do the voice prompts come from that are mentioned in the commented lines?

Mark Newby, KX4LEO
Emergency Coordinator
Sumter County ARES

@knobby4444
Copy link

@Mason10198 I can merge this with the ASL3 manual page and add my info for setting up flowroute SIP. If you are good with that please let me know if you have any additional updates you want me to work with. I can put something together for you to look at or if you want to be involved in the process that works great too.

@fpcaptain
Copy link

I have this working for outgoing calls (using Hamvoip), but I am getting a busy signal when I call the phone number (for reverse autopatch). Any idea what might be causing this?

@kx4leo
Copy link

kx4leo commented Dec 16, 2024 via email

@Mason10198
Copy link
Author

Mason10198 commented Dec 16, 2024

The instructions above already show you how to set up inbound (reverse autopatch) calls from the VoIP.ms side. There is no need for any sub-accounts or anything like that. Any troubles you are having are more than likely on your end (at the node). Cannot say much else since this was written for ASL3 and I do not support/endorse/recommend/use hamvoip.

@Mason10198
Copy link
Author

I don't keep up with the comments here. I don't have time to. I wrote the guide assuming it would be used by people who could work the details out on their own. The dialplan (extensions.conf) is the most confusing part, but all you have to do is read the comments to follow the logic and understand how it works in order to modify it for your needs.

I see a lot of comments with issues/questions that seems to all be from people using that old outdated hamvoip stuff... this was written for ASL3. Time for those hamvoip users to upgrade to modern software...

@jxmx
Copy link

jxmx commented Dec 16, 2024

Is this ready to pull into the ASL3 Manual and maybe close this gist @Mason10198 ?

@Mason10198
Copy link
Author

@jxmx I think so, myself and a lots of others have been using this with no issues. The ones having issues either have not configured it correctly or didn't read the part of the title that says "ASL3". The reverse-autopatch stanza could probably be perfected, but what I wrote was supposed to be something that works for everyone, while also being an introduction to advanced topics if customized functionality is desired.

@jxmx
Copy link

jxmx commented Dec 16, 2024

Would you see this completely replacing https://allstarlink.github.io/adv-topics/autopatch/ or be a companion document? I don't do Autopatch stuff so I have no orientation on this.

@fpcaptain
Copy link

Thanks. Haven't had a need to look at ASL3 so far, It works for the outgoing calls, so would think things should be similar. I had it setup another way, but after some time that didn't always work for outgoing calls, so thought I would give this a try. It could even be a setting with voip.ms for all I know. I'll see what else I can find. Thanks again and for the work you do. - KB3AWQ

@Mason10198
Copy link
Author

@jxmx Once added to the contib list I can branch the Manual and combine the old & new

@jxmx
Copy link

jxmx commented Dec 16, 2024

HamVOIP and ASL3 are similar only in that they're both using Asterisk. ASL3 has 15+ years of accumulated changes contained in the leap from Asterisk 1.4 -> Asterisk 20. A lot of stuff with extensions.conf and the templating is different and there's subtle nuances.

@jxmx
Copy link

jxmx commented Dec 16, 2024

@jxmx Once added to the contib list I can branch the Manual and combine the old & new

You should have access.

@knobby4444
Copy link

I have incorporated everything from here and have a pull request in the manual repo I need to fix.... Let me get to that and this should be included.

@knobby4444
Copy link

Neve rmind above, I misremembered. Currently working on bringing this and other info into the allstar docs. I think the voip phone number could be used as the connecting extension, instead of 'connect' in the dialplan. As it is here, when you list channels, the 'connect' shows up where I think one would typically see the phone number. @Mason10198 have you started work on combining the manuals yet?

@Mason10198
Copy link
Author

I think the voip phone number could be used as the connecting extension, instead of 'connect' in the dialplan. As it is here, when you list channels, the 'connect' shows up where I think one would typically see the phone number.

I'm not sure what you mean by this. If you're referring to the example contexts I provide for extensions.conf, there are so many possibilities of things you can do with the dialplan that they really are just examples of one way you could do it. Should work for anyone who doesn't know how / doesn't want to learn how to work and Asterisk dialplan though.

have you started work on combining the manuals yet?

I have not, since you said you already had it in a PR. I still can, though.

@knobby4444
Copy link

I will do the docs combining if you have not started yet, just wanted to make sure we weren't both doing the same thing.

@knobby4444
Copy link

And yes you are correct the way you have it setup works great. What I noticed is if I do a chow channels it looks like this, some channels removed from the list before posting below:
Channel Location State Application(Data)
PJSIP/flowroute-endpoint-00000000 connect@reverse-autopatch:2 Up Rpt(49520|Pv)
IAX2/192.168.10.31:4569-9573 49520@radio-secure:12 Up Rpt(49520)

I think the connect@reverse-autopatch should probably be the voip phone number of the patch, but I'm no expert. I did a find and replace on connect to my voip number and I think that might be better. But again, I agree with your statement that it makes no difference.

PJSIP/flowroute-endpoint-00000000 4322031499@reverse-autopatch:2 Up Rpt(49520|Pv)

@knobby4444
Copy link

The PR is in, my interpretation of this should be in the ASL3 documentation soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment