I was able to work with this when we were chan_sip but since moving to pjsip I am not sure the best way to accomplish this. I have DIDs that have e911 service for 2 locations and was able to use outbound routes to map the extension to dial 911 with the corresponding DID. Now that pjsip allows multiple extension registrations the only constant variable I can use is the static IP we have from our ISP. I saw this in the forum and am having trouble trying to adapt it for our usage to comply with e911. We have a combination of chan_sip and pjsip extensions but have a static IP for each location. How could I get the below to work so that eg. Static IP of 123.12.123.12 would use DID 1234567890 and Static IP of 123.12.123.13 would use DID 1234567891 when dialing 911.
[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp()
exten => s,n,GotoIf($[$["${CALLERID(dnid)}" = "911"] | $["${EMERGENCYROUTE}" = "YES"]]?s_CHANNLE_TYPE,1:s_exit,1)
exten => s_CHANNLE_TYPE,1,NoOp()
exten => s_CHANNLE_TYPE,n,GotoIF($["${CHANNEL(channeltype)}" = "PJSIP"]?s_PJSIP_IP,1)
exten => s_CHANNLE_TYPE,n,GotoIF($["${CHANNEL(channeltype)}" = "SIP"]?s_SIP_IP,1)
exten => s_CHANNLE_TYPE,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to get channel type. CID-IP Mapping not used.)
exten => s_CHANNLE_TYPE,n,Goto(s_exit,1)
exten => s_PJSIP_IP,1,NoOp()
exten => s_PJSIP_IP,n,Set(endpoint_addr=${CHANNEL(pjsip,remote_addr)})
exten => s_PJSIP_IP,n,Set(ip_addr=${CUT(endpoint_addr,:,1)})
exten => s_PJSIP_IP,n,GotoIF($ ["${ip_addr}" != ""]?s_CID_IP_MAP,1)
exten => s_PJSIP_IP,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to get endpoint ip from PJSIP channel. CID-IP Mapping not used.)
exten => s_PJSIP_IP,n,Goto(s_exit,1)
exten => s_SIP_IP,1,NoOp()
exten => s_SIP_IP,n,Set(ip_addr=${CHANNEL(sip,peerip)})
exten => s_SIP_IP,n,GotoIF($ ["${ip_addr}" != ""]?s_CID_IP_MAP,1)
exten => s_SIP_IP,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to get endpoint ip from SIP channel. CID-IP Mapping not used.)
exten => s_SIP_IP,n,Goto(s_exit,1)
exten => s_CID_IP_MAP,1,NoOp()
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.7\.[0-9])" ${ip_addr})}?s_SetCID,1(5551117777)) ;location1
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.8\.[0-9])" ${ip_addr})}?s_SetCID,1(5551118888)) ;location2
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.9\.[0-9])" ${ip_addr})}?s_SetCID,1(5551119999)) ;location3
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.0\.[0-9])" ${ip_addr})}?s_SetCID,1(5551110000)) ;location4
exten => s_CID_IP_MAP,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to find CID mapping for ${ip_addr} . CID-IP Mapping not used.)
exten => s_CID_IP_MAP,n,Goto(s_exit,1)
exten => s_SetCID,1,NoOp()
exten => s_SetCID,n,Set(CALLERID(num)=${ARG1})
exten => s_SetCID,n,Goto(s_exit,1)
exten => s_exit,1,NoOP()
exten => s_exit,n,MacroExit()