Skip to content

Commit

Permalink
add kali nethunter
Browse files Browse the repository at this point in the history
Thanks FutureBSD for this tip
  • Loading branch information
HRTKernel authored and javilonas committed May 26, 2015
1 parent 3b977f1 commit 542f714
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 8 deletions.
102 changes: 102 additions & 0 deletions arch/arm/configs/apq8084_sec_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,108 @@ CONFIG_CROSS_COMPILE="/home/lonas/Kernel_Lonas/toolchains/arm-eabi-4.8/bin/arm-e
CONFIG_LOCALVERSION="-$KERNEL_VERSION"
# CONFIG_LOCALVERSION_AUTO is not set

#Kali NetHunter
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_BT_HCIBTUSB=y
CONFIG_BT_HCIUART=y
# CONFIG_BT_HCIUART_H4 is not set
# CONFIG_BT_HCIUART_BCSP is not set
# CONFIG_BT_HCIUART_ATH3K is not set
# CONFIG_BT_HCIUART_LL is not set
# CONFIG_BT_HCIUART_3WIRE is not set
CONFIG_BT_HCIBCM203X=m
CONFIG_BT_HCIBPA10X=m
CONFIG_BT_HCIBFUSB=m
# CONFIG_BT_ATH3K is not set
CONFIG_LIB80211=y
# CONFIG_LIB80211_DEBUG is not set
CONFIG_MAC80211=y
CONFIG_MAC80211_HAS_RC=y
# CONFIG_MAC80211_RC_PID is not set
CONFIG_MAC80211_RC_MINSTREL=y
CONFIG_MAC80211_RC_MINSTREL_HT=y
CONFIG_MAC80211_RC_DEFAULT_MINSTREL=y
CONFIG_MAC80211_RC_DEFAULT="minstrel_ht"
# CONFIG_MAC80211_MESH is not set
CONFIG_MAC80211_LEDS=y
# CONFIG_MAC80211_DEBUGFS is not set
# CONFIG_MAC80211_MESSAGE_TRACING is not set
# CONFIG_MAC80211_DEBUG_MENU is not set
CONFIG_EEPROM_93CX6=y
CONFIG_DM_BUFIO=y
CONFIG_USB_RTL8150=y
CONFIG_USB_NET_RNDIS_HOST=y
# CONFIG_LIBERTAS_THINFIRM is not set
CONFIG_AT76C50X_USB=m
CONFIG_USB_ZD1201=m
CONFIG_USB_NET_RNDIS_WLAN=y
# CONFIG_RTL8180 is not set
CONFIG_RTL8187=y
CONFIG_RTL8187_LEDS=y
# CONFIG_ADM8211 is not set
# CONFIG_MAC80211_HWSIM is not set
# CONFIG_MWL8K is not set
CONFIG_ATH_COMMON=y
CONFIG_ATH_CARDS=y
# CONFIG_ATH_DEBUG is not set
# CONFIG_ATH5K is not set
# CONFIG_ATH5K_PCI is not set
CONFIG_ATH9K_HW=y
CONFIG_ATH9K_COMMON=y
CONFIG_ATH9K_BTCOEX_SUPPORT=y
# CONFIG_ATH9K is not set
CONFIG_ATH9K_HTC=y
# CONFIG_ATH9K_HTC_DEBUGFS is not set
CONFIG_CARL9170=y
CONFIG_CARL9170_LEDS=y
CONFIG_CARL9170_WPC=y
# CONFIG_CARL9170_HWRNG is not set
CONFIG_ATH6KL=y
# CONFIG_ATH6KL_SDIO is not set
CONFIG_ATH6KL_USB=y
# CONFIG_ATH6KL_DEBUG is not set
# CONFIG_ATH6KL_TRACING is not set
# CONFIG_AR5523 is not set
# CONFIG_WIL6210 is not set
# CONFIG_B43 is not set
# CONFIG_B43LEGACY is not set
# CONFIG_IWLWIFI is not set
# CONFIG_IWL4965 is not set
# CONFIG_IWL3945 is not set
# CONFIG_P54_COMMON is not set
CONFIG_RT2X00=y
# CONFIG_RT2400PCI is not set
# CONFIG_RT2500PCI is not set
# CONFIG_RT61PCI is not set
# CONFIG_RT2800PCI is not set
CONFIG_RT2500USB=y
CONFIG_RT73USB=y
CONFIG_RT2800USB=y
CONFIG_RT2800USB_RT33XX=y
CONFIG_RT2800USB_RT35XX=y
CONFIG_RT2800USB_RT53XX=y
CONFIG_RT2800USB_RT55XX=y
CONFIG_RT2800USB_UNKNOWN=y
CONFIG_RT2800_LIB=y
CONFIG_RT2X00_LIB_USB=y
CONFIG_RT2X00_LIB=y
CONFIG_RT2X00_LIB_FIRMWARE=y
CONFIG_RT2X00_LIB_CRYPTO=y
CONFIG_RT2X00_LIB_LEDS=y
# CONFIG_RT2X00_DEBUG is not set
CONFIG_RTLWIFI=y
CONFIG_RTLWIFI_DEBUG=y
# CONFIG_RTL8192CE is not set
# CONFIG_RTL8192SE is not set
# CONFIG_RTL8192DE is not set
# CONFIG_RTL8723AE is not set
# CONFIG_RTL8188EE is not set
CONFIG_RTL8192CU=y
CONFIG_RTL8192C_COMMON=y
# CONFIG_ZD1211RW is not set
# CONFIG_W35UND is not set
CONFIG_CRC_ITU_T=y

