Android Qcom USB Driver学习(十)
本章主要是基于之前的学习,实现一个hidraw的驱动,发现有两种用于识别usb设备的方式,放别是usb_device_id和hid_device_id
hid_probe
(1)hid_device_id
kernel/msm-4.19/drivers/hid/usbhid/hid-core.c
bus = usb usb_register 注册驱动 -> sys/bus/usb/driver
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
kernel/msm-4.19/drivers/hid/hid-core.c
bus = hid hid_register_driver 注册驱动 -> sys/bus/hid/driver
hid bus本身没有探测的能力,都是需要其他模块来进行hid_add_device,
(2)usb_device_id
kernel/msm-4.19/drivers/hid/usbhid/usbmouse.c
static const struct usb_device_id usb_mouse_id_table[] = {
USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
USB_INTERFACE_PROTOCOL_MOUSE)
usb探测的过程如下
usb_new_device -> usb_enumerate_device + announce_device + device_add -> bus_probe_device -> device_initial_probe
-> driver_match_device -> usb_device_match (driver.c)-> usb_match_id (usb_device_id usbmouse.c)
-> driver_probe_device -> really_probe -> usb_mouse_probe -> input_register_device(usbmouse.c)
-> usbhid_probe (usbhid/hid-core.c)-> hid_add_device -> device_add
-> driver_match_device -> hid_bus_match (hid/hid-core.c) -> hid_match_id (hid_device_id hid-generic.c)
-> driver_probe_device -> hid_device_probe(hid/hid-core.c) -> hid_generic_probe (hid/hid-generic.c)
issues
E hidraw 0003: 0C2E:1007.0001: device has no listeners, quitting
.raw_event = hidraw_raw_event, //hidwar必须要实现这个函数
CONFIG_HIDRAW=y //需要打开这个函数,不然会调用hidraw.h中的空函数
hidraw_demo
在android的源码中没有只有hidraw的驱动,只有一些定义在hidraw.c中的api, 通过这些参数实现了hidraw接口的功能并测试通过
/* Copyright (c) 2014-2014, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/hid.h>
#include <linux/hid-debug.h>
#include "hid-ids.h"
#include "usbhid/usbhid.h"
#include <linux/usb.h>
#include <linux/vmalloc.h>
#include <linux/completion.h>
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/poll.h>
#include <linux/device.h>
#include <linux/major.h>
#include <linux/slab.h>
#include <linux/hid.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/sched/signal.h>
#include <linux/hidraw.h>
#define hidtype 0//1:use clamied , 0: use connect_mask
struct hidraw_data {
struct hid_device *hdev;
};
static int hidraw_raw_event(struct hid_device *hdev,
struct hid_report *report, u8 *raw_data, int size)
{
struct hidraw_data *data = hid_get_drvdata(hdev);
int ret = 0;
if (!data)
return 1;
hidraw_report_event(hdev, raw_data, size);
return ret;
}
#ifdef CONFIG_PM
static int hidraw_suspend(struct hid_device *hdev, pm_message_t message)
{
return 0;
}
static int hidraw_resume(struct hid_device *hdev)
{
return 0;
}
static int hidraw_reset_resume(struct hid_device *hdev)
{
return 0;
}
#endif
static int hidraw_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
struct hidraw_data *data;
int error = -ENOMEM;
struct usbhid_device *usbhid = hdev->driver_data;
if(usbhid->ifnum != 0) {
hid_err(hdev, "usbhid ifnum = %d\n", usbhid->ifnum);
return error;
}
//hidraw_init();
data = kzalloc(sizeof(struct hidraw_data), GFP_KERNEL);
if (data == NULL) {
hid_err(hdev, "failed to kzallocc \n");
error = -ENOMEM;
goto err_kzalloc;
}
data->hdev = hdev;
hid_set_drvdata(hdev, data);
error = hid_parse(hdev);
if (error) {
hid_err(hdev, "failed to parse \n");
goto err_kzalloc;
}
hdev->quirks = HID_QUIRK_NO_INIT_REPORTS;
#if hidtype
hdev->claimed = HID_CLAIMED_HIDRAW;
error = hid_hw_start(hdev, 0);
#else
error = hid_hw_start(hdev, HID_CONNECT_HIDRAW );
#endif
if (error) {
hid_err(hdev, "failed to hw start\n");
goto err_drvdata_null;
}
#if hidtype
hidraw_connect(hdev);
#endif
return 0;
err_kzalloc:
kfree(data);
err_drvdata_null:
hid_set_drvdata(hdev, NULL);
return error;
}
static void hidraw_remove(struct hid_device *hdev)
{
struct hidraw_data *data = hid_get_drvdata(hdev);
hid_hw_stop(hdev);
#if hidtype
hidraw_disconnect(hdev);
#endif
hid_set_drvdata(hdev, NULL);
//hidraw_exit();
kfree(data);
}
static const struct hid_device_id hidraw_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_xxx, USB_DEVICE_ID_xxx) },
{ }
};
MODULE_DEVICE_TABLE(hid, hidraw_devices);
static struct hid_driver hidraw_driver = {
.name = "hid-own",
.id_table = hidraw_devices,
.probe = hidraw_probe,
.remove = hidraw_remove,
.raw_event = hidraw_raw_event,
#ifdef CONFIG_PM
.suspend = hidraw_suspend,
.resume = hidraw_resume,
.reset_resume = hidraw_reset_resume,
#endif
};
//module_hid_driver(hidraw_driver);
static int __init hidown_init(void)
{
int result;
hidraw_init();
result = hid_register_driver(&hidraw_driver);
return result;
}
static void __exit hidown_exit(void)
{
hid_unregister_driver(&hidraw_driver);
hidraw_exit();
}
module_init(hidown_init);
module_exit(hidown_exit);
MODULE_DESCRIPTION("Hid Raw Demo");
MODULE_LICENSE("GPL v2");
Android Qcom USB Driver学习(十)的更多相关文章
- Delphi 调试连接 任意Android手机/平板/盒子(要安装Google USB Driver,并且还有USB的相关许多文章)
Delphi有时候无法连接调试一些手机,解决方案: 1.安装Google USB Driver 2.通过设备管理器查看手机或平板USB的VID,PID 3.修改你的电脑上的android_winusb ...
- CVE-2016-2502-drivers/usb/gadget/f_serial.c in the Qualcomm USB driver in Android. Buffer Overflow Vulnerability reported by #plzdonthackme, Soctt.
CVE-2016-2502-drivers/usb/gadget/f_serial.c in the Qualcomm USB driver in Android.Buffer Overflow Vu ...
- Android项目实战(四十五):Usb转串口通讯(CH34xUARTDriver)
需求为:手机usb接口插入一个硬件,从硬件上获取数据 例如:手机usb插入硬件A,A通过蓝牙通讯获取设备a.b的数据,作为中转站(可以做些数据处理)将数据(设备a.b产生的)传给手机程序. 设备A也可 ...
- Android系统--输入系统(十)Reader线程_核心类及配置文件深入分析
Android系统--输入系统(十)Reader线程_核心类及配置文件深入分析 0. 前言 个人认为该知识点阅读Android源代码会不仅容易走进死胡同,并且效果并不好,前脚看完后脚忘记,故进行总结, ...
- Android自动化测试之Monkeyrunner学习笔记(一)
Android自动化测试之Monkeyrunner学习笔记(一) 因项目需要,开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括Monkey.Monkeyr ...
- Android Wear(手表)开发 - 学习指南
版权声明:欢迎自由转载-非商用-非衍生-保持署名.作者:Benhero,博客地址:http://www.cnblogs.com/benhero/ Android Wear开发 - 学习指南 http: ...
- Android 音视频开发学习思路
Android 音视频开发这块目前的确没有比较系统的教程或者书籍,网上的博客文章也都是比较零散的.只能通过一点点的学习和积累把这块的知识串联积累起来. 初级入门篇: Android 音视频开发(一) ...
- Head First Android --- Enable USB debugging on your device
1. Enable USB debugging on your device On your device, open “Developer options” (in Android 4.0 o ...
- Android命令行工具学习总结
15.setting命令 setting命令可以很方便的更改系统设置中的参数(如修改系统默认输入法) 安卓Settings模块浅析:https://www.jianshu.com/p/ed8508fe ...
- 移动设备 小米2S不显示CD驱动器(H),便携设备,MTP,驱动USB Driver,MI2感叹号的解决方法
小米2S不显示CD驱动器(H),便携设备,MTP,驱动USB Driver,MI2感叹号的解决方法 by:授客 QQ:1033553122 用户环境 操作系统:Win7 手机设备:小米2S 问题描 ...
随机推荐
- 新年恭喜发财-scratch编程作品
程序说明: <新年-恭喜发财>是一个基于Scratch平台制作的动画贺卡项目.该项目通过编程和艺术设计,展现了浓厚的中国新年(2024年为龙年)氛围,以及传统的恭喜发财祝福.动画中包含有喜 ...
- Fiddler篡改请求和响应数据
Fiddler标记断点后,我们可以通过篡改请求或响应数据,来模拟客户端请求和服务器响应. 一.打断点的方式 1.1 工具栏设置断点 工具栏勾选断点类型进行断点,路径:Rules->Automat ...
- 对比python学julia(第一章)--(第一节)万事开头也不难
自1989年被创立以后,历经30多年的发展,Python已经如日中天,在运维.大数据.云计算.web.科学计算上混的风生水起,并且于2020.2021年蝉联TIOBE年度编程语言首座.以至于,如今不会 ...
- 【Vue】Re06 组件化
将一个应用页面拆分成若干个可重复使用的组件 一.Vue的组件的使用步骤: 1.创建组件构造器 2.注册组件 3.使用组件 <!DOCTYPE html> <html lang=&qu ...
- python高性能计算:cython入门代码
三种实现的对比: (1)纯python x.py def is_prime(num): for j in range(2, num): if (num%j)==0: return False retu ...
- NVIDIA中的cupti的作用及设置: CUDA profiling tools interface —— Could not load dynamic library 'libcupti.so.10.1' —— failed with error CUPTI_ERROR_INSUFFICIENT_PRIVILEGES
NVIDIA官方给出的说明: 可以知道,这个组件的作用是对NVIDIA的CUDA进程进行性能分析的,通过对这个组件的调用可以实现对CUDA进程的性能监测. 在使用深度学习框架时有时需要对运行的代码的C ...
- RabbitMq 初学五大模式 通俗易懂 超详细 【包含案例】
RabbitMQ五种工作模式 HelloWorld 简单模式 WorkQueues 工作队列模式 Publish/Subscribe 发布/订阅模式 Routing 路由模式 Topic 通配符模式 ...
- 22张图详解浏览器请求数据包如何到达web服务器(搞懂网络可以毕业了)
浏览器的请求数据包如何到达web服务器? 很多读者对于其中的完整流程不是特别的了解,下面一口君通过这22张图,详细的讲解我们点击浏览器的网址之后,数据包是如何经过重重险阻到达web server的. ...
- vscode使用说明
# 要经常保存 # centos打开vscode方式 普通用户:[bw@localhost ~]$ /usr/share/code/bin/code 超级用户:[root@localhost shar ...
- 在 macOS 上安装 fish
安装 fish brew install zsh 将默认 shell 切换为 fish 由于 Homebrew 安装的 fish 不在标准 shell 列表 /etc/shell 里,因此要先将 fi ...