-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathetherify4.sh
executable file
·176 lines (136 loc) · 4.41 KB
/
etherify4.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
# Etherify 4 - silly hack to send data wirelessly by changing the speed
# of an ethernet interface. This is an implementation for
# devices which change speed slowly
#
# (c) 2020 Jacek Lipkowski SQ5BPF <[email protected]>
# https://lipkowski.com/etherify4
#
# See also: https://lipkowski.com/etherify
#
# Tested on two Dell Laptops: Latitude 6220 running debian bullseye
# (transmitter) and Latitude D610 running debian stretch (passively sitting
# on the other side of the ethernet link)
# This works by switching between 10Mbps and 100Mbps, which results
# in a change of the electromagnetic radiation that leaks from the devices.
# Switching to 100Mbps produces a signal at 125MHz and it's harmonics,
# which is used to transmit slow morse code.
#
# This enables one to leak data out via morse code.
#
# To receive use software for slow telegraphy (search for QRSS CW),
# such as an sdr receiver and DL4YHF Spectrum Lab
#
# During tests the signal could be received at a distance of 7m.
# Longer distances might work also, but haven't been tested.
#
# Notice:
# - conduct the tests in an electromagnetically quiet area
# - make sure that there is an ethernet link
# - run this as root
# - listen at integer multiples od 125MHz, often they are stronger
#
# This script is licensed under GPL v3
#
# I disclaim any liability for things that this software does or doesn't do.
# Everything is the responsibility of the user.
#
declare -A cw=( [0]='-----' [1]='.----' [2]='..---' [3]='...--' [4]='....-' [5]='.....' [6]='-....' [7]='--...' [8]='---..' [9]='----.' [a]='.-' [b]='-...' [c]='-.-.' [d]='-..' [e]='.' [f]='..-.' [g]='--.' [h]='....' [i]='..' [j]='.---' [k]='-.-' [l]='.-..' [m]='--' [n]='-.' [o]='---' [p]='.--.' [q]='--.-' [r]='.-.' [s]='...' [t]='-' [u]='..-' [v]='...-' [w]='.--' [x]='-..-' [y]='-.--' [z]='--..' ['/']='-..-.' ['.']='.-.-.-' ['!']='--..--' ['?']='..--..' ['=']='-...-' [kn]='-.--.' [sk]='...-.-' [ar]='.-.-.' [bk]='-...-.-' )
text2morse() {
IN="${1,,}"
OUT=""
for (( pos=0 ; pos < ${#IN} ; pos++ ))
do
ch="${IN:$pos:1}"
[ "$ch" = " " ] && OUT+=" " && continue
[ "${cw[$ch]}" ] && OUT+="${cw[$ch]} " || OUT+="${cw['?']} "
done
echo "$OUT"
}
txon() {
ethtool -s $NETDEVICE autoneg off duplex full speed 100
}
txoff() {
ethtool -s $NETDEVICE autoneg off duplex full speed 10
}
wait_linkdetected() {
while : ; do
ethtool $NETDEVICE | grep 'Link detected: yes' >/dev/null && break
sleep 0.01
done
}
calibrate() {
echo "calibrating link renegotiation time"
txoff; txon
TXBEGIN=$EPOCHREALTIME
wait_linkdetected
TXEND=$EPOCHREALTIME
LINKDELAY=`echo -e "scale=5\n${TXEND}-${TXBEGIN}"| bc -l`
}
etherify4_send() {
B="$1"
while [ "$B" ]; do
C="${B:0:1}"
B="${B:1}"
echo -n "$C"
txon; sleep 0.1; txoff #hack
case "$C" in
"-") txon; wait_linkdetected ; sleep $SLEEPDASH ;;
".") txon; wait_linkdetected; sleep $SLEEPDOT ;;
" ") txoff; sleep $SLEEPDASH ;;
esac
txoff
done
echo
}
find_ethernet_device() {
for i in /sys/class/net/*
do
j=`basename $i`
ethtool $j | grep Duplex >/dev/null && echo $j && return
done
echo "No suitable ethernet device found"
exit 1
}
find_prerequisites() {
while [ "$1" ]; do
which "$1" >/dev/null && shift && continue
echo "ERROR: $1 not found, please install it"
exit 1
done
}
############# main
cat <<EOF
Etherify 4 , sending wireless by manipulating interface speed.
Please tune around 125MHz QRSS CW, or it's harmonics 250MHz, 375MHz, 500MHz etc
(c) 2020 Jacek Lipkowski SQ5BPF
EOF
find_prerequisites bc ethtool
[ ! "$NETDEVICE" ] && NETDEVICE=`find_ethernet_device`
echo "Using network device $NETDEVICE"
calibrate
A=`echo -e "scale=5; $LINKDELAY > 0.1" | bc -l`
if [ "$A" = 0 ]; then
echo "The link-change delay is too small, use etherify1.sh instead"
exit 1
fi
TEXT="etherify4demo="
[ "$1" -a -f "$1" ] && TEXT=`tr '\n' ' ' < $1 | sed -re 's/ */ /g'`
CWTEXT=`text2morse "$TEXT"`
cat <<EOF
Sending: "${TEXT}"
$CWTEXT
EOF
SLEEPDOT=$LINKDELAY
SLEEPDASH=`echo -e "scale=5\n${LINKDELAY}*3"| bc -l`
SLEEPSPACE=`echo -e "scale=5\n${LINKDELAY}*2"| bc -l`
echo "delay: $LINKDELAY seconds"
echo "dot: $SLEEPDOT seconds dash: $SLEEPDASH seconds"
if ethtool $NETDEVICE | grep 'Link detected: yes' > /dev/null; then
while : ; do
etherify4_send "$CWTEXT"
sleep $SLEEPSPACE ; sleep $SLEEPSPACE ; sleep $SLEEPSPACE ; sleep $SLEEPSPACE
done
else
echo "Aborting, there is no ethernet link on interface $NETDEVICE"
fi