Split RNDIS gadget into individual script

This commit is contained in:
Marc Riera 2023-05-16 00:12:57 +02:00
parent a98a1c07d6
commit f03c7849df
5 changed files with 29 additions and 23 deletions

View file

@ -98,6 +98,14 @@ fi
chmod 755 /usr/bin/ddgo-pnp-controller chmod 755 /usr/bin/ddgo-pnp-controller
if ! cp -f "${USB_ROOT}/payload/rndis-gadget.sh" /usr/bin; then
echo "Failed to install rndis-gadget.sh"
error_exit
fi
chmod 755 /usr/bin/rndis-gadget.sh
echo "Installation complete" echo "Installation complete"
# We're done # We're done

View file

@ -2,16 +2,7 @@
start() { start() {
echo 3 > /sys/devices/platform/gpio-keys-polled.0/input/input1/poll echo 3 > /sys/devices/platform/gpio-keys-polled.0/input/input1/poll
ddgo-pnp-controller ddgo-pnp-controller &
echo 0ae4 > "/sys/class/android_usb/android0/idVendor"
echo 0003 > "/sys/class/android_usb/android0/idProduct"
echo -n "TAITO" > "/sys/class/android_usb/android0/iManufacturer"
echo -n "Densha de Go! Plug & Play (RNDIS mode)" > "/sys/class/android_usb/android0/iProduct"
echo "rndis" > "/sys/class/android_usb/android0/functions"
echo 1 > "/sys/class/android_usb/android0/f_rndis/wceis"
echo 1 > "/sys/class/android_usb/android0/enable"
sleep 1
ifconfig rndis0 169.254.215.100 netmask 255.255.0.0
} }
stop() { stop() {

11
dist/payload/rndis-gadget.sh vendored Normal file
View file

@ -0,0 +1,11 @@
#!/bin/sh -e
echo 0ae4 > "/sys/class/android_usb/android0/idVendor"
echo 0003 > "/sys/class/android_usb/android0/idProduct"
echo -n "TAITO" > "/sys/class/android_usb/android0/iManufacturer"
echo -n "Densha de Go! Plug & Play (RNDIS mode)" > "/sys/class/android_usb/android0/iProduct"
echo "rndis" > "/sys/class/android_usb/android0/functions"
echo 1 > "/sys/class/android_usb/android0/f_rndis/wceis"
echo 1 > "/sys/class/android_usb/android0/enable"
sleep 1
ifconfig rndis0 169.254.215.100 netmask 255.255.0.0

View file

@ -98,10 +98,11 @@ pub fn set_model(state: &ControllerState) -> Option<ControllerModel> {
descriptors = (&vok00106::DEVICE_DESCRIPTOR, &vok00106::DESCRIPTORS, &vok00106::STRINGS); descriptors = (&vok00106::DEVICE_DESCRIPTOR, &vok00106::DESCRIPTORS, &vok00106::STRINGS);
} */ } */
else { else {
println!("No controller selected."); println!("ddgo-pnp-controller: No controller selected, starting RNDIS gadget.");
Command::new("rndis-gadget.sh").output().ok();
return None; return None;
} }
println!("Selected controller {}.", model_name); println!("ddgo-pnp-controller: Selected controller {}.", model_name);
init_gadget(&model, descriptors); init_gadget(&model, descriptors);
return Some(model); return Some(model);
} }
@ -139,7 +140,7 @@ pub fn set_state(state: &mut ControllerState, model: &ControllerModel) {
} }
pub fn handle_ctrl_transfer(model: ControllerModel, data: &[u8]) { pub fn handle_ctrl_transfer(model: ControllerModel, data: &[u8]) {
//println!("CTRL REQ: {:?}", data); println!("ddgo-pnp-controller: CTRL REQ: {:?}", data);
if data[1] == 6 && data[3] == 34 { if data[1] == 6 && data[3] == 34 {
// Get HID report descriptor // Get HID report descriptor
let report: Option<&[u8]>; let report: Option<&[u8]>;
@ -164,11 +165,6 @@ pub fn handle_ctrl_transfer(model: ControllerModel, data: &[u8]) {
} }
} }
else if data[1] == 9 { else if data[1] == 9 {
// if let Ok(mut ep0) = File::open(&ENDPOINT0) {
// let mut buffer = [0; 8];
// ep0.read(&mut buffer).ok();
// println!("CTRL DAT: {:?}", buffer);
// }
} }
} }
@ -206,9 +202,9 @@ fn init_gadget(model: &ControllerModel, (device, descriptors, strings): (&Device
}); });
if let Ok(mut ep0) = File::create(&ENDPOINT0) { if let Ok(mut ep0) = File::create(&ENDPOINT0) {
ep0.write_all(descriptors).ok(); ep0.write_all(descriptors).ok();
println!("USB Gadget: Descriptors written to EP0"); println!("ddgo-pnp-controller: Descriptors written to EP0");
ep0.write_all(strings).ok(); ep0.write_all(strings).ok();
println!("USB Gadget: Strings written to EP0"); println!("ddgo-pnp-controller: Strings written to EP0");
} }
// Init Android Gadget for old 3.4 kernel // Init Android Gadget for old 3.4 kernel
@ -222,7 +218,7 @@ fn init_gadget(model: &ControllerModel, (device, descriptors, strings): (&Device
fs::write(gadget.join(Path::new("iManufacturer")), &device.i_manufacturer.to_string()).ok(); fs::write(gadget.join(Path::new("iManufacturer")), &device.i_manufacturer.to_string()).ok();
fs::write(gadget.join(Path::new("iProduct")), &device.i_product.to_string()).ok(); fs::write(gadget.join(Path::new("iProduct")), &device.i_product.to_string()).ok();
fs::write(gadget.join(Path::new("iSerial")), &device.i_serial_number.to_string()).ok(); fs::write(gadget.join(Path::new("iSerial")), &device.i_serial_number.to_string()).ok();
fs::write(gadget.join(Path::new("functions")), "ffs,rndis").ok(); fs::write(gadget.join(Path::new("functions")), "ffs").ok();
fs::write(gadget.join(Path::new("f_ffs/aliases")), "ffs").ok(); fs::write(gadget.join(Path::new("f_ffs/aliases")), "ffs").ok();
fs::write(gadget.join(Path::new("enable")), "1").ok(); fs::write(gadget.join(Path::new("enable")), "1").ok();
} }

View file

@ -11,7 +11,7 @@ fn main() -> Result<()> {
match controller::physical::init() { match controller::physical::init() {
Ok(dev) => { Ok(dev) => {
// Wait 3 seconds and get current state of the controller // Wait 3 seconds and get current state of the controller
println!("Press a button to select the controller model..."); println!("ddgo-pnp-controller: Press a button to select the controller model...");
sleep(Duration::from_secs(3)); sleep(Duration::from_secs(3));
let mut controller_state = Default::default(); let mut controller_state = Default::default();
controller::physical::get_state(&mut controller_state, &dev); controller::physical::get_state(&mut controller_state, &dev);
@ -44,7 +44,7 @@ fn main() -> Result<()> {
} }
return Result::Ok(()); return Result::Ok(());
}, },
Err(_e) => println!("ERROR: Could not read input devices! Exiting."), Err(_e) => println!("ddgo-pnp-controller: ERROR: Could not read input devices! Exiting."),
} }
Ok(()) Ok(())
} }