How To Use API of OpenVox GSM Gateway
How To Use API of OpenVox GSM Gateway
App Note
VoxStack GSM Gateway API
Rev: 1.0
Date: August 05, 2013, Rev 1.0
From:
Content
TABLE OF CONTENTS
10
10
10
13
19
19
21
Protocol Characteristics
When the first line of packets is Action, it indicates that the packets have been
When the first line of packets is Event or Response, it indicates that the
packets from OpenVox GSM Gateway Asterisk have been received by clients
management program.
The break line is used to isolate every line. Double return indicates the end
of commands and OpenVox GSM Gateway Asterisk begins to deal with
commands.
Event: Some information about OpenVox GSM Gateway Asterisk core events.
Notice: Concerning the Permit option, if you have one more IP addresses, you
can input them with symbol &. In the demo test, allow servers
172.16.0.81 and 172.16.0.82 to access to the GSM Gateway.
You can define read/write authorization for various events.
Notice: In this illustration, you will be able to define custom authorization for
various events, Read authorization permits you to receive asynchronous
events, in general, write authorization permits you to send commands
and get responses.
You can edit the file and save, then reload the configuration.
Command:
asterisk r
core reload
OpenVox Communication Co. LTD.
Create Connection
Create Connection
Using Telnet to Demonstrate AMI Connectivity over TCP Socket
Here shows how to get access to the gateway and some responds to the actions from
OpenVox GSM Gateway AMI.
You must send a Login action to log in your GSM Gateway Asterisk server. Then
input your username and password.
Notice: If you want to send commands, please press double [Enter] key.
Now we have guided you to the first command:
Login: Start a Manager session
AMI over TCP for Windows
Yes, you can get access to your OpenVox GSM Gateway over AMI protocol in
Windows system. Please follow this flow:
Click Start Run Open, at the input text box, type cmd to enter a Windows
console.
Hit the [Enter] key, and it will automatically skip to the next illustration.
Create Connection
Create Connection
fflush(stdin);
memset(login_buf,'\0',40);
sprintf(login_buf,"action:Login\r\nusername:%s\r\nsecret:%s\r\n\r\n",username,secre
t);
login_len = strlen(login_buf);
if(res = write(sock_fd,login_buf,login_len) == login_len)
{
sleep(1);
memset(receive_buf,'\0',4096);
if(res = read(sock_fd,receive_buf,sizeof(receive_buf))<0)
{
perror("login failed\n");
return;
}
printf("%s\n",receive_buf);
if(NULL != strstr(receive_buf,"Authentication accepted"))
{
printf("login success\n");
}
}
}
int main(void)
{
int client_socket;
struct sockaddr_in client_addr;
char ServerIp[20];
memset(ServerIp,'\0',20);
printf("Please input your server ip address\n");
scanf("%s",ServerIp);
fflush(stdin);
client_socket = socket(AF_INET,SOCK_STREAM,0);
if(client_socket < 0)
{
OpenVox Communication Co. LTD.
Create Connection
perror("create socket error\n");
return -1;
}
client_addr.sin_family = AF_INET;
client_addr.sin_port
= htons(5038);
client_addr.sin_addr.s_addr = inet_addr(ServerIp);
//connect
if(connect(client_socket,(struct sockaddr *)&client_addr,sizeof(client_addr))<0)
{
perror("connect error\n");
return -1;
}
else
{
printf("connect to %s success\n",ServerIp);
}
login_fun(client_socket);
return 0;
}
10
Action: command.
Description: Execute a CLI command
Step 1: Login your AMI server.
Step 2: Use the AMI action to send SMS
The client manager will receive an event repot when you have message comes in.
For example:
NoticeIf you need know the status that send sms. Please use
gsm send sync sms <span> <destination> <message> <timeout> [id]
for example:
11
In the whole transaction, you can find a code segment above. This section is the most
important when you want to monitor the incoming short messages. Asterisk
(Gateway core) will report a new event to the client.
Arguments:
OpenVox Communication Co. LTD.
12
Event: Newexten
When a new short message comes in, Asterisk (Gateway core) will report a
new event to client.
Priviledge: Dialplan
Allowed event
Channel: EXTRA-SMS/3-1
The channel to be used
Context: gsm-2
Context name
Extension: sms
Transaction type. When the short message comes in, the gateway will
invoke sms extension.
Priority: 1
Executed priority first while shore message coming in.
AppData: This is a short message from my mobile phone. Data which will be saved in
CDR
Notice: If TCP socket connection is still alive, and you receive parameters Newexten
and sms, that indicates there is a new short message coming in. You can use Ping
action to check if your connection is alive or not, and monitor the incoming short
message by these two events.
Using the Program to Create a Simple SMS/USSD Center
This program works with C language sending and receiving SMS, based on our first
program.
Compile command:
gcc send_sms.c o send_sms
void sendsms_fun(int sock_fd)
{
char send_buf[4096];
char span_num[3];
char destination[12];
char message[2048];
int res;
int send_len;
char receive_buf[4096];
13
memset(send_buf,'\0',4096);
memset(destination,'\0',11);
memset(message,'\0',2048);
memset(span_num,'\0',3);
printf("please input the span you want used\n");
scanf("%s",span_num);
fflush(stdin);
printf("please input the destination num you want send\n");
scanf("%s",destination);
fflush(stdin);
printf("Please input the message you want send\n");
scanf("%s",message);
fflush(stdin);
sprintf(send_buf,"action:Command\r\ncommand:GSM send
sms %s %s %s\r\n\r\n",span_num,destination,message);
send_len = strlen(send_buf);
memset(receive_buf,'\0',4096);
printf("%s\n",send_buf);
if(res = write(sock_fd,send_buf,send_len) == send_len)
{
sleep(1);
if(res = read(sock_fd,receive_buf,sizeof(receive_buf))<0)
{
perror("send sms error\n");
return;
}
printf("%s\n",receive_buf);
if(NULL != strstr(receive_buf,"Response: Follows"))
{
printf("send SMS success\n");
}
}
}
int main(void)
14
{
int client_socket;
struct sockaddr_in client_addr;
char ServerIp[20];
memset(ServerIp,'\0',20);
printf("Please input your server ip address\n");
scanf("%s",ServerIp);
fflush(stdin);
client_socket = socket(AF_INET,SOCK_STREAM,0);
if(client_socket < 0)
{
perror("create socket error\n");
return -1;
}
client_addr.sin_family = AF_INET;
client_addr.sin_port
= htons(5038);
client_addr.sin_addr.s_addr = inet_addr(ServerIp);
if(connect(client_socket,(struct sockaddr *)&client_addr,sizeof(client_addr))<0)
{
perror("connect error\n");
return -1;
}
else
{
printf("connect to %s success\n",ServerIp);
}
//login
login_fun(client_socket);
//send SMS
sendsms_fun(client_socket);
return 0;
}
Now use the program receive SMS.
This program base on our first program.
15
16
strcpy(temp_buf,receive_AppData);
}
if((temp=strstr(temp_buf,"process_sms"))!=NULL)
{
for(i = 0;i<13;i++)
{
temp++;
}
strncpy(SMS_buf.span,temp,1);
for(i=0;i<7;i++)
{
temp++;
}
strncpy(SMS_buf.sender_num,temp,11);
for(i =0;i<14;i++)
{
temp++;
}
strncpy(SMS_buf.receive_time,temp,19);
for(i = 0;i<22;i++)
{
temp++;
}
strcpy(SMS_buf.message_buf,temp);
printf("span = %s\n",SMS_buf.span);
printf("num=%s\n",SMS_buf.sender_num);
printf("time = %s\n",SMS_buf.receive_time);
printf("message = %s\n",SMS_buf.message_buf);
}
//printf("span = %s\n",SMS_buf.span);
}
}
}
int main(void)
{
int client_socket;
17
= htons(5038);
client_addr.sin_addr.s_addr = inet_addr(ServerIp);
if(connect(client_socket,(struct sockaddr *)&client_addr,sizeof(client_addr))<0)
{
perror("connect error\n");
return -1;
}
else
{
printf("connect to %s success\n",ServerIp);
}
login_fun(client_socket);
//sendsms_fun(client_socket);
readsms_fun(client_socket);
return 0;
}
18
Privilege
-----------
Synopsis
-----------
waitEvent
<none>
SIPnotify
system,all
SIPshowregistry
system,reportin
SIPqualifypeer
system,reportin
SIPshowpeer
system,reportin
SIPpeers
system,reportin
AGI
agi,all
DBDelTree
system,all
delete DB Tree
DBDel
system,all
delete DB entry
19
DBPut
system,all
put DB entry
DBGet
system,reportin
Bridge
call,all
Park
call,all
park a channel
ParkedCalls
<none>
ShowDialPlan
config,reportin
AOCMessage
aoc,all
ModuleCheck
system,all
ModuleLoad
system,all
module management
CoreShowChannel system,reportin
Reload
system,config
CoreStatus
system,reportin
CoreSettings
system,reportin
UserEvent
user,all
UpdateConfig
config,all
SendText
call,all
ListCommands
<none>
MailboxCount
call,reporting,
MailboxStatus
call,reporting,
Check mailbox
AbsoluteTimeout system,call,all
ExtensionState
call,reporting,
Command
command,all
Originate
originate,all
Originate a call
Atxfer
call,all
Attended transfer
Redirect
call,all
ListCategories
config,all
CreateConfig
config,all
Status
system,call,
GetConfigJSON
system,config
GetConfig
system,config,a
Retrieve configuration
Getvar
call,reporting,
Setvar
call,all
Ping
<none>
Keepalive command
Hangup
system,call,all
Hangup channel.
Challenge
<none>
Login
<none>
Login Manager
Logoff
<none>
Logoff Manager
Events
<none>
DataGet
<none>
20
Notice: If you want to know the active channels, please run CLI command:
Core show channel SIP/[tab]
C. (1)CoreShowChannles: List current defined channels and some information
about them.
Action: CoreShowChannels
Example:
Action: CoreShowChannels
Return information:
Response: Success
EventList: start
Message: Channels will follow
21
Example:
Action: CreateConfig
Filename: test.conf
22
Example:
Action: Events
EventMask: on
Example:
Action: ExtensionState
Context: default
Exten: 1001
Return:
Responese: success
Message: Extension Status
Exten: 1001
Context: default
Hint:
Status: -1
Status:
-1: cant find exten
0: ready
1: be used
2: busy
4: no available
8: ring
16:waiting
OpenVox Communication Co. LTD.
23
L. (1)ListCommands: Returns the action name and synopsis for every action that is
available to the user.
Example:
Action: ListCommands
S. (1)SIPpeers: List SIP peers in text format, details on current status.peerlist will
follow as separate events, followed by a final event called peerlistComplete.
24
Example:
Action: SIPpeers
25