# CONFIG_ARM_PATCH_PHYS_VIRT is not set
CONFIG_DEFERRED_INITCALLS=y
CONFIG_SYSVIPC=y
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/gadget/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ g_nokia-y := nokia.o
g_webcam-y := webcam.o
g_ncm-y := ncm.o
g_acm_ms-y := acm_ms.o
g_android-y := android.o
g_android-y := android.o f_hid.o
g_tcm_usb_gadget-y := tcm_usb_gadget.o

obj-$(CONFIG_USB_ZERO) += g_zero.o
Expand Down
41 changes: 41 additions & 0 deletions drivers/usb/gadget/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
#include "f_mtp.c"
#endif
#include "f_accessory.c"
#include "f_hid.h"
#include "f_hid_android_keyboard.c"
#include "f_hid_android_mouse.c"
#include "f_rndis.c"
#include "rndis.c"
#include "f_qc_ecm.c"
Expand Down Expand Up @@ -2768,6 +2771,41 @@ static struct android_usb_function uasp_function = {
.bind_config = uasp_function_bind_config,
};

static int hid_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
{
return ghid_setup(cdev->gadget, 2);
}

static void hid_function_cleanup(struct android_usb_function *f)
{
ghid_cleanup();
}

static int hid_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
{
int ret;
printk(KERN_INFO "hid keyboard\n");
ret = hidg_bind_config(c, &ghid_device_android_keyboard, 0);
if (ret) {
pr_info("%s: hid_function_bind_config keyboard failed: %d\n", __func__, ret);
return ret;
}
printk(KERN_INFO "hid mouse\n");
ret = hidg_bind_config(c, &ghid_device_android_mouse, 1);
if (ret) {
pr_info("%s: hid_function_bind_config mouse failed: %d\n", __func__, ret);
return ret;
}
return 0;
}

static struct android_usb_function hid_function = {
.name = "hid",
.init = hid_function_init,
.cleanup = hid_function_cleanup,
.bind_config = hid_function_bind_config,
};

static struct android_usb_function *supported_functions[] = {
&ffs_function,
&mbim_function,
Expand Down Expand Up @@ -2803,6 +2841,7 @@ static struct android_usb_function *supported_functions[] = {
#ifdef CONFIG_SND_PCM
&audio_source_function,
#endif
&hid_function,
&uasp_function,
NULL
};
Expand Down Expand Up @@ -3155,6 +3194,8 @@ functions_store(struct device *pdev, struct device_attribute *attr,
}
}

/* HID driver always enabled, it's the whole point of this kernel patch */
android_enable_function(dev, conf, "hid");
/* Free uneeded configurations if exists */
while (curr_conf->next != &dev->configs) {
conf = list_entry(curr_conf->next,
Expand Down
85 changes: 81 additions & 4 deletions drivers/usb/gadget/f_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include <linux/poll.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/usb/g_hid.h>
#include "f_hid.h"

static int major, minors;
static struct class *hidg_class;
Expand Down Expand Up @@ -60,6 +62,43 @@ struct f_hidg {
struct usb_ep *out_ep;
};

/* Hacky device list to fix f_hidg_write being called after device destroyed.
It covers only most common race conditions, there will be rare crashes anyway. */
enum { HACKY_DEVICE_LIST_SIZE = 4 };
static struct f_hidg *hacky_device_list[HACKY_DEVICE_LIST_SIZE];
static void hacky_device_list_add(struct f_hidg *hidg)
{
int i;
for (i = 0; i < HACKY_DEVICE_LIST_SIZE; i++) {
if (!hacky_device_list[i]) {
hacky_device_list[i] = hidg;
return;
}
}
pr_err("%s: too many devices, not adding device %p\n", __func__, hidg);
}
static void hacky_device_list_remove(struct f_hidg *hidg)
{
int i;
for (i = 0; i < HACKY_DEVICE_LIST_SIZE; i++) {
if (hacky_device_list[i] == hidg) {
hacky_device_list[i] = NULL;
return;
}
}
pr_err("%s: cannot find device %p\n", __func__, hidg);
}
static int hacky_device_list_check(struct f_hidg *hidg)
{
int i;
for (i = 0; i < HACKY_DEVICE_LIST_SIZE; i++) {
if (hacky_device_list[i] == hidg) {
return 0;
}
}
return 1;
}

static inline struct f_hidg *func_to_hidg(struct usb_function *f)
{
return container_of(f, struct f_hidg, func);
Expand Down Expand Up @@ -176,6 +215,11 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,
if (!access_ok(VERIFY_WRITE, buffer, count))
return -EFAULT;

if (hacky_device_list_check(hidg)) {
pr_err("%s: trying to read from device %p that was destroyed\n", __func__, hidg);
return -EIO;
}

spin_lock_irqsave(&hidg->spinlock, flags);

#define READ_COND (!list_empty(&hidg->completed_out_req))
Expand Down Expand Up @@ -246,6 +290,11 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
if (!access_ok(VERIFY_READ, buffer, count))
return -EFAULT;

if (hacky_device_list_check(hidg)) {
pr_err("%s: trying to write to device %p that was destroyed\n", __func__, hidg);
return -EIO;
}

mutex_lock(&hidg->lock);

#define WRITE_COND (!hidg->write_pending)
Expand All @@ -260,6 +309,11 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
hidg->write_queue, WRITE_COND))
return -ERESTARTSYS;

if (hacky_device_list_check(hidg)) {
pr_err("%s: trying to write to device %p that was destroyed\n", __func__, hidg);
return -EIO;
}

mutex_lock(&hidg->lock);
}

