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