开发中,其他模块提出需求,需要我提供一个接口,另一个模块会启动独立线程,不断的调用这个接口,来实现USB事件的分离和提取,详细的接口代码如下:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#define UEVENT_MSG_LEN 2048
#define UEVENT_LOG_SAVE 1
struct uevent_struct {
const char *action;
const char *path;
const char *subsystem;
const char *firmware;
const char *usbstate;
int major;
int minor;
};
static int open_uevent_struct_socket(void);
static void parse_event(const char *msg, struct uevent_struct *uevent_struct);
/*******************************************************************
* Function : main
* Description : Keep Look For Monitor Uevent And Receive Uevent
* Input : int argc
* : char* argv[]
* Date : 20151015
********************************************************************/
int main(int argc, char* argv[])
{
int
Linux驱动:监控与提取USB插入uevent事件

本文介绍了如何在Linux驱动开发中,通过监听uevent消息来捕获USB设备插入事件,以实现USB事件的独立处理。具体实现包括创建接口以及使用线程持续调用接口来检测USB插入操作。
最低0.47元/天 解锁文章
1190

被折叠的 条评论
为什么被折叠?



