From: Michael Tremer Date: Sun, 23 Sep 2012 20:08:25 +0000 (+0000) Subject: Move phy functions in their own file. X-Git-Tag: 005~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=590cb657e686a3eb1dbe19f3e4e00114e5ba58c0;p=network.git Move phy functions in their own file. --- diff --git a/functions.phy b/functions.phy new file mode 100644 index 00000000..f6b74984 --- /dev/null +++ b/functions.phy @@ -0,0 +1,84 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2010 Michael Tremer & Christian Schmidt # +# # +# 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 . # +# # +############################################################################### + +PHY_DIR="/sys/class/ieee80211" + +function phy_dir() { + local phy=${1} + + echo "${PHY_DIR}/${phy}" +} + +function phy_exists() { + local phy=${1} + assert isset phy + + [ -d "$(phy_dir ${phy})" ] +} + +function phy_list() { + local phy + + for phy in $(phy_dir)/*; do + [ -d "${phy}" ] || continue + + basename ${phy} + done +} + +function phy_get() { + local info=${1} + + local phy + + if listmatch ${info} $(phy_list); then + phy="${info}" + elif device_exists ${info}; then + info=$(device_get_address ${info}) + fi + + if [ -z "${phy}" ] && mac_is_valid ${info}; then + local i + for i in $(phy_list); do + if [ "${info}" = "$(phy_get_address ${i})" ]; then + phy=${i} + break + fi + done + fi + + if [ -z "${phy}" ]; then + return ${EXIT_ERROR} + fi + + echo "${phy}" + return ${EXIT_OK} +} + +function phy_get_address() { + local phy=${1} + assert isset phy + + local path="$(phy_dir ${phy})/macaddress" + [ -r "${path}" ] || return ${EXIT_ERROR} + + print "$(<${path})" +} diff --git a/functions.wireless b/functions.wireless index 22477a05..4913eae9 100644 --- a/functions.wireless +++ b/functions.wireless @@ -19,65 +19,6 @@ # # ############################################################################### -PHY_DIR="/sys/class/ieee80211" - -function phy_dir() { - local phy=${1} - - echo "${PHY_DIR}/${phy}" -} - -function phy_exists() { - local phy=${1} - - [ -d "$(phy_dir ${phy})" ] -} - -function phy_list() { - local phy - for phy in $(phy_dir)/*; do - phy=$(basename ${phy}) - echo "${phy}" - done -} - -function phy_get() { - local info=${1} - - local phy - - if listmatch ${info} $(phy_list); then - phy="${info}" - elif device_exists ${info}; then - info=$(device_get_address ${info}) - fi - - if [ -z "${phy}" ] && mac_is_valid ${info}; then - local i - for i in $(phy_list); do - if [ "${info}" = "$(phy_get_address ${i})" ]; then - phy=${i} - break - fi - done - fi - - if [ -z "${phy}" ]; then - return ${EXIT_ERROR} - fi - - echo "${phy}" - return ${EXIT_OK} -} - -function phy_get_address() { - local phy=${1} - - assert isset phy - - cat $(phy_dir ${phy})/macaddress 2>/dev/null -} - function wireless_create() { local device=${1} local phy=$(phy_get ${2})