xref: /base/startup/init/ueventd/include/ueventd.h (revision d9f0492f)
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef BASE_STARTUP_INITLITE_UEVENTD_H
17#define BASE_STARTUP_INITLITE_UEVENTD_H
18#include <unistd.h>
19#ifdef __cplusplus
20#if __cplusplus
21extern "C" {
22#endif
23#endif
24
25// Refer to linux kernel kobject.h
26typedef enum ACTION {
27    ACTION_ADD,
28    ACTION_REMOVE,
29    ACTION_CHANGE,
30    ACTION_MOVE,
31    ACTION_ONLINE,
32    ACTION_OFFLINE,
33    ACTION_BIND,
34    ACTION_UNBIND,
35    ACTION_UNKNOWN,
36} ACTION;
37
38struct UidGid {
39    uid_t uid;
40    gid_t gid;
41};
42
43struct Uevent {
44    const char *subsystem;
45    const char *syspath;
46    // DEVNAME may has slash
47    const char *deviceName;
48    const char *partitionName;
49    const char *firmware;
50    ACTION action;
51    int partitionNum;
52    int major;
53    int minor;
54    struct UidGid ug;
55    // for usb device.
56    int busNum;
57    int devNum;
58};
59
60typedef enum SUBYSTEM {
61    SUBSYSTEM_EMPTY = -1,
62    SUBSYSTEM_BLOCK = 0,
63    SUBSYSTEM_PLATFORM = 1,
64    SUBSYSTEM_FIRMWARE = 2,
65    SUBSYSTEM_OTHERS = 3,
66} SUBSYSTEMTYPE;
67
68#define CMDLINE_VALUE_LEN_MAX 512
69#define PROCESS_NAME_MAX_LENGTH 1024
70#define UEVENTD_POLL_TIME (5 * 60 * 1000)
71#define UEVENTD_FLAG "/dev/.ueventd_trigger_done"
72
73extern char bootDevice[CMDLINE_VALUE_LEN_MAX];
74
75const char *ActionString(ACTION action);
76void ParseUeventMessage(const char *buffer, ssize_t length, struct Uevent *uevent);
77void RetriggerUevent(int sockFd, char **devices, int num);
78void RetriggerUeventByPath(int sockFd, char *path);
79void ProcessUevent(int sockFd, char **devices, int num);
80void CloseUeventConfig(void);
81#ifdef __cplusplus
82#if __cplusplus
83}
84#endif
85#endif
86#endif // BASE_STARTUP_INITLITE_UEVENTD_H
87