Please note that Sangoma Media Gateway is designed to work in CentOS 5.
If you are using any other Linux distribution some instructions may not work exactly, however with a bit of tweaking you should be able to get it to work.


== Sangoma Media Gateway Installation ==

- Install the latest version of the Wanpipe drivers first from http://wiki.sangoma.com/wanpipe-linux-drivers

	# tar xfz wanpipe-x.x.x.tgz
	# cd wanpipe-x.x.x
	# make freetdm
	# make install

- Go to ftp://ftp.sangoma.com/linux/smg/3.x/ and download sangoma-media-gateway-<os>-<arch>-3.x.x.tar.gz

- Untar the sangoma-media-gateway distribution:

	# tar -xzf sangoma-media-gateway-<os>-<arch>-3.x.x.tar.gz
	# cd sangoma-media-gateway-<os>-<arch>-3.x.x
	# make DESTDIR=/usr/local/smg install

You can choose any other DESTDIR or not specify it at all to leave the default. 

- You can now start the web interface doing:
	
	# service smg-webgui start

- You can also add sangoma media gateway service to the boot sequence (to start automatically the next time you restart your server) by doing:

	# make boot

This will launch the web server, you can now connect with any web browser to your server to configure the gateway using port 8888: ie http://192.168.1.100:8888/

== Configuration ==
Default is $prefix = /usr/local/smg/

During this instructions We assume the gateway install $prefix is /usr/local/smg

- The main configuration is located at $prefix/conf/smg.xml, the default configuration is good enough, but you are encouraged to change default credentials at least.

- Configure your TDM spans in:

	- $prefix/conf/freetdm.conf
	- $prefix/conf/autoload_configs/freetdm.conf.xml

Remember that any span configured in freetdm.conf.xml *MUST* have the <param name="context" value="$${pstn_context}"/> in order to work properly (send all pstn calls towards the SIP registered peers).
See the sample freetdm.conf.xml provided for details.

The default SIP configuration is to wait for register requests on port 5062, user and password "sangoma". You are encouraged to change the default user and password. To do this edit "smg.xml" in "$prefix/conf" and just run "/etc/init.d/sangoma-media-gateway restart" and this will apply the change.

All registered endpoints will receive the PSTN calls. The first one answering will get the call.

WARNING: is not recommended to touch any other configuration files unless you really understand what you are doing.

== Starting the gateway ==

You can start the gateway from the web administration panel. To start the web panel you must run this command:

	# service smg-webgui start

This will start the web server. You can now use your favorite web browser (firefox, chrome etc) to access http://<server-ip>/

Sangoma Media Gateway is composed of FreeSWITCH + FreeTDM Sangoma PSTN stacks. If you want to start the service manually run this command:

	# service sangoma-media-gateway start

This will start FreeSWITCH in safe mode. You can access the CLI by executing 

	# smg_cli 

The smg_cli program is located at /usr/sbin, so you must have that in your $PATH environment variable or execute it using the full path.

== Dialing to the gateway ==

The Gateway understand some special SIP URL pattern to pass parameters.

The following is the pattern used by the gateway:

sip:number[-g=<group name>][-h=<hunt identifier>][-fax]

The -g or -h and -fax options are not mandatory, default group and hunting (as specified in smg.xml) will be used if they are missing.
and no T.38 will be performed if -fax is not specified.

The -g option is to determine the group to be used by the gateway for the hunting:

-g=<group name> where group name is the name of a group defined in freetdm.conf

The -h option determines the hunting scheme.

-h=[A|a] where A is to hunt from bottom to top and a is from top to bottom.

The -fax option enables T.38 in the gateway. If you need -fax, you must specify both -g and -h too.

Asterisk Examples:

This examples assume sangomagw is the host name resolving the IP address of the gateway.

SIP/1234@sangomagw - This will use the default PSTN group and hunting scheme (as defined in smg.xml)
SIP/1234-g=wp1@sangomagw - This will use the group wp1 with the default hunting scheme defined in smg.xml
SIP/1234-h=A@sangomagw - This will use the hunting scheme A (bottom to top) and the default group defined in smg.xml
SIP/1234-g=wp1-h=A@sangomagw - This will use the group named "wp1" and hunting scheme "A" (bottom to top).

== Transcoding ==
If you wish to enable Sangoma Media Gateway Transcoding using D-Series Sangoma transcoding cards, you have to:

1. Configure the transcoding server (you need to be root) for your D-Series cards using $prefix/sbin/sngtc_cfg tool.
	
	# cd $prefix/sbin/

	# ./sngtc_cfg --server --asterisk

	or

	# ./sngtc_cfg --server --freeswitch

	This should place the configuration in /etc/sngtc

2. Enable transcoding in /etc/smg/sangoma-media-gateway.conf by setting SMG_TRANSCODING_SERVER=YES

3. Configure $prefix/conf/autoload_configs/sangoma_codec.conf.xml

4. Add mod_sangoma_codec in $prefix/conf/autoload_configs/modules.conf.xml

5. Start the transcoding daemon with 'service sngtc_server_ctrl start'. You can set it in the boot sequence by doing "make boot"
   

