Asterisk chan_dahdi 使用过程

不同于chan_sip,chan_dahdi 的使用需要硬件的支持。
使用步骤如下:

  • 安装/加载 dahdi驱动
  • 执行dahdi_cfg (需要安装dahdi_tools,并依赖于/etc/dahdi/system.conf 文件)
  • 修改chan_dahdi.conf
  • 编写dialplan
  • 重启asterisk

1.安装/加载 dahdi驱动

modprobe my_wctdm.ko

2.执行dahdi_cfg

编辑 /etc/dahdi/system.conf (没有则需要创建)内容如下

loadzone=cn
defaultzone=cn
fxsks=1
echocanceller=OSLEC,1

我这里是通道1 是 FXO 口,对应于fxsks=1。如有多个通道则添加多行

...
fxsks=1
echocanceller=OSLEC,1
fxsks=2
echocanceller=OSLEC,1
...

dahdi_cfg

无报错信息则说明正常。

3.修改 chan_dahdi.conf

末尾添加如下内容,这样dahdi 通道才能被asterisk 识别

signalling=fxs_ks
context=from-pstn 
channel=>1 
callerid= 
group= 
context=default 

4.编写dialplan

这里我用1. sip/x 呼叫任意号码,再由dahdi/1 呼出 。2. dahdi/1收到来电转接到 sip/8000

/etc/asterisk/extensions.conf 如下

[from-internal]
exten => _x.,1,dial(dahdi/1/${EXTEN})
exten => _x.,n,hangup()

[from-pstn]
exten =>s,1,dial(sip/8000/${EXTEN})
exten =>s,2,Hangup()

5.重启asterisk

到这,所有配置ok , 让我们重启asterisk 。

重启后检查是否识别到chan_dahdi。
进入cli 命令行,aterisk -r 输入命令 dahdi show channels

172*CLI> dahdi show channels
172*CLI> 
   Chan Extension       Context         Language   MOH Interpret        Blocked    In Service Description                     
 pseudo                 default                    default                         Yes                                        
      1                 from-pstn                  default                         Yes                                        
172*CLI> 

看到有 1 from-pstn 说明已经识别到了。

接下来,可以用sip 登录,拨打号码,测试 dahdi/1 能否打通

去电

  == Using SIP RTP CoS mark 5
172*CLI> [ 2969.792901] dahdi_open unit=253
       > 0xb600c6a0 -- Strict RTP learning after[ 2969.802967] dahdi_open unit=253
 remote address set to: 172.16.0.158:7366
    -- Executing [101@from-internal:1] Dial("SIP/8000-00000002", "dahdi/1/101") in new stack
    -- Called dahdi/1/101
    -- DAHDI/1-1 answered SIP/8000-00000002
    -- Channel DAHDI/1-1 joined 'simple_bridge' basic-bridge <54760c9f-013d-43e5-813f-a6bc26fc85c3>
    -- Channel SIP/8000-00000002 joined 'simple_bridge' basic-bridge <54760c9f-013d-43e5-813f-a6bc26fc85c3>
       > 0xb600c6a0 -- Strict RTP switching to RTP target address 172.16.0.158:7366 as source
       > 0xb600c6a0 -- Strict RTP learning complete - Locking on source address 172.16.0.158:7366
    -- Channel DAHDI/1-1 left 'simple_bridge' basic-bridge <54760c9f-013d-43e5-813f-a6bc26fc85c3>
    -- Channel SIP/8000-00000002 left 'simple_bridge' basic-bridge <54760c9f-013d-43e5-813f-a6bc26fc85c3>
    -- Hanging up on 'DAHDI/1-1'
    -- Hungup 'DAHDI/1-1'
  == Spawn extension (from-internal, 101, 1) exited non-zero on 'SIP/8000-00000002'
  == Using SIP RTP CoS mark 5

来电:

-- Starting simple switch on 'DAHDI/1-1'
    -- Executing [s@from-pstn:1] Dial(" 3200.163136] dahdi_open unit=253
;35mDAHDI/1-1", "sip/8000/s") in new stack
  == Using SIP RTP CoS mark 5
    -- Called sip/8000/s
    -- SIP/8000-00000005 is ringing
       > 0xb6506058 -- Strict RTP learning after remote address set to: 172.16.0.158:61038
    -- SIP/8000-00000005 answered DAHDI/1-1
    -- Channel SIP/8000-00000005 joined 'simple_bridge' basic-bridge 
    -- Channel DAHDI/1-1 joined 'simple_bridge' basic-bridge 
       > 0xb6506058 -- Strict RTP switching to RTP target address 172.16.0.158:61038 as source
       > 0xb6506058 -- Strict RTP learning complete - Locking on source address 172.16.0.158:61038
    -- Channel SIP/8000-00000005 left 'simple_bridge' basic-bridge 
    -- Channel DAHDI/1-1 left 'simple_bridge' basic-bridge 
  == Spawn extension (from-pstn, s, 1) exited non-zero on 'DAHDI/1-1'
    -- Hanging up on 'DAHDI/1-1'
    -- Hungup 'DAHDI/1-1'

你可能感兴趣的:(VOIP)