Skip to content

Commit

Permalink
PiNav v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alatnet committed Dec 24, 2018
1 parent 5b813de commit 02ec088
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 35 deletions.
95 changes: 95 additions & 0 deletions bin/enableNet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

#Parts of code used are from https://gist.github.com/Gadgetoid/c52ee2e04f1cd1c0854c3e77360011e2
#Props to Gadgetoid for getting rndis working on windows with multiple composited usb devices.

if [ ! -d /sys/kernel/config/usb_gadget ]; then
modprobe libcomposite
fi

if [ -d /sys/kernel/config/usb_gadget/g1 ]; then
exit 0
fi

ID_VENDOR="0x1d6b"
ID_PRODUCT="0x0104"

SERIAL="$(grep Serial /proc/cpuinfo | sed 's/Serial\s*: 0000\(\w*\)/\1/')"
MAC="$(echo ${SERIAL} | sed 's/\(\w\w\)/:\1/g' | cut -b 2-)"
MAC_HOST="12$(echo ${MAC} | cut -b 3-)"
MAC_DEV="02$(echo ${MAC} | cut -b 3-)"

cd /sys/kernel/config/usb_gadget/

mkdir g1
cd g1

echo "0x0200" > bcdUSB
echo "0x02" > bDeviceClass
echo "0x00" > bDeviceSubClass
echo "0x0001" > bcdDevice
echo $ID_VENDOR > idVendor
echo $ID_PRODUCT > idProduct

# Windows extensions to force config

echo "1" > os_desc/use
echo "0xcd" > os_desc/b_vendor_code
echo "MSFT100" > os_desc/qw_sign

mkdir strings/0x409
echo "$SERIAL" > strings/0x409/serialnumber
echo "Pimoroni Ltd." > strings/0x409/manufacturer
echo "PiNav Network" > strings/0x409/product

# Config #1 for OSX / Linux

mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "CDC RNDIS" > configs/c.1/strings/0x409/configuration

mkdir functions/rndis.usb0 # Flippin' Windows

#network
echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id

echo $MAC_HOST > functions/rndis.usb0/host_addr
echo $MAC_DEV > functions/rndis.usb0/dev_addr

# Set up the rndis device only first

ln -s functions/rndis.usb0 configs/c.1 #network

# Tell Windows to use config #2

ln -s configs/c.1 os_desc

# Show Windows the RNDIS device with
# bDeviceClass 0x02
# bDeviceSubClass 0x02

ls /sys/class/udc > UDC

# Give it time to install

sleep 5

# Yank it back

echo "" > UDC

# Reset bDeviceClass to 0x00
# This is essential to make it work in Windows 10
# Basically forces it to use device information
# in the descriptors versus assuming a particular class.

echo "0x00" > bDeviceClass

# Re-attach the gadget

ls /sys/class/udc > UDC

# BOOM!

ifconfig usb0 up 10.0.99.1
Binary file added bin/navpair
Binary file not shown.
Binary file added bin/pinav_bridge_daemon
Binary file not shown.
Binary file added bin/pinav_usb
Binary file not shown.
Binary file added bin/sixpair
Binary file not shown.
38 changes: 26 additions & 12 deletions install_pinav.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,32 @@
#enable console on serial
#systemctl enable getty@ttyGS0.service

#copy and enable the pinav usb gadget service
cp /boot/pinav/pinav_usb /usr/bin/pinav_usb
chmod +x /usr/bin/pinav_usb
cp /boot/pinav/pinav_usb.service /etc/systemd/system/pinav_usb.service
systemctl enable pinav_usb
#copy libusbgx libraries
cp libusbgx/libusbgx.a /usr/local/lib
cp libusbgx/libusbgx.la /usr/local/lib
cp libusbgx/libusbgx.lai /usr/local/lib
cp libusbgx/libusbgx.so /usr/local/lib
cp libusbgx/libusbgx.so.2 /usr/local/lib
cp libusbgx/libusbgx.so.2.0.0 /usr/local/lib
ldconfig

#copy executables
cp bin/navpair /usr/bin
cp bin/sixpair /usr/bin
cp bin/pinav_usb /usr/bin
cp bin/pinav_bridge_daemon /usr/bin

