本章主要是基于之前的学习,实现一个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学习(九)的更多相关文章

  1. Delphi 调试连接 任意Android手机/平板/盒子(要安装Google USB Driver,并且还有USB的相关许多文章)

    Delphi有时候无法连接调试一些手机,解决方案: 1.安装Google USB Driver 2.通过设备管理器查看手机或平板USB的VID,PID 3.修改你的电脑上的android_winusb ...

  2. 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 ...

  3. 【转】Android实战技巧之四十九:Usb通信之USB Host

    零 USB背景知识 USB是一种数据通信方式,也是一种数据总线,而且是最复杂的总线之一. 硬件上,它是用插头连接.一边是公头(plug),一边是母头(receptacle).例如,PC上的插座就是母头 ...

  4. Android自动化测试之Monkeyrunner学习笔记(一)

    Android自动化测试之Monkeyrunner学习笔记(一) 因项目需要,开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括Monkey.Monkeyr ...

  5. Android Wear(手表)开发 - 学习指南

    版权声明:欢迎自由转载-非商用-非衍生-保持署名.作者:Benhero,博客地址:http://www.cnblogs.com/benhero/ Android Wear开发 - 学习指南 http: ...

  6. Android系统--输入系统(九)Reader线程_核心类及配置文件

    Android系统--输入系统(九)Reader线程_核心类及配置文件 1. Reader线程核心类--EventHub 1.1 Reader线程核心结构体 实例化对象:mEventHub--表示多个 ...

  7. Android 音视频开发学习思路

    Android 音视频开发这块目前的确没有比较系统的教程或者书籍,网上的博客文章也都是比较零散的.只能通过一点点的学习和积累把这块的知识串联积累起来. 初级入门篇: Android 音视频开发(一) ...

  8. 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 ...

  9. Android命令行工具学习总结

    15.setting命令 setting命令可以很方便的更改系统设置中的参数(如修改系统默认输入法) 安卓Settings模块浅析:https://www.jianshu.com/p/ed8508fe ...

  10. 移动设备 小米2S不显示CD驱动器(H),便携设备,MTP,驱动USB Driver,MI2感叹号的解决方法

    小米2S不显示CD驱动器(H),便携设备,MTP,驱动USB Driver,MI2感叹号的解决方法 by:授客 QQ:1033553122 用户环境 操作系统:Win7 手机设备:小米2S   问题描 ...

随机推荐

  1. 1、Springboot2简介

    在学习 SpringBoot 之前,建议先具备 SpringMVC(控制层).Spring(业务层)和 Mybatis(持久层)的相关知识 1.1.概述 1.1.1.Spring的缺点 Spring ...

  2. 【DataBase】SQL优化案例:其一

    原始SQL: 这里想做的事情就是查询一周的一个计算值 可以理解为报表的那种 主表 t_wechat_clue 生产库上200万数据量 然后需要联表一些限制条件 SELECT IFNULL(SUM((C ...

  3. 【Layui】01 快速入门

    [原生JavaScript 与 JQuery] <!DOCTYPE html> <html lang="en"> <head> <meta ...

  4. 【Shiro】04 ini授权实现

    [授权概念] 访问控制,即在应用中控制谁能访问哪些资源(如访问页面/编辑数据/页面操作等). 在授权中需了解的几个关键对象:主体(Subject).资源(Resource).权限(Permission ...

  5. 在计算机论文中suppose suggest assume 用法上的区别

    ChatGPT3.5的答案: 在计算机论文中,"suppose," "suggest," 和 "assume" 有不同的用法和含义.它们在表 ...

  6. 大语言模型(LLM)的逻辑推理能力的例子 —— 以ChatGPT3.5为例

    例子: PS. 不得不说,这个表现虽然没有那么完美但是已经比较惊艳了,比传统的自然语言对话系列的表现高出很多呀,很神奇,这个LLM的逻辑能力是如何实现的呢?虽然LLM不具备逻辑推理能力,但是LLM确实 ...

  7. 关于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 ...

  8. 花店橱窗(线性DP)

    线性DP--花店橱窗 谨以此题解献给线性dp最后一道题 题目大致 Description xq和他的老婆xz最近开了一家花店,他们准备把店里最好看的花都摆在橱窗里.但是他们有很多花瓶,每个花瓶都具有各 ...

  9. MySQL中的char与varchar

    MySQL中的char与varchar char类型为固定长度的字符串 varchar类型是长度可变的字符串 char为固定长度的字符串意思是当我们设置一个字段类型为char时,指定char(100) ...

  10. PPT或Visio比较舒适的RGB配色参数

    1.187 204 235 2.222 156 83 3.117 156 83 4.64 116 52 5.117 121 74 6.69 137 148 7.182 194 154 8.207 19 ...