OpenVox Document Center OpenVox Document Center
  • Home 
  • Products 
  • Solutions 
  • Resources 
    • Document Center 
    • Datasheets 
    • Firmwares 
    • Videos 
  • Partners 
  • Blog 
  • Company 
OpenVox Document Center OpenVox Document Center
OpenVox Document Center
  • Home 
  • Products 
  • Solutions 
  • Resources 
    • Document Center 
    • Datasheets 
    • Firmwares 
    • Videos 
  • Partners 
  • Blog 
  • Company 

EOL-Product

  • folder icon closed folder iconUser Manual
    • iCallDroid User Manual
    • iCallDroid spot User Manual
    • IX120 User Manual
    • IX132 Series IP-PBX User Manual
    • SWG2008_User_Manual
    • SWG-1016C User Manual
    • WGW1002 User Manual
    • VS-GW1202-8G User Manual
    • VS-GW1600 User Manual
    • VS-GW2120 Series User Manual
    • 3G Gateways User Manual
    • A800E on DAHDI User Manual
    • A800P on DAHDI User Manual
    • A1200E on DAHDI User Manual
    • A1200P on DAHDI User Manual
    • D110P /D110E on DAHDI User Manual
    • D115P/DE115P on Elastix User Manual
    • DE115P/DE115E on DAHDI User Manual
    • G400P/G400E/G410P/G410E User Manual
    • iAG804/iAG808 User Manual
    • iAG840/iAG880 User Manual
  • folder icon closed folder iconDatasheet
    • VS-GW1600 GSM Series Datasheet
    • VS-GWM400 Datasheet
    • VS-GWM400W Datasheet
  • folder icon closed folder iconQuick Start Guide
    • Quickstart Guide of VS-GW1600-20G Connect with VOS3000 Operation Platform
    • Quickstart Guide of VS-GW1600-20G Connect with 3CX Server
    • Quickstart Guide of VS-GW1600-20G Connect with Asterisk Server
    • Quickstart Guide of VS-GW1600-20G Connect with Elastix Server
    • Quickstart Guide of VS-GW1600-20G Connect with FreeSWITCH Server
  • folder icon closed folder iconAPP Note
    • GSM Gateways APP Note
      • APP Note_AMI
      • Expand Callback Function
      • How to Bind the GSM Gateway Ports with PBX Sip Extension
      • How to Integrate the Analog Gateway and the GSM Gateway in One OpenVox Box
      • OpenVox GSM Gateway Function User Manual
      • OpenVox GSM Gateway HTTP Interface
      • Openvox HTTP SMS API Demo
      • OpenVox Wireless Gateway Connect with playSMS Manual
      • Remote Server Get CDR from GSM Gateway by AMI
      • VoxStack GSM Gateway API 1.0.0
      • VoxStack GSM Gateway Connect with iCallDrid Manual
      • VoxStack GSM Module Upgrading Guide
  • folder icon closed folder iconFAQ
    • IPC100/110
loading
Popular Searches
  • Array
  • Array
  • Array
  1. Home
  2. Docs
  3. EOL-Product
  4. APP Note
  5. GSM Gateways APP Note
  6. Remote Server Get CDR from GSM Gateway by AMI
Updated on March 17, 2022

EOL-Product

  • folder icon closed folder iconUser Manual
    • iCallDroid User Manual
    • iCallDroid spot User Manual
    • IX120 User Manual
    • IX132 Series IP-PBX User Manual
    • SWG2008_User_Manual
    • SWG-1016C User Manual
    • WGW1002 User Manual
    • VS-GW1202-8G User Manual
    • VS-GW1600 User Manual
    • VS-GW2120 Series User Manual
    • 3G Gateways User Manual
    • A800E on DAHDI User Manual
    • A800P on DAHDI User Manual
    • A1200E on DAHDI User Manual
    • A1200P on DAHDI User Manual
    • D110P /D110E on DAHDI User Manual
    • D115P/DE115P on Elastix User Manual
    • DE115P/DE115E on DAHDI User Manual
    • G400P/G400E/G410P/G410E User Manual
    • iAG804/iAG808 User Manual
    • iAG840/iAG880 User Manual
  • folder icon closed folder iconDatasheet
    • VS-GW1600 GSM Series Datasheet
    • VS-GWM400 Datasheet
    • VS-GWM400W Datasheet
  • folder icon closed folder iconQuick Start Guide
    • Quickstart Guide of VS-GW1600-20G Connect with VOS3000 Operation Platform
    • Quickstart Guide of VS-GW1600-20G Connect with 3CX Server
    • Quickstart Guide of VS-GW1600-20G Connect with Asterisk Server
    • Quickstart Guide of VS-GW1600-20G Connect with Elastix Server
    • Quickstart Guide of VS-GW1600-20G Connect with FreeSWITCH Server
  • folder icon closed folder iconAPP Note
    • GSM Gateways APP Note
      • APP Note_AMI
      • Expand Callback Function
      • How to Bind the GSM Gateway Ports with PBX Sip Extension
      • How to Integrate the Analog Gateway and the GSM Gateway in One OpenVox Box
      • OpenVox GSM Gateway Function User Manual
      • OpenVox GSM Gateway HTTP Interface
      • Openvox HTTP SMS API Demo
      • OpenVox Wireless Gateway Connect with playSMS Manual
      • Remote Server Get CDR from GSM Gateway by AMI
      • VoxStack GSM Gateway API 1.0.0
      • VoxStack GSM Gateway Connect with iCallDrid Manual
      • VoxStack GSM Module Upgrading Guide
  • folder icon closed folder iconFAQ
    • IPC100/110

