magicJack  and magicJack Plus Support, Reviews, FAQs and Hacks Forum Index

magicJack and magicJack Plus Support, Reviews, FAQs and Hacks


magicJack and magicJack Plus Unofficial Technical Support. Your Magic Jack and Magic Jack Plus phone service information resource
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Magicjack Patch for Asterisk(updated)


Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    magicJack and magicJack Plus Support, Reviews, FAQs and Hacks Forum Index -> magicJack Tips, Tricks, and Hacks
View previous topic :: View next topic  
Author Message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Fri Aug 07, 2009 5:00 am    Post subject: Magicjack Patch for Asterisk(updated) Reply with quote

Credit goes to dtm for the algorithm and teddy_b for mjproxy, the main part is just a rip-off from his code. Smile

The patch adds the new MJ auth. routine to chan_sip, good for using (multi) MJ as native trunk to make/receive calls and eliminate the needs for additional programs. Never messed with Asterisk source code before, lucky enough to get it working on the first try. Embarassed

8/19:
Patch updated, fix a bug since Asterisk verifies(!!) the return auth. hash value. I missed this part at first. Tested on several versions of Asterisk 1.4.21+, including 1.6 branch, also work for OpenWrt build.

8/22:
Another bug fixed, thanks bent.

Note
For old versions, the first part is in function check_auth() and the second in build_reply_digest(). Try to add them manually...

The forum converts all TABs in source code to spaces, so if the patch doesn't apply, try to use "patch -l" instead of "patch".

Code:

--- old/channels/chan_sip.c     2009-08-13 10:24:40.000000000 -0700
+++ new/channels/chan_sip.c     2009-08-22 13:47:29.000000000 -0700
@@ -8535,6 +8535,32 @@
                ast_md5_hash(a2_hash, a2);
                snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash);
                ast_md5_hash(resp_hash, resp);
+
+
+       /* To a Magicjack domain */
+               if (strstr(uri,"talk4free.com"))
+               {
+               char callid[256];
+               char newnonce[256];
+               char *c;
+               int i;
+               ast_copy_string(callid, p->callid, sizeof(callid));
+               ast_copy_string(newnonce, p->nonce, sizeof(newnonce));
+
+               strcat(newnonce, "_");
+               c = newnonce + strlen(newnonce);
+               char hex[2];
+               hex[1] = 0;
+               for (i = 0; i < 8; i++) {
+                       hex[0] = newnonce[i];
+                       int x = strtol(hex, NULL, 16);
+                       *c++ = callid[x];
+                       }
+               *c++ = 0;
+
+               snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
+               ast_md5_hash(resp_hash, resp);
+               }
        }

        good_response = keys[K_RESP].s &&
@@ -11658,6 +11684,31 @@
                snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, p->nonce, a2_hash);
        ast_md5_hash(resp_hash, resp);