#copy the bridge daemon
cp /boot/pinav/99-pinav_bridge_daemon.rules /etc/udev/rules.d
cp /boot/pinav/pinav_bridge_daemon@.service /etc/systemd/system
cp /boot/pinav/pinav_bridge_daemon /usr/bin
#make the executables... well... executable
chmod +x /usr/bin/navpair
chmod +x /usr/bin/sixpair
chmod +x /usr/bin/pinav_usb
chmod +x /usr/bin/pinav_bridge_daemon

#copy the navpair program
cp /boot/pinav/navpair /usr/bin
chmod +x /usr/bin/navpair
#copy misc files
cp misc/pinav.ini /boot
cp misc/pinav_usb.service /etc/systemd/system
cp misc/pinav_bridge_daemon@.service /etc/systemd/system
cp misc/99-pinav_bridge_daemon.rules /etc/udev/rules.d

#enable pinav service
systemctl enable pinav_usb
Binary file added libusbgx/libusbgx.a
Binary file not shown.
41 changes: 41 additions & 0 deletions libusbgx/libusbgx.la
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# libusbgx.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-2
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libusbgx.so.2'

# Names of this library.
library_names='libusbgx.so.2.0.0 libusbgx.so.2 libusbgx.so'

# The name of the static archive.
old_library='libusbgx.a'

# Linker flags that cannot go in dependency_libs.
inherited_linker_flags=''

# Libraries that this one depends upon.
dependency_libs=' -lconfig'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libusbgx.
current=2
age=0
revision=0

# Is this an already installed library?
installed=no

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
41 changes: 41 additions & 0 deletions libusbgx/libusbgx.lai
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# libusbgx.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-2
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libusbgx.so.2'

# Names of this library.
library_names='libusbgx.so.2.0.0 libusbgx.so.2 libusbgx.so'

# The name of the static archive.
old_library='libusbgx.a'

# Linker flags that cannot go in dependency_libs.
inherited_linker_flags=''

# Libraries that this one depends upon.
dependency_libs=' -lconfig'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libusbgx.
current=2
age=0
revision=0

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
Binary file added libusbgx/libusbgx.so
Binary file not shown.
Binary file added libusbgx/libusbgx.so.2
Binary file not shown.
Binary file added libusbgx/libusbgx.so.2.0.0
Binary file not shown.
1 change: 1 addition & 0 deletions misc/99-pinav_bridge_daemon.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KERNEL=="js[0-9]*", SUBSYSTEM=="input", ACTION=="add", PROGRAM="/bin/systemd-escape -p --template=pinav_bridge_daemon@.service $env{DEVNAME}", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%c"
8 changes: 8 additions & 0 deletions misc/pinav.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pinav]
numControllers=2

[pinav.net]
enabled=false

[pinav.serial]
enabled=false
12 changes: 12 additions & 0 deletions misc/pinav_bridge_daemon@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=PiNav Bridge Daemon on %I
BindTo=%i.device
After=%i.device

[Service]
Type=forking
User=root
ExecStart=/usr/bin/pinav_bridge_daemon %I

[Install]
WantedBy=%i.device
12 changes: 12 additions & 0 deletions misc/pinav_usb.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=PiNav USB Gadget

[Service]
Type=simple
User=root
WorkingDirectory=/usr/bin
ExecStart=/usr/bin/pinav_usb
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
56 changes: 43 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,55 @@ Follow the same instructions as you would flash a normal Raspbian image.

