mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 19:23:24 +02:00
Add modem status page.
On this page, much useful information is displayed about the hardware and the status of an LTE/3G or other kinds of modems that respond to AT commands.
This commit is contained in:
@@ -153,6 +153,10 @@ sub genmenu {
|
||||
if (&General::RedIsWireless()) {
|
||||
$menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1;
|
||||
}
|
||||
|
||||
if ($ethsettings{'RED_TYPE'} eq "PPPOE") {
|
||||
$menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub showhttpheaders
|
||||
|
||||
276
config/cfgroot/modem-lib.pl
Normal file
276
config/cfgroot/modem-lib.pl
Normal file
@@ -0,0 +1,276 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
# #
|
||||
# IPFire.org - A linux based firewall #
|
||||
# Copyright (C) 2014 IPFire Team <info@ipfire.org> #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
use Device::Modem;
|
||||
|
||||
package Modem;
|
||||
|
||||
sub new() {
|
||||
my $class = shift;
|
||||
|
||||
my $port = shift;
|
||||
my $baud = shift;
|
||||
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
# Initialize the connetion to the modem.
|
||||
$self->_initialize($port, $baud);
|
||||
|
||||
if ($self->_is_working()) {
|
||||
return $self;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub DESTROY() {
|
||||
my $self = shift;
|
||||
|
||||
# Close connection to modem.
|
||||
if ($self->{modem}) {
|
||||
$self->{modem}->close();
|
||||
}
|
||||
}
|
||||
|
||||
sub _initialize() {
|
||||
my ($self, $port, $baud) = @_;
|
||||
|
||||
# Establish connection to the modem.
|
||||
$self->{modem} = new Device::Modem(port => $port);
|
||||
$self->{modem}->connect(baudrate => $baud);
|
||||
}
|
||||
|
||||
sub _is_working() {
|
||||
my $self = shift;
|
||||
|
||||
# Check if the modem responds to AT commands.
|
||||
$self->{modem}->atsend("AT\r\n");
|
||||
|
||||
my $response = $self->{modem}->answer();
|
||||
return ($response eq "OK");
|
||||
}
|
||||
|
||||
sub _command() {
|
||||
my $self = shift;
|
||||
my $cmd = shift;
|
||||
|
||||
# Terminate the AT command with newline.
|
||||
$cmd .= "\r\n";
|
||||
|
||||
$self->{modem}->atsend($cmd);
|
||||
|
||||
my $response = $self->{modem}->answer();
|
||||
my @response = split(/\n/, $response);
|
||||
|
||||
# Trim leading and trailing spaces.
|
||||
foreach my $line (@response) {
|
||||
$line =~ s/^\s+|\s+$//g;
|
||||
chomp($line);
|
||||
}
|
||||
|
||||
my $last_element = pop(@response);
|
||||
unless ($last_element eq "OK") {
|
||||
push(@response, $last_element);
|
||||
}
|
||||
|
||||
$response = join("\n", @response);
|
||||
|
||||
return $self->_trim($response);
|
||||
}
|
||||
|
||||
sub _trim() {
|
||||
my $self = shift;
|
||||
my $input = shift;
|
||||
|
||||
my $first_char = substr($input, 0, 1);
|
||||
if ($first_char eq "+") {
|
||||
my @output = split(/:/, $input);
|
||||
if ($#output == 1) {
|
||||
return $output[1];
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
sub get_vendor() {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_command("AT+GMI");
|
||||
}
|
||||
|
||||
sub get_model() {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_command("AT+GMM");
|
||||
}
|
||||
|
||||
sub get_software_version() {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_command("AT+GMR");
|
||||
}
|
||||
|
||||
sub get_imei() {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_command("AT+GSN");
|
||||
}
|
||||
|
||||
sub get_capabilities() {
|
||||
my $self = shift;
|
||||
|
||||
my $output = $self->_command("AT+GCAP");
|
||||
return split(/,/, $output);
|
||||
}
|
||||
|
||||
sub is_sim_unlocked() {
|
||||
my $self = shift;
|
||||
|
||||
# TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_sim_imsi() {
|
||||
my $self = shift;
|
||||
|
||||
if ($self->is_sim_unlocked()) {
|
||||
return $self->_command("AT+CIMI");
|
||||
}
|
||||
}
|
||||
|
||||
sub get_network_registration() {
|
||||
my $self = shift;
|
||||
|
||||
my @elements;
|
||||
foreach my $i ([0, 1]) {
|
||||
my $output = $self->_command("AT+CREG?");
|
||||
|
||||
@elements = split(/,/, $output);
|
||||
if ($#elements != 2) {
|
||||
# Output in wrong format. Resetting.
|
||||
$self->_command("AT+CREG=0");
|
||||
}
|
||||
}
|
||||
|
||||
if ($elements[0] == 0) {
|
||||
if ($elements[1] == 0) {
|
||||
return "NOT REGISTERED, NOT SEARCHING";
|
||||
} elsif ($elements[1] == 1) {
|
||||
return "REGISTERED TO HOME NETWORK";
|
||||
} elsif ($elements[1] == 2) {
|
||||
return "NOT REGISTERED, SEARCHING";
|
||||
} elsif ($elements[1] == 3) {
|
||||
return "REGISTRATION DENIED";
|
||||
} elsif ($elements[1] == 5) {
|
||||
return "REGISTERED, ROAMING";
|
||||
} else {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub _get_network_operator() {
|
||||
my $self = shift;
|
||||
|
||||
my $output = $self->_command("AT+COPS?");
|
||||
$output =~ s/\"//g;
|
||||
|
||||
my @elements = split(/,/, $output);
|
||||
if ($#elements == 3) {
|
||||
return @elements;
|
||||
}
|
||||
}
|
||||
|
||||
sub get_network_operator() {
|
||||
my $self = shift;
|
||||
|
||||
my ($mode, $format, $operator, $act) = $self->_get_network_operator();
|
||||
|
||||
return $operator;
|
||||
}
|
||||
|
||||
sub get_network_mode() {
|
||||
my $self = shift;
|
||||
|
||||
my ($mode, $format, $operator, $act) = $self->_get_network_operator();
|
||||
|
||||
if ($act == 0) {
|
||||
return "GSM";
|
||||
} elsif ($act == 1) {
|
||||
return "Compact GSM";
|
||||
} elsif ($act == 2) {
|
||||
return "UMTS";
|
||||
} elsif ($act == 3) {
|
||||
return "GSM WITH EGPRS";
|
||||
} elsif ($act == 4) {
|
||||
return "UMTS WITH HSDPA";
|
||||
} elsif ($act == 5) {
|
||||
return "UMTS WITH HSUPA";
|
||||
} elsif ($act == 6) {
|
||||
return "UMTS WITH HSDPA+HSUPA";
|
||||
} elsif ($act == 7) {
|
||||
return "LTE";
|
||||
} else {
|
||||
return "UNKNOWN ($act)";
|
||||
}
|
||||
}
|
||||
|
||||
sub _get_signal_quality() {
|
||||
my $self = shift;
|
||||
|
||||
my $output = $self->_command("AT+CSQ");
|
||||
|
||||
my @elements = split(/,/, $output);
|
||||
if ($#elements == 1) {
|
||||
return @elements;
|
||||
}
|
||||
}
|
||||
|
||||
sub get_signal_quality() {
|
||||
my $self = shift;
|
||||
|
||||
my ($rssi, $ber) = $self->_get_signal_quality();
|
||||
|
||||
# 99 equals unknown.
|
||||
unless ($rssi == 99) {
|
||||
my $dbm = ($rssi * 2) - 113;
|
||||
return $dbm;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub get_bit_error_rate() {
|
||||
my $self = shift;
|
||||
|
||||
my ($rssi, $ber) = $self->_get_signal_quality();
|
||||
|
||||
# 99 indicates unknown.
|
||||
unless ($ber == 99) {
|
||||
return $ber;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -70,6 +70,11 @@
|
||||
'title' => "$Lang::tr{'qos graphs'}",
|
||||
'enabled' => 1,
|
||||
};
|
||||
$substatus->{'74.modem-status'} = {'caption' => $Lang::tr{'modem status'},
|
||||
'uri' => '/cgi-bin/modem-status.cgi',
|
||||
'title' => $Lang::tr{'modem status'},
|
||||
'enabled' => 0,
|
||||
};
|
||||
$substatus->{'75.atm-status'} = {'caption' => 'Atm-status',
|
||||
'uri' => '/cgi-bin/atm-status.cgi',
|
||||
'title' => 'Atm-status',
|
||||
|
||||
@@ -1415,6 +1415,7 @@ srv/web/ipfire/cgi-bin/mac.cgi
|
||||
srv/web/ipfire/cgi-bin/media.cgi
|
||||
srv/web/ipfire/cgi-bin/memory.cgi
|
||||
srv/web/ipfire/cgi-bin/modem.cgi
|
||||
srv/web/ipfire/cgi-bin/modem-status.cgi
|
||||
srv/web/ipfire/cgi-bin/netexternal.cgi
|
||||
srv/web/ipfire/cgi-bin/netinternal.cgi
|
||||
srv/web/ipfire/cgi-bin/netother.cgi
|
||||
|
||||
@@ -116,6 +116,7 @@ var/ipfire/menu.d/70-log.menu
|
||||
var/ipfire/modem
|
||||
#var/ipfire/modem/defaults
|
||||
#var/ipfire/modem/settings
|
||||
var/ipfire/modem-lib.pl
|
||||
var/ipfire/net-traffic
|
||||
#var/ipfire/net-traffic/net-traffic-admin.pl
|
||||
#var/ipfire/net-traffic/net-traffic-lib.pl
|
||||
|
||||
18
config/rootfiles/common/perl-Device-Modem
Normal file
18
config/rootfiles/common/perl-Device-Modem
Normal file
@@ -0,0 +1,18 @@
|
||||
#usr/lib/perl5/site_perl/5.12.3/Device
|
||||
#usr/lib/perl5/site_perl/5.12.3/Device/Modem
|
||||
usr/lib/perl5/site_perl/5.12.3/Device/Modem.pm
|
||||
#usr/lib/perl5/site_perl/5.12.3/Device/Modem/FAQ.pod
|
||||
#usr/lib/perl5/site_perl/5.12.3/Device/Modem/Log
|
||||
usr/lib/perl5/site_perl/5.12.3/Device/Modem/Log/File.pm
|
||||
usr/lib/perl5/site_perl/5.12.3/Device/Modem/Log/Syslog.pm
|
||||
#usr/lib/perl5/site_perl/5.12.3/Device/Modem/Protocol
|
||||
usr/lib/perl5/site_perl/5.12.3/Device/Modem/Protocol/Xmodem.pm
|
||||
usr/lib/perl5/site_perl/5.12.3/Device/Modem/UsRobotics.pm
|
||||
#usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device/Modem
|
||||
#usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device/Modem/.packlist
|
||||
#usr/share/man/man3/Device::Modem.3
|
||||
#usr/share/man/man3/Device::Modem::FAQ.3
|
||||
#usr/share/man/man3/Device::Modem::Log::File.3
|
||||
#usr/share/man/man3/Device::Modem::Log::Syslog.3
|
||||
#usr/share/man/man3/Device::Modem::Protocol::Xmodem.3
|
||||
#usr/share/man/man3/Device::Modem::UsRobotics.3
|
||||
10
config/rootfiles/common/perl-Device-SerialPort
Normal file
10
config/rootfiles/common/perl-Device-SerialPort
Normal file
@@ -0,0 +1,10 @@
|
||||
#usr/bin/modemtest
|
||||
usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/Device
|
||||
usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/Device/SerialPort.pm
|
||||
#usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device
|
||||
#usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device/SerialPort
|
||||
#usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device/SerialPort/.packlist
|
||||
#usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device/SerialPort/SerialPort.bs
|
||||
usr/lib/perl5/site_perl/5.12.3/MACHINE-linux-thread-multi/auto/Device/SerialPort/SerialPort.so
|
||||
#usr/share/man/man1/modemtest.1
|
||||
#usr/share/man/man3/Device::SerialPort.3
|
||||
Reference in New Issue
Block a user