]>
Commit | Line | Data |
---|---|---|
6c74a64c MT |
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 | ||
1c6a4e30 | 25 | serial_list() { |
f90dd58c MT |
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 | ||
1c6a4e30 | 34 | serial_exists() { |
6c74a64c MT |
35 | local device=${1} |
36 | ||
37 | [ -c "${device}" ] | |
38 | } | |
39 | ||
1c6a4e30 | 40 | serial_is_locked() { |
6c74a64c MT |
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 | ||
1c6a4e30 | 55 | serial_is_unlocked() { |
6c74a64c MT |
56 | serial_is_locked ${device} \ |
57 | && return ${EXIT_FALSE} || return ${EXIT_TRUE} | |
58 | } | |
59 | ||
1c6a4e30 | 60 | serial_is_modem() { |
6c74a64c MT |
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 | } | |
95416c1e | 79 | |
1c6a4e30 | 80 | serial_get_bus_type() { |
95416c1e MT |
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 | } |