Last time, we set up the Clara HD to automatically start USB networking when connected. We will now set it up to automatically stop USB networking when file transfer mode is activated in the main interface.

Much like ac and plug, /usr/local/Kobo/udev/usb is responsible for switching the USB connection to file transfer mode. However, while the kernel modules for USB networking are loaded, this will fail, and this is why USB file transfers do not work until we stop USB networking.

We will therefore modify /usr/local/Kobo/udev/usb (via /opt, to preserve changes across updates) to first stop USB networking.

On the Clara HD, run:

cp /usr/local/Kobo/udev/usb /opt/udev/usb


Now edit /opt/udev/usb and make the following change:

if [ $ACTION == add ]; then sync umount -l /mnt/onboard umount -l /mnt/sd /opt/usbtosd # add this line if [$CPU == mx6sll ] || [ $CPU == mx6ull ]; then PARAMS="idVendor=$VENDOR_ID idProduct=$PRODUCT_ID iManufacturer=Kobo iProduct=eReader-$VERSION iSerialNumber=$SN" /sbin/insmod /drivers/$PLATFORM/usb/gadget/configfs.ko
/sbin/insmod /drivers/$PLATFORM/usb/gadget/libcomposite.ko /sbin/insmod /drivers/$PLATFORM/usb/gadget/usb_f_mass_storage.ko


Edit /opt/afterinit.sh and add the following line to the end:

cp /opt/udev/usb /usr/local/Kobo/udev/usb


(Assuming that you set up everything in part 4.2)

If we connect the Clara HD to the computer via USB, the USB port will now automatically be switched to networking mode. If we then tap Connect in the Computer detected dialog box, the USB port will be automatically switched to file transfer mode, so we can continue to use the Clara HD as normal.

(Note: I've experienced intermittent issues with the USB networking. I haven't identified the cause, but stability seems to be improved by dismissing the Computer detected dialog box.)

## What next

Part 5: Setting up SSH