本文主要实现 OpenWRT 系统通过 Huawei 3G Modem 加 asterisk 套件将 GSM 通话转为 SIP 通话
安装 openwrt 下的 asterisk16 套件
opkg update opkg install asterisk16-app-system asterisk16-chan-dongle asterisk16-pjsip asterisk16-codec-ulaw asterisk16-codec-alaw asterisk16-res-rtp-asterisk asterisk16-bridge-simple 调整 PJSIP 作为默认服务,并且新增几个 PJSIP 账户,用以测试内线通
/etc/asterisk/pjsip.conf
[transport-udp] type=transport protocol=udp ;udp,tcp,tls,ws,wss bind=0.0.0.0 [6003] type=endpoint transport=transport-udp cOntext=from-internal disallow=all allow=ulaw auth=6003-auth aors=6003 [6003-auth] type=auth auth_type=userpass password=6003 username=6003 [6003] type=aor max_cOntacts=1 [6004] type=endpoint transport=transport-udp cOntext=from-internal disallow=all allow=ulaw auth=6004-auth aors=6004 [6004-auth] type=auth auth_type=userpass password=6004 username=6004 [6004] type=aor max_cOntacts=1 新增分机拨打模板,
/etc/asterisk/extension.conf
[from-internal] exten => _Z.,1,Dial(PJSIP/${EXTEN},60,Trg) same => n,Hangup() 用 asterisk 查看分机状态,拨打过程中pjsip show endpoints中显示的状态会从Not in use转换为In use
asterisk -rvvvv OpenWrt*CLI> pjsip show contacts Contact: <Aor/ContactUri..............................> <Hash....> <Status> <RTT(ms)..> ========================================================================================== Contact: 6001/sip:[email protected]:53117;transport= 378e2db08b NonQual nan Contact: 6001/sip:[email protected]:53117;transport= 378e2db08b NonQual nan Contact: 6003/sip:[email protected]:49989;transport= 2ec100f865 NonQual nan Contact: 6003/sip:[email protected]:49989;transport= 2ec100f865 NonQual nan Contact: 6004/sip:[email protected]:5060 586381001a NonQual nan Contact: 6004/sip:[email protected]:5060 586381001a NonQual nan Objects found: 6 -- PJSIP/6001-00000005 is ringing -- PJSIP/6001-00000005 is ringing > 0x2262b00 -- Strict RTP learning after remote address set to: 192.168.234.127:52518 -- PJSIP/6001-00000005 answered PJSIP/6004-00000004 > 0x2270c60 -- Strict RTP learning after remote address set to: 192.168.104.11:11866 -- Channel PJSIP/6001-00000005 joined 'simple_bridge' basic-bridge <ee120657-8627-4868-b677-cb0d896a2b5a> -- Channel PJSIP/6004-00000004 joined 'simple_bridge' basic-bridge <ee120657-8627-4868-b677-cb0d896a2b5a> > 0x2262b00 -- Strict RTP switching to RTP target address 192.168.234.127:52518 as source > 0x2270c60 -- Strict RTP switching to RTP target address 192.168.104.11:11866 as source OpenWrt*CLI> pjsip show endpoints Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.> I/OAuth: <AuthId/UserName...........................................................> Aor: <Aor...........................................> <MaxContact> Contact: <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..> Transport: <TransportId........> <Type> <cos> <tos> <BindAddress..................> Identify: <Identify/Endpoint.........................................................> Match: <criteria.........................> Channel: <ChannelId......................................> <State.....> <Time.....> Exten: <DialedExten...........> CLCID: <ConnectedLineCID.......> ========================================================================================== Endpoint: 6001 In use 1 of inf InAuth: 6001-auth/6001 Aor: 6001 1 Contact: 6001/sip:[email protected]:53117;transp 378e2db08b NonQual nan Transport: transport-udp udp 0 0 0.0.0.0:5060 Channel: PJSIP/6001-00000005/AppDial Up 00:00:04 Exten: CLCID: "6004" <6004> Endpoint: 6002 Unavailable 0 of inf InAuth: 6002-auth/6002 Aor: 6002 1 Transport: transport-udp udp 0 0 0.0.0.0:5060 Endpoint: 6003 Not in use 0 of inf InAuth: 6003-auth/6003 Aor: 6003 1 Contact: 6003/sip:[email protected]:49989;transp 2ec100f865 NonQual nan Transport: transport-udp udp 0 0 0.0.0.0:5060 Endpoint: 6004 In use 1 of inf InAuth: 6004-auth/6004 Aor: 6004 1 Contact: 6004/sip:[email protected]:5060 586381001a NonQual nan Transport: transport-udp udp 0 0 0.0.0.0:5060 Channel: PJSIP/6004-00000004/Dial Up 00:00:04 Exten: 6001 CLCID: "" <6001> Objects found: 4 > 0x2270c60 -- Strict RTP learning complete - Locking on source address 192.168.104.11:11866 > 0x2262b00 -- Strict RTP learning complete - Locking on source address 192.168.234.127:52518 有条件的情况下建议可以考虑使用 IAX 分机替代 SIP 分机,这样只需要 NAT 打通一个 UDP 端口就能通话,而不用像 SIP 那样要考虑 ALG,ICE,STUN 等方案
下面是新增一个 IAX 分机的用例
opkg update opkg install asterisk16-chan-iax2 /etc/asterisk/iax.conf
[general] bindport=4569 bindaddr=0.0.0.0 iaxcompat=yes nochecksums=yes disallow=all allow=ulaw [6010] type=friend username=6010 secret=6010 cOntext=from-internal host=dynamic callerid=6010<6010> /etc/asterisk/extensions.conf
[from-internal] exten => 6010,1,Dial(IAX2/6010,60,Trg) 由于 3G modem 还没到货,所以目前先更新到这里,等到货后继续配置。
12 月 27 号收货,继续更,用到的型号是 Huawei K3765.
K3765 3G modem
在 openwrt 下配置 dongle 设备,请结合实际数据配置
/etc/asterisk/dongle.conf
[general] interval=20 [defaults] cOntext=dongle-in group=0 exten=+862022221234 [dongle0] imei=123451234512345 通过 asterisk 控制台查一下设备状态,
asterisk -rvvvv RiWifi*CLI> dongle show devices ID Group State RSSI Mode Submode Provider Name Model Firmware IMEI IMSI Number dongle0 0 Free 16 3 3 FFFFFFFFFFFFFF K3765 11.126.03.04.521 123451234512345 123451234512345 Unknown 接下来新增呼出、呼入的分机配置
/etc/asterisk/extensions.conf
[from-internal] exten => _1.,1,Dial(Dongle/g0/${EXTEN:1}) ;呼出设置,结合实际,我这边是加了"1"这个前缀,例如我的 SIP 分机要拨打 10011,那么拨号就是 110011 [dongle-in] exten => +862022221234,1,Dial(IAX2/6010,60,Trg) ;呼入设置,我这边就是配置成所有呼叫直接转到 IAX-6010 分机,复杂点的可以做 IVR,号码本,不过只有一路的电话就不需要搞这么复杂了。 最后,拨号测试
呼入测试
呼出测试
refer: https://www.ppuu.org/2019/12/openwrt-asterisk-dongle-gsm-to-sip/