+       /* To a Magicjack domain */
+       if (strstr(uri,"talk4free.com"))
+       {
+               char callid[256];
+               char newnonce[256];
+               char *c;
+               int i;
+               ast_copy_string(callid, p->callid, sizeof(callid));
+               ast_copy_string(newnonce, p->nonce, sizeof(newnonce));
+
+               strcat(newnonce, "_");
+               c = newnonce + strlen(newnonce);
+               char hex[2];
+               hex[1] = 0;
+               for (i = 0; i < 8; i++) {
+                       hex[0] = newnonce[i];
+                       int x = strtol(hex, NULL, 16);
+                       *c++ = callid[x];
+                       }
+               *c++ = 0;
+
+               snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
+               ast_md5_hash(resp_hash, resp);
+       }
+
        /* only include the opaque string if it's set */
        if (!ast_strlen_zero(p->opaque)) {
          snprintf(opaque, sizeof(opaque), ", opaque=\"%s\"", p->opaque);


Last edited by pagemen on Sat Aug 22, 2009 5:21 pm; edited 4 times in total
Back to top
View user's profile Send private message
jaybob413
MagicJack Newbie


Joined: 23 Mar 2009
Posts: 6

PostPosted: Mon Aug 17, 2009 9:35 am    Post subject: Re: Magicjack Patch for Asterisk Reply with quote

This is working well for me on Asterisk 1.4.21.2 and 1.6.1.1 on CentOS 5.3 for both physical and virtual instances.

Thanks!

pagemen wrote:
Credit goes to dtm for the algorithm and teddy_b for mjproxy, the main part is just a rip-off from his code. Smile

The patch adds the new MJ auth. routine to chan_sip, good for using (multi) MJ as native trunk to make/receive calls and eliminate the needs for additional programs. Never messed with Asterisk source code before, lucky enough to get it working on the first try. Embarassed

Tested on Debian Lenny w/Asterisk 1.4.21.2 and should work on other Asterisk releases(hopefully). Please report back any bugs.

Back to top
View user's profile Send private message
lowno
MagicJack Newbie


Joined: 09 Mar 2009
Posts: 7

PostPosted: Mon Aug 17, 2009 6:11 pm    Post subject: Reply with quote

How do you patch the chan_sip.so?
Back to top
View user's profile Send private message
bent
MagicJack Newbie


Joined: 10 Jun 2009
Posts: 4

PostPosted: Mon Aug 17, 2009 7:20 pm    Post subject: Reply with quote

Hi!
Try this patch on 1.4.21.1.
Successful registered and got incoming calls, but still unauthorized on outgoing...

register => EXXXXXXXXXX01:[email protected]:5070/EXXXXXXXXXX01

What's wrong?
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Tue Aug 18, 2009 3:00 pm    Post subject: Reply with quote

bent wrote:
Hi!
Try this patch on 1.4.21.1.
Successful registered and got incoming calls, but still unauthorized on outgoing...

register => EXXXXXXXXXX01:[email protected]:5070/EXXXXXXXXXX01

What's wrong?


that's just for incoming, you need to set up an outgoing trunk as well.
an example:

http://www.phoneservicesupport.com/post45455.html#45455
Back to top
View user's profile Send private message
lowno
MagicJack Newbie


Joined: 09 Mar 2009
Posts: 7

PostPosted: Tue Aug 18, 2009 5:10 pm    Post subject: Reply with quote

I would be more then happy to pay someone to patch my asterisk PBX, so that I can use the magicjack service again.

Let me know. I bet it is really fast and easy.
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Wed Aug 19, 2009 10:56 am    Post subject: No joy on Asterisk ver 1.4.15 PBIAF Reply with quote

I am running PBXIAF and have applied all the latest automatic updates. Which brings my OS up to CentOS 5 (final) and the FreePBX up to version 2.5.1.5 and Asterisk itself up to version 1.4.15.

The patch fails on this Asterisk version 1.4.15 and after examining the source code I can see that the chan_sip.c source is sufficiently different on version 1.4.15 so that the patch should fail.

I am not sure what I am going to do at this point. If I update Asterisk manually I may break FreePBX. If I just update the chan_sip.c that could break Asterisk.

I'll have to think about this some but I wanted to let others who may be running the same versions as me that the patch doesn't work unfortunately.
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Wed Aug 19, 2009 4:27 pm    Post subject: Reply with quote

Should still work in 1.4.15, but some changes in the source code prevent the patch from applying.

Try to add the following code between line 11465 and 11466 in chan_sip.c, thats between

ast_md5_hash(resp_hash, resp);
/* XXX We hard code our qop to "auth" for now. XXX */

Code:

       /* To a Magicjack domain */
       if (strstr(uri,"talk4free.com"))
       {
      char callid[256];
      char newnonce[256];
      char *c;
      int i;
      ast_copy_string(callid, p->callid, sizeof(callid));
      ast_copy_string(newnonce, p->nonce, sizeof(newnonce));

      strcat(newnonce, "_");
      c = newnonce + strlen(newnonce);
      char hex[2];
      hex[1] = 0;
      for (i = 0; i < 8; i++) {
      hex[0] = newnonce[i];
      int x = strtol(hex, NULL, 16);
      *c++ = callid[x];
      }

      snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
      ast_md5_hash(resp_hash, resp);
       }
 


untested but should work.
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Wed Aug 19, 2009 5:16 pm    Post subject: Reply with quote

pagemen wrote:
Should still work in 1.4.15, but some changes in the source code prevent the patch from applying.

Try to add the following code between line 11465 and 11466 in chan_sip.c, thats between

ast_md5_hash(resp_hash, resp);
/* XXX We hard code our qop to "auth" for now. XXX */

untested but should work.


Thanks pageman I'll give that a shot!

Edited 22 Aug 2009 - removed code section to shorten post.


Last edited by VaHam on Sat Aug 22, 2009 8:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Thu Aug 20, 2009 7:58 pm    Post subject: Reply with quote

pagemen wrote:
bent wrote:
Hi!
Try this patch on 1.4.21.1.
Successful registered and got incoming calls, but still unauthorized on outgoing...

register => EXXXXXXXXXX01:[email protected]:5070/EXXXXXXXXXX01

What's wrong?


that's just for incoming, you need to set up an outgoing trunk as well.
an example:

http://www.phoneservicesupport.com/post45455.html#45455


I assume you mean an out going route not "outgoing trunk" right?

I applied the patches and just like Bent I get registered and can receive incoming calls but I get the following error when making out going calls.

"chan_sip.c: Failed to authenticate on INVITE"

My Trunk Setup is as follows:

Maximum Channels: 1

Dial Rules: 1|.

Trunk Name: magicjack

PEER Details:
username=ENXXNXXXXXX01
type=friend
secret=MJ20CHARACTERPASSWRD
qualify=2000
port=5070
nat=yes
insecure=very
host=MJPROXYIP {Edit: 22 Aug 2009 This needs to be MJPROXYURL instead of IP}
fromuser=ENXXNXXXXXX01
dtmfmode=inband
context=from-trunk

USER Context: {blank}

USER Details: {blank}

Register String:
ENXXNXXXXXX01:MJ20CHARACTERPASSWRD@MJPROXYIP:ENXXNXXXXXX01@MJPROXYURL:5070/NXXNXXXXXX

Edit: 10 Sep 2009 - The following simple register string works

ENXXNXXXXXX01:MJ20CHARACTERPASSWRD@MJPROXYIP@MJPROXYURL:5070/NXXNXXXXXX

----------------------------------------------------------------------------

My Outbound Route Setup is as follows:

Route Name: MJ3-Outgoing

Dial Patterns: 1NXXNXXXXXX

Trunk Sequence 0 SIP/magicjack

Either something is wrong with my settings or my patch job.

Edited: 22 Aug 2009 {The only problem with the above settings was the PEER host setting. If you use the proxy url these settings work on a PIAF/FreePBX distro.}


Last edited by VaHam on Thu Sep 10, 2009 3:46 am; edited 2 times in total
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Thu Aug 20, 2009 8:22 pm    Post subject: Reply with quote

I'm not familar with FreePBX but the patch works on a vanilla Asterisk. Here is my configuration, Asterisk 1.6.1.4 on an OpenWrt router.

register => ENUMBER01:[email protected]:5070/NUMBER

[magicjack]
type=peer
secret=PASSWORD
host=proxy01.city.talk4free.com
port=5070
insecure=port,invite
username=ENUMBER01
fromuser=ENUMBER01
context=magicjack
qualify=yes
disallow=all
allow=ulaw
dtmfmode=rfc2833
nat=yes

then for outgoing:

exten => _03NXXNXXXXXX,1,Dial(SIP/${EXTEN:2}@magicjack)

The patch is updated to suppress a warning msg but you should still get outgoing calls without that.
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Fri Aug 21, 2009 2:45 am    Post subject: Reply with quote

pagemen wrote:
I'm not familar with FreePBX but the patch works on a vanilla Asterisk. Here is my configuration, Asterisk 1.6.1.4 on an OpenWrt router.

register => ENUMBER01:[email protected]:5070/NUMBER

[magicjack]
type=peer
secret=PASSWORD
host=proxy01.city.talk4free.com
port=5070
insecure=port,invite
username=ENUMBER01
fromuser=ENUMBER01
context=magicjack
qualify=yes
disallow=all
allow=ulaw
dtmfmode=rfc2833
nat=yes

then for outgoing:

exten => _03NXXNXXXXXX,1,Dial(SIP/${EXTEN:2}@magicjack)

The patch is updated to suppress a warning msg but you should still get outgoing calls without that.


Thanks! That gave me the hint I needed and sucesss! Very Happy

I should have mentioned earlier that I had tried several different register strings without success including:
register => ENUMBER01:[email protected]:5070/NUMBER

But what I hadn't tried was using the proxy url instead of proxy ip in the trunk PEER settings, as all the other examples I found have used. As soon as I saw you were doing that; it smacked me in the face, of coarse, that is the trigger for MD5 in the patch. VOILA The eagle has landed!

Ok another linux newbie question what flags do you use with diff to get the nice patch file listings you show above? I tried diff -rcs and that is close but not exactly the same.

I'd like to do the same for this older version of asterisk 1.4.15 since it is the current version for the popular PBIAF distro.

So I can now happily report the patch works like a champ on asterisk version 1.4.15 as well.

Thanks again for your work and that of the others involved with the MD5 work!
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Fri Aug 21, 2009 3:30 pm    Post subject: Reply with quote

Sorry, that's my bad, I just assume everyone is using proxy url(and that's easier for coding Very Happy ), its also possible to use other "trigger" like sip realm value. Anyway, for Asterisk configuration, its safer to use domain name instead of IP as MJ might change the server IP address so will just leave the patch as it is.