### Script
Current Distro as of time of writing: [Stretch](https://www.raspberrypi.org/downloads/raspbian/)
You are going to need a UART adapter to connect to the Pi Zero W.
Pinout for uart connection is as followed when the HDMI and USB connections are pointed down starting from the top left:
- Pin 1: 5V
- Pin 2: NC
- Pin 3: GND
- Pin 4: TX
- Pin 5: RX

Note: The baud rate is 115200.

#
1. Flash official Raspbian Light image (you dont need a gui unless you are doing extra stuff.)
2. While microsd card is still on the computer, open up the boot partition and extract the zip file to the root of it or create a pinav folder and download the github files.
3. Remove the microsd card from the computer and insert it into the Raspberry Pi Zero W. (Note, have your pi connected to a monitor with a keyboard, we will not be connecting to the computer at this time)
4. Power on the Raspberry Pi Zero W and wait until you get a prompt.
* Note, you may need to set your keyboard locale.
4. Edit the config.txt file and add \"enable_uart=1\" and \"dtoverlay=dwc2\" to the end of the file (use something other than notepad as it doesnt handle unix formated new lines).
5. Remove the microsd card from the computer and insert it into the Raspberry Pi Zero W.
6. Connect a UART adapter to the Pi Zero W.
4. Power on the Raspberry Pi Zero W via USB connection to your computer and wait until you get a prompt via the UART adapter.
5. IMPORTANT: Set your password. I cannot stress this enough so that your Pi doesnt become a vector of attack on your computer.
6. Type in the following:
> echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
echo "dwc2" | sudo tee -a /etc/modules
> echo "dwc2" | sudo tee -a /etc/modules
echo "libcomposite" | sudo tee -a /etc/modules

7. Afterwards, type in the following:
7. Reboot the Pi Zero W.
8. Go into the bin folder within the pinav folder on the boot partition.
9. Type in the following:
> sudo chmod +x ./enableNet.sh
sudo ./enableNet.sh

10. Share your internet connection with the Pi Zero W via the new RNDIS connection.
11. Type in the following when you verified that the Pi Zero W has a network connection:
> sudo apt-get install libconfig9
12. Afterwards, type in the following:
> sudo chmod +x ./install_pinav.sh
sudo ./install_pinav.sh

*if this does not work, you can open up the install_pinav.sh file with nano or cat and execute anything that doesnt have a # symbol manually.*
8. Reboot your device by unplugging and replugging the Pi.
*if you want ssh over the serial connection, type this:*
*If this does not work, you can open up the install_pinav.sh file with nano or cat and execute anything that doesnt have a # symbol manually.*

*If you want ssh over the usb serial connection, type this:*
> sudo systemctl enable getty@ttyGS0.service
*Note that the connection on a computer is via a com port and the baud rate is 115200.*
*Note that the connection on a computer is via a com port and the baud rate is 115200.*

13. Reboot the Pi Zero W.
14. If you wish, you can disable uart by removing the \"enable_uart=1\" from the config.txt file on the boot partition.
You wouldnt really need it anymore as PiNav has the ability to enable a serial connection via USB.

9. To pair a PS Nav Controller:
### Connecting a PS Nav Controller
1. To pair a PS Nav Controller:
* Connect a nav controller to the Pi via usb.
> sudo navpair
Expand All @@ -70,5 +96,9 @@ sudo ./install_pinav.sh
[bluetooth]# trust \<psnav mac\>
[bluetooth]# quit

10. Disconnect the Raspberry Pi Zero W from the monitor and keyboard and connect it to a computer via usb cable.
11. Once it has installed all drivers, press the PS button on the PS Nav controller, you can verify that it is working via the game controller settings.
2. Disconnect the Raspberry Pi Zero W from the monitor and keyboard and connect it to a computer via usb cable.
3. Once it has installed all drivers, press the PS button on the PS Nav controller, you can verify that it is working via the game controller settings.

# Configuration
PiNav allows for easy configuration via an ini file on the root of the boot partition.
The file's name is \"pinav.ini\".
14 changes: 4 additions & 10 deletions uninstall_pinav.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
#disable console on serial
#systemctl disable getty@ttyGS0.service

#disable and remove the pinav usb gadget service
#disable the pinav service
systemctl disable pinav_usb
rm /etc/systemd/system/pinav_usb.service
rm /usr/bin/pinav_usb

#remove the bridge daemon
rm /boot/pinav/99-pinav_bridge_daemon.rules
rm /boot/pinav/pinav_bridge_daemon@.service
rm /usr/bin/pinav_bridge_daemon

#remove the navpair program
rm /usr/bin/navpair
#remove the files
rm /usr/bin/navpair /usr/bin/sixpair /usr/bin/pinav_usb /usr/bin/pinav_bridge_daemon /etc/systemd/system/pinav_usb.service /etc/systemd/system/pinav_bridge_daemon@.service /etc/udev/rules.d/99-pinav_bridge_daemon.rules /usr/local/lib/libusbgx.a /usr/local/lib/libusbgx.la /usr/local/lib/libusbgx.lai /usr/local/lib/libusbgx.so /usr/local/lib/libusbgx.so.2 /usr/local/lib/libusbgx.so.2.0.0
ldconfig

0 comments on commit 02ec088

Please sign in to comment.