]> git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.serial
Remove the function keyword which is a bashism
[people/stevee/network.git] / src / functions / functions.serial
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 # This is a list of baudrates that are supported.
23 SERIAL_BAUDRATES="921600 460800 230400 115200 57600 38400 19200 9600"
24
25 serial_list() {
26 local device
27 for device in /dev/ttyUSB*; do
28 if serial_exists "${device}"; then
29 echo "${device}"
30 fi
31 done
32 }
33
34 serial_exists() {
35 local device=${1}
36
37 [ -c "${device}" ]
38 }
39
40 serial_is_locked() {
41 local device=${1}
42 assert isset device
43
44 device=$(basename ${device})
45
46 local dir
47 for dir in /var/lock /var/lock/ppp; do
48 [ -e "${dir}/LCK..${device}" ] \
49 && return ${EXIT_TRUE}
50 done
51
52 return ${EXIT_FALSE}
53 }
54
55 serial_is_unlocked() {
56 serial_is_locked ${device} \
57 && return ${EXIT_FALSE} || return ${EXIT_TRUE}
58 }
59
60 serial_is_modem() {
61 local device=${1}
62 assert isset device
63
64 modem_chat --timeout=2 "${device}" "AT" &>/dev/null
65 local ret=$?
66
67 case "${ret}" in
68 ${EXIT_OK})
69 return ${EXIT_TRUE}
70 ;;
71 ${EXIT_ERROR})
72 return ${EXIT_FALSE}
73 ;;
74 *)
75 return ${EXIT_UNKNOWN}
76 ;;
77 esac
78 }
79
80 serial_get_bus_type() {
81 local device="${1}"
82 assert isset device
83
84 case "${device}" in
85 /dev/ttyUSB*)
86 print "usb"
87 return ${EXIT_OK}
88 ;;
89 esac
90
91 print "unknown"
92 return ${EXIT_ERROR}
93 }