Archive

Archive for the ‘Linux’ Category

Configuring Asterisk to work with Broadvoice SIP

September 15th, 2009 jesse No comments

We recently dumped our land line in favor of and end-to-end VOIP solution. For some reason voice networks haven’t received the fully automated treatment IP networks have enjoyed, so it was something os an involved process. The process was not helped by Broadvoice’s “bring your own device” instructions, which are wrong.

The system is very simple: enable a set of SIP IP phones to make and receive calls through our own IP PBX. This was done through a PRI, which we replaced with a VOIP trunk (running SIP) with an external phone company (Broadvoice).

asterisk-pbx-setup

Here’s what we did (after some trial and error).

Set up and configure the Ubuntu 9.04 server with Asterisk:

Very easy: Just install Asterisk.

% sudo apt-get install asterisk

Make a back up of config files. In /etc/asterisk:

% sudo mkdir -p Defaults
% sudo cp * Defaults/

Configure Cisco 7960 IP Phones and Asterisk

There are two ways to configure the Cisco IP phones: via TFTP or from the key pad. Either way, you’ll want to set up the following:

1) On Asterisk server, edit /etc/asterisk/sip.conf

Add the following at the very bottom of the file:

[username] ; this is the phone’s log in username (use something cute like phone1)
secret=password ; this is the phone’s log in password
username=KeyBridge ; this is the displayed outbound caller id
type=friend
user=phone
context=default
qualify=200
nat=no
host=dynamic
canreinvite=no

Note: Do NOT use your Broadvoice phone number for the Cisco username. It will confuse Asterisk. Instead, use something cute like ‘line1′ or ‘frontdesk’.

2) On the Cisco IP phone

First unlock the phone: hit [settings], then [9] Unlock Config and enter your phone password

Then configure your phone:

[4] SIP Configuration

[1] Line 1 settings

[1] Name should be set to the ‘username’ you chose in the asterisk configuration above
[2] Shortname is what this ‘line’ will be called on the local display. Try ‘Line 1′
[3] Authentication Name is the same as [1]
[4] Authentication Password is the ‘secret’ you specified in sip.conf
[5] Shortname is what this ‘line’ will be called on the local display. Try ‘Line 1′ (duplicate?)
[6] Proxy Address the IP address of your Asterisk server
Hit the [Save] smart key to save the new configuration.

Getting your Broadvoice SIP password

A word of caution: The Broadvoice portal password you set during account creation is NOT your SIP password. To get the SIP password, log in to the Broadvoice portal, then click [Account] on the tab and [Show Settings] under the My Devices block. Your SIP password follows the ‘auth_password[1]‘ text.

Configure Asterisk to Broadvoice SIP Trunk

On the Asterisk Ubuntu server, edit SIP.conf.

In the [general] section, uncomment the following lines:

disallow=all ; First disallow all codecs
allow=ulaw ; Allow codecs in order of preference
allow=ilbc ; see doc/rtp-packetization for framing options
allow=gsm ; Allow codecs in order of preference

Also in the [general] section, add a register command using the following format. (Note – the Broadvoice instructions are wong – they tell you use use some craziness like PHONENUMBER@sip.broadvoice.com as your username – follow this template).

register => PHONENUMBER:PASSWORD:PHONENUMBER@sip.broadvoice.com/PHONENUMBER

Obviously, substitute your own phonenumber and password.

At the bottom of the file (before of after your Cisco phone – it doesn’t matter) add a Broadvoice entry as follows:

[sip.broadvoice.com]
type=peer
user=phone
host=sip.broadvoice.com
fromdomain=sip.broadvoice.com
fromuser=USERNAME
secret=PASSWORD
username=USERNAME
insecure=very
authname=USERNAME
dtmfmode=inband
dtmf=inband

Edit extensions.conf

Now we’re done with sip.conf. Close it and let’s create the necessary dial plan. It’s easiest to start from scratch. Since we made a backup in ‘Defaults’, delete the file and create a new one.

% rm extensions.conf
% vi extensions.conf

