~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy

« back to all changes in this revision

Viewing changes to pattest.c

  • Committer: Stefan Lesicnik
  • Date: 2011-05-08 12:22:46 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: stefan@lsd.co.za-20110508122246-lh6k2x1uy8pl3vdi
Tags: 1:2.4.1-1ubuntu1
* Merge from Debian. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
* debian/control: Added gawk as dependency for dkms build (LP: #493304)
* New upstream release (Closes: #581076, #582094).
* Patches hardware_rescan, perl_fix_noserial, perl_fix_transportdir,
  astribank_allow_ignoreend, init_unload_modules and wcb4xxp_extra_trunk
  dropped: merged upstream.
* dahdi-linux 2.3.0 is required (extra config options for dahdi_cfg).
* Convert to dpkg v.3 format.
* Standards version: 3.9.1.0 (No change needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "dahdi_tools_version.h"
42
42
 
43
43
#define BLOCK_SIZE 2039
 
44
#define DEVICE    "/dev/dahdi/channel"
 
45
 
 
46
static const char       rcsid[] = "$Id: pattest.c 7658 2009-12-02 19:45:45Z tzafrir $";
 
47
char                    *prog_name;
 
48
 
 
49
static void usage(void)
 
50
{
 
51
        fprintf(stderr, "Usage: %s <dahdi_chan>\n", prog_name);
 
52
        fprintf(stderr, "   e.g.: %s /dev/dahdi/55\n", prog_name);
 
53
        fprintf(stderr, "         %s 455\n", prog_name);
 
54
        fprintf(stderr, "%s version %s\n", prog_name, rcsid);
 
55
        exit(1);
 
56
}
44
57
 
45
58
void print_packet(unsigned char *buf, int len)
46
59
{
51
64
        printf("}\n");
52
65
}
53
66
 
 
67
int channel_open(char *name, int *bs)
 
68
{
 
69
        int                     channo;
 
70
        int                     fd;
 
71
        struct                  dahdi_params tp;
 
72
        char                    *dev;
 
73
 
 
74
        channo = atoi(name);
 
75
        /* channo==0: The user passed a file name to be opened. */
 
76
        dev = channo ? DEVICE : name;
 
77
 
 
78
        fd = open(dev, O_RDWR, 0600);
 
79
 
 
80
        if (fd < 0) {
 
81
                perror(DEVICE);
 
82
                return -1;
 
83
        }
 
84
 
 
85
        /* If we got a channel number, get it from /dev/dahdi/channel: */
 
86
        if(channo && ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
 
87
                perror("SPECIFY");
 
88
                return -1;
 
89
        }
 
90
        if(ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
 
91
                perror("SET_BLOCKSIZE");
 
92
                return -1;
 
93
        }
 
94
 
 
95
        if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
 
96
                fprintf(stderr, "Unable to get channel parameters\n");
 
97
                return -1;
 
98
        }
 
99
 
 
100
        return fd;
 
101
}
 
102
 
54
103
int main(int argc, char *argv[])
55
104
{
56
105
        int fd;
57
106
        int res, x;
58
 
        struct dahdi_params tp;
59
107
        int bs = BLOCK_SIZE;
60
108
        unsigned char c=0;
61
109
        unsigned char outbuf[BLOCK_SIZE];
62
110
        int setup=0;
63
111
        int errors=0;
64
112
        int bytes=0;
 
113
 
 
114
        prog_name = argv[0];
 
115
 
65
116
        if (argc < 2) {
66
 
                fprintf(stderr, "Usage: %s <DAHDI device>\n", argv[0]);
67
 
                exit(1);
68
 
        }
69
 
        fd = open(argv[1], O_RDWR, 0600);
70
 
        if (fd < 0) {
71
 
                fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
72
 
                exit(1);
73
 
        }
74
 
        if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs)) {
75
 
                fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
76
 
                exit(1);
77
 
        }
78
 
        if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
79
 
                fprintf(stderr, "Unable to get channel parameters\n");
80
 
                exit(1);
81
 
        }
 
117
                usage();
 
118
        }
 
119
 
 
120
        fd = channel_open(argv[1], &bs);
 
121
        if (fd < 0)
 
122
                exit(1);
 
123
 
82
124
        ioctl(fd, DAHDI_GETEVENT);
83
125
        for(;;) {
84
126
                res = bs;