A więc tak, w założeniu chcę zbudować wewnętrzną sieć LAN przeznaczoną do debugowania. W sieci będą dwa typy komputerów:
Host --> Komputer na którym piszę program, kompiluję, uruchamiam ewentualny debugger itp.
Target --> Komputer docelowy, system na którym program będzie uruchamiany. Docelowo kontrola tego komputera ma być poprzez połączenie ssh, teraz jest poprzez TTL (a dokładniej TTL <--> USB i wirtualny port COM).
Jako karty WiFi posiadam Ralink RT3070 (dwie identyczne):
Kod: Zaznacz cały
Bus 005 Device 003: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
Opis konfiguracji Hosta:
Slackware current (z okolic luty/marzec 2013):
Kod: Zaznacz cały
bash-4.2$ uname -a
Linux host_name 3.8.8-smp #2 SMP Thu Apr 18 22:59:19 CDT 2013 i686 Intel(R) Pentium(R) M processor 1.60GHz GenuineIntel GNU/Linux
Kod: Zaznacz cały
bash-4.2# cat /etc/udev/rules.d/95-wifi-detect.rules
ACTION=="add", KERNEL=="ra0", SUBSYSTEM=="net", RUN+="/bin/sh -c '/etc/rc.d/rc.ra0_wifi start &'"
ACTION=="remove", KERNEL=="ra0", SUBSYSTEM=="net", RUN+="/bin/sh -c '/etc/rc.d/rc.ra0_wifi stop &'"
bash-4.2#
bash-4.2# cat /etc/rc.d/rc.ra0_wifi
#! /bin/sh
# /etc/rc.d/rc.ra0_wifi
# Skrypt podnosi i zatrzymuje development network.
# Function to start the network:
start() {
/sbin/ifconfig ra0 up
/sbin/iwconfig ra0 mode ad-hoc
/sbin/iwconfig ra0 channel 1
/sbin/iwconfig ra0 essid 'dev_lan'
/sbin/ifconfig ra0 10.0.0.1 netmask 255.255.255.0 up
}
# Function to stop the network:
stop() {
sleep 1
}
############
### MAIN ###
############
case "$1" in
'start') # "start" brings up all configured interfaces:
start
;;
'stop') # "stop" takes down all configured interfaces:
stop
;;
*) # The default is to bring up all configured interfaces:
start
esac
# End of /etc/rc.d/rc.ra0_wifi
Kod: Zaznacz cały
bash-4.2# ifconfig
ra0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.1 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::225:22ff:fe3f:xxxx prefixlen 64 scopeid 0x20<link>
ether 00:25:22:xx:xx:xx txqueuelen 1000 (Ethernet)
RX packets 0 bytes 2045 (1.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 1556 (1.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
bash-4.2#
bash-4.2# iwconfig
ra0 Ralink STA ESSID:"dev_lan" Nickname:"RT2870STA"
Mode:Ad-Hoc Frequency=2.412 GHz Cell: 7E:2D:28:34:1C:BE
Bit Rate=135 Mb/s
RTS thr:off Fragment thr:off
Encryption key:off
Link Quality=100/100 Signal level:-33 dBm Noise level:-33 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Raspberry pi --> 2013-05-25-wheezy-raspbian
Kod: Zaznacz cały
pi@raspberrypi:~$ uname -a
Linux raspberrypi 3.6.11+ #456 PREEMPT Mon May 20 17:42:15 BST 2013 armv6l GNU/Linux
Kod: Zaznacz cały
pi@raspberrypi:~$ cat /etc/init.d/ra0_wifi
#! /bin/sh
# /etc/init.d/ra0_wifi
# Skrypt podnosi i zatrzymuje development network.
### BEGIN INIT INFO
# Provides: ra0 interface with Ad-Hoc network
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Skrypt podnosi i zatrzymuje development network.
# Description: Skrypt podnosi i zatrzymuje development network.
### END INIT INFO
# Function to start the network:
start() {
/sbin/ifconfig ra0 up
/sbin/iwconfig ra0 mode ad-hoc
/sbin/iwconfig ra0 channel 1
/sbin/iwconfig ra0 essid 'dev_lan'
/sbin/ifconfig ra0 10.0.0.2 netmask 255.255.255.0 up
}
# Function to stop the network:
stop() {
sleep 1
}
############
### MAIN ###
############
case "$1" in
'start') # "start" brings up all configured interfaces:
start
;;
'stop') # "stop" takes down all configured interfaces:
stop
;;
*) # The default is to bring up all configured interfaces:
start
esac
exit 0
# End of /etc/init.d/ra0_wifi
Kod: Zaznacz cały
pi@raspberrypi:~$ ifconfig
ra0 Link encap:Ethernet HWaddr 00:25:22:xx:xx:xx
inet addr:10.0.0.2 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:3 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:380637 (371.7 KiB) TX bytes:6790 (6.6 KiB)
pi@raspberrypi:~$
pi@raspberrypi:~$ iwconfig
ra0 Ralink STA ESSID:"dev_lan" Nickname:"RT2870STA"
Mode:Ad-Hoc Frequency=2.412 GHz Cell: 7E:2D:28:34:1C:BE
Bit Rate=135 Mb/s
RTS thr:off Fragment thr:off
Link Quality=100/100 Signal level:-31 dBm Noise level:-49 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Kod: Zaznacz cały
bash-4.2# ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=3.63 ms
64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=1.16 ms
64 bytes from 10.0.0.2: icmp_req=3 ttl=64 time=2.62 ms
^C
--- 10.0.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.160/2.470/3.630/1.014 ms
Kod: Zaznacz cały
bash-4.2# ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
^C
--- 10.0.0.2 ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 5999ms
Jeżeli wyjmę kartę WiFi z hosta i odetnę zasilanie w targecie, następnie podłączę kartę WiFi do hosta i włączę zasilanie w targecie; wtedy bingo, znów działa:
Kod: Zaznacz cały
pi@raspberrypi:~$ ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_req=1 ttl=64 time=6.47 ms
64 bytes from 10.0.0.1: icmp_req=2 ttl=64 time=1.14 ms
64 bytes from 10.0.0.1: icmp_req=3 ttl=64 time=1.07 ms
64 bytes from 10.0.0.1: icmp_req=4 ttl=64 time=1.16 ms
64 bytes from 10.0.0.1: icmp_req=5 ttl=64 time=1.08 ms
64 bytes from 10.0.0.1: icmp_req=6 ttl=64 time=1.15 ms
64 bytes from 10.0.0.1: icmp_req=7 ttl=64 time=1.20 ms
^C
--- 10.0.0.1 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6009ms
rtt min/avg/max/mdev = 1.077/1.899/6.479/1.870 ms
Dlaczego odłączenie jednego z komputerów w sieci wymusza restart obydwóch interfejsów sieciowych?
PS.
Wydaje się lepszym rozwiązaniem hostapd, ale rt5370 nie wspiera tego trybu niestety.