Asterisk provides an open source solution forthose who want to deploy VoIP in an organization, but don't want to invest a lot ofmoney in a proprietary solution. After you get the software installed on a server, you have some more work to do. You have toconnect your server to an outside voice line.
In this article, I'm going to show you how toset up the Asterisk Soft PBX system interface with a T1 PRI connection. Afterwards, youshould be able to install a Zaptel-compatible PRIcard, configure it for your needs, and modify your Asterisk dial plan to beginmaking outgoing phone calls from your internal SIP phones, as well as receivephone calls over your PRI line to your SIP clients.

Author's note

There are many different options for configuringyour outgoing trunk, and it's impossible to cover all of the options in thescope of this article. What will be covered is the most common configuration inthe United States, which is for a T1 PRI. I recommend that you become friendlywith your sales/support representative and tech support, as you should askquestions about what the channel stepping method is, encodings, and D-Channel.

Zaptel device preparation

Before you can worry about making a connection,you should have Asterisk installed on your server, as well as have inserted andinstalled your PRI card into your server. To start the install process, you'llneed libpriand the Zaptel package of drivers; you can downloadthe sources to these packages from the Asterisk Web site. Since we are using the Gentoo distributionfor our examples, you&'ll need to log in as root to install these (or su over thecommand shell). From here, you need to run emerge -pv libpri zaptel, as shown in Figure A.

Figure A

Run the emergecommand to install Zaptel packages.
If you've installed Asterisk with all the USEflags, then you can probably skip this step, as these packages are alreadyinstalled.
When installing these packages using emerge, you can view the availableoptions with the -pvargument if you're using a BRI connection or require any additional settingsfor the Zaptel package. You can also add theappropriate USE flag in the /etc/portage/package.use file. For example, if you were using a BRIline, your package.usefile may have these following entries.
net-libs/libpri bri
net-misc/zaptel bri

Zaptel device configuration

Now that you've installed the drivers needed byyour PRI card, you'll need to load the appropriate module's using modprobe <module>. In this case, thecommand is modprobe wct1xxp.
Whatever your kernel module is, you'll probablywant to have it automatically loaded when your server boots. To do this in Gentoo, just append the module name to/etc/modules.autoload.d/kernel-2.6(if you're using the Linux kernel 2.4 series, this file is kernel-2.4).
Next, you'll need to configure the /etc/zaptel.conf with the options for Zaptelto understand how your PRI will behave. This is where you need to contact yoursupport representative from your provider and find out a few configurationoptions, such as the required framing and coding (typically ESFframing and B8ZS coding). You'll also need to know what channels areyour B (data) channels and which channel is your D (control) channel. Unlessyou're using a partial/split T1, your card will most likely be configured with1-23 for your B channels and 24 for your control channel. For our T100P PRIcard, this configuration in /etc/zaptel.conf looks like:
This defines one trunk group exists using ESFsignaling and B8ZS coding. The trunk spans across B (data) channels 1-23, usingchannel 24 as the control (D) channel.
After setting the configuration and loading the Zaptel kernel modules, you can start the Zaptel service. The first time you start the service, youshould begin with a verbose debug run to make sure everything is working. To dothis, use the ztcfg -vv command. Theresults should list each of the channels and the status of the channel, asshown in Figure B.

Figure B

Do a test run before the finalconfiguration.
After you have tested the configuration, you canstart the Asterisk service via the Gentoo init script/etc/init.d/zaptel start. The next step is toconfigure Asterisk to accept the Zaptel span.

Configuring the Asterisk Zap channel

The Zap module is what Asterisk uses tointerface with the Zaptel device driver. In thisfile, you'll need to add your definitions for the context of the PRIconnection, signaling, and available channels. There are many configurationparameters available for configuring the Zap device, including automatic faxdetection, caller ID details, echo cancellation, and default ring cadences.These details, however, are going to be either outside the scope of thisarticle or may be covered in later articles in this series.


The important parameters for the Zap device aregoing to be under the [channels] context. Using a text editor, modify /etc/asterisk/zapata.conf, find the option signalling, and make itsignalling=fxo_ls.For the options that will work with your specific configuration, you need tospeak with your provider; but here's the list of available options, as providedby
  • em: E & M ImmediateStart
  • em_w: E & M Wink Start
  • em_e1: E & M CAS signallingfor E1 lines
  • featd: Feature Group D (Thefake, Adtran style, DTMF)
  • featdmf_ta: Feature Group D (The realthing, MF [domestic, US]) through a Tandem Access point
  • fgccama: Feature Group C-CAMA (DPDNIS, MF ANI)
  • fgccamamf: Feature Group C-CAMA MF(MF DNIS, MF ANI)
  • featdmf: Feature Group D (The realthing, MF [domestic, US])
  • featb: Feature Group B (MF[domestic, US])
  • fxs_ls: FXS (Loop Start)
  • fxs_gs: FXS (Ground Start)
  • fxs_ks: FXS (KewlStart)
  • fxo_ls: FXO (Loop Start)
  • fxo_gs: FXO (Ground Start)
  • fxo_ks: FXO (KewlStart)
  • pri_cpe: PRI signalling, CPE side
  • pri_net: PRI signalling, Networkside (for instance, side that provides the dialtone)
  • sf: SF (InbandTone) Signalling
  • sf_w: SF Wink
  • sf_featd: SF Feature Group D (Thefake, Adtran style, DTMF)
  • sf_featdmf: SF Feature Group D (Thereal thing, MF [domestic, US])
  • sf_featb: SF Feature Group B (MF[domestic, US])
  • e911: E911 (MF) stylesignalling. Originating switch goes off-hook, far-end winks, originating sendsKP-911-ST, far-end gives answer supervision, Originating-end sends KP-0-ANI-ST
