Imported Upstream version 2.4.3

This commit is contained in:
arnaud.quette@free.fr 2010-03-26 00:20:59 +01:00
commit 26fb71b504
446 changed files with 148951 additions and 0 deletions

14
tools/Makefile.am Normal file
View file

@ -0,0 +1,14 @@
EXTRA_DIST = nut-usbinfo.pl device-recorder.sh
# only call the USB info script upon "make dist", and if Perl is present
dist-hook:
@if test -x /usr/bin/perl; then \
echo "Regenerating the USB helper files."; \
$(distdir)/nut-usbinfo.pl; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: Perl is not available."; \
echo "Skipping the USB helper files regeneration."; \
echo "----------------------------------------------------------------------"; \
fi

426
tools/Makefile.in Normal file
View file

@ -0,0 +1,426 @@
# Makefile.in generated by automake 1.11 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
subdir = tools
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/nut_arg_with.m4 \
$(top_srcdir)/m4/nut_check_ipv6.m4 \
$(top_srcdir)/m4/nut_check_libgd.m4 \
$(top_srcdir)/m4/nut_check_libhal.m4 \
$(top_srcdir)/m4/nut_check_libneon.m4 \
$(top_srcdir)/m4/nut_check_libnetsnmp.m4 \
$(top_srcdir)/m4/nut_check_libpowerman.m4 \
$(top_srcdir)/m4/nut_check_libssl.m4 \
$(top_srcdir)/m4/nut_check_libusb.m4 \
$(top_srcdir)/m4/nut_check_libwrap.m4 \
$(top_srcdir)/m4/nut_check_os.m4 \
$(top_srcdir)/m4/nut_report_feature.m4 \
$(top_srcdir)/m4/nut_type_socklen_t.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
SOURCES =
DIST_SOURCES =
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BINDIR = @BINDIR@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CONFPATH = @CONFPATH@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@
DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@
DRIVER_MAN_LIST = @DRIVER_MAN_LIST@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GREP = @GREP@
HAL_CALLOUTS_PATH = @HAL_CALLOUTS_PATH@
HAL_DEVICE_MATCH_KEY = @HAL_DEVICE_MATCH_KEY@
HAL_FDI_PATH = @HAL_FDI_PATH@
HAL_USER = @HAL_USER@
HAVE_GLIB_2_14 = @HAVE_GLIB_2_14@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBGD_CFLAGS = @LIBGD_CFLAGS@
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
LIBHAL_LDFLAGS = @LIBHAL_LDFLAGS@
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
LIBNEON_LDFLAGS = @LIBNEON_LDFLAGS@
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
LIBNETSNMP_LDFLAGS = @LIBNETSNMP_LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@
LIBPOWERMAN_LDFLAGS = @LIBPOWERMAN_LDFLAGS@
LIBS = @LIBS@
LIBSSL_CFLAGS = @LIBSSL_CFLAGS@
LIBSSL_LDFLAGS = @LIBSSL_LDFLAGS@
LIBTOOL = @LIBTOOL@
LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
LIBUSB_LDFLAGS = @LIBUSB_LDFLAGS@
LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@
LIBWRAP_LDFLAGS = @LIBWRAP_LDFLAGS@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NETLIBS = @NETLIBS@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OS_NAME = @OS_NAME@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
RUN_AS_GROUP = @RUN_AS_GROUP@
RUN_AS_USER = @RUN_AS_USER@
SED = @SED@
SERLIBS = @SERLIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STATEPATH = @STATEPATH@
STRIP = @STRIP@
SUN_LIBUSB = @SUN_LIBUSB@
VERSION = @VERSION@
WORDS_BIGENDIAN = @WORDS_BIGENDIAN@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
cgiexecdir = @cgiexecdir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
driverexecdir = @driverexecdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
hotplugdir = @hotplugdir@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
pkgconfigdir = @pkgconfigdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
udevdir = @udevdir@
EXTRA_DIST = nut-usbinfo.pl device-recorder.sh
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tools/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --gnu tools/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
tags: TAGS
TAGS:
ctags: CTAGS
CTAGS:
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$(top_distdir)" distdir="$(distdir)" \
dist-hook
check-am: all-am
check: check-am
all-am: Makefile
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
dist-hook distclean distclean-generic distclean-libtool \
distdir dvi dvi-am html html-am info info-am install \
install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
uninstall uninstall-am
# only call the USB info script upon "make dist", and if Perl is present
dist-hook:
@if test -x /usr/bin/perl; then \
echo "Regenerating the USB helper files."; \
$(distdir)/nut-usbinfo.pl; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: Perl is not available."; \
echo "Skipping the USB helper files regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

