blob: 3052b6634b3942cd2abae4de4541fad386b378be [file] [log] [blame]
mj.qu5c355a02025-08-25 19:59:01 -07001/**
2 *
3 * @file ext_amt_func.c
4 * @brief
5 * This file is part of FTM.
6 * AMTÄ£¿éÏà¹ØATÃüÁî
7 *
8 * @details
9 * @author Tools Team.
10 * @email
11 * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
12 * @warning
13 * @date 2019/02/02
14 * @version 1.1
15 * @pre
16 * @post
17 *
18 * @par
19 * Change History :
20 * ---------------------------------------------------------------------------
21 * date version author description
22 * ---------------------------------------------------------------------------
23 * 2018/04/28 1.0 liu.xin Create file
24 * 2019/02/02 1.1 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
25 * ---------------------------------------------------------------------------
26 *
27 *
28 */
29
30#include "ext_regist.h"
31#include "at_com.h"
32#include <unistd.h>
33#include <sys/syscall.h>
34#include "RONvParam_AMT.h"
35#include "ref_nv_def.h"
36#include "nv_api.h"
37#include "amtnv.h"
38#include <linux/soc/zte/efuse/efuse_zx.h>
39#include "NvParam_drv.h"
40#include "libkey.h"
41
42//mdlÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨½á¹û
43static int auth_device_key_result = 0;
44
45#define GET_LCD_INFO 378
46#define GET_WIFI_INFO 379
47#define GET_FLASH_INFO 380
48#define GET_CPU_INFO 381
49#define GET_DDR_INFO 382
50//CP
51typedef unsigned char BYTE;
52
53#define DC_MacLen (BYTE)12
54#define DC_ImeiLen (BYTE)8
55#define MSN_MAX_NVINFO_LEN 20
56#define MSINFO_MAX_NVINFO_LEN 200
57#define MDMVERSION_MAX_LEN 64
58#define bInside(data, up, down) (((data) <= (up) && (data) >= (down)) || \
59 ((data) >= (up) && (data) <= (down)))
60typedef unsigned long u32_t;
61
62#ifndef SMEMCPY
63#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
64#endif
65
66/**
67 * @brief ZMDMVERSIONÏìÓ¦ÏûÏ¢½á¹¹Ìå
68 * @param result ½á¹ûÂë AT_RSP_OK/AT_RSP_ERR
69 * @param mdmVer modem°æ±¾ºÅ
70 */
71typedef struct
72{
73 char mdmVer[MDMVERSION_MAX_LEN];
74 int result;
75}AT_MDMVERSION_RSP_INFO;
76
77//static char mdmVer[MDMVERSION_MAX_LEN] = {0};//ÓÃÓڼǼZGMR »Ø¸´½á¹û
78
79struct flash_ddr_info{
80 char manu[32];
81 char model[32];
82 char size[32];
83 char other[32];
84};
85
86struct lcd_info
87{
88 char manu[32];
89 char ic[32];
90 char resolution[32];
91};
92
93struct wifi_info
94{
95 char manu[32];
96 char ic[32];
97};
98struct cpu_info{
99 char manu[32];
100 char model[32];
101};
102
103/* Data structure for MD5 (Message-Digest) computation */
104typedef struct {
105 u32_t i[2]; /* number of _bits_ handled mod 2^64 */
106 u32_t buf[4]; /* scratch buffer */
107 unsigned char in[64]; /* input buffer */
108 unsigned char digest[16]; /* actual digest after md5_final call */
109} md5_ctx;
110
111
112extern void at_context_chn_info_mod(char *at_paras);
113
114/*
115 ***********************************************************************
116 ** Message-digest routines: **
117 ** To form the message digest for a message M **
118 ** (1) Initialize a context buffer ctx using md5_init **
119 ** (2) Call md5_update on ctx and M **
120 ** (3) Call md5_final on ctx **
121 ** The message digest is now in ctx->digest[0...15] **
122 ***********************************************************************
123 */
124
125/* forward declaration */
126static void transform(u32_t *buf, u32_t *in);
127
128static unsigned char PADDING[64] = {
129 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
137};
138
139/* F, G, H and I are basic MD5 functions */
140#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
141#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
142#define H(x, y, z) ((x) ^ (y) ^ (z))
143#define I(x, y, z) ((y) ^ ((x) | (~z)))
144
145/* ROTATE_LEFT rotates x left n bits */
146#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
147
148/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
149/* Rotation is separate from addition to prevent recomputation */
150#define FF(a, b, c, d, x, s, ac) \
151 {(a) += F ((b), (c), (d)) + (x) + (u32_t)(ac); \
152 (a) = ROTATE_LEFT ((a), (s)); \
153 (a) += (b); \
154 }
155#define GG(a, b, c, d, x, s, ac) \
156 {(a) += G ((b), (c), (d)) + (x) + (u32_t)(ac); \
157 (a) = ROTATE_LEFT ((a), (s)); \
158 (a) += (b); \
159 }
160#define HH(a, b, c, d, x, s, ac) \
161 {(a) += H ((b), (c), (d)) + (x) + (u32_t)(ac); \
162 (a) = ROTATE_LEFT ((a), (s)); \
163 (a) += (b); \
164 }
165#define II(a, b, c, d, x, s, ac) \
166 {(a) += I ((b), (c), (d)) + (x) + (u32_t)(ac); \
167 (a) = ROTATE_LEFT ((a), (s)); \
168 (a) += (b); \
169 }
170
171#ifdef __STDC__
172#define UL(x) x##UL
173#else
174#ifdef WIN32
175#define UL(x) x##UL
176#else
177#define UL(x) x
178#endif
179#endif
180
181/* The routine md5_init initializes the message-digest context
182 mdContext. All fields are set to zero.
183 */
184void md5_init(md5_ctx *ctx)
185{
186 ctx->i[0] = ctx->i[1] = (u32_t)0;
187
188 /* Load magic initialization constants. */
189 ctx->buf[0] = (u32_t)0x67452301UL;
190 ctx->buf[1] = (u32_t)0xefcdab89UL;
191 ctx->buf[2] = (u32_t)0x98badcfeUL;
192 ctx->buf[3] = (u32_t)0x10325476UL;
193}
194
195/* The routine md5_update updates the message-digest context to
196 account for the presence of each of the characters buf[0..inLen-1]
197 in the message whose digest is being computed.
198 */
199
200void md5_update(md5_ctx *ctx, unsigned char *buf, unsigned int len)
201{
202 u32_t in[16];
203 int mdi;
204 unsigned int i, ii;
205
206#if 0
207 ppp_trace(LOG_INFO, "MD5Update: %u:%.*H\n", len, MIN(len, 20) * 2, buf);
208 ppp_trace(LOG_INFO, "MD5Update: %u:%s\n", len, buf);
209#endif
210
211 /* compute number of bytes mod 64 */
212 mdi = (int)((ctx->i[0] >> 3) & 0x3F);
213
214 /* update number of bits */
215 if ((ctx->i[0] + ((u32_t)len << 3)) < ctx->i[0]) {
216 ctx->i[1]++;
217 }
218 ctx->i[0] += ((u32_t)len << 3);
219 ctx->i[1] += ((u32_t)len >> 29);
220
221 while (len--) {
222 /* add new character to buffer, increment mdi */
223 ctx->in[mdi++] = *buf++;
224
225 /* transform if necessary */
226 if (mdi == 0x40) {
227 for (i = 0, ii = 0; i < 16; i++, ii += 4) {
228 in[i] = (((u32_t)ctx->in[ii+3]) << 24) |
229 (((u32_t)ctx->in[ii+2]) << 16) |
230 (((u32_t)ctx->in[ii+1]) << 8) |
231 ((u32_t)ctx->in[ii]);
232 }
233 transform (ctx->buf, in);
234 mdi = 0;
235 }
236 }
237}
238
239/* The routine md5_final terminates the message-digest computation and
240 ends with the desired message digest in ctx->digest[0...15].
241 */
242
243void md5_final(unsigned char hash[], md5_ctx *ctx)
244{
245 u32_t in[16];
246 int mdi;
247 unsigned int i, ii;
248 unsigned int pad_len;
249
250 /* save number of bits */
251 in[14] = ctx->i[0];
252 in[15] = ctx->i[1];
253
254 /* compute number of bytes mod 64 */
255 mdi = (int)((ctx->i[0] >> 3) & 0x3F);
256
257 /* pad out to 56 mod 64 */
258 pad_len = (mdi < 56) ? (56 - mdi) : (120 - mdi);
259 md5_update (ctx, PADDING, pad_len);
260
261 /* append length in bits and transform */
262 for (i = 0, ii = 0; i < 14; i++, ii += 4) {
263 in[i] = (((u32_t)ctx->in[ii+3]) << 24) |
264 (((u32_t)ctx->in[ii+2]) << 16) |
265 (((u32_t)ctx->in[ii+1]) << 8) |
266 ((u32_t)ctx->in[ii]);
267 }
268 transform (ctx->buf, in);
269
270 /* store buffer in digest */
271 for (i = 0, ii = 0; i < 4; i++, ii += 4) {
272 ctx->digest[ii] = (unsigned char)(ctx->buf[i] & 0xFF);
273 ctx->digest[ii+1] =
274 (unsigned char)((ctx->buf[i] >> 8) & 0xFF);
275 ctx->digest[ii+2] =
276 (unsigned char)((ctx->buf[i] >> 16) & 0xFF);
277 ctx->digest[ii+3] =
278 (unsigned char)((ctx->buf[i] >> 24) & 0xFF);
279 }
280 SMEMCPY(hash, ctx->digest, 16);
281}
282
283/* Basic MD5 step. Transforms buf based on in.
284 */
285static void transform (u32_t *buf, u32_t *in)
286{
287 u32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3];
288
289 /* Round 1 */
290 #define S11 7
291 #define S12 12
292 #define S13 17
293 #define S14 22
294 FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
295 FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
296 FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
297 FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
298 FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
299 FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
300 FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
301 FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
302 FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
303 FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
304 FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
305 FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
306 FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
307 FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
308 FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
309 FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
310
311 /* Round 2 */
312 #define S21 5
313 #define S22 9
314 #define S23 14
315 #define S24 20
316 GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
317 GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
318 GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
319 GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
320 GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
321 GG ( d, a, b, c, in[10], S22, UL( 38016083)); /* 22 */
322 GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
323 GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
324 GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
325 GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
326 GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
327 GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
328 GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
329 GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
330 GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
331 GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
332
333 /* Round 3 */
334 #define S31 4
335 #define S32 11
336 #define S33 16
337 #define S34 23
338 HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
339 HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
340 HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
341 HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
342 HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
343 HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
344 HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
345 HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
346 HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
347 HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
348 HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
349 HH ( b, c, d, a, in[ 6], S34, UL( 76029189)); /* 44 */
350 HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
351 HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
352 HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
353 HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
354
355 /* Round 4 */
356 #define S41 6
357 #define S42 10
358 #define S43 15
359 #define S44 21
360 II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
361 II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
362 II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
363 II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
364 II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
365 II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
366 II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
367 II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
368 II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
369 II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
370 II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
371 II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
372 II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
373 II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
374 II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
375 II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
376
377 buf[0] += a;
378 buf[1] += b;
379 buf[2] += c;
380 buf[3] += d;
381}
382
383static int is_mac_valid(char*macStr)
384{
385 int Macindex = 0;
386 for (; (macStr[Macindex] != '\0') && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE); Macindex++)
387 {
388 char chmac = macStr[Macindex];
389 if (!(bInside(chmac, '0', '9') || bInside(chmac, 'a', 'f') || bInside(chmac, 'A', 'F')))
390 {
391 at_print(AT_DEBUG,"mac is not hex str\r");
392 return FALSE;
393 }
394 }
395 return TRUE;
396}
397static char Ascii2BCD(char iAscii)
398{
399 char iBCD;
400
401 if ( bInside(iAscii, '0', '9'))
402 {
403 iBCD = iAscii - '0';
404
405 }
406 else if (bInside(iAscii, 'a', 'f'))
407 {
408 iBCD = iAscii - 'a' + 0x0a;
409
410 }
411 else if (bInside(iAscii, 'A', 'F'))
412 {
413 iBCD = iAscii - 'A' + 0x0a;
414 }
415 else
416 {
417 return -1;
418 }
419
420 return iBCD;
421
422}
423
424static char BCD2Ascii(char iBCD)
425{
426 char iAscii;
427
428 if (bInside(iBCD, 0x00, 0x09))
429 {
430 iAscii = (unsigned char)(iBCD + '0');
431 }
432 else if (bInside(iBCD, 0x0a, 0x0f))
433 {
434 iAscii = (unsigned char)((iBCD - 0x0a) + 'A');
435 }
436 else
437 {
438 return -1;
439 }
440 return iAscii;
441}
442
443static int IsImeiStrValid(char* imeiStr)
444{
445 int i = 0;
446 for (; i < 15; ++i)
447 {
448 if (imeiStr[i] < '0' || imeiStr[i] > '9')
449 {
450 return FALSE;
451 }
452 }
453 return TRUE;
454}
455
456static long Char2Int(char chr)
457{
458 long value = 0;
459 value = (chr - '0');
460 return value;
461}
462
463static char Int2Char(long value)
464{
465 char ch = '0'+value;
466 return ch;
467}
468
469static unsigned long DC_Writeimei(char * imeistr)
470{
471 int Imeiindex =0,checkindex=0;
472 BYTE abImei[DC_ImeiLen]={0};
473 BYTE Index1=0,Index2=0;
474
475 for(Imeiindex=0;imeistr[Imeiindex]!='\0';Imeiindex+=2)
476 {
477 at_print(AT_DEBUG,"Imeiindex= %d\r\n",Imeiindex);
478 at_print(AT_DEBUG,"imeistr[%d]= %c\r\n",Imeiindex,imeistr[Imeiindex]);
479
480 Index1=Char2Int((char)imeistr[Imeiindex]);
481 at_print(AT_DEBUG,"Index1= %d\r",Index1);
482
483 if((imeistr[Imeiindex+1])!='\0')
484 {
485
486 Index2= Char2Int((char)imeistr[Imeiindex+1]);
487 at_print(AT_DEBUG,"Index2= %d, Index2<<4 =%x , (Index2<<4)&Index1 = %x\r\n",Index2,Index2<<4,(Index2<<4)|Index1);
488
489 abImei[Imeiindex/2]=(Index2<<4)|Index1;
490 at_print(AT_DEBUG,"abImei[%d]= %x\r\n",Imeiindex/2,abImei[Imeiindex/2]);
491 }
492 else
493 {
494 abImei[Imeiindex/2]=0xF0|Index1;
495 at_print(AT_DEBUG,"abImei[%d]= %x\r\n",Imeiindex/2,abImei[Imeiindex/2]);
496 break;
497 }
498 }
499 for(checkindex=0;checkindex<8;checkindex++)
500 {
501 at_print(AT_DEBUG,"abImei[%d] = %x\r\n",checkindex,abImei[checkindex]);
502 }
503
504 if(CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, sizeof(abImei), abImei))
505 {
506 at_print(AT_ERR,"Write amt imei failed\r\n");
507 return -1;
508 }
509
510 return 0;
511}
512
513
514/**************************************************************************
515* º¯ÊýÃû³Æ: DC_WriteMacAddr
516* ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
517* ²ÎÊý˵Ã÷: (IN)
518* (OUT)
519* ·µ »Ø Öµ: ÎÞ
520* ÆäËü˵Ã÷:
521**************************************************************************/
522static unsigned long DC_WriteMacAddr(char *macstr)
523{
524 unsigned long Macindex = 0;
525 unsigned char abMac[OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE] = {0};
526 unsigned char Index1 = 0;
527 unsigned char Index2 = 0;
528
529 if(!is_mac_valid(macstr))
530 {
531 at_print(AT_DEBUG,"mac is not hex str\r");
532 return -1;
533 }
534
535 /*ASCIIÂëת»»³ÉBCDÂë*/
536 for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE); Macindex += 2)
537 {
538 Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
539 Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
540 abMac[Macindex/2]=(Index1<<4)|Index2;
541 }
542
543 if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_WIFIMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE, abMac))
544 {
545 at_print(AT_DEBUG,"Write amt mac failed\r");
546 return -1;
547 }
548
549 return 0;
550}
551
552/**************************************************************************
553* º¯ÊýÃû³Æ: DC_WriteMac2Addr
554* ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
555* ²ÎÊý˵Ã÷: (IN)
556* (OUT)
557* ·µ »Ø Öµ: ÎÞ
558* ÆäËü˵Ã÷:
559**************************************************************************/
560static unsigned long DC_WriteMac2Addr(char *macstr)
561{
562 unsigned long Macindex = 0;
563 unsigned char abMac[OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE] = {0};
564 unsigned char Index1 = 0;
565 unsigned char Index2 = 0;
566
567 if(!is_mac_valid(macstr))
568 {
569 at_print(AT_DEBUG,"mac is not hex str\r");
570 return -1;
571 }
572
573 /*ASCIIÂëת»»³ÉBCDÂë*/
574 for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE); Macindex += 2)
575 {
576 Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
577 Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
578 abMac[Macindex/2]=(Index1<<4)|Index2;
579 }
580
581 if (CPNV_ERROR== amt_nvro_write(OS_FLASH_AMT_COMM_RO_WIFIMAC2_ADDRESS, OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE, abMac))
582 {
583 at_print(AT_DEBUG,"Write amt mac failed\r");
584 return -1;
585 }
586
587 return 0;
588}
589
590/**************************************************************************
591* º¯ÊýÃû³Æ: DC_WriteRJ45MacAddr
592* ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
593* ²ÎÊý˵Ã÷: (IN)
594* (OUT)
595* ·µ »Ø Öµ: ÎÞ
596* ÆäËü˵Ã÷:
597**************************************************************************/
598unsigned long DC_WriteRJ45MacAddr(char *macstr)
599{
600 unsigned long Macindex = 0;
601 unsigned char abMac[OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE] = {0};
602 unsigned char Index1 = 0;
603 unsigned char Index2 = 0;
604
605 if(!is_mac_valid(macstr))
606 {
607 at_print(AT_DEBUG,"mac is not hex str\r");
608 return -1;
609 }
610
611 /*ASCIIÂëת»»³ÉBCDÂë*/
612 for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE); Macindex += 2)
613 {
614 Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
615 Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
616 abMac[Macindex/2]=(Index1<<4)|Index2;
617 }
618
619 if (CPNV_ERROR== amt_nvro_write(OS_FLASH_AMT_COMM_RO_ETHMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE, abMac))
620 {
621 at_print(AT_DEBUG,"Write amt ethmac failed\r");
622 return -1;
623 }
624
625 return 0;
626}
627
628
629/**************************************************************************
630* º¯ÊýÃû³Æ: DC_WriteMacAddr
631* ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«USB MACµØÖ·Ð´Èëµ½NVÖÐ
632* ²ÎÊý˵Ã÷: (IN)
633* (OUT)
634* ·µ »Ø Öµ: ÎÞ
635* ÆäËü˵Ã÷:
636**************************************************************************/
637static unsigned long DC_WriteUSBMacAddr(char *macstr)
638{
639 unsigned long Macindex = 0;
640 unsigned char abMac[OS_FLASH_AMT_COMM_RO_USBMAC_SIZE] = {0};
641 unsigned char Index1 = 0;
642 unsigned char Index2 = 0;
643
644 if(!is_mac_valid(macstr))
645 {
646 at_print(AT_DEBUG,"mac is not hex str\r");
647 return -1;
648 }
649
650 /*ASCIIÂëת»»³ÉBCDÂë*/
651 for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_USBMAC_SIZE); Macindex += 2)
652 {
653 Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
654 Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
655 abMac[Macindex/2]=(Index1<<4)|Index2;
656 }
657
658 if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_USBMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_USBMAC_SIZE, abMac))
659 {
660 at_print(AT_DEBUG,"Write amt usb mac failed\r");
661 return -1;
662 }
663
664 return 0;
665}
666
667/**************************************************************************
668* º¯ÊýÃû³Æ: DC_WriteMacAddr
669* ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«GMACµØÖ·Ð´Èëµ½NVÖÐ
670* ²ÎÊý˵Ã÷: (IN)
671* (OUT)
672* ·µ »Ø Öµ: ÎÞ
673* ÆäËü˵Ã÷:
674**************************************************************************/
675static unsigned long DC_WriteGmacAddr(char *macstr)
676{
677 unsigned long Macindex = 0;
678 unsigned char abMac[OS_FLASH_AMT_COMM_RO_GMAC_SIZE] = {0};
679 unsigned char Index1 = 0;
680 unsigned char Index2 = 0;
681
682 if(!is_mac_valid(macstr))
683 {
684 at_print(AT_DEBUG,"mac is not hex str\r");
685 return -1;
686 }
687
688 /*ASCIIÂëת»»³ÉBCDÂë*/
689 for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_GMAC_SIZE); Macindex += 2)
690 {
691 Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
692 Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
693 abMac[Macindex/2]=(Index1<<4)|Index2;
694 }
695
696 if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_GMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_GMAC_SIZE, abMac))
697 {
698 at_print(AT_DEBUG,"Write amt Gmac failed\r");
699 return -1;
700 }
701
702 return 0;
703}
704
705
706static int rkeydc_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
707{
708 int retCode = -1;
709 //char pStr[8] = {0};
710 char *at_str = NULL;
711 struct flash_ddr_info flashInfo = {{0}};
712 struct flash_ddr_info ddrInfo = {{0}};
713 struct cpu_info cpuInfo = {{0}};
714 struct wifi_info wifiInfo = {{0}};
715 struct lcd_info lcdInfo = {{0}};
716
717 at_print(AT_ERR,"rkeydc_act_func: \n");
718 at_str = malloc(64);
719 if(at_str == NULL)
720 return AT_END;
721 memset(at_str,0,64);
722 if(strstr(at_paras, "DDR"))
723 {
724 retCode = syscall(GET_DDR_INFO,ddrInfo.manu,ddrInfo.size,ddrInfo.model);
725 if(retCode < 0)
726 {
727 at_print(AT_ERR,"rkeydc_act_func: syscall GET_DDR_INFO failed \n");
728 free(at_str);
729 return AT_END;
730 }
731 at_print(AT_ERR,"rkeydc_act_func: ddrInfo.manu = %s,size = %s,model =%s\n",ddrInfo.manu,ddrInfo.size,ddrInfo.model);
732 snprintf((char*)at_str,64,"\r\n%s?NA?NA?%s?%s\r\n",ddrInfo.manu,ddrInfo.size,ddrInfo.model);
733 *res_msg = at_str;
734 *res_msglen = strlen(*res_msg);
735 }
736 else if(strstr(at_paras, "FLASH"))
737 {
738 retCode = syscall(GET_FLASH_INFO,flashInfo.manu,flashInfo.model,flashInfo.size);
739 if(retCode < 0)
740 {
741 at_print(AT_ERR,"rkeydc_act_func: syscall GET_FLASH_INFO failed \n");
742 free(at_str);
743 return AT_END;
744 }
745 at_print(AT_ERR,"rkeydc_act_func: flashInfo.manu = %s,model = %s,size =%s\n",flashInfo.manu,flashInfo.model,flashInfo.size);
746 snprintf((char*)at_str,64,"\r\n%s?%s?NA?%s?NA\r\n",flashInfo.manu,flashInfo.model,flashInfo.size);
747 *res_msg = at_str;
748 *res_msglen = strlen(*res_msg);
749 }
750 else if(strstr(at_paras, "LCD"))
751 {
752 retCode = syscall(GET_LCD_INFO,lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
753 if(retCode < 0)
754 {
755 at_print(AT_ERR,"rkeydc_act_func: syscall GET_LCD_INFO failed \n");
756 free(at_str);
757 return AT_END;
758 }
759 at_print(AT_ERR,"rkeydc_act_func: lcdInfo.manu = %s,ic = %s,resolution =%s\n",lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
760 snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?%s\r\n",lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
761 *res_msg = at_str;
762 *res_msglen = strlen(*res_msg);
763 }
764 else if(strstr(at_paras, "WIFI"))
765 {
766 retCode = syscall(GET_WIFI_INFO,wifiInfo.manu,wifiInfo.ic);
767 if(retCode < 0)
768 {
769 at_print(AT_ERR,"rkeydc_act_func: syscall GET_WIFI_INFO failed \n");
770 free(at_str);
771 return AT_END;
772 }
773 at_print(AT_ERR,"rkeydc_act_func: wifiInfo.manu = %s,ic = %s\n",wifiInfo.manu,wifiInfo.ic);
774 snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?NA\r\n",wifiInfo.manu,wifiInfo.ic);
775 *res_msg = at_str;
776 *res_msglen = strlen(*res_msg);
777 }
778 else if(strstr(at_paras, "CPU"))
779 {
780 retCode = syscall(GET_CPU_INFO,cpuInfo.manu,cpuInfo.model);
781 if(retCode < 0)
782 {
783 at_print(AT_ERR,"rkeydc_act_func: syscall GET_CPU_INFO failed \n");
784 free(at_str);
785 return AT_END;
786 }
787 at_print(AT_ERR,"rkeydc_act_func: cpuInfo.manu = %s,model =%s\n",cpuInfo.manu,cpuInfo.model);
788 snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?NA\r\n",cpuInfo.manu,cpuInfo.model);
789 *res_msg = at_str;
790 *res_msglen = strlen(*res_msg);
791 }
792 else
793 {
794 free(at_str);
795 }
796
797 return AT_END;
798
799}
800
801int poweroff_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
802{
803 system("poweroff");
804 // add by houweifeng for zhangwei 20200707, systemº¯Êý²¢²»ÊÇÒ»¶¨Í¬²½Ö´ÐÐ
805 *res_msg = at_ok_build();
806 *res_msglen = strlen(*res_msg);
807 return AT_END;
808}
809
810/**************************************************************************
811* º¯ÊýÃû³Æ: chip_platform_read_act_func
812* ¹¦ÄÜÃèÊö: return chip platform 1:7520V3 2:7100
813* ²ÎÊý˵Ã÷: (IN)
814* (OUT)
815* ·µ »Ø Öµ: ÎÞ
816* ÆäËü˵Ã÷:
817**************************************************************************/
818int chip_platform_read_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
819{
820 char TmpChipPlatform[32] ={0};
821 snprintf((char *)TmpChipPlatform, 32,"1");
822 *res_msg = at_query_result_build("PLATFORM",TmpChipPlatform);
823 *res_msglen = strlen(*res_msg);
824
825 return AT_END;
826}
827
828/**************************************************************************
829* º¯ÊýÃû³Æ: imeiRead_act_func
830* ¹¦ÄÜÃèÊö: ¶ÁimeiºÅ
831* ²ÎÊý˵Ã÷: (IN)
832* (OUT)
833* ·µ »Ø Öµ: ÎÞ
834* ÆäËü˵Ã÷:
835**************************************************************************/
836int imeiRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
837{
838 unsigned int retCode = -1;
839 char TmpImei[DC_ImeiLen]= {0}; //imei³¤¶È×î´óÖµ
840 int abImeiindex = 0,imeistrindex = 0;
841 static char imeistr[2*DC_ImeiLen] = {0};
842 char *at_str = NULL;
843
844 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, (unsigned char *)TmpImei, OS_FLASH_AMT_COMM_RO_IMEI_SIZE);
845 at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
846 if(CPNV_ERROR == retCode )
847 {
848 *res_msg = at_err_build(ATERR_PROC_FAILED);
849 *res_msglen = strlen(*res_msg);
850 return AT_END;
851 }
852
853 for (abImeiindex=0; abImeiindex<DC_ImeiLen-1; abImeiindex++,imeistrindex+=2)
854 {
855 imeistr[imeistrindex] = Int2Char(TmpImei[abImeiindex]&0x0F);
856 imeistr[imeistrindex+1] = Int2Char((TmpImei[abImeiindex]&0xF0)>>4);
857 }
858
859 imeistr[2*DC_ImeiLen-2]=Int2Char(TmpImei[DC_ImeiLen-1]&0x0F);
860 imeistr[2*DC_ImeiLen-1] = '\0';
861
862 //*res_msg = at_query_result_build(NULL,imeistr);
863 at_str = malloc(32);
864 if(at_str)
865 {
866 sprintf(at_str,"\r\n%s\r\nOK\r\n",imeistr);
867 *res_msg = at_str;
868 *res_msglen = strlen(*res_msg);
869 }
870 return AT_END;
871}
872
873
874/**************************************************************************
875* º¯ÊýÃû³Æ: imeiWrite_act_func
876* ¹¦ÄÜÃèÊö: дimeiºÅ
877* ²ÎÊý˵Ã÷: (IN)
878* (OUT)
879* ·µ »Ø Öµ: ÎÞ
880* ÆäËü˵Ã÷:
881**************************************************************************/
882int imeiWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
883{
884 //long retCode = -1;
885 char *at_str = NULL;
886 char Imeistr[2*DC_ImeiLen]= {0};
887
888
889 at_str = at_paras;
890
891 at_print(AT_DEBUG,"imeiWrite_act_func = %s.\n", at_str);
892
893 //if ((strstr((const char *)at_str,"\r")-(char *)at_str)!= (2*DC_ImeiLen-1) || !IsImeiStrValid(at_str))
894 if (strlen(at_paras) != (2*DC_ImeiLen-1) || !IsImeiStrValid(at_str))
895 {
896 *res_msg = at_err_build(ATERR_PARAM_INVALID);
897 *res_msglen = strlen(*res_msg);
898 }
899 else
900 {
901 if (-1 ==DC_Writeimei((char *)at_str))
902 {
903 *res_msg = at_err_build(ATERR_PROC_FAILED);
904 *res_msglen = strlen(*res_msg);
905 return AT_END;
906 }
907
908 memcpy(Imeistr,at_str,2*DC_ImeiLen-1);
909 Imeistr[2*DC_ImeiLen-1] = '\0';
910 *res_msg = at_query_result_build("MODIMEI",Imeistr);
911 *res_msglen = strlen(*res_msg);
912 }
913
914 return AT_END;
915}
916
917/**************************************************************************
918* º¯ÊýÃû³Æ: ssidRead_act_func
919* ¹¦ÄÜÃèÊö: »ñÈ¡SSIDºÅ
920* ²ÎÊý˵Ã÷: (IN)
921* (OUT)
922* ·µ »Ø Öµ: ÎÞ
923* ÆäËü˵Ã÷:
924**************************************************************************/
925int ssidRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
926{
927 unsigned int retCode = CPNV_ERROR;
928 char TmpSSID[ZPS_REF_MSINFO_MAX_SSID_LEN+1]={0};
929
930 retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_SSID_BASE_ADDR, (unsigned char*)TmpSSID, ZPS_REF_MSINFO_MAX_SSID_LEN);
931 TmpSSID[ZPS_REF_MSINFO_MAX_SSID_LEN] = '\0';
932 if(CPNV_ERROR == retCode)
933 {
934 at_print(AT_ERR,"cpnv_NvItemRead ssid fail !\n");
935 *res_msg = at_err_build(ATERR_PROC_FAILED);
936 *res_msglen = strlen(*res_msg);
937 return AT_END;
938 }
939 //strcpy(TmpSSID, (const char*)cfg_get("zssid"));
940
941 *res_msg = at_query_result_build("SSID",TmpSSID);
942 *res_msglen = strlen(*res_msg);
943 return AT_END;
944}
945
946/**************************************************************************
947* º¯ÊýÃû³Æ: ssidWrite_act_func
948* ¹¦ÄÜÃèÊö: дSSIDºÅ
949* ²ÎÊý˵Ã÷: (IN)
950* (OUT)
951* ·µ »Ø Öµ: ÎÞ
952* ÆäËü˵Ã÷: µ±SSIDºÅ¸Ä±äʱatserverÖ÷¶¯Éϱ¨¸øctrm£¬ctrm½«SSIDºÅдÈëNVÖÐ
953**************************************************************************/
954int ssidWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
955{
956 unsigned int retCode = CPNV_ERROR;
957 char *at_str = NULL;
958
959 at_print(AT_ERR,"at_paras=%s\n",at_paras);
960
961 at_str = at_paras;
962
963 retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_SSID_BASE_ADDR, (unsigned char*)at_str, strlen(at_str));
964 at_print(AT_ERR,"at_str=%s\n",at_str);
965 at_print(AT_ERR,"retCode=%d\n",retCode);
966
967 if(CPNV_ERROR == retCode)
968 {
969 at_print(AT_ERR,"cpnv_NvItemWrite ssid fail !\n");
970 *res_msg = at_err_build(ATERR_PROC_FAILED);
971 *res_msglen = strlen(*res_msg);
972 return AT_END;
973 }
974 else
975 {
976 at_print(AT_ERR,"cpnv_NvItemWrite ssid success !\n");
977 }
978
979 cfg_set("zssid",at_str);
980
981 retCode = cpnv_NvramFlush();
982
983 if (retCode == CPNV_OK)
984 {
985 *res_msg = at_query_result_build("SSID",at_str);
986 }
987 else
988 {
989 at_print(AT_ERR,"cpnv_NvramFlush ssid fail !\n");
990 *res_msg = at_err_build(ATERR_PROC_FAILED);
991 }
992 *res_msglen = strlen(*res_msg);
993
994 return AT_END;
995
996}
997
998
999/**************************************************************************
1000* º¯ÊýÃû³Æ: versionTypeSet_act_func
1001* ¹¦ÄÜÃèÊö: ÉèÖð汾ÀàÐÍ£¬AMT°æ±¾/´ó°æ±¾
1002* ²ÎÊý˵Ã÷: (IN)
1003* (OUT)
1004* ·µ »Ø Öµ: ÎÞ
1005* ÆäËü˵Ã÷: AT+ZVERSIONTYPE=0Ϊ´ó°æ±¾£¬AT+ZVERSIONTYPE=1ΪAMT°æ±¾
1006**************************************************************************/
1007int versionTypeSet_act_func(int at_fd, char * at_paras,void **res_msg, int * res_msglen)
1008{
1009 long retCode = -1;
1010 char *at_str = NULL;
1011 int ntype = -1;
1012
1013 at_print(AT_ERR,"at_paras=%s\n", at_paras);
1014 at_str = at_paras;
1015
1016 unsigned char bootmode[] = {0x54, 0x4D};
1017 unsigned char atmode[] = {0x41, 0x54};
1018 get_at_cmd_param_int(at_str, &ntype, (const char **)&at_str);
1019
1020 if(!is_at_cmd_end(at_str))
1021 {
1022 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1023 *res_msglen = strlen(*res_msg);
1024 return AT_END;
1025 }
1026
1027 if(ntype == 1)
1028 {
1029 retCode = amt_set_bootmode(bootmode);
1030 }
1031 else if(ntype == 0)
1032 {
1033 memset(bootmode, 0xFF, 2);
1034 retCode = amt_set_bootmode(bootmode);
1035 }
1036 else if(ntype == 2)
1037 {
1038 retCode = amt_set_amt_atmode(bootmode,atmode);
1039 }
1040 else
1041 {
1042 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1043 *res_msglen = strlen(*res_msg);
1044 return AT_END;
1045 }
1046 if (retCode == 0)
1047 {
1048 if (ntype == 0)
1049 {
1050 *res_msg = at_query_result_build("versionType","0");
1051 }
1052 else if(ntype == 1)
1053 {
1054 *res_msg = at_query_result_build("versionType","1");
1055 }
1056 else if(ntype == 2)
1057 {
1058 *res_msg = at_query_result_build("versionType","2");
1059 }
1060 }
1061 else
1062 {
1063 *res_msg = at_err_build(ATERR_PROC_FAILED);
1064 }
1065
1066 *res_msglen = strlen(*res_msg);
1067
1068 return AT_END;
1069}
1070
1071/**************************************************************************
1072* º¯ÊýÃû³Æ: macRead_act_func
1073* ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
1074* ²ÎÊý˵Ã÷: (IN)
1075* (OUT)
1076* ·µ »Ø Öµ: ÎÞ
1077* ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
1078**************************************************************************/
1079int macRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1080{
1081 unsigned int retCode = CPNV_ERROR;
1082 char TmpMacAddr[Comm_DEV_MSINFO_MAX_WIFIMAC_Area_Len] = {0};//imei³¤¶È×î´óÖµ
1083 char str[13];
1084 unsigned long abMacindex = 0;
1085 static char macstr[2 * AT_CMD_MAX - 1] = {0};
1086
1087 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_WIFIMAC_ADDRESS, (unsigned char *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE);
1088 at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
1089 if(CPNV_ERROR == retCode )
1090 {
1091 *res_msg = at_err_build(ATERR_PROC_FAILED);
1092 *res_msglen = strlen(*res_msg);
1093 return AT_END;
1094 }
1095
1096 /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
1097 memset(str, 0, 13);
1098
1099 for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
1100 {
1101 str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
1102 str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
1103
1104 macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
1105 macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
1106 }
1107
1108 *res_msg = at_query_result_build("MAC",macstr);
1109 *res_msglen = strlen(*res_msg);
1110
1111 return AT_END;
1112
1113}
1114
1115/**************************************************************************
1116* º¯ÊýÃû³Æ: macWrite_act_func
1117* ¹¦ÄÜÃèÊö: дMACµØÖ·
1118* ²ÎÊý˵Ã÷: (IN)
1119* (OUT)
1120* ·µ »Ø Öµ: ÎÞ
1121* ÆäËü˵Ã÷:
1122**************************************************************************/
1123int macWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1124{
1125 //long retCode = CPNV_ERROR;
1126 char *at_str = NULL;
1127
1128 //zOss_ASSERT(at_paras!=NULL);
1129 at_str = at_paras;
1130
1131 if (strlen(at_str) != DC_MacLen)
1132 {
1133 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1134 }
1135 else
1136 {
1137 if (-1 == DC_WriteMacAddr((char *)at_str))
1138 {
1139 *res_msg = at_err_build(ATERR_PROC_FAILED);
1140 }
1141 else
1142 {
1143 //*res_msg = at_query_result_build("MAC",at_str);
1144 *res_msg = at_ok_build();
1145 }
1146 }
1147
1148 *res_msglen = strlen(*res_msg);
1149
1150 return AT_END;
1151}
1152
1153/**************************************************************************
1154* º¯ÊýÃû³Æ: wifikeyRead_act_func
1155* ¹¦ÄÜÃèÊö: »ñÈ¡WifiKeyµÄÖµ
1156* ²ÎÊý˵Ã÷: (IN)
1157* (OUT)
1158* ·µ »Ø Öµ: ÎÞ
1159* ÆäËü˵Ã÷:
1160**************************************************************************/
1161int wifikeyRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1162{
1163 unsigned int retCode = CPNV_ERROR;
1164 char TmpWifiKey[ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN+1]={0};
1165
1166 retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_NEWWIFIKEY_BASE_ADDR, (unsigned char *)TmpWifiKey, ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN);
1167 TmpWifiKey[ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN] = '\0';
1168 //zOss_ASSERT(retCode!=ZOSS_ERROR);
1169 if(CPNV_ERROR == retCode)
1170 {
1171 at_print(AT_ERR,"cpnv_NvItemRead wifikey fail !\n");
1172 *res_msg = at_err_build(ATERR_PROC_FAILED);
1173 *res_msglen = strlen(*res_msg);
1174 return AT_END;
1175 }
1176 //strcpy(TmpWifiKey, (const char*)cfg_get("zwifikey"));
1177
1178 *res_msg = at_query_result_build("WIFIKEY",TmpWifiKey);
1179 *res_msglen = strlen(*res_msg);
1180
1181 return AT_END;
1182}
1183
1184/**************************************************************************
1185* º¯ÊýÃû³Æ: wifikeyWrite_act_func
1186* ¹¦ÄÜÃèÊö: дWIFI KEYµÄÖµ
1187* ²ÎÊý˵Ã÷: (IN)
1188* (OUT)
1189* ·µ »Ø Öµ: ÎÞ
1190* ÆäËü˵Ã÷:
1191**************************************************************************/
1192int wifikeyWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1193{
1194 char *at_str = NULL;
1195 //char *pStrValue = NULL;
1196 unsigned long retCode = CPNV_ERROR;
1197
1198 //zOss_ASSERT(at_paras!=NULL);
1199 at_str = at_paras;
1200 if(strlen(at_str)> ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN)
1201 {
1202 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1203 *res_msglen = strlen(*res_msg);
1204 return AT_END;
1205 }
1206
1207 retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_NEWWIFIKEY_BASE_ADDR, (unsigned char *)at_str, strlen(at_str));
1208 //cfg_set("zwifikey",at_str);
1209
1210 if (retCode == CPNV_OK)
1211 {
1212 retCode = cpnv_NvramFlush();
1213
1214 if (retCode == CPNV_OK)
1215 {
1216 *res_msg = at_query_result_build("WIFIKEY",at_str);
1217 }
1218 else
1219 {
1220 *res_msg = at_err_build(ATERR_PROC_FAILED);
1221 }
1222
1223 }
1224 else
1225 {
1226 *res_msg = at_err_build(ATERR_PROC_FAILED);
1227 }
1228
1229 *res_msglen = strlen(*res_msg);
1230 return AT_END;
1231}
1232
1233/**************************************************************************
1234* º¯ÊýÃû³Æ: rj45MacAddrRead_act_func
1235* ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
1236* ²ÎÊý˵Ã÷: (IN)
1237* (OUT)
1238* ·µ »Ø Öµ: ÎÞ
1239* ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
1240**************************************************************************/
1241int rj45MacAddrRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1242{
1243 unsigned long retCode = CPNV_ERROR;
1244 char TmpMacAddr[OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE] = {0};
1245 char str[13];
1246 long abMacindex = 0;
1247 static char macstr[2 * OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE - 1] = {0};
1248
1249 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_ETHMAC_ADDRESS, (unsigned char *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE);
1250 at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
1251 if(CPNV_ERROR == retCode )
1252 {
1253 *res_msg = at_err_build(ATERR_PROC_FAILED);
1254 *res_msglen = strlen(*res_msg);
1255 return AT_END;
1256 }
1257
1258 /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
1259 memset(str, 0, 13);
1260
1261 for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
1262 {
1263 str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
1264 str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
1265
1266 macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
1267 macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
1268 }
1269
1270 /* MACµØÖ·×ª»»½áÊø*/
1271 *res_msg = at_query_result_build("ETHMAC",macstr);
1272 *res_msglen = strlen(*res_msg);
1273
1274 return AT_END;
1275}
1276
1277/**************************************************************************
1278* º¯ÊýÃû³Æ: rj45MacAddWrite_act_func
1279* ¹¦ÄÜÃèÊö: дMACµØÖ·
1280* ²ÎÊý˵Ã÷: (IN)
1281* (OUT)
1282* ·µ »Ø Öµ: ÎÞ
1283* ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
1284**************************************************************************/
1285int rj45MacAddWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1286{
1287 //long retCode = CPNV_ERROR;
1288 char *at_str = NULL;
1289
1290 //zOss_ASSERT(at_paras!=NULL);
1291 at_str = at_paras;
1292
1293 if (strlen(at_str)!= DC_MacLen)
1294 {
1295 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1296 }
1297 else
1298 {
1299 if (-1 == DC_WriteRJ45MacAddr((char *)at_str))
1300 {
1301 *res_msg = at_err_build(ATERR_PROC_FAILED);
1302 }
1303 else
1304 {
1305 *res_msg = at_query_result_build("ETHMAC",at_str);
1306 }
1307 }
1308
1309 *res_msglen = strlen(*res_msg);
1310
1311 return AT_END;
1312}
1313
1314/**************************************************************************
1315* º¯ÊýÃû³Æ: mac2Read_act_func
1316* ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
1317* ²ÎÊý˵Ã÷: (IN)
1318* (OUT)
1319* ·µ »Ø Öµ: ÎÞ
1320* ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
1321**************************************************************************/
1322int mac2Read_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1323{
1324 unsigned long retCode = CPNV_ERROR;
1325 char TmpMacAddr[OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE] = {0};//imei³¤¶È×î´óÖµ
1326 char str[13];
1327 long abMacindex = 0;
1328 static char macstr[2 * OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE - 1] = {0};
1329
1330 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_WIFIMAC2_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE);
1331
1332 if (CPNV_ERROR == retCode )
1333 {
1334 *res_msg = at_err_build(ATERR_PROC_FAILED);
1335 *res_msglen = strlen(*res_msg);
1336 return AT_END;
1337 }
1338
1339 /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
1340 memset(str, 0, 13);
1341
1342 for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
1343 {
1344 str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
1345 str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
1346
1347 macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
1348 macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
1349 }
1350
1351 /* MACµØÖ·×ª»»½áÊø*/
1352 *res_msg = at_query_result_build("MAC2",macstr);
1353 *res_msglen = strlen(*res_msg);
1354 return AT_END;
1355}
1356
1357/**************************************************************************
1358* º¯ÊýÃû³Æ: mac2Write_act_func
1359* ¹¦ÄÜÃèÊö: дMACµØÖ·
1360* ²ÎÊý˵Ã÷: (IN)
1361* (OUT)
1362* ·µ »Ø Öµ: ÎÞ
1363* ÆäËü˵Ã÷:
1364**************************************************************************/
1365int mac2Write_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1366{
1367 //long retCode = CPNV_ERROR;
1368 char *at_str = NULL;
1369
1370 //zOss_ASSERT(at_paras!=NULL);
1371 at_str = at_paras;
1372
1373 if (strlen(at_str)!= DC_MacLen)
1374 {
1375 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1376 }
1377 else
1378 {
1379 if (-1 == DC_WriteMac2Addr((char *)at_str))
1380 {
1381 *res_msg = at_err_build(ATERR_PROC_FAILED);
1382 }
1383 else
1384 {
1385 *res_msg = at_query_result_build("MAC2",at_str);
1386 }
1387 }
1388
1389 *res_msglen = strlen(*res_msg);
1390
1391 return AT_END;
1392}
1393
1394/**************************************************************************
1395* º¯ÊýÃû³Æ: usbmacRead_act_func
1396* ¹¦ÄÜÃèÊö: ¶ÁUSB MACµØÖ·
1397* ²ÎÊý˵Ã÷: (IN)
1398* (OUT)
1399* ·µ »Ø Öµ: ÎÞ
1400* ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
1401**************************************************************************/
1402int usbmacRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1403{
1404 unsigned long retCode = CPNV_ERROR;
1405 char TmpMacAddr[OS_FLASH_AMT_COMM_RO_USBMAC_SIZE] = {0};//imei³¤¶È×î´óÖµ
1406 char str[13];
1407 long abMacindex = 0;
1408 static char macstr[2 * OS_FLASH_AMT_COMM_RO_USBMAC_SIZE - 1] = {0};
1409
1410 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_USBMAC_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_USBMAC_SIZE);
1411
1412 if (CPNV_ERROR == retCode )
1413 {
1414 *res_msg = at_err_build(ATERR_PROC_FAILED);
1415 *res_msglen = strlen(*res_msg);
1416 return AT_END;
1417 }
1418
1419 /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
1420 memset(str, 0, 13);
1421
1422 for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
1423 {
1424 str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
1425 str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
1426
1427 macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
1428 macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
1429 }
1430
1431 /* MACµØÖ·×ª»»½áÊø*/
1432 *res_msg = at_query_result_build("USBMAC",macstr);
1433 *res_msglen = strlen(*res_msg);
1434 return AT_END;
1435}
1436
1437/**************************************************************************
1438* º¯ÊýÃû³Æ: usbmacWrite_act_func
1439* ¹¦ÄÜÃèÊö: дUSB MACµØÖ·
1440* ²ÎÊý˵Ã÷: (IN)
1441* (OUT)
1442* ·µ »Ø Öµ: ÎÞ
1443* ÆäËü˵Ã÷:
1444**************************************************************************/
1445int usbmacWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1446{
1447 //long retCode = CPNV_ERROR;
1448 char *at_str = NULL;
1449
1450 //zOss_ASSERT(at_paras!=NULL);
1451 at_str = at_paras;
1452
1453 if (strlen(at_str)!= DC_MacLen)
1454 {
1455 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1456 }
1457 else
1458 {
1459 if (-1 == DC_WriteUSBMacAddr((char *)at_str))
1460 {
1461 *res_msg = at_err_build(ATERR_PROC_FAILED);
1462 }
1463 else
1464 {
1465 *res_msg = at_query_result_build("USBMAC",at_str);
1466 }
1467 }
1468
1469 *res_msglen = strlen(*res_msg);
1470
1471 return AT_END;
1472
1473}
1474
1475/**************************************************************************
1476* º¯ÊýÃû³Æ: gmacRead_act_func
1477* ¹¦ÄÜÃèÊö: ¶ÁGMACµØÖ·
1478* ²ÎÊý˵Ã÷: (IN)
1479* (OUT)
1480* ·µ »Ø Öµ: ÎÞ
1481* ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
1482**************************************************************************/
1483
1484int gmacRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1485{
1486 unsigned long retCode = CPNV_ERROR;
1487 char TmpMacAddr[OS_FLASH_AMT_COMM_RO_GMAC_SIZE] = {0};//imei³¤¶È×î´óÖµ
1488 char str[13];
1489 long abMacindex = 0;
1490 static char macstr[2 * OS_FLASH_AMT_COMM_RO_GMAC_SIZE - 1] = {0};
1491
1492 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_GMAC_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_GMAC_SIZE);
1493
1494 if (CPNV_ERROR == retCode )
1495 {
1496 *res_msg = at_err_build(ATERR_PROC_FAILED);
1497 *res_msglen = strlen(*res_msg);
1498 return AT_END;
1499 }
1500
1501 /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
1502 memset(str, 0, 13);
1503
1504 for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
1505 {
1506 str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
1507 str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
1508
1509 macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
1510 macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
1511 }
1512
1513 /* MACµØÖ·×ª»»½áÊø*/
1514 *res_msg = at_query_result_build("GMAC",macstr);
1515 *res_msglen = strlen(*res_msg);
1516 return AT_END;
1517}
1518
1519/**************************************************************************
1520* º¯ÊýÃû³Æ: gmacWrite_act_func
1521* ¹¦ÄÜÃèÊö: дGMACµØÖ·
1522* ²ÎÊý˵Ã÷: (IN)
1523* (OUT)
1524* ·µ »Ø Öµ: ÎÞ
1525* ÆäËü˵Ã÷:
1526**************************************************************************/
1527int gmacWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1528{
1529 //long retCode = CPNV_ERROR;
1530 char *at_str = NULL;
1531
1532 //zOss_ASSERT(at_paras!=NULL);
1533 at_str = at_paras;
1534
1535 if (strlen(at_str)!= DC_MacLen)
1536 {
1537 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1538 }
1539 else
1540 {
1541 if (-1 == DC_WriteGmacAddr((char *)at_str))
1542 {
1543 *res_msg = at_err_build(ATERR_PROC_FAILED);
1544 }
1545 else
1546 {
1547 *res_msg = at_query_result_build("GMAC",at_str);
1548 }
1549 }
1550
1551 *res_msglen = strlen(*res_msg);
1552
1553 return AT_END;
1554
1555}
1556
1557/**************************************************************************
1558* º¯ÊýÃû³Æ: batdetRead_act_func
1559* ¹¦ÄÜÃèÊö: »ñÈ¡BATDETµÄÖµ
1560* ²ÎÊý˵Ã÷: (IN)
1561* (OUT)
1562* ·µ »Ø Öµ: ÎÞ
1563* ÆäËü˵Ã÷:
1564**************************************************************************/
1565int batdetRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1566{
1567 unsigned int retCode = CPNV_ERROR;
1568 char TmpBatdet[32] = {0};
1569 int nv_value = 0;
1570
1571 retCode = cpnv_NvItemRead(DRV_PERI_NV_ADDR, (unsigned char *)&nv_value, 1);
1572
1573 at_print(AT_DEBUG, "batdetRead_act_func:nv_value = %d\n", nv_value);
1574
1575 snprintf((char *)TmpBatdet, 32, "%d", nv_value);
1576 if(retCode != CPNV_ERROR)
1577 {
1578 *res_msg = at_query_result_build("BATDET", TmpBatdet);
1579 *res_msglen = strlen(*res_msg);
1580 }
1581 else
1582 {
1583 *res_msg = at_err_build(ATERR_PROC_FAILED);
1584 *res_msglen = strlen(*res_msg);
1585 }
1586 return AT_END;
1587}
1588
1589/**************************************************************************
1590* º¯ÊýÃû³Æ: batdetWrite_act_func
1591* ¹¦ÄÜÃèÊö: дBATDETµÄÖµ
1592* ²ÎÊý˵Ã÷: (IN)
1593* (OUT)
1594* ·µ »Ø Öµ: ÎÞ
1595* ÆäËü˵Ã÷:
1596**************************************************************************/
1597int batdetWrite_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
1598{
1599 char *at_str = NULL;
1600 //char *pStrValue = NULL;
1601 //char TmpBatdet[32] = {0};
1602 unsigned long retCode = CPNV_ERROR;
1603 int nv_value = -1;
1604
1605 at_str = at_paras;
1606 at_print(AT_DEBUG, "batdetWrite_act_func:at_str = %s\n", at_str);
1607
1608 get_at_cmd_param_int(at_str, &nv_value, (const char **)&at_str);
1609
1610 at_print(AT_DEBUG,"batdetWrite_act_func:at_str = %s\n", at_str);
1611 at_print(AT_DEBUG,"batdetWrite_act_func:nv_value = %d\n", nv_value);
1612
1613 if(!(0 == nv_value || 1 == nv_value)) // szLanEnableÖ»ÓÐ0ºÍ1Á½¸öÖµ
1614 {
1615 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1616 *res_msglen = strlen(*res_msg);
1617 return AT_END;
1618 }
1619
1620 retCode =amt_set_batdet_flag(nv_value);
1621
1622 if (retCode == CPNV_OK)
1623 {
1624 if(nv_value == 1)
1625 {
1626 *res_msg = at_query_result_build("BATDET","1");
1627 }
1628 else
1629 {
1630 *res_msg = at_query_result_build("BATDET","0");
1631 }
1632 }
1633 else
1634 {
1635 *res_msg = at_err_build(ATERR_PROC_FAILED);
1636 }
1637
1638 *res_msglen = strlen(*res_msg);
1639 return AT_END;
1640}
1641
1642int msnRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1643{
1644 unsigned int retCode = CPNV_ERROR;
1645 char TmpMSN[MSN_MAX_NVINFO_LEN+1]= {0};
1646
1647 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_MSerialNum_ADDRESS, (UINT8 *)TmpMSN, MSN_MAX_NVINFO_LEN);
1648 TmpMSN[MSN_MAX_NVINFO_LEN] = '\0';
1649 if(retCode != CPNV_ERROR)
1650 {
1651 *res_msg = at_query_result_build("MSN",TmpMSN);
1652 *res_msglen = strlen(*res_msg);
1653 }
1654 else
1655 {
1656 *res_msg = at_err_build(ATERR_PROC_FAILED);
1657 *res_msglen = strlen(*res_msg);
1658 }
1659 return AT_END;
1660}
1661
1662int msnWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1663{
1664 unsigned int retCode = CPNV_ERROR;
1665 char *at_str = NULL;
1666
1667 if(NULL !=at_paras)
1668 {
1669 at_str = at_paras;
1670 at_print(AT_DEBUG,"msnWrite_act_func = %s.\n", at_str);
1671 if((strlen(at_str) >= 12) && (strlen(at_str) <= 20))
1672 {
1673 retCode = amt_nvro_write(OS_FLASH_AMT_COMM_RO_MSerialNum_ADDRESS, MSN_MAX_NVINFO_LEN, (unsigned char *)at_str);
1674 if(retCode != CPNV_ERROR)
1675 {
1676 *res_msg = at_ok_build();
1677 *res_msglen = strlen(*res_msg);
1678 return AT_END;
1679 }
1680 }
1681 }
1682 *res_msg = at_err_build(ATERR_PROC_FAILED);
1683 *res_msglen = strlen(*res_msg);
1684 return AT_END;
1685
1686}
1687
1688int testInfoRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1689{
1690 unsigned int retCode = CPNV_ERROR;
1691 char TmpTestInfo[MSINFO_MAX_NVINFO_LEN+1] = {0};
1692
1693 retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_TestInfo_ADDRESS, (UINT8 *)TmpTestInfo, MSINFO_MAX_NVINFO_LEN);
1694 TmpTestInfo[MSINFO_MAX_NVINFO_LEN] = '\0';
1695 if(retCode != CPNV_ERROR)
1696 {
1697 *res_msg = at_query_result_build("RTESTINFO",TmpTestInfo);
1698 *res_msglen = strlen(*res_msg);
1699 }
1700 else
1701 {
1702 *res_msg = at_err_build(ATERR_PROC_FAILED);
1703 *res_msglen = strlen(*res_msg);
1704 }
1705 return AT_END;
1706}
1707
1708int closeAutoInd_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1709{
1710 if('1' == at_paras[0])
1711 {
1712 at_context_chn_info_mod("none");
1713 *res_msg = at_ok_build();
1714 *res_msglen = strlen(*res_msg);
1715 }
1716 else
1717 {
1718 *res_msg = at_err_build(ATERR_PROC_FAILED);
1719 *res_msglen = strlen(*res_msg);
1720 }
1721 return AT_END;
1722}
1723
1724
1725
1726int zphone_mode_query_req_act(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1727{
1728 UINT32 retCode = CPNV_ERROR;
1729 UINT8 TmpPhoneMode = 0;
1730 char *pPtr = NULL;
1731
1732 pPtr = malloc(256);
1733 if(pPtr == NULL)
1734 {
1735 softap_assert("");
1736 return AT_END;
1737 }
1738 memset(pPtr, 0x00, 256);
1739
1740 retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR, &TmpPhoneMode, sizeof(UINT8));
1741 if(retCode == CPNV_ERROR){softap_assert("");}
1742
1743 if( 1 == (TmpPhoneMode & 0x1)) //×îºóһλÊÇ1 ´¿modem°æ±¾
1744 {
1745 snprintf((char *)pPtr, 64,"\r\n+PHONEMODE: %d", 0);
1746 }
1747 else if (0 == (TmpPhoneMode & 0x1)) //×îºóһλÊÇ 0 Õý³£°æ±¾
1748 {
1749 snprintf((char *)pPtr, 64,"\r\n+PHONEMODE: %d", 1);
1750 }
1751
1752 strcat((char *)pPtr,"\r\n\r\nOK\r\n");
1753
1754
1755 *res_msg = pPtr;
1756 *res_msglen = strlen(pPtr);
1757
1758 return AT_END;
1759}
1760
1761int zphone_mode_set_req_act(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1762{
1763 UINT8 phoneModeStatus = 0;
1764 UINT32 retCode = CPNV_ERROR;
1765
1766 retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
1767 if(retCode == CPNV_ERROR)
1768 {
1769 softap_assert("");
1770 }
1771
1772 //Õý³£°æ±¾
1773 if('1' == at_paras[0])
1774 {
1775 phoneModeStatus = (0xfe & phoneModeStatus); // ºóһλ0±íʾÕý³£°æ±¾
1776 cfg_set("version_mode","0");
1777 }
1778 //´¿modem°æ±¾
1779 else if('0' == at_paras[0])
1780 {
1781 phoneModeStatus = (0x1 | phoneModeStatus); // ºóһλ1±íʾÊÇ´¿modem°æ±¾
1782 cfg_set("version_mode","1"); //version_mode==1 phonemode==0 Ϊ´¿modem°æ±¾
1783 }
1784 else
1785 {
1786 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1787 *res_msglen = strlen(*res_msg);
1788 return AT_END;
1789 }
1790 retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
1791 if(retCode == CPNV_ERROR){softap_assert("");}
1792 retCode = cpnv_NvramFlush();
1793 if(retCode == CPNV_ERROR){softap_assert("");}
1794
1795 *res_msg = at_ok_build();
1796 *res_msglen = strlen(*res_msg);
1797 return AT_END;
1798}
1799
1800/**************************************************************************
1801* º¯ÊýÃû³Æ: zsoftreset_act_func
1802* ¹¦ÄÜÃèÊö: ÉèÖÃÈí¼þÖØÆô
1803* ²ÎÊý˵Ã÷: (IN)
1804* (OUT)
1805* ·µ »Ø Öµ: ÎÞ
1806* ÆäËü˵Ã÷:
1807**************************************************************************/
1808int zsoftreset_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
1809{
1810 //char *pPtr = NULL;
1811
1812 //zOss_SysSoftReset(SYS_RESET_TO_NORMAL);
1813 ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL,0);
1814
1815 *res_msg = at_query_result_build("ZSOFTRESET", "");
1816 *res_msglen = strlen(*res_msg);
1817
1818 return AT_END;
1819}
1820
1821int ext_ramdump_func(char *at_paras, void ** res_msg)
1822{
1823 assert(0);
1824 return AT_END;
1825}
1826
1827int zmodeSet_act_func_check_mode(char *at_paras, void ** res_msg, int *res_msglen)
1828{
1829 int iUsbMode = -1;
1830 char* at_str = NULL;
1831
1832
1833 if(at_paras==NULL)
1834 softap_assert("zmodeSet_act_func:at_paras is null");
1835
1836 at_str = at_paras;
1837 get_at_cmd_param_int(at_str, &iUsbMode, (const char **)&at_str);
1838 at_print(AT_DEBUG,"zmodeSet_act_func:iUsbMode == %d\n", iUsbMode);
1839
1840 char strCfgGetItem[AT_CMD_MAX] = {0};
1841 nv_get_item(NV_RO, "usb_modetype", strCfgGetItem, sizeof(strCfgGetItem));
1842 at_print(AT_ERR,"current usb mode type = %s\n", strCfgGetItem);
1843
1844 //´ÓÓû§Ä£Ê½Çе½ÆäËû·ÇÓû§Ä£Ê½¶¼ÐèÒª¼øÈ¨
1845/* if((strcmp(strCfgGetItem,"user")== 0)&&(iUsbMode != 0))
1846 {
1847 if(auth_device_key_result != 1 && auth_device_key_init_value() != 1)
1848 {
1849 at_print(AT_ERR,"auth_device_key_result=%d,device key verify fail!\n", auth_device_key_result);
1850 *res_msg = at_err_build(ATERR_NOT_ALLOWED);
1851 *res_msglen = strlen(*res_msg);
1852
1853 iUsbMode = -1;
1854 }
1855 }*/
1856
1857 return iUsbMode;
1858}
1859
1860
1861int zmodeSet_act_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
1862{
1863 int iUsbMode = 0;
1864 UINT8 bootmode[] = {0x54,0x4D};
1865 long retCode = -1;
1866
1867 at_print(AT_DEBUG,"ext_amt_func.c:zmodeSet_act_func\n");
1868
1869 iUsbMode = zmodeSet_act_func_check_mode(at_paras, res_msg, res_msglen);
1870 if(iUsbMode < 0)
1871 {
1872 return AT_END;
1873 }
1874
1875 switch(iUsbMode)
1876 {
1877 case 0: //user mode
1878 {
1879 nv_set_item(NV_RO, "usb_modetype", "user", 1);
1880 bootmode[1] =0x00;
1881 retCode = amt_set_bootmode(bootmode);
1882 break;
1883 }
1884 case 1://debug mode
1885 {
1886 nv_set_item(NV_RO, "usb_modetype", "debug", 1);
1887 bootmode[1] =0x01;
1888 retCode = amt_set_bootmode(bootmode);
1889 break;
1890 }
1891 case 2://factory mode
1892 {
1893 nv_set_item(NV_RO, "usb_modetype", "factory", 1);
1894 bootmode[1] =0x02;
1895 retCode = amt_set_bootmode(bootmode);
1896 break;
1897 }
1898 case 3://amt mode
1899 {
1900 //nv_set_item(NV_RO, "usb_modetype", "amt", 1);
1901 retCode = amt_set_bootmode(bootmode);
1902 break;
1903 }
1904 default:
1905 {
1906 *res_msg = at_err_build(ATERR_PARAM_INVALID);
1907 *res_msglen = strlen(*res_msg);
1908 return AT_END;
1909 }
1910 }
1911
1912 nv_commit(NV_RO);
1913
1914 at_print(AT_DEBUG,"zmodeSet_act_func:retCode == %d\n", retCode);
1915 if (retCode == 0)
1916 {
1917 *res_msg = at_ok_build();
1918 }
1919 else
1920 {
1921 *res_msg = at_err_build(ATERR_PROC_FAILED);
1922 }
1923 *res_msglen = strlen(*res_msg);
1924 return AT_END;
1925}
1926
1927int write_security_info(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
1928{
1929 UINT32 pubKeyHash[4] = {0};
1930 UINT32 secureFlag = 0xFF;
1931 T_ZDrvEfuse_Secure efuseInfo = {{0}};
1932 char strValue[16];
1933 char strLog[256] = {0};
1934 md5_ctx stStc;
1935 int i;
1936 int efuse_fd = -1;
1937 //int ret = -1;
1938
1939 /*************************»ñÈ¡¹«Ô¿hash**************************/
1940 // »ñÈ¡¹«Ô¿
1941 efuse_fd = open("/dev/efuse", O_RDWR);
1942 if (efuse_fd < 0) {
1943 at_print(AT_ERR,"open %s fail.\n","/dev/efuse");
1944 *res_msg = at_err_build(ATERR_PROC_FAILED);
1945 *res_msglen = strlen(*res_msg);
1946 return AT_END;
1947 }
1948
1949 if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
1950 {
1951 at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
1952 *res_msg = at_err_build(ATERR_PROC_FAILED);
1953 *res_msglen = strlen(*res_msg);
1954 close(efuse_fd);
1955 return AT_END;
1956 }
1957 at_print(AT_NORMAL, "security flag in efuse: %08X\r", efuseInfo.secureFlag);
1958
1959 // ¼ÆË㹫ԿhashÖµ
1960 md5_init(&stStc);
1961 md5_update(&stStc, (unsigned char *)efuseInfo.pubKeyRsaE, sizeof(efuseInfo.pubKeyRsaE));
1962 md5_update(&stStc, (unsigned char *)efuseInfo.pubKeyRsaN, sizeof(efuseInfo.pubKeyRsaN));
1963 md5_final((UINT8 *)pubKeyHash, &stStc);
1964
1965 // ´òÓ¡¹«Ô¿hash
1966 strLog[0] = '\0';
1967 for (i = 0; i < sizeof(pubKeyHash)/sizeof(UINT32); i++)
1968 {
1969 pubKeyHash[i] = ((pubKeyHash[i] & 0xff000000) >> 24)
1970 | ((pubKeyHash[i] & 0x00ff0000) >> 8)
1971 | ((pubKeyHash[i] & 0x0000ff00) << 8)
1972 | ((pubKeyHash[i] & 0x000000ff) << 24) ;
1973
1974 sprintf(strValue, "%08lX", pubKeyHash[i]);
1975 strcat(strLog, strValue);
1976 }
1977
1978 at_print(AT_NORMAL, "Public key hash: %s\r", strLog);
1979
1980 /*************************½«°²È«ÐÅϢдÈëefuse**************************/
1981
1982 if (memcmp(efuseInfo.pubKeyHash, pubKeyHash, sizeof(pubKeyHash)) != 0)
1983 {
1984 // ¹«Ô¿hashֵдÈëefuse
1985 if (ioctl(efuse_fd , EFUSE_SET_PUB_KEY_HASH, pubKeyHash) != 0)
1986 {
1987 at_print(AT_ERR, "Write public key hash to efuse fail!\r");
1988 *res_msg = at_err_build(ATERR_PROC_FAILED);
1989 *res_msglen = strlen(*res_msg);
1990 close(efuse_fd);
1991 return AT_END;
1992 }
1993 else
1994 {
1995 at_print(AT_NORMAL, "Write public key hash to efuse success!\r");
1996 }
1997 }
1998 else
1999 {
2000 at_print(AT_NORMAL, "Public key's hash value already exists!\r");
2001 }
2002 /*efuseInfo.secureFlagÇ°Ãæ3¸ö×Ö½ÚÊÇchip flag,×îºóÒ»¸ö×Ö½ÚÊǰ²È«Ê¹ÄܱêÖ¾*/
2003
2004 if ((efuseInfo.secureFlag&0xff) != secureFlag)
2005 {
2006 // ʹÄܱêʶλдÈëefuse
2007 if (ioctl(efuse_fd , EFUSE_SET_SECURE_EN, &secureFlag) != 0)
2008 {
2009 at_print(AT_ERR, "Write security flag to efuse fail!\r");
2010 *res_msg = at_err_build(ATERR_PROC_FAILED);
2011 *res_msglen = strlen(*res_msg);
2012 close(efuse_fd);
2013 return AT_END;
2014 }
2015 else
2016 {
2017 at_print(AT_NORMAL, "Write security flag to efuse success!\r");
2018 }
2019 }
2020
2021 else
2022 {
2023 at_print(AT_NORMAL, "Secure flag already exists!\r");
2024 }
2025
2026 /*************************ÅжÏдÈëµÄÐÅÏ¢ÊÇ·ñÕýÈ·**************************/
2027 // ´Óefuse¶ÁÈ¡
2028 memset(&efuseInfo, 0, sizeof(efuseInfo));
2029 if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
2030 {
2031 at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
2032 *res_msg = at_err_build(ATERR_PROC_FAILED);
2033 *res_msglen = strlen(*res_msg);
2034 close(efuse_fd);
2035 return AT_END;
2036 }
2037
2038 if ((efuseInfo.secureFlag&0xff) != secureFlag)
2039 {
2040 at_print(AT_ERR, "Security flag(%#08X) is not consistent!\r", efuseInfo.secureFlag);
2041 *res_msg = at_err_build(ATERR_PROC_FAILED);
2042 *res_msglen = strlen(*res_msg);
2043 close(efuse_fd);
2044 return AT_END;
2045 }
2046
2047 if (memcmp(efuseInfo.pubKeyHash, pubKeyHash, sizeof(pubKeyHash)) != 0)
2048 {
2049 at_print(AT_ERR, "Public key hash is not consistent!\r");
2050 *res_msg = at_err_build(ATERR_PROC_FAILED);
2051 *res_msglen = strlen(*res_msg);
2052 close(efuse_fd);
2053 return AT_END;
2054 }
2055
2056 *res_msg = at_query_result_build("write security infomation", NULL);
2057 *res_msglen = strlen(*res_msg);
2058 close(efuse_fd);
2059 return AT_END;
2060}
mj.qu9ffae7d2025-08-25 20:03:44 -07002061
2062int read_security_info(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
2063{
2064 char strValue[16];
2065 char strLog[256] = {0};
2066 int i;
2067 int ret = 0;
2068 T_ZDrvEfuse_Secure efuseInfo = {{0}};
2069 int efuse_fd = -1;
2070
2071 efuse_fd = open("/dev/efuse", O_RDWR);
2072 if (efuse_fd < 0)
2073 {
2074 at_print(AT_ERR,"open %s fail.\n","/dev/efuse");
2075 *res_msg = at_err_build(ATERR_PROC_FAILED);
2076 *res_msglen = strlen(*res_msg);
2077 return AT_END;
2078 }
2079
2080 at_print(AT_ERR,"open %s success.\n","/dev/efuse");
2081
2082 // ´Óefuse¶ÁÈ¡
2083 if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
2084 {
2085 at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
2086 *res_msg = at_err_build(ATERR_PROC_FAILED);
2087 *res_msglen = strlen(*res_msg);
2088 close(efuse_fd);
2089 return AT_END;
2090 }
2091 else
2092 {
2093 at_print(AT_ERR,"ioctl: EFUSE_GET_DATA success.\n");
2094 strLog[0] = '\0';
2095 sprintf(strValue, "%02X,", efuseInfo.secureFlag&0xFF);
2096 strcat(strLog, strValue);
2097 for (i = 0; i < sizeof(efuseInfo.pubKeyHash)/sizeof(UINT32); i++)
2098 {
2099 sprintf(strValue, "%08lX", efuseInfo.pubKeyHash[i]);
2100 strcat(strLog, strValue);
2101 }
2102 at_print(AT_ERR, "Secure Flag,Public key hash: %s\n", strLog);
2103 close(efuse_fd);
2104 *res_msg = at_query_result_build("read security information", strLog);
2105 *res_msglen = strlen(*res_msg);
2106 return AT_END;
2107
2108 }
2109}
2110
mj.qu5c355a02025-08-25 19:59:01 -07002111/*
2112int auth_device_key(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
2113{
2114 char *at_str = NULL;
2115
2116 at_print(AT_ERR,"at_paras=%s\n",at_paras);
2117
2118 at_str = at_paras;
2119 char seed[] = SEED;
2120 auth_device_key_result = verify_device_key(at_str,strlen(at_str),seed,strlen(seed));
2121 at_print(AT_ERR,"auth_device_key_result=%d\n",auth_device_key_result);
2122
2123 if (auth_device_key_result == 1)
2124 {
2125 *res_msg = at_ok_build();
2126 }
2127 else
2128 {
2129 at_print(AT_ERR,"verify device key fail !\n");
2130 *res_msg = at_err_build(ATERR_PROC_FAILED);
2131 }
2132 *res_msglen = strlen(*res_msg);
2133
2134 return AT_END;
2135}
2136*/
2137
2138int ext_amt_regist(void)
2139{
2140 if(!ext_is_usermode())
2141 {
2142 register_serv_func2("MODIMEI=",0,0,0,imeiWrite_act_func,NULL);
2143 register_serv_func2("PHONEMODE=",0,0,0,zphone_mode_set_req_act, 0);
2144 register_serv_func("ramdump",0,ext_ramdump_func);
2145 // дÈ밲ȫÐÅÏ¢
2146 register_serv_func2("WSCYINFO",0,0,0,write_security_info,NULL);
2147 }
2148 register_serv_func2("RKEYDC=",0,0,0,rkeydc_act_func,NULL);
2149 register_serv_func2("ZPOWEROFF",0,0,0,poweroff_act_func,NULL);
2150 register_serv_func2("PLATFORM?",0,0,0,chip_platform_read_act_func,NULL);
2151 register_serv_func2("READIMEI",0,0,0,imeiRead_act_func,NULL);
2152 register_serv_func2("READIMEI?",0,0,0,imeiRead_act_func,NULL);
2153 register_serv_func2("SSID?",0,0,0,ssidRead_act_func,NULL);
2154 register_serv_func2("SSID=",0,0,0,ssidWrite_act_func,NULL);
2155 register_serv_func2("ZVERSIONTYPE=",0,0,0,versionTypeSet_act_func,NULL);
2156 register_serv_func2("MAC?",0,0,0,macRead_act_func,NULL);
2157 register_serv_func2("MAC=",0,0,0,macWrite_act_func,NULL);
2158 register_serv_func2("WIFIKEY?",0,0,0,wifikeyRead_act_func,NULL);
2159 register_serv_func2("WIFIKEY=",0,0,0,wifikeyWrite_act_func,NULL);
2160 register_serv_func2("ETHMAC?",0,0,0,rj45MacAddrRead_act_func,NULL);
2161 register_serv_func2("ETHMAC=",0,0,0,rj45MacAddWrite_act_func,NULL);
2162 register_serv_func2("MAC2?",0,0,0,mac2Read_act_func,NULL);
2163 register_serv_func2("MAC2=",0,0,0,mac2Write_act_func,NULL);
2164 register_serv_func2("USBMAC?",0,0,0,usbmacRead_act_func,NULL);
2165 register_serv_func2("USBMAC=",0,0,0,usbmacWrite_act_func,NULL);
2166 register_serv_func2("GMAC?",0,0,0,gmacRead_act_func,NULL);
2167 register_serv_func2("GMAC=",0,0,0,gmacWrite_act_func,NULL);
2168 register_serv_func2("BATDET?",0,0,0,batdetRead_act_func,NULL);
2169 register_serv_func2("BATDET=",0,0,0,batdetWrite_act_func,NULL);
2170 register_serv_func2("MSN?",0,0,0,msnRead_act_func,NULL);
2171 register_serv_func2("MSN=",0,0,0,msnWrite_act_func,NULL);
2172 register_serv_func2("RTESTINFO",0,0,0,testInfoRead_act_func,NULL);
2173 register_serv_func2("ZAMTMODE=",0,0,0,closeAutoInd_act_func,NULL);
2174
2175 //Çл»Õý³£°æ±¾ºÍ´¿modem°æ±¾
2176 register_serv_func2("PHONEMODE?",0,0,0,zphone_mode_query_req_act, 0);
2177
2178 register_serv_func2("ZSOFTRESET",0,0,0,zsoftreset_act_func,NULL);
2179
2180 register_serv_func2("zmode=",0,0,0,zmodeSet_act_func,NULL);
2181 //mdlÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨AT+ZAUTH=KEY
2182 //register_serv_func2("ZAUTH=",0,0,0,auth_device_key,NULL);
mj.qu9ffae7d2025-08-25 20:03:44 -07002183 register_serv_func2("RSCYINFO",0,0,0,read_security_info,NULL);
mj.qu5c355a02025-08-25 19:59:01 -07002184 return 0;
2185}