简体   繁体   English

MJSIP:向服务器注册android客户端:onUaRegistrationFailure; Wireshark 400 /错误请求

[英]MJSIP: Register android client with server: onUaRegistrationFailure; Wireshark 400/Bad Request

'Hello '你好

I try to develop a softphone with MJSIP for android. 我尝试使用MJSIP for android开发一款软电话。 I have a simple test setup: 我有一个简单的测试设置:

  • 1 PC (Win7) with a sip phone (number 1000) 1台PC(Win7)带一个SIP电话(1000号)
  • 1 VM (Win7) with a sip phone (number 1001) and Freeswitch installed 1个VM(Win7),带有SIP电话(编号1001)和Freeswitch

sip phone #1000 can call #1001 and backwords. sip phone#1000可以拨打#1001和后备词。 On the VM I am running eclipse where I try to register the android siphone (number 1002) with the Freeswitch. 在VM上我正在运行eclipse,我尝试用Freeswitch注册android siphone(号码1002)。 But I always get onUaRegistrationFailure 但我总是得到失败的注册失败

public class MainActivity extends Activity {

private static final String TAG = "Mjsip-Test-App|| ";
private IpAddress ip;
private int port = 5060;
int audioport = 3000;
private String password = "1234";
private String username = "1002";
private String realm = "172.22.0.34";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port+">"; // FROM
String toUrl = "<sip:" + "1000@" + realm + ":" + port+">"; // TO

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.v(TAG, "Start");
    if(!SipStack.isInit()){
    SipStack.init();
    Log.v(TAG, "Stack.init");
    }
    ip = IpAddress.getLocalHostAddress();
    SipProvider sipProvider = new SipProvider(ip.toString(), port);
    Log.v(TAG, "IP: " + ip.toString() + " port: " + port);
    Log.v(TAG, "new sipProvider created");
    UserAgentProfile profile = new UserAgentProfile();
    profile.audio = true;// using audio
    profile.audio_port = audioport;
    profile.passwd = password;
    profile.username = username;
    profile.realm = realm;
    Log.v(TAG, "new profile");

    RegisterAgent reg = new RegisterAgent(sipProvider, toUrl, fromUrl,
            username, realm, password, new RegisterAgentListener() {

                @Override
                public void onUaRegistrationSuccess(RegisterAgent ra,
                        NameAddress target, NameAddress contact,
                        String result) {
                    Log.v(TAG, "Listener: onUaRegistrationSuccess");

                }

                @Override
                public void onUaRegistrationFailure(RegisterAgent ra,
                        NameAddress target, NameAddress contact,
                        String result) {
                    Log.v(TAG, "Listener: onUaRegistrationFailure");
                }
            });

