diff options
author | James <> | 2013-03-17 12:16:37 +0000 |
---|---|---|
committer | James <> | 2013-03-17 12:16:37 +0000 |
commit | 27b76ab0671089c47506615a796a261e993896a7 (patch) | |
tree | 61213d67e7fa87b20356b23798558e2c4212c42f /package/system/utils/usb-modeswitch | |
download | trunk-36060-27b76ab0671089c47506615a796a261e993896a7.tar.gz trunk-36060-27b76ab0671089c47506615a796a261e993896a7.tar.bz2 trunk-36060-27b76ab0671089c47506615a796a261e993896a7.zip |
Diffstat (limited to 'package/system/utils/usb-modeswitch')
6 files changed, 571 insertions, 0 deletions
diff --git a/package/system/utils/usb-modeswitch/.svn/entries b/package/system/utils/usb-modeswitch/.svn/entries new file mode 100644 index 0000000..e3010d2 --- /dev/null +++ b/package/system/utils/usb-modeswitch/.svn/entries @@ -0,0 +1,65 @@ +10 + +dir +36060 +svn://svn.openwrt.org/openwrt/trunk/package/system/utils/usb-modeswitch +svn://svn.openwrt.org/openwrt + + + +2013-01-29T12:27:17.572122Z +35381 +nbd + + + + + + + + + + + + + + +3c298f89-4303-0410-b956-a3cf2f4a3e73 + +files +dir + +Makefile +file + + + + +2013-03-17T12:13:15.000000Z +56a0a31781f5f099ee19aa50821746c8 +2013-01-29T12:27:17.572122Z +35381 +nbd + + + + + + + + + + + + + + + + + + + + + +2306 + diff --git a/package/system/utils/usb-modeswitch/.svn/text-base/Makefile.svn-base b/package/system/utils/usb-modeswitch/.svn/text-base/Makefile.svn-base new file mode 100644 index 0000000..d82a83c --- /dev/null +++ b/package/system/utils/usb-modeswitch/.svn/text-base/Makefile.svn-base @@ -0,0 +1,82 @@ +# +# Copyright (C) 2008-2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=usb-modeswitch +PKG_VERSION:=1.2.5 +PKG_DATA_VERSION:=20121109 +PKG_RELEASE:=1 + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=http://www.draisberghof.de/usb_modeswitch +PKG_MD5SUM:=c393603908eceab95444c5bde790f6f0 + +PKG_DATA_PATH:=usb-modeswitch-data-$(PKG_DATA_VERSION) +PKG_DATA_FILENAME:=$(PKG_DATA_PATH).tar.bz2 + +PKG_MAINTAINER := Felix Fietkau <nbd@openwrt.org> + +include $(INCLUDE_DIR)/package.mk + +define Package/usb-modeswitch + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=+libusb-compat + TITLE:=USB ModeSwitch + URL:=http://www.draisberghof.de/usb_modeswitch/ +endef + +define Package/usb-modeswitch/description + A mode switching tool for controlling + "flip flop" (multiple device) USB gear. +endef + +define Package/usb-modeswitch-data + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=usb-modeswitch + VERSION:=$(PKG_DATA_VERSION) + TITLE:=USB ModeSwitch - Dongle configuration database + URL:=http://www.draisberghof.de/usb_modeswitch/ +endef + +define Package/usb-modeswitch-data/description + Configuration database for usb-modeswitch. + Contains definitions for many USB devices required to + autoswitch "flip flop" gear. +endef + +define Download/data + FILE:=$(PKG_DATA_FILENAME) + URL:=$(PKG_SOURCE_URL) + MD5SUM:=a7d23a03157871013a0d708ab2b1b6df +endef +$(eval $(call Download,data)) + +define Build/Compile + tar xvfj $(DL_DIR)/$(PKG_DATA_FILENAME) -C $(PKG_BUILD_DIR) + $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) $(TARGET_LDFLAGS) \ + -lusb \ + -o $(PKG_BUILD_DIR)/usb_modeswitch-OpenWrt \ + $(PKG_BUILD_DIR)/usb_modeswitch.c +endef + +define Package/usb-modeswitch/install + $(INSTALL_DIR) $(1)/usr/bin $(1)/etc/hotplug.d/usb + $(INSTALL_BIN) $(PKG_BUILD_DIR)/usb_modeswitch-OpenWrt $(1)/usr/bin/usb_modeswitch + $(INSTALL_DATA) ./files/modeswitch.hotplug $(1)/etc/hotplug.d/usb/20-modeswitch +endef + +define Package/usb-modeswitch-data/install + $(INSTALL_DIR) $(1)/etc + $(CP) $(PKG_BUILD_DIR)/$(PKG_DATA_PATH)/usb_modeswitch.d $(1)/etc/ +endef + +$(eval $(call BuildPackage,usb-modeswitch)) +$(eval $(call BuildPackage,usb-modeswitch-data)) diff --git a/package/system/utils/usb-modeswitch/Makefile b/package/system/utils/usb-modeswitch/Makefile new file mode 100644 index 0000000..d82a83c --- /dev/null +++ b/package/system/utils/usb-modeswitch/Makefile @@ -0,0 +1,82 @@ +# +# Copyright (C) 2008-2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=usb-modeswitch +PKG_VERSION:=1.2.5 +PKG_DATA_VERSION:=20121109 +PKG_RELEASE:=1 + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=http://www.draisberghof.de/usb_modeswitch +PKG_MD5SUM:=c393603908eceab95444c5bde790f6f0 + +PKG_DATA_PATH:=usb-modeswitch-data-$(PKG_DATA_VERSION) +PKG_DATA_FILENAME:=$(PKG_DATA_PATH).tar.bz2 + +PKG_MAINTAINER := Felix Fietkau <nbd@openwrt.org> + +include $(INCLUDE_DIR)/package.mk + +define Package/usb-modeswitch + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=+libusb-compat + TITLE:=USB ModeSwitch + URL:=http://www.draisberghof.de/usb_modeswitch/ +endef + +define Package/usb-modeswitch/description + A mode switching tool for controlling + "flip flop" (multiple device) USB gear. +endef + +define Package/usb-modeswitch-data + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=usb-modeswitch + VERSION:=$(PKG_DATA_VERSION) + TITLE:=USB ModeSwitch - Dongle configuration database + URL:=http://www.draisberghof.de/usb_modeswitch/ +endef + +define Package/usb-modeswitch-data/description + Configuration database for usb-modeswitch. + Contains definitions for many USB devices required to + autoswitch "flip flop" gear. +endef + +define Download/data + FILE:=$(PKG_DATA_FILENAME) + URL:=$(PKG_SOURCE_URL) + MD5SUM:=a7d23a03157871013a0d708ab2b1b6df +endef +$(eval $(call Download,data)) + +define Build/Compile + tar xvfj $(DL_DIR)/$(PKG_DATA_FILENAME) -C $(PKG_BUILD_DIR) + $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) $(TARGET_LDFLAGS) \ + -lusb \ + -o $(PKG_BUILD_DIR)/usb_modeswitch-OpenWrt \ + $(PKG_BUILD_DIR)/usb_modeswitch.c +endef + +define Package/usb-modeswitch/install + $(INSTALL_DIR) $(1)/usr/bin $(1)/etc/hotplug.d/usb + $(INSTALL_BIN) $(PKG_BUILD_DIR)/usb_modeswitch-OpenWrt $(1)/usr/bin/usb_modeswitch + $(INSTALL_DATA) ./files/modeswitch.hotplug $(1)/etc/hotplug.d/usb/20-modeswitch +endef + +define Package/usb-modeswitch-data/install + $(INSTALL_DIR) $(1)/etc + $(CP) $(PKG_BUILD_DIR)/$(PKG_DATA_PATH)/usb_modeswitch.d $(1)/etc/ +endef + +$(eval $(call BuildPackage,usb-modeswitch)) +$(eval $(call BuildPackage,usb-modeswitch-data)) diff --git a/package/system/utils/usb-modeswitch/files/.svn/entries b/package/system/utils/usb-modeswitch/files/.svn/entries new file mode 100644 index 0000000..f809162 --- /dev/null +++ b/package/system/utils/usb-modeswitch/files/.svn/entries @@ -0,0 +1,62 @@ +10 + +dir +36060 +svn://svn.openwrt.org/openwrt/trunk/package/system/utils/usb-modeswitch/files +svn://svn.openwrt.org/openwrt + + + +2013-01-29T12:02:10.199677Z +35379 +nbd + + + + + + + + + + + + + + +3c298f89-4303-0410-b956-a3cf2f4a3e73 + +modeswitch.hotplug +file + + + + +2013-03-17T12:13:15.000000Z +b72c264f2a28f8da63f1a7b6621c18a5 +2013-01-29T12:02:10.199677Z +35379 +nbd + + + + + + + + + + + + + + + + + + + + + +3073 + diff --git a/package/system/utils/usb-modeswitch/files/.svn/text-base/modeswitch.hotplug.svn-base b/package/system/utils/usb-modeswitch/files/.svn/text-base/modeswitch.hotplug.svn-base new file mode 100644 index 0000000..eb71b30 --- /dev/null +++ b/package/system/utils/usb-modeswitch/files/.svn/text-base/modeswitch.hotplug.svn-base @@ -0,0 +1,140 @@ +#!/bin/sh + +local uVid uPid uMa uPr uSe +local sVe sMo sRe + +local modeswitch="/usr/bin/usb_modeswitch" + + +log() { + logger -t "usb-modeswitch" "$@" +} + +sanitize() { + sed -e 's/[[:space:]]\+$//; s/[[:space:]]\+/_/g' "$@" +} + +find_scsi_attrs() { + [ -n "$DEVPATH" ] && [ -d /sys/$DEVPATH/host* ] && { + log "$DEVICENAME is a SCSI device, waiting for it to settle..." + local timeout=20 + while [ $((--timeout)) -ge 0 ]; do + [ -d /sys/$DEVPATH/host*/target* ] && { + local scsi_dir + for scsi_dir in /sys/$DEVPATH/host*/target*/*; do + [ -d "$scsi_dir" ] || break + case "$scsi_dir" in + */host*/target*/*:*:*:*) + sVe=$(sanitize "$scsi_dir/vendor") + sMo=$(sanitize "$scsi_dir/model") + sRe=$(sanitize "$scsi_dir/rev") + + log "$DEVICENAME: Vendor=${sVe:-?} Model=${sMo:-?} Revision=${sRe:-?}" + return 0 + ;; + esac + done + } || { + sleep 1 + } + done + log "$DEVICENAME: Failed to get SCSI attributes!" + } + + return 1 +} + +find_usb_attrs() { + local usb_dir="/sys/$DEVPATH" + [ -f "$usb_dir/idVendor" ] || usb_dir="${usb_dir%/*}" + + uVid=$(cat "$usb_dir/idVendor") + uPid=$(cat "$usb_dir/idProduct") + uMa=$(sanitize "$usb_dir/manufacturer") + uPr=$(sanitize "$usb_dir/product") + uSe=$(sanitize "$usb_dir/serial") + + log "$DEVICENAME: Manufacturer=${uMa:-?} Product=${uPr:-?} Serial=${uSe:-?}" +} + +match_config_tag() { + local conf="$1" + local tag="$2" + + case "${conf##*/}" in + *:*$tag=*) + local cmp; eval "cmp=\$$tag" + local pat="${conf#*:$tag=}"; pat="${pat%%:*}" + case "$cmp" in + *$pat*) return 0 ;; + *) return 1 ;; + esac + ;; + esac + + return 0 +} + +match_config() { + local conf="$1" + local tag + + for tag in uMa uPr uSe sVe sMo sRe; do + match_config_tag "$conf" "$tag" || return 1 + done + + return 0 +} + + + +if [ "$ACTION" = add ]; then + [ -d "/etc/usb_modeswitch.d" ] && [ -x "$modeswitch" ] && { + case "$DEVICENAME" in + *-*:*.*) : ;; + *) exit 0 ;; + esac + + find_usb_attrs + + local candidates=0 + local conf configs + for conf in /etc/usb_modeswitch.d/$uVid:$uPid*; do + [ -f "$conf" ] || break + configs="${configs:+$configs }$conf" + $((candidates++)) + done + + # Found more than one candidate, read SCSI attributes and find the best match + [ $candidates -gt 1 ] && { + find_scsi_attrs + for conf in $configs; do + match_config "$conf" && { + configs="$conf" + candidates=1 + break + } + done + } + + # If a candidate is remaining, start usb-modeswitch + [ -n "$configs" ] && { + log "$DEVICENAME: Selecting ${configs%% *} for mode switching" + # ugly workaround, but working for all hw we got for testing + switching_done=0 + switching_tries=0 + local usb_dir="/sys/$DEVPATH" + [ -f "$usb_dir/idVendor" ] || usb_dir="${usb_dir%/*}" + while [ $switching_done -lt 1 -a $switching_tries -le 6 ]; do + $modeswitch -v $uVid -p $uPid -I -D -n -s 30 -c "${configs%% *}" + if [ $(sanitize "$usb_dir/idProduct") = $uPid ]; then + log "$DEVICENAME: Switching seemingly failed" + sleep 1 + else + switching_done=1 + fi + switching_tries=$(( $switching_tries + 1 )) + done + } + } +fi diff --git a/package/system/utils/usb-modeswitch/files/modeswitch.hotplug b/package/system/utils/usb-modeswitch/files/modeswitch.hotplug new file mode 100644 index 0000000..eb71b30 --- /dev/null +++ b/package/system/utils/usb-modeswitch/files/modeswitch.hotplug @@ -0,0 +1,140 @@ +#!/bin/sh + +local uVid uPid uMa uPr uSe +local sVe sMo sRe + +local modeswitch="/usr/bin/usb_modeswitch" + + +log() { + logger -t "usb-modeswitch" "$@" +} + +sanitize() { + sed -e 's/[[:space:]]\+$//; s/[[:space:]]\+/_/g' "$@" +} + +find_scsi_attrs() { + [ -n "$DEVPATH" ] && [ -d /sys/$DEVPATH/host* ] && { + log "$DEVICENAME is a SCSI device, waiting for it to settle..." + local timeout=20 + while [ $((--timeout)) -ge 0 ]; do + [ -d /sys/$DEVPATH/host*/target* ] && { + local scsi_dir + for scsi_dir in /sys/$DEVPATH/host*/target*/*; do + [ -d "$scsi_dir" ] || break + case "$scsi_dir" in + */host*/target*/*:*:*:*) + sVe=$(sanitize "$scsi_dir/vendor") + sMo=$(sanitize "$scsi_dir/model") + sRe=$(sanitize "$scsi_dir/rev") + + log "$DEVICENAME: Vendor=${sVe:-?} Model=${sMo:-?} Revision=${sRe:-?}" + return 0 + ;; + esac + done + } || { + sleep 1 + } + done + log "$DEVICENAME: Failed to get SCSI attributes!" + } + + return 1 +} + +find_usb_attrs() { + local usb_dir="/sys/$DEVPATH" + [ -f "$usb_dir/idVendor" ] || usb_dir="${usb_dir%/*}" + + uVid=$(cat "$usb_dir/idVendor") + uPid=$(cat "$usb_dir/idProduct") + uMa=$(sanitize "$usb_dir/manufacturer") + uPr=$(sanitize "$usb_dir/product") + uSe=$(sanitize "$usb_dir/serial") + + log "$DEVICENAME: Manufacturer=${uMa:-?} Product=${uPr:-?} Serial=${uSe:-?}" +} + +match_config_tag() { + local conf="$1" + local tag="$2" + + case "${conf##*/}" in + *:*$tag=*) + local cmp; eval "cmp=\$$tag" + local pat="${conf#*:$tag=}"; pat="${pat%%:*}" + case "$cmp" in + *$pat*) return 0 ;; + *) return 1 ;; + esac + ;; + esac + + return 0 +} + +match_config() { + local conf="$1" + local tag + + for tag in uMa uPr uSe sVe sMo sRe; do + match_config_tag "$conf" "$tag" || return 1 + done + + return 0 +} + + + +if [ "$ACTION" = add ]; then + [ -d "/etc/usb_modeswitch.d" ] && [ -x "$modeswitch" ] && { + case "$DEVICENAME" in + *-*:*.*) : ;; + *) exit 0 ;; + esac + + find_usb_attrs + + local candidates=0 + local conf configs + for conf in /etc/usb_modeswitch.d/$uVid:$uPid*; do + [ -f "$conf" ] || break + configs="${configs:+$configs }$conf" + $((candidates++)) + done + + # Found more than one candidate, read SCSI attributes and find the best match + [ $candidates -gt 1 ] && { + find_scsi_attrs + for conf in $configs; do + match_config "$conf" && { + configs="$conf" + candidates=1 + break + } + done + } + + # If a candidate is remaining, start usb-modeswitch + [ -n "$configs" ] && { + log "$DEVICENAME: Selecting ${configs%% *} for mode switching" + # ugly workaround, but working for all hw we got for testing + switching_done=0 + switching_tries=0 + local usb_dir="/sys/$DEVPATH" + [ -f "$usb_dir/idVendor" ] || usb_dir="${usb_dir%/*}" + while [ $switching_done -lt 1 -a $switching_tries -le 6 ]; do + $modeswitch -v $uVid -p $uPid -I -D -n -s 30 -c "${configs%% *}" + if [ $(sanitize "$usb_dir/idProduct") = $uPid ]; then + log "$DEVICENAME: Switching seemingly failed" + sleep 1 + else + switching_done=1 + fi + switching_tries=$(( $switching_tries + 1 )) + done + } + } +fi |