mirror of https://github.com/aredn/aredn.git
142 lines
4.0 KiB
Perl
Executable File
142 lines
4.0 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
=for comment
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
Copyright (C) 2015 Conrad Lara
|
|
See Contributors file for additional contributors
|
|
|
|
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
|
|
|
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 version 3 of the License.
|
|
|
|
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/>.
|
|
|
|
Additional Terms:
|
|
|
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
|
See AREDNLicense.txt for more info.
|
|
|
|
Attributions to the AREDN Project must be retained in the source code.
|
|
If importing this code into a new or existing project attribution
|
|
to the AREDN project must be added to the source code.
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
version.
|
|
|
|
=cut
|
|
|
|
# do the initial setup of the essential nvram variables
|
|
# node - node name
|
|
# mac2 - last 3 bytes of wifi mac address in the form ddd.ddd.ddd
|
|
# wifi_mac - full mac address of wireless card in the form hh:hh:hh:hh:hh:hh
|
|
#
|
|
# intended to run every boot but it should only actually do anything
|
|
# on the first boot
|
|
|
|
sub fail
|
|
{
|
|
open(ERR, ">>/tmp/nvram_errors");
|
|
print ERR "@_\n";
|
|
close(ERR);
|
|
die "@_\n";
|
|
}
|
|
|
|
sub get_wlan2phy
|
|
{
|
|
my ($wlan) = $1;
|
|
my ($phy) = "";
|
|
return "phy0" unless $wlan;
|
|
foreach(`iwinfo $wlan info`)
|
|
{
|
|
next unless /^.*PHY name:\s*([a-z0-4]+)/;
|
|
$phy = $1;
|
|
}
|
|
return $phy;
|
|
}
|
|
|
|
$commit = 0;
|
|
$wifiif = `uci -q get network.wifi.ifname`;
|
|
$phy = get_wlan2phy("$wifiif");
|
|
|
|
# Added new wifimac parm, the radio* wont startup without it, use the path location in wifi config
|
|
# Actually it just needs some path to get to the radio.
|
|
|
|
chomp ($wifi_mac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.wifimac`);
|
|
|
|
if($wifi_mac eq "")
|
|
{
|
|
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available");
|
|
while(<FILE>)
|
|
{
|
|
next unless /(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/;
|
|
$wifi_mac = $1;
|
|
last;
|
|
}
|
|
close(FILE);
|
|
fail("ERROR: wireless mac not found") if $wifi_mac eq "";
|
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.wifimac=$wifi_mac";
|
|
$commit = 1;
|
|
}
|
|
|
|
|
|
chomp ($mac2 = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.mac2`);
|
|
|
|
if($mac2 eq "")
|
|
{
|
|
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available");
|
|
while(<FILE>)
|
|
{
|
|
next unless /\w\w:\w\w:\w\w:(\w\w):(\w\w):(\w\w)/;
|
|
$mac2 = join ".", hex $1, hex $2, hex $3;
|
|
last;
|
|
}
|
|
close(FILE);
|
|
fail("ERROR: wireless mac not found") if $mac2 eq "";
|
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.mac2=$mac2";
|
|
$commit = 1;
|
|
}
|
|
|
|
chomp ($node = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.node`);
|
|
|
|
if($node eq "")
|
|
{
|
|
$mac2 =~ s/\./-/g;
|
|
$node = "NOCALL-$mac2";
|
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.node=NOCALL-$mac2";
|
|
$commit = 1;
|
|
}
|
|
|
|
chomp ($dtdmac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.dtdmac`);
|
|
|
|
if($dtdmac eq "")
|
|
{
|
|
# We should always have an eth0 interface on all nodes.
|
|
# Not porting get_interface into this file at this time
|
|
# as on a firstboot where nvram-setup runs the interfaces
|
|
# should not be changed yet.
|
|
open(FILE, "/sbin/ifconfig eth0 |") or fail("ERROR: eth0 mac not available");
|
|
while(<FILE>)
|
|
{
|
|
next unless /\w\w:\w\w:\w\w:(\w\w):(\w\w):(\w\w)/;
|
|
$dtdmac = join ".", hex $1, hex $2, hex $3;
|
|
last;
|
|
}
|
|
close(FILE);
|
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.dtdmac=$dtdmac";
|
|
$commit = 1;
|
|
}
|
|
|
|
|
|
system "uci -c /etc/local/uci/ commit" if $commit;
|