View Single Post
Old 11-28-2019, 06:36 PM   #281
katadelos
rm -rf /
katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.
 
Posts: 219
Karma: 3333683
Join Date: Nov 2019
Location: United Kingdom
Device: K5, KT, KT2, KT3, KT4, KV, PW2, PW3, PW4, PW5
This might be useful for anyone working on OTG stuff - when an OTG cable with a device attached is plugged into a Kindle, the Kindle will switch between gadget and host mode every ~10 seconds. If you have a look at the output from dmesg, it'll look something like this:
Code:
[ 3232.841151] Schedule OTG enumeration triggered recovery
[ 3232.851811] switch to host?
[ 3240.861125]  otg_enum_fn not enumerated, catcha!
[ 3240.871392] fsl_otg_event ID changed to [0] during work
[ 3240.871419] asking for device mode and in host mode, thats okay 
[ 3240.871444] switch to gadget
[ 3246.931240] Unknown wakeup.(OTGSC 0x9282b20)
[ 3247.081258] 
[ 3247.081264] Schedule OTG enumeration triggered recovery
[ 3247.091818] switch to host?
[ 3255.101107]  otg_enum_fn not enumerated, catcha!
[ 3255.111309] fsl_otg_event ID changed to [0] during work
[ 3255.111333] asking for device mode and in host mode, thats okay 
[ 3255.111359] switch to gadget
[ 3261.171072] Unknown wakeup.(OTGSC 0x9282b20)
[ 3261.321176] 
[ 3261.321182] Schedule OTG enumeration triggered recovery
[ 3261.331837] switch to host?
[ 3269.341100]  otg_enum_fn not enumerated, catcha!
[ 3269.351374] fsl_otg_event ID changed to [0] during work
[ 3269.351399] asking for device mode and in host mode, thats okay 
[ 3269.351424] switch to gadget
[ 3275.411069] Unknown wakeup.(OTGSC 0x9280b20)
otg_enum_fn is a function defined within arch/arm/mach-mx6/usb_dr.c, which checks if the audio_enumerated variable is set at line 246. This variable is set by the USB sound card driver sound/usb/card.c and seems to be used by usb_dr.c as a crude way of locking out devices other than the Kindle Audio Adapter; generic USB sound cards can be used in the official adapters place because card.c is part of ALSA, rather than being Amazon specific code.

The mousedev.ko file distributed as part of usbotgmouse and KindleLazy is modified to set the audio_enumerated variable in the same way - if you run strings on the file and grep for the variable name, you'll find a match. It also seems to be the same file in both packages as they're exactly the same size.

It seemed a bit hacky to set the variable in mousedev.c, so I've created this dummy kernel module solely to set/unset the audio_enumerated variable - I think that it makes more sense to do things like this instead of adding extra functionality to mousedev.c. The code is really simple and based on the kernel module Hello World, nothing complicated here.

Code:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

extern int audio_enumerated;

MODULE_AUTHOR("katadelos");
MODULE_DESCRIPTION("Kindle USB OTG dummy module");
MODULE_LICENSE("GPL");

int __init otg_init(void) {
        printk("Inserting dummy kernel module...\n");
        audio_enumerated = 1;
        printk("Audio interface inserted ;)\n");
        return 0;
}
 
void __exit otg_exit(void) {
        printk("Removing dummy kernel module...\n");
        audio_enumerated = 0;
        printk("Audio interface removed...\n");
}
 
module_init(otg_init);
module_exit(otg_exit);
This can be cross-compiled with NiLuJe's toolchain and insmod'ed in the usual way. As an aside, the OTG functionality can be used for some really interesting stuff - if you compile the Linux serial drivers, you can add support for Arduinos, 3D printers and other fun toys. It also opens up the possibility of performing Kindle to Kindle serial jailbreaks, if you were so inclined.
katadelos is offline   Reply With Quote