pelya / android-keyboard-gadget

Convert your Android device into USB keyboard/mouse, control your PC from your Android device remotely, including BIOS/bootloader.
Apache License 2.0
1.22k stars 308 forks source link

Trying to compile a kernel for CM 11 and Samsung Note 3 #4

Closed NeverUsedID closed 6 years ago

NeverUsedID commented 10 years ago

Hello,

thank you very much for great idea and code. My idea of this usb mode is to use it with keypass2Android. It would be an outstanding feature to simply plugging the phone into usb and select (or copy to clipboard) the username/password from keypass or any other passwordstore and send it to your pc.

But for now iam having problems of compiling the kernel. The Patch had issues with android.c, so i tried to fix it manualy. There are some light differences in the android.c.

Now when i try to compile i get the following error: ../../../../../../kernel/samsung/hlte/drivers/usb/gadget/android.c: In function 'functions_store': ../../../../../../kernel/samsung/hlte/drivers/usb/gadget/android.c:2758:16: warning: passing argument 2 of 'android_enable_function' from incompatible pointer type [enabled by default] error, forbidden warning: android.c:2758 make[5]: * [drivers/usb/gadget/android.o] Error 1 make[4]: * [drivers/usb/gadget] Error 2 make[3]: *\ [drivers/usb] Error 2

the section is and line 2758 is: " android_enable_function(dev, "hid");":

functions_store(struct device pdev, struct device_attribute attr, const char buff, size_t size) { struct android_dev dev = dev_get_drvdata(pdev); struct list_head curr_conf = &dev->configs; struct android_configuration conf; char conf_str; struct android_usb_function_holder f_holder; char name; char buf[256], b; int err; int hid_enabled;

    mutex_lock(&dev->mutex);

    if (dev->enabled) {
            mutex_unlock(&dev->mutex);
            return -EBUSY;
    }

    /* Clear previous enabled list */
    list_for_each_entry(conf, &dev->configs, list_item) {
            while (conf->enabled_functions.next !=
                            &conf->enabled_functions) {
                    f_holder = list_entry(conf->enabled_functions.next,
                                    typeof(*f_holder),
                                    enabled_list);
                    f_holder->f->android_dev = NULL;
                    list_del(&f_holder->enabled_list);
                    kfree(f_holder);
            }
            INIT_LIST_HEAD(&conf->enabled_functions);
    }

    strlcpy(buf, buff, sizeof(buf));
    b = strim(buf);

    while (b) {
            conf_str = strsep(&b, ":");
            if (conf_str) {
                    /* If the next not equal to the head, take it */
                    if (curr_conf->next != &dev->configs)
                            conf = list_entry(curr_conf->next,
                                              struct android_configuration,
                                              list_item);
                    else
                            conf = alloc_android_config(dev);

                    curr_conf = curr_conf->next;
            }
           while (conf_str) {
                    name = strsep(&conf_str, ",");
                    if (name) {
   #ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
                            /* Enable ncm function */
                            if (is_ncm_ready(name)) {
                                    printk(KERN_DEBUG "usb: %s ncm on\n",
                                                    __func__);
                                    err = android_enable_function(dev, conf,
                                                    "ncm");
                                    continue;
                            }
      #endif
                            err = android_enable_function(dev, conf, name);
                            if (err)
                                    pr_err("android_usb: Cannot enable %s", name);
                             if (!strcmp(name, "hid"))
                                     hid_enabled = 1;
                    }
            }
   /* HID driver always enabled, it's the whole point of this kernel patch */
   if (hid_enabled)
           android_enable_function(dev, "hid");

    }

    /* Free uneeded configurations if exists */
    while (curr_conf->next != &dev->configs) {
            conf = list_entry(curr_conf->next,
                              struct android_configuration, list_item);
            free_android_config(dev, conf);
    }

    mutex_unlock(&dev->mutex);

    return size;

}

BTW. Iam very new dot kernelcompiling :=)

best regards...

pelya commented 10 years ago

You may try to apply this patch, it was adopted for newer kernel:

https://github.com/neobuddy89/hammerhead_kernel_caf/commit/5199daa72289c311c6d69f1b1c344e41ae8a7caa On Jul 3, 2014 12:29 AM, "NeverUsedID" notifications@github.com wrote:

Hello,

iam having problems of comiling the kernel. The Patch had issues with android.c, so i tried to fix it manualy. there are some light differences in the android.c.

