blob: ef1159e6f41078e360bda89e44e20d957624faf3 [file] [log] [blame]
#!/bin/bash
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#### CATEGORY=Other
### Setup udev rules for USB CDC ethernet
## usage: fx setup-usb-ethernet
##
## This script is only for Linux systems.
if [[ $(uname) != "Linux" ]]; then
echo >&2 "This script is only intended for Linux systems"
exit 1
fi
echo "Adding the following udev rules:"
cat << EOF | sudo tee /etc/udev/rules.d/70-zircon-ethernet.rules
# Check for Google network devices being added
ACTION=="add", SUBSYSTEM=="net", ATTRS{idVendor}=="18d1", GOTO="zircon_add_net_google"
GOTO="zircon_end"
# Check for Zircon CDC Ethernet devices being added
LABEL="zircon_add_net_google"
# CDC Ethernet-only configuration
ATTRS{idProduct}=="a020", GOTO="zircon_net_name"
# CDC Ethernet & USB Test Function composite configuration
ATTRS{idProduct}=="a023", GOTO="zircon_net_name"
GOTO="zircon_end"
# Set the interface name based on the MAC
LABEL="zircon_net_name"
IMPORT{builtin}="net_id"
PROGRAM="/bin/sh -c 'echo \$\${ID_NET_NAME_MAC#enx}'", NAME="zx-%c"
LABEL="zircon_end"
EOF
sudo udevadm control --reload
sudo udevadm trigger --action=change