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

« back to all changes in this revision

Viewing changes to xpp/perl_modules/Dahdi/Xpp/Xpd.pm

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2013-08-25 12:48:37 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130825124837-wtefi7f9dsihg8is
Tags: 1:2.7.0-1ubuntu1
* Merge from debian. Remaining changes:
  - debian/control: Added gawk as dependency for dkms build
  - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
  - debian/control: Set ubuntu maintainer    
  - added debian/dahdi.postinst
  - debian/control: Removed Uploaders field.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# This program is free software; you can redistribute and/or
6
6
# modify it under the same terms as Perl itself.
7
7
#
8
 
# $Id: Xpd.pm 7256 2009-09-29 19:20:32Z tzafrir $
 
8
# $Id$
9
9
#
10
10
use strict;
11
11
use Dahdi::Utils;
52
52
 
53
53
Textual name: E.g. C<XPD-10>.
54
54
 
55
 
=head1 dir
56
 
 
57
 
The ProcFS directory with information about the XPD. e.g.
58
 
C</proc/xpp/XBUS-00/XPD-10>.
59
 
 
60
55
=head1 sysfs_dir
61
56
 
62
57
The SysFS directory with information about the module. E.g.
104
99
 
105
100
sub xpd_attr_path($@) {
106
101
        my $self = shift || die;
 
102
        my $xbus = $self->xbus;
107
103
        my ($busnum, $unitnum, $subunitnum, @attr) = (
108
 
                $self->xbus->num,
 
104
                $xbus->num,
109
105
                $self->unit,
110
106
                $self->subunit,
111
107
                @_);
112
108
        foreach my $attr (@attr) {
113
 
                my $file = sprintf "$Dahdi::Xpp::sysfs_xpds/%02d:%1d:%1d/$attr",
114
 
                   $busnum, $unitnum, $subunitnum;
115
 
                unless(-f $file) {
116
 
                        my $procfile = sprintf "/proc/xpp/XBUS-%02d/XPD-%1d%1d/$attr",
117
 
                           $busnum, $unitnum, $subunitnum;
118
 
                        warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to /proc\n"
119
 
                                unless $file_warned{$attr}++;
120
 
                        $file = $procfile;
121
 
                }
 
109
                my $file = sprintf "%s/%02d:%1d:%1d/$attr",
 
110
                   $xbus->sysfs_dir, $busnum, $unitnum, $subunitnum;
122
111
                next unless -f $file;
123
112
                return $file;
124
113
        }
125
114
        return undef;
126
115
}
127
116
 
128
 
# Backward compat plug for old /proc interface...
129
 
sub xpd_old_gettype($) {
130
 
        my $xpd = shift || die;
131
 
        my $summary = "/proc/xpp/" . $xpd->fqn . "/summary";
132
 
        open(F, $summary) or die "Failed to open '$summary': $!";
133
 
        my $head = <F>;
134
 
        close F;
135
 
        chomp $head;
136
 
        $head =~ s/^XPD-\d+\s+\(//;
137
 
        $head =~ s/,.*//;
138
 
        return $head;
139
 
}
140
 
 
141
 
sub xpd_old_getspan($) {
142
 
        my $xpd = shift || die;
143
 
        my $dahdi_registration = "/proc/xpp/" . $xpd->fqn . "/dahdi_registration";
144
 
        open(F, $dahdi_registration) or die "Failed to open '$dahdi_registration': $!";
145
 
        my $head = <F>;
146
 
        close F;
147
 
        chomp $head;
148
 
        return $head;
149
 
}
150
 
 
151
 
sub xpd_old_getoffhook($) {
152
 
        my $xpd = shift || die;
153
 
        my $summary = "/proc/xpp/" . $xpd->fqn . "/summary";
154
 
        my $channels;
155
 
 
156
 
        local $/ = "\n";
157
 
        open(F, "$summary") || die "Failed opening $summary: $!\n";
158
 
        my $head = <F>;
159
 
        chomp $head;    # "XPD-00 (BRI_TE ,card present, span 3)"
160
 
        my $offhook;
161
 
        while(<F>) {
162
 
                chomp;
163
 
                if(s/^\s*offhook\s*:\s*//) {
164
 
                        s/\s*$//;
165
 
                        $offhook = $_;
166
 
                        $offhook || die "No channels in '$summary'";
167
 
                        last;
168
 
                }
169
 
        }
170
 
        close F;
171
 
        return $offhook;
172
 
}
173
 
 
174
117
my %attr_missing_warned;        # Prevent duplicate warnings
175
118
 
176
119
sub xpd_driver_getattr($$) {
198
141
        $attr = lc($attr);
199
142
        my $file = $xpd->xpd_attr_path(lc($attr));
200
143
 
201
 
        # Handle special cases for backward compat
202
 
        return xpd_old_gettype($xpd) if $attr eq 'type' and !defined $file;
203
 
        return xpd_old_getspan($xpd) if $attr eq 'span' and !defined $file;
204
 
        return xpd_old_getoffhook($xpd) if $attr eq 'offhook' and !defined $file;
205
144
        if(!defined($file)) {
206
145
                warn "$0: xpd_getattr($attr) -- Missing attribute.\n" if
207
146
                        $attr_missing_warned{$attr};
279
218
        return @idx;
280
219
}
281
220
 
282
 
sub new($$$$$) {
 
221
sub new($$$) {
283
222
        my $pack = shift or die "Wasn't called as a class method\n";
284
 
        my $xbus = shift || die;
285
 
        my $unit = shift;       # May be zero
286
 
        my $subunit = shift;    # May be zero
287
 
        my $procdir = shift || die;
288
 
        my $sysfsdir = shift || die;
 
223
        my $xbus = shift or die;
 
224
        my $xpdstr = shift or die;
 
225
        my $sysfsdir = sprintf "%s/%s", $xbus->sysfs_dir, $xpdstr;
 
226
        my ($busnum, $unit, $subunit) = split(/:/, $xpdstr);
289
227
        my $self = {
290
228
                XBUS            => $xbus,
291
229
                ID              => sprintf("%1d%1d", $unit, $subunit),
292
230
                FQN             => $xbus->name . "/" . "XPD-$unit$subunit",
293
231
                UNIT            => $unit,
294
232
                SUBUNIT         => $subunit,
295
 
                DIR             => $procdir,
296
233
                SYSFS_DIR       => $sysfsdir,
297
234
                };
298
235
        bless $self, $pack;
319
256
                }
320
257
        }
321
258
        $self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} );
322
 
        Dahdi::Xpp::Line->create_all($self, $procdir);
 
259
        Dahdi::Xpp::Line->create_all($self);
323
260
        return $self;
324
261
}
325
262
 
327
264
# static xpd related helper functions
328
265
#------------------------------------
329
266
 
 
267
# Returns only the telephony XPD's from a list
 
268
# of one or more XPD's.
 
269
# I.e: Filters-out ECHO cancelers
 
270
sub telephony_devs {
 
271
        my @devs = grep { $_->channels } @_;
 
272
        return @devs;
 
273
}
 
274
 
330
275
sub format_rank($$) {
331
276
        my ($rank, $prio) = @_;
332
277
        my $width = 2;