commit e53ad5dd51208ae6bc97130142af184f7a61833f Author: Pierre VERBAERE Date: Mon Feb 1 22:32:41 2021 +0100 Repo Init with files diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/cmd.sh b/cmd.sh new file mode 100755 index 0000000..14a6854 --- /dev/null +++ b/cmd.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +sudo apt-get update +sudo apt-get upgrade -y +sudo apt-get -y install dnsmasq +sudo apt-get clean +sudo chmod +x /usr/local/sbin/usb-gadget.sh +sudo systemctl enable usbgadget.service +sudo echo dtoverlay=dwc2 >> /boot/config.txt +sudo sed -i 's/$/ modules-load=dwc2/' /boot/cmdline.txt +sudo echo libcomposite >> /etc/modules +sudo systemctl enable getty@ttyGS0.service + diff --git a/etc/dhcpcd.conf b/etc/dhcpcd.conf new file mode 100644 index 0000000..3225c9b --- /dev/null +++ b/etc/dhcpcd.conf @@ -0,0 +1,61 @@ +# A sample configuration for dhcpcd. +# See dhcpcd.conf(5) for details. + +# Allow users of this group to interact with dhcpcd via the control socket. +#controlgroup wheel + +# Inform the DHCP server of our hostname for DDNS. +hostname + +# Use the hardware address of the interface for the Client ID. +clientid +# or +# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361. +# Some non-RFC compliant DHCP servers do not reply with this set. +# In this case, comment out duid and enable clientid above. +#duid + +# Persist interface configuration when dhcpcd exits. +persistent + +# Rapid commit support. +# Safe to enable by default because it requires the equivalent option set +# on the server to actually work. +option rapid_commit + +# A list of options to request from the DHCP server. +option domain_name_servers, domain_name, domain_search, host_name +option classless_static_routes +# Respect the network MTU. This is applied to DHCP routes. +option interface_mtu + +# Most distributions have NTP support. +#option ntp_servers + +# A ServerID is required by RFC2131. +require dhcp_server_identifier + +# Generate SLAAC address using the Hardware Address of the interface +#slaac hwaddr +# OR generate Stable Private IPv6 Addresses based from the DUID +slaac private + +# Example static IP configuration: +interface usb0 +static ip_address=10.55.0.1/29 +nohook wpa_supplicant # don't call the wpa_supplicant hook +denyinterfaces usb0 # don't send DHCP requests +#static ip6_address=fd51:42f8:caae:d92e::ff/64 +#static routers=192.168.0.1 +#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1 + +# It is possible to fall back to a static IP if DHCP fails: +# define static profile +#profile static_eth0 +#static ip_address=192.168.1.23/24 +#static routers=192.168.1.1 +#static domain_name_servers=192.168.1.1 + +# fallback to static profile on eth0 +#interface eth0 +#fallback static_eth0 diff --git a/etc/dnsmasq.conf b/etc/dnsmasq.conf new file mode 100644 index 0000000..acffe56 --- /dev/null +++ b/etc/dnsmasq.conf @@ -0,0 +1,7 @@ +dhcp-authoritative +dhcp-rapid-commit +no-ping +interface=usb0 +dhcp-range=10.55.0.2,10.55.0.6,255.255.255.248,1h +dhcp-option=3,10.55.0.1 +leasefile-ro diff --git a/etc/network/interfaces.d/wlan0 b/etc/network/interfaces.d/wlan0 new file mode 100644 index 0000000..e014f61 --- /dev/null +++ b/etc/network/interfaces.d/wlan0 @@ -0,0 +1,4 @@ +auto wlan0 +allow-hotplug wlan0 +iface wlan0 inet dhcp +wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf diff --git a/etc/sysctl.conf b/etc/sysctl.conf new file mode 100644 index 0000000..b41f07b --- /dev/null +++ b/etc/sysctl.conf @@ -0,0 +1,68 @@ +# +# /etc/sysctl.conf - Configuration file for setting system variables +# See /etc/sysctl.d/ for additional system variables. +# See sysctl.conf (5) for information. +# + +#kernel.domainname = example.com + +# Uncomment the following to stop low-level messages on console +#kernel.printk = 3 4 1 3 + +##############################################################3 +# Functions previously found in netbase +# + +# Uncomment the next two lines to enable Spoof protection (reverse-path filter) +# Turn on Source Address Verification in all interfaces to +# prevent some spoofing attacks +#net.ipv4.conf.default.rp_filter=1 +#net.ipv4.conf.all.rp_filter=1 + +# Uncomment the next line to enable TCP/IP SYN cookies +# See http://lwn.net/Articles/277146/ +# Note: This may impact IPv6 TCP sessions too +#net.ipv4.tcp_syncookies=1 + +# Uncomment the next line to enable packet forwarding for IPv4 +net.ipv4.ip_forward=1 + +# Uncomment the next line to enable packet forwarding for IPv6 +# Enabling this option disables Stateless Address Autoconfiguration +# based on Router Advertisements for this host +#net.ipv6.conf.all.forwarding=1 + + +################################################################### +# Additional settings - these settings can improve the network +# security of the host and prevent against some network attacks +# including spoofing attacks and man in the middle attacks through +# redirection. Some network environments, however, require that these +# settings are disabled so review and enable them as needed. +# +# Do not accept ICMP redirects (prevent MITM attacks) +#net.ipv4.conf.all.accept_redirects = 0 +#net.ipv6.conf.all.accept_redirects = 0 +# _or_ +# Accept ICMP redirects only for gateways listed in our default +# gateway list (enabled by default) +# net.ipv4.conf.all.secure_redirects = 1 +# +# Do not send ICMP redirects (we are not a router) +#net.ipv4.conf.all.send_redirects = 0 +# +# Do not accept IP source route packets (we are not a router) +#net.ipv4.conf.all.accept_source_route = 0 +#net.ipv6.conf.all.accept_source_route = 0 +# +# Log Martian Packets +#net.ipv4.conf.all.log_martians = 1 +# + +################################################################### +# Magic system request Key +# 0=disable, 1=enable all, >1 bitmask of sysrq functions +# See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html +# for what other values do +#kernel.sysrq=438 + diff --git a/etc/wpa_supplicant/wpa_supplicant.conf b/etc/wpa_supplicant/wpa_supplicant.conf new file mode 100644 index 0000000..4a646ef --- /dev/null +++ b/etc/wpa_supplicant/wpa_supplicant.conf @@ -0,0 +1,9 @@ +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 + +country=FR +network={ + ssid="" + psk="" + key_mgmt=WPA-PSK +} diff --git a/lib/systemd/system/usbgadget.service b/lib/systemd/system/usbgadget.service new file mode 100644 index 0000000..b3ac482 --- /dev/null +++ b/lib/systemd/system/usbgadget.service @@ -0,0 +1,13 @@ +[Unit] +Description=My USB gadget +After=systemd-modules-load.service network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/sbin/usb-gadget.sh + +[Install] +WantedBy=sysinit.target + diff --git a/usr/local/sbin/usb-gadget.sh b/usr/local/sbin/usb-gadget.sh new file mode 100755 index 0000000..52a3f14 --- /dev/null +++ b/usr/local/sbin/usb-gadget.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +GADGET=/sys/kernel/config/usb_gadget/display-pi + +SERIAL=`cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2` +if [ -n "$SERIAL" ]; then + MAC="fa:${SERIAL:6:2}:${SERIAL:8:2}:${SERIAL:10:2}:${SERIAL:12:2}:${SERIAL:14:2}" +else + MAC="fa:31:43:14:31:43" +fi + +mount -t configfs none /sys/kernel/config +mkdir -p $GADGET +cd $GADGET + +echo 0x1d6b > idVendor # Linux Foundation +echo 0x0104 > idProduct # Multifunction Composite Gadget +echo 0x0100 > bcdDevice # v1.0.0 +echo 0x0200 > bcdUSB # USB2 + +echo 0xEF > bDeviceClass +echo 0x02 > bDeviceSubClass +echo 0x01 > bDeviceProtocol + +mkdir strings/0x409 +echo $SERIAL > strings/0x409/serialnumber +echo "Raspberry Pi" > strings/0x409/manufacturer +echo "Display-Pi USB Device" > strings/0x409/product + +mkdir -p functions/acm.usb0 # serial +mkdir -p functions/rndis.usb0 # network +#mkdir -p functions/ecm.usb0 +#echo $MAC > functions/ecm.usb0/dev_addr + +mkdir -p configs/c.1 +echo 250 > configs/c.1/MaxPower +ln -s functions/rndis.usb0 configs/c.1/ +ln -s functions/acm.usb0 configs/c.1/ +#ln -s functions/ecm.usb0 configs/c.1/ + +# OS descriptors +# echo 1 > os_desc/use +# echo 0xcd > os_desc/b_vendor_code +# echo MSFT100 > os_desc/qw_sign +# +# echo RNDIS > functions/rndis.usb0/os_desc/interface.rndis/compatible_id +# echo 5162001 > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id +# +# ln -s configs/c.1 os_desc + +# Assuming there is only ever going to be one UDC +udevadm settle -t 5 || : +ls /sys/class/udc > UDC + +# systemctl restart networking +# systemctl restart dnsmasq +# systemctl restart sshd +