    reg.register();
    Log.v(TAG, "reg.register()");

My Logging shows: 我的记录显示:

06-13 13:08:04.390: V/Mjsip-Test-App||(772): Start
06-13 13:08:04.409: V/Mjsip-Test-App||(772): Stack.init
06-13 13:08:04.539: V/Mjsip-Test-App||(772): IP: 127.0.0.1 port: 5060
06-13 13:08:04.539: V/Mjsip-Test-App||(772): new sipProvider created
06-13 13:08:04.539: V/Mjsip-Test-App||(772): new profile
06-13 13:08:04.989: V/Mjsip-Test-App||(772): reg.register()
06-13 13:08:05.399: I/ActivityManager(59): Displayed activity com.example.mjsipstacktest/.MainActivity: 2159 ms (total 2159 ms)
06-13 13:08:05.649: V/Mjsip-Test-App||(772): Listener: onUaRegistrationFailure

Can someone give me a hint how to register the android emulator? 有人能给我一个如何注册Android模拟器的提示吗? Why do I get onUaRegistrationFailure? 为什么我会收到注册失败?

thx 谢谢

edit1: I changed some minor things, tested again and look into wireshark. edit1:我改变了一些小事,再次测试并查看wireshark。

From wireshark: 400 Request: 来自wireshark:400请求:

REGISTER sip:172.22.0.33:5060 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK11085
Max-Forwards: 70
To: <sip:1000@172.22.0.33:5060>
From: <sip:1000@172.22.0.33:5060>;tag=z9hG4bK15659795
Call-ID: 522184753761@127.0.0.1
CSeq: 1 REGISTER
Contact: <sip:1002@172.22.0.33:5060>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0

edit2: After editing the port to "54321" and the IP to 10.0.2.15 which should be the emulators network interface as written on the android dev page wireshark shows 405 (Method Not Allowed). edit2:将端口编辑为“54321”并将IP编辑为10.0.2.15,这应该是android dev页面上写的模拟器网络接口wireshark显示405(Method Not Allowed)。

Trace: 跟踪:

REGISTER sip:172.22.0.33:54321 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:54321;rport;branch=z9hG4bK49856
Max-Forwards: 70
To: <sip:1000@172.22.0.33:54321>
From: <sip:1000@172.22.0.33:54321>;tag=z9hG4bK23560417
Call-ID: 241065424059@10.0.2.15
CSeq: 1 REGISTER
Contact: <sip:1002@172.22.0.33:54321>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0

edit3: realm "172.22.0.34" port 5060 and own ip:10.0.2.15 showes Result: 403 Forbidden but I can't see anything in wireshark. edit3:领域“172.22.0.34”端口5060和自己的ip:10.0.2.15 showes结果:403禁止但我在wireshark中看不到任何内容。 So nothing is send from the emulator? 那么仿真器什么都没发送?

edit4: I used different configurations of IP and port. edit4:我使用了不同的IP和端口配置。 This is what I have tested. 这是我测试过的。 config: 配置:

private String ip = "10.0.2.15";
private int port = 5060;
int audioport = 3000;
private String password = "1234";
private String username = "1001";
private String realm = "172.22.0.34";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port + ">"; // FROM
String toUrl = "<sip:" + "1001@" + realm + ":" + port + ">"; // TO

Result 403 Forbidden
---> Wireshark is empty

Changing the port 改变端口

private String ip = "10.0.2.15";
private int port = 5554;
int audioport = 3000;
private String password = "1234";
private String username = "1001";
private String realm = "172.22.0.34";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port + ">"; // FROM
String toUrl = "<sip:" + "1001@" + realm + ":" + port + ">"; // TO

06-18 08:42:52.617: V/Mjsip-Test-App||(2108): Result: Timeout
  06-18 08:42:52.927: I/System.out(2108): UA: NOT FOUND/TIMEOUT

