本章主要是基于之前的学习,实现一个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转串口通讯(CH34xUARTDriver)

    需求为:手机usb接口插入一个硬件,从硬件上获取数据 例如:手机usb插入硬件A,A通过蓝牙通讯获取设备a.b的数据,作为中转站(可以做些数据处理)将数据(设备a.b产生的)传给手机程序. 设备A也可 ...

  4. Android系统--输入系统(十)Reader线程_核心类及配置文件深入分析

    Android系统--输入系统(十)Reader线程_核心类及配置文件深入分析 0. 前言 个人认为该知识点阅读Android源代码会不仅容易走进死胡同,并且效果并不好,前脚看完后脚忘记,故进行总结, ...

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

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

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

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

  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. 新项目加入mybatisplus,我给自己挖了个坑 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 上述问题的解决办法:1首先看看@mapp ...

  2. VScode配置PHP开发环境

    vscode配置php开发环境 使用vscode配置PHP开发环境,首先要下载vscode, vscode下载 下载完vscode之后,可以在扩展里面下载中文版本 将vscode下载完之后,需要下载x ...

  3. 【VMware VCF】VMware Cloud Foundation Part 06:部署 VI 工作负载域。

    VMware Cloud Foundation 标准架构中,管理域和 VI 工作负载域需要分开部署,管理域是初始构建(Bring-up)中部署的一个工作负载域并且只有一个,管理域专门用于承载管理相关组 ...

  4. CentOS-7离线安装policycoreutils-python

    1.下载相关安装包 policycoreutils-2.5-34.el7.src.rpm 快速下载地址:https://vault.centos.org/7.9.2009/os/x86_64/Pack ...

  5. 为什么要使用工业仿真软件? —— CAE(Computer Aided Engineering)工程设计中的计算机辅助工程

    CAE技术: 引自: https://baike.baidu.com/item/CAE技术/18884456?fr=ge_ala 引自: https://www.mscsoftware.com.cn/ ...

  6. 如何在AWS上构建Apache DolphinScheduler

    引言 随着云计算技术的发展,Amazon Web Services (AWS) 作为一个开放的平台,一直在帮助开发者更好的在云上构建和使用开源软件,同时也与开源社区紧密合作,推动开源项目的发展. 本文 ...

  7. 使用BizyAir,没有显卡,也能玩AI绘图

    或许很多人跟我一样,没有显卡,但又很想玩AI绘图,但本地绘图怕是无缘了,只能借助云GPU的方式了. 今天跟大家分享一下一个简单目前可白嫖无门槛的方法实现无显卡也能玩AI绘图. 方案就是ComfyUI+ ...

  8. 学习SSD—day1_20240814

    1.SSD的基本概念以及结构 SSD是一种以半导体(半导体闪存)作为存储介质吗,使用纯电子电路实现的存储设备. SSD硬件包括几大组成部分:主控.闪存.缓存芯片DRAM(可选,有些SSD上可能只有SR ...

  9. 麒麟系统ARM架构下MySQL5.7离线安装,搭建主从集群

    一.检查本机操作系统 #一定要注意查看本机的操作系统,是amd(x86)还是arm(aarch)架构 $ uname -a Linux Server-58aa6d9e-9412-4ab6-b496-2 ...

  10. SQL Server使用脚本实现自动备份

    因服务器安装的SQL Server版本不支持自动定时备份,需自行实现,大概思路为: 创建备份数据库的脚本 创建批处理脚本执行步骤一中的脚本 创建Windows定时任务执行步骤二中的脚本 1. 创建SQ ...