jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <fcntl.h> |
| 7 | #include <errno.h> |
| 8 | #include <pthread.h> |
jb.qi | e7aac6d | 2023-12-28 01:32:19 -0800 | [diff] [blame] | 9 | #include <unistd.h> |
jb.qi | 1f6204d | 2024-01-30 22:14:24 -0800 | [diff] [blame] | 10 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 11 | #include <lynq_autosuspend.h> |
| 12 | #include "lynq-qser-autosuspend.h" |
| 13 | #include "liblog/lynq_deflog.h" |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 14 | #include <include/lynq_uci.h> |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | |
| 21 | extern int lynq_autosleep_enable(void); |
| 22 | extern int lynq_autosleep_disable(void); |
| 23 | extern int release_wake_lock(char *name); |
| 24 | extern int acquire_wake_lock(int lock, char *name); |
| 25 | |
| 26 | #define USER_LOG_TAG "LYNQ_QSER_AUTOSUSPEND" |
| 27 | #define FILE_LOCK_TABLE "/tmp/.lock_table" |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 28 | #define LOG_UCI_MODULE "lynq_autosuspend" |
| 29 | #define LOG_UCI_FILE "lynq_uci" |
| 30 | |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 31 | #define UEVENT_MSG_LEN 128 |
| 32 | |
jb.qi | 1b4d54e | 2024-01-03 22:22:42 -0800 | [diff] [blame] | 33 | int g_init_flag = 0; |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 34 | |
| 35 | |
| 36 | qser_lpm_Handler_t g_lpm_handler = NULL; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 37 | |
| 38 | |
| 39 | LOCK_TABLE lock_status; |
| 40 | |
| 41 | |
| 42 | int file_fd; |
| 43 | int first_run = 0; |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 44 | pthread_t thid; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 45 | |
| 46 | |
| 47 | int lock_table_init(void) |
| 48 | { |
| 49 | int ret; |
| 50 | int err; |
| 51 | |
| 52 | file_fd = open(FILE_LOCK_TABLE, O_RDWR| O_CREAT,0777); |
| 53 | if(file_fd < 0) |
| 54 | { |
| 55 | err = errno; |
| 56 | LYINFLOG("Error open lock_table file:%s\n", strerror(errno)); |
| 57 | return -err; |
| 58 | } |
| 59 | memset(&lock_status, 0, sizeof(lock_status)); |
| 60 | ret = write(file_fd, (char*)&lock_status, sizeof(lock_status)); |
| 61 | if(ret <= 0) |
| 62 | { |
| 63 | LYINFLOG("write fail\n"); |
| 64 | close(file_fd); |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 65 | return E_WRITE; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 66 | } |
| 67 | sync(); |
| 68 | close(file_fd); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | int read_lock_table(void) |
| 74 | { |
| 75 | int err; |
| 76 | int ret; |
| 77 | int i; |
| 78 | LYLOGSET(LOG_INFO); |
| 79 | LYLOGEINIT(USER_LOG_TAG); |
| 80 | |
| 81 | if(access(FILE_LOCK_TABLE,0) < 0) |
| 82 | { |
| 83 | ret = lock_table_init(); |
| 84 | if(ret < 0) |
| 85 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 86 | return E_READ; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
| 90 | file_fd = open(FILE_LOCK_TABLE,O_RDWR); |
| 91 | if(file_fd < 0) |
| 92 | { |
| 93 | err = errno; |
| 94 | LYINFLOG("Error open lock_table file:%s\n", strerror(errno)); |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 95 | return E_READ; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | memset(&lock_status, 0, sizeof(lock_status)); |
| 99 | lseek(file_fd,0,SEEK_SET); |
| 100 | ret = read(file_fd,(unsigned char *)&lock_status,sizeof(lock_status)); |
| 101 | LYINFLOG("read ret=%d\n", ret); |
| 102 | if(ret <= 0) |
| 103 | { |
| 104 | close(file_fd); |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 105 | return E_READ; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | for(i=0;i<MAX_LOCK_NUM;i++) |
| 109 | { |
| 110 | if(strlen(lock_status.lock_name[i]) != 0) |
| 111 | { |
| 112 | LYINFLOG("fd: %d lock_name:%s strlen:%d\n", i, lock_status.lock_name[i], strlen(lock_status.lock_name[i])); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | close(file_fd); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | int save_lock_table(void) |
| 122 | { |
| 123 | int err; |
| 124 | int ret; |
| 125 | file_fd = open(FILE_LOCK_TABLE,O_RDWR); |
| 126 | if(file_fd < 0) |
| 127 | { |
| 128 | err = errno; |
| 129 | LYINFLOG("Error open lock_table file:%s\n", strerror(errno)); |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 130 | return E_WRITE; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 131 | } |
| 132 | LYINFLOG("write lock_name[0]: %s\n", lock_status.lock_name[0]); |
| 133 | ret = write(file_fd, (unsigned char *)&lock_status, sizeof(lock_status)); |
| 134 | LYINFLOG("write ret=%d\n", ret); |
| 135 | if(ret <= 0) |
| 136 | { |
| 137 | LYINFLOG("write fail\n"); |
| 138 | close(file_fd); |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 139 | return E_WRITE; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 140 | } |
| 141 | sync(); |
| 142 | close(file_fd); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 147 | int check_pid(int pid) |
| 148 | { |
| 149 | char cmd1[64]; |
| 150 | int ret = -1; |
| 151 | sprintf(cmd1, "ps -ef |awk '{print $1}'|grep \"^%d$\"", pid); |
| 152 | ret = system(cmd1); |
| 153 | return ret; |
| 154 | } |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 155 | |
| 156 | int check_lock(char *name) |
| 157 | { |
| 158 | int j; |
| 159 | int num; |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 160 | int ret=-1; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 161 | for(j=0;j<MAX_LOCK_NUM;j++) |
| 162 | { |
| 163 | if(strcmp(lock_status.lock_name[j], name) == 0) |
| 164 | { |
| 165 | num = j; |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if(j < MAX_LOCK_NUM) |
| 171 | { |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 172 | ret = check_pid(lock_status.lock_pid[j]); |
| 173 | if(!ret) |
| 174 | { |
| 175 | LYINFLOG("the pid is exist\n"); |
| 176 | num = MAX_LOCK_NUM+1; |
| 177 | return num; |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | LYINFLOG("the pid is not exist\n"); |
| 182 | return num; |
| 183 | } |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | return -1; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | int add_lock(char *name) |
| 191 | { |
| 192 | int ret; |
| 193 | int i = 0; |
| 194 | int num; |
| 195 | int check_flag; |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 196 | int pid; |
| 197 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 198 | ret = read_lock_table(); |
| 199 | LYINFLOG("read_lock_table ret = %d\n", ret); |
| 200 | if(ret <0) |
| 201 | { |
| 202 | return ret; |
| 203 | } |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 204 | pid = getpid(); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 205 | check_flag = check_lock(name); |
| 206 | |
| 207 | if(check_flag < 0) |
| 208 | { |
| 209 | for(i=0;i<MAX_LOCK_NUM;i++) |
| 210 | { |
| 211 | if(strlen(lock_status.lock_name[i]) == 0) |
| 212 | { |
| 213 | strcpy(lock_status.lock_name[i], name); |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 214 | lock_status.lock_pid[i] = pid; |
| 215 | LYINFLOG("lock_name[%d] %s, lock_pid = %d\n", i, lock_status.lock_name[i], pid); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 216 | break; |
| 217 | } |
| 218 | } |
| 219 | if(i == MAX_LOCK_NUM) |
| 220 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 221 | return E_TABLE_FULL; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 222 | } |
| 223 | else |
| 224 | { |
| 225 | num = i; |
| 226 | } |
| 227 | } |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 228 | else if(check_flag > MAX_LOCK_NUM) |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 229 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 230 | return E_LOCK_EXIST; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 231 | } |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 232 | else |
| 233 | { |
| 234 | num = check_flag; |
| 235 | lock_status.lock_pid[num] = pid; |
| 236 | } |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 237 | |
| 238 | LYINFLOG("num = %d\n", num); |
| 239 | ret = save_lock_table(); |
| 240 | if(ret < 0) |
| 241 | { |
| 242 | return ret; |
| 243 | } |
| 244 | return num; |
| 245 | } |
| 246 | |
| 247 | int delete_lock(int fd) |
| 248 | { |
| 249 | int ret; |
| 250 | int i; |
| 251 | ret = read_lock_table(); |
| 252 | memset(lock_status.lock_name[fd], 0, sizeof(lock_status.lock_name[fd])); |
jb.qi | 562fd03 | 2024-02-01 02:42:10 -0800 | [diff] [blame] | 253 | lock_status.lock_pid[fd] = -1; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 254 | ret = save_lock_table(); |
| 255 | return ret; |
| 256 | } |
| 257 | |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 258 | |
| 259 | void *check_dtr(void * arg) |
| 260 | { |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 261 | qser_lpm_edge_t lpm_edge; |
jb.qi | 1f6204d | 2024-01-30 22:14:24 -0800 | [diff] [blame] | 262 | char msg[16]; |
| 263 | int fd=0; |
| 264 | int ret=0; |
| 265 | |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 266 | while(1) |
| 267 | { |
jb.qi | 1f6204d | 2024-01-30 22:14:24 -0800 | [diff] [blame] | 268 | fd = open("/sys/xp2xp/xp2xp_notify/xp2xp_state", O_RDONLY); |
| 269 | ret=read(fd, &msg,15); |
| 270 | LYERRLOG("xp2xp_state ret = %d\n", ret); |
| 271 | close(fd); |
| 272 | |
| 273 | if(ret == 5) |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 274 | { |
jb.qi | 1f6204d | 2024-01-30 22:14:24 -0800 | [diff] [blame] | 275 | lpm_edge =E_QL_LPM_FALLING; |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 276 | } |
jb.qi | 1f6204d | 2024-01-30 22:14:24 -0800 | [diff] [blame] | 277 | else if(ret == 6) |
| 278 | { |
| 279 | lpm_edge =E_QL_LPM_RISING; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | continue; |
| 284 | } |
| 285 | g_lpm_handler(lpm_edge); |
| 286 | |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 293 | int qser_lpm_init(qser_lpm_Handler_t qser_lpm_handler, qser_pm_cfg_t *qser_lpm_cfg) |
| 294 | { |
| 295 | int ret; |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 296 | int num; |
jb.qi | 1b4d54e | 2024-01-03 22:22:42 -0800 | [diff] [blame] | 297 | if(g_init_flag != 0) |
| 298 | { |
| 299 | LYERRLOG("g_init_flag is error\n"); |
| 300 | return -1; |
| 301 | } |
| 302 | g_init_flag = 1; |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 303 | g_lpm_handler = qser_lpm_handler; |
| 304 | ret = pthread_create(&thid,NULL,check_dtr,NULL); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 305 | if(ret != 0) |
| 306 | { |
jb.qi | 1b4d54e | 2024-01-03 22:22:42 -0800 | [diff] [blame] | 307 | LYERRLOG("pthread create fail, qser_lpm_init fail\n"); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 308 | } |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | int qser_lpm_deinit(void) |
| 314 | { |
| 315 | int ret; |
jb.qi | 1b4d54e | 2024-01-03 22:22:42 -0800 | [diff] [blame] | 316 | if(g_init_flag != 1) |
| 317 | { |
| 318 | LYERRLOG("g_init_flag is error"); |
| 319 | return -1; |
| 320 | } |
| 321 | g_init_flag = 0; |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 322 | ret = pthread_cancel(thid); |
| 323 | if(!ret) |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 324 | { |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 325 | LYERRLOG("pthread cancel success, lpm deinit success\n"); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 326 | } |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 327 | else |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 328 | { |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 329 | LYERRLOG("pthread cancel fail, lpm deinit fail\n"); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 330 | } |
jb.qi | fbef514 | 2023-12-18 00:49:10 -0800 | [diff] [blame] | 331 | return ret; |
| 332 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 333 | } |
| 334 | |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 335 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 336 | int qser_autosuspend_enable(char enable) |
| 337 | { |
| 338 | int ret; |
| 339 | if(enable == '0') |
| 340 | { |
| 341 | ret = lynq_autosleep_disable(); |
| 342 | |
| 343 | } |
| 344 | else if(enable == '1') |
| 345 | { |
| 346 | ret = lynq_autosleep_enable(); |
| 347 | } |
| 348 | else |
| 349 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 350 | return E_INPUT_ERROR; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 351 | |
| 352 | } |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 353 | if(ret >= 0) |
| 354 | { |
| 355 | ret = 0; |
| 356 | } |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 357 | return ret; |
| 358 | |
| 359 | } |
| 360 | |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 361 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 362 | int qser_wakelock_create(const char *name, size_t len) |
| 363 | { |
| 364 | int ret; |
| 365 | if(name == NULL) |
| 366 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 367 | return E_INPUT_ERROR; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 368 | } |
| 369 | LYINFLOG("%s\n", name); |
| 370 | ret = add_lock(name); |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | int qser_wakelock_lock(int fd) |
| 375 | { |
| 376 | |
| 377 | int ret; |
| 378 | if(fd < 0 || fd >= MAX_LOCK_NUM) |
| 379 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 380 | return E_INPUT_ERROR; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 381 | } |
| 382 | ret = read_lock_table(); |
| 383 | ret = acquire_wake_lock( 0, lock_status.lock_name[fd]); |
jb.qi | 68fe778 | 2023-09-18 20:40:58 -0700 | [diff] [blame] | 384 | if(ret > 0) |
| 385 | { |
| 386 | ret = 0; |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | ret = -1; |
| 391 | } |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 392 | return ret; |
| 393 | } |
| 394 | |
| 395 | int qser_wakelock_unlock(int fd) |
| 396 | { |
| 397 | int ret; |
| 398 | if(fd < 0 || fd >= MAX_LOCK_NUM) |
| 399 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 400 | return E_INPUT_ERROR; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 401 | } |
| 402 | ret = read_lock_table(); |
| 403 | if(strlen(lock_status.lock_name[fd]) == 0) |
| 404 | { |
| 405 | LYINFLOG("%d is null\n", fd); |
| 406 | return -1; |
| 407 | } |
| 408 | ret = release_wake_lock(lock_status.lock_name[fd]); |
jb.qi | 68fe778 | 2023-09-18 20:40:58 -0700 | [diff] [blame] | 409 | if(ret > 0) |
| 410 | { |
| 411 | ret = 0; |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | ret = -1; |
| 416 | } |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 417 | return ret; |
| 418 | } |
| 419 | |
| 420 | int qser_wakelock_destroy(int fd) |
| 421 | { |
| 422 | int ret; |
| 423 | if(fd < 0 || fd >= MAX_LOCK_NUM) |
| 424 | { |
jb.qi | aa241cf | 2023-09-18 18:35:00 -0700 | [diff] [blame] | 425 | return E_INPUT_ERROR; |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 426 | } |
jb.qi | 5221035 | 2023-09-19 23:29:09 -0700 | [diff] [blame] | 427 | ret = qser_wakelock_unlock(fd); |
| 428 | if(ret) |
| 429 | { |
| 430 | LYINFLOG("unlock is fail\n"); |
| 431 | return ret; |
| 432 | } |
| 433 | |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 434 | ret = delete_lock(fd); |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 435 | return ret; |
| 436 | } |
| 437 | |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 438 | int qser_whitelist_set(char *whitelist) |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 439 | { |
| 440 | int ret; |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 441 | char cmd[64]; |
| 442 | if(strlen(whitelist) != 4) |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 443 | { |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 444 | LYINFLOG("string len is error\n"); |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 445 | return -1; |
| 446 | } |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 447 | sprintf(cmd, "uci set lynq_uci.lynq_autosuspend.whitelist_state='%s'", whitelist); |
| 448 | ret = system(cmd); |
| 449 | system("uci commit"); |
| 450 | if(ret != 0) |
| 451 | { |
| 452 | LYINFLOG("qser_whitlist_set fail"); |
| 453 | } |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 454 | return ret; |
| 455 | |
| 456 | } |
| 457 | |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 458 | int qser_whitelist_get(char *whitelist) |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 459 | { |
| 460 | int ret; |
jb.qi | 7a90186 | 2024-01-03 19:45:23 -0800 | [diff] [blame] | 461 | ret = lynq_get_value(LOG_UCI_FILE, LOG_UCI_MODULE, "whitelist_state", whitelist); |
| 462 | LYERRLOG("ret =%d, whitelist_state is %s\n", ret, whitelist); |
jb.qi | 422ee11 | 2023-11-21 03:04:03 -0800 | [diff] [blame] | 463 | return ret; |
| 464 | |
| 465 | } |
| 466 | |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 467 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_AUTOSUSPEND) |
| 468 | |
jb.qi | 3a8298c | 2023-09-07 04:48:51 -0700 | [diff] [blame] | 469 | #ifdef __cplusplus |
| 470 | } |
| 471 | #endif |
| 472 | |
| 473 | |
| 474 | |