2
* Wilcard TC400B Digium Transcoder Engine Interface Driver for Zapata Telephony interface test tool.
4
* Written by Matt O'Gorman <mogorman@digium.com>
6
* Copyright (C) 2006-2007, Digium, Inc.
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
#include <netinet/in.h>
34
#include <sys/ioctl.h>
38
#ifdef STANDALONE_ZAPATA
41
#include <linux/zaptel.h>
44
#define MAX_CARDS_TO_TEST 6
45
#define MAX_CHANNELS_PER_CARD 96
47
#define AST_FORMAT_ULAW (1 << 2)
48
#define AST_FORMAT_G729A (1 << 8)
50
#define AST_FRIENDLY_OFFSET 64
54
static unsigned char ulaw_slin_ex[] = {
55
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
67
static unsigned char g729a_expected[] = {
68
0xE9, 0x88, 0x4C, 0xA0, 0x00, 0xFA, 0xDD, 0xA2, 0x06, 0x2D,
69
0x69, 0x88, 0x00, 0x60, 0x68, 0xD5, 0x9E, 0x20, 0x80, 0x50
74
unsigned int map[32][32];
82
struct zt_transcode_header *hdr;
83
// struct ast_frame f;
88
int numchans[MAX_CARDS_TO_TEST];
91
int overcnt_error; /* Too many cards found */
92
int undercnt_error; /* Too few cards found */
93
int timeout_error[MAX_CARDS_TO_TEST];
94
int data_error[MAX_CARDS_TO_TEST];
99
static int find_transcoders(struct tctest_info *tctest_info)
101
struct zt_transcode_info info = { 0, };
104
if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0) {
105
printf("Warning: No Zaptel transcoder support!\n");
109
tctest_info->total_chans = 0;
110
info.op = ZT_TCOP_GETINFO;
111
for (info.tcnum = 0; !(res = ioctl(fd, ZT_TRANSCODE_OP, &info)); info.tcnum++) {
113
printf("Found transcoder %d, '%s' with %d channels.\n", info.tcnum, info.name, info.numchannels);
114
if ((info.tcnum % 2) == 0)
116
tctest_info->numchans[info.tcnum/2] = info.numchannels;
117
tctest_info->total_chans += info.numchannels;
120
tctest_info->numcards = info.tcnum / 2;
124
printf("No hardware transcoders found.\n");
129
static int open_transcoder(struct tcpvt *ztp, int dest, int source)
132
unsigned int x = ZT_TCOP_ALLOCATE;
133
struct zt_transcode_header *hdr;
136
if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0)
138
flags = fcntl(fd, F_GETFL);
140
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
141
printf("Could not set non-block mode!\n");
144
if ((hdr = mmap(NULL, sizeof(*hdr), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
145
printf("Memory Map failed for transcoding (%s)\n", strerror(errno));
151
if (hdr->magic != ZT_TRANSCODE_MAGIC) {
152
printf("Transcoder header (%08x) wasn't magic. Abandoning\n", hdr->magic);
153
munmap(hdr, sizeof(*hdr));
159
hdr->srcfmt = source;
162
if (ioctl(fd, ZT_TRANSCODE_OP, &x)) {
163
printf("Unable to attach transcoder: %s\n", strerror(errno));
164
munmap(hdr, sizeof(*hdr));
177
static void close_transcoder(struct tcpvt *ztp)
182
if (ioctl(ztp->fd, ZT_TRANSCODE_OP, &x))
183
printf("Failed to release transcoder channel: %s\n", strerror(errno));
185
munmap(ztp->hdr, sizeof(*ztp->hdr));
190
static int encode_packet(struct tcpvt *ztp, unsigned char *packet_in, unsigned char *packet_out)
192
struct zt_transcode_header *hdr = ztp->hdr;
197
memcpy(hdr->srcdata + hdr->srcoffset + hdr->srclen, packet_in, 160);
201
hdr->dstoffset = AST_FRIENDLY_OFFSET;
202
x = ZT_TCOP_TRANSCODE;
203
if (ioctl(ztp->fd, ZT_TRANSCODE_OP, &x))
204
printf("Failed to transcode: %s\n", strerror(errno));
209
memcpy(packet_out, hdr->dstdata + hdr->dstoffset, hdr->dstlen);
217
static void print_failed()
219
printf("______ ___ _____ _ _____ ______\n");
220
printf("| ___| / _ \\ |_ _| | | | ___| | _ \\\n");
221
printf("| |_ / /_\\ \\ | | | | | |__ | | | |\n");
222
printf("| _| | _ | | | | | | __| | | | |\n");
223
printf("| | | | | | _| |_ | |____ | |___ | |/ /\n");
224
printf("\\_| \\_| |_/ \\___/ \\_____/ \\____/ |___/ \n");
228
int main(int argc, char *argv[])
230
int arg1, arg2, i, j, card_testing, chan_testing;
231
struct tcpvt ztp[MAX_CHANNELS_PER_CARD * MAX_CARDS_TO_TEST];
232
unsigned char packet_out[200];
233
struct tctest_info tctest_info;
235
memset(&tctest_info, 0, sizeof(tctest_info));
237
if ((argc < 2) || (argc > 3))
239
printf("codec_test requires one argument.\n");
240
printf(" arg1 = number of cards to test\n");
245
sscanf(argv[1], "%d", &arg1);
248
sscanf(argv[1], "%d %d", &arg1, &arg2);
252
printf("Beginning test of %d TC400B cards\n", arg1);
255
/* Search for TC400Bs */
256
find_transcoders(&tctest_info);
258
if (tctest_info.numcards > arg1)
260
tctest_info.errors++;
261
tctest_info.overcnt_error = 1;
263
if (tctest_info.numcards < arg1)
265
tctest_info.errors++;
266
tctest_info.undercnt_error = 1;
269
if (tctest_info.errors == 0)
271
/* Begin testing transcoder channels */
272
for (card_testing = 0; card_testing < tctest_info.numcards; card_testing++)
274
tctest_info.data_error[card_testing] = 0;
275
tctest_info.timeout_error[card_testing] = 0;
276
for (chan_testing = 0; chan_testing < tctest_info.numchans[card_testing]; chan_testing++)
279
for(j = 0; j < card_testing; j++)
280
i += tctest_info.numchans[j];
282
open_transcoder(&ztp[i], AST_FORMAT_G729A, AST_FORMAT_ULAW);
284
if ((tctest_info.timeout_error[card_testing] = encode_packet(&ztp[i], ulaw_slin_ex, packet_out) == -1))
285
tctest_info.errors++;
287
if (memcmp(g729a_expected, packet_out, 20) != 0)
289
tctest_info.errors++;
290
tctest_info.data_error[card_testing] += 1;
293
if ( (tctest_info.data_error[card_testing]) || (tctest_info.timeout_error[card_testing]) )
294
tctest_info.numcards_werrors++;
297
for (i = 0; i < tctest_info.total_chans; i++)
298
close_transcoder(&ztp[i]);
304
printf("tctest_info.errors = %d\n", tctest_info.errors);
305
printf("tctest_info.overcnt_error = %d\n", tctest_info.overcnt_error);
306
printf("tctest_info.undercnt_error = %d\n", tctest_info.undercnt_error);
307
printf("tctest_info.numcards_werrors = %d\n", tctest_info.numcards_werrors);
309
for (i = 0; i < tctest_info.numcards; i++)
311
printf("tctest_info.data_error[%d] = %d\n", i, tctest_info.data_error[i]);
312
printf("tctest_info.timeout_error[%d] = %d\n", i, tctest_info.timeout_error[i]);
316
if (tctest_info.errors)
319
if (tctest_info.numcards_werrors)
320
printf("%d of %d cards\n", tctest_info.numcards_werrors, tctest_info.numcards);
322
if (tctest_info.overcnt_error)
323
printf("\n%d cards found, %d expected\n", tctest_info.numcards, arg1);
324
if (tctest_info.undercnt_error)
325
printf("\n%d cards found, %d expected\n", tctest_info.numcards, arg1);
329
printf("%d of %d cards PASSED\n", tctest_info.numcards - tctest_info.numcards_werrors, tctest_info.numcards);