Remote Server Get CDR from GSM Gateway by AMI

Estimated reading: 4 minutes 666 views

Introduction:

OpenVox GSM Gateway can support AMI(Asterisk Manager Interface,if you want to get the CDR from remote server,you can use the AMI to do it!

 

Step 1:

Set the AMI in OpenVox GSM Gateway,follows:

image2016 2 24%2016:31:16

image2016 2 24%2016:31:39

 

Step 2:Write a Program to get the CDR like follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
//Login
void login_fun(int sock_fd)
{
    char username[20];
    char secret[20];
    int login_len=0;
    int secret_len=0;
    int res = 0;
    char receive_buf[4096];
    char login_buf[40];
    memset(username,'\0',20);
    memset(secret,'\0',20);
    printf("please input your username\n");
    scanf("%s",username);
    fflush(stdin);
    printf("please input your secret\n");
    scanf("%s",secret);
    fflush(stdin);
    memset(login_buf,'\0',40);
    sprintf(login_buf,"action:Login\r\nusername:%s\r\nsecret:%s\r\n\r\n",username,secret);
    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");
        }
    }
}
void read_cdr(int sock_fd)
{
    char receive_buf[4096];
    int res=0;
    char *receive_Data;
    char temp_buf[1024];
    char *temp = NULL;
    struct CDR
    {
        char CallerID[512];
        char CalleeID[512];
        char From[512];
        char To[512];
        char StartTime[512];
        char Duration[512];
        char Result[512];
    };
    struct CDR cdr_buff;
    int i =0;  
    int j =0;  
        while(1)
    {
        memset(receive_buf,'\0',4096);
        memset(cdr_buff.CallerID,'\0',512);
        memset(cdr_buff.CalleeID,'\0',512);
        memset(cdr_buff.From,'\0',512);
        memset(cdr_buff.To,'\0',512);
        memset(cdr_buff.StartTime,'\0',512);
        memset(cdr_buff.Duration,'\0',512);
        memset(cdr_buff.Result,'\0',512);
        
        if(res = read(sock_fd,receive_buf,sizeof(receive_buf))<0)
        {
            perror("read failed\n");
        }
        else
        {
            //memset(receive_buf,'\0',4096);
            if((receive_Data = strstr(receive_buf,"Application: WriteCDR"))!=NULL)
            {
                    
                //printf("111111111111111111111111111111111111111111111%s\n",receive_Data);
                i=0;
                j=0;   
                if((temp=strstr(receive_Data,"AppData:"))!=NULL)
                {
                    for(i=0;i<strlen(temp);i++)
                    {
                        if(temp[i]!=':')
                        {
                            j++;
                        }
                        else
                        {
                            break;     
                        }
                    }
                    temp=temp+j+2;
                    for(i=0;i<strlen(temp);i++)
                    {
                        if(temp[i]!=',')
                        {
                            cdr_buff.CallerID[i]=temp[i];
                        }
                        else
                        {
                            break;
                        }  
                    }
                    temp=temp+i+1;
                    for(i=0;i<strlen(temp);i++)
                                        {
                                                if(temp[i]!=',')
                                                {
                                                        cdr_buff.CalleeID[i]=temp[i];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                    temp=temp+i+1;
                    for(i=0;i<strlen(temp);i++)
                                        {
                                                if(temp[i]!=',')
                                                {
                                                        cdr_buff.From[i]=temp[i];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                    temp=temp+i+1;
                    for(i=0;i<strlen(temp);i++)
                                        {
                                                if(temp[i]!=',')
                                                {
                                                        cdr_buff.To[i]=temp[i];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                    temp=temp+i+1;
                    for(i=0;i<strlen(temp);i++)
                                        {
                                                if(temp[i]!=',')
                                                {
                                                        cdr_buff.StartTime[i]=temp[i];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                    temp=temp+i+1;
                    for(i=0;i<strlen(temp);i++)
                                        {
                                                if(temp[i]!=',')
                                                {
                                                        cdr_buff.Duration[i]=temp[i];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                    temp=temp+i+1;
                    for(i=0;i<strlen(temp);i++)
                                        {
                                                if(temp[i]!='\n')
                                                {
                                                        cdr_buff.Result[i]=temp[i];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                    printf("Callerid==============%s\n",cdr_buff.CallerID);
                    printf("Calleeid==============%s\n",cdr_buff.CalleeID);
                    printf("From==============%s\n",cdr_buff.From);
                    printf("To==============%s\n",cdr_buff.To);
                    printf("StartTime==============%s\n",cdr_buff.StartTime);
                    printf("Duration==============%s\n",cdr_buff.Duration);
                    printf("Result==============%s\n",cdr_buff.Result);
        //          break; 
                }              
            }
        }
    }
}
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)
    {
        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);
    read_cdr(client_socket);
    return 0;
}

 

Step 3:compile and run the app

image2016 2 24%2016:40:2

image2016 2 24%2016:40:32

Notice: This just a test program,just use for refer it!

Thanks!

Still stuck? How can we help?

Was this page helpful? Yes 1 No

How can we help?

Leave a Comment Cancel reply

CONTENTS

Copyright © 2002-2024 OpenVox all rights reserved.