#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2013 IPFire Network Development Team # # # # 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 3 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, see . # # # ############################################################################### function usb_device_find_by_tty() { local tty="${1}" assert isset tty # Strip /dev. tty="$(basename "${tty}")" local path="/sys/bus/usb-serial/devices/${tty}" # Resolve symlink path="$(readlink -m "${path}")" print "$(dirname "${path}")" return ${EXIT_OK} } function usb_device_list_interfaces() { local path="${1}" assert [ -d "${path}" ] local interface for interface in ${path}/ep_*; do [ -d "${interface}" ] || continue print "${interface}" done return ${EXIT_OK} } function usb_device_get_interface_type() { local interface="${1}" assert isset interface fread "${interface}/type" } function usb_device_has_interface_type_interrupt() { local device="${1}" assert isset device local interface type while read -r interface; do type="$(usb_device_get_interface_type "${interface}")" [ "${type}" = "Interrupt" ] && return ${EXIT_TRUE} done <<< "$(usb_device_list_interfaces "${device}")" return ${EXIT_FALSE} }