Why asterisk reject FXO'call,when FXS and FXO in the same IP

Hi Guys

Recently, I meet a issue, I find a solution as well. But I don’t know how it will happen.

I have a 1 FXS and 1 FXO gateway from voptech.com, they call VG3X-1s/1.

I register FXS port as 701, and register 801 to my asterisk. Both already connect into asterisk. No Problem

701/701 119.139.245.43 D N 5060 Unmonitored
801/801 119.139.245.43 D N 5060 Unmonitored

The following is sip.conf setting
[701]
type=peer
context=LocalSets
secret=50
host=dynamic
nat=yes
secret=ast!@34
dtmfmode=auto
disallow=all
allow=ulaw
allow=alaw
allow=gsm
directmedia=no
qualify=no

[801]
type=peer
host=dynamic
nat=yes
dtmfmode=auto
disallow=all
allow=ulaw
allow=alaw
allow=gsm
directmedia=no
secret=10
qualify=no

According to my extension.conf setting. 801 dial 200, my asterisk will play hello world voice.
And I already do binding number 200 in my FXO Port setting.(some one dial my FXO number-PSTN number, it will send 200 to my asterisk)

The issue is when I use my cell phone-18688977086 call PSTN number. And my gateway send call 200 to asterisk. But asterisk reject my call.(My FXO open Call ID detection alrady)

In CLI, sip set debug peer 801, I find the following

— (14 headers 15 lines) —
Sending to 119.139.245.43:5060 (NAT)
Using INVITE request as basis request - 13403379281227073496-0@192.168.1.191
Found peer ‘701’ for '18688977086’ from 119.139.245.43:5060
[2012-06-22 00:05:28] WARNING[10328]: chan_sip.c:14413 check_auth: username mismatch, have <701>, digest has <801>
[2012-06-22 00:05:28] NOTICE[10328]: chan_sip.c:22579 handle_request_invite: Failed to authenticate device sip:18688977086@208.111.42.239;tag=13403379281340337898-1

The 701 is the FXS number, I don’t understand why, asterisk will use 701 as authenticate to verify my FXO 801. I think that’s why, asterisk will reject my FXO’s call.

:neutral_face: :neutral_face: Could anyone tell me why asterisk will use 701 verify my FXO 801. why asterisk don’t use 801?

:open_mouth: Another interesting thing is, if I turn off the call ID detection in FXO Port. Asterisk will use 801 to verify my FXO, so everything is perfect.

The solution to let asterisk don’t reject my FXO 's call, is turn off the verify. :confused: I use inseure=invite in my sip.conf setting in 701 and 801.

It is matching by IP address; that’s what peer does.

Why do you have nat=yes?

[quote=“david55”]It is matching by IP address; that’s what peer does.

Why do you have nat=yes?[/quote]

Dear David,

Thank you for your answer, I appreciate it.

Yes, I know peer is matching Ip address, but I don’t understand, why asterisk use 701, why it don’t use 801? 801 have the same IP address as 701?why?