The parameter for diff is "diff -ruN".
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Fri Aug 21, 2009 6:36 pm    Post subject: Reply with quote

pagemen wrote:
Sorry, that's my bad, I just assume everyone is using proxy url(and that's easier for coding Very Happy ), its also possible to use other "trigger" like sip realm value. Anyway, for Asterisk configuration, its safer to use domain name instead of IP as MJ might change the server IP address so will just leave the patch as it is.

The parameter for diff is "diff -ruN".


Wasn't any problem on your part I was just having a Duh moment Smile Yes I agree using the url is much better!

Thanks Again!
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Fri Aug 21, 2009 6:58 pm    Post subject: Asterisk ver 1.4.15 - MJ Patch file. Reply with quote

The patch below is just pagemen's work incorporated into an older version of Asterisk. The reason I post it is to make it easier for those of you who like me may be running PIAF and the most recent update of Asterisk is right now ver 1.4.15

WARNING Backup your original chan_sip files before you try implementing this patch!

Code:
--- chan_sip.c.orig   2007-11-27 10:23:17.000000000 -0500
+++ chan_sip.c   2009-08-22 21:09:54.000000000 -0400
@@ -8364,7 +8364,33 @@
       ast_md5_hash(a2_hash, a2);
       snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash);
       ast_md5_hash(resp_hash, resp);
-   }
+      
+      /* MJ Patch Part 1 */
+      /* To a Magicjack domain */
+         if (strstr(uri,"talk4free.com"))
+         {
+         char callid[256];
+         char newnonce[256];
+         char *c;
+         int i;
+         ast_copy_string(callid, p->callid, sizeof(callid));
+         ast_copy_string(newnonce, p->nonce, sizeof(newnonce));
+
+         strcat(newnonce, "_");
+         c = newnonce + strlen(newnonce);
+         char hex[2];
+         hex[1] = 0;
+         for (i = 0; i < 8; i++) {
+            hex[0] = newnonce[i];
+            int x = strtol(hex, NULL, 16);
+            *c++ = callid[x];
+            }
+         *c++ = 0;
+            snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
+            ast_md5_hash(resp_hash, resp);
+         }
+      /* End of MJ Patch Part1 */
+   }      
 
    good_response = keys[K_RESP].s &&
          !strncasecmp(keys[K_RESP].s, resp_hash, strlen(resp_hash));
@@ -11455,14 +11481,39 @@
       ast_copy_string(a1_hash, md5secret, sizeof(a1_hash));
    else
       ast_md5_hash(a1_hash,a1);
-   ast_md5_hash(a2_hash,a2);
-
-   p->noncecount++;
+      ast_md5_hash(a2_hash,a2);
+      p->noncecount++;
    if (!ast_strlen_zero(p->qop))
       snprintf(resp,sizeof(resp),"%s:%s:%08x:%s:%s:%s", a1_hash, p->nonce, p->noncecount, cnonce, "auth", a2_hash);
    else
       snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, p->nonce, a2_hash);
