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通信之USB Host
零 USB背景知识 USB是一种数据通信方式,也是一种数据总线,而且是最复杂的总线之一. 硬件上,它是用插头连接.一边是公头(plug),一边是母头(receptacle).例如,PC上的插座就是母头 ...
- Android自动化测试之Monkeyrunner学习笔记(一)
Android自动化测试之Monkeyrunner学习笔记(一) 因项目需要,开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括Monkey.Monkeyr ...
- Android Wear(手表)开发 - 学习指南
版权声明:欢迎自由转载-非商用-非衍生-保持署名.作者:Benhero,博客地址:http://www.cnblogs.com/benhero/ Android Wear开发 - 学习指南 http: ...
- Android系统--输入系统(九)Reader线程_核心类及配置文件
Android系统--输入系统(九)Reader线程_核心类及配置文件 1. Reader线程核心类--EventHub 1.1 Reader线程核心结构体 实例化对象:mEventHub--表示多个 ...
- 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 问题描 ...
随机推荐
- git篇-- Git在项目实操中常见的使用命令--02
Git是现代软件开发中不可或缺的版本控制工具.它能帮助开发者跟踪项目的所有变更,并与团队成员高效协作.本文将介绍一些在项目实操中常见的Git命令,帮助你更好地管理代码. 1. 初始化和配置 初始化仓库 ...
- MySQL常用语句(经常容易忘记)
MySQL常用语句 一.连接MySQL 格式: mysql -h <主机地址> -u<用户名> -p<用户密码> --port=<端口号> 1.例1:连 ...
- 【Ubuntu】下载安装 20.04.版本 桌面端
下载 Download 这次的是直接在界面上下载的,我都不知道为什么怎么点到之前的版本去了 12.04.5远古版本界面怪难看的... [下载地址:点我访问] https://cn.ubuntu.com ...
- 如何在Windows10电脑上打开3D建模STL文件
相关: https://www.bilibili.com/video/BV1gD4y1h7tj/
- AI领域的国产显卡如何在现有技术下吸引用户 —— 廉价增加显存 —— 大显存
先给出一个不大准确的但相差不差的背景介绍: 同样性能级别的显卡,NVIDA的24G的要3W,32G的要5W,48G的要7W, 80G的要10W. 国产同同性能的显卡32G的要10W,48G的要15W, ...
- java多线程-补充-面试
1.背景 在这个课程之前我们已经讲了2个关于多线程的课程 一个是主要是关于多线程基础的: 另一个主要是关于JUC的: 今天我们对之前课程中没有讲到的或者重要的或者是童鞋们反馈的技术点做一个补充讲解 当 ...
- Apache DolphinScheduler 社区5月月报更新!
各位热爱 DolphinScheduler 的小伙伴们,社区5月份月报更新啦!这里将记录 DolphinScheduler 社区每月的重要更新,欢迎关注,期待下个月你也登上Merge Star月度榜单 ...
- 关于SpringBoot 启动失败 Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. 的问题解析
Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean ...
- 9组-Beta冲刺-总结
一.基本情况 组长博客链接:9组-Beta冲刺-总结 现场答辩总结:本次答辩,我们演示了我们到Beta冲刺周结束时的成果展示,离目标还有一些距离,不过本次答辩完成了任务,总体来说还不错,希望下次最终答 ...
- 【动画进阶】神奇的卡片 Hover 效果与 Blur 的特性探究
本文,我们将一起探讨探讨,如下所示的一个卡片 Hover 动画,应该如何实现: 这个效果的几个难点: 鼠标移动的过程中,展示当前卡片边缘的 border 以及发光效果: 效果只出现在鼠标附近?这一块的 ...