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