# USB tethering with VOXL

Source: https://forum.modalai.com/topic/2998/usb-tethering-with-voxl
Category: Flight Core and Legacy VOXL (https://forum.modalai.com/category/9/flight-core-and-legacy-voxl)
Tags: voxl-flight
Posted: 2024-01-09 08:16:37 UTC by skl1g14
Replies: 8 · Views: 2960

## skl1g14 · 2024-01-09 08:16:37 UTC

Hi,

I have been following this thread https://forum.modalai.com/topic/851/rndis-connection?_=1704780402514.

I have a Jetson nano and a Voxl flight deck with the base Linux Yocto Jethro with 3.18 kernel System Image but my jetson nano does not have any Ethernet port and wireless adapter.
I was planning to reverse USB tether so that the network from voxl can extend to the jetson nano.

By default, the jetson nano have a usb0 virtual Ethernet interface and I verify it by connecting my PC (host) and jetson nano (device).  
https://jetbot.org/master/software_setup/wifi_setup.html.

However, there is no interface when i try to connect my voxl (host) to jetson nano (device).
From the guide, https://docs.modalai.com/voxl-as-usb-host , i suspect it is my OTG cable being incompatible.

With that, i am considering setting up rndis for the voxl flight such that i can do jetson nano (host) and voxl (device) instead.
Is there a guide on how to do so? Or will it be less pain to just get different cables and retry.

## Reply by Moderator (ModalAI staff) · 2024-01-11 01:58:00 UTC

@skl1g14 it might be easier to just use a UART between the two?

## Reply by skl1g14 · 2024-01-14 11:40:06 UTC (in reply to Moderator)

Dear @Moderator,

That is true but we are expecting a data rate much higher than what UART is able to provide.

## Reply by Alex Kushleyev (ModalAI staff) · 2024-01-16 13:57:03 UTC (in reply to skl1g14)

@skl1g14 , can you please confirm that you are using VOXL1 or VOXL2?

## Reply by skl1g14 · 2024-01-16 14:12:39 UTC (in reply to Alex Kushleyev)

@Alex-Kushleyev 
voxl1

## Reply by Alex Kushleyev (ModalAI staff) · 2024-01-16 14:34:32 UTC (in reply to skl1g14)

@skl1g14 , thank you for confirming

Yes if you would like to use VOXL1 as host via OTG connector, you need to have a special cable. 

A few other options:

* since VOXL1 has on-board wifi, can you just plug in a wifi dongle into your Jetson Nano (VOXL1 can be a wifi AP or station)
   * this seems like the option requiring least amount of adapters!
* using USB expander board (https://docs.modalai.com/usb-to-ethernet-with-voxl/) you could add USB-to-ethernet adapter to VOXL and plug in another USB-ethernet adapter into Jetson Nano .. and connect it all together using an ethernet cable.. too many adapters though!

I don't think we ever tried to do USB tethering with VOXL. That would also require enabling a usb gadget kernel module : https://linuxlink.timesys.com/docs/wiki/engineering/HOWTO_Use_USB_Gadget_Ethernet

## Reply by skl1g14 · 2024-01-16 14:42:28 UTC (in reply to Alex Kushleyev)

@Alex-Kushleyev 

Hi Alex, thanks for the quick response.
For now we are going option A with a wifi adapter. That works well.

In the meantime I am moving on to other stuff. 
I tried recompiling the kernel with https://gitlab.com/voxl-public/system-image-build/meta-voxl/-/tree/master?ref_type=heads enabling the usb_gadget flag but no luck so far.
Apparently yocto does not have a simple way to just "make menuconfig"

Will keep this post updated if i manage to get it.

## Reply by skl1g14 · 2024-01-24 15:53:39 UTC (in reply to skl1g14)

Here is the hack if anyone needs it.

The latest platform image have the RNDIS host flag set. https://gitlab.com/voxl-public/system-image-build/meta-voxl/-/blob/master/recipes-kernel/linux-quic/files/enable_RNDIS_HOST.cfg?ref_type=heads

1. First step is to get a compatible OTG cable. I got an off-brand one that works. Run dmesg -wH on your jetson carrier board. If there are the usb0/rndis0/l4tbr0 means the connection is solid. 
![8ccd6bd4-54ac-4b90-af91-7c199e23b565-image.png](https://forum.modalai.com/assets/uploads/files/1706110265888-8ccd6bd4-54ac-4b90-af91-7c199e23b565-image.png) 

2. In voxl, save the following script somewhere. /home/root/usb_tethering.sh is a good choice.
```
#!/bin/bash

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Bring up usb0 interface
ifconfig usb0 up

# Assign IP address to usb0
ifconfig usb0 192.168.55.2 netmask 255.255.255.0

# Add route for USB network
route add -net 192.168.55.0 netmask 255.255.255.0 dev usb0

# Set up iptables rules for NAT
iptables -A FORWARD -o wlan0 -i usb0 -s 192.168.55.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
```

3. Make it persistent by creating a systemd service. Save it at /etc/systemd/system/tethering.service
```
[Unit]
Description=USB Tethering Service
After=network.target

[Service]
Type=simple
ExecStart=/home/root/usb_tethering.sh

[Install]
WantedBy=default.target
```

4. Run the following
```
sudo systemctl daemon-reload
sudo systemctl enable tethering.service
```

5. Check with ifconfig on voxl (should have a static addr 192.168.55.2 for usb0 interface)
![7f3df687-cb2b-4e84-b657-15965453d5d0-image.png](https://forum.modalai.com/assets/uploads/files/1706110671520-7f3df687-cb2b-4e84-b657-15965453d5d0-image.png) 

6. Check with ifconfig on jetson carrier board (the l4tbr0 default addr should be 192.168.55.1)
![e36c7c92-a5ac-4813-a6ba-6873d993a456-image.png](https://forum.modalai.com/assets/uploads/files/1706110744599-e36c7c92-a5ac-4813-a6ba-6873d993a456-image.png) 

7. Try pinging each other (optional)

8. In voxl, set to station mode and connect to a access point. For jetson carrier board, check if it is possible to connect to a public web.
```
ping google.com
```
![8d2deb76-5669-4746-878a-84c54e39394e-image.png](https://forum.modalai.com/assets/uploads/files/1706110908383-8d2deb76-5669-4746-878a-84c54e39394e-image.png) 
* In jetson, the dns nameserver for the l4tbr0 interface may need to change to 8.8.8.8. 
Check with 
```
systemd-resolve --status
```
* Alternatively, change globally by modifying the nameserver address to 8.8.8.8 at /etc/resolv.conf

Bandwidth ~ 265 Mbps which should be expected from a usb2.0 controller (max 480 Mbps) and the overhead from the interfaces.
![5090762d-76b9-47f3-9d81-a24e2e3e7af6-image.png](https://forum.modalai.com/assets/uploads/files/1706111433020-5090762d-76b9-47f3-9d81-a24e2e3e7af6-image.png) 
![20a2f942-8713-4007-b7cd-709ece27b3bd-image.png](https://forum.modalai.com/assets/uploads/files/1706111446476-20a2f942-8713-4007-b7cd-709ece27b3bd-image.png)

## Reply by Alex Kushleyev (ModalAI staff) · 2024-01-24 19:34:21 UTC (in reply to skl1g14)

@skl1g14 , very nice!! Thank you for documenting your configuration and results!!
