blob: 90116ebf59f6b5e0b0d48573fa19ae2555e8d13d [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2* ¹¦ÄÜ״̬µÈÏà¹ØÐÅÏ¢²éѯÓëÉèÖÃ,Ö÷ÒªÓÃÓÚ״̬²éѯ¡¢ÎÊÌâ·ÖÎö¡¢¼¯³É²âÊԵȣ¬½öÔÚAP²àLINUXʹÓÃ
3* Ö§³ÖµÄ¹¦ÄÜÈçÏÂ:
4* ²éѯ»òÉèÖÃÍø¿ÚÇл»
5* ²éѯ»òÉèÖù¤×÷ģʽÇл»
6* ²éѯ»òÉèÖÃTELNET״̬
7* ²éѯ»òÉèÖÃSALESTAT״̬
8
9* ºóÐøÈçÓй¦ÄÜ״̬²éѯ»ò¿ª¹ØÉèÖõÄÏà¹ØÐèÇ󣬿ÉÒÔÔÚ´ËÎļþÖÐÌí¼ÓATÃüÁî´¦Àí
10**********************************************************************************/
11
12#if (APP_OS_TYPE == APP_OS_LINUX)
13#include "ext_regist.h"
14#include "softap_api.h"
15#include "at_utils.h"
16#include "zxic_errno.h"
17#include "nv_api.h"
18#include "at_context.h"
19#include "syncnv.h"
20#include <fcntl.h>
21#include <sys/ioctl.h>
22#include "RONvParam_AMT.h"
23#include "ref_nv_def.h"
24#include <linux/input.h>
25#include "NvParam_drv.h"
26#include "libcpnv.h"
27
28static int32_t cardSlotFlag = 0;
29
30//========================================================================================================//
31//º¯ÊýʵÏÖÇø
32//========================================================================================================//
33#define USB_HOTPLUG_FILE_NAME "/sys/dwc_usb/usbconfig/hotplug"
34#define AP_WORK_LOCK "ap_work_lock"
35
36int writefile(char*path, char*buf, unsigned len)
37{
38 FILE *fp;
39 int rtv;
40 if((fp=fopen(path,"w"))==NULL)
41 {
42 return -1;
43 }
44 rtv = fwrite(buf,len,1, fp);
45 fclose(fp);
46 return rtv;
47}
48
49int zlanenableGet_req(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
50{
51 char enable_flag[2] = {0};
52
53 sc_cfg_get("LanEnable", enable_flag, sizeof(enable_flag));
54 at_print(AT_DEBUG,"zlanenableGet_req:LanEnable = %s\n", enable_flag);
55
56 *res_msg = at_query_result_build("ZLANENABLE",enable_flag);
57 *res_msglen = strlen(*res_msg);
58
59 return AT_END;
60}
61
62static void sc_cfg_set_ufi_state(void)
63{
64 sc_cfg_set("LanEnable","1");
65 sc_cfg_set("usblan", "usblan0");
66 sc_cfg_set("need_jilian", "0");
67 sc_cfg_set("need_init_modem","yes");
68 //sc_cfg_set("cid_reserved","12");
69}
70int zlanenableSet_req(int at_fd,char * at_paras,void * * res_msg,int * res_msglen)
71{
72 char* at_str = NULL;
73 int32_t iLanEnable = 0;
74 int32_t iOldLanEnable = 0;
75 char strCfgGetItem[AT_CMD_MAX] = {0};
76
77 if(at_paras==NULL)
78 softap_assert("zlanenableSet_req:at_paras is null");
79
80 at_str = at_paras;
81 get_at_cmd_param_int(at_str, &iLanEnable, &at_str);
82 at_print(AT_DEBUG,"zlanenableSet_rsq:iLanEnable == %d\n", iLanEnable);
83
84 if(!(0 == iLanEnable || 1 == iLanEnable
85 || 2 == iLanEnable|| 3 == iLanEnable)) // szLanEnableÖ»ÓÐ0ºÍ1Á½¸öÖµ
86 {
87 *res_msg = at_err_build(ATERR_PARAM_INVALID);
88 *res_msglen = strlen(*res_msg);
89 return AT_END;
90 }
91
92 sc_cfg_get("LanEnable", strCfgGetItem, sizeof(strCfgGetItem));
93
94 if(0==strcmp(strCfgGetItem,""))
95 {
96 *res_msg = at_err_build(ATERR_PROC_FAILED);
97 *res_msglen = strlen(*res_msg);
98 return AT_END;
99 }
100
101 iOldLanEnable = atoi(strCfgGetItem);
102
103 if(iOldLanEnable != iLanEnable)
104 {
105 if(iLanEnable == 0)
106 {
107 sc_cfg_set("LanEnable","0");
108 sc_cfg_set("usblan", "");
109 sc_cfg_set("need_jilian", "1");
110 sc_cfg_set("need_init_modem","no");
111 sc_cfg_set("boot_prj","mdl");
112 //sc_cfg_set("cid_reserved","3");
113 }
114 else if(iLanEnable == 1)
115 {
116 sc_cfg_set_ufi_state();
117
118 sc_cfg_set("boot_prj","mifi");
119 }
120 else if(iLanEnable == 2)
121 {
122 sc_cfg_set_ufi_state();
123
124 sc_cfg_set("boot_prj","cpe");
125 }
126 else if(iLanEnable == 3)
127 {
128 sc_cfg_set_ufi_state();
129
130 sc_cfg_set("boot_prj","evb");
131 }
132
133 // sc_cfg_save();
134 }
135
136 *res_msg = at_query_result_build("ZLANENABLE",at_paras);
137 *res_msglen = strlen(*res_msg);
138
139 //ģʽÇл»ºó·¢ËÍÏûÏ¢¸øÖ÷¿ØÖØÆô
140 ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL,0);
141
142 return AT_END;
143}
144
145int zmode_req_rcv_act(char *at_paras,int at_fd,struct at_context *context)
146{
147 char* err_str = NULL;
148 int32_t iUsbMode = 0;
149
150 at_print(AT_DEBUG, "at_str = %s\n", at_paras);
151
152 get_at_cmd_param_int(at_paras, &iUsbMode, &at_paras);
153 at_print(AT_DEBUG, "iUsbMode == %d\n", iUsbMode);
154 switch(iUsbMode)
155 {
156 case 0:
157 {
158 nv_set_item(NV_RO,"usb_modetype", "user",1);
159 break;
160 }
161 case 1:
162 {
163 nv_set_item(NV_RO,"usb_modetype", "debug",1);
164 break;
165 }
166 case 2:
167 {
168 nv_set_item(NV_RO,"usb_modetype", "factory",1);
169 break;
170 }
171 case 3:
172 {
173 nv_set_item(NV_RO,"usb_modetype", "amt",1);
174 break;
175 }
176 default:
177 {
178 err_str = at_err_build(ATERR_PARAM_INVALID);
179 at_write(context->at_channel->at_fd, err_str, strlen(err_str));
180 free(err_str);
181 return AT_END;
182 }
183 }
184 nv_commit(NV_RO);
185
186 context->app_param = (void*)malloc(sizeof(iUsbMode)+1);
187 if(context->app_param == NULL){softap_assert("");return AT_END;}
188 memset(context->app_param, 0, sizeof(iUsbMode)+1);
189 sprintf(context->app_param, "%d", iUsbMode);
190
191 return AT_CONTINUE;
192}
193
194int zmodeGet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
195{
196 int32_t setResult = 0;
197 char strCfgGetItem[AT_CMD_MAX] = {0};
198 int tmp = -1;
199
200 nv_get_item(NV_RO, "usb_modetype", strCfgGetItem, sizeof(strCfgGetItem));
201 at_print(AT_DEBUG,"zmodeGet_req:strCfgGetItem = %s\n", strCfgGetItem);
202
203 if(!strcmp(strCfgGetItem,"user"))
204 {
205 *res_msg = at_query_result_build("ZMODE","0");
206 }
207 else if(!strcmp(strCfgGetItem,"debug"))
208 {
209 *res_msg = at_query_result_build("ZMODE","1");
210 }
211 else if(!strcmp(strCfgGetItem,"factory"))
212 {
213 *res_msg = at_query_result_build("ZMODE","2");
214 }
215 else if(!strcmp(strCfgGetItem,"amt"))
216 {
217 *res_msg = at_query_result_build("ZMODE","3");
218 }
219 else
220 {
221 *res_msg = at_err_build(ATERR_PROC_FAILED);
222 }
223 *res_msglen = strlen(*res_msg);
224
225 return AT_END;
226}
227
228int plugoutSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
229{
230 int32_t iPlutout = 0;
231 char* at_str = NULL;
232
233 if(at_paras==NULL)
234 softap_assert("zmodeSet_req:at_paras is null");
235
236 at_str = at_paras;
237 get_at_cmd_param_int(at_str, &iPlutout, &at_str);
238 at_print(AT_DEBUG,"zmodeSet_rsq:iUsbMode == %d\n", iPlutout);
239
240 switch(iPlutout)
241 {
242 case 0:
243 {
244 writefile(USB_HOTPLUG_FILE_NAME,"0",1);
245 break;
246 }
247 case 1:
248 {
249 writefile(USB_HOTPLUG_FILE_NAME,"1",1);
250 break;
251 }
252 default:
253 {
254 *res_msg = at_err_build(ATERR_PARAM_INVALID);
255 *res_msglen = strlen(*res_msg);
256 return AT_END;
257 }
258 }
259
260 *res_msg = at_ok_build();
261 *res_msglen = strlen(*res_msg);
262
263 return AT_END;
264}
265
266int znetcardtypeSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
267{
268 int32_t iNetcardType = 0;
269 int32_t iResult = 0;
270 char* at_str = NULL;
271
272 if(at_paras==NULL)
273 softap_assert("znetcardtypeSet_req:at_paras is null");
274
275 at_str = at_paras;
276 at_print(AT_DEBUG,"znetcardtypeSet_rsq: come in.\n");
277 get_at_cmd_param_int(at_str, &iNetcardType, &at_str);
278 at_print(AT_DEBUG,"znetcardtypeSet_rsq:iNetcardType == %d\n", iNetcardType);
279
280 switch(iNetcardType)
281 {
282 case 0:
283 {
284 nv_set_item(NV_RO,"forcenetcard_type", "force_ndis",1);
285 break;
286 }
287 case 1:
288 {
289 nv_set_item(NV_RO,"forcenetcard_type", "force_ecm",1);
290 break;
291 }
292 case 2:
293 {
294 nv_set_item(NV_RO,"forcenetcard_type", "force_mbim",1);
295 break;
296 }
297 case 3:
298 {
299 nv_set_item(NV_RO,"forcenetcard_type", "force_rndis",1);
300 break;
301 }
302 default:
303 {
304 *res_msg = at_err_build(ATERR_PARAM_INVALID);
305 *res_msglen = strlen(*res_msg);
306 return AT_END;
307 }
308 }
309 nv_commit(NV_RO);
310
311 *res_msg = at_ok_build();
312 *res_msglen = strlen(*res_msg);
313
314 return AT_END;
315}
316
317int znetcardtypeGet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
318{
319 int32_t setResult = 0;
320 char strCfgGetItem[AT_CMD_MAX] = {0};
321 int tmp = -1;
322
323 nv_get_item(NV_RO, "forcenetcard_type", strCfgGetItem, sizeof(strCfgGetItem));
324 at_print(AT_DEBUG,"znetcardtypeGet_req:strCfgGetItem = %s\n", strCfgGetItem);
325
326 if(!strcmp(strCfgGetItem,"force_ndis"))
327 {
328 *res_msg = at_query_result_build("CARDTYPE","force_ndis");
329 }
330 else if(!strcmp(strCfgGetItem,"force_ecm"))
331 {
332 *res_msg = at_query_result_build("CARDTYPE","force_ecm");
333 }
334 else if(!strcmp(strCfgGetItem,"force_mbim"))
335 {
336 *res_msg = at_query_result_build("CARDTYPE","force_mbim");
337 }
338 else if(!strcmp(strCfgGetItem,"force_rndis"))
339 {
340 *res_msg = at_query_result_build("CARDTYPE","force_rndis");
341 }
342 else
343 {
344 *res_msg = at_err_build(ATERR_PROC_FAILED);
345 }
346 *res_msglen = strlen(*res_msg);
347
348 return AT_END;
349}
350
351int zusbmodeSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
352{
353 int32_t iUsbMode = 0;
354 char* at_str = NULL;
355
356 if(at_paras==NULL)
357 softap_assert("zusbmodeSet_req:at_paras is null");
358
359 at_str = at_paras;
360 get_at_cmd_param_int(at_str, &iUsbMode, &at_str);
361 at_print(AT_DEBUG,"zusbmodeSet_req:iUsbMode == %d\n", iUsbMode);
362
363 switch(iUsbMode)
364 {
365 case 0:
366 {
367 nv_set_item(NV_RO,"usb_modetype", "user",1);
368 break;
369 }
370 case 1:
371 {
372 nv_set_item(NV_RO,"usb_modetype", "debug",1);
373 break;
374 }
375 case 2:
376 {
377 nv_set_item(NV_RO,"usb_modetype", "factory",1);
378 break;
379 }
380 case 3:
381 {
382 nv_set_item(NV_RO,"usb_modetype", "amt",1);
383 break;
384 }
385 default:
386 {
387 *res_msg = at_err_build(ATERR_PARAM_INVALID);
388 *res_msglen = strlen(*res_msg);
389 return AT_END;
390 }
391 }
392 nv_commit(NV_RO);
393
394 *res_msg = at_ok_build();
395 *res_msglen = strlen(*res_msg);
396
397 return AT_END;
398}
399
400int znvset_req_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
401{
402 char *strch = at_paras;
403 char *p[4] = {0};
404 char nv_name[NV_NAME_LEN] = {0};
405 char nv_value[1024] = {0};
406 int i = 0;
407 if(at_paras == NULL)
408 {
409 *res_msg = at_err_build(ATERR_PARAM_INVALID);
410 *res_msglen = strlen(*res_msg);
411 return AT_END;
412 }
413 for(i=0; i < 4; i++)
414 {
415 strch = strchr(strch, '"');
416 p[i] = strch;
417 if(strch == NULL)
418 {
419 *res_msg = at_err_build(ATERR_PARAM_INVALID);
420 *res_msglen = strlen(*res_msg);
421 return AT_END;
422 }
423 strch++;
424 }
425 memcpy(nv_name, p[0]+1, (int)(p[1]-p[0]-1));
426 memcpy(nv_value,p[2]+1, (int)(p[3]-p[2]-1));
427
428 sc_cfg_set(nv_name, nv_value);
429 sc_cfg_save();
430
431 at_print(AT_DEBUG,"znvset_req_func name=%s value=%s\n", nv_name, nv_value);
432 *res_msg = at_ok_build();
433 *res_msglen = strlen(*res_msg);
434 return AT_END;
435}
436
437int znvget_req_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
438{
439 char *strch = at_paras;
440 char nv_name[NV_NAME_LEN] = {0};
441 char nv_value[1024] = {0};
442 char *p[2] = {0};
443 int i = 0;
444 if(at_paras == NULL)
445 {
446 *res_msg = at_err_build(ATERR_PARAM_INVALID);
447 *res_msglen = strlen(*res_msg);
448 return AT_END;
449 }
450 for(i=0; i < 2; i++)
451 {
452 strch = strchr(strch, '"');
453 p[i] = strch;
454 if(strch == NULL)
455 {
456 *res_msg = at_err_build(ATERR_PARAM_INVALID);
457 *res_msglen = strlen(*res_msg);
458 return AT_END;
459 }
460 strch++;
461 }
462 memcpy(nv_name, p[0]+1, (int)(p[1]-p[0]-1));
463 sc_cfg_get(nv_name, nv_value, sizeof(nv_value));
464 strch = malloc(strlen(nv_name)+strlen(nv_value)+32);
465 if(strch == NULL) {softap_assert("");return AT_END;}
466 sprintf(strch,"\"%s\",\"%s\"",nv_name, nv_value);
467 *res_msg = at_query_result_build("znvget",strch);
468 *res_msglen = strlen(*res_msg);
469 free(strch);
470 strch = NULL;
471 return AT_END;
472}
473
474/* ͨ¹ýAT ¿Ú½øÐÐshellÃüÁîµ÷ÊÔ*/
475int ext_atshell_req(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
476{
477 char* cmd = NULL;
478 char *at_str = NULL;
479 int len = strlen(at_paras)+1;
480 cmd = malloc(len);
481 if(cmd == NULL){softap_assert("");return AT_END;}
482 memset(cmd,0,len);
483 memcpy(cmd, at_paras, len-1);
484 soft_system(cmd);
485 at_str = at_ok_build();
486 *res_msg = at_str;
487 *res_msglen = strlen(at_str);
488 free(cmd);
489 return AT_END;
490}
491
492int ext_pcfc_set_func(char *at_paras,int at_fd,struct at_context *context)
493{
494 int flag = 0;
495 void *p[1] = {&flag};
496 int ret = 0;
497 char* rspStr = NULL;
498 char strCfgGetItem[AT_CMD_MAX] = {0};
499 int iOldLanEnable = 0;
500 int iLanEnable = 0;
501 UINT8 phoneModeStatus = 0;
502 UINT32 retCode = CPNV_ERROR;
503
504 ret = parse_param("%d", at_paras, p);
505 if (ret != AT_PARSE_OK) // cov M
506 {
507 return AT_END;
508 }
509
510 retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
511 if(retCode == CPNV_ERROR)
512 {
513 // todo: cov m
514 }
515 sc_cfg_get("LanEnable", strCfgGetItem, sizeof(strCfgGetItem));
516 if(0==strcmp(strCfgGetItem,""))
517 {
518 rspStr = at_err_build(ATERR_PROC_FAILED);
519 at_write(context->at_channel->at_fd, rspStr, strlen(rspStr));
520 free(rspStr);
521 return AT_END;
522 }
523 iOldLanEnable = atoi(strCfgGetItem);
524
525 if ((1 <= flag)&&(3 >= flag)){
526 phoneModeStatus = (0x1 | phoneModeStatus); // ºóһλ1±íʾÊÇ´¿modem°æ±¾
527 sc_cfg_set("version_mode","1"); //version_mode==1 phonemode==0 Ϊ´¿modem°æ±¾
528 ret = cpnv_NvItemWrite(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
529 if(ret == CPNV_ERROR){softap_assert("");}
530 ret = cpnv_NvramFlush();
531 if(ret == CPNV_ERROR){softap_assert("");}
532
533 iLanEnable = 0;
534 //sc_cfg_set("cid_reserved","15");
535 sc_cfg_set("cid_reserved","255");
536 if(iOldLanEnable != iLanEnable)
537 {
538 sc_cfg_set("LanEnable","0");
539 sc_cfg_set("usblan", "");
540 sc_cfg_set("need_jilian", "1");
541 sc_cfg_set("need_init_modem","no");
542 sc_cfg_set("boot_prj","mdl");
543
544 //sc_cfg_save();
545 }
546 sc_cfg_save();
547 return AT_CONTINUE;
548 }
549 else
550 {
551 //rspStr = at_err_build(ATERR_PARAM_INVALID);
552 //at_write(context->at_channel->at_fd, rspStr, strlen(rspStr));
553 //free(rspStr);
554 //return AT_END;
555 return AT_CONTINUE;
556 }
557}
558
559int ext_is_usermode(void)
560{
561 char strCfgGetItem[16] = {0};
562
563 nv_get_item(NV_RO, "usb_modetype", strCfgGetItem, sizeof(strCfgGetItem));
564 return !strcmp(strCfgGetItem,"user");
565}
566
567#ifndef CONFIG_MIN_8M_VERSION
568int ztelnetSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
569{
570 char* at_str = NULL;
571 int32_t user_cmd = 0;
572 char enable_flag[AT_CMD_MAX] = {0};
573
574 sc_cfg_get("telnetd_enable", enable_flag, sizeof(enable_flag));
575
576 if(at_paras==NULL)
577 softap_assert("ztelnetSet_req:at_paras is null");
578
579 at_str = at_paras;
580 get_at_cmd_param_int(at_str, &user_cmd, &at_str);
581 at_print(AT_DEBUG,"zlanenableSet_rsq:user_cmd == %d\n", user_cmd);
582
583 switch(user_cmd)
584 {
585 case 0:
586 if (0 == strcmp(enable_flag, "y"))
587 {
588 system("killall -9 telnetd");
589 sc_cfg_set("telnetd_enable", "n");
590 //sc_cfg_save();
591 }
592 *res_msg = at_query_result_build("ZTELNET","0");
593 break;
594 case 1:
595 if (0 == strcmp(enable_flag, "n"))
596 {
597 system("/usr/sbin/telnetd -p 4719");
598 sc_cfg_set("telnetd_enable", "y");
599 //sc_cfg_save();
600 }
601 system("adbd &");
602 *res_msg = at_query_result_build("ZTELNET","1");
603 break;
604 default:
xf.libdd93d52023-05-12 07:10:14 -0700605 at_print(AT_DEBUG,"lnetSet_rsp:: invaild user_cmd == %d\n", user_cmd);
lh9ed821d2023-04-07 01:36:19 -0700606 *res_msg = at_err_build(ATERR_PARAM_INVALID);
607 }
608
609 *res_msglen = strlen(*res_msg);
610
611 return AT_END;
612}
613
614int ztelnetGet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
615{
616 char enable_flag[2] = {0};
617
618 sc_cfg_get("telnetd_enable", enable_flag, sizeof(enable_flag));
619 if (0 == strcmp(enable_flag, "y"))
620 {
621 *res_msg = at_query_result_build("ZTELNET","1");
622 }
623 else if (0 == strcmp(enable_flag, "n"))
624 {
625 *res_msg = at_query_result_build("ZTELNET","0");
626 }
627 else
628 {
629 *res_msg = at_err_build(ATERR_PROC_FAILED);
630 }
631 *res_msglen = strlen(*res_msg);
632
633 return AT_END;
634}
635
636int zppptatusGet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
637{
638 int32_t state = 0;
639 char pdpState[AT_CMD_MAX] = {0};
640
641 sc_cfg_get("ppp_pdpstate", pdpState, sizeof(pdpState));
642 if(strcmp(pdpState, "working") == 0)
643 {
644 *res_msg = at_query_result_build("ZPPPSTATUS","1");
645 }
646 else
647 {
648 *res_msg = at_query_result_build("ZPPPSTATUS","0");
649 }
650 *res_msglen = strlen(*res_msg);
651
652 return AT_END;
653}
654
655int salestatSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
656{
657 int32_t iEnable = 0;
658 char *at_str = NULL;
659
660 if(at_paras==NULL)
661 softap_assert("salestatSet_req:at_paras is null");
662
663 at_str = at_paras;
664 get_at_cmd_param_int(at_str, &iEnable, &at_str);
665 at_print(AT_DEBUG,"salestatSet_rsq:str_saleType == %d\n", iEnable);
666
667 if(0 == iEnable)
668 {
669 sc_cfg_set("sale_stat_on","no");
670
671 }
672 else if(1 == iEnable)
673 {
674 sc_cfg_set("sale_stat_on","yes");
675 }
676 else
677 {
678 *res_msg = at_err_build(ATERR_PARAM_INVALID);
679 *res_msglen = strlen(*res_msg);
680 return AT_END;
681 }
682
683 *res_msg = at_ok_build();
684 *res_msglen = strlen(*res_msg);
685
686 return AT_END;
687}
688
689int salestatGet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
690{
691 char salestatState[AT_CMD_MAX] = {0};
692
693 sc_cfg_get("sale_stat_on", salestatState, sizeof(salestatState));
694// at_print(AT_DEBUG,"salestatGet_req ret salestatState= %s.\n",salestatState);
695
696 if (0 == strcmp(salestatState, "yes"))
697 {
698 *res_msg = at_query_result_build("SALESTAT","1");
699 }
700 else if(0 == strcmp(salestatState, "no"))
701 {
702 *res_msg = at_query_result_build("SALESTAT","0");
703 }
704 else
705 {
706 *res_msg = at_err_build(ATERR_PROC_FAILED);
707 }
708
709 *res_msglen = strlen(*res_msg);
710
711 return AT_END;
712}
713
714int zerrSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
715{
716 int32_t err = 0;
717 int32_t iResult = 0;
718 char* at_str = NULL;
719
720 if(at_paras==NULL)
721 softap_assert("zerrSet_req:at_paras is null");
722
723 at_str = at_paras;
724 get_at_cmd_param_int(at_str, &err, &at_str);
725
726 //at_print(1,"[ERR]zerrSet_req:err = %d\n",err);
727
728 zxic_err_track(err);
729
730 *res_msg = at_ok_build();
731 *res_msglen = strlen(*res_msg);
732
733 return AT_END;
734}
735
736int zautorspSet_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
737{
738 char channel_value[50] = {0};
739
740 if(at_paras==NULL){
741 softap_assert("zautorspSet_req:at_paras is null");
742 return AT_END;
743 }
744 if(strstr(at_paras, "all") != NULL)
745 {
746 sc_cfg_set("autorspchannel_list", "all");
747 }
748 else if(strstr(at_paras, "none") != NULL)
749 {
750 sc_cfg_set("autorspchannel_list", "none");
751 }
752 else
753 {
754 char *pchar = strchr(at_paras,'\0');
755 if(pchar == NULL)
756 softap_assert("");
757
758 memset(channel_value, 0, sizeof(channel_value));
759 if((pchar-at_paras) > 0 && (pchar-at_paras)< sizeof(channel_value))
760 memcpy(channel_value, at_paras, (int)(pchar-at_paras));
761 sc_cfg_set("autorspchannel_list",channel_value);
762 }
763 sc_cfg_save();
764#ifdef MULTI_CPU
765 sync_appointed_nv(NEAR_PS, "autorspchannel_list");
766#endif
767 *res_msg = at_ok_build();
768 *res_msglen = strlen(*res_msg);
769 return AT_END;
770}
771
772
773//AT+ZISSENDAUTO=1±íʾ¿ªat_fdͨµÀµÄÖ÷¶¯Éϱ¨£¬0±íʾ¹Ø±Õ
774int modAutoInd_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
775{
776 struct at_channel_info * at_channel = at_context_find_chn_by_fd(at_fd);
777 if(at_channel){
778 if('1' == at_paras[0])
779 {
780 at_channel->attribution &= 0xFE;
781 }
782 else if('0' == at_paras[0])
783 {
784 at_channel->attribution |= (1<<CH_AUTOIND);
785 }
786 }
787 *res_msg = at_ok_build();
788 *res_msglen = strlen(*res_msg);
789
790 return AT_END;
791}
792
793int ext_softap_info_req(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
794{
795 char *at_str = NULL;
796 char lan_enable[NV_NAME_LEN] = {0};
797 char need_init_modem[NV_NAME_LEN] = {0};
798 char cid_reserved[NV_NAME_LEN] = {0};
799
800 at_str = malloc(AT_CMD_MAX);
801 if(at_str == NULL)
802 {
803 softap_assert("");
804 return AT_END;
805 }
806 memset(at_str, 0, AT_CMD_MAX);
807 sc_cfg_get("LanEnable", lan_enable, sizeof(lan_enable));
808 sc_cfg_get("need_init_modem", need_init_modem, sizeof(need_init_modem));
809 sc_cfg_get("cid_reserved", cid_reserved, sizeof(cid_reserved));
810
811 sprintf(at_str+strlen(at_str), "\r\nLanEnable=%s\r\n", lan_enable);
812 sprintf(at_str+strlen(at_str), "\r\nneed_init_modem=%s\r\n", need_init_modem);
813 sprintf(at_str+strlen(at_str), "\r\cid_reserved=%s\r\n", cid_reserved);
814 sprintf(at_str+strlen(at_str), "\r\nOK\r\n");
815
816 *res_msg = at_str;
817 *res_msglen = strlen(at_str);
818 return AT_END;
819}
820
821
822/*
823 * Function: int redirect_console(int redirect)
824 * Param: int redirect
825 * 1: to redirect
826 * 0: reset to console
827 * Return value:
828 * 0: success; -1: error.
829 */
830int redirect_console(int redirect)
831{
832#if (APP_OS_TYPE == APP_OS_LINUX)
833
834 int fp = 0;
835 int ret = 0;
836 char rd_name[128] = {0};
837
838 if(redirect)
839 strcpy(rd_name, "/dev/ttyGS0");
840 else
841 strcpy(rd_name, "/dev/console");
842
843 fp = open(rd_name, O_RDWR);
844 if(fp < 0)
845 {
846 printf("Open %s(fp=%d) failed!\n", rd_name, fp);
847 return -1;
848 }
849 printf("tty_redirect:fd=%d\n", fp);
850
851 ret = ioctl(fp, TIOCCONS);
852 printf("tty_redirect:ret=%d\n", ret);
853
854 close(fp);
855
856 fp = open("/dev/console", O_RDWR);
857 if(fp < 0)
858 {
859 return -1;
860 }
861 dup2(fp, 1);
862 close(fp);
863
864 return 0;
865#endif
866}
867
868
869/* ½«LOGÊä³öµ½ATͨµÀÉÏ */
870int ext_log_stdout_req(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
871{
872 char *at_str = NULL;
873 int opt = 0;
874 void *p[1] = {&opt};
875
876 parse_param2("%d", at_paras, p);
877
878 if (1 != strlen(at_paras) || opt < 0 || opt > 1)
879 {
880 *res_msg = at_err_build(ATERR_PARAM_INVALID);
881 *res_msglen = strlen(*res_msg);
882 return AT_END;
883 }
884
885 redirect_console(opt);
886
887 at_str = at_ok_build();
888
889 *res_msg = at_str;
890 *res_msglen = strlen(at_str);
891 return AT_END;
892}
893
894
895/* ͨ¹ýÀ©Õ¹ÃüÁîÉèÖÃÍⲿMCUÐèÒªµÄÖ÷¶¯Éϱ¨ÃüÁî*/
896int zindcmd_set_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
897{
898 if (strlen(at_paras)>= NV_MAX_VAL_LEN)
899 {
900 *res_msg = at_err_build(ATERR_PARAM_INVALID);
901 }
902 else
903 {
904 if(strlen(at_paras) == 0)
905 sc_cfg_set("customIndCmdList","");
906 else
907 sc_cfg_set("customIndCmdList",at_paras);
908 sc_cfg_save();
909 *res_msg = at_ok_build();
910
911 }
912
913 *res_msglen = strlen(*res_msg);
914
915 return AT_END;
916}
917
918int ext_worklock_set_func(char *at_paras, void ** res_msg)
919{
920 int i = 0;
921 unsigned long result = 0; // cov M
922 //ÅжϲÎÊýÊÇ·ñÊÇÊ®Áù½øÖÆÊý
923 for(;i<strlen(at_paras);i++)
924 {
925 if(isxdigit(at_paras[i]) == 0)
926 {
927 goto ERROR_PROC;
928 }
929 }
930 errno = 0;
931 result = strtoul(at_paras,0,16);//½«16½øÖƵÄ×Ö·û´®×ª»»³É³¤ÕûÐÎÊý
932 if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
933 {
934 at_print(AT_ERR, "strtoul errno %d: %s\n", errno, strerror(errno));
935 }
936 if(result == 0)//ÊÍ·ÅËø
937 {
938 if(set_wake_unlock(AP_WORK_LOCK) == 0)//ÊÍ·ÅËø²Ù×÷³É¹¦·µ»Øok
939 return AT_END;
940 else
941 {
942 *res_msg = at_err_build(ATERR_PROC_FAILED);
943 return AT_END;
944 }
945 }
946 else if(result>0 && result<0xFFFF)//ÉèÖó¬Ê±Ëø
947 {
948 //µ÷ÓÃÉèÖó¬Ê±ËøµÄ½Ó¿Ú
949 if(set_wake_lock_timeout(AP_WORK_LOCK,result) == 0)//ÉèÖó¬Ê±Ëø³É¹¦·µ»Øok
950 return AT_END;
951 else
952 {
953 *res_msg = at_err_build(ATERR_PROC_FAILED);
954 return AT_END;
955 }
956 }
957 else if(result == 0xFFFF)//ÉèÖÃÆÕÍ¨Ëø
958 {
959 if(set_wake_lock(AP_WORK_LOCK) == 0)//ÉèÖÃËø²Ù×÷³É¹¦·µ»Øok
960 return AT_END;
961 else
962 {
963 *res_msg = at_err_build(ATERR_PROC_FAILED);
964 return AT_END;
965 }
966 }
967ERROR_PROC:
968 //ÎÞЧµÄ²ÎÊýÖµ£¬·µ»Ø´íÎó
969 *res_msg = at_err_build(ATERR_PARAM_INVALID);
970 return AT_END;
971}
972
973
974//#ifdef _ENABLE_AUTOTEST
975#define KPD_PATH "/dev/event0"
976
977#define LED_WAN_RED_BRIGHTNESS "/sys/class/leds/modem_r_led/brightness"
978#define LED_WAN_RED_BLINKTIMEON "/sys/class/leds/modem_r_led/delay_on"
979
980#define LED_WAN_BLUE_BRIGHTNESS "/sys/class/leds/modem_b_led/brightness"
981#define LED_WAN_BLUE_BLINKTIMEON "/sys/class/leds/modem_b_led/delay_on"
982
983#define LED_WAN_GREEN_BRIGHTNESS "/sys/class/leds/modem_g_led/brightness"
984#define LED_WAN_GREEN_BLINKTIMEON "/sys/class/leds/modem_g_led/delay_on"
985
986#define LED_BATTERY_GREEN_BRIGHTNESS "/sys/class/leds/battery_g_led/brightness"
987#define LED_BATTERY_GREEN_BLINKTIMEON "/sys/class/leds/battery_g_led/delay_on"
988
989#define LED_BATTERY_RED_BRIGHTNESS "/sys/class/leds/battery_r_led/brightness"
990#define LED_BATTERY_RED_BLINKTIMEON "/sys/class/leds/battery_r_led/delay_on"
991
992#define LED_SMS_BLUE_BRIGHTNESS "/sys/class/leds/sms_led/brightness"
993#define LED_SMS_BLUE_BLINKTIMEON "/sys/class/leds/sms_led/delay_on"
994
995#define LED_LAN_BLUE_BRIGHTNESS "/sys/class/leds/wifi_led/brightness"
996#define LED_LAN_BLUE_BLINKTIMEON "/sys/class/leds/wifi_led/delay_on"
997
998static int readfile(const char *path, char * buf, int len)
999{
1000 FILE *fp = NULL;
1001 int cnt = -1;;
1002
1003 if (NULL == path || NULL == buf)
1004 return -1;
1005
1006 if ( (fp = fopen (path, "rb")) == NULL) {
1007 at_print(AT_ERR, "%s can not be open\n", path);
1008 cnt = -1;
1009 goto err;
1010 }
1011
1012 cnt = fread (buf, 1, len, fp);
1013 if (cnt < 0) {
1014 at_print(AT_ERR, "%s read failed \n", path);
1015 cnt = -1;
1016 goto err;
1017 }
1018err:
1019 if (fp != NULL)
1020 fclose(fp);
1021 return cnt;
1022}
1023
1024static int autotest_led_get(char *fileled, char *fileact)
1025{
1026 int ledstat_i = 0;
1027 char ledstat_s[4] = {0};
1028
1029 if (access(fileact, F_OK) == 0){
1030 ledstat_i = 2;
1031 } else {
1032 readfile(fileled, ledstat_s, sizeof(ledstat_s) - 1);
1033 ledstat_i = atoi(ledstat_s);
1034 }
1035
1036 return ledstat_i;
1037}
1038
1039/*
1040AT+KEYEVENT=<code>,<value>
1041code: 116 POWER; 117 WPS; 118 RESET;
1042value: 0 up; 1 down; 2 long press;
1043
1044AT+TKEYEVENT=116,1
1045OK
1046AT+TKEYEVENT=116,0
1047OK
1048AT+TKEYEVENT=117,1
1049OK
1050sleep:4
1051AT+TKEYEVENT=117,2
1052OK
1053+TKEYEVENT: WPS ACTIVED
1054AT+TKEYEVENT=117,0
1055OK
1056*/
1057int autotest_keyset_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen)
1058{
1059 autotest_key_rspmsg param = {0};
1060 CHAR *p[2] = {&param.code, &param.value};
1061 int fd = -1;
1062 struct input_event event = {0};
1063 unsigned char *buf = NULL;
1064
1065 parse_param2("%d,%d", at_paras, p);
1066 at_print(AT_NORMAL, "autotest_keyset_req key code:%d,value:%d\n",param.code,param.value);
1067
1068 buf = malloc(sizeof(struct input_event));
1069 if(buf == NULL) {
1070 *res_msg = at_err_build(ATERR_PROC_FAILED);
1071 *res_msglen = strlen(*res_msg);
1072 return AT_END;
1073 }
1074
1075 fd = open(KPD_PATH, O_WRONLY|O_SYNC);
1076 if (fd == -1) {
1077 free(buf);
1078 *res_msg = at_err_build(ATERR_PROC_FAILED);
1079 *res_msglen = strlen(*res_msg);
1080 return AT_END;
1081 }
1082
1083 event.type = 1; //EV_KEY
1084 event.code = (unsigned short)param.code;
1085 event.value = param.value;
1086 memcpy(buf, &event, sizeof(struct input_event));//klocwork
1087 if (write(fd, /*&event*/buf, sizeof(struct input_event)) != sizeof(struct input_event)) {
1088 close(fd);
1089 free(buf);
1090 *res_msg = at_err_build(ATERR_PROC_FAILED);
1091 *res_msglen = strlen(*res_msg);
1092 return AT_END;
1093 }
1094 event.type = 0; //EV_SYN
1095 event.code = 0;
1096 event.value = 0;
1097 memcpy(buf, &event, sizeof(struct input_event));//klocwork
1098 if (write(fd, /*&event*/buf, sizeof(struct input_event)) != sizeof(struct input_event)) {
1099 close(fd);
1100 free(buf);
1101 *res_msg = at_err_build(ATERR_PROC_FAILED);
1102 *res_msglen = strlen(*res_msg);
1103 return AT_END;
1104 }
1105 close(fd);
1106 free(buf);
1107
1108 *res_msg = at_ok_build();
1109 *res_msglen = strlen(*res_msg);
1110 return AT_END;
1111#if 0
1112 autotest_key_rspmsg *param = malloc(sizeof(autotest_key_rspmsg));
1113 assert(param);
1114 CHAR *p[2] = {&param->code,&param->value};
1115
1116 memset(param, 0, sizeof(autotest_key_rspmsg));
1117 parse_param2("%d,%d", at_paras, p);
1118 at_print(AT_NORMAL, "autotest_keyset_req key code:%d,value:%d\n",param->code,param->value);
1119
1120 *res_msg = param;
1121 *res_msglen = sizeof(autotest_key_rspmsg);
1122 return AT_END_AND_MSG;
1123#endif
1124}
1125/*
1126AT+TCPUSTATUS?
1127+TCPUSTATUS: 0.0% USR 9.0% SYS 0.0% NIC 90.9% IDLE 0.0% IO 0.0% IRQ 0.0% SIRQ
1128OK
1129*/
1130int autotest_cpuget_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1131{
1132 char *tmp_str = NULL;
1133
1134 tmp_str = malloc(AT_CMD_MAX);
1135 if (tmp_str != NULL) {
1136 char *cpu_ptr = NULL;
1137 char *cpu_end = NULL;
1138 system("top -n 1 > /tmp/cputop");
1139 memset(tmp_str, 0, AT_CMD_MAX);
1140 readfile("/tmp/cputop", tmp_str, AT_CMD_MAX - 1);
1141 tmp_str[AT_CMD_MAX - 1] = '\0';
1142 if ((cpu_ptr = strstr(tmp_str, "CPU: ")) != NULL &&
1143 (cpu_end = strstr(tmp_str, "\nLoad average:")) != NULL) {
1144 cpu_ptr += strlen("CPU: ");
1145 *cpu_end = 0;
1146 *res_msg = at_query_result_build("TCPUSTATUS",cpu_ptr);
1147 } else {
1148 *res_msg = at_err_build(ATERR_PROC_FAILED);
1149 }
1150
1151 free(tmp_str);
1152 } else {
1153 *res_msg = at_err_build(ATERR_MEM_LESS);
1154 }
1155 if(*res_msg)
1156 *res_msglen = strlen(*res_msg);
1157 return AT_END;
1158}
1159
1160/*+TLEDSTATUS: <tpye>,<stat>,<color>;...
1161tpye: 0 battery; 1 network; 2 sms; 3 wifi
1162stat: 0 off; 1 on; 2 blink
1163color: 0 null/off; 1 red; 2 green; 3 blue;
1164
1165AT+TLEDSTATUS?
1166+TLEDSTATUS: 0,1,2;1,0,0;2,0,0;3,0,0
1167OK
1168*/
1169int autotest_ledget_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1170{
1171 char led_str[36] = {0};
1172 int ledstat = 0;
1173 int ledcolor = 0;
1174 int len = 0;
1175 //char *net_led = LED_WAN_BLUE_BRIGHTNESS;
1176 //char *net_act = LED_WAN_BLUE_BLINKTIMEON;
1177 int net_color = 3;
1178 char cus_type[20] = {0};
1179
1180 sc_cfg_get("customer_type",cus_type,sizeof(cus_type));
1181 /*
1182 if(0 == strcmp(cus_type, "sdk_min")) {
1183 net_led = LED_WAN_GREEN_BRIGHTNESS;
1184 net_act = LED_WAN_GREEN_BLINKTIMEON;
1185 net_color = 2;
1186 }
1187 */
1188 //battery
1189 ledstat = autotest_led_get(LED_BATTERY_GREEN_BRIGHTNESS, LED_BATTERY_GREEN_BLINKTIMEON);
1190 if (ledstat) {
1191 ledcolor = 2;
1192 } else {
1193 ledstat = autotest_led_get(LED_BATTERY_RED_BRIGHTNESS, LED_BATTERY_RED_BLINKTIMEON);
1194 if (ledstat) {
1195 ledcolor = 1;
1196 }
1197 }
1198 len = strlen(led_str);
1199 snprintf(led_str + len, sizeof(led_str) - len, "0,%d,%d;", ledstat, ledcolor);
1200
1201 //network
1202 ledcolor = 0;
1203 //ledstat = autotest_led_get(net_led, net_act);
1204 if(0 == strcmp(cus_type, "sdk_min")) {
1205 ledstat = autotest_led_get(LED_WAN_GREEN_BRIGHTNESS, LED_WAN_GREEN_BLINKTIMEON);
1206 net_color = 2;
1207 }// kw OVERWRITE_CONST_CHAR
1208 else
1209 {
1210 ledstat = autotest_led_get(LED_WAN_BLUE_BRIGHTNESS, LED_WAN_BLUE_BLINKTIMEON);
1211 }
1212 if (ledstat) {
1213 ledcolor = net_color;
1214 } else {
1215 ledstat = autotest_led_get(LED_WAN_RED_BRIGHTNESS, LED_WAN_RED_BLINKTIMEON);
1216 if (ledstat) {
1217 ledcolor = 1;
1218 }
1219 }
1220 len = strlen(led_str);
1221 snprintf(led_str + len, sizeof(led_str) - len, "1,%d,%d;", ledstat, ledcolor);
1222
1223 //sms
1224 ledcolor = 0;
1225 ledstat = autotest_led_get(LED_SMS_BLUE_BRIGHTNESS, LED_SMS_BLUE_BLINKTIMEON);
1226 if (ledstat) {
1227 ledcolor = net_color;
1228 }
1229 len = strlen(led_str);
1230 snprintf(led_str + len, sizeof(led_str) - len, "2,%d,%d;", ledstat, ledcolor);
1231
1232 //wifi
1233 ledcolor = 0;
1234 ledstat = autotest_led_get(LED_LAN_BLUE_BRIGHTNESS, LED_LAN_BLUE_BLINKTIMEON);
1235 if (ledstat) {
1236 ledcolor = net_color;
1237 }
1238 len = strlen(led_str);
1239 snprintf(led_str + len, sizeof(led_str) - len, "3,%d,%d", ledstat, ledcolor);
1240
1241 *res_msg = at_query_result_build("TLEDSTATUS",led_str);
1242 //*res_msg = at_err_build(ATERR_PROC_FAILED);
1243
1244 *res_msglen = strlen(*res_msg);
1245 return AT_END;
1246}
1247
1248
1249#define LED_SIGNAL1_BLUE_BRIGHTNESS "/sys/class/leds/4g_1_led/brightness"
1250#define LED_SIGNAL1_BLUE_BLINKTIMEON "/sys/class/leds/4g_1_led/delay_on"
1251
1252#define LED_SIGNAL2_BLUE_BRIGHTNESS "/sys/class/leds/4g_2_led/brightness"
1253#define LED_SIGNAL2_BLUE_BLINKTIMEON "/sys/class/leds/4g_2_led/delay_on"
1254
1255#define LED_SIGNAL3_BLUE_BRIGHTNESS "/sys/class/leds/4g_3_led/brightness"
1256#define LED_SIGNAL3_BLUE_BLINKTIMEON "/sys/class/leds/4g_3_led/delay_on"
1257
1258#define LED_SIGNAL4_BLUE_BRIGHTNESS "/sys/class/leds/4g_4_led/brightness"
1259#define LED_SIGNAL4_BLUE_BLINKTIMEON "/sys/class/leds/4g_4_led/delay_on"
1260
1261#define LED_SIGNAL5_BLUE_BRIGHTNESS "/sys/class/leds/4g_5_led/brightness"
1262#define LED_SIGNAL5_BLUE_BLINKTIMEON "/sys/class/leds/4g_5_led/delay_on"
1263
1264#define LED_WPS_BLUE_BRIGHTNESS "/sys/class/leds/wps_led/brightness"
1265#define LED_WPS_BLUE_BLINKTIMEON "/sys/class/leds/wps_led/delay_on"
1266
1267#define LED_RJ11_BLUE_BRIGHTNESS "/sys/class/leds/rj11_led/brightness"
1268#define LED_RJ11_BLUE_BLINKTIMEON "/sys/class/leds/rj11_led/delay_on"
1269
1270
1271/*
1272cpe switch
1273+TLEDSTATUS: <tpye>,<stat>,<color>;...
1274tpye: 0 signal; 1 network; 2 wps; 3 wifi; 4 rj11
1275stat: 0 off; 1 on; 2 blink (signal 1 1led, 2 2led, 3 3led, 4 4led, 5 5led, 12 1led blink)
1276color: 0 null/off; 1 red; 2 green; 3 blue;
1277
1278AT+TLEDSTATUS?
1279+TLEDSTATUS: 0,1,2;1,0,0;2,0,0;3,0,0
1280OK
1281*/
1282int autotest_ledget_cpesw_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1283{
1284 char led_str[36] = {0};
1285 int ledstat = 0;
1286 int ledcolor = 0;
1287 int len = 0;
1288
1289 //signal
1290 ledcolor = 0;
1291 if ((ledstat = autotest_led_get(LED_SIGNAL5_BLUE_BRIGHTNESS, LED_SIGNAL5_BLUE_BLINKTIMEON)) > 0) {
1292 ledstat = 5;
1293 ledcolor = 3;
1294 } else if ((ledstat = autotest_led_get(LED_SIGNAL4_BLUE_BRIGHTNESS, LED_SIGNAL4_BLUE_BLINKTIMEON)) > 0) {
1295 ledstat = 4;
1296 ledcolor = 3;
1297 } else if ((ledstat = autotest_led_get(LED_SIGNAL3_BLUE_BRIGHTNESS, LED_SIGNAL3_BLUE_BLINKTIMEON)) > 0) {
1298 ledstat = 3;
1299 ledcolor = 3;
1300 } else if ((ledstat = autotest_led_get(LED_SIGNAL2_BLUE_BRIGHTNESS, LED_SIGNAL2_BLUE_BLINKTIMEON)) > 0) {
1301 ledstat = 2;
1302 ledcolor = 3;
1303 } else if ((ledstat = autotest_led_get(LED_SIGNAL1_BLUE_BRIGHTNESS, LED_SIGNAL1_BLUE_BLINKTIMEON)) > 0) {
1304 if (ledstat == 2)
1305 ledstat = 12;
1306 else
1307 ledstat = 1;
1308 ledcolor = 3;
1309 }
1310 len = strlen(led_str);
1311 snprintf(led_str + len, sizeof(led_str) - len, "0,%d,%d;", ledstat, ledcolor);
1312
1313 //network
1314 ledcolor = 0;
1315 ledstat = autotest_led_get(LED_WAN_BLUE_BRIGHTNESS, LED_WAN_BLUE_BLINKTIMEON);
1316 if (ledstat) {
1317 ledcolor = 3;
1318 } else {
1319 ledstat = autotest_led_get(LED_WAN_RED_BRIGHTNESS, LED_WAN_RED_BLINKTIMEON);
1320 if (ledstat) {
1321 ledcolor = 1;
1322 }
1323 }
1324 len = strlen(led_str);
1325 snprintf(led_str + len, sizeof(led_str) - len, "1,%d,%d;", ledstat, ledcolor);
1326
1327 //wps
1328 ledcolor = 0;
1329 ledstat = autotest_led_get(LED_WPS_BLUE_BRIGHTNESS, LED_WPS_BLUE_BLINKTIMEON);
1330 if (ledstat) {
1331 ledcolor = 3;
1332 }
1333 len = strlen(led_str);
1334 snprintf(led_str + len, sizeof(led_str) - len, "2,%d,%d;", ledstat, ledcolor);
1335
1336 //wifi
1337 ledcolor = 0;
1338 ledstat = autotest_led_get(LED_LAN_BLUE_BRIGHTNESS, LED_LAN_BLUE_BLINKTIMEON);
1339 if (ledstat) {
1340 ledcolor = 3;
1341 }
1342 len = strlen(led_str);
1343 snprintf(led_str + len, sizeof(led_str) - len, "3,%d,%d;", ledstat, ledcolor);
1344
1345 //rj11
1346 ledcolor = 0;
1347 ledstat = autotest_led_get(LED_RJ11_BLUE_BRIGHTNESS, LED_RJ11_BLUE_BLINKTIMEON);
1348 if (ledstat) {
1349 ledcolor = 3;
1350 }
1351 len = strlen(led_str);
1352 snprintf(led_str + len, sizeof(led_str) - len, "4,%d,%d", ledstat, ledcolor);
1353
1354 *res_msg = at_query_result_build("TLEDSTATUS", led_str);
1355 *res_msglen = strlen(*res_msg);
1356 return AT_END;
1357}
1358
1359#endif
1360
1361extern UINT8 Sim_Inserted;
1362
1363int zCardSwitch_Set_Req(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1364{
1365 int32_t simCardFlag = 0;
1366 unsigned long retCode = CPNV_ERROR;
1367 int32_t SimInserted = 0;
xf.libdd93d52023-05-12 07:10:14 -07001368 int ret = 0;
lh9ed821d2023-04-07 01:36:19 -07001369
1370 char *p[] = {
1371 &simCardFlag,
1372 &cardSlotFlag,
1373 };
xf.libdd93d52023-05-12 07:10:14 -07001374
1375 ret = parse_param("%d,%d", at_paras, p);
1376 if (ret != AT_PARSE_OK) // cov M
1377 {
1378 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1379 *res_msglen = strlen(*res_msg);
1380 return AT_END;
1381 }
lh9ed821d2023-04-07 01:36:19 -07001382
1383 at_print(AT_DEBUG,"zCardSwitch_Set_Req:simCardFlag == %d\n", simCardFlag);
1384
1385 if(simCardFlag < 0 || simCardFlag > 6) //0 = UICC_CARD, 1 = VSIM_CARD, 2 = UICC_VSIM_AUTO, 3 = UICC_ESIM_CARD,4 = CLOUD_CARD,5 =SOFTSIM_CARD
1386 {
1387 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1388 *res_msglen = strlen(*res_msg);
1389 return AT_END;
1390 }
1391
1392 #ifdef USE_DSDS_VSIM
1393 if (simCardFlag == 0)
1394 {
1395 simCardFlag = 0;
1396 }
1397 else if (simCardFlag == 1)
1398 {
1399 simCardFlag = 4;
1400 }
1401 else if (simCardFlag == 2)
1402 {
1403 simCardFlag = 5;
1404 }
1405 else if (simCardFlag == 3)
1406 {
1407 simCardFlag = 1;
1408 }
1409 #endif
1410
1411 at_print(AT_DEBUG,"zCardSwitch_Set_Req:simCardFlag transform == %d\n", simCardFlag);
1412
1413 if(1 == cardSlotFlag)
1414 {
1415 retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(uicc1PreSwitch), (unsigned char *)(&simCardFlag), DRV_SYS_NV_ITEM_SIZE(uicc1PreSwitch));
1416 }
1417 else
1418 {
1419 retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(uiccPreSwitch), (unsigned char *)(&simCardFlag), DRV_SYS_NV_ITEM_SIZE(uiccPreSwitch));
1420 }
1421
1422 if (CPNV_OK == retCode)
1423 {
1424 retCode= cpnv_NvramFlush();
1425 }
1426
1427 if (retCode == CPNV_OK)
1428 {
1429 *res_msg = at_ok_build();
1430 }
1431 else
1432 {
1433 *res_msg = at_err_build(retCode);
1434 }
1435 *res_msglen = strlen(*res_msg);
1436 return AT_END;
1437}
1438
1439int zCardSwitch_Get_Req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1440{
1441 int32_t simCard0Flag = 0;
1442 int32_t simCard1Flag = 0;
1443 int32_t simCard0PreFlag = 0;
1444 int32_t simCard1PreFlag = 0;
1445
1446 unsigned long retCode = CPNV_ERROR;
1447 char tmp[100];
1448
1449 if (cardSlotFlag == 1)
1450 {
1451 retCode = cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(uicc1modeSwitch), (unsigned char *)(&simCard1Flag), DRV_SYS_NV_ITEM_SIZE(uicc1modeSwitch));
1452 retCode = cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(uicc1PreSwitch), (unsigned char *)(&simCard1PreFlag), DRV_SYS_NV_ITEM_SIZE(uicc1PreSwitch));
1453 }
1454
1455 retCode = cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(uiccmodeSwitch), (unsigned char *)(&simCard0Flag), DRV_SYS_NV_ITEM_SIZE(uiccmodeSwitch));
1456 retCode = cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(uiccPreSwitch), (unsigned char *)(&simCard0PreFlag), DRV_SYS_NV_ITEM_SIZE(uiccPreSwitch));
1457
1458 #ifdef USE_DSDS_VSIM
1459
1460 if (cardSlotFlag == 1)
1461 {
1462 if (simCard1Flag == 0)
1463 {
1464 simCard1Flag = 0;
1465 }
1466 else if (simCard1Flag == 4)
1467 {
1468 simCard1Flag = 1;
1469 }
1470 else if (simCard1Flag == 5)
1471 {
1472 simCard1Flag = 2;
1473 }
1474 else if (simCard1Flag == 1)
1475 {
1476 simCard1Flag = 3;
1477 }
1478
1479 if (simCard1PreFlag == 0)
1480 {
1481 simCard1PreFlag = 0;
1482 }
1483 else if (simCard1PreFlag == 4)
1484 {
1485 simCard1PreFlag = 1;
1486 }
1487 else if (simCard1PreFlag == 5)
1488 {
1489 simCard1PreFlag = 2;
1490 }
1491 else if (simCard1PreFlag == 1)
1492 {
1493 simCard1PreFlag = 3;
1494 }
1495 }
1496
1497 if (simCard0Flag == 0)
1498 {
1499 simCard0Flag = 0;
1500 }
1501 else if (simCard0Flag == 4)
1502 {
1503 simCard0Flag = 1;
1504 }
1505 else if (simCard0Flag == 5)
1506 {
1507 simCard0Flag = 2;
1508 }
1509 else if (simCard0Flag == 1)
1510 {
1511 simCard0Flag = 3;
1512 }
1513
1514 if (simCard0PreFlag == 0)
1515 {
1516 simCard0PreFlag = 0;
1517 }
1518 else if (simCard0PreFlag == 4)
1519 {
1520 simCard0PreFlag = 1;
1521 }
1522 else if (simCard0PreFlag == 5)
1523 {
1524 simCard0PreFlag = 2;
1525 }
1526 else if (simCard0PreFlag == 1)
1527 {
1528 simCard0PreFlag = 3;
1529 }
1530
1531 #endif
1532
1533 if (CPNV_ERROR == retCode)
1534 {
1535 *res_msg = at_err_build(retCode);
1536 }
1537 if (cardSlotFlag == 1)
1538 {
1539 snprintf(tmp,sizeof(tmp),"%d,%d,%d,%d,%d",simCard0PreFlag, simCard0Flag, simCard1PreFlag, simCard1Flag, cardSlotFlag);
1540 }
1541 else
1542 {
1543 snprintf(tmp,sizeof(tmp),"%d,%d",simCard0PreFlag, simCard0Flag);
1544 }
1545
1546 *res_msg = at_query_result_build("ZCARDSWITCH", tmp);
1547 *res_msglen = strlen(*res_msg);
1548 return AT_END;
1549}
1550
1551int ext_normal_regist(void)
1552{
1553 char mmi_nv_value[32] = {0};
1554 //ÅжϿͻ§ÀàÐÍ
1555 if(!ext_is_usermode())
1556 {
1557 char needInit[20] = {0};
1558 sc_cfg_get("customer_type",needInit,sizeof(needInit));
1559 if(0 != strcmp(needInit, "v3modem"))
1560 {
1561 register_serv_func2("znvset=",0,0,0,znvset_req_func,NULL);
1562 register_serv_func2("znvget=",0,0,0,znvget_req_func,NULL);
1563 }
1564
1565 //USBģʽÇл»ÃüÁî
1566 register_serv_func2("ZUSBMODE=",0,0,0,zusbmodeSet_req,NULL);
1567
1568 //ÓÃatÃüÁîÖ´ÐÐshellÃüÁÊäÈëµÄ²ÎÊý²»ÐèÒª´øË«ÒýºÅ
1569 register_serv_func2("shell=",0,0,0,ext_atshell_req,NULL);
1570 }
1571 //¹¤×÷ģʽÇл»
1572 register_serv_func2("zlanenable?",0,0,0,zlanenableGet_req,NULL);
1573 register_serv_func2("zlanenable=",0,0,0,zlanenableSet_req,NULL);
1574#ifndef CONFIG_MIN_8M_VERSION
1575 if(!ext_is_usermode())
1576 {
1577 //¿ØÖÆtelnetÆô¶¯
1578 register_serv_func2("ztelnet?",0,0,0,ztelnetGet_req,NULL);
1579 register_serv_func2("ztelnet=",0,0,0,ztelnetSet_req,NULL);
1580 }
1581 register_serv_func2("zpppstatus?",0,0,0,zppptatusGet_req,NULL);
1582
1583 //SALESTAT
1584 register_serv_func2("salestat=",0,0,0,salestatSet_req,NULL);
1585 register_serv_func2("salestat?",0,0,0,salestatGet_req,NULL);
1586 //CP֪ͨAP·¢Éú´íÎó
1587 register_serv_func2("CPERR=",0,0,0, zerrSet_req,NULL);
1588 register_serv_func2("zautorspset=",0,0,0,zautorspSet_req,NULL);
1589
1590 //ÉèÖýÓÊÕ¸ÃÀ©Õ¹ÃüÁîµÄͨµÀÖ÷¶¯Éϱ¨ÊôÐÔ
1591 register_serv_func2("ZISSENDAUTO=",0,0,0,modAutoInd_act_func,NULL);
1592
1593 //»ñȡƽ̨ÐÅÏ¢
1594 register_serv_func2("ZSOFTAPINFO",0,0,0,ext_softap_info_req,NULL);
1595 //LOGÊä³öµ½AT¿Ú
1596 register_serv_func2("ZSETOUT=",0,0,0,ext_log_stdout_req,NULL);
1597
1598 //ÉèÖÃÍⲿMCUÐèÒªµÄÖ÷¶¯Éϱ¨ÃüÁî ʾÀý£ºAT+ZNEEDIND=+CREG+CSQ
1599 register_serv_func2("ZNEEDIND=",0,0,0,zindcmd_set_func,NULL);
1600
1601 //Íâ²¿Ëø¿ªÆôÊÍ·ÅÃüÁî
1602 register_serv_func("ZWORKLOCK=", 0, ext_worklock_set_func);
1603#endif
1604
1605 register_serv_func2("ZCARDSWITCH=",0,0,0,zCardSwitch_Set_Req,NULL);
1606 register_serv_func2("ZCARDSWITCH?",0,0,0,zCardSwitch_Get_Req,NULL);
1607
1608 //register_fwd_func("zmode=",zmode_req_rcv_act,NULL,NULL);
1609 register_serv_func2("zmode?",0,0,0,zmodeGet_req,NULL);
1610 register_serv_func2("plugout=",0,0,0,plugoutSet_req,NULL);
1611
1612 //Íø¿ÚÇл»
1613 register_serv_func2("znetcardtype=",0,0,0,znetcardtypeSet_req,NULL);
1614
1615 register_serv_func2("znetcardtype?",0,0,0,znetcardtypeGet_req,NULL);
1616
1617
1618 register_fwd_func("PCFC=",ext_pcfc_set_func,NULL,NULL);
1619
1620#ifndef CONFIG_MIN_8M_VERSION//def _ENABLE_AUTOTEST
1621 //×Ô¶¯»¯²âÊÔ ---KEYEVENT=ºÍphoneÖØÃû
1622 //register_serv_func2("TKEYEVENT=",MODULE_ID_MMI, MSG_CMD_AUTOTEST_KEY_REQ, 0, autotest_keyset_req, NULL);
1623 register_serv_func2("TKEYEVENT=",0,0,0,autotest_keyset_req,NULL);
1624 register_serv_func2("TCPUSTATUS?",0,0,0,autotest_cpuget_req,NULL);
1625 sc_cfg_get("mmi_led_plan", mmi_nv_value, sizeof(mmi_nv_value));
1626 if (0 == strcmp(mmi_nv_value, "yaoyuan")) {
1627 register_serv_func2("TLEDSTATUS?",0,0,0,autotest_ledget_cpesw_req,NULL);
1628 } else {
1629 register_serv_func2("TLEDSTATUS?",0,0,0,autotest_ledget_req,NULL);
1630 }
1631#endif
1632 return 0;
1633}
1634
1635#endif