Here is my complete file:

[general]
static=yes
writeprotect=no
clearglobalvars=no

[default]
; Broadvoice Domestic Dialplan
exten => _1NXXNXXXXXX, 1, dial(SIP/${EXTEN}@sip.broadvoice.com,30)
exten => _1NXXNXXXXXX, 2, congestion()
exten => _1NXXNXXXXXX, 102, busy()

; Broadvoice International Dialplan
exten=_011.,1,dial(SIP/${EXTEN}@sip.broadvoice.com,30)
exten=_011.,2,congestion() ; No answer, nothing
exten=_011.,102,busy() ; Busy

; Forward inbound calls to SIP Phone
exten => USERNAME, 1 , Dial(SIP/CISCOPHONE,20,rt)

Again, obviously substitute your Broadvoice phone number for ‘USERNAME’ and your Cisco phone username for ‘CISCOPHONE’

Start/restart Asterisk and you should be able to make and receive calls.

% sudo /etc/init.d/asterisk restart

A few quick confirmations just to see everything is working:

% sudo asterisk -vvvvr

> sip show peers
> sip show users
> show dialplan

Categories: Linux Misc Tags:

VI : Convert Upper to Lower Case

May 25th, 2009 jesse No comments

I knew this was possible, but wasn’t sure exactly how.

:%s/[A-Z]/\l\0/g

or

:%s/[A-Z]/\L&/g

Categories: Linux Misc Tags:

MySQL Foreign Keys

May 7th, 2009 jesse No comments

db schema

We’re trying to create a series of cross-referencing database tables in MySQL using foreign keys. However, despite following the documentation the linking did not seem to work.

I found that MySQL by default uses MyISAM for the DB engine, which does not support FOREIGN KEYs.

The solution is to force MySQL to use the INNODB engine.

For example: This will not work.

CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;
CREATE TABLE child (id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=MyISAM;

This is how is should be written:

CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;

A frustrating detail.

Categories: Java Development, Linux Misc Tags:

Compiling Splat! on Ubuntu 8.10 x86_64

April 29th, 2009 jesse No comments

SPLAT! is an RF Signal Propagation, Loss, And Terrain analysis tool for the spectrum between 20 MHz and 20 GHz.

Unfortunately, compiling this out of the box threw a number of compiler errors. Here’s what I found & how I fixed it.

8854

Target system:

  • Ubuntu 8.10 x86_64 (64 bit)

Supporting libraries installed for this program:

  • libbz2-dev
  • libzzip-dev
  • llib1g-dev

splat.cpp

Problem:
Compiler complains of a potential buffer overrun

Details:
Offending lines are here:
line 1663 strncat(path_plus_name,sdf_file,255);
line 1896 strncat(path_plus_name,sdf_file,255);

The offending variables are declared here:
line 1612 char path_plus_name[255]
line 1842 char path_plus_name[255]

Solution:
Double the path_plus_name char size to 512 bytes

Explanation:
On lines 1663 and 1896 strncat creates a potential buffer overrun condition by concatenating sdf_file[255] with path_plus_name[255]. There is some earlier logic that ensures this won’t happen, but the compiler throws a fit regardless. This is corrected by doubling the path_plus_name size to 512 byte.
Line 1612 modified char path_plus_name[512]
Line 1852 modified char path_plus_name[512]

Background:
char * strncat ( char * destination, char * source, size_t num );
Appends the first num characters of source to destination, plus a terminating null-character. If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.

destination
Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string, including the additional null-character.

source
C string to be appended.

num
Maximum number of characters to be appended.

Build Error Messages:
Compiling SPLAT!…

In function ‘char* strncat(char*, const char*, size_t)’,
inlined from ‘int LoadSDF_SDF(char*)’ at splat.cpp:1663:
/usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, long unsigned int, long unsigned int) might overflow destination buffer

In function ‘char* strncat(char*, const char*, size_t)’,
inlined from ‘int LoadSDF_BZ(char*)’ at splat.cpp:1896:
/usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, long unsigned int, long unsigned int) might overflow destination buffer