96
tools/device-recorder.sh Executable file
View file

@ -0,0 +1,96 @@
#!/bin/sh
################################################################################
#
# device-recorder.sh
# A script to record device running sequence and dump it in a .seq format
# The .seq file can then be used by dummy-ups to replay the sequence.
#
################################################################################
# FIXME:
# - implement PAUSE / RESUME (do not increment TIMER) on pressing space
################################################################################
strUsage="Usage: dummy-recorder.sh <device-name> [output-file] [interval]"
# log data each 5 seconds
DEFAULT_INTERVAL=5
# temporary files location
TEMP_DIR="/tmp"
# output to dummy-device.dev by default
DEFAULT_OUTPUT="dummy-device.seq"
# Process command line parameters
if [ -z "$1" ]; then
echo "$strUsage"
exit
else
devName=$1
fi
if [ -z "$2" ]; then
outFile=$DEFAULT_OUTPUT
else
outFile=$2
fi
if [ -z "$3" ]; then
pollInterval=$DEFAULT_INTERVAL
else
pollInterval=$3
fi
# initialize TIMER value
curTimer=0
# Test communication with the device
testResult="`upsc $devName > /dev/null`"
if [ $? -gt 0 ]; then
echo "$devName: $testResult"
exit
fi
# initialize output file
echo "# dummy-ups sequence recorded with $0\n"> $outFile
# initialize data
upsc $devName >> $outFile
cp -f $outFile ${TEMP_DIR}/prevDump.tmp
echo "Initial data:\n"
cat $outFile
while (true)
do
# rest a bit before getting fresh data
sleep $pollInterval
# update the TIMER value
curTimer=`expr $curTimer + $pollInterval`
# dump the current data
testResult="`upsc $devName > ${TEMP_DIR}/curDump.tmp`"
if [ $? -gt 0 ]; then
echo "$devName: $testResult"
# FIXME: what to do (pause, exit)?
fi
# do the diff
dataDiff="`diff --unchanged-line-format='' --old-line-format='' --new-line-format='%L' ${TEMP_DIR}/prevDump.tmp ${TEMP_DIR}/curDump.tmp`"
# dump actual, if any
if [ ! -z "${dataDiff}" ]; then
# dump differences
echo "TIMER $curTimer" >> $outFile
echo "$dataDiff" >> $outFile
# and echo out
echo "TIMER $curTimer"
echo "$dataDiff"
curTimer=0
fi
# rotate dumps
mv ${TEMP_DIR}/curDump.tmp ${TEMP_DIR}/prevDump.tmp
done

274
tools/nut-usbinfo.pl Executable file
View file