  ---> Wireshark is empty

Changing the ip of realm 改变领域的ip

private String ip = "10.0.2.15";
private int port = 5554;
int audioport = 3000;
private String password = "1234";
private String username = "1001";
private String realm = "172.22.0.31";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port + ">"; // FROM
String toUrl = "<sip:" + "1001@" + realm + ":" + port + ">"; // TO

Result:
06-18 08:47:24.529: V/Mjsip-Test-App||(2191): Result: Timeout
06-18 08:47:24.828: I/System.out(2191): UA: NOT FOUND/TIMEOUT

Wireshark:
REGISTER sip:172.22.0.31:5554 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:5554;rport;branch=z9hG4bK81091
Max-Forwards: 70
To: <sip:1001@172.22.0.31:5554>
From: <sip:1001@172.22.0.31:5554>;tag=z9hG4bK13966145
Call-ID: 270499704138@10.0.2.15
CSeq: 1 REGISTER
Contact: <sip:1001@172.22.0.31:5554>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0

INVITE sip:1001@172.22.0.31:5554 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:5554;rport;branch=z9hG4bK35740
Max-Forwards: 70
To: <sip:1001@172.22.0.31:5554>
From: <sip:1001@10.0.2.15:5554>;tag=z9hG4bK16532567
Call-ID: 020447961933@10.0.2.15
CSeq: 1 INVITE
Contact: <sip:1001@10.0.2.15:5554>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 145
Content-Type: application/sdp

v=0
o=sip:1001@10.0.2.15:5554 0 0 IN IP4 10.0.2.15
s=Session SIP/SDP
c=IN IP4 10.0.2.15
t=0 0
m=audio 3000 RTP/AVP 0
a=rtpmap:0 PCMU/8000
REGISTER sip:172.22.0.31:5554 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:5554;rport;branch=z9hG4bK81091
Max-Forwards: 70
To: <sip:1001@172.22.0.31:5554>
From: <sip:1001@172.22.0.31:5554>;tag=z9hG4bK13966145
Call-ID: 270499704138@10.0.2.15
CSeq: 1 REGISTER
Contact: <sip:1001@172.22.0.31:5554>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0

edit5: This is how wireshark trace looks like if I register X-Lite: edit5:如果我注册X-Lite,这就是wireshark跟踪的样子:

REGISTER sip:172.22.0.34 SIP/2.0
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-f3f38111bfc1d85a-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:1000@172.22.0.33:38170;rinstance=d3164432408a0132>;expires=0
To: "SipTestAcc1000"<sip:1000@172.22.0.34>
From: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=5f26a73a
Call-ID: YjAwMTQ2MmY4ZTU3MThhZjI2NTBlN2MwYTEzMWFjYTI
CSeq: 3 REGISTER
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
User-Agent: X-Lite release 4.5.2 stamp 70142
Authorization: Digest    username="1000",realm="172.22.0.34",nonce="495a96a8-00d9-4d01-9976-0c1abd541874",uri="sip:172.22.0.34",response="b99aeb2f5c8f14282f91f6130d14b584",cnonce="efe1a8fc4b143d1f711fac8efe63e4e3",nc=00000002,qop=auth,algorithm=MD5
Content-Length: 0


NOTIFY sip:1000@172.22.0.33:38170 SIP/2.0
Via: SIP/2.0/UDP 172.22.0.34;rport;branch=z9hG4bKFaS6H1D4yU1cQ
Max-Forwards: 70
From: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
To: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=0079587c
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 45446966 NOTIFY
Contact: <sip:1000@172.22.0.34:5060>
Expires: 0
User-Agent: FreeSWITCH-mod_sofia/1.5.2b+git~20130607T065407Z~e7fa70416d
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY,   PUBLISH, SUBSCRIBE
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, presence, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Subscription-State: terminated;reason=noresource
Content-Length: 0



SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.22.0.34;rport=5060;branch=z9hG4bKFaS6H1D4yU1cQ
Contact: <sip:1000@172.22.0.33:38170>
To: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=0079587c
From: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 45446966 NOTIFY
User-Agent: X-Lite release 4.5.2 stamp 70142
Content-Length: 0


SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-f3f38111bfc1d85a-1---d8754z-;rport=38170
From: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=5f26a73a
To: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=FQZ535ytt8m1S
Call-ID: YjAwMTQ2MmY4ZTU3MThhZjI2NTBlN2MwYTEzMWFjYTI
CSeq: 3 REGISTER
Date: Tue, 18 Jun 2013 14:34:21 GMT
User-Agent: FreeSWITCH-mod_sofia/1.5.2b+git~20130607T065407Z~e7fa70416d
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, precondition, path, replaces
Content-Length: 0



SUBSCRIBE sip:1000@172.22.0.34:5060;transport=udp SIP/2.0
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-64e0fd2ee573d443-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:1000@172.22.0.33:38170>
To: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
From: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=0079587c
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 3 SUBSCRIBE
Expires: 0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
Supported: eventlist
User-Agent: X-Lite release 4.5.2 stamp 70142
Event: message-summary
Content-Length: 0



SIP/2.0 202 Accepted
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-64e0fd2ee573d443-1---d8754z-;rport=38170
From: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=0079587c
To: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 3 SUBSCRIBE
Contact: <sip:1000@172.22.0.34:5060>
Expires: 0
User-Agent: FreeSWITCH-mod_sofia/1.5.2b+git~20130607T065407Z~e7fa70416d
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, presence, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Subscription-State: terminated;reason=noresource
Content-Length: 0

edit6: The log of FS when I try to make a call to toURL: edit6:当我尝试调用toURL时FS的日志:

2013-06-19 10:05:32.753652 [NOTICE] switch_channel.c:1027 New Channel sofia/internal/1001@172.22.0.34 [912a29fa-51db-4c87-86c1-e76eac1e2d5a]
2013-06-19 10:05:33.733181 [NOTICE] sofia.c:1786 Hangup sofia/internal/1001@172.22.0.34 [CS_NEW] [CALL_REJECTED]
2013-06-19 10:05:33.753690 [NOTICE] switch_core_session.c:1567 Session 15 (sofia/internal/1001@172.22.0.34) Ended
2013-06-19 10:05:33.753690 [NOTICE] switch_core_session.c:1571 Close Channel sofia/internal/1001@172.22.0.34 [CS_DESTROY]

edit7 test with a real device in wlan of pc: 使用pc的wlan中的真实设备进行edit7测试:

06-20 09:48:23.576: V/Mjsip-Test-App||(9988): Start 
06-20 09:48:23.584: V/Mjsip-Test-App||(9988): IP: 192.168.173.176
06-20 09:48:23.584: V/Mjsip-Test-App||(9988): Stack.init
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): IP: 192.168.173.176 port: 5554
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): new sipProvider created
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): new profile
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): From: <sip:1002@172.22.0.34>
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): To: <sip:1002@172.22.0.34>
06-20 09:48:23.677: V/Mjsip-Test-App||(9988): reg.register()
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): Listener: onUaRegistrationFailure
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): RegisterAgent: org.hsc.sip.ua.core.core.RegisterAgent@405373f0
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): target: <sip:1002@172.22.0.34>
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): contact: <sip:1002@172.22.0.34>
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): Result: Timeout
06-20 09:50:31.755: I/System.out(9988): UA: NOT FOUND/TIMEOUT