-   ast_md5_hash(resp_hash, resp);
+      ast_md5_hash(resp_hash, resp);
+      /* MJ Patch Part 2 */
+      /* To a Magicjack domain */
+         if (strstr(uri,"talk4free.com"))
+         {
+         char callid[256];
+         char newnonce[256];
+         char *c;
+         int i;
+         ast_copy_string(callid, p->callid, sizeof(callid));
+         ast_copy_string(newnonce, p->nonce, sizeof(newnonce));
+
+         strcat(newnonce, "_");
+         c = newnonce + strlen(newnonce);
+         char hex[2];
+         hex[1] = 0;
+         for (i = 0; i < 8; i++) {
+            hex[0] = newnonce[i];
+            int x = strtol(hex, NULL, 16);
+            *c++ = callid[x];
+            }
+         *c++ = 0;
+            snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
+            ast_md5_hash(resp_hash, resp);
+         }
+      /* End of MJ Patch Part 2 */
+   
    /* XXX We hard code our qop to "auth" for now.  XXX */
    if (!ast_strlen_zero(p->qop))
       snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\", opaque=\"%s\", qop=auth, cnonce=\"%s\", nc=%08x", username, p->realm, uri, p->nonce, resp_hash, p->opaque, cnonce, p->noncecount);


Edited: 22 Aug 2009 -- This patch is for Asterisk version 1.4.15. If your looking for the most recent patch for newer versions see the first post in this thread!!!!
- added the *c++ = 0; fix
- dropped the full path to simplify the patch command. This means the patch should be run from the directory where chan_sip.c is located.


Last edited by VaHam on Mon Aug 24, 2009 4:43 am; edited 4 times in total
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Sat Aug 22, 2009 7:54 am    Post subject: Reply with quote

lowno wrote:
How do you patch the chan_sip.so?


There are many different ways but below is to the best of my recollection the way I did it.

22 Aug 2009 - Edited Instructions to fix a bug and make them more general purpose

1) {login to your Asterisk box using the 'root' account - you can use putty to do this remotly}

2) {Backup the original version of chan_sip:}
{Hint: you can copy the following commands to the clip board, one at a time, and then right click on the putty window and the command will be copied there. Then just hit enter to execute the command in putty}

cp -p /usr/src/asterisk/channels/chan_sip.c /usr/src/asterisk/channels/chan_sip.c.b4patch
cp -p /usr/src/asterisk/channels/chan_sip.c.orig /usr/src/asterisk/channels/chan_sip.c.orig.b4patch
cp -p /usr/src/asterisk/channels/chan_sip.so /usr/src/asterisk/channels/chan_sip.so.b4patch
cp -p /usr/lib/asterisk/modules/chan_sip.so /usr/lib/asterisk/modules/chan_sip.so.b4patch
mv /usr/src/asterisk/channels/chan_sip.c.orig /usr/src/asterisk/channels/chan_sip.c.orig.b4patch

{used mv here to rename the chan_sip.c.orig if there was one so it won't interfer with the application of the patch later on}

3) {Navigate to the Asterisk source directory where chan_sip.c is located}

cd /usr/src/asterisk/channels

4) {highlight the patch text from the webpage here and copy the text to your clipboard}

5) {open a blank text file named chan_sip_mj_patch.txt}

cat > chan_sip_mj_patch.txt

6) {right click the mouse on the putty window to paste the text into the open chan_sip_mj_patch.txt}

7) {use the keyboard command below to close and save the chan_sip_mj_patch.txt file}
{Edit: 22 Aug 2009 - After pasting the text into putty hit return once before the Cntrl-d to eliminate the unexpected end in middle of line warning during patch}

Cntrl-D

Cool {Apply the patch}
{Edit: 22 Aug 2009 modified the patch command to assist with tab vs. spaces in patch file}

patch -l <chan_sip_mj_patch.txt

9) {move up one level to the asterisk source directory}

cd ..

10) {Compile your new chan_sip.so...saving a copy of the compilation messages to /tmp/make.all}
{Edit: If you have problems with the following command on your distro then just use the plain make command.}

make all 2>&1|tee /tmp/make.all

{If no errors during the compilation then stop asterisk and install the new chan_sip.so}

11) {stop asterisk}

/usr/sbin/asterisk -rx "stop gracefully"

12) {Copy the new chan_sip.so to the asterisk modules directory}

cp -p /usr/src/asterisk/channels/chan_sip.so /usr/lib/asterisk/modules/chan_sip.so

13) {Restart Asterisk}

/usr/sbin/asterisk


Last edited by VaHam on Sun Aug 23, 2009 11:41 am; edited 5 times in total
Back to top
View user's profile Send private message
lowno
MagicJack Newbie


Joined: 09 Mar 2009
Posts: 7

PostPosted: Sat Aug 22, 2009 10:40 am    Post subject: Reply with quote

Wow, thanks a ton VaHam. I appreciate the detailed instructions.
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Sat Aug 22, 2009 11:56 am    Post subject: Reply with quote

lowno wrote:
Wow, thanks a ton VaHam. I appreciate the detailed instructions.


Your welcome let us know how you make out!
Back to top
View user's profile Send private message
bent
MagicJack Newbie


Joined: 10 Jun 2009
Posts: 4

PostPosted: Sat Aug 22, 2009 2:53 pm    Post subject: Reply with quote

Hi!
To pagemen
I think the first part of patch (check_auth) is not need, it's used only for incoming authentications with your peers.
And there is a little bug in code: variable newnonce is longer than necessary, it's need cut Smile

