I need the "pn-tok" value

Hi, is there somene who knows a command to retrieve the “pn-tok” token? It should be listed on the pjsip contact registration, but i dont see it :frowning:

There doesn’t seem to be any specification for this. RFC 8599 defines some pn-* URI parameters, but not pn-tok. It does say they should be suppressed when the URI is, subsequently sent, so it may well be deleted before the Contact information is stored.

The RFC post dates the release of Asterisk 16, so I wouldn’t expect Asterisk 16 to have specific knowledge of pn-* parameters.

ah, yes, i found this script, but its an old post

but not sure, where he is getting the value from

it was just a link to another thread :slight_smile:

$db2=new SQLite3('/opt/etc/asterisk/tokens.sqlite3');
if (isset($argv[2])) {
        if (preg_match('/pn-tok=([^;]+)/i', $v,$token)) {
                $db2->query("delete from keys where key='$k'");
                $db2->query("insert into keys values( '$k','$v')");
                fwrite($f,"got token $v\r\n");

        fwrite($f,"k=$k, v=$v\r\n");

Oops. It didn’t click that it was a preview until a couple of minutes ago.

1 Like

It seems to be using an undocumented feature, only in chan_sip, that stores the full contact in AstDB. It couldn’t be implemented like that in chan_pjsip, as chan_pjsip allows more than one contact.

(It is also confusing extensions and endpoints, as ph is the endpoint, not the extension, even if commonly made the same.)

ah, its undocumented? for testing, can i also do some command from the console?

I’ve been looking for the same, and it seems it’s not available. If you have control over the softphone, and can modify it, you could send the token out of band, and store it separately from Asterisk (Or use AMI to put it into AstDB if you like).

If you don’t control the softphone, you could add a proxy in front of Asterisk, to capture the token on registration. Kamailio should be able to do the job just fine, but other options may exist.

I’ve built a setup for our in-house developed softphone, where the softphone registers the token out of band, then an AGI script run on incoming calls to the device, gets the token from the database, sends the push message, waits about 10 sec. for a SIP registration to arrive, then proceeds with the dialplan.

This works just fine, for our use case, with a custom softphone. At least on iOS, which is our current target.

But it would be nice, if Asterisk had built-in support, that would allow us to just get the token from Asterisk.

Yeah, I have control over the softphone, I use linphone or linhome, compiled it, and added an extra text field where I make the token visible…

I had a look at script below also, but it’s not 100% clear to me yet, line 60 , there they retrieve it, but I think it’s based for chan_sip…

But for now I use Linhome, maybe the attribuut is different, gonna register later today with linphone if I can see the token there…

If not, I make linhome sending the push token indeed, into some extra database…

hey @Chano , on other question , not related to the pn-tok
are you familiar with kamailio then? I use opensips, and the only reason i use it, is that i need to send an extra header/body in the registar part

I use opensips, but its the same…
What i have done, i have setup an outbound UAC register in opensips, then created an user with same username as the UAC register… and modifief the .cfg file to add the extra headers

Then in aterisk, i setup a trunk where i use that username

So on incoming call on that UAC, it sends the call to asterisk… it works , but i dont think its the correct approach…
I believe i need to setup asterisk also as an trunk, and opensips should forward it with modified header… but i dont know how to do it? do you have an idea? its hard to find info about it

I’ve never really managed Kamailio myself, even though it’s part of our setup, it’s not my area of expertise. I have a vague idea of what it’s capable of, and what it’s NOT capable of.

But we have many cases where sip devices (Hardphones or softphones) register to Kamailio, then Kamailio forwards the calls to asterisk for processing.

What we do is simply to trust everything from Kamailo, then handles the calls in Asterisk based mainly on the destination. Our setup also includes cellphones which are always sent to asterisk as incoming calls, even though they are actually outbound. Kamailio then adds a header telling Asterisk what type of call it’s dealing with, and if the call is not terminated in Asterisk, Asterisk sends it back to Kamailio for outbound routing, with a few headers added, that allows Kamailo to handle it correctly.

ok, thats indeed a complete different approach :slight_smile:
i do everything in asterisk for softphones, and opensips is jiust for the outbound trunk

As I read that script, it reads the token from some value passed on the command line. What that value is, and where it comes from, is not obvious.

Here is another example, but i think its based on chan_sip
basicly they store the token in a seperate database, but i dont think it works with pjsip either

We have two types of customers. We have “normal” phone customers, that only has a single phone with a single phone number, and no PBX features. Most calls from this group are handled directly by Kamailio, no asterisk at all. For some special features like voicemail, and fraud prevention, we use Asterisk to handle the calls.

For the PBX customers, they register directly to Asterisk (For SIP devices, not cellphones), and Asterisk passes the call on to Kamailio for outbound routing, but handles all internal calls by itself. For Cellphones the calls first hits Kamailio, which hands them off to Asterisk for processing of internal calls (Like calls to extensions, or system requests like call forwarding, logging in and out of queues, etc.)

We also handle all accounting with data from Kamailio, internal calls in the same PBX are never accounted.

What a nasty hack… It relies on the token being logged to the Asterisk console log… Too fragile for me to rely on. For playing around, sure, for production with possibly paying customers? No way.

Might as well just have ngrep running as input to the scirpt, then getting it directly from the SIP traffic. Would even be less fragile. :stuck_out_tongue:

1 Like

yes, for me its just or home use
I just want to setup a trunk for outbound registration in Asterisk, but opensips needs to modify the header… not sure how i can do that

Now i have a trunk in asterisk, that registers on opensips (user created in opensips)
and then in opensips i have setup a trunk for outbound egistration with same username…
seems on inbound call from opensips it forwards the call to asterisk… it works, but i dont think its the correct way…

If you just need to add an extra header, or two, there’s no need to register on opensips (Also if it’s called Opensips, it’s not kamailio, but a fork, they are no longer equal in capabilites, to my knowledge).

You could simply have opensips take the register message, then add the headers, and pass it on to your provider, when your provider replies, you just forward that back to asterisk.

yes, opensips should take the register header and indeed forward it , but i dont know how todo that :slight_smile:
its quite new to me, and wasnt able to find a tutorial for it , documentation is quite limited

can you give me a hand on it?

Unfortunately not, as I mentioned previously, Kamailio is not my area of expertise, and I’ve only touched the config file to either figure out the logic, or change an IP address.