[asterisk-dev] connecting to PSTN to make further calls

Sam Liddicott sam at liddicott.com
Fri Feb 27 05:23:58 CST 2009


I've got most of the USBB3G / USBB2K stuff working now, but I just have 
one question which is how to setup a call to a PSTN line ready for 
further outgoing dialing.

Currently:

1. Incoming calls from the PSTN can be forwarded to any extensions and 
that works.
2. Any IP extension can dial the usbb3g and ring the handset, which when 
picked up also works.
3. I still need to let the IP extensions dial out on the PSTN line.

In the channel technology call handler (ast_channel_tech.call) I had this:

..
if (chan_yealink.owner)
            f.subclass = AST_CONTROL_RINGING;
            ast_queue_frame(chan_yealink.owner, &f);
            ast_channel_unlock(chan_yealink.owner);
            usbb2k_setmode(USB_MODE);
            UNJOIN_PSTN(chan_yealink);
            chan_yealink.from_usb=1;
            ast_indicate(chan_yealink.owner, AST_CONTROL_RINGING);
}
snd_pcm_prepare(chan_yealink.icard);
snd_pcm_start(chan_yealink.icard);
ast_mutex_unlock(&usbb3g_lock);

Now I can test the "dest" string to decide if I should connect to the 
PSTN side, and if so, the code might then look like this:
(with extensions of the form USBB2K/s for the pstn side and USBB2K/o for 
the phone side)

    if (chan_yealink.owner) {
        /* Ringing fxs? */
        if (dest && *dest='s') {
NOTE: There isn't going to BE any "ringing" do I need to do this?
            f.subclass = AST_CONTROL_RINGING;
            ast_queue_frame(chan_yealink.owner, &f);

            ast_channel_unlock(chan_yealink.owner);
            usbb2k_setmode(USB_MODE);
            JOIN_PSTN(chan_yealink);
            PICKUP_PSTN(chan_yealink);
            chan_yealink.from_usb=1;
NOTE: Asterisk should now have a dial tone
NOTE: I really want it to check for a dial tone and then dial some
NOTE: more if there is any... or just let the caller have the dial tone
NOTE: Do I need this?
            ast_indicate(chan_yealink.owner, AST_CONTROL_RINGING);
        } else {
            f.subclass = AST_CONTROL_RINGING;
                ast_queue_frame(chan_yealink.owner, &f);
            ast_channel_unlock(chan_yealink.owner);
            usbb2k_setmode(USB_MODE);
            UNJOIN_PSTN(chan);
            chan_yealink.from_usb=1;
            ast_indicate(chan_yealink.owner, AST_CONTROL_RINGING);
        }
    }
snd_pcm_prepare(chan_yealink.icard);
snd_pcm_start(chan_yealink.icard);
ast_mutex_unlock(&usbb3g_lock);

Notes:

For "safety" the analogue handset takes priority. Picking up the 
analogue handset will always steal the PSTN line.
If the analog phone picks up during such a call it then asterisk will 
drop the call and the channel driver will pass the call to the analogue 
handset.  This also works while the PSTN is ringing so the analogue 
handset can steal the incoming call from asterisk.

The analogue handset is not generally intended to be used. Although it 
can be called, the PSTN number can't be forwarded to it yet, I may try 
and get the bridging right later.

Sam




More information about the asterisk-dev mailing list