Code:

for (i = 0; i < 8; i++) {
                       hex[0] = newnonce[i];
                       int x = strtol(hex, NULL, 16);
                       *c++ = callid[x];
                       }
*c++ = 0;
^^^^^^^


Now working on incoming/outgoing calls w/o mjproxy.
Back to top
View user's profile Send private message
lowno
MagicJack Newbie


Joined: 09 Mar 2009
Posts: 7

PostPosted: Sat Aug 22, 2009 3:14 pm    Post subject: Reply with quote

I am working on it as per the instructions, I am currently stuck with at the following error in terminal:

File to patch: chan_sip.c
patching file chan_sip.c
Hunk #1 FAILED at 8535.
patch unexpectedly ends in middle of line
Hunk #2 FAILED at 11683.
2 out of 2 hunks FAILED -- saving rejects to file chan_sip.c.rej

I am trying to do this on my trixbox distro that has asterisk 1.4.22. Trixbox doesn't include sources, so I downloaded the sources from digium.

I'll keep hacking away at it.

Could someone possible post their recompiled chan_sip.so for 1.4.22?
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Sat Aug 22, 2009 4:44 pm    Post subject: Reply with quote

bent wrote:
Hi!
To pagemen
I think the first part of patch (check_auth) is not need, it's used only for incoming authentications with your peers.
And there is a little bug in code: variable newnonce is longer than necessary, it's need cut Smile

Code:

for (i = 0; i < 8; i++) {
                       hex[0] = newnonce[i];
                       int x = strtol(hex, NULL, 16);
                       *c++ = callid[x];
                       }
*c++ = 0;
^^^^^^^


Now working on incoming/outgoing calls w/o mjproxy.


First part is necessary or you'll see "Got 200 OK on REGISTER that isn't a register" warning message in log -- basically, server accepts our new md5 hash and return "200 OK" but Asterisk still checks the value against old routine thus thinks the return value is wrong.

And thanks for pointing out "*c++ = 0" part, will update the first post later. Seems that one works because the complier initializes all elements in the char array with '\0'...
Back to top
View user's profile Send private message
bent
MagicJack Newbie


Joined: 10 Jun 2009
Posts: 4

PostPosted: Sat Aug 22, 2009 5:00 pm    Post subject: Reply with quote

pagemen wrote:


First part is necessary or you'll see "Got 200 OK on REGISTER that isn't a register" warning message in log -- basically, server accepts our new md5 hash and return "200 OK" but Asterisk still checks the value against old routine thus thinks the return value is wrong.


About message "Got 200..." see, for example: http://forum.voxilla.com/asterisk-support-forum/got-200-ok-register-isnt-register-23269.html

I noticed magicjack not required auth on Registry, only on Invite.


Last edited by bent on Sat Aug 22, 2009 5:04 pm; edited 1 time in total
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Sat Aug 22, 2009 5:02 pm    Post subject: Reply with quote

lowno wrote:
I am working on it as per the instructions, I am currently stuck with at the following error in terminal:

File to patch: chan_sip.c
patching file chan_sip.c
Hunk #1 FAILED at 8535.
patch unexpectedly ends in middle of line
Hunk #2 FAILED at 11683.
2 out of 2 hunks FAILED -- saving rejects to file chan_sip.c.rej

I am trying to do this on my trixbox distro that has asterisk 1.4.22. Trixbox doesn't include sources, so I downloaded the sources from digium.

I'll keep hacking away at it.

Could someone possible post their recompiled chan_sip.so for 1.4.22?


Seems that you have some problem when retrieving the patch. Also please notice that, the original code using TAB for indent while the forum converts all TABs to spaces when posting the code, and the patch might fail when you c/p directly from the post. Try to use "patch -l" instead of "patch" when applying it.
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Sat Aug 22, 2009 5:15 pm    Post subject: Reply with quote

bent wrote:
pagemen wrote:


First part is necessary or you'll see "Got 200 OK on REGISTER that isn't a register" warning message in log -- basically, server accepts our new md5 hash and return "200 OK" but Asterisk still checks the value against old routine thus thinks the return value is wrong.


About message "Got 200..." see, for example: http://forum.voxilla.com/asterisk-support-forum/got-200-ok-register-isnt-register-23269.html

I noticed magicjack not required auth on Registry, only on Invite.


I'm not familar with * code, so whatever Smile Anyway, is there any side effect by adding the first part? if not, maybe we can just leave it there?
Back to top
View user's profile Send private message
lowno
MagicJack Newbie


Joined: 09 Mar 2009
Posts: 7

PostPosted: Sat Aug 22, 2009 5:31 pm    Post subject: Reply with quote

Thanks for the tip. i think it patched correctly. I fixed the tabs, then tried it with the "patch -l". I received the following response, but no error;s or anything like that.

patching file chan_sip.c
Hunk #1 succeeded at 8907 (offset 372 lines).
patch unexpectedly ends in middle of line
Hunk #2 succeeded at 11803 with fuzz 1 (offset 120 lines).

