-
Notifications
You must be signed in to change notification settings - Fork 0
/
ztenetlink.cc
56 lines (44 loc) · 1.28 KB
/
ztenetlink.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright: (C) 2016 ESIMTEK ALL RIGHTS RESERVED
// author: Yonghua Zheng
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "uevent.h"
#include "ztenetlink.h"
#include "dispatchmanager.h"
ZteNetlink* ZteNetlink::open()
{
int sock = uevent_open_socket(0, true);
if (sock >= 0)
return new ZteNetlink(sock);
return NULL;
}
ZteNetlink::ZteNetlink(int sock)
: NetlinkObserver(sock)
{
}
ZteNetlink::~ZteNetlink()
{
}
int ZteNetlink::on_event(NetlinkEvent *evt)
{
if (evt->getAction() == NetlinkEvent::NlActionAdd) {
const char *subsystem = evt->getSubsystem();
if (strncmp(subsystem, "tty", 3))
return 0;
const char *devname = evt->getDevname();
if (strncmp(devname, "tty", 3) || isdigit(devname[3]))
return 0;
int idVendor = evt->getIdVendor();
int idProduct = evt->getIdProduct();
if (idVendor != 0x19d2 && idProduct != 0x0199)
return 0;
const char *interface = evt->getInterface();
if (!strncmp(interface, "USB-AT", 6)) {
char message[64];
snprintf(message, sizeof(message), "ACTION=add, DEVNODE=/dev/%s", devname);
DispatchManager::Post(DispatchManager::main_id, message);
}
}
return 0;
}