@ -0,0 +1,274 @@
#!/usr/bin/perl
# Current Version : 1.0
# Copyright (C) 2008
# Arnaud Quette <arnaud.quette@gmail.com>
# dloic (loic.dardant AT gmail DOT com)
#
# Based on the usbdevice.pl script, made for the Ubuntu Media Center
# for the final use of the LIRC project.
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use File::Find;
use strict;
# path to scan for USB_DEVICE pattern
my $scanPath="../drivers";
# HAL output file
my $outputHAL="../scripts/hal/ups-nut-device.fdi.in";
# Hotplug output file
my $outputHotplug="../scripts/hotplug/libhid.usermap";
# udev output file
my $outputUdev="../scripts/udev/nut-usbups.rules.in";
# DeviceKit-power output file
my $outputDKp="../scripts/dkp/95-devkit-power-hid.rules";
# tmp output, to allow generating the ENV{DKP_VENDOR} header list
my $tmpOutputDKp;
# mfr header flag
my $dkpMfrHeaderDone = 0;
# array of products indexed by vendorID
my %vendor;
# contain for each vendor, its name (and...)
my %vendorName;
################# MAIN #################
find(\&find_usbdevs,$scanPath);
&gen_usb_files;
################# SUB METHOD #################
sub gen_usb_files
{
# HAL file header
open my $outHAL, ">$outputHAL" || die "error $outputHAL : $!";
print $outHAL '<?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- SGML -*- -->'."\n";
print $outHAL '<deviceinfo version="0.2">'."\n";
print $outHAL ' <device>'."\n";
print $outHAL ' <match key="@HAL_DEVICE_MATCH_KEY@" string="usb_device">'."\n";
# Hotplug file header
open my $outHotplug, ">$outputHotplug" || die "error $outputHotplug : $!";
print $outHotplug '# This file is generated and installed by the Network UPS Tools package.'."\n";
print $outHotplug "#\n";
print $outHotplug '# Sample entry (replace 0xVVVV and 0xPPPP with vendor ID and product ID respectively) :'."\n";
print $outHotplug '# libhidups 0x0003 0xVVVV 0xPPPP 0x0000 0x0000 0x00 0x00';
print $outHotplug ' 0x00 0x00 0x00 0x00 0x00000000'."\n";
print $outHotplug "#\n";
print $outHotplug '# usb module match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi';
print $outHotplug ' bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass';
print $outHotplug ' bInterfaceProtocol driver_info'."\n";
# Udev file header
open my $outUdev, ">$outputUdev" || die "error $outputUdev : $!";
print $outUdev '# This file is generated and installed by the Network UPS Tools package.'."\n\n";
print $outUdev 'ACTION!="add", GOTO="nut-usbups_rules_end"'."\n";
print $outUdev 'SUBSYSTEM=="usb_device", GOTO="nut-usbups_rules_real"'."\n";
print $outUdev 'SUBSYSTEM=="usb", GOTO="nut-usbups_rules_real"'."\n";
print $outUdev 'BUS!="usb", GOTO="nut-usbups_rules_end"'."\n\n";
print $outUdev 'LABEL="nut-usbups_rules_real"'."\n";
# DeviceKit-power file header
open my $outputDKp, ">$outputDKp" || die "error $outputDKp : $!";
print $outputDKp '##############################################################################################################'."\n";
print $outputDKp '# Uninterruptible Power Supplies with USB HID interfaces'."\n#\n";
print $outputDKp '# to keep up to date, monitor: http://svn.debian.org/wsvn/nut/trunk/scripts/dkp/95-devkit-power-hid.rules'."\n\n";
print $outputDKp '# only support USB, else ignore'."\n".'SUBSYSTEM!="usb", GOTO="dkp_hid_end"'."\n\n";
print $outputDKp '# if usbraw device, ignore'."\n".'KERNEL!="hiddev*", GOTO="dkp_hid_end"'."\n\n";
print $outputDKp '# if an interface, ignore'."\n".'ENV{DEVTYPE}=="usb_interface", GOTO="dkp_hid_end"'."\n\n";
# generate the file in alphabetical order (first for VendorID, then for ProductID)
foreach my $vendorId (sort { lc $a cmp lc $b } keys %vendorName)
{
# HAL vendor header
if ($vendorName{$vendorId}) {
print $outHAL "\n <!-- ".$vendorName{$vendorId}." -->\n";
}
print $outHAL " <match key=\"usb_device.vendor_id\" int=\"".$vendorId."\">\n";
# Hotplug vendor header
if ($vendorName{$vendorId}) {
print $outHotplug "\n# ".$vendorName{$vendorId}."\n";
}
# udev vendor header
if ($vendorName{$vendorId}) {
print $outUdev "\n# ".$vendorName{$vendorId}."\n";
}
# DeviceKit-power vendor header flag
$dkpMfrHeaderDone = 0;
foreach my $productId (sort { lc $a cmp lc $b } keys %{$vendor{$vendorId}})
{
# HAL device entry
print $outHAL " <!-- ".$vendor{$vendorId}{$productId}{"comment"}." -->\n";
print $outHAL " <match key=\"usb_device.product_id\" int=\"".$productId."\">\n";
print $outHAL ' <append key="info.category" type="string">battery</append>'."\n";
print $outHAL ' <merge key="info.capabilities" type="strlist">battery</merge>'."\n";
print $outHAL " <merge key=\"info.addons\" type=\"strlist\">hald-addon-".$vendor{$vendorId}{$productId}{"driver"}."</merge>\n";
print $outHAL ' <merge key="battery.type" type="string">ups</merge>'."\n";
print $outHAL ' </match>'."\n";
# Hotplug device entry
print $outHotplug "# ".$vendor{$vendorId}{$productId}{"comment"}."\n";
print $outHotplug "libhidups 0x0003 ".$vendorId." ".$productId." 0x0000 0x0000 0x00";
print $outHotplug " 0x00 0x00 0x00 0x00 0x00 0x00000000\n";
# udev device entry
print $outUdev "# ".$vendor{$vendorId}{$productId}{"comment"}.' - '.$vendor{$vendorId}{$productId}{"driver"}."\n";
print $outUdev "ATTR{idVendor}==\"".removeHexPrefix($vendorId);
print $outUdev "\", ATTR{idProduct}==\"".removeHexPrefix($productId)."\",";
print $outUdev ' MODE="664", GROUP="@RUN_AS_GROUP@"'."\n";
# DeviceKit-power device entry (only for USB/HID devices!)
if ($vendor{$vendorId}{$productId}{"driver"} eq "usbhid-ups")
{
if ($dkpMfrHeaderDone == 0)
{
# DeviceKit-power vendor header
if ($vendorName{$vendorId}) {
$tmpOutputDKp = $tmpOutputDKp."\n# ".$vendorName{$vendorId}."\n";
}
print $outputDKp "ATTRS{idVendor}==\"".removeHexPrefix($vendorId)."\", ENV{DKP_VENDOR}=\"".$vendorName{$vendorId}."\"\n";
$dkpMfrHeaderDone = 1;
}
$tmpOutputDKp = $tmpOutputDKp."ATTRS{idVendor}==\"".removeHexPrefix($vendorId);
$tmpOutputDKp = $tmpOutputDKp."\", ATTRS{idProduct}==\"".removeHexPrefix($productId)."\",";
$tmpOutputDKp = $tmpOutputDKp.' ENV{DKP_BATTERY_TYPE}="ups"'."\n";
}
}
# HAL vendor footer
print $outHAL " </match>\n";
}
# HAL footer
print $outHAL " </match>\n";
print $outHAL " </device>\n";
print $outHAL "</deviceinfo>\n";
# Udev footer
print $outUdev "\n".'LABEL="nut-usbups_rules_end"'."\n";
# DeviceKit-power...
# ...flush device table
print $outputDKp $tmpOutputDKp;
# ...and print footer
print $outputDKp "\n".'LABEL="dkp_hid_end"'."\n";
}
sub find_usbdevs
{
return $File::Find::prune = 1 if $_ eq '.svn';
my $nameFile=$_;
my $lastComment="";
open my $file,$nameFile or die "error open file $nameFile";
while(my $line=<$file>)
{
# catch comment (should permit comment on the precedent or on the current line of USB_DEVICE declaration)
if($line =~/\s*\/\*(.+)\*\/\s*$/)
{
$lastComment=$1;
}
if($line =~/^\s*\{\s*USB_DEVICE\((.+)\,(.+)\)\s*/) # for example : { USB_DEVICE(MGE_VENDORID, 0x0001)... }
{
my $VendorID=trim($1);
my $ProductID=trim($2);
my $VendorName="";
# special thing for backward declaration using #DEFINE
# Format: #define VENDORID 0x???? /* vendor name */
if(!($VendorID=~/\dx(\d|\w)+/))
{
open my $fh,$nameFile or die "error open file $nameFile";
while(my $data=<$fh>)
{
# catch Vendor Name
if($data =~/\s*\/\*(.+)\*\/\s*$/)
{
$VendorName=$1;
}
# catch VendorID
if ($data =~ /(#define|#DEFINE)\s+$VendorID\s+(\dx(\d|\w)+)/)
{
$VendorID=$2;
last;
}
}
}
# same thing for the productID
if(!($ProductID=~/\dx(\d|\w)+/))
{
my $data = do { open my $fh, $nameFile or die "error open file $nameFile"; join '', <$fh> };
if ($data =~ /(#define|#DEFINE)\s+$ProductID\s+(\dx(\d|\w)+)/)
{
$ProductID=$2;
}
else
{
die "In file $nameFile, for product $ProductID, can't find the declaration of the constant";
}
}
# store date (to be optimized)
$vendorName{$VendorID}=trim($VendorName);
$vendor{$VendorID}{$ProductID}{"comment"}=$lastComment;
# process the driver name
my $driver=$nameFile;
if($nameFile=~/(.+)-hid\.c/) {
$driver="usbhid-ups";
}
# FIXME: make a generic matching rule *.c => *
elsif ($nameFile eq "bcmxcp_usb.c") {
$driver="bcmxcp_usb";
}
elsif ($nameFile eq "tripplite_usb.c") {
$driver="tripplite_usb";
}
elsif ($nameFile eq "megatec_usb.c") {
$driver="megatec_usb";
}
elsif ($nameFile eq "blazer_usb.c") {
$driver="blazer_usb";
}
elsif ($nameFile eq "richcomm_usb.c") {
$driver="richcomm_usb";
}
else {
die "Unknown driver type: $nameFile";
}
$vendor{$VendorID}{$ProductID}{"driver"}=$driver;
}
}
}
sub removeHexPrefix {
# make a local copy, not to alter the original entry
my $string = $_[0];
$string =~ s/0x//;
return $string;
}
sub trim {
my($str) = shift =~ m!^\s*(.+?)\s*$!i;
defined $str ? return $str : return '';
}