1 | 11 | simandl | package HotSaNICmod::OSdep; |
2 | | | |
3 | | | use RRDs; |
4 | | | |
5 | | | sub version { |
6 | | | ($VERSION = '$Revision: 1.0 $') =~ s/.*(\d+\.\d+).*/$1/; |
7 | | | my $platform; |
8 | | | foreach (keys(%INC)) { $platform=$_ if $_ =~ /platform/; } |
9 | | | return "$platform $VERSION"; |
10 | | | } |
11 | | | |
12 | | | sub sample { |
13 | | | |
14 | | | #uncomment this for debug output to temp.txt |
15 | | | #all print will be done into the file |
16 | | | $temp = "/opt/HotSaNIC/modules/iwconf/temp.txt"; |
17 | | | open (TEMPFILE,">$temp"); |
18 | | | open (STDERR,">&TEMPFILE") || die ("open STDERR failed"); |
19 | | | open (STDOUT,">&TEMPFILE") || die ("open STDOUT failed"); |
20 | | | |
21 | | | |
22 | | | my %args=@_; |
23 | | | |
24 | | | $mtime=(stat("rrd"))[9]; |
25 | | | $now=time; |
26 | | | |
27 | | | utime $now,$now,"rrd"; |
28 | | | |
29 | | | $IWCONF = $args{IWCONFIG}; |
30 | | | $IWLIST = $args{IWLIST}; |
31 | | | $hostap = $args{HOSTAP}; |
32 | | | |
33 | | | |
34 | | | my @IFACES=(); |
35 | | | my @IFMACS=(); |
36 | | | |
37 | | | foreach (keys(%args)) { |
38 | | | if (index($_,"IFACE:") >=0 ) { |
39 | | | (undef,$device)=split /:/; |
40 | | | push @IFACES,$device; |
41 | | | } |
42 | | | } |
43 | | | foreach (keys(%args)) { |
44 | | | if (index($_,"MAC,") >=0 ) { |
45 | | | (undef,$dev,$mac)=split /,/; |
46 | | | push @IFMACS,"$dev,$mac"; |
47 | | | } |
48 | | | } |
49 | | | |
50 | | | foreach $device (@IFACES) { |
51 | | | my $rate = 0; |
52 | | | my $quality = 0; |
53 | | | my $signal = 0; |
54 | | | my $noise = 0; |
55 | | | my $mode = 0; |
56 | | | |
57 | | | $command = "$IWCONF $device"; |
58 | | | open (FILE,"$command|"); |
59 | | | while(<FILE>) { |
60 | | | $var=$_; |
61 | | | if ($var =~ /^.*Rate[=|:]+(.*)M.*/) { |
62 | | | $rate = $1; |
63 | | | } elsif ($var =~ /^.*Quality[=|:]+(.*)\/.*[=|:](.*)\sdBm.*[=|:](.*)\sdBm.*/) { |
64 | | | $quality = $1; |
65 | | | $signal = $2; |
66 | | | $noise = $3; |
67 | | | last; |
68 | | | } elsif ($var =~ /^.*Mode[=|:]+(.*) Fre.*/ ) { |
69 | | | $mode=$1; |
70 | | | } |
71 | | | } |
72 | | | close(FILE); |
73 | | | $rate=$rate*1; |
74 | | | |
75 | | | if ( $mode eq "Managed" ) { |
76 | | | if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") } |
77 | | | RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise; |
78 | | | if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; } |
79 | | | } |
80 | | | |
81 | | | if ( $mode eq "Ad-Hoc" ) { |
82 | | | if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") } |
83 | | | RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise; |
84 | | | if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; } |
85 | | | } |
86 | | | |
87 | | | #print "$device $mode $signal\n"; |
88 | | | |
89 | | | if (( $mode eq "Master" ) && ( $device =~ /ath(.*)/ )) { |
90 | | | $IFMACSNR[0]=7; |
91 | | | $IFMACSNR[1]=4; |
92 | | | $clients = 0; |
93 | | | $madwifing=0; |
94 | | | $wlancmd = "/usr/local/bin/wlanconfig"; |
95 | | | |
96 | | | #old vs ng madwifi detection |
97 | | | $command = "/sbin/modinfo ath_pci"; |
98 | | | open (FILE,"$command|"); |
99 | | | while(<FILE>) { |
100 | | | $var=$_; |
101 | | | if ($var =~ /^version:.*svn (.*)/) { |
102 | | | $version = $1; |
103 | | | $madwifing=1; |
104 | | | } |
105 | | | } |
106 | | | close(FILE); |
107 | | | |
108 | | | #print "version: $version\n"; |
109 | | | |
110 | | | |
111 | | | if ( $madwifing == 1 ) { |
112 | | | ############# madwifi-ng ########### |
113 | | | #getting all clients into variable |
114 | | | $command = "$wlancmd $device list sta | grep ^0"; |
115 | | | #print "ng: $command\n"; |
116 | | | #processing all clients to get mac and signal |
117 | | | #print "twu som @macline \n"; |
118 | | | open (FILE,"$command|"); |
119 | | | while(<FILE>) { |
120 | | | $var=$_; |
121 | | | @macline=split(" ",$var); |
122 | | | #print "tu som @macline \n"; |
123 | | | $clients = $clients + 1; |
124 | | | |
125 | | | $mac = shift(@macline); |
126 | | | $signal = shift(@macline); |
127 | | | $signal = shift(@macline); |
128 | | | $signal = shift(@macline); |
129 | | | $signal = shift(@macline); |
130 | | | #print "mac adresa : $mac ma signal $signal\n"; |
131 | | | #print "mac adresy : @IFMACS\n"; |
132 | | | $nummac = 0; |
133 | | | foreach $ifmac (@IFMACS) { |
134 | | | ($ifmaci,$ifmacm)=split(/,/,$ifmac); |
135 | | | if ($ifmaci eq $device ) { |
136 | | | if ($ifmacm eq $mac) { |
137 | | | #print "$ifmaci $ifmacm $ifmac\n"; |
138 | | | $IFMACSNR[$nummac]=$signal; |
139 | | | } |
140 | | | $nummac = $nummac + 1; |
141 | | | } # if |
142 | | | } # foreach |
143 | | | } # while |
144 | | | close(FILE); |
145 | | | } # if |
146 | | | else { ############# old madwifi ########### |
147 | | | $command = "$IWLIST $device peers | grep 00 | tr \"A-Z\" \"a-z\""; |
148 | | | print "old: $command\n"; |
149 | | | open (FILE,"$command|"); |
150 | | | while(<FILE>) { |
151 | | | $var=$_; |
152 | | | $clients = $clients + 1; |
153 | | | if ($var =~ /^\s*(.*)\s:\s.*quality[=|:]+(.*)\/.*/) { |
154 | | | $signal = $2; |
155 | | | $mac = $1; |
156 | | | print "$1 $2\n"; |
157 | | | print "@IFMACS\n"; |
158 | | | $nummac = 0; |
159 | | | foreach $ifmac (@IFMACS) { |
160 | | | ($ifmaci,$ifmacm)=split(/,/,$ifmac); |
161 | | | if ($ifmaci eq $device ) { |
162 | | | if ($ifmacm eq $mac) { |
163 | | | #print "$ifmaci $ifmacm $ifmac\n"; |
164 | | | $IFMACSNR[$nummac]=$signal; |
165 | | | } |
166 | | | $nummac = $nummac + 1; |
167 | | | } # if |
168 | | | } # foreach |
169 | | | } # if |
170 | | | } # while |
171 | | | close(FILE); |
172 | | | } |
173 | | | ############# old madwifi ########### |
174 | | | |
175 | | | if ($IFMACSNR[0] eq "") { |
176 | | | $IFMACSNR[0]=1; |
177 | | | } |
178 | | | if ($IFMACSNR[1] eq "") { |
179 | | | $IFMACSNR[1]=2; |
180 | | | } |
181 | | | #print "@IFMACSNR\n"; |
182 | | | if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") } |
183 | | | RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1]; |
184 | | | if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; } |
185 | | | } # if |
186 | | | |
187 | | | if (( $mode eq "Master" ) && ( $device =~ /wlan(.*)/ )) { |
188 | | | @clients = glob( "/proc/net/hostap/$device/00*" ); |
189 | | | $clients = @clients; |
190 | | | $clients = $clients*1; |
191 | | | $signal=0; |
192 | | | $noise=0; |
193 | | | @IFMACSNR=(); |
194 | | | foreach $ifmac (@IFMACS) |
195 | | | { |
196 | | | ($ifmaci,$ifmacm)=split(/,/,$ifmac); |
197 | | | if ($ifmaci eq $device ) { |
198 | | | $iwmsnr=0; |
199 | | | if ( -r "/proc/net/hostap/$ifmaci/$ifmacm" ) |
200 | | | { |
201 | | | open (FILE,"/proc/net/hostap/$ifmaci/$ifmacm"); |
202 | | | while(<FILE>) |
203 | | | { |
204 | | | $var=$_; |
205 | | | if ($var =~ /^.*silence=+(.*) dBm.*signal=+(.*) dBm.*rate=.*/) |
206 | | | { |
207 | | | ($iwmsilence,undef)=split(/ /,$1); |
208 | | | ($iwmsignal,undef)=split(/ /,$2); |
209 | | | $iwmsnr=$iwmsignal-$iwmsilence; |
210 | | | last; |
211 | | | } |
212 | | | } |
213 | | | close(FILE); |
214 | | | } |
215 | | | push @IFMACSNR,$iwmsnr; |
216 | | | } |
217 | | | } |
218 | | | push @IFMACSNR,15; |
219 | | | push @IFMACSNR,25; |
220 | | | if ($IFMACSNR[0] eq "") { |
221 | | | $IFMACSNR[0]=11; |
222 | | | } |
223 | | | if ($IFMACSNR[1] eq "") { |
224 | | | $IFMACSNR[1]=22; |
225 | | | } |
226 | | | |
227 | | | if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") } |
228 | | | RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1]; |
229 | | | if ($ERROR = RRDs::error) { dupe_control("warn",$ARGS{"MODNAME"},"unable to update `$device.rrd': $ERROR"); } |
230 | | | } |
231 | | | } |
232 | | | #uncomment this for debug output to temp.txt |
233 | | | #all print will be done into the file |
234 | | | close (TEMPFILE); |
235 | | | close (STDERR); |
236 | | | close (STDOUT); |
237 | | | } |
238 | | | 1; |