I am stuck at the compiling part now. I went up a directory and ran "make all 2>&1|tee /tmp/make.all", but get the following response:
make: *** No rule to make target `all'. Stop.

Thanks for all the help. I really appreciate it. I am trying to find a solution via google, sometimes it is a lot faster to just ask the experts.

pagemen wrote:
lowno wrote:
I am working on it as per the instructions, I am currently stuck with at the following error in terminal:

File to patch: chan_sip.c
patching file chan_sip.c
Hunk #1 FAILED at 8535.
patch unexpectedly ends in middle of line
Hunk #2 FAILED at 11683.
2 out of 2 hunks FAILED -- saving rejects to file chan_sip.c.rej

I am trying to do this on my trixbox distro that has asterisk 1.4.22. Trixbox doesn't include sources, so I downloaded the sources from digium.

I'll keep hacking away at it.

Could someone possible post their recompiled chan_sip.so for 1.4.22?


Seems that you have some problem when retrieving the patch. Also please notice that, the original code using TAB for indent while the forum converts all TABs to spaces when posting the code, and the patch might fail when you c/p directly from the post. Try to use "patch -l" instead of "patch" when applying it.
Back to top
View user's profile Send private message
bent
MagicJack Newbie


Joined: 10 Jun 2009
Posts: 4

PostPosted: Sat Aug 22, 2009 6:12 pm    Post subject: Reply with quote

Quote:
I am stuck at the compiling part now. I went up a directory and ran "make all 2>&1|tee /tmp/make.all", but get the following response:
make: *** No rule to make target `all'. Stop.

Try simple "make".

Quote:
I'm not familar with * code, so whatever Smile Anyway, is there any side effect by adding the first part? if not, maybe we can just leave it there?

No any side effect, except for extra code Smile
Back to top
View user's profile Send private message
lowno
MagicJack Newbie


Joined: 09 Mar 2009
Posts: 7

PostPosted: Sat Aug 22, 2009 6:23 pm    Post subject: Reply with quote

So I realized that the distro didn't have a compiler. Ran yum install gcc-c++ to get the compiler. The ran the make and got a gagillion errors. I would post it the output, but it would seriously annoy anyone looking at this thread. I think I may give up on this one.

Thanks for all the help guys.

bent wrote:
Quote:
I am stuck at the compiling part now. I went up a directory and ran "make all 2>&1|tee /tmp/make.all", but get the following response:
make: *** No rule to make target `all'. Stop.

Try simple "make".

Quote:
I'm not familar with * code, so whatever Smile Anyway, is there any side effect by adding the first part? if not, maybe we can just leave it there?

No any side effect, except for extra code Smile
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Sun Aug 23, 2009 4:52 pm    Post subject: Reply with quote

lowno wrote:
So I realized that the distro didn't have a compiler. Ran yum install gcc-c++ to get the compiler. The ran the make and got a gagillion errors. I would post it the output, but it would seriously annoy anyone looking at this thread. I think I may give up on this one.

Thanks for all the help guys.

bent wrote:
Quote:
I am stuck at the compiling part now. I went up a directory and ran "make all 2>&1|tee /tmp/make.all", but get the following response:
make: *** No rule to make target `all'. Stop.

Try simple "make".

Quote:
I'm not familar with * code, so whatever Smile Anyway, is there any side effect by adding the first part? if not, maybe we can just leave it there?

No any side effect, except for extra code Smile


I am a linux newbie but the makefile which gives instructions for make may be the problem. The reason for running make from /usr/src/asterisk is because that is where the makefile is stored at least in my distro. Could there be some cross up between your original makefile and one which would be appropriate for the new 1.4.22 asterisk version?
Back to top
View user's profile Send private message
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Mon Aug 24, 2009 2:30 am    Post subject: Reply with quote

I guess i am just a little slow when it comes to some Asterisk CLI.

I had this working. then I proceeded to clean up my AvantFax install by finishing configuring it. did a reboot and BAM... now the MJ's don't work.


I just dont get it.

i am getting a 400 response / congestion back!

anybody got a clue as to wtf happened?

I cant seem to find anything. so what I did is copy the old file back. then start all over with the last post of the first page of this thread. as it says it was updated.

I am running PIAF
Asterisk 1.4.21.2 and of course it has CentOS 5. on it.

thanks for the help! Question Shocked Question Shocked
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Mon Aug 24, 2009 4:36 am    Post subject: Reply with quote

completetech wrote:
I guess i am just a little slow when it comes to some Asterisk CLI.

I had this working. then I proceeded to clean up my AvantFax install by finishing configuring it. did a reboot and BAM... now the MJ's don't work.


I just dont get it.

i am getting a 400 response / congestion back!

anybody got a clue as to wtf happened?

I cant seem to find anything. so what I did is copy the old file back. then start all over with the last post of the first page of this thread. as it says it was updated.

I am running PIAF
Asterisk 1.4.21.2 and of course it has CentOS 5. on it.

thanks for the help! Question Shocked Question Shocked


The congestion error shows up when MJ is not getting authorized. Just a guess but sounds like during your cleanup you reverted to a old chan_sip.so perhaps.

The last post of the first page is a patch for Asterisk ver 1.4.15 and is updated as noted but still only applies for version 1.4.15. I am going to go add a second notice at the bottom of the post regarding that that post applies to version 1.4.15.

If your running Asterisk version 1.4.21.2 the updated patch for version 1.4.21 is in the first post of the thread. pagemen has been keeping the first post updated with fixes for the later versions there.

I don't think the patch for ver 1.4.15 could have been applied to ver 4.1.21.2 successfully. Didn't you get errors when applying the patch and recompiling?

How did you wind up with Asterisk version 1.4.21.2 as your Asterisk version in PIAF? My PIAF install admittedly was done many months ago, but has been updated to FreePBX 2.5.1.5 using the automated update features. The updates are all current and have only brought Asterisk up to version 1.4.15 on my system. Did you manually upgrade Asterisk outside of the FreePBX update system or something? The reason I ask is because the only reason I posted the patch for the older version is because I believe the very popular PIAF distro is not yet up to the latest version of Asterisk yet even with all current automatic updates applied.
Back to top
View user's profile Send private message
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Mon Aug 24, 2009 4:48 am    Post subject: Reply with quote

