Incoming Call Troubles

Hi all,

I have a strange issue. 99.9% of all incoming calls work just fine, but if I receive calls from Versatel, I get some junk in the dialed number (the number that is to be called).

– Executing [4971414574030" <sip:@from-trunk:1] Set("SIP/Toplink-00000641", "__FROM_DID=4971414574030" <sip:") in new stack

– Executing [4971414574030" <sip:@from-trunk:2] NoOp("SIP/Toplink-00000641", "Received an unknown call with DID set to 4971414574030" <sip:") in new stack

– Executing [4971414574030" <sip:@from-trunk:3] Goto("SIP/Toplink-00000641", "s,a2") in new stack

The Problem is the <sip: at the end.

Has anybody an idea how to fix this?

Kind regards,


That looks like a malformed SIP header. You’ll need more debug details. Do the following:

asterisk -rvvvvvvvvvv
sip set debug on

Then make an inbound call over this provider/trunk and post the output. Need to see how the INVITE is actually coming in and formatted.

As @BlazeStudios says. But also, what is the context for the Toplink trunk? That may be trying to reformat the called number and/or fish it out of the To header. Possibly, because of a direct interconnection between the providers, the format may be valid but different from normally occurs and what the special context expects. If this context is custom written, please post the added code.


the context is custom-written, it looks like this:

exten => _.,1,GotoIf($["${CALLERID(num):0:1}" != “+”]?noplusatstart)
exten => _.,n,Set(CALLERID(num)=00${CALLERID(num):1})
exten => _.,n(noplusatstart),Goto(from-trunk,${CUT(CUT(SIP_HEADER(To),@,1),+,2)},1)
exten => _.,n,Goto(from-trunk,${CUT(CUT(CALLERID(dnip),@,1),+,2)},1)

I had to do this, because the numbers did not come in normalized.

Kind regards,


OK so the problem is you’re not CUT()ing the header properly and you’re malforming it.

Try using from-pstn-toheader as the context if you’re trying to grab details from the To header.


so if I get this right, I should move the whole thing to [from-pstn-toheader] is there anything else wrong as you are saying I am malforming it?



At the Asterisk console, issue
sip set debug on
and have a Versatel user call in. Take a look at the incoming INVITE, especially the To header. Possibly, it’s already malformed and you’ll need to get Toplink to fix it. Or, it may be formatted differently from ‘normal’ calls but something that you can deal with, by modifying the code for [from-sip-toplink].

1 Like


seems like I get it malformed with a second trailing <sip:+Number>. Because I defined + as a delimiter, this results in the nasty string. I could reduce the whole processing to:

exten => _.,1,Goto(from-trunk,${CUT(CUT(CUT(SIP_HEADER(To),@,1),+,2),<,1)},1)

The CUT(…),<,1) should remove the trailing <sip:, am I right with this?

Kind regards,


That’s not what your first post implies. I am guessing that in the working case you are seeing something like:
To: "4971414574030" <sip:[email protected]>
but the failing case has
To: "+4971414574030" <sip:[email protected]>
so the + in the name field is confusing the CUT functions.

If that’s the case, try just replacing the

If my assumptions were wrong, please post the To header (as received) for both working and failing cases.

If the first two lines of the context (replacing + with 00 in the caller ID) are working properly, you should leave them alone. They have nothing to do with the called number.

Have you changed your incoming context to this and tested?

I’m pretty sure that’s not what the OP wants. He is rewriting the caller ID to show for example:
030 2345 6789 (Berlin)
00 33 1 2345 6789 (Paris)

The context from-pstn-toheader does not modify the caller ID at all.

Also, he wants to remove the + from the beginning of the called number (but leave the country code intact). I don’t know whether he has any DIDs outside of Germany.

I know it doesn’t, I was asking if it dealt with routing the DIDs based on the To Header since that is the actual issue at hand. Modifying the CallerID is secondary as if the from-pstn-toheader tests properly you can just end up with:

exten => _.,1,GotoIf($["${CALLERID(num):0:1}" != “+”]?noplusatstart)
exten => _.,n(noplusatstart),Set(CALLERID(num)=00${CALLERID(num):1})
exten => _.,n,Goto(from-pstn-toheader,${EXTEN},1)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.