Monday, August 14, 2006

Tesco's VOIP & Asterisk

UPDATE (2007-01-06) - I think the problems with Asterisk's registration expiring with Tesco is due to a bug in Asterisk. Have a look at my new post on the issue. You can find a link to the bug report I filed, which includes a patch against Asterisk 1.4.

Tesco's internet phone uses Asterisk's own protocol (IAX2), so you would think it should be relatively simple to get my asterisk server talking to it, and it almost is. I've been able to get my asterisk server and Tesco talking, by using the following:

iax.conf

[general]
bandwidth=low
diallow=lpc10
jitterbuffer=no
forcejitterbuffer=no
tos=lowdelay
;autokill=yes

register => TESCONUMBER:password@gateway.tescointernetphone.com

[TESCONUMBER]
type=friend
context=tesco
auth==md5
username=TESCONUMBER
secret=password
host=gateway.tescointernetphone.com
qualify=no


and the following in extensions.conf

[macro-outtesco]
exten => s,1,SetCallerID("TESCONUMBER" <TESCONUMBER>)
exten => s,2,Dial(IAX2/TESCONUMBER:password@gateway.tescointernetphone.com/${ARG1},${ARG2},r)
exten => s,3,Congestion


[tesco]
exten => INTTESCONUMBER9,1,Dial(SIP/scot)
exten => INTTESCONUMBER9,1,Answer()
exten => INTTESCONUMBER9,2,Echo()



Where TESCONUMBER is my Tesco telephone number, INTESCONUMBER is the international version of my tesco number (ie drop the leading 0 and add 44) and password is the password. Note the 9 after the INTTESCONUMBER. I was able to figure this out from the information about using the Australian Firefly/Freshtel service, as they are the people who provided Tesco the voip system and from looking at where Tesco's client is calling out to (gateway.tescointernetphone.com). This mostly works - I can dial out and recieve calls, but reception only works for a short period of time after I start asterisk or I reload iax2. Fortunatly, I think I've worked out why.

When asterisk registers itself with Tesco, one of the parameters that gets sent back is the length of time between registration refreshes (which lets Tesco know that I'm still online and listening). If asterisk doesn't recieve that parameter back, it assumes that it should refresh every 60 seconds. However, Tesco send back a value of 0, which gives the following little warning from asterisk:

Aug 12 21:57:19 NOTICE[3917]: sched.c:234 ast_sched_add_variable: Scheduled event in 0 ms?

A side effect of getting sent a refresh value of 0 is that Asterisk never sends out a registration refresh request, so Tesco assumes that we've gone offline. From what I've been able to gather from seaching through google and looking at the source to asterisk, there is no way to overide the setting that gets sent from the server (though I could be wrong). As such, I modified the source so that if it gets a value of 0, it changes it to 60. So far, this seems to work.

3 comments:

Rob Walker said...

Interesting! I've been wanting to do this for a while. How did you modify the source? Could you make this available to linux newbies like myself??

JamesM said...

Scot very intrested to see your patch as well I have been looking at the code my self but as i am not a programer it would take me a few days with the help of google to work out how to fix the code and then to create a small patch fix for the source code and then to recompile it so any help or tips would be great.

00214 int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, void *data, int variable)
00215 {
00216 struct sched *tmp;
00217 int res = -1;
00218 DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n"));
00219 if (!when) {
00220 ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n");
00221 return -1;
00222 }

Maria said...

Can you tell me something about Centrex and IAX2 Phone and what are the features of these product.