i just run the updates as directed on pbxinaflash.com/forum

i have ver 1.4.21.2

I ran all the commands again and copied the entire part of the code.

I just dont get how it was just fine and now after a reboot it is toast!!!!

any ideas

I guess can you maybe walk me through it again like the idiot i am. maybe the lack of sleep is wtf the issue is. lol....

if you got a step by step idea that would be great!
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Mon Aug 24, 2009 11:36 am    Post subject: Reply with quote

completetech wrote:
i just run the updates as directed on pbxinaflash.com/forum

i have ver 1.4.21.2

I ran all the commands again and copied the entire part of the code.

I just dont get how it was just fine and now after a reboot it is toast!!!!

any ideas

I guess can you maybe walk me through it again like the idiot i am. maybe the lack of sleep is wtf the issue is. lol....

if you got a step by step idea that would be great!


I posted as close to step by step as I know of IN THIS POST EARLIER for applying the patch.

If you scroll back in the thread you can see my PBXIAF setup which works as well.

By the entire part of the code do you mean you tried it again with pagmen's code in the first post of this thread? Did you get any errors during the patch or recompile?
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Mon Aug 24, 2009 2:32 pm    Post subject: Reply with quote

run "strings chan_sip.so | grep talk4free.com"
to check if the binary is patched or not.
Back to top
View user's profile Send private message
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Mon Aug 24, 2009 4:06 pm    Post subject: Reply with quote

ok I will give that a try when i get back to the office where it is at.

if not then how should I start all over and re-patch it?

I would really love to get this going so that I can use a MJ as a specific trunk for something.

thanks a bunch guys for all of yer work in getting this going.
Back to top
View user's profile Send private message
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Mon Aug 24, 2009 8:21 pm    Post subject: Reply with quote

completetech wrote:
ok I will give that a try when i get back to the office where it is at.

if not then how should I start all over and re-patch it?

I would really love to get this going so that I can use a MJ as a specific trunk for something.

thanks a bunch guys for all of yer work in getting this going.


chan_sip.so should be in two places if all is well.

/usr/src/asterisk/channels/chan_sip.so

and

/usr/lib/asterisk/modules/chan_sip.so

The latter is the one Asterisk uses at run time.
Back to top
View user's profile Send private message
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Mon Aug 24, 2009 8:43 pm    Post subject: Reply with quote

so bad news is that it is located in both.

any quick run down of how to start all over and get it going again. I am a little lost here!
Back to top
View user's profile Send private message
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Mon Aug 24, 2009 9:48 pm    Post subject: Reply with quote

VaHam wrote:
completetech wrote:
i just run the updates as directed on pbxinaflash.com/forum

i have ver 1.4.21.2

I ran all the commands again and copied the entire part of the code.

I just dont get how it was just fine and now after a reboot it is toast!!!!

any ideas

I guess can you maybe walk me through it again like the idiot i am. maybe the lack of sleep is wtf the issue is. lol....

if you got a step by step idea that would be great!


I posted as close to step by step as I know of IN THIS POST EARLIER for applying the patch.

If you scroll back in the thread you can see my PBXIAF setup which works as well.

By the entire part of the code do you mean you tried it again with pagmen's code in the first post of this thread? Did you get any errors during the patch or recompile?


yes i re-ran it.

what I did was remove teh newly edited version. then started all over. I am still getting a error 400 and congestion
Back to top
View user's profile Send private message
pagemen
Dan isn't smart enough to hire me


Joined: 15 Dec 2008
Posts: 128

PostPosted: Mon Aug 24, 2009 11:04 pm    Post subject: Reply with quote

Quick checklist:

1. strings /usr/lib/asterisk/modules/chan_sip.so | grep talk4free.com

you should see an output of "talk4free.com" so you know the chan_sip.so is patched

2. Use mjmd5/mjproxy with ATA or softphone to check if the password is correct and unchanged

3. If both look good, post your configuration and see if someone can get a hint on it.
Back to top
View user's profile Send private message
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Mon Aug 24, 2009 11:12 pm    Post subject: Reply with quote

I guess that from the few hours I had it working the password could have changed. I doubt it though. possible.

at this point I guess it is off to the router proxy add-on in order to get it to work. Sad
Back to top
View user's profile Send private message
mykroft
MagicJack User


Joined: 19 Oct 2008
Posts: 47

PostPosted: Mon Aug 24, 2009 11:18 pm    Post subject: Reply with quote

completetech wrote:
I guess that from the few hours I had it working the password could have changed. I doubt it though. possible.

at this point I guess it is off to the router proxy add-on in order to get it to work. Sad


check your PM's - I can walk you thru this either via MSN or a MJ call - let me know
Back to top
View user's profile Send private message MSN Messenger
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Thu Aug 27, 2009 12:06 am    Post subject: Reply with quote

slightly off topic.... but now for some reason i can not do

areacode+NXXXXXX and have it allow me 7 digit dialing..

any idea?
Back to top
View user's profile Send private message
mykroft
MagicJack User


Joined: 19 Oct 2008
Posts: 47

PostPosted: Thu Aug 27, 2009 5:32 am    Post subject: Reply with quote

completetech wrote:
slightly off topic.... but now for some reason i can not do

areacode+NXXXXXX and have it allow me 7 digit dialing..

any idea?


try 1|areacodeNXXNXXXX

