Networking ‐ USB Direct w CDC (NCM) - themactep/thingino-firmware GitHub Wiki

General Concepts

There's three major areas where it's easy to screw this up:

  1. USB Direct is not enabled in default builds of Thingino.

  2. The cables that come with many cameras are power only. For instance both the WyzeV3 and Atom V2 ship with micro usb to usb A that are power only and don't have the data wires necessary.

  3. Your computer probably does not want to poewr that many cameras through its usb port.

  4. what happens when you make an NCM connection is a ethernet over usb network between just the host computer and the camera. This is probably not what you want.

Solutions:

  1. Compile thingino with two flags set in the compile environment:
  BR2_PACKAGE_USBNET: y
  BR2_PACKAGE_USBNET_USB_DIRECT_NCM: y 
  1. use a usb-cable that has data.

  2. Get a powered USB-hub.

  3. Make a bridge on the host computer, manage the IP addresses and enable forwarding.

Implementation in "Buster" (Debian 10) (/etc/network/)

  1. Load the module for cdc_ncm:

sudo modprobe cdc_ncm

make it permanent with: echo 'cdc_ncm' | sudo tee /etc/modules-load.d/ncm.conf

  1. Setup the bridge network. In /etc/network/interfaces.d

add a conf-file 10-bridge.conf

iface br0 inet static
        address 192.168.9.1
        netmask 255.255.255.0
        bridge_ports usb0 usb1 usb2 usb3 usb4 usb5 usb6

allow-hotplug usb0
allow-hotplug usb1
allow-hotplug usb2
allow-hotplug usb3
allow-hotplug usb4
allow-hotplug usb5
allow-hotplug usb6

auto usb0
iface usb0 inet manual
	address 192.168.9.10
	netmask 255.255.255.0
	up ifconfig usb0 up
	up brctl addif br0 usb0

auto usb1
iface usb1 inet manual
        address 192.168.9.11
        netmask 255.255.255.0
        up ifconfig usb1 up
        up brctl addif br0 usb1

auto usb2
iface usb2 inet manual
        address 192.168.9.12
        netmask 255.255.255.0
	up ifconfig usb2 up
        up brctl addif br0 usb2

auto usb3
iface usb3 inet manual
        address 192.168.9.13
        netmask 255.255.255.0
        up ifconfig usb3 up
        up brctl addif br0 usb3

auto usb4
iface usb4 inet manual
        address 192.168.9.14
        netmask 255.255.255.0
        up ifconfig usb4 up
        up brctl addif br0 usb4


allow-hotplug usb5
iface usb5 inet manual
        address 192.168.9.15
        netmask 255.255.255.0
        up ifconfig usb5 up
        up brctl addif br0 usb5

allow-hotplug usb6
iface usb6 inet manual
        address 192.168.9.16
        netmask 255.255.255.0
        up ifconfig usb6 up
        up brctl addif br0 usb6



This will create a bridge that covers seven cameras

  1. In addition, you need something like dnsmasq to configure and give them ip addresses.

in the dnsmasq.conf, you need to

  1. tell it to listen to the br0 interface:
interface=br0
  1. have it assign IP addreseses. I default to DHCP but have it statically assign within the IP range:
dhcp-range=br0,192.168.9.2,192.168.9.255,255.255.255.0,24h
dhcp-host=br0,02:b3:cc:b3:8c:a6,02:FF:FF:FF:FF:01,192.168.9.101
dhcp-host=br0,02:FF:FF:FF:FF:02,02:14:82:3b:bd:e2,192.168.9.102
dhcp-host=br0,02:FF:FF:FF:FF:03,02:73:55:08:b9:ba,192.168.9.103
dhcp-host=br0,02:FF:FF:FF:FF:04,02:2d:86:29:5a:58,192.168.9.104
dhcp-host=br0,02:FF:FF:FF:FF:05,192.168.9.105
dhcp-host=br0,02:FF:FF:FF:FF:07,192.168.9.107
dhcp-host=br0,02:bb:71:df:c8:b0,192.168.9.108

on a dhcp-host line, you need the interface and then can give it multiple MAC addresses to match up to an IP address.

  1. You also need to tell the device to route IP4 traffic:
sudo sysctl -w net.ipv4.ip_forward=1

and then to make it permanent: add net.ipv4.ip_forward=1 to /etc/sysctl.conf and run sysctl -p

  1. setup the route sudo ip route add 192.168.9.0/24 dev br0 src <ip of your device>

On Trixie

Trixie does not use /etc/network but rather NetworkManager to manage its network so some of the steps are different.

What's the same:

  1. No longer need to load the driver for NCM
  2. Still need to enable IPv4 traffic forwarding (same as above)
  3. Still need to run a dhcp server to give IP addresses (same as above
  4. Still need to setup a bridge network (but done differently)
  5. Still need to setup a route

For three, the following script should do the trick:



# 1. Create bridge
nmcli con add type bridge con-name br0 ifname br0 stp no
nmcli con mod br0 ipv4.method manual ipv4.addresses "192.168.9.1/24"
nmcli con mod br0 ipv4.route1 "192.168.9.0/24 10.0.0.1"

# 2. Add each USB as slave
for i in {0..6}; do
  nmcli con add type ethernet con-name br0-slave-usb$i ifname usb$i master br0
done

# 3. Bring up
nmcli con up br0
for i in {0..6}; do nmcli con up br0-slave-usb$i; done

So the main thing is to setup the bridge and then tell NetworkManager that the USB connections are its slaves.