Now when i try to compile i get the following error: ../../../../../../kernel/samsung/hlte/drivers/usb/gadget/android.c: In function 'functions_store': ../../../../../../kernel/samsung/hlte/drivers/usb/gadget/android.c:2758:16: warning: passing argument 2 of 'android_enable_function' from incompatible pointer type [enabled by default] error, forbidden warning: android.c:2758 make[5]: * [drivers/usb/gadget/android.o] Error 1 make[4]: * [drivers/usb/gadget] Error 2 make[3]: *\ [drivers/usb] Error 2

the section is and line 2758 is: " android_enable_function(dev, "hid");":

functions_store(struct device pdev, struct device_attribute attr, const char buff, size_t size) { struct android_dev dev = dev_get_drvdata(pdev); struct list_head curr_conf = &dev->configs; struct android_configuration conf; char conf_str; struct android_usb_function_holder f_holder; char name; char buf[256], b; int err; int hid_enabled;

mutex_lock(&dev->mutex);

if (dev->enabled) {
        mutex_unlock(&dev->mutex);
        return -EBUSY;
}

/* Clear previous enabled list */
list_for_each_entry(conf, &dev->configs, list_item) {
        while (conf->enabled_functions.next !=
                        &conf->enabled_functions) {
                f_holder = list_entry(conf->enabled_functions.next,
                                typeof(*f_holder),
                                enabled_list);
                f_holder->f->android_dev = NULL;
                list_del(&f_holder->enabled_list);
                kfree(f_holder);
        }
        INIT_LIST_HEAD(&conf->enabled_functions);
}

strlcpy(buf, buff, sizeof(buf));
b = strim(buf);

while (b) {
        conf_str = strsep(&b, ":");
        if (conf_str) {
                /* If the next not equal to the head, take it */
                if (curr_conf->next != &dev->configs)
                        conf = list_entry(curr_conf->next,
                                          struct android_configuration,
                                          list_item);
                else
                        conf = alloc_android_config(dev);

                curr_conf = curr_conf->next;
        }

        while (conf_str) {
                name = strsep(&conf_str, ",");
                if (name) {

ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE

/* Enable ncm function

_/ if (is_ncm_ready(name)) { printk(KERN_DEBUG "usb: %s ncm on\n",func); err = android_enable_function(dev, conf, "ncm"); continue; } #endif err = android_enable_function(dev, conf, name); if (err) pr_err("android_usb: Cannot enable %s", name); if (!strcmp(name, "hid")) hidenabled = 1; } } / HID driver always enabled, it's the whole point of this kernel patch */ if (hid_enabled) android_enable_function(dev, "hid");

}

/* Free uneeded configurations if exists */
while (curr_conf->next != &dev->configs) {
        conf = list_entry(curr_conf->next,
                          struct android_configuration, list_item);
        free_android_config(dev, conf);
}

mutex_unlock(&dev->mutex);

return size;

}

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/4.

NeverUsedID commented 10 years ago

ahh thank you very much for the fast answer and the Link i will give the new one a try. Just found out which line of code the problem was:

its: android_enable_function(dev, "hid"); It should be android_enable_function(dev, conf, "hid");

NeverUsedID commented 10 years ago

Okay, ive got it to work. Thank you very much for this great app.

Btw. is there a way to send clipboard from a bashscript to the connected computer ? Iam just starting with kernelcompiling and programming, so for me making an app which simple send the clipboard when its startet and ends himself is a very big project for me :)

edit: cant type german umlauts and special signs (f.e. äö #). is there a way to enhance this ?

pelya commented 10 years ago

I've added description of the binary protocol to my github page few days ago: https://github.com/pelya/android-keyboard-gadget/

You can use this commandline tool to send key events: https://github.com/pelya/android-keyboard-gadget/tree/master/hid-gadget-test

I don't know how to access Android clipboard from command line.

My app already has a clipboard button, if that will help you, you can just take it's sources and butcher all other functionality from it. On Jul 3, 2014 11:51 PM, "NeverUsedID" notifications@github.com wrote:

Okay, ive got it to work. Thank you very much for this great app.

Btw. is there a way to send clipboard from a bashscript to the connected computer ? Iam just starting with kernelcompiling and programming, so for me making an app which simple send the clipboard when its startet and ends himself is a very big project for me :)

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/4#issuecomment-47983417 .

the-st0rm commented 9 years ago

@NeverUsedID would you send me the patch files you used please. I also would like to make sure that you are using Samsung Note 3 with cyangonmod installed and you edited in the kernel code in /kernel/samsung/hlte/ right?