By the way, when many FXS and FXO in the same Ip address(They all register into Asterisk, what setting you suggest I did in asterisk? still invite=yes?

One more thing, when a gateway, which have many FXS Ports, and they registered to asterisk separately, it could work. inbound and outbound both are ok. But why, a gateway which have many FXO Ports, and they

register to asterisk. Inbound will meet the issue- that asterisk using wrong peer to verify?

Thank you very much.

It uses the first match based on the address.

Try switching the type to friend from peer. Your case might actually be one of the few where friend is required.
You could also check if your device allows using different originating udp ports for different fxs/fxo ports, something that Linksys devices do ( SPA3102 or PAP2-NT).

For more details:

viewtopic.php?t=79338

Also feel free to comment on this issue:

issues.asterisk.org/jira/browse/ASTERISK-16983

He will need to use “user”, not friend. friend still matches on IP as first choice.

This may compromise the ability to receive CLID.

[quote=“david55”]He will need to use “user”, not friend. friend still matches on IP as first choice.
[/quote]

The above statement is incorrect. The user portion of friend is matched before the peer part. This is easily testable or you can check the code.

[quote=“voptech”][quote=“david55”]It is matching by IP address; that’s what peer does.

Why do you have nat=yes?[/quote]

Because both my 50 and 10 is behind the router. Is it ok?

Dear David,

Thank you for your answer, I appreciate it.

Yes, I know peer is matching Ip address, but I don’t understand, why asterisk use 701, why it don’t use 801? 801 have the same IP address as 701?why?

By the way, when many FXS and FXO in the same Ip address(They all register into Asterisk, what setting you suggest I did in asterisk? still invite=yes?

One more thing, when a gateway, which have many FXS Ports, and they registered to asterisk separately, it could work. inbound and outbound both are ok. But why, a gateway which have many FXO Ports, and they

register to asterisk. Inbound will meet the issue- that asterisk using wrong peer to verify?

Thank you very much.[/quote]

Hi Guys,

OK. I test 701 as friend. 801 as peer. Still no working. Asterisk still use 701 to veryfi 801(My FXO Port).

:open_mouth: I think it is really a bug for asterisk?

[701]
type=friend
context=LocalSets
host=dynamic ; the device will register with asterisk
nat=yes ; assume device is behind NAT
secret=50 ; a secure password for this device – DON’T USE THIS PASSWORD!
dtmfmode=auto ; accept touch-tones from the devices, negotiated automatically
disallow=all ; reset which voice codecs this device will accept or offer
allow=ulaw ; which audio codecs to accept from, and request to, the device
allow=alaw ; in the order we prefer
allow=gsm ; only gsm codec to work with my sipphone software
qualify=yes ; JOE FU add this line. 13 wang.
directmedia=no
;insecure=invite

[801]
type=peer
host=dynamic ; the device will register with asterisk
nat=yes ; assume device is behind NAT
dtmfmode=auto ; accept touch-tones from the devices, negotiated automatically
disallow=all ; reset which voice codecs this device will accept or offer
allow=ulaw ; which audio codecs to accept from, and request to, the device
allow=alaw ; in the order we prefer
allow=gsm ; only gsm codec to work with my sipphone software
qualify=yes ; JOE FU add this line. 13 wang.
directmedia=no
secret=vggateway
;insecure=invite

If it is a bug, and I have my doubts, it would be classed as “minor”, because it doesn’t affect many users (most bugs on the issue tracker are mis-classified, because they are classified by the effect on the reporter, rather than on the community in general).

Most people would want to treat your sort of device as being connected by a single trunk, not as multiple trunks. The normal variant of this problem is when people use services intended for single users, to simulate trunks, by taking out multiple accounts.

I haven’t had time to check the code with respect to the order of user and peer matches, but I would suggest:

Make sure the device sets the user part of the From address, rather than uses it for CLID.

Define pure users for each category, for incoming calls.

Define one or more peers, with static addresses, for outgoing calls.

801 should be defined as friend. You might need to consider adding match_auth_username=yes if it still does not work.

Hi David,

Or it might no be a bug, or I could say, I want asterisk more better.

In this condition>>

Peer 701
peer 801

Both 701 and 801 have the same record of IP address and Port. In this condition of asterisk,
You know 801 is a trunk, when it send call to asterisk, it will bring the call ID together, such as 18688977086.
In this condition, because 18688977086 is not a peer name in asterisk, asterisk will send 401. Then my gateway will send its ID 801 and password to asterisk.

But the point is asterisk will only use the first peer 701 to verify my 801(because 701 register earlier then 801,that’s why, asterisk will use 701 to verify my 801??)

asterisk will only use the first peer (701)to verified the trunk which is recorded in asterisk(my gateway register 701 to asterisk then it register 801 later.

I test this in 3 of my gateway, 1FXS/1FXO gateway, 2 FXS/2FXO Gateway and 4 FXS/4FXO Gateway.
All asterisk will only use the first peer 701 to verify the call from FXO.

Or I could say, it is my voptech VG gateway’s issue? Because asterisk never thought, it will have the condition that Port number and Ip address will be the same.
:smiley: :smiley: :smiley: :smiley:

Thank you all your guys’ answers. I appreciate it so much.

What you will need to do is to use different SIP UDP ports for each of these numbers (701,801). The standard UDP port is 5060 which you can keep for 701. Make 801 use 5061 or anything different from 701’s port number. They are both coming from the same UDP port on the same IP address at the moment which is likely to really confuse Asterisk!

To change port settings on Asterisk enter:

port = 5061

under the peer settings for 801. There will be a setting on your voptech box to do the same. Set that to 5061 as well.