yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #include <sys/syscall.h> |
| 2 | #include <linux/reboot.h> |
| 3 | #include <openssl/aes.h> |
| 4 | |
| 5 | #include "rtc_timer.h" |
| 6 | #include "zte_mainctrl.h" |
| 7 | #include "libcpnv.h" |
| 8 | /************************************************************************** |
| 9 | * Global Variables * |
| 10 | **************************************************************************/ |
| 11 | |
| 12 | char ps_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 13 | char usb_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 14 | char eth_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 15 | char wifi_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 16 | |
| 17 | unsigned char ethwan_id = 0; //ÓÃÓÚRJ45ÍâÍø¿ÚµÄ³¬Ê±´¦Àí |
| 18 | unsigned char wifiwan_id = 0;//ÓÃÓÚwifiÍâÍø¿ÚµÄ³¬Ê±´¦Àí |
| 19 | |
| 20 | int g_limit_time_flag = 0; //ÓÃÓÚ¼Ò³¤Ä£Ê½ 1£º½ûÖ¹ÉÏÍøÊ±¼ä¶Î 0 £ºÔÊÐíÉÏÍøÊ±¼ä¶Î |
| 21 | |
| 22 | //¼Ç¼ÊÇ·ñÕýÔÚ»Ö¸´³ö³§ÉèÖ㬴˽׶β»½øÐÐcfg_saveµÈ²Ù×÷ |
| 23 | int g_mainctrl_factory_reset = 0; |
| 24 | int g_mainctrl_reset_ext_cmd = 0; |
| 25 | int g_mainctrl_poweroff_ext_cmd = 0; |
| 26 | int g_mainctrl_restart_ext_cmd = 0; |
| 27 | |
| 28 | struct list_head g_mainctrl_reset_notify; |
| 29 | struct list_head g_mainctrl_poweroff_notify; |
| 30 | struct list_head g_mainctrl_restart_notify; |
| 31 | |
| 32 | //Èç¹ûreset·¢Æð·½²»ÐèÒªÉ豸×öreboot£¬ÔòÖ÷¿ØÍê³Éresetºó·¢ËÍÏûÏ¢¸øËü£¬±¾Éí²»ÔÙ×öÈÎºÎÆäËû²Ù×÷ |
| 33 | static int g_restart_from = 0; |
| 34 | static int g_restart_subaction = Operate_By_SOC; |
| 35 | static int g_poweroff_from = 0; |
| 36 | |
| 37 | //¸øAT·¢pdp¼¤»îÏûÏ¢£¬Óöµ½ATµÚÒ»´Îû×öÍêµÚ¶þÌõÓÖÀ´ÁËAT»á¶ÏÑÔËÀ»ú |
| 38 | static int g_pdpact_reqing = 0;//·¢ËÍpdp¼¤»îÏûÏ¢ÇÒ»¹Î´ÊÕµ½»Ø¸´ |
| 39 | static int g_pdpdeact_reqing = 0;//·¢ËÍpdpÈ¥¼¤»îÏûÏ¢ÇÒ»¹Î´ÊÕµ½»Ø¸´ |
| 40 | int g_poweron_type = 0; |
| 41 | #define itoa(i,a,b) (((b) == 16) ? sprintf((a), "%x", (i)) : sprintf((a), "%d", (i))) |
| 42 | |
| 43 | //bsim |
| 44 | typedef struct |
| 45 | { |
| 46 | unsigned int pubKeyRsaE[32]; |
| 47 | unsigned int pubKeyRsaN[32]; |
| 48 | unsigned int secureFlag; |
| 49 | unsigned int pubKeyHash[4]; |
| 50 | unsigned int secureDevId[3]; |
| 51 | }T_ZDrvEfuse_Secure; |
| 52 | |
| 53 | #define EFUSE_IOC_MAGIC 'E' |
| 54 | #define EFUSE_GET_DATA _IOWR(EFUSE_IOC_MAGIC, 1, char *) |
| 55 | #define PPPOE_CODE_LEN 32 //webui limit 30 |
| 56 | |
| 57 | unsigned char pppoe_aes_key[16] = {0}; |
| 58 | |
| 59 | static int bs_string2bytes(const char* pSrc, unsigned char* pDst, int nSrcLength) |
| 60 | { |
| 61 | int i=0; |
| 62 | |
| 63 | //УÑé²ÎÊý |
| 64 | if(pSrc == NULL || pDst == NULL || nSrcLength < 0) |
| 65 | { |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | for(i = 0; i < nSrcLength; i += 2) |
| 70 | { |
| 71 | // Êä³ö¸ß4λ |
| 72 | if(*pSrc >= '0' && *pSrc <= '9') |
| 73 | { |
| 74 | *pDst = (*pSrc - '0') << 4; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | *pDst = ((toupper(*pSrc) - 'A') + 10) << 4; |
| 79 | } |
| 80 | |
| 81 | pSrc++; |
| 82 | |
| 83 | // Êä³öµÍ4λ |
| 84 | if(*pSrc >= '0' && *pSrc <= '9') |
| 85 | { |
| 86 | *pDst |= *pSrc - '0'; |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | *pDst |= (toupper(*pSrc) - 'A') + 10; |
| 91 | } |
| 92 | |
| 93 | pSrc++; |
| 94 | pDst++; |
| 95 | } |
| 96 | |
| 97 | // ·µ»ØÄ¿±êÊý¾Ý³¤¶È |
| 98 | return nSrcLength / 2; |
| 99 | } |
| 100 | |
| 101 | static int bs_bytes2string(const unsigned char* pSrc, char* pDst, int nSrcLength) |
| 102 | { |
| 103 | const char tab[]="0123456789ABCDEF"; // 0x0-0xfµÄ×Ö·û²éÕÒ±í |
| 104 | int i = 0; |
| 105 | |
| 106 | //УÑé²ÎÊý |
| 107 | if(pSrc == NULL || pDst == NULL || nSrcLength < 0) |
| 108 | { |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | for(i=0; i<nSrcLength; i++) |
| 113 | { |
| 114 | *pDst++ = tab[*pSrc >> 4]; // Êä³öµÍ4λ |
| 115 | *pDst++ = tab[*pSrc & 0x0f]; // Êä³ö¸ß4λ |
| 116 | pSrc++; |
| 117 | } |
| 118 | |
| 119 | // ·µ»ØÄ¿±ê×Ö·û´®³¤¶È |
| 120 | return nSrcLength * 2; |
| 121 | } |
| 122 | |
| 123 | static int bs_aes_init_key(unsigned char *aes_key, int k_len) |
| 124 | { |
| 125 | int efuse_fd = -1; |
| 126 | T_ZDrvEfuse_Secure efuse = {0}; |
| 127 | |
| 128 | memset(&efuse, 0, sizeof(efuse)); |
| 129 | efuse_fd = open("/dev/efuse", O_RDWR); |
| 130 | if (efuse_fd < 0) { |
| 131 | printf("wifi_aes_init_key efuse open errno=%d\n", errno); |
| 132 | return 0; |
| 133 | } |
| 134 | if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuse) != 0) { |
| 135 | printf("wifi_aes_init_key efuse ioctl errno=%d\n", errno); |
| 136 | close(efuse_fd); |
| 137 | return 0; |
| 138 | } |
| 139 | close(efuse_fd); |
| 140 | memcpy(aes_key, efuse.pubKeyHash, k_len); |
| 141 | |
| 142 | return 1; |
| 143 | } |
| 144 | |
| 145 | static int bs_aes_encrypt(char* in, int len, char* out, unsigned char* key, int key_len) |
| 146 | { |
| 147 | if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) { |
| 148 | printf("bs_aes_encrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len); |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | AES_KEY aes = {0}; //cov h |
| 153 | if (AES_set_encrypt_key(key, key_len*8, &aes) < 0) { |
| 154 | printf("bs_aes_encrypt AES_set_encrypt_key err\n"); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | int en_len = 0; |
| 159 | while (en_len < len) { |
| 160 | AES_encrypt((unsigned char*)in, (unsigned char*)out, &aes); |
| 161 | in += AES_BLOCK_SIZE; |
| 162 | out += AES_BLOCK_SIZE; |
| 163 | en_len += AES_BLOCK_SIZE; |
| 164 | } |
| 165 | |
| 166 | return 1; |
| 167 | } |
| 168 | |
| 169 | static int bs_aes_decrypt(char* in, int len, char* out, char* key, int key_len) |
| 170 | { |
| 171 | if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) { |
| 172 | printf("bs_aes_decrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len); |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | AES_KEY aes = {0}; //cov h |
| 177 | if (AES_set_decrypt_key((unsigned char*)key, key_len*8, &aes) < 0) { |
| 178 | printf("bs_aes_decrypt AES_set_decrypt_key err\n"); |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | int en_len = 0; |
| 183 | while (en_len < len) { |
| 184 | AES_decrypt((unsigned char*)in, (unsigned char*)out, &aes); |
| 185 | in += AES_BLOCK_SIZE; |
| 186 | out += AES_BLOCK_SIZE; |
| 187 | en_len += AES_BLOCK_SIZE; |
| 188 | } |
| 189 | |
| 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | int pppoe_encrypt_code(void) |
| 194 | { |
| 195 | char w_code[PPPOE_CODE_LEN + 1]= {0}; |
| 196 | char b_aes[PPPOE_CODE_LEN + 1] = {0}; |
| 197 | char s_aes[PPPOE_CODE_LEN*2 + 1] = {0}; |
| 198 | |
| 199 | cfg_get_item("pppoe_cc", w_code, sizeof(w_code)); |
| 200 | bs_aes_encrypt(w_code, PPPOE_CODE_LEN, b_aes, pppoe_aes_key, sizeof(pppoe_aes_key)); |
| 201 | bs_bytes2string(b_aes, s_aes, PPPOE_CODE_LEN); |
| 202 | cfg_set("pppoe_password", s_aes); |
| 203 | printf("encrypt pppoe_cc w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 204 | |
| 205 | return 1; |
| 206 | } |
| 207 | //2±íʾfota´ÓÀϰ汾ÍùÉÏÉý¼¶£¬pppoe_password´æµÄÊÇÃ÷ÎÄÃÜÂ룬а汾ÊÇÃÜÎÄ |
| 208 | int pppoe_decrypt_code(void) |
| 209 | { |
| 210 | char w_code[PPPOE_CODE_LEN + 1]= {0}; |
| 211 | char b_aes[PPPOE_CODE_LEN + 1] = {0}; |
| 212 | char s_aes[PPPOE_CODE_LEN*2 + 1] = {0}; |
| 213 | int flag = 0; |
| 214 | |
| 215 | cfg_get_item("pppoe_password", s_aes, sizeof(s_aes)); |
| 216 | if (strlen(s_aes) == PPPOE_CODE_LEN*2) { |
| 217 | bs_string2bytes(s_aes, b_aes, PPPOE_CODE_LEN*2); |
| 218 | bs_aes_decrypt(b_aes, PPPOE_CODE_LEN, w_code, pppoe_aes_key, sizeof(pppoe_aes_key)); |
| 219 | cfg_set("pppoe_cc", w_code); |
| 220 | // printf("decrypt pppoe_cc w_code=%s, s_aes=%s\n", w_code, s_aes); |
| 221 | } else if (strlen(s_aes) > 0){ |
| 222 | cfg_set("pppoe_cc", s_aes); |
| 223 | return 2; |
| 224 | } |
| 225 | |
| 226 | return 1; |
| 227 | } |
| 228 | |
| 229 | int pppoe_aes_init(void) |
| 230 | { |
| 231 | bs_aes_init_key(pppoe_aes_key, sizeof(pppoe_aes_key)); |
| 232 | if (2 == pppoe_decrypt_code()) |
| 233 | pppoe_encrypt_code(); |
| 234 | |
| 235 | return 1; |
| 236 | } |
| 237 | |
| 238 | /* ¼Ç¼restartÀàÐÍ£¬¼Í¼ÇëÇóÊÇ·ñÀ´×ÔÀ©Õ¹AT ÒÔ¼°ÊÇ·ñÓÉÖ÷¿ØÍê³ÉREBOOT */ |
| 239 | void record_restart_type(MSG_BUF *msg) |
| 240 | { |
| 241 | restart_info *msgData = NULL; |
| 242 | |
| 243 | //À´×ÔÀ©Õ¹ATºóÃæÐèÒª¸øAT·µ»ØÏûÏ¢£¬subActionΪRestart_By_MCUµÄ²»ÐèÒªÖ÷¿Øreboot |
| 244 | if (msg->usMsgCmd == MSG_CMD_RESET_REQUEST || msg->usMsgCmd == MSG_CMD_RESTART_REQUEST) { |
| 245 | if (msg->src_id == MODULE_ID_AT_CTL) { //À´×ÔÀ©Õ¹AT |
| 246 | g_restart_from = msg->src_id; |
| 247 | } else { |
| 248 | g_restart_from = 0; |
| 249 | } |
| 250 | |
| 251 | if (msg->usDataLen > 0) { |
| 252 | msgData = (restart_info*)msg->aucDataBuf; |
| 253 | if (msgData->subaction == Operate_By_MCU) { |
| 254 | g_restart_subaction = Operate_By_MCU; |
| 255 | } else { |
| 256 | g_restart_subaction = Operate_By_SOC; |
| 257 | } |
| 258 | } else { |
| 259 | g_restart_subaction = Operate_By_SOC; |
| 260 | } |
| 261 | } |
| 262 | slog(NET_PRINT, SLOG_NORMAL, "record_restart_type = %d--%d\n", g_restart_from, g_restart_subaction); |
| 263 | |
| 264 | } |
| 265 | |
| 266 | void record_poweroff_type(MSG_BUF *msg) |
| 267 | { |
| 268 | slog(NET_PRINT, SLOG_NORMAL, "record_poweroff_type msg->src_id = 0x%x, msg->usMsgCmd = 0x%x\n", msg->src_id, msg->usMsgCmd); |
| 269 | |
| 270 | //²»ÐèÒªÖ÷¿Øreboot |
| 271 | if (msg->src_id == MODULE_ID_AT_CTL && msg->usMsgCmd == MSG_CMD_POWEROFF_REQUEST) //À´×ÔÀ©Õ¹AT |
| 272 | g_poweroff_from = msg->src_id; |
| 273 | else |
| 274 | g_poweroff_from = 0; |
| 275 | slog(NET_PRINT, SLOG_NORMAL, "record_poweroff_type = 0x%x\n", g_poweroff_from); |
| 276 | } |
| 277 | |
| 278 | /********************************************************************************** |
| 279 | º¯Êý×÷ÓÃ:µÃµ½ÊÇ·ñÊÇÓÐÏß¿í´øÄ£Ê½:1:ÊÇ;0:·ñ |
| 280 | ***********************************************************************************/ |
| 281 | static int get_wan_mode() |
| 282 | { |
| 283 | char blc_wan_mode[16] = {0}; |
| 284 | char blc_wan_auto_mode[16] = {0}; |
| 285 | |
| 286 | cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode)); |
| 287 | cfg_get_item("blc_wan_auto_mode", blc_wan_auto_mode, sizeof(blc_wan_auto_mode)); |
| 288 | if (strcmp("PPP", blc_wan_mode) == 0 || (strcmp("AUTO", blc_wan_mode) == 0 && strcmp("AUTO_PPP", blc_wan_auto_mode) == 0)) { |
| 289 | slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, blc_wan_auto_mode=%s, now is auto or PPP mode\n", blc_wan_mode, blc_wan_auto_mode); |
| 290 | return 0; |
| 291 | } else { |
| 292 | slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, blc_wan_auto_mode=%s, now is not auto or PPP mode \n", blc_wan_mode, blc_wan_auto_mode); |
| 293 | return 1; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | |
| 298 | void set_wan_auto_mode(char * mode) |
| 299 | { |
| 300 | char blc_wan_mode[16] = {0}; |
| 301 | |
| 302 | cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode)); |
| 303 | |
| 304 | if (strcmp(blc_wan_mode, "AUTO") == 0) { |
| 305 | cfg_set("blc_wan_auto_mode", mode); |
| 306 | slog(NET_PRINT, SLOG_NORMAL, "blc_set_wan_mode: mode = %s\n", mode); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | |
| 311 | /********************************************************************************** |
| 312 | º¯Êý×÷ÓÃ:µÃµ½ÆÕͨģʽ-wifistation ¿ª¹ØµÄÉèÖÃ:1:wifistation¿ªÆô;0:¹Ø±Õ |
| 313 | ***********************************************************************************/ |
| 314 | static int get_wifiwan_onoff() |
| 315 | { |
| 316 | int result = -1; |
| 317 | char nv_wifiap_state[32] = {0}; |
| 318 | char wifi_cur_state[8] = {0}; |
| 319 | |
| 320 | cfg_get_item("wifi_cur_state", wifi_cur_state, sizeof(wifi_cur_state)); |
| 321 | cfg_get_item("wifi_sta_connection", nv_wifiap_state, sizeof(nv_wifiap_state)); |
| 322 | slog(NET_PRINT, SLOG_NORMAL, "get_wifiwan_onoff wifi_cur_state:%s,nv_wifiap_state:%s\n", wifi_cur_state, nv_wifiap_state); |
| 323 | if (!strcmp(nv_wifiap_state, "1") && !strcmp(wifi_cur_state, "1")) { //£±´ú±íwifistation ÆôÓà |
| 324 | result = 1; |
| 325 | } else { |
| 326 | result = 0; |
| 327 | } |
| 328 | |
| 329 | slog(NET_PRINT, SLOG_DEBUG, "get_wifiwan_onoff result:%d\n", result); |
| 330 | return result; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /********************************************************************************** |
| 335 | º¯Êý×÷ÓÃ:µÃµ½ÆÕͨģʽ-wifistation ÓÅÏȵÄÉèÖÃ:1:wifistationÓÅÏÈ;0:modem ÓÅÏÈ |
| 336 | ***********************************************************************************/ |
| 337 | static int get_wifiwan_pre() |
| 338 | { |
| 339 | int result = 0; |
| 340 | char nv_wifi_state[32] = {0}; |
| 341 | char ps_wan_pri[32] = {0}; |
| 342 | char wifi_wan_pri[32] = {0}; |
| 343 | int ps_pri = 0; |
| 344 | int wifi_pri = 0; |
| 345 | |
| 346 | cfg_get_item("wifi_sta_connection", nv_wifi_state, sizeof(nv_wifi_state)); |
| 347 | cfg_get_item("pswan_priority", ps_wan_pri, sizeof(ps_wan_pri)); |
| 348 | cfg_get_item("wifiwan_priority", wifi_wan_pri, sizeof(wifi_wan_pri)); |
| 349 | |
| 350 | ps_pri = atoi(ps_wan_pri); |
| 351 | wifi_pri = atoi(wifi_wan_pri); |
| 352 | |
| 353 | if (!strcmp(nv_wifi_state, "1")) { //£±´ú±íwifistation ÆôÓà |
| 354 | if (wifi_pri > ps_pri) { |
| 355 | result = 1; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | slog(NET_PRINT, SLOG_NORMAL, "get_wifiwan_pre result:%d\n", result); |
| 360 | return result; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | /********************************************************************************** |
| 365 | º¯Êý×÷ÓÃ:ÆÕͨģʽ-wifistation ¹Ø±ÕÁ¬½Ó |
| 366 | ***********************************************************************************/ |
| 367 | static int close_wifiwan_access() |
| 368 | { |
| 369 | int ret = 0; |
| 370 | |
| 371 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_BLC_CLOSE_WIFISTATION_ACCESS, 0, NULL, 0); |
| 372 | if (0 != ret) { |
| 373 | return -1; |
| 374 | } |
| 375 | |
| 376 | slog(NET_PRINT, SLOG_NORMAL, "close_wifiwan_access request ok!\n"); |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | /********************************************************************************** |
| 382 | º¯Êý×÷ÓÃ:ÆÕͨģʽ-wifistation ÆôÓÃÁ¬½Ó |
| 383 | ***********************************************************************************/ |
| 384 | static int open_wifiwan_access() |
| 385 | { |
| 386 | char blc_wan_mode[16] = {0}; |
| 387 | char blc_wan_auto_mode[16] = {0}; |
| 388 | int ret = 0; |
| 389 | |
| 390 | cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode)); |
| 391 | cfg_get_item("blc_wan_auto_mode", blc_wan_auto_mode, sizeof(blc_wan_auto_mode)); |
| 392 | |
| 393 | /*ÈôÉèÖÃΪÎÞÏß½ÓÈ룬Ôò´ò¿ªwifi*/ |
| 394 | if (strcmp("PPP", blc_wan_mode) == 0 || (strcmp("AUTO", blc_wan_mode) == 0 && strcmp("AUTO_PPP", blc_wan_auto_mode) == 0)) { |
| 395 | slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, can open WifiStation\n", blc_wan_mode); |
| 396 | |
| 397 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_BLC_OPEN_WIFISTATION_ACCESS, 0, NULL, 0); |
| 398 | if (0 != ret) { |
| 399 | return -1; |
| 400 | } |
| 401 | |
| 402 | slog(NET_PRINT, SLOG_NORMAL, "open wifiwan request ok!\n"); |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | slog(NET_PRINT, SLOG_ERR, "blc_wan_mode=%s, can not open WifiStation\n", blc_wan_mode); |
| 407 | return -1; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | /********************************************************************************** |
| 412 | º¯Êý×÷ÓÃ:·¢ËÍÆÕͨģʽ-Modem ¹Ø±ÕÁ¬½ÓµÄÖ¸Áî |
| 413 | ***********************************************************************************/ |
| 414 | static int close_pswan_access() |
| 415 | { |
| 416 | int ret = 0; |
| 417 | if(g_pdpdeact_reqing != 0){ |
| 418 | slog(NET_PRINT, SLOG_ERR, "last close pswan request without rsp!\n"); |
| 419 | return -1; |
| 420 | } |
| 421 | cfg_set("user_blc_disconnect", "1"); //Ö÷¿ØÖ÷¶¯¶Ï¿ªÁ¬½Ó |
| 422 | |
| 423 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, MSG_CMD_PDP_DEACT_REQ, 0, NULL, 0); |
| 424 | if (0 != ret) { |
| 425 | return -1; |
| 426 | } |
| 427 | g_pdpdeact_reqing = 1; |
| 428 | slog(NET_PRINT, SLOG_NORMAL, "close pswan request ok!\n"); |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | /********************************************************************************** |
| 434 | º¯Êý×÷ÓÃ:·¢ËÍÆÕͨģʽ-Modem ÆôÓÃÁ¬½ÓµÄÖ¸Áî |
| 435 | ***********************************************************************************/ |
| 436 | static int open_pswan_access() |
| 437 | { |
| 438 | char needInit[10] = {0}; |
| 439 | char blc_wan_mode[16] = {0}; |
| 440 | char blc_wan_auto_mode[16] = {0}; |
| 441 | char dial_mode [20] = {0}; |
| 442 | char user_initiate_disconnect[20] = {0}; |
| 443 | char sta_ip_status[30] = {0}; |
| 444 | char work_state[30] = {0}; |
| 445 | |
| 446 | int ret = 0; |
| 447 | |
| 448 | if(g_pdpact_reqing != 0){ |
| 449 | slog(NET_PRINT, SLOG_ERR, "last open_modem request without rsq!\n"); |
| 450 | return -1; |
| 451 | } |
| 452 | |
| 453 | cfg_get_item ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status)); |
| 454 | if (0 == strcmp(sta_ip_status, "connect")) |
| 455 | { |
| 456 | slog(NET_PRINT, SLOG_ERR, "ap station have connected, can not open modem\n"); |
| 457 | return -1; |
| 458 | } |
| 459 | |
| 460 | cfg_get_item("rj45_state", work_state, sizeof(work_state)); |
| 461 | if (0 == strcmp(work_state, "connect")) |
| 462 | { |
| 463 | slog(NET_PRINT, SLOG_ERR, "rj45 have connected, can not open modem\n"); |
| 464 | return -1; |
| 465 | } |
| 466 | |
| 467 | cfg_get_item("need_init_modem", needInit, sizeof(needInit)); |
| 468 | if (0 != strcmp(needInit, "yes")) |
| 469 | return -1; |
| 470 | |
| 471 | cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode)); |
| 472 | cfg_get_item("blc_wan_auto_mode", blc_wan_auto_mode, sizeof(blc_wan_auto_mode)); |
| 473 | cfg_get_item("user_initiate_disconnect", user_initiate_disconnect, sizeof(user_initiate_disconnect)); |
| 474 | cfg_get_item("dial_mode", dial_mode, sizeof(dial_mode)); |
| 475 | |
| 476 | if (0 == strcmp(user_initiate_disconnect, "1")) |
| 477 | return -1; |
| 478 | |
| 479 | if (0 == strcmp("auto_dial", dial_mode) && (strcmp("PPP", blc_wan_mode) == 0 || (strcmp("AUTO", blc_wan_mode) == 0 && strcmp("AUTO_PPP", blc_wan_auto_mode) == 0))) { |
| 480 | slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, can open modem\n", blc_wan_mode); |
| 481 | |
| 482 | cfg_set("user_blc_disconnect", "0"); //Ö÷¿ØÍ˳öÖ÷¶¯¶Ï¿ªÁ¬½Ó |
| 483 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, 0); |
| 484 | if (0 != ret) { |
| 485 | return -1; |
| 486 | } |
| 487 | g_pdpact_reqing = 1; |
| 488 | |
| 489 | slog(NET_PRINT, SLOG_NORMAL, "open_modem request ok!\n"); |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | slog(NET_PRINT, SLOG_ERR, "blc_wan_mode=%s, can not open modem\n", blc_wan_mode); |
| 494 | return -1; |
| 495 | } |
| 496 | |
| 497 | static void set_modem_off() |
| 498 | { |
| 499 | #if (PRODUCT_TYPE == PRODUCT_PHONE)//¹¦ÄÜ»úÊÇcp×öÍêËùÓвÙ×÷ºóÔÙ֪ͨAP,ËùÒÔ²»ÐèÒª |
| 500 | return; |
| 501 | #else //cov m |
| 502 | if(g_poweron_type == 2){//¹Ø»ú³äµçmodem²»ÔÚ²»·¢at+cfun=0 |
| 503 | return; |
| 504 | } |
| 505 | int ret = get_modem_info("at+cfun=0\r\n", NULL, NULL); |
| 506 | if(ret){ |
| 507 | slog(NET_PRINT, SLOG_ERR, "at+cfun=0 err =%d, can not close modem\n", ret); |
| 508 | } |
| 509 | #endif |
| 510 | } |
| 511 | |
| 512 | static int pdp_auto_dial() |
| 513 | { |
| 514 | int ret; |
| 515 | |
| 516 | char needInit[10] = {0};//ÅжÏÊÇ·ñÖ§³Ömodem¿ª»ú³õʼ»¯ |
| 517 | char pppStatus [20] = {0}; |
| 518 | char blc_wan_mode[20] = {0}; |
| 519 | char blc_wan_auto_mode[20] = {0}; |
| 520 | char user_initiate_disconnect[20] = {0}; |
| 521 | char user_blc_disconnect[20] = {0}; |
| 522 | char dial_mode [20] = {0}; |
| 523 | |
| 524 | cfg_get_item("need_init_modem", needInit, sizeof(needInit)); |
| 525 | cfg_get_item(NV_BLC_WAN_MODE, blc_wan_mode, sizeof(blc_wan_mode)); |
| 526 | cfg_get_item(NV_BLC_WAN_AUTO_MODE, blc_wan_auto_mode, sizeof(blc_wan_auto_mode)); |
| 527 | cfg_get_item(NV_DIAL_MODE, dial_mode, sizeof(dial_mode)); |
| 528 | cfg_get_item("user_initiate_disconnect", user_initiate_disconnect, sizeof(user_initiate_disconnect)); |
| 529 | cfg_get_item("user_blc_disconnect", user_blc_disconnect, sizeof(user_blc_disconnect)); |
| 530 | |
| 531 | if (0 != strcmp(needInit, "yes")) { |
| 532 | return -1; |
| 533 | } |
| 534 | |
| 535 | if (0 != strcmp("PPP", blc_wan_mode) && 0 != strcmp("AUTO", blc_wan_mode)) { |
| 536 | return -1; |
| 537 | } |
| 538 | |
| 539 | if (0 != strcmp("auto_dial", dial_mode)) { |
| 540 | return -1; |
| 541 | } |
| 542 | |
| 543 | if (0 == strcmp(user_initiate_disconnect, "1") || 0 == strcmp(user_blc_disconnect, "1")) { |
| 544 | return -1; |
| 545 | } |
| 546 | |
| 547 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, 0); |
| 548 | if (0 != ret) { |
| 549 | slog(NET_PRINT, SLOG_ERR, "pdp_auto_dial err!\n"); |
| 550 | } |
| 551 | g_pdpact_reqing = 1; |
| 552 | |
| 553 | slog(NET_PRINT, SLOG_NORMAL, "pdp_auto_dial ok!\n"); |
| 554 | return ret; |
| 555 | |
| 556 | } |
| 557 | |
| 558 | |
| 559 | /********************************************************************************** |
| 560 | º¯Êý×÷ÓÃ:ĬÈÏÍâÍø¿Ú´¦Àí |
| 561 | ***********************************************************************************/ |
| 562 | void net_default_wan_proc(struct default_dev_info *dev) |
| 563 | { |
| 564 | char dev_coexist[32] = {0}; |
| 565 | char modem_wan_pri[32] = {0}; |
| 566 | char wifi_wan_pri[32] = {0}; |
| 567 | char rj45_wan_pri[32] = {0}; |
| 568 | int modem_pri = 0; |
| 569 | int wifi_pri = 0; |
| 570 | int rj45_pri = 0; |
| 571 | |
| 572 | slog(NET_PRINT, SLOG_NORMAL, "net_default_wan_proc dev_id:%d \n", dev->dev_id); |
| 573 | |
| 574 | cfg_get_item("netdev_coexist", dev_coexist, sizeof(dev_coexist)); |
| 575 | |
| 576 | /*ÍâÍø¿Ú¹²´æ*/ |
| 577 | if (0 == strcmp(dev_coexist, "1")) { |
| 578 | /*ÔÚÍø¿Ú¼¤»îʱ£¬wan_ipv4.sh»áΪ¼¤»îÍâÍø¿ÚÅäÖÃÒ»ÌõĬÈÏ·ÓÉ£¬ÔÚ¶àÍâÍø¿Ú¹²´æÊ±£¬ |
| 579 | ĬÈÏ·ÓÉÊÇ·ñÓ¦¸ÃÒÔĬÈÏÍâÍø¿Ú·ÓÉ×÷Ϊʵ¼ÊĬÈÏ·ÓÉ??? |
| 580 | */ |
| 581 | slog(NET_PRINT, SLOG_NORMAL, "net device coexist!\n"); |
| 582 | if (dev->dev_id == RJ45_WAN_DEV || dev->dev_id == SW_WAN_DEV) { |
| 583 | |
| 584 | slog(NET_PRINT, SLOG_DEBUG, "Now rj45 is open!\n"); |
| 585 | |
| 586 | } else if (dev->dev_id == WIFI_WAN_DEV) { |
| 587 | int ret = -1; |
| 588 | slog(NET_PRINT, SLOG_DEBUG, "Now wifi station is open.\n"); |
| 589 | |
| 590 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_BLC_CONNECTED, 0, NULL, 0); |
| 591 | if (0 != ret) { |
| 592 | softap_assert("send msg to wlan_server error"); |
| 593 | return; |
| 594 | } |
| 595 | } else if (dev->dev_id == PS_NET_DEV) { |
| 596 | slog(NET_PRINT, SLOG_DEBUG, "Now ps is open\n"); |
| 597 | } else if (dev->dev_id == NO_DEV) { |
| 598 | if (get_wifiwan_onoff()) { |
| 599 | open_wifiwan_access(); |
| 600 | } |
| 601 | open_pswan_access(); |
| 602 | } else |
| 603 | slog(NET_PRINT, SLOG_ERR, "dev_id:%d is unknow!!!\n", dev->dev_id); |
| 604 | } else { |
| 605 | cfg_get_item("pswan_priority", modem_wan_pri, sizeof(modem_wan_pri)); |
| 606 | cfg_get_item("wifiwan_priority", wifi_wan_pri, sizeof(wifi_wan_pri)); |
| 607 | cfg_get_item("ethwan_priority", rj45_wan_pri, sizeof(rj45_wan_pri)); |
| 608 | modem_pri = atoi(modem_wan_pri); |
| 609 | wifi_pri = atoi(wifi_wan_pri); |
| 610 | rj45_pri = atoi(rj45_wan_pri); |
| 611 | |
| 612 | if (dev->dev_id == RJ45_WAN_DEV || dev->dev_id == SW_WAN_DEV) { |
| 613 | slog(NET_PRINT, SLOG_DEBUG, "Now wan is rj45, need close modem or wifi\n"); |
| 614 | //¹Ø±ÕÆäËüÍøÂç |
| 615 | if (rj45_pri > modem_pri) { |
| 616 | close_pswan_access(); |
| 617 | } |
| 618 | if (rj45_pri > wifi_pri) { |
| 619 | if (get_wifiwan_onoff()) { |
| 620 | close_wifiwan_access(); |
| 621 | } |
| 622 | } |
| 623 | } else if (dev->dev_id == WIFI_WAN_DEV) { |
| 624 | |
| 625 | int ret = -1; |
| 626 | slog(NET_PRINT, SLOG_DEBUG, "Now wan is wifi station.\n"); |
| 627 | |
| 628 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_BLC_CONNECTED, 0, NULL, 0); |
| 629 | if (0 != ret) { |
| 630 | softap_assert("send msg to wlan_server error"); |
| 631 | return; |
| 632 | } |
| 633 | |
| 634 | if (wifi_pri > rj45_pri) { // ÔÝʱû¹Ø±Õrj45µÄ³¡¾° |
| 635 | int result = -1; |
| 636 | } |
| 637 | if (wifi_pri > modem_pri) { |
| 638 | close_pswan_access(); |
| 639 | } |
| 640 | |
| 641 | |
| 642 | } else if (dev->dev_id == PS_NET_DEV) { |
| 643 | slog(NET_PRINT, SLOG_DEBUG, "Now wan is ps\n"); |
| 644 | if (modem_pri > rj45_pri) { // ÔÝʱû¹Ø±Õrj45µÄ³¡¾° |
| 645 | int result = -1; |
| 646 | } else if (modem_pri > wifi_pri) { |
| 647 | if (get_wifiwan_onoff()) { |
| 648 | close_wifiwan_access(); |
| 649 | } |
| 650 | } |
| 651 | } else if (dev->dev_id == NO_DEV) { |
| 652 | slog(NET_PRINT, SLOG_NORMAL, "Now wan is None, need open ps or wifi\n"); |
| 653 | if (get_wifiwan_onoff()) { |
| 654 | open_wifiwan_access(); |
| 655 | } |
| 656 | open_pswan_access(); |
| 657 | } else |
| 658 | slog(NET_PRINT, SLOG_ERR, "dev_id:%d is unknow!!!\n", dev->dev_id); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | |
| 663 | |
| 664 | /********************************************************************************** |
| 665 | º¯Êý×÷ÓÃ:»Ö¸´³ö³§ÉèÖòÎÊýÅäÖà |
| 666 | ***********************************************************************************/ |
| 667 | //·¢ËÍÏûÏ¢¸øÄ£¿é£¬ÐèÒª´ËÄ£¿é½øÐлظ´ |
| 668 | void notify_list_add(struct list_head *head, int dst_id) |
| 669 | { |
| 670 | struct mainctrl_notify_queue *tmp = NULL, *notify = NULL; |
| 671 | |
| 672 | slog(NET_PRINT, SLOG_DEBUG, "notify_list_add start, id:0x%x!!!\n", dst_id); |
| 673 | |
| 674 | list_for_each_entry(tmp, head, list) { |
| 675 | //·¢Ë͸øtarget_idÄ£¿éµÄÏûÏ¢ÒѾ¼Ç¼¹ý |
| 676 | if (tmp->notify_id == dst_id) { |
| 677 | slog(NET_PRINT, SLOG_ERR, "notify_list_add dst_id:0x%x alread existed! \n", dst_id); |
| 678 | return; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | notify = malloc(sizeof(struct mainctrl_notify_queue)); |
| 683 | if (notify == NULL) { |
| 684 | slog(NET_PRINT, SLOG_ERR, "notify_list_add id:0x%x malloc failed! \n", dst_id); |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | INIT_LIST_HEAD(¬ify->list); |
| 689 | notify->notify_id = dst_id; |
| 690 | list_add_tail(¬ify->list, head); |
| 691 | |
| 692 | slog(NET_PRINT, SLOG_NORMAL, "notify_list_add id:0x%x success !!!\n", dst_id); |
| 693 | } |
| 694 | |
| 695 | //·¢ËÍÏûÏ¢¸øÄ£¿é£¬ÐèÒª´ËÄ£¿é½øÐлظ´ |
| 696 | void notify_list_del(struct list_head *head, int id) |
| 697 | { |
| 698 | struct mainctrl_notify_queue *tmp = NULL, *notify = NULL; |
| 699 | |
| 700 | slog(NET_PRINT, SLOG_DEBUG, "notify_list_del start, id:0x%x!!!\n", id); |
| 701 | |
| 702 | list_for_each_entry(tmp, head, list) { |
| 703 | if (tmp->notify_id == id) { |
| 704 | slog(NET_PRINT, SLOG_NORMAL, "notify_list_del id = 0x%x\n", id); |
| 705 | list_del(&tmp->list); |
| 706 | free(tmp); |
| 707 | break; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | slog(NET_PRINT, SLOG_DEBUG, "notify_list_del success !!!\n"); |
| 712 | } |
| 713 | |
| 714 | static void reset_factory_configure() |
| 715 | { |
| 716 | char port_mode[16] = {0}; |
| 717 | char time_to_2000[16] = {0}; |
| 718 | char path_log[32] = {0}; |
| 719 | char cmd[128] = {0}; |
| 720 | int ret = -1; |
| 721 | |
| 722 | cfg_get_item("port_stat", port_mode, 16); |
| 723 | if (strcmp(port_mode, "port_open") == 0) { |
| 724 | system("killall -9 monitor"); |
| 725 | } |
| 726 | // system("rm -rf /etc_rw/config/sms_db/sms.db"); ÓÉATµ÷Ó㬲»ÔÙ´¦Àí |
| 727 | // system("rm -rf /etc_rw/config/pbm.db");ÓÉATµ÷Ó㬲»ÔÙ´¦Àí |
| 728 | |
| 729 | // Óû§fotaÅäÖÃÊý¾Ý»Ö¸´³ö³§ÉèÖà |
| 730 | system("rm -rf /usr/dm/config.ini"); |
| 731 | system("rm -rf /usr/dm/zteconfig/userseting_nvconfig.txt"); |
| 732 | |
| 733 | cfg_get_item("time_to_2000_when_restore", time_to_2000, 16); |
| 734 | if (strcmp(time_to_2000, "yes") == 0) { |
| 735 | system("rm -rf /etc_rw/TZ"); |
| 736 | system("date -s \"2000-01-01 00:00:00\""); |
| 737 | system("zte-rtc-clock"); |
| 738 | } |
| 739 | |
| 740 | //ÍøÂç×é½Ó¿Ú |
| 741 | tcpip_reset_configure(); |
| 742 | |
| 743 | //add by diaolifang begin »Ö¸´³ö³§ÉèÖÃʱɾ³ýlogÎļþ |
| 744 | system("killall -9 syslogd"); |
| 745 | cfg_get_item("path_log", path_log, sizeof(path_log)); |
| 746 | sprintf(cmd, "/bin/rm -rf %s*.*", path_log); |
| 747 | zxic_system(cmd);//kw 3 |
| 748 | //add by diaolifang end |
| 749 | |
| 750 | cfg_reset(); |
| 751 | ret = cpnv_ResetNVFactory(); |
| 752 | slog(NET_PRINT, SLOG_NORMAL, "cpnv_ResetNVFactory ret=%d.\n",ret); |
| 753 | |
| 754 | slog(NET_PRINT, SLOG_NORMAL, "reset_factory_configure !\n"); |
| 755 | } |
| 756 | |
| 757 | /*¹Ø»ú³äµç*/ |
| 758 | static void poweroff_charging_process() |
| 759 | { |
| 760 | char reboot_cmd[20] = {0}; |
| 761 | |
| 762 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_charging_process start!!!\n"); |
| 763 | |
| 764 | sprintf(reboot_cmd, "mmi_key reboot"); |
| 765 | syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_cmd); |
| 766 | |
| 767 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_charging_process success!!!\n"); |
| 768 | } |
| 769 | /* RTCÖØÆô¹Ø»úģʽ*/ |
| 770 | static VOID poweroff_clock_process(void) |
| 771 | { |
| 772 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_clock_process start!!!\n"); |
| 773 | char reboot_cmd[20] = {0}; |
| 774 | sprintf(reboot_cmd, "mmi_rtc reboot"); |
| 775 | syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_cmd); |
| 776 | } |
| 777 | //mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù |
| 778 | static int execute_ext_cmd(int cmd) |
| 779 | { |
| 780 | //if (cmd <= Ext_Cmd_Base || cmd >= Ext_Cmd_MAX) |
| 781 | // return 0; |
| 782 | |
| 783 | if (cmd == Ext_Cmd_REBOOT || cmd == Ext_Cmd_POWEROFF) |
| 784 | system("app_monitor.sh off"); |
| 785 | |
| 786 | if (cmd == Ext_Cmd_REBOOT) |
| 787 | system("reboot"); |
| 788 | else if (cmd == Ext_Cmd_POWEROFF) |
| 789 | system("poweroff"); |
| 790 | else if (cmd == Ext_Cmd_POWEROFF_CHARGING) |
| 791 | poweroff_charging_process(); |
| 792 | else if (cmd == Ext_Cmd_POWEROFF_FAKE) { |
| 793 | set_wake_unlock(MAINCTRL_LOCK); |
| 794 | cfg_set("doingPowerOff", "0"); |
| 795 | slog(NET_PRINT, SLOG_NORMAL, "execute_ext_cmd Ext_Cmd_POWEROFF_FAKE!!!\n"); |
| 796 | } else if (cmd == Ext_Cmd_POWEROFF_CLOCK) { |
| 797 | slog(NET_PRINT, SLOG_NORMAL, "execute_ext_cmd Ext_Cmd_POWEROFF_CLOCK!!!\n"); |
| 798 | poweroff_clock_process(); |
| 799 | } else { |
| 800 | return 0; //kw 3 |
| 801 | } |
| 802 | return 1; |
| 803 | } |
| 804 | |
| 805 | /*´¦ÀíÆäËûÄ£¿éÀ´µÄRESET_RSPÏûÏ¢£¬ÖØÖÃÆäÓàÄÚÈÝ*/ |
| 806 | void reset_rsp_process(MSG_BUF *msg) |
| 807 | { |
| 808 | int id; |
| 809 | struct mainctrl_notify_queue *temp = NULL; |
| 810 | |
| 811 | slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process start!!!\n"); |
| 812 | |
| 813 | if (msg) { |
| 814 | id = msg->src_id; |
| 815 | slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process id = %x!!!\n", id); |
| 816 | //MMIÒò¿ìËÙ¿ª¹Ø»úµÄ´æÔÚ£¬×îÖÕ´¦ÀíµÄÃüÁîÓëÉèÖûáÓÐËù²»Í¬ |
| 817 | if (msg->src_id == MODULE_ID_MMI && msg->usDataLen > 0) { |
| 818 | struct ext_msg_data *ext_data = (struct ext_msg_data *) msg->aucDataBuf; |
| 819 | g_mainctrl_reset_ext_cmd = ext_data->cmd; |
| 820 | } |
| 821 | notify_list_del(&g_mainctrl_reset_notify, id); |
| 822 | } |
| 823 | |
| 824 | //֪ͨresetµÄÄ£¿é¶¼´¦Àí²¢»Ø¸´ºóÔÙ½øÐÐÖ÷¿ØµÄ»Ö¸´³ö³§ÉèÖò¢ÖØÆô |
| 825 | if (list_empty(&g_mainctrl_reset_notify)) { |
| 826 | system("app_monitor.sh off");//±ØÐëÔÚreset NV ֮ǰ |
| 827 | slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process success, ext_cmd:%d, from:0x%x subaction:%d!!!\n", g_mainctrl_reset_ext_cmd, g_restart_from, g_restart_subaction); |
| 828 | reset_factory_configure();//µ÷Óûָ´³ö³§ÉèÖà |
| 829 | set_modem_off(); |
| 830 | |
| 831 | /* Èç¹ûÊÇÀ©Õ¹AT·¢ÆðµÄreset£¬ÐèÒª¸øAT»Ø¸´ÏûÏ¢*/ |
| 832 | if (g_restart_from != 0) { |
| 833 | ipc_send_message(MODULE_ID_MAIN_CTRL, g_restart_from, MSG_CMD_RESTART_RSP, 0, NULL, 0); |
| 834 | //return; |
| 835 | } |
| 836 | /* ¸ù¾ÝsubactionÅжÏ×îºóµÄreboot¡¢¶ÏµçµÈ²Ù×÷ÊÇ·ñ½»ÓÉÍⲿMCU¸ºÔð*/ |
| 837 | if (g_restart_subaction == Operate_By_MCU) { |
| 838 | return; |
| 839 | } |
| 840 | // mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù |
| 841 | if (execute_ext_cmd(g_mainctrl_reset_ext_cmd)) |
| 842 | return; |
| 843 | |
| 844 | system("reboot"); |
| 845 | return; |
| 846 | } |
| 847 | |
| 848 | slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process still wait for reply !!!\n"); |
| 849 | } |
| 850 | |
| 851 | /*´¦ÀíÆäËûÄ£¿éÀ´µÄRESET_RSPÏûÏ¢£¬ÖØÖÃÆäÓàÄÚÈÝ*/ |
| 852 | void poweroff_rsp_process(MSG_BUF *msg) |
| 853 | { |
| 854 | int id; |
| 855 | struct mainctrl_notify_queue *temp = NULL; |
| 856 | |
| 857 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process start!!!\n"); |
| 858 | |
| 859 | if (msg) { |
| 860 | id = msg->src_id; |
| 861 | //MMIÒò¿ìËÙ¿ª¹Ø»úµÄ´æÔÚ£¬×îÖÕ´¦ÀíµÄÃüÁîÓëÉèÖûáÓÐËù²»Í¬ |
| 862 | if (msg->src_id == MODULE_ID_MMI && msg->usDataLen > 0) { |
| 863 | struct ext_msg_data *ext_data = (struct ext_msg_data *) msg->aucDataBuf; |
| 864 | g_mainctrl_poweroff_ext_cmd = ext_data->cmd; |
| 865 | } |
| 866 | notify_list_del(&g_mainctrl_poweroff_notify, id); |
| 867 | } |
| 868 | |
| 869 | //֪ͨresetµÄÄ£¿é¶¼´¦Àí²¢»Ø¸´ºóÔÙ½øÐÐÖ÷¿ØµÄ»Ö¸´³ö³§ÉèÖò¢ÖØÆô |
| 870 | if (list_empty(&g_mainctrl_poweroff_notify)) { |
| 871 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process success, g_poweroff_from:0x%x, ext_cmd:%d!!!\n", g_poweroff_from, g_mainctrl_poweroff_ext_cmd); |
| 872 | if (g_mainctrl_factory_reset == 0) |
| 873 | cfg_save(); |
| 874 | if(g_mainctrl_poweroff_ext_cmd != Ext_Cmd_POWEROFF_FAKE){//¿ìËٹػú²»¿ÉÒÔ·¢at_cfun=0 |
| 875 | set_modem_off(); |
| 876 | } |
| 877 | /* Èç¹ûÊÇÀ©Õ¹AT·¢ÆðµÄreset£¬×îºóµÄreboot¡¢¶ÏµçµÈ²Ù×÷½»ÓÉAT¸ºÔð*/ |
| 878 | if (g_poweroff_from != 0) { |
| 879 | ipc_send_message(MODULE_ID_MAIN_CTRL, g_poweroff_from, MSG_CMD_POWEROFF_RSP, 0, NULL, 0); |
| 880 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process MSG_CMD_POWEROFF_RSP to AT !!!\n"); |
| 881 | return; |
| 882 | } |
| 883 | // mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù |
| 884 | if (execute_ext_cmd(g_mainctrl_poweroff_ext_cmd)) |
| 885 | return; |
| 886 | system("app_monitor.sh off"); |
| 887 | system("poweroff"); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process still wait for reply !!!\n"); |
| 892 | } |
| 893 | |
| 894 | /*´¦ÀíÆäËûÄ£¿éÀ´µÄRESTART_RSPÏûÏ¢£¬ÖØÖÃÆäÓàÄÚÈÝ*/ |
| 895 | void restart_rsp_process(MSG_BUF *msg) |
| 896 | { |
| 897 | int id; |
| 898 | struct mainctrl_notify_queue *temp = NULL; |
| 899 | |
| 900 | slog(NET_PRINT, SLOG_NORMAL, "restart_rsp_process start!!!\n"); |
| 901 | |
| 902 | if (msg) { |
| 903 | id = msg->src_id; |
| 904 | //MMIÒò¿ìËÙ¿ª¹Ø»úµÄ´æÔÚ£¬×îÖÕ´¦ÀíµÄÃüÁîÓëÉèÖûáÓÐËù²»Í¬ |
| 905 | if (msg->src_id == MODULE_ID_MMI && msg->usDataLen > 0) { |
| 906 | struct ext_msg_data *ext_data = (struct ext_msg_data *) msg->aucDataBuf; |
| 907 | g_mainctrl_restart_ext_cmd = ext_data->cmd; |
| 908 | } |
| 909 | notify_list_del(&g_mainctrl_restart_notify, id); |
| 910 | } |
| 911 | |
| 912 | //֪ͨresetµÄÄ£¿é¶¼´¦Àí²¢»Ø¸´ºóÔÙ½øÐÐÖ÷¿ØµÄ»Ö¸´³ö³§ÉèÖò¢ÖØÆô |
| 913 | if (list_empty(&g_mainctrl_restart_notify)) { |
| 914 | slog(NET_PRINT, SLOG_NORMAL, "restart_rsp_process success, ext_cmd:%d, subaction:%d!!!\n", g_mainctrl_restart_ext_cmd, g_restart_subaction); |
| 915 | if (g_mainctrl_factory_reset == 0) |
| 916 | cfg_save(); |
| 917 | |
| 918 | set_modem_off(); |
| 919 | |
| 920 | // ATÐèÒª»Ø¸´ |
| 921 | if (g_restart_from != 0) { |
| 922 | ipc_send_message(MODULE_ID_MAIN_CTRL, g_restart_from, MSG_CMD_RESTART_RSP, 0, NULL, 0); |
| 923 | } |
| 924 | if (g_restart_subaction == Operate_By_MCU) { |
| 925 | return; |
| 926 | } |
| 927 | |
| 928 | // mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù |
| 929 | if (execute_ext_cmd(g_mainctrl_restart_ext_cmd)) |
| 930 | return; |
| 931 | |
| 932 | system("app_monitor.sh off"); |
| 933 | system("reboot"); |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | slog(NET_PRINT, SLOG_NORMAL, "restart_rsp_process still wait for reply !!!\n"); |
| 938 | } |
| 939 | |
| 940 | /********************************************************************************** |
| 941 | º¯Êý×÷ÓÃ:»Ö¸´³ö³§ÉèÖÃÏûÏ¢´¦Àíº¯Êý |
| 942 | ***********************************************************************************/ |
| 943 | void reset_msg_process(MSG_BUF *msg) |
| 944 | { |
| 945 | struct mainctrl_notify_queue *notify = NULL; |
| 946 | char fota_update_flag[32] = {0}; |
| 947 | |
| 948 | slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process start!!!\n"); |
| 949 | |
| 950 | //fotaÉý¼¶Ê±²»ÔÊÐí×ö»Ö¸´³ö³§ÉèÖà |
| 951 | cfg_get_item("fota_update_flag", fota_update_flag, sizeof(fota_update_flag)); |
| 952 | if (atoi(fota_update_flag) == 1) { |
| 953 | slog(NET_PRINT, SLOG_ERR, "reset_msg_process: fota is in upgrading process! can not reset!!!\n"); |
| 954 | return; |
| 955 | } |
| 956 | |
| 957 | #if 0 |
| 958 | //·ÇCPÀ´µÄÏûÏ¢£¬ÐèÒª¸øCP·¢ÏûϢ֪ͨCP reset£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 959 | //if (msg->usMsgCmd != MSG_CMD_SOC_RESET_REQUEST) |
| 960 | slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process msg->src_id = %x!!!\n", msg->src_id); |
| 961 | if (msg->src_id & MODULE_ID_APBASE) { |
| 962 | if (send_soc_msg(NEAR_PS, MODULE_ID_AT_CTL, MSG_CMD_RESET_NOTIFY, 0, NULL) == 0) { |
| 963 | slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process: send msg to CP ok!!!\n"); |
| 964 | //notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_AT_CTL); |
| 965 | notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_CP_AT_CTL); |
| 966 | } |
| 967 | } |
| 968 | #endif |
| 969 | |
| 970 | //¸øRTC·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 971 | if (rtc_timer_del_all(MODULE_ID_MAIN_CTRL, MSG_CMD_RESET_RSP) == 0) { |
| 972 | slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to rtc ok!!!\n"); |
| 973 | notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_RTC_SERVICE); |
| 974 | } |
| 975 | |
| 976 | //¸øSMS·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 977 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_SMS, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) { |
| 978 | slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to sms ok!!!\n"); |
| 979 | notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_SMS); |
| 980 | } |
| 981 | |
| 982 | //¸øFOTA·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 983 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_DM_WEBUI_AT, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) { |
| 984 | slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to FOTA ok!!!\n"); |
| 985 | notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_DM_WEBUI_AT); |
| 986 | } |
| 987 | |
| 988 | //¸øPB·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 989 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_PB, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) { |
| 990 | slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to pb ok!!!\n"); |
| 991 | notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_PB); |
| 992 | } |
| 993 | |
| 994 | //¸øMMI·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´,²»ÐèÒªÖ÷¿Ø×öresetÔò²»¸øMMI |
| 995 | if (g_restart_subaction == Operate_By_SOC) { |
| 996 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MMI, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) { |
| 997 | slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to mmi ok!!!\n"); |
| 998 | notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_MMI); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | //ÒÔÉÏÓ¦Óò»´æÔÚ£¬Ö÷¿Ø×ßÓ¦´ðÁ÷³Ì |
| 1003 | if (list_empty(&g_mainctrl_reset_notify)) { |
| 1004 | reset_rsp_process(NULL); |
| 1005 | } else { |
| 1006 | slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process success!!!\n"); |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | /********************************************************************************** |
| 1011 | º¯Êý×÷ÓÃ:ÊÇ·ñ¼Ù¹Ø»ú |
| 1012 | ***********************************************************************************/ |
| 1013 | static BOOL blc_is_fakepoweroff() |
| 1014 | { |
| 1015 | char nv_abnormal_poweroff[2] = {0}; |
| 1016 | char rj45_sta[24] = {0}; |
| 1017 | char nv_poweron_mode[8] = {0}; |
| 1018 | char nv_sim_pin[8] = {0}; |
| 1019 | |
| 1020 | cfg_get_item("abnormal_poweroff_flag", nv_abnormal_poweroff, sizeof(nv_abnormal_poweroff)); |
| 1021 | cfg_get_item("rj45_plug", rj45_sta, sizeof(rj45_sta)); |
| 1022 | cfg_get_item("mgmt_quicken_power_on", nv_poweron_mode, sizeof(nv_poweron_mode)); |
| 1023 | cfg_get_item("need_sim_pin", nv_sim_pin, sizeof(nv_sim_pin)); |
| 1024 | slog(NET_PRINT, SLOG_NORMAL, "blc_is_fakepoweroff nv_abnormal_poweroff= %s,rj45_sta= %s,nv_poweron_mode= %s,nv_sim_pin= %s\n", nv_abnormal_poweroff, rj45_sta, nv_poweron_mode, nv_sim_pin); |
| 1025 | if ((!strncmp(rj45_sta, "wan_on_lan_off", strlen("wan_on_lan_off"))) |
| 1026 | || (!strncmp(rj45_sta, "wan_off_lan_on", strlen("wan_off_lan_on"))) |
| 1027 | || (!strncmp(rj45_sta, "wan_lan_on", strlen("wan_lan_on")))) { |
| 1028 | return FALSE; |
| 1029 | } |
| 1030 | if (strncmp(nv_poweron_mode, "1", sizeof("1"))) { |
| 1031 | return FALSE; |
| 1032 | } |
| 1033 | if (!strncmp(nv_sim_pin, "yes", sizeof("yes"))) { |
| 1034 | return FALSE; |
| 1035 | } |
| 1036 | if (!strncmp(nv_abnormal_poweroff, "1", 1)) { |
| 1037 | return FALSE; |
| 1038 | } |
| 1039 | slog(NET_PRINT, SLOG_NORMAL, "blc_is_fakepoweroff !\n"); |
| 1040 | return TRUE; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | /********************************************************************************** |
| 1045 | º¯Êý×÷ÓÃ:¹Ø»úÏûÏ¢´¦Àíº¯Êý |
| 1046 | ***********************************************************************************/ |
| 1047 | void poweroff_msg_process(MSG_BUF *msg) |
| 1048 | { |
| 1049 | struct ext_msg_data *msgData = NULL; |
| 1050 | |
| 1051 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process !\n"); |
| 1052 | |
| 1053 | #if (PRODUCT_TYPE == PRODUCT_PHONE) |
| 1054 | if (g_poweroff_from == 0) { //À©Õ¹AT·¢ÆðµÄ¹Ø»úÇëÇ󣬲»´ø¹Ø»úÔÒò£¬²»ÐèÒª×ßÒÔÏÂÁ÷³Ì£»CP·¢ÆðµÄ¹Ø»úÇëÇó×ßÒÔÏÂÁ÷³Ì |
| 1055 | if (!msg || msg->usDataLen <= 0) { |
| 1056 | slog(NET_PRINT, SLOG_ERR, "poweroff_msg_process msg is empty \n"); |
| 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | msgData = (struct ext_msg_data*)msg->aucDataBuf; |
| 1061 | if (!msgData) { |
| 1062 | slog(NET_PRINT, SLOG_ERR, "poweroff_msg_process param is NULL \n"); |
| 1063 | return; |
| 1064 | } |
| 1065 | g_mainctrl_poweroff_ext_cmd = (T_zUfi_ExtCmd)msgData->cmd; |
| 1066 | } |
| 1067 | #endif |
| 1068 | |
| 1069 | //¸ødata·¢ÏûÏ¢£¬²»ÐèÒªÊÕµ½»Ø¸´ |
| 1070 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_FLUXSTAT, MSG_CMD_DATA_END, 0, NULL, 0) != 0) { |
| 1071 | slog(NET_PRINT, SLOG_ERR, "send msg to data fail!!!\n"); |
| 1072 | } |
| 1073 | |
| 1074 | //·Ç¼Ù¹Ø»úʱ¸øRTC·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 1075 | if (!blc_is_fakepoweroff()) { |
| 1076 | if (rtc_timer_del_all(MODULE_ID_MAIN_CTRL, MSG_CMD_POWEROFF_RSP) == 0) { |
| 1077 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process: send msg to rtc ok!!!\n"); |
| 1078 | notify_list_add(&g_mainctrl_poweroff_notify, MODULE_ID_RTC_SERVICE); |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | //¸øMMI·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 1083 | if (g_poweroff_from == 0) { |
| 1084 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MMI, MSG_CMD_POWEROFF_NOTIFY, 0, NULL, 0) == 0) { |
| 1085 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process: send msg to mmi ok!!!\n"); |
| 1086 | notify_list_add(&g_mainctrl_poweroff_notify, MODULE_ID_MMI); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | //ÒÔÉÏÓ¦Óò»´æÔÚ£¬Ö÷¿Ø×ßÓ¦´ðÁ÷³Ì |
| 1091 | if (list_empty(&g_mainctrl_poweroff_notify)) { |
| 1092 | poweroff_rsp_process(NULL); |
| 1093 | } else { |
| 1094 | slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process success!!!\n"); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | /********************************************************************************** |
| 1099 | º¯Êý×÷ÓÃ:ÖØÆôÏûÏ¢´¦Àíº¯Êý |
| 1100 | ***********************************************************************************/ |
| 1101 | void restart_msg_process(void) |
| 1102 | { |
| 1103 | slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process !\n"); |
| 1104 | |
| 1105 | //¸ødata·¢ÏûÏ¢£¬²»ÐèÒªÊÕµ½»Ø¸´ |
| 1106 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_FLUXSTAT, MSG_CMD_DATA_END, 0, NULL, 0) != 0) { |
| 1107 | slog(NET_PRINT, SLOG_ERR, "send msg to data fail!!!\n"); |
| 1108 | } |
| 1109 | |
| 1110 | //¸øRTC·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 1111 | if (rtc_timer_del_all(MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_RSP) == 0) { |
| 1112 | slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process: send msg to rtc ok!!!\n"); |
| 1113 | notify_list_add(&g_mainctrl_restart_notify, MODULE_ID_RTC_SERVICE); |
| 1114 | } |
| 1115 | |
| 1116 | //¸øMMI·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´ |
| 1117 | if (g_restart_subaction == Operate_By_SOC) { |
| 1118 | if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MMI, MSG_CMD_RESTART_NOTIFY, 0, NULL, 0) == 0) { |
| 1119 | slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process: send msg to mmi ok!!!\n"); |
| 1120 | notify_list_add(&g_mainctrl_restart_notify, MODULE_ID_MMI); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | //ÒÔÉÏÓ¦Óò»´æÔÚ£¬Ö÷¿Ø×ßÓ¦´ðÁ÷³Ì |
| 1125 | if (list_empty(&g_mainctrl_restart_notify)) { |
| 1126 | restart_rsp_process(NULL); |
| 1127 | } else { |
| 1128 | slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process success!!!\n"); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | /*rj45×÷ΪÄÚÍø¿Úʱ£¬´ò¿ªwifiºÍpsÖÐÓÅÏȼ¶¸ßµÄ×÷ΪÍâÍø¿Ú*/ |
| 1133 | void set_rj45_lan() |
| 1134 | { |
| 1135 | int result = -1; |
| 1136 | int wifi_pre = 0; |
| 1137 | |
| 1138 | set_wan_auto_mode("AUTO_PPP"); |
| 1139 | |
| 1140 | wifi_pre = get_wifiwan_pre(); |
| 1141 | if (wifi_pre == 1) { //½øÐÐwifistation Á¬½Ó |
| 1142 | open_wifiwan_access(); |
| 1143 | } else if (wifi_pre == 0) { //½øÐÐmodem Á¬½Ó |
| 1144 | open_pswan_access(); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | static void check_limit_time(void) |
| 1149 | { |
| 1150 | /* 0:·ÇÏÞÖÆÉÏÍøÊ±¼ä¶Î 1:ÏÞÖÆÉÏÍøÊ±¼ä¶Î*/ |
| 1151 | if (g_limit_time_flag == 1) { |
| 1152 | zte_children_start_nonet(); |
| 1153 | } else if (g_limit_time_flag == 0) { |
| 1154 | zte_children_stop_nonet(); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | static int create_msg_queue(void) |
| 1159 | { |
| 1160 | return msgget(MODULE_ID_MAIN_CTRL, IPC_CREAT | 0600); |
| 1161 | } |
| 1162 | |
| 1163 | void get_wan_name() |
| 1164 | { |
| 1165 | cfg_get_item("pswan", ps_wan, sizeof(ps_wan)); |
| 1166 | cfg_get_item("wifiwan", wifi_wan, sizeof(wifi_wan)); |
| 1167 | cfg_get_item("ethwan", eth_wan, sizeof(eth_wan)); |
| 1168 | } |
| 1169 | |
| 1170 | void mainctrl_init() |
| 1171 | { |
| 1172 | INIT_LIST_HEAD(&g_mainctrl_reset_notify); |
| 1173 | INIT_LIST_HEAD(&g_mainctrl_poweroff_notify); |
| 1174 | INIT_LIST_HEAD(&g_mainctrl_restart_notify); |
| 1175 | pppoe_aes_init(); |
| 1176 | } |
| 1177 | |
| 1178 | void Router_msg_proc(MSG_BUF *msg) |
| 1179 | { |
| 1180 | if (NULL == msg) { |
| 1181 | slog(NET_PRINT, SLOG_ERR, "NULL para input!"); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | switch (msg->usMsgCmd) { |
| 1186 | /*ÍøÂçÏà¹ØµÄÏûÏ¢´¦Àí*/ |
| 1187 | case MSG_CMD_NET_IPPORT_FILTER: { |
| 1188 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_IPPORT_FILTER \n"); |
| 1189 | zte_iptables_filter_run(); |
| 1190 | zte_iptables_filter_run_v6(); |
| 1191 | break; |
| 1192 | } |
| 1193 | case MSG_CMD_NET_IPPORT_FORWARD: { |
| 1194 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_IPPORT_FORWARD \n"); |
| 1195 | zte_iptables_sys_fw_run(); |
| 1196 | zte_iptables_port_forward_run(); |
| 1197 | break; |
| 1198 | } |
| 1199 | case MSG_CMD_NET_DMZ: { |
| 1200 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DMZ \n"); |
| 1201 | zte_iptables_DMZ_Run(); |
| 1202 | break; |
| 1203 | } |
| 1204 | /* EC: 616000297057, ÔÒò: ÍøÂç²»Ö§³Ö¶Ë¿ÚÓ³Éä */ |
| 1205 | case MSG_CMD_NET_IPPORT_MAPPING: { |
| 1206 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_IPPORT_MAPPING \n"); |
| 1207 | zte_iptables_port_map_all_run(); |
| 1208 | break; |
| 1209 | } |
| 1210 | case MSG_CMD_NET_UPNP: { |
| 1211 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_UPNP \n"); |
| 1212 | zte_unpn_set(); |
| 1213 | break; |
| 1214 | } |
| 1215 | case MSG_CMD_NET_URL_FILTER: { |
| 1216 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_URL_FILTER \n"); |
| 1217 | zte_iptables_Webs_Filter_Run(); |
| 1218 | break; |
| 1219 | } |
| 1220 | case MSG_CMD_NET_MTU: { |
| 1221 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_MTU \n"); |
| 1222 | zte_router_mtu_set_process(); |
| 1223 | break; |
| 1224 | } |
| 1225 | case MSG_CMD_NET_WAN4_CHANGE: { |
| 1226 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_WAN4_CHANGE %s\n", msg->aucDataBuf); |
| 1227 | proc_wan_change_v4(); |
| 1228 | break; |
| 1229 | } |
| 1230 | case MSG_CMD_NET_WAN6_CHANGE: { |
| 1231 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_WAN6_CHANGE %s\n", msg->aucDataBuf); |
| 1232 | proc_wan_change_v6(); |
| 1233 | break; |
| 1234 | } |
| 1235 | case MSG_CMD_NET_PLUGIN: { |
| 1236 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PLUGIN \n"); |
| 1237 | if(g_poweron_type != 2)//¹Ø»ú³äµç²»ÆðÍøÂçÉ豸£¬¹²½ø³Ì°æ±¾¹Ø»ú³äµç»áÆðhotplug£¬»á·¢À´usbplugin |
| 1238 | net_netdev_plugin_proc(*((unsigned char *)msg->aucDataBuf)); |
| 1239 | break; |
| 1240 | } |
| 1241 | case MSG_CMD_NET_PLUGOUT: { |
| 1242 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PLUGOUT \n"); |
| 1243 | net_netdev_plugout_proc(*((unsigned char *)msg->aucDataBuf)); |
| 1244 | break; |
| 1245 | } |
| 1246 | case MSG_CMD_NET_CONNECT: { |
| 1247 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_CONNECT \n"); |
| 1248 | net_netdev_connect_internet(*((unsigned char *)msg->aucDataBuf)); |
| 1249 | break; |
| 1250 | } |
| 1251 | case MSG_CMD_NET_DISCON: { |
| 1252 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DISCON \n"); |
| 1253 | net_netdev_disconnect_internet(*((unsigned char *)msg->aucDataBuf)); |
| 1254 | break; |
| 1255 | } |
| 1256 | case MSG_CMD_NET_PDP_ACT: { |
| 1257 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PDP_ACT \n"); |
| 1258 | net_pdp_act_proc((struct pdp_active_info *)msg->aucDataBuf); |
| 1259 | break; |
| 1260 | } |
| 1261 | case MSG_CMD_NET_PDP_DEACT: { |
| 1262 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PDP_DEACT \n"); |
| 1263 | struct pdp_deactive_info temp = *((struct pdp_deactive_info *)msg->aucDataBuf); |
| 1264 | net_pdp_deact_proc(temp.c_id, temp.ip46flag); |
| 1265 | break; |
| 1266 | } |
| 1267 | case MSG_CMD_NET_TC_CTRL: { |
| 1268 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_TC_CTRL \n"); |
| 1269 | net_tc_control((struct tc_control_info *)msg->aucDataBuf,msg->src_id); |
| 1270 | break; |
| 1271 | } |
| 1272 | case MSG_CMD_NET_GET_HOSTNAME: { |
| 1273 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_GET_HOSTNAME \n"); |
| 1274 | get_mac_hostname_pro((struct mac_hostname_info *)msg->aucDataBuf); |
| 1275 | break; |
| 1276 | } |
| 1277 | case MSG_CMD_NET_STATIC_DHCP: { |
| 1278 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_STATIC_DHCP \n"); |
| 1279 | zte_macip_list_run(); |
| 1280 | break; |
| 1281 | } |
| 1282 | case MSG_CMD_NET_DHCP_SETTING_REQ: { |
| 1283 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DHCP_SETTING_REQ \n"); |
| 1284 | zte_router_dhcp_setting_req_process((dhcp_setting_req *)msg->aucDataBuf); |
| 1285 | break; |
| 1286 | } |
| 1287 | case MSG_CMD_NET_TIMER_OUT: { |
| 1288 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_TIMER_OUT \n"); |
| 1289 | out_of_time(*((unsigned char *)msg->aucDataBuf)); |
| 1290 | break; |
| 1291 | } |
| 1292 | case MSG_CMD_NET_TIMER_DEL: { |
| 1293 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_TIMER_DEL \n"); |
| 1294 | char wanname[20] = {0}; |
| 1295 | strncpy(wanname, (char *)msg->aucDataBuf, sizeof(wanname)-1);//klocwork |
| 1296 | slog(NET_PRINT, SLOG_ERR, "MSG_CMD_NET_TIMER_DEL:%s \n", wanname); |
| 1297 | if (0 == strcmp("ethwan", wanname)) |
| 1298 | deletetimer(ethwan_id); |
| 1299 | else if (0 == strcmp("wifiwan", wanname)) |
| 1300 | deletetimer(wifiwan_id); |
| 1301 | break; |
| 1302 | } |
| 1303 | case MSG_CMD_NET_BIND_STATIC_ADDRESS: { |
| 1304 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_BIND_STATIC_ADDRESS \n"); |
| 1305 | zte_bind_macip_list(); |
| 1306 | break; |
| 1307 | } |
| 1308 | case MSG_CMD_NET_BIND_STATIC_ADDRESS_ADD: { |
| 1309 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_BIND_STATIC_ADDRESS_ADD \n"); |
| 1310 | zte_bind_macip_list_add((struct static_macip_info*)msg->aucDataBuf); |
| 1311 | break; |
| 1312 | } |
| 1313 | case MSG_CMD_NET_BIND_STATIC_ADDRESS_DEL: { |
| 1314 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_BIND_STATIC_ADDRESS_DEL \n"); |
| 1315 | zte_bind_macip_list_del((char*)msg->aucDataBuf); |
| 1316 | break; |
| 1317 | } |
| 1318 | case MSG_CMD_NET_ADD_CHILDREN_DEVICE: { |
| 1319 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_ADD_CHILDREN_DEVICE \n"); |
| 1320 | children_device_add((struct mac_hostname_info *)msg->aucDataBuf); |
| 1321 | slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname MESSAGE TO MC END"); |
| 1322 | check_limit_time(); |
| 1323 | break; |
| 1324 | } |
| 1325 | case MSG_CMD_NET_DEL_CHILDREN_DEVICE: { |
| 1326 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DEL_CHILDREN_DEVICE \n"); |
| 1327 | children_device_del((char *)msg->aucDataBuf); |
| 1328 | slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname MESSAGE TO MC END"); |
| 1329 | check_limit_time(); |
| 1330 | break; |
| 1331 | } |
| 1332 | case MSG_CMD_NET_ADD_WHITE_SITE: { |
| 1333 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_ADD_WHITE_SITE \n"); |
| 1334 | white_site_add((struct white_site_info *)msg->aucDataBuf); |
| 1335 | slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname MESSAGE TO MC END"); |
| 1336 | check_limit_time(); |
| 1337 | break; |
| 1338 | } |
| 1339 | case MSG_CMD_NET_REMOVE_WHITE_SITE: { |
| 1340 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_REMOVE_WHITE_SITE \n"); |
| 1341 | white_site_remove((char *)msg->aucDataBuf); |
| 1342 | slog(NET_PRINT, SLOG_DEBUG, "zte_edit_hostname MESSAGE TO MC END"); |
| 1343 | check_limit_time(); |
| 1344 | break; |
| 1345 | } |
| 1346 | case MSG_CMD_NET_START_NONET: { |
| 1347 | g_limit_time_flag = 1; |
| 1348 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_START_NONET \n"); |
| 1349 | zte_children_start_nonet(); |
| 1350 | break; |
| 1351 | } |
| 1352 | case MSG_CMD_NET_STOP_NONET: { |
| 1353 | g_limit_time_flag = 0; |
| 1354 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_STOP_NONET \n"); |
| 1355 | zte_children_stop_nonet(); |
| 1356 | break; |
| 1357 | } |
| 1358 | case MSG_CMD_PDP_ACT_RSP: { |
| 1359 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_PDP_ACT_RSP \n"); |
| 1360 | g_pdpact_reqing = 0; |
| 1361 | break; |
| 1362 | } |
| 1363 | case MSG_CMD_PDP_DEACT_RSP: { |
| 1364 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_PDP_DEACT_RSP \n"); |
| 1365 | g_pdpdeact_reqing = 0; |
| 1366 | break; |
| 1367 | } |
| 1368 | //case MSG_CMD_SOC_RESET_REQUEST: |
| 1369 | case MSG_CMD_RESET_REQUEST: { |
| 1370 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESET_REQUEST, cmd:0x%x \n", msg->usMsgCmd); |
| 1371 | set_wake_lock(MAINCTRL_LOCK); //reset¡¢¹Ø»ú¡¢ÖØÆô²»ÔÊÐíÔÙ½øÐÝÃß |
| 1372 | g_mainctrl_factory_reset = 1; |
| 1373 | cfg_set("doingPowerOff", "1"); |
| 1374 | record_restart_type(msg); |
| 1375 | reset_msg_process(msg); |
| 1376 | break; |
| 1377 | } |
| 1378 | case MSG_CMD_POWEROFF_REQUEST: { |
| 1379 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_POWEROFF_REQUEST \n"); |
| 1380 | set_wake_lock(MAINCTRL_LOCK); |
| 1381 | cfg_set("doingPowerOff", "1"); |
| 1382 | record_poweroff_type(msg); |
| 1383 | poweroff_msg_process(msg); |
| 1384 | break; |
| 1385 | } |
| 1386 | //²»´ø²ÎÊýĬÈÏ×ßÖØÆô£¬²ÎÊýaction : 1-RESET, 0 -RESTART ; subaction:1-Ö÷¿Ø×îÖÕÍê³ÉÖØÆô»ñ»Ö¸´³ö³§ÉèÖÃ, 0-Ö÷¿ØÖ»ÒªÍê³ÉÖØÆô»ñ»Ö¸´³ö³§ÉèÖÃ֮ǰµÄ¶¯×÷¼´¿É |
| 1387 | case MSG_CMD_RESTART_REQUEST: { |
| 1388 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESTART_REQUEST \n"); |
| 1389 | set_wake_lock(MAINCTRL_LOCK); |
| 1390 | cfg_set("doingPowerOff", "1"); |
| 1391 | record_restart_type(msg); |
| 1392 | |
| 1393 | if (msg->usDataLen > 0) { |
| 1394 | restart_info *msgData = (restart_info*)msg->aucDataBuf; |
| 1395 | if (msgData->action == Restart_Action_RESET) { |
| 1396 | g_mainctrl_factory_reset = 1; |
| 1397 | reset_msg_process(msg); |
| 1398 | } else { |
| 1399 | restart_msg_process(); |
| 1400 | } |
| 1401 | } else { |
| 1402 | restart_msg_process(); |
| 1403 | } |
| 1404 | break; |
| 1405 | } |
| 1406 | /*ÆäËûÄ£¿é´¦ÀíÍêresetºó»ØµÄÏûÏ¢*/ |
| 1407 | //case MSG_CMD_SOC_RESET_RSP: |
| 1408 | case MSG_CMD_RESET_RSP: { |
| 1409 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESET_RSP, cmd:0x%x \n", msg->usMsgCmd); |
| 1410 | reset_rsp_process(msg); |
| 1411 | break; |
| 1412 | } |
| 1413 | /*ÆäËûÄ£¿é´¦ÀíÍêpoweroffºó»ØµÄÏûÏ¢*/ |
| 1414 | case MSG_CMD_POWEROFF_RSP: { |
| 1415 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_POWEROFF_RSP \n"); |
| 1416 | poweroff_rsp_process(msg); |
| 1417 | break; |
| 1418 | } |
| 1419 | /*ÆäËûÄ£¿é´¦ÀíÍêrestartºó»ØµÄÏûÏ¢*/ |
| 1420 | case MSG_CMD_RESTART_RSP: { |
| 1421 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESTART_RSP \n"); |
| 1422 | restart_rsp_process(msg); |
| 1423 | break; |
| 1424 | } |
| 1425 | case MSG_CMD_NET_SET_RJ45_LAN: { |
| 1426 | set_rj45_lan(); |
| 1427 | break; |
| 1428 | } |
| 1429 | case MSG_CMD_NET_PING_DIAGNOSTICS: { |
| 1430 | slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_PING_DIAGNOSTICS \n"); |
| 1431 | zte_router_ping_diagnostics(); |
| 1432 | break; |
| 1433 | } |
| 1434 | default: |
| 1435 | //assert(0); |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | static void print_mainctrl_info(void) |
| 1441 | { |
| 1442 | struct mainctrl_notify_queue *temp = NULL; |
| 1443 | int ret; |
| 1444 | |
| 1445 | if (!list_empty(&g_mainctrl_poweroff_notify)) { |
| 1446 | list_for_each_entry(temp, &g_mainctrl_poweroff_notify, list) { |
| 1447 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_poweroff_notify: module_id = 0x%x\n", temp->notify_id); |
| 1448 | } |
| 1449 | } else { |
| 1450 | slog(RTC_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_poweroff_notify list is empty! \n"); |
| 1451 | } |
| 1452 | |
| 1453 | if (!list_empty(&g_mainctrl_restart_notify)) { |
| 1454 | list_for_each_entry(temp, &g_mainctrl_restart_notify, list) { |
| 1455 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_restart_notify: module_id = 0x%x\n", temp->notify_id); |
| 1456 | } |
| 1457 | } else { |
| 1458 | slog(RTC_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_restart_notify list is empty! \n"); |
| 1459 | } |
| 1460 | |
| 1461 | if (!list_empty(&g_mainctrl_reset_notify)) { |
| 1462 | list_for_each_entry(temp, &g_mainctrl_reset_notify, list) { |
| 1463 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_reset_notify: module_id = 0x%x\n", temp->notify_id); |
| 1464 | } |
| 1465 | } else { |
| 1466 | slog(RTC_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_reset_notify list is empty! \n"); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | static void mainctrl_sig_usr1(int signo) |
| 1471 | { |
| 1472 | /*if (signo == SIGUSR1) { |
| 1473 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl receive SIGUSR1!\n"); |
| 1474 | |
| 1475 | print_mainctrl_info(); |
| 1476 | } else { |
| 1477 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl receive signo %d", signo); |
| 1478 | }*/ |
| 1479 | } |
| 1480 | |
| 1481 | static void nv_save_timeout(void) |
| 1482 | { |
| 1483 | slog(NET_PRINT, SLOG_DEBUG, "nv_save_timeout factory_reset:%d \n", g_mainctrl_factory_reset); |
| 1484 | |
| 1485 | if (g_mainctrl_factory_reset == 0) |
| 1486 | cfg_save(); |
| 1487 | } |
| 1488 | |
| 1489 | static void zte_security_log_entry(char *arg) |
| 1490 | { |
| 1491 | int msg_handle = msgget(MODULE_ID_SECURITY_LOG, IPC_CREAT | 0600); |
| 1492 | int ret = 0; |
| 1493 | MSG_BUF stMsg; |
| 1494 | LONG msgSize = sizeof(MSG_BUF) - sizeof(LONG); |
| 1495 | char seclog[32] = {0}; |
| 1496 | |
| 1497 | cfg_get_item("seclog_switch", seclog, sizeof(seclog)); |
| 1498 | prctl(PR_SET_NAME, "seclog", 0, 0, 0); |
| 1499 | slog(NET_PRINT, SLOG_ERR, "zte_security_log begin --build date: %s %s \n", __DATE__, __TIME__); |
| 1500 | if (msg_handle == -1) { |
| 1501 | slog(NET_PRINT, SLOG_ERR, "can not create msg queue for security_log!\n"); |
| 1502 | return; |
| 1503 | } |
| 1504 | for (;;) { |
| 1505 | memset(&stMsg, 0, sizeof(stMsg)); |
| 1506 | ret = msgrcv(msg_handle, &stMsg, msgSize, 0, 0); |
| 1507 | if (ret == -1) { |
| 1508 | if (EINTR == errno) { |
| 1509 | slog(NET_PRINT, SLOG_ERR, "sl_recev msg EINTR\n"); |
| 1510 | continue; |
| 1511 | } else { |
| 1512 | slog(NET_PRINT, SLOG_ERR, "sl_recev msg fail errno = %d \n", errno); |
| 1513 | break; |
| 1514 | } |
| 1515 | } |
| 1516 | slog(NET_PRINT, SLOG_NORMAL, "sl:%s\n", stMsg.aucDataBuf); |
| 1517 | if(seclog[0] == '1') |
| 1518 | { |
| 1519 | file_write("security",stMsg.aucDataBuf); |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | int zte_mainctrl_main(int argc, char * argv[]) |
| 1525 | { |
| 1526 | int iMsgHandle = 0; |
| 1527 | int iRet = 0; |
| 1528 | MSG_BUF stMsg; |
| 1529 | MSG_BUF send_stMsg; |
| 1530 | LONG msgSize = sizeof(MSG_BUF) - sizeof(LONG); |
| 1531 | int interruptSIG = 0; |
| 1532 | char nv_save_interval[32] = {0}; |
| 1533 | unsigned int interval_time = 0; |
| 1534 | int i = 0; |
| 1535 | prctl(PR_SET_NAME, "mainctrl", 0, 0, 0); |
| 1536 | //¸ù¾ÝNV³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿ |
| 1537 | loglevel_init(); |
| 1538 | |
| 1539 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl begin ======= build date: %s %s \n", __DATE__, __TIME__); |
| 1540 | |
| 1541 | pthread_t zte_security_log_tid; |
| 1542 | if (pthread_create(&zte_security_log_tid, NULL, (void *)zte_security_log_entry, NULL) != 0) //cov m |
| 1543 | slog(NET_PRINT, SLOG_ERR, "zte_security_log_entry create fail\n"); |
| 1544 | |
| 1545 | iMsgHandle = create_msg_queue(); |
| 1546 | if (-1 == iMsgHandle) { |
| 1547 | slog(NET_PRINT, SLOG_ERR, "can not create msg queue for ZTE_router!\n"); |
| 1548 | return -1; |
| 1549 | } |
| 1550 | |
| 1551 | if (signal(SIGUSR1, mainctrl_sig_usr1) == SIG_ERR) |
| 1552 | slog(NET_PRINT, SLOG_ERR, "zte_mainctrl cat not catch SIGUSR1!\n"); |
| 1553 | |
| 1554 | cfg_get_item("nv_save_interval", nv_save_interval, sizeof(nv_save_interval)); |
| 1555 | interval_time = atoi(nv_save_interval); |
| 1556 | if (interval_time < 0x400000) {//klocwork ΪÁ˲»Òç³ö |
| 1557 | interval_time = interval_time*1000; |
| 1558 | CreateSoftTimer(TIMER_MainCtrl_NvSaveID, TIMER_FLAG_RESTART, interval_time, nv_save_timeout, NULL); |
| 1559 | } |
| 1560 | |
| 1561 | /*init the router*/ |
| 1562 | //zte_router_init(); |
| 1563 | get_wan_name(); |
| 1564 | |
| 1565 | //³õʼ»¯È«¾Ö±äÁ¿ |
| 1566 | mainctrl_init(); |
| 1567 | if (argc >= 2) { |
| 1568 | g_poweron_type = 2;//¹Ø»ú³äµç |
| 1569 | } |
| 1570 | if(g_poweron_type != 2) |
| 1571 | system("internet.sh"); |
| 1572 | //µÈat_ctl×¼±¸ºÃ |
| 1573 | while (i < 10) { |
| 1574 | char ppp_status[20] = {0}; |
| 1575 | cfg_get_item("ppp_status", ppp_status, sizeof(ppp_status)); |
| 1576 | if (0 != strcmp("", ppp_status)) |
| 1577 | break; |
| 1578 | usleep(200000); |
| 1579 | i++; |
| 1580 | } |
| 1581 | pdp_auto_dial(); |
| 1582 | |
| 1583 | for (;;) { |
| 1584 | if (0 == interruptSIG) { |
| 1585 | slog(NET_PRINT, SLOG_ERR, "ZTE_router begin to rcv msg from queue %d. \n", iMsgHandle); |
| 1586 | } |
| 1587 | memset(&stMsg, '\0', sizeof(stMsg)); |
| 1588 | iRet = 0; |
| 1589 | iRet = msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0); |
| 1590 | if (-1 == iRet) { |
| 1591 | if (EINTR == errno) { |
| 1592 | slog(NET_PRINT, SLOG_ERR, "received msg EINTR\n"); |
| 1593 | // we use SIGALRM to timer, but the SIG will interrupt mgsrcv, so we should |
| 1594 | //do this action |
| 1595 | //DEBUG(LOG_ERR, "msgrcv faild as received a signal EINTR, need continue...\n"); |
| 1596 | //usleep(1000); |
| 1597 | interruptSIG = 1; |
| 1598 | continue; |
| 1599 | } else { |
| 1600 | //ZTE_LOG(LOG_ERR, "recv msg from the Goahead fail errno=%d!", errno); |
| 1601 | slog(NET_PRINT, SLOG_ERR, "recv msg fail errno = %d \n", errno); |
| 1602 | return -1; |
| 1603 | } |
| 1604 | } else { |
| 1605 | interruptSIG = 1; |
| 1606 | } |
| 1607 | slog(NET_PRINT, SLOG_NORMAL, "mainctrl received msg usMsgCmd=0x%x, src=0x%x \n", stMsg.usMsgCmd, stMsg.src_id); |
| 1608 | |
| 1609 | /*set the firewall or router*/ |
| 1610 | Router_msg_proc(&stMsg); |
| 1611 | } |
| 1612 | //closelog(); |
| 1613 | } |
| 1614 | |
| 1615 | |
| 1616 | |