3

'Hello

I try to develop a softphone with MJSIP for android. I have a simple test setup:

  • 1 PC (Win7) with a sip phone (number 1000)
  • 1 VM (Win7) with a sip phone (number 1001) and Freeswitch installed

sip phone #1000 can call #1001 and backwords. On the VM I am running eclipse where I try to register the android siphone (number 1002) with the Freeswitch. 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? Why do I get onUaRegistrationFailure?

thx

edit1: I changed some minor things, tested again and look into wireshark.

From wireshark: 400 Request:

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).

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. So nothing is send from the emulator?

edit4: I used different configurations of IP and port. 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

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:

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:

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:

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
B770
  • 1,272
  • 3
  • 17
  • 34

1 Answers1

4

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 ? 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. 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. 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. 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. 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 message does not have 400 code, 400 SIP code stands for "Bad Request".

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.
- "403 Forbidden" : the server refuses to "handle" your request.
- "404 Not found" : the requested (to register) user can't be found in the server's "records"
- "407 Unauthorized" (does not apply in your case) for proxy authentication.
- etc. (full list of 4xx failure responses)

in the onUaRegistrationFailure() method print the "result" string in Logcat. The problem may be also due to MjSip as many of its APIs are not fully implemented.

JohnTube
  • 1,782
  • 27
  • 46
  • Hey John, thanks for your answer. Printing out "result" showes Timeout. I will check how I can connect my android emulator to the LAN. I will write the results later – B770 Jun 14 '13 at 13:17
  • So I changed the port to "54321" and the IP to "10.0.2.15" which should be the emulators network interface (http://developer.android.com/tools/devices/emulator.html#emulatornetworking). now wireshark shows 405. Method not allowed. Hum strange. I add the wireshark trace in my first posting – B770 Jun 14 '13 at 13:47
  • So I see that in the wireshark trace there is from and to the same?Strange – B770 Jun 14 '13 at 14:38
  • 2
    The second SIP message you quoted proves that you're sending the REGISTER message to the emulator itself and the emulator is sending you back a 405 error as it acts as a UAC and not as UAS so receiving REGISTER messages is not allowed. (Both messages contain the same user-agent signature : mjsip-1.6 the Freeswitch server should have other UA signature). What is the IP address of your server (realm)? check if you have configured a working virtual network and then do an IP config in your VM.w – JohnTube Jun 14 '13 at 16:49
  • Thanks for your reply. I will check that tomorrow and post infos, like the registering of phone 1000 and 1001 – B770 Jun 16 '13 at 07:03
  • the IPv4 address of the vm is 172.22.0.34 – B770 Jun 17 '13 at 07:18
  • 1
    You can't see nothing in Wireshark because you're not using it in the VM ! Open Wireshark in the VM and try registration you'll find the REGISTER request and the server's reply. 403 Forbidden means that you succeeded to communicate with the server but you must either change the server's configuration so it can accept REGISTER messages or you must change something in the REGISTER message itself so it can be accepted by the server. – JohnTube Jun 17 '13 at 12:50
  • I am running wireshark in the vm and on the real pc but I can't see a sip package. The servers config must be ok because i can register with a x-light client. – B770 Jun 17 '13 at 17:28
  • I've tested some other configurations and added them and the results above – B770 Jun 18 '13 at 08:58
  • 1
    Are you sure you that the SIP [from] source port and the SIP [to] destination port are the same ? In your configuration you are only setting the source port. The destination port (the server's SIP port) must be the same as the server's configuration it's likely to be the default one 5060. Besides, I didn't understand why there's an INVITE message trace ? – JohnTube Jun 18 '13 at 13:53
  • No I'm not shure if sip(from) and sip(to) have to have the same port. I really don't get it. Really confusing for me at the moment. I added the registration of 1000 (X-Lite) to the posting above (edit 5) – B770 Jun 18 '13 at 14:55
  • 1
    Try to ommit the port from the "To" and "From" addresses : String fromUrl = ""; // FROM String toUrl = ""; // TO – JohnTube Jun 19 '13 at 01:37
  • I changed the from and to addresses. Still 403 forbidden. I also added a line in the code to make a call to the toUrl. Freeswith is logging that the call is rejected. I will post the log of FS above – B770 Jun 19 '13 at 08:09
  • 1
    I'm not familiar with Freeswitch I only used Asterisk for a while. I think you should re implement the RegisterAgent yourself as most MjSIP APIs are incomplete and sometimes useless ! Here's the link to Sipdroid's RegisterAgent's source code [link](http://code.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/RegisterAgent.java) In this case I think that Authentication Digest operation with the server is not done properly ! Another minor detail : I thought you wanted to register the user 1002 so why in the Freeswitch log the user is 1001 ?! – JohnTube Jun 19 '13 at 17:09
  • Thanks for your replay. During time I log off the 1002 client and changed the code of the android client to user 1001 because I wanted to be shure that the problem is not the account 1002. After testing I forgot to change it back to 1002. Thats why freeswitch shows 1001. Implementing the whole thing by myself is maybe the last option. Have you tried some working sip libraries for android and give me a hint. I can't use the standard android sip stack. – B770 Jun 20 '13 at 07:28
  • I changed the setting a bit. I open a wlan network from my computer (not the vm) and let my android connect to it (not the emulator any more). After it is connectet it shoult take its own ip (192.168.173.176) and try to register with that. But still Timeout (UA: NOT FOUND/TIMEOUT) (edit7) – B770 Jun 20 '13 at 08:15
  • I guess that the request is send from the phone but never arrives FreeSwitch – B770 Jun 20 '13 at 13:15
  • Tanks for your help and your time :) It's not working but your deserve the bounty – B770 Jun 23 '13 at 18:46
  • You're welcome, I'm glad I helped ! Sorry I couldn't solve your problems but maybe this [link](https://github.com/JohnTube/PCD_test/blob/master/src/com/example/test_app/RegisterAgent.java) will help you if you decided to implement SIP operations all by yourself as MjSIP APIs are not reliable, my experience with MjSIP was terrible but I got inspiration from Sipdroid's code. (the link is for a school project but the code on Github is not the final version as I still got problems with Git and EGit, the RegisterAgent is a very basic one) – JohnTube Jun 23 '13 at 19:52
  • Hi, I will check your code. Thanks! Did you get it working, so that you can register with a server and make a call? – B770 Jun 26 '13 at 13:49