OpenWrtでパケットキャプチャ可能なリピータハブ

TODO
OpenWrtを有線リピータハブとして使用する。

HW

Buffalo WHR-G301N

参考

この手順書を途中まで進めることでリピータハブとして動作させる。
要点は

設定

/etc/config/network
config 'interface' 'loopback'
	option 'ifname' 'lo'
	option 'proto' 'static'
	option 'ipaddr' '127.0.0.1'
	option 'netmask' '255.0.0.0'

config 'interface' 'wan'
	option 'ifname' 'eth1'
	option 'proto' 'static'
	option 'ipaddr' '192.168.222.111'
	option 'netmask' '255.255.255.0'

config 'switch'
	option 'name' 'eth0'
	option 'reset' '1'
	option 'enable_vlan' '1'
	option 'enable_learning' '0'

/etc/config/firewall
以下を追記

#Allow SSH
config rule
	option src wan
	option proto tcp
	option dest_port ssh
	option target ACCEPT
/etc/init.d/network

以下を追加

boot() {の最後に
	/sbin/swconfig dev eth0 set enable_learning 0 # add
start() {の最後に
	/sbin/swconfig dev eth0 set enable_learning 0 # add
各種サービスの停止

LAN側のDHCPサーバの停止

/etc/init.d/dnsmasq stop
/etc/init.d/dnsmasq disable

Raspberry Pi Zero WでBluetooth

メモ

import evdev
from evdev import InputDevice, categorize, ecodes

devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
for device in devices:
    print(device.path, device.name, device.phys)

dev = evdev.InputDevice('/dev/input/event0')
print(dev)
dev.capabilities()
dev.capabilities(verbose=True)

for event in dev.read_loop():
    if event.type == ecodes.EV_KEY:
        print(categorize(event))
pi@raspberrypi:~/bluetooth_shutter $ python evdev_shutter.py
('/dev/input/event0', 'AB Shutter3       ', 'B8:27:EB:xx:xx:xx')
device /dev/input/event0, name "AB Shutter3       ", phys "B8:27:EB:xx:xx:xx"
key event at 1533192623.166096, 28 (KEY_ENTER), down
key event at 1533192623.203584, 115 (KEY_VOLUMEUP), down
key event at 1533192623.278570, 115 (KEY_VOLUMEUP), up
key event at 1533192623.353599, 28 (KEY_ENTER), up
key event at 1533192628.003608, 115 (KEY_VOLUMEUP), down
key event at 1533192628.256591, 115 (KEY_VOLUMEUP), hold

Raspberry Pi Zero WのSDイメージのバックアップ

Raspberry Piの本体を使用せずにPCでSDカードのイメージを

  • バックアップ
  • リストア

する場合のメモ。

  1. GParted Liveを使用してパーティションを(少し)縮小しておく
  2. Win32 Disk Imager を使用してSDカードから"Read"でイメージファイルを保存する
  3. Win32 Disk Imager を使用して(別の)SDカードに"Write"でイメージファイルを書き込む

Raspberry Pi Zero Wの設定

Raspberry Pi Zero Wを購入して初期設定したのでメモ。

実施内容

  1. イメージのSDカードへの書き込み
    • https://www.raspberrypi.org/ から RASPBIAN STRETCH WITH DESKTOP をダウンロード
    • Win32DiskImagerを使用してSDカードへ書き込み
  2. 初期設定
  3. WiFiで接続(クライアントとして動作)
  4. APモードに切り替える(アクセスポイントとして動作)
/etc/dnsmasq.conf
/etc/hostapd/hostapd.conf
/etc/network/interfaces
/etc/default/hostapd
/etc/dhcpcd.conf
    • WiFiモード(クライアント)とAPモード(アクセスポイント)を切り替えるために以下を実施
      • それぞれ、元の設定を.wifiとして、APモードの設定を.apとして残しておく
/etc/dhcpcd.conf.wifi
/etc/dhcpcd.conf.ap
/etc/network/interfaces.wifi
/etc/network/interfaces.ap
      • 切り替える
APモードへ
sudo cp -p /etc/dhcpcd.conf.ap /etc/dhcpcd.conf
sudo cp -p /etc/network/interfaces.ap /etc/network/interfaces
sudo systemctl enable dnsmasq
sudo systemctl enable hostapd
sudo service dnsmasq start
sudo service hostapd start
→ リブート
WiFiモードへ
sudo cp -p /etc/dhcpcd.conf.wifi /etc/dhcpcd.conf
sudo cp -p /etc/network/interfaces.wifi /etc/network/interfaces
sudo systemctl disable dnsmasq
sudo systemctl disable hostapd
→ リブート