3

'你好

我尝试用 MJSIP 为 android 开发一个软电话。我有一个简单的测试设置:

  • 1 台 PC (Win7) 和 SIP 电话(号码 1000)
  • 1 台带有 sip 电话(号码 1001)和 Freeswitch 的 VM (Win7)

sip phone #1000 可以拨打#1001 和backwords。在我正在运行 eclipse 的 VM 上,我尝试使用 Freeswitch 注册 android siphone(编号 1002)。但我总是得到 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()");

我的日志显示:

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

有人可以给我一个提示如何注册android模拟器吗?为什么我会收到 onUaRegistrationFailure?

谢谢

编辑1:我改变了一些小东西,再次测试并查看wireshark。

来自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

编辑2:将端口编辑为“54321”并将IP编辑为10.0.2.15后,这应该是android开发页面wireshark上写的模拟器网络接口显示405(不允许方法)。

痕迹:

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

编辑3:领域“172.22.0.34”端口5060和自己的ip:10.0.2.15显示结果:403禁止但我在wireshark中看不到任何东西。所以模拟器没有发送任何东西?

edit4:我使用了不同的 IP 和端口配置。这是我测试过的。配置:

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

更改端口

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

更改领域的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:如果我注册 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:当我尝试调用 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 在 pc 的 wlan 中使用真实设备进行测试:

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
4

1 回答 1

4

我不确定您是否成功地将请求从模拟器发送到服务器(VM 中的 Freeswitch),您确定可以在模拟器中使用 wifi 吗?即使 SIP 帧存在于 Wireshark 中,也并不意味着它已经到达目的地,它可能只意味着它已被发送。“通过”字段必须包含“真实/物理”IP 地址(在您的情况下)而不是“逻辑”(环回)地址,换句话说,127.0.0.1:5060 必须是发送设备的 IPv4 地址。您正在使用 IpAddress.getLocalHostAddress() (与 SipProvider 构造函数中的参数相同的地址)获取 Via 字段,该字段返回 127.0.0.1 ,这只能意味着您的模拟器没有“连接”到任何网络。我建议您更改默认端口,尝试“手动/静态” 设置通过地址(在 SipProvider 构造函数中)并验证您的虚拟网络设置。正如您在问题中提供的 REGISTER 消息一样,您似乎正在将 REGISTER 消息发送到 PC [可能是模拟器]而不是 VM。

REGISTER 消息没有 400 代码,400 SIP 代码代表“Bad Request”。

您必须提供注册失败原因(代码 + 原因),可以是以下之一(如果不是注册超时):
- “401 Unauthorized”:您必须重新发送带有身份验证(或 Www-authentication)的 REGISTER 消息) 标头,其中包含从用户(注册)凭据生成的响应和服务器对发送的第一个 REGISTER 消息的回复提供的“nonce”(密钥)。
- “403 Forbidden”:服务器拒绝“处理”您的请求。
- “404 Not found”:在服务器的“记录”中找不到请求的(注册)用户
- “407 Unauthorized”(不适用于您的情况)用于代理身份验证。
- 等等(4xx 失败响应的完整列表

在 onUaRegistrationFailure() 方法中打印 Logcat 中的“结果”字符串。这个问题也可能是由于 MjSip 造成的,因为它的许多 API 没有完全实现。

于 2013-06-14T12:43:16.847 回答