lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #define _GNU_SOURCE /**/ |
| 2 | |
| 3 | #include <string.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdarg.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <time.h> |
| 8 | #include <syslog.h> |
| 9 | #include <unistd.h> |
| 10 | #include <errno.h> |
| 11 | #include <signal.h> |
| 12 | #include <netdb.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <sys/socket.h> |
| 16 | #include <sys/time.h> |
| 17 | #include <sys/uio.h> |
| 18 | #include <sys/stat.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <sys/sysctl.h> |
| 21 | #include <net/if.h> |
| 22 | #include <poll.h> |
| 23 | #include <stddef.h> |
| 24 | #include <linux/if_packet.h> |
| 25 | #include <netinet/ether.h> |
| 26 | #include <netinet/if_ether.h> |
| 27 | #include <arpa/inet.h> |
| 28 | #include <pthread.h> |
| 29 | #include <zte_mdl.h> |
| 30 | |
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 31 | #define PROC_CMDLINE_NO_CONSOLE (0) |
| 32 | #define PROC_CMDLINE_CONSOLE (1) |
| 33 | #define STDOUT_BUFFER_SIZE (256) |
| 34 | #define STDOUT_PATH_DEVNULL "/dev/null" |
| 35 | |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 36 | void nvserver_entry(void) |
| 37 | { |
| 38 | nvserver_main(0,NULL); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | void at_ctl_entry(char *arg) |
| 43 | { |
| 44 | //printf("at_ctl_entry boot:%s\n", arg); |
| 45 | char *argv[2]; |
| 46 | argv[0] = NULL; |
| 47 | argv[1] = arg; |
| 48 | |
| 49 | at_ctl_main(2, argv); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | void rtc_service_entry(char *arg) |
| 54 | { |
| 55 | rtc_service_main(0,NULL); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | void zte_mainctrl_entry(char *arg) |
| 60 | { |
| 61 | zte_mainctrl_main(0,NULL); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | void zte_hotplug_entry(char *arg) |
| 66 | { |
| 67 | zte_hotplug_main(0,NULL); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | void zte_audio_res_ctrl_entry(char *arg) |
| 72 | { |
| 73 | zte_audio_res_ctrl_main(0,NULL); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | void zte_drv_serial_ctrl_entry(char *arg) |
| 78 | { |
| 79 | zte_drv_serial_ctrl_main(); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | void zte_drv_usb_ctrl_entry(char *arg) |
| 84 | { |
| 85 | zte_drv_usb_ctrl_main(0,NULL); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | void sntp_entry(char *arg) |
| 90 | { |
| 91 | sntp_main(0,NULL); |
| 92 | return; |
| 93 | } |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 94 | void wlan_entry(char *arg) |
| 95 | { |
you.chen | 94a5608 | 2024-06-20 21:22:25 +0800 | [diff] [blame] | 96 | #if (defined _USE_VEHICLE_DC_REF) //jb.qi add for wifi config on 20240301 |
| 97 | if (system("cat /sys/class/lynq_nv_cfg/cdev_lynq_nv_cfg/wifi_enable | grep 1") == 0) { |
| 98 | wlan_main(0,NULL); |
| 99 | } |
| 100 | else{ |
| 101 | printf("not need to start wifi\n"); |
| 102 | } |
jb.qi | 5532c6f | 2024-02-29 23:55:54 -0800 | [diff] [blame] | 103 | #endif |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 104 | return; |
| 105 | } |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 106 | void fota_dm_entry(char *arg) |
| 107 | { |
| 108 | fota_dm_main(0,NULL); |
| 109 | //return; //kw 3 |
| 110 | } |
| 111 | |
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 112 | void rediect_stdout(void) |
| 113 | { |
| 114 | int fd = 0; |
| 115 | FILE *file = NULL; |
| 116 | int console = PROC_CMDLINE_NO_CONSOLE; |
| 117 | char buffer[STDOUT_BUFFER_SIZE] = {0}; |
| 118 | |
| 119 | file = fopen("/proc/cmdline", "r"); |
| 120 | if (file == NULL) { |
| 121 | printf("rediect_stdout: cmdline file read error\n"); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | while (fgets(buffer, sizeof(buffer), file) != NULL) |
| 126 | { |
| 127 | if(strstr(buffer, "console")) |
| 128 | { |
| 129 | console = PROC_CMDLINE_CONSOLE; |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | if((console == PROC_CMDLINE_NO_CONSOLE) |
| 135 | && ((fd = open(STDOUT_PATH_DEVNULL, O_RDWR, 0)) > 0)) |
| 136 | { |
| 137 | (void)dup2(fd, STDIN_FILENO); |
| 138 | (void)dup2(fd, STDOUT_FILENO); |
| 139 | (void)dup2(fd, STDERR_FILENO); |
| 140 | |
| 141 | setvbuf(stdout, NULL, _IOLBF, 0); |
| 142 | if (fd > STDERR_FILENO) |
| 143 | (void)close(fd); |
| 144 | } |
| 145 | fclose(file); |
| 146 | } |
| 147 | |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 148 | int main(int argc, char *argv[]) |
| 149 | { |
| 150 | /* nvserver */ |
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 151 | pthread_t nvserver_thread_tid; |
| 152 | |
xf.li | be70461 | 2024-05-28 19:09:12 -0700 | [diff] [blame] | 153 | rediect_stdout(); |
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 154 | pthread_create(&nvserver_thread_tid, NULL, (void *)nvserver_entry, NULL); |
| 155 | |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 156 | /* zte_drv_serial_ctrl */ |
| 157 | pthread_t zte_drv_serial_ctrl_thread_tid; |
| 158 | pthread_create(&zte_drv_serial_ctrl_thread_tid, NULL, (void *)zte_drv_serial_ctrl_entry, NULL); |
| 159 | /* zte_drv_usb_ctrl */ |
| 160 | pthread_t zte_drv_usb_ctrl_thread_tid; |
| 161 | pthread_create(&zte_drv_usb_ctrl_thread_tid, NULL, (void *)zte_drv_usb_ctrl_entry, NULL); |
| 162 | |
| 163 | if (0 != strcmp(argv[2], "amt")) { //³äµç»òÕý³£¿ª»úģʽ |
| 164 | /* zte_hotplug */ |
| 165 | pthread_t zte_hotplug_thread_tid; |
| 166 | pthread_create(&zte_hotplug_thread_tid, NULL, (void *)zte_hotplug_entry, NULL); |
| 167 | |
| 168 | #if(PRODUCT_TYPE != PRODUCT_TH) |
| 169 | /* at_ctl */ |
| 170 | pthread_t at_ctl_thread_tid; |
| 171 | pthread_create(&at_ctl_thread_tid, NULL, (void *)at_ctl_entry, argv[1]); |
| 172 | /* rtc_service */ |
| 173 | pthread_t rtc_service_thread_tid; |
| 174 | pthread_create(&rtc_service_thread_tid, NULL, (void *)rtc_service_entry, NULL); |
| 175 | /* zte_mainctrl */ |
| 176 | pthread_t zte_mainctrl_thread_tid; |
| 177 | pthread_create(&zte_mainctrl_thread_tid, NULL, (void *)zte_mainctrl_entry, NULL); |
| 178 | #endif |
| 179 | |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 180 | #ifdef _USE_VEHICLE_DC_REF |
| 181 | /* wifi_manager */ |
| 182 | pthread_t wlan_thread_tid; |
| 183 | pthread_create(&wlan_thread_tid, NULL, (void *)wlan_entry, NULL); |
| 184 | #endif |
| 185 | |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 186 | /* zte_audio_res_ctrl */ |
| 187 | pthread_t zte_audio_res_ctrl_thread_tid; |
| 188 | pthread_create(&zte_audio_res_ctrl_thread_tid, NULL, (void *)zte_audio_res_ctrl_entry, NULL); |
| 189 | |
| 190 | /* sntp */ |
| 191 | //pthread_t sntp_thread_tid; |
| 192 | //pthread_create(&sntp_thread_tid, NULL, (void *)sntp_entry, NULL); |
| 193 | /* zte_fota */ |
| 194 | pthread_t fota_dm_thread_tid; |
| 195 | pthread_create(&fota_dm_thread_tid, NULL, (void *)fota_dm_entry, NULL); |
| 196 | |
| 197 | } |
| 198 | while(1) |
| 199 | { |
| 200 | sleep(20); |
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 201 | //printf("app test -1 \n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |