b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <string.h> |
| 7 | #include <errno.h> |
| 8 | #include <termios.h> |
| 9 | #include <unistd.h> |
| 10 | #include <stdint.h> |
| 11 | #include <sys/ioctl.h> |
| 12 | #include <dlfcn.h> |
hong.liu | cd37079 | 2025-05-28 06:29:19 -0700 | [diff] [blame] | 13 | #include "gsw_usb_interface.h" |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 14 | |
| 15 | #define TMP_USB_RESTART "/sbin/tmp_usb_init" |
| 16 | #define USB_OPEN 3300 |
| 17 | #define USB_CLOSE 3329 |
| 18 | |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 19 | int32_t gsw_usb_permanent_switch(EN_GSW_USB_SWITCH_TYPE type) |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 20 | { |
| 21 | int ret; |
| 22 | char cmd[256]; |
| 23 | if(type != EN_GSW_USB_SWITCH_OPEN && type != EN_GSW_USB_SWITCH_CLOSE) |
hong.liu | cd37079 | 2025-05-28 06:29:19 -0700 | [diff] [blame] | 24 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 25 | sprintf(cmd, "setprop persist.mbtk.usb_pid %d && %s %d &", type?USB_OPEN:USB_CLOSE, TMP_USB_RESTART, type?USB_OPEN:USB_CLOSE); |
| 26 | ret = system(cmd); |
| 27 | return ret; |
| 28 | } |
| 29 | |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 30 | int32_t gsw_usb_temporary_switch(EN_GSW_USB_SWITCH_TYPE type) |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 31 | { |
| 32 | int ret; |
| 33 | char cmd[256]; |
| 34 | if(type != EN_GSW_USB_SWITCH_OPEN && type != EN_GSW_USB_SWITCH_CLOSE) |
hong.liu | cd37079 | 2025-05-28 06:29:19 -0700 | [diff] [blame] | 35 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 36 | sprintf(cmd, "%s %d &", TMP_USB_RESTART, type?USB_OPEN:USB_CLOSE); |
| 37 | ret = system(cmd); |
| 38 | return ret; |
| 39 | } |