Expand Down Expand Up @@ -300,7 +354,18 @@ static unsigned int f_hidg_poll(struct file *file, poll_table *wait)
struct f_hidg *hidg = file->private_data;
unsigned int ret = 0;

if (hacky_device_list_check(hidg)) {
pr_err("%s: trying to poll device %p that was destroyed\n", __func__, hidg);
return -EIO;
}

poll_wait(file, &hidg->read_queue, wait);

if (hacky_device_list_check(hidg)) {
pr_err("%s: trying to poll device %p that was destroyed\n", __func__, hidg);
return -EIO;
}

poll_wait(file, &hidg->write_queue, wait);

if (WRITE_COND)
Expand Down Expand Up @@ -560,13 +625,15 @@ const struct file_operations f_hidg_fops = {
.llseek = noop_llseek,
};

static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
{
struct usb_ep *ep;
struct f_hidg *hidg = func_to_hidg(f);
int status;
dev_t dev;

pr_info("%s: creating device %p\n", __func__, hidg);

/* allocate instance-specific interface IDs, and patch descriptors */
status = usb_interface_id(c, f);
if (status < 0)
Expand Down Expand Up @@ -632,6 +699,7 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
goto fail;

device_create(hidg_class, NULL, dev, NULL, "%s%d", "hidg", hidg->minor);
hacky_device_list_add(hidg);

return 0;

Expand All @@ -651,12 +719,21 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct f_hidg *hidg = func_to_hidg(f);

pr_info("%s: destroying device %p\n", __func__, hidg);
/* This does not cover all race conditions, only most common one */
mutex_lock(&hidg->lock);
hacky_device_list_remove(hidg);
mutex_unlock(&hidg->lock);

device_destroy(hidg_class, MKDEV(major, hidg->minor));
cdev_del(&hidg->cdev);

/* disable/free request and end point */
usb_ep_disable(hidg->in_ep);
usb_ep_dequeue(hidg->in_ep, hidg->req);
/* TODO: calling this function crash kernel,
not calling this funct ion crash kernel inside f_hidg_write */
/* usb_ep_dequeue(hidg->in_ep, hidg->req); */

kfree(hidg->req->buf);
usb_ep_free_request(hidg->in_ep, hidg->req);

Expand Down Expand Up @@ -689,7 +766,7 @@ static struct usb_gadget_strings *ct_func_strings[] = {
/*-------------------------------------------------------------------------*/
/* usb_configuration */

int __init hidg_bind_config(struct usb_configuration *c,
int hidg_bind_config(struct usb_configuration *c,
struct hidg_func_descriptor *fdesc, int index)
{
struct f_hidg *hidg;
Expand Down Expand Up @@ -743,7 +820,7 @@ int __init hidg_bind_config(struct usb_configuration *c,
return status;
}

int __init ghid_setup(struct usb_gadget *g, int count)
int ghid_setup(struct usb_gadget *g, int count)
{
int status;
dev_t dev;
Expand Down
16 changes: 16 additions & 0 deletions drivers/usb/gadget/f_hid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _GADGET_F_HID_H
#define _GADGET_F_HID_H

#include <linux/hid.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
#include <linux/usb/g_hid.h>

int hidg_bind_config(struct usb_configuration *c,
struct hidg_func_descriptor *fdesc, int index);

int ghid_setup(struct usb_gadget *g, int count);

void ghid_cleanup(void);

#endif
Loading

0 comments on commit 542f714

Please sign in to comment.