The following are used for Radio interfaces:
  • fxs_rx: Receive audio/CORon an FXS kewlstart interface (FXO at the channelbank)
  • fxs_tx: Transmit audio/PTTon an FXS loopstart interface (FXO at the channelbank)
  • fxo_rx: Receive audio/CORon an FXO loopstart interface (FXS at the channelbank)
  • fxo_tx: Transmit audio/PTTon an FXO groundstart interface (FXS at the channelbank)
  • em_rx: Receive audio/CORon an E&M interface (1-way)
  • em_tx: Transmit audio/PTTon an E&M interface (1-way)
  • em_txrx: Receive audio/CORAND Transmit audio/PTT on an E&M interface (2-way)
  • em_rxtx: Same as em_txrx (for our dyslexic friends)
  • sf_rx: Receive audio/CORon an SF interface (1-way)
  • sf_tx: Transmit audio/PTTon an SF interface (1-way)
  • sf_txrx: Receive audio/CORAND Transmit audio/PTT on an SF interface (2-way)
  • sf_rxtx: Same as sf_txrx (for our dyslexic friends)


The next option you want to look at is your PRIswitch type. This is controlled through theswitchtype option. The default is national; however, here is a list of available options:
  • national: National ISDN type2(common in the US)
  • ni1: National ISDN type 1
  • dms100: Nortel DMS100
  • 4ess: AT&T 4ESS
  • 5ess: Lucent 5ESS
  • euroisdn: EuroISDN
  • qsigMinimalistic protocol to build a"network" with two or more PBX of different vendors

Channels and context

After the signallingand switchtypeare defined, the next step is to define the channels that the Zap channel workson. These translate to the D channels of the PRI device, which is definedthrough the option channel => 1-23.
You'll need to define the context that thesechannels with operate in context = remote. Optionally, if yourconfiguration will be splitting your T1 channels for dedicated DID's to groups/spans of channels, it's important to notethat your context is defined after the channel group. So if you need channels1-12 to be in context A and channels 13-23 to be in context B, you can do it.

The dial plan

Now that your Zap channel in Asterisk isconfigured to work with the Zaptel device, it's timeto modify the dial plan to allow for incoming and outgoing calls on your PRItrunk. You'll want to have the outside world call you on your DID numbers thatwill connect to your PRI card, then to Asterisk, then on to your SIP clientphone inside your office.
You should remember from the previous sectionthat we set Zap channels 1 through 23 in the context remote. This is to signifythat all communications on these channels connect directly to the PSTN (PublicSwitched Telephone Network), and thus are remote connections.
The first thing to do is to open /etc/asterisk/extensions.conf with your favorite text editor. At thebottom of the file, add the extensions that will describe the remote contextand our PRI connections. Figure Cshows our remote context in action.

Figure C

Add the extensions you need to the /etc/asterisk/extensions.conffile.
In this example, you can see that the extensionis the DID (Direct Inward Dialing) number (your telephone number). It's pickedup on the first step using the Goto function. In Asterisk, itforwards the call to the office context at extension 212 priority 1. Thistranslates to 555-1234 being the direct number to extension 212 in the office.Alternatively you can treat the call like any other extension, including beingable to run an AGI script, or forward the call to a call queue which will becovered in depth in later articles.

Outgoing connections

To allow users in the office to make an outgoingcall, you must first add them to the outgoing context. To do this, edit extensions.conf, and under the [office] context, add include =>outgoing.
Now thattelephone calls from the outside world can be delivered into the Asteriskcontrolled PBX network, there needs to be a method to allow the extensions inthe office context to call out, perhaps to order a pizza. To do this, define a newcontext labeled "outgoing". This will ensure that outbound phonecalls are separate in access from the rest of your dial plan. Figure D shows what the edits look like.

Figure D

Additional changes to the /etc/asterisk/extensions.conf file allowoutgoing phone calls.
This is different than what you've done so far. First, you're goingto notice the underscore (_) before the context. The underscore tells Asteriskto match the extension against the pattern that is going to follow theunderscore. The format for the pattern is simple, and contains attributes closeto a lightweight implementation of regular expressions:
  • X references any digit from0-9
  • Z references any digit from1-9
  • N references any digit from2-9
There are other matching methods also, but arecloser to regular expressions pattern matching functionality. In the example,you can see that there is a dial plan for seven- and 10-digit telephonenumbers, and the pattern should match any telephone number in the UnitedStates. The dial command uses the context variable ${EXTEN} which is the dialedextension that matches the pattern. The dial function dials the first group onthe Zap channel we configured earlier and attempts to connect to the extensionacross that channel. At this point, the extension being dialed is an outsidetelephone number and an actual call is going to be made.
As with any extension in Asterisk, you havecomplete control over the dial plan. So in this dial plan, if someone decidesthey want to dial a (900) adult phone line, the call will be immediatelydisconnected. Using the above matching methods, you can control who has accessmake long-distance phone calls, or create a process that requires a PIN numberin order to make a long-distance call.

That's it

Now everything is put together. You've configuredyour Zaptel drivers, the Asterisk Zap channel, andmodified the dial plan to allow incoming and outgoing telephone calls. Nowyou'll want to reload Asterisk by running /etc/init.d/asteriskrestart.
Alternatively, you can access the Asteriskconsole by running asterisk -vvvvcr on thecommand line and enter the restartgracefully command at the asterisk*CLI> prompt. The gracefully command will instruct Asterisk to wait until all openchannels are closed before shutting down, and then start itselfup again.