or 1NXXNXXNXXXX

to force a 1 dial?
Back to top
View user's profile Send private message MSN Messenger
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Thu Aug 27, 2009 8:06 am    Post subject: Reply with quote

no i mean i want to dial seven digits.

i.e.... 222-2222

so my dial rule should look like

123+NXXXXXX
so that it passes
123-222-2222 when ?i dial 222-2222

but when i do that like I did before when it worked it will not let it pass
Back to top
View user's profile Send private message
mykroft
MagicJack User


Joined: 19 Oct 2008
Posts: 47

PostPosted: Thu Aug 27, 2009 4:13 pm    Post subject: Reply with quote

check your dial patterns on BOTH your trunks and outbound routes.

I dont use them on the trunks, i configure mine in the outbound routes so I can pick what trunk I need by how i dial
Back to top
View user's profile Send private message MSN Messenger
completetech
magicJack Apprentice


Joined: 26 Jul 2009
Posts: 16

PostPosted: Thu Aug 27, 2009 9:54 pm    Post subject: Reply with quote

i tried it that way and still get the message of your call can not be completed please try again later
Back to top
View user's profile Send private message
mykroft
MagicJack User


Joined: 19 Oct 2008
Posts: 47

PostPosted: Thu Aug 27, 2009 10:41 pm    Post subject: Reply with quote

I will try it when I get home
Back to top
View user's profile Send private message MSN Messenger
DarwinPeru
magicJack Apprentice


Joined: 03 Feb 2009
Posts: 28

PostPosted: Fri Aug 28, 2009 3:06 pm    Post subject: Reply with quote

lowno wrote:
I am stuck at the compiling part now. I went up a directory and ran "make all 2>&1|tee /tmp/make.all", but get the following response:
make: *** No rule to make target `all'. Stop.


Sorry if my english is not good, but Iowno: where are you doing make all 2>&1|tee /tmp/make.all ???

You have eject that in : The asterisk source directory (/usr/src/asteriskxxxx)

bye
Back to top
View user's profile Send private message
DarwinPeru
magicJack Apprentice


Joined: 03 Feb 2009
Posts: 28

PostPosted: Fri Aug 28, 2009 3:18 pm    Post subject: Thanks Reply with quote

Thanks for this tutorial, for me it is working good, I have Debian 5.0, Asterisk 1.6.0.13 and used the first patch.

now I can use my 5 MJ�s in the same time.

thanks

but....

I have a problem, I can�t to recive calls, I can make calls but I can�t recive calls, some one know why????????

my SIP:

register => ENUMBER01:[email protected]:5070/1234


[magicjack]
context=Gerente
username=ENUMBER01
type=friend
secret=XXXPASSWORDXXX
port=5070
nat=yes
insecure=very
host=proxy1.SanFrancisco.talk4free.com
fromuser=ENUMBER01
dtmfmode=inband
qualify=2500
dtmfmode=rfc2833
;disallow=all
;allow=g729


MY EXTENSIONS.CONF:

[Gerente]

exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@magicjack,30,tTr)
exten => _1NXXNXXXXXX,2,congestion()
exten => _1NXXNXXXXXX,102,busy()
exten => i,1,Hangup()
exten => t,1,Hangup()
exten => h,1,Hangup()


exten => 1234,1,Answer
exten => 1234,2,Dial(SIP/200,30,Ttr)
exten => 1234,3,Hangup()


and when I make a call to my MJ number my CLI show this message:

[Aug 28 14:19:44] WARNING[2645]: chan_sip.c:10502 check_auth: username mismatch, have <MYMJNUMBER>, digest has <EMYMJNUMBER01>
[Aug 28 14:19:44] NOTICE[2645]: chan_sip.c:17282 handle_request_invite: Failed to authenticate user <sip:[email protected]:5070>;tag=3584d42c-co6406-INS024


Please Help me...

Thanks a lot from Lima Per�
Back to top
View user's profile Send private message
mykroft
MagicJack User


Joined: 19 Oct 2008
Posts: 47

PostPosted: Fri Aug 28, 2009 3:50 pm    Post subject: Reply with quote

On my inbound routes I had to add E and 01 to my DID number, dunno when MJ starting doing this - but it has changed....
Back to top
View user's profile Send private message MSN Messenger
VaHam
Dan Should Pay Me


Joined: 13 Feb 2008
Posts: 851

PostPosted: Sat Aug 29, 2009 1:15 pm    Post subject: Re: Thanks Reply with quote

DarwinPeru wrote:
Thanks for this tutorial, for me it is working good, I have Debian 5.0, Asterisk 1.6.0.13 and used the first patch.

and when I make a call to my MJ number my CLI show this message:

[Aug 28 14:19:44] WARNING[2645]: chan_sip.c:10502 check_auth: username mismatch, have <MYMJNUMBER>, digest has <EMYMJNUMBER01>
[Aug 28 14:19:44] NOTICE[2645]: chan_sip.c:17282 handle_request_invite: Failed to authenticate user <sip:[email protected]:5070>;tag=3584d42c-co6406-INS024


Hopefully mykroft's hint about matching the inbound exactly with your fromuser got you going.

I think you could also have set the global parameter to accept anonymous sip calls and that would have worked as well. If you use ENUM to allow incoming sip calls I think you need to set the allow anonymous sip for that to work as well.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    magicJack and magicJack Plus Support, Reviews, FAQs and Hacks Forum Index -> magicJack Tips, Tricks, and Hacks All times are GMT - 4 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB Turbo Extended Edition © 2010, phpBB Group