I am not sure if you succeeded to send a request from the emulator to the server (Freeswitch in the VM), did you make sure you could use wifi in the emulator ? 我不确定你是否成功向模拟器发送请求到服务器(VM中的Freeswitch),你确定可以在模拟器中使用wifi吗? Even if the SIP frame is there in Wireshark it does not mean that it has arrived to destination it may only mean that it is sent. 即使在Wireshark中存在SIP帧,也不意味着它已到达目的地,它可能仅意味着它被发送。 The "Via" field must contain a "real/physical" IP address (in your case) and not a "logical" (loopback) one, in other terms 127.0.0.1:5060 must be the IPv4 address of the sending device. “Via”字段必须包含“实际/物理”IP地址(在您的情况下)而不是“逻辑”(环回)IP地址,换句话说127.0.0.1:5060必须是发送设备的IPv4地址。 You are getting the Via field with IpAddress.getLocalHostAddress() (same address taken as argument in the SipProvider constructor) which returns 127.0.0.1 and this can only mean that your emulator is not "connected" to any network. 您正在使用IpAddress.getLocalHostAddress()(在SipProvider构造函数中作为参数的相同地址)获取Via字段,该字段返回127.0.0.1,这只能表示您的模拟器未与任何网络“连接”。 I advice you to change default ports, try to "manually/statically" set the via address (in the SipProvider constructor) and verify your virtual network settings. 我建议你更改默认端口,尝试“手动/静态”设置通过地址(在SipProvider构造函数中)并验证您的虚拟网络设置。 As in the REGISTER message you have provided in your question it looks like you are sending [back] the REGISTER message to the PC [emulator maybe] instead of the VM. 与您在问题中提供的REGISTER消息一样,您似乎正在将[返回] REGISTER消息发送到PC [仿真器]而不是VM。

REGISTER message does not have 400 code, 400 SIP code stands for "Bad Request". REGISTER消息没有400个代码,400个SIP代码代表“错误请求”。

You must provide the registration failure cause (code + reason) which can be one of the following (if it is not Registration Time Out): 您必须提供注册失败原因(代码+原因),该原因可以是以下之一(如果不是注册超时):
- "401 Unauthorized" : you have to resend a REGISTER message with an authentication (or Www-authentication) header that contains a response generated from user (to register) credentials and "nonce" (key) provided by the server reply to the first REGISTER message sent. - “401 Unauthorized”:您必须重新发送带有身份验证(或Www身份验证)标头的REGISTER消息,该标头包含从用户(注册)凭据生成的响应和服务器回复第一个提供的“nonce”(密钥)发送REGISTER消息。
- "403 Forbidden" : the server refuses to "handle" your request. - “403 Forbidden”:服务器拒绝“处理”您的请求。
- "404 Not found" : the requested (to register) user can't be found in the server's "records" - “404 Not found”:在服务器的“记录”中找不到请求的(注册)用户
- "407 Unauthorized" (does not apply in your case) for proxy authentication. - “407 Unauthorized”(在您的情况下不适用)进行代理身份验证。
- etc. ( full list of 4xx failure responses ) - 等( 4xx失败响应的完整列表

in the onUaRegistrationFailure() method print the "result" string in Logcat. 在onUaRegistrationFailure()方法中打印Logcat中的“result”字符串。 The problem may be also due to MjSip as many of its APIs are not fully implemented. 问题可能还在于MjSip,因为它的许多API都没有完全实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM