#!/usr/bin/perl -w =for commnet 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 . 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 conained 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"; } $commit = 0; # Added new wifimac parm, the radio0 wont startup without it, use the path location in wifi config # Actually it just needs some path to get to the radio. # Using radio0.path as it seems to always be set as method to get to the card. chomp ($wifi_path = `uci -q get wireless.radio0.path`); chomp ($wifi_mac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.wifimac`); if($wifi_mac eq "") { open(FILE, "/sys/devices/$wifi_path/ieee80211/phy0/macaddress") or fail("ERROR: wireless mac not available"); while() { 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/devices/$wifi_path/ieee80211/phy0/macaddress") or fail("ERROR: wireless mac not available"); while() { 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() { 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;