Done!

Compiling SPLAT! HD…

In function ‘char* strncat(char*, const char*, size_t)’,
inlined from ‘int LoadSDF_SDF(char*)’ at splat.cpp:1663:
/usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, long unsigned int, long unsigned int) might overflow destination buffer

In function ‘char* strncat(char*, const char*, size_t)’,
inlined from ‘int LoadSDF_BZ(char*)’ at splat.cpp:1896:
/usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, long unsigned int, long unsigned int) might overflow destination buffer

Compiling srtm2sdf…

In function ‘strncat’,
inlined from ‘LoadSDF_SDF’ at srtm2sdf.c:264:
/usr/include/bits/string3.h:153: warning: call to __builtin___strncat_chk might overflow destination buffer
In function ‘strncat’,
inlined from ‘LoadSDF_BZ’ at srtm2sdf.c:371:
/usr/include/bits/string3.h:153: warning: call to __builtin___strncat_chk might overflow destination buffer


splat.cpp

Problem:
Building with parameter (8) 8 x 8 Degrees ——— 3330 Megabytes minimum”
sets the following in hd-parms.h
#define MAXPAGES 64
and causes compiler link errors:
collect2: ld returned 1 exit status

Explanation:
For some reason the branches are too large for the opcode field. (Don’t know enough about the GCC compiler at this time to explain in more detail.)

Solution:
Use a smaller build parameter. (6) worked for me.

Output of the faultly build:
Compiling SPLAT! HD… /tmp/cc0XOrhm.o: In function `LoadDBMColors(site)’:
splat.cpp:(.text+0x2cc): relocation truncated to fit: R_X86_64_PC32 against symbol `region’ defined in .bss section in /tmp/cc0XOrhm.o
splat.cpp:(.text+0x2d6): relocation truncated to fit: R_X86_64_PC32 against symbol `region’ defined in .bss section in /tmp/cc0XOrhm.o
splat.cpp:(.text+0x2ff): relocation truncated to fit: R_X86_64_PC32 against symbol `region’ defined in .bss section in /tmp/cc0XOrhm.o

splat.cpp:(.text+0×343): relocation truncated to fit: R_X86_64_PC32 against symbol `region’ defined in .bss section in /tmp/cc0XOrhm.o
splat.cpp:(.text+0x34a): additional relocation overflows omitted from the output
collect2: ld returned 1 exit status


srtm2sdf.c

Problem:
Same buffer overrun complaint as splat.cpp

Solution:
Same solution: double the size of path_plus_name[255] to [512] in two places:
Line 264 modified char path_plus_name[512]
Line 371 modified char path_plus_name[512]

Build Error messages:
Compiling srtm2sdf… In function ‘strncat’,
inlined from ‘LoadSDF_SDF’ at srtm2sdf.c:264:
/usr/include/bits/string3.h:153: warning: call to __builtin___strncat_chk might overflow destination buffer
In function ‘strncat’,
inlined from ‘LoadSDF_BZ’ at srtm2sdf.c:371:
/usr/include/bits/string3.h:153: warning: call to __builtin___strncat_chk might overflow destination buffer

Links >

Categories: Linux Misc Tags:

Shell script to change filename case from upper to lower / lower to upper

February 19th, 2009 jesse No comments

Use this script to change case names of all files in the current directory. Code:

#!/bin/sh
# Script to change name from upper to lower / lower to upper
# <usage> [lower | upper]
if [[ $# -ne 1 ]]
then
  echo "Usage: $0 [lower|upper]"
  exit 1
fi
for file in `find . -type f`
do
  if [[ "$1" = "lower" ]]
  then
    mv $file $(echo $file | tr [[:upper:]] [[:lower:]])
  elif [[ "$1" = "upper" ]]
  then
    mv $file $(echo $file | tr [[:lower:]] [[:upper:]])
  else
    echo "Unknown option $1. Use upper | lower"
  exit 1
fi
done
exit 0
Categories: Linux Misc Tags: