| /**
 | 
 |  * 
 | 
 |  * @file      ext_amt_func.c
 | 
 |  * @brief     
 | 
 |  *            This file is part of FTM.
 | 
 |  *            AMTÄ£¿éÏà¹ØATÃüÁî
 | 
 |  *            
 | 
 |  * @details   
 | 
 |  * @author    Tools Team.
 | 
 |  * @email     
 | 
 |  * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
 | 
 |  * @warning   
 | 
 |  * @date      2019/02/02
 | 
 |  * @version   1.1
 | 
 |  * @pre       
 | 
 |  * @post      
 | 
 |  *            
 | 
 |  * @par       
 | 
 |  * Change History :
 | 
 |  * ---------------------------------------------------------------------------
 | 
 |  * date        version  author         description
 | 
 |  * ---------------------------------------------------------------------------
 | 
 |  * 2018/04/28  1.0      liu.xin        Create file
 | 
 |  * 2019/02/02  1.1      jiang.fenglin  ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
 | 
 |  * ---------------------------------------------------------------------------
 | 
 |  * 
 | 
 |  * 
 | 
 |  */
 | 
 | 
 | 
 | #include "ext_regist.h"
 | 
 | #include "at_com.h"
 | 
 | #include <unistd.h>
 | 
 | #include <sys/syscall.h> 
 | 
 | #include "RONvParam_AMT.h"
 | 
 | #include "ref_nv_def.h"
 | 
 | #include "nv_api.h"
 | 
 | #include "amtnv.h"
 | 
 | #include <linux/soc/zte/efuse/efuse_zx.h>
 | 
 | #include "NvParam_drv.h"
 | 
 | #include "libkey.h"
 | 
 | 
 | 
 | //mdlÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨½á¹û
 | 
 | static int auth_device_key_result = 0;
 | 
 | 
 | 
 | #define GET_LCD_INFO   378
 | 
 | #define GET_WIFI_INFO  379
 | 
 | #define GET_FLASH_INFO 380
 | 
 | #define GET_CPU_INFO   381
 | 
 | #define GET_DDR_INFO   382
 | 
 | //CP
 | 
 | typedef unsigned char  BYTE;
 | 
 | 
 | 
 | #define DC_MacLen               (BYTE)12
 | 
 | #define DC_ImeiLen              (BYTE)8
 | 
 | #define MSN_MAX_NVINFO_LEN      20
 | 
 | #define MSINFO_MAX_NVINFO_LEN   200
 | 
 | #define MDMVERSION_MAX_LEN      64
 | 
 | #define bInside(data, up, down) (((data) <= (up) && (data) >= (down)) || \
 | 
 |                                                   ((data) >= (up) && (data) <= (down)))
 | 
 | typedef unsigned long u32_t;
 | 
 | 	
 | 
 | #ifndef SMEMCPY
 | 
 | #define SMEMCPY(dst,src,len)            memcpy(dst,src,len)
 | 
 | #endif
 | 
 | 
 | 
 | /**
 | 
 |  * @brief ZMDMVERSIONÏìÓ¦ÏûÏ¢½á¹¹Ìå
 | 
 |  * @param result  ½á¹ûÂë AT_RSP_OK/AT_RSP_ERR
 | 
 |  * @param mdmVer  modem°æ±¾ºÅ
 | 
 |  */
 | 
 | typedef struct
 | 
 | {
 | 
 |     char mdmVer[MDMVERSION_MAX_LEN]; 
 | 
 |     int result;
 | 
 | }AT_MDMVERSION_RSP_INFO;
 | 
 | 
 | 
 | //static char mdmVer[MDMVERSION_MAX_LEN] = {0};//ÓÃÓڼǼZGMR »Ø¸´½á¹û
 | 
 | 
 | 
 | struct flash_ddr_info{
 | 
 |     char manu[32];
 | 
 |     char model[32];
 | 
 |     char size[32];
 | 
 |     char other[32];
 | 
 | };
 | 
 | 
 | 
 | struct lcd_info
 | 
 | {
 | 
 |     char manu[32];
 | 
 |     char ic[32];
 | 
 |     char resolution[32];
 | 
 | };
 | 
 | 
 | 
 | struct wifi_info
 | 
 | {
 | 
 |     char manu[32];
 | 
 |     char ic[32];
 | 
 | };
 | 
 | struct cpu_info{
 | 
 |     char manu[32];
 | 
 |     char model[32];
 | 
 | };
 | 
 | 
 | 
 | /* Data structure for MD5 (Message-Digest) computation */
 | 
 | typedef struct {
 | 
 |   u32_t i[2];               /* number of _bits_ handled mod 2^64 */
 | 
 |   u32_t buf[4];             /* scratch buffer */
 | 
 |   unsigned char in[64];     /* input buffer */
 | 
 |   unsigned char digest[16]; /* actual digest after md5_final call */
 | 
 | } md5_ctx;
 | 
 | 
 | 
 | 
 | 
 | extern void at_context_chn_info_mod(char *at_paras);
 | 
 | 
 | 
 | /*
 | 
 |  ***********************************************************************
 | 
 |  **  Message-digest routines:                                         **
 | 
 |  **  To form the message digest for a message M                       **
 | 
 |  **    (1) Initialize a context buffer ctx using md5_init             **
 | 
 |  **    (2) Call md5_update on ctx and M                               **
 | 
 |  **    (3) Call md5_final on ctx                                      **
 | 
 |  **  The message digest is now in ctx->digest[0...15]                 **
 | 
 |  ***********************************************************************
 | 
 |  */
 | 
 | 
 | 
 | /* forward declaration */
 | 
 | static void transform(u32_t *buf, u32_t *in);
 | 
 | 
 | 
 | static unsigned char PADDING[64] = {
 | 
 |   0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
 |   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 | 
 | };
 | 
 | 
 | 
 | /* F, G, H and I are basic MD5 functions */
 | 
 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
 | 
 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
 | 
 | #define H(x, y, z) ((x) ^ (y) ^ (z))
 | 
 | #define I(x, y, z) ((y) ^ ((x) | (~z)))
 | 
 | 
 | 
 | /* ROTATE_LEFT rotates x left n bits */
 | 
 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
 | 
 | 
 | 
 | /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
 | 
 | /* Rotation is separate from addition to prevent recomputation */
 | 
 | #define FF(a, b, c, d, x, s, ac) \
 | 
 |   {(a) += F ((b), (c), (d)) + (x) + (u32_t)(ac); \
 | 
 |    (a) = ROTATE_LEFT ((a), (s)); \
 | 
 |    (a) += (b); \
 | 
 |   }
 | 
 | #define GG(a, b, c, d, x, s, ac) \
 | 
 |   {(a) += G ((b), (c), (d)) + (x) + (u32_t)(ac); \
 | 
 |    (a) = ROTATE_LEFT ((a), (s)); \
 | 
 |    (a) += (b); \
 | 
 |   }
 | 
 | #define HH(a, b, c, d, x, s, ac) \
 | 
 |   {(a) += H ((b), (c), (d)) + (x) + (u32_t)(ac); \
 | 
 |    (a) = ROTATE_LEFT ((a), (s)); \
 | 
 |    (a) += (b); \
 | 
 |   }
 | 
 | #define II(a, b, c, d, x, s, ac) \
 | 
 |   {(a) += I ((b), (c), (d)) + (x) + (u32_t)(ac); \
 | 
 |    (a) = ROTATE_LEFT ((a), (s)); \
 | 
 |    (a) += (b); \
 | 
 |   }
 | 
 | 
 | 
 | #ifdef __STDC__
 | 
 | #define UL(x) x##UL
 | 
 | #else
 | 
 | #ifdef WIN32
 | 
 | #define UL(x) x##UL
 | 
 | #else
 | 
 | #define UL(x) x
 | 
 | #endif
 | 
 | #endif
 | 
 | 
 | 
 | /* The routine md5_init initializes the message-digest context
 | 
 |    mdContext. All fields are set to zero.
 | 
 |  */
 | 
 | void md5_init(md5_ctx *ctx)
 | 
 | {
 | 
 | 	ctx->i[0] = ctx->i[1] = (u32_t)0;
 | 
 | 
 | 
 |   /* Load magic initialization constants. */
 | 
 |     ctx->buf[0] = (u32_t)0x67452301UL;
 | 
 |     ctx->buf[1] = (u32_t)0xefcdab89UL;
 | 
 |     ctx->buf[2] = (u32_t)0x98badcfeUL;
 | 
 |     ctx->buf[3] = (u32_t)0x10325476UL;
 | 
 | }
 | 
 | 
 | 
 | /* The routine md5_update updates the message-digest context to
 | 
 |    account for the presence of each of the characters buf[0..inLen-1]
 | 
 |    in the message whose digest is being computed.
 | 
 |  */
 | 
 | 
 | 
 | void md5_update(md5_ctx *ctx, unsigned char *buf, unsigned int len)
 | 
 | {
 | 
 |   u32_t in[16];
 | 
 |   int mdi;
 | 
 |   unsigned int i, ii;
 | 
 | 
 | 
 | #if 0
 | 
 |   ppp_trace(LOG_INFO, "MD5Update: %u:%.*H\n", len, MIN(len, 20) * 2, buf);
 | 
 |   ppp_trace(LOG_INFO, "MD5Update: %u:%s\n", len, buf);
 | 
 | #endif
 | 
 | 
 | 
 |   /* compute number of bytes mod 64 */
 | 
 |   mdi = (int)((ctx->i[0] >> 3) & 0x3F);
 | 
 | 
 | 
 |   /* update number of bits */
 | 
 |   if ((ctx->i[0] + ((u32_t)len << 3)) < ctx->i[0]) {
 | 
 |     ctx->i[1]++;
 | 
 |   }
 | 
 |   ctx->i[0] += ((u32_t)len << 3);
 | 
 |   ctx->i[1] += ((u32_t)len >> 29);
 | 
 | 
 | 
 |   while (len--) {
 | 
 |     /* add new character to buffer, increment mdi */
 | 
 |     ctx->in[mdi++] = *buf++;
 | 
 | 
 | 
 |     /* transform if necessary */
 | 
 |     if (mdi == 0x40) {
 | 
 |       for (i = 0, ii = 0; i < 16; i++, ii += 4) {
 | 
 |         in[i] = (((u32_t)ctx->in[ii+3]) << 24) |
 | 
 |                 (((u32_t)ctx->in[ii+2]) << 16) |
 | 
 |                 (((u32_t)ctx->in[ii+1]) << 8)  |
 | 
 |                 ((u32_t)ctx->in[ii]);
 | 
 |       }
 | 
 |       transform (ctx->buf, in);
 | 
 |       mdi = 0;
 | 
 |     }
 | 
 |   }
 | 
 | }
 | 
 | 
 | 
 | /* The routine md5_final terminates the message-digest computation and
 | 
 |    ends with the desired message digest in ctx->digest[0...15].
 | 
 |  */
 | 
 | 
 | 
 | void md5_final(unsigned char hash[], md5_ctx *ctx)
 | 
 | {
 | 
 |   u32_t in[16];
 | 
 |   int mdi;
 | 
 |   unsigned int i, ii;
 | 
 |   unsigned int pad_len;
 | 
 | 
 | 
 |   /* save number of bits */
 | 
 |   in[14] = ctx->i[0];
 | 
 |   in[15] = ctx->i[1];
 | 
 | 
 | 
 |   /* compute number of bytes mod 64 */
 | 
 |   mdi = (int)((ctx->i[0] >> 3) & 0x3F);
 | 
 | 
 | 
 |   /* pad out to 56 mod 64 */
 | 
 |   pad_len = (mdi < 56) ? (56 - mdi) : (120 - mdi);
 | 
 |   md5_update (ctx, PADDING, pad_len);
 | 
 | 
 | 
 |   /* append length in bits and transform */
 | 
 |   for (i = 0, ii = 0; i < 14; i++, ii += 4) {
 | 
 |     in[i] = (((u32_t)ctx->in[ii+3]) << 24) |
 | 
 |             (((u32_t)ctx->in[ii+2]) << 16) |
 | 
 |             (((u32_t)ctx->in[ii+1]) << 8)  |
 | 
 |             ((u32_t)ctx->in[ii]);
 | 
 |   }
 | 
 |   transform (ctx->buf, in);
 | 
 | 
 | 
 |   /* store buffer in digest */
 | 
 |   for (i = 0, ii = 0; i < 4; i++, ii += 4) {
 | 
 |     ctx->digest[ii]   = (unsigned char)(ctx->buf[i] & 0xFF);
 | 
 |     ctx->digest[ii+1] =
 | 
 |       (unsigned char)((ctx->buf[i] >> 8)  & 0xFF);
 | 
 |     ctx->digest[ii+2] =
 | 
 |       (unsigned char)((ctx->buf[i] >> 16) & 0xFF);
 | 
 |     ctx->digest[ii+3] =
 | 
 |       (unsigned char)((ctx->buf[i] >> 24) & 0xFF);
 | 
 |   }
 | 
 |   SMEMCPY(hash, ctx->digest, 16);
 | 
 | }
 | 
 | 
 | 
 | /* Basic MD5 step. Transforms buf based on in.
 | 
 |  */
 | 
 | static void transform (u32_t *buf, u32_t *in)
 | 
 | {
 | 
 |   u32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3];
 | 
 | 
 | 
 |   /* Round 1 */
 | 
 |   #define S11 7
 | 
 |   #define S12 12
 | 
 |   #define S13 17
 | 
 |   #define S14 22
 | 
 |   FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
 | 
 |   FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
 | 
 |   FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
 | 
 |   FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
 | 
 |   FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
 | 
 |   FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
 | 
 |   FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
 | 
 |   FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
 | 
 |   FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
 | 
 |   FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
 | 
 |   FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
 | 
 |   FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
 | 
 |   FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
 | 
 |   FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
 | 
 |   FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
 | 
 |   FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
 | 
 | 
 | 
 |   /* Round 2 */
 | 
 |   #define S21 5
 | 
 |   #define S22 9
 | 
 |   #define S23 14
 | 
 |   #define S24 20
 | 
 |   GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
 | 
 |   GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
 | 
 |   GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
 | 
 |   GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
 | 
 |   GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
 | 
 |   GG ( d, a, b, c, in[10], S22, UL(  38016083)); /* 22 */
 | 
 |   GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
 | 
 |   GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
 | 
 |   GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
 | 
 |   GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
 | 
 |   GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
 | 
 |   GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
 | 
 |   GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
 | 
 |   GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
 | 
 |   GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
 | 
 |   GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
 | 
 | 
 | 
 |   /* Round 3 */
 | 
 |   #define S31 4
 | 
 |   #define S32 11
 | 
 |   #define S33 16
 | 
 |   #define S34 23
 | 
 |   HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
 | 
 |   HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
 | 
 |   HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
 | 
 |   HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
 | 
 |   HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
 | 
 |   HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
 | 
 |   HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
 | 
 |   HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
 | 
 |   HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
 | 
 |   HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
 | 
 |   HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
 | 
 |   HH ( b, c, d, a, in[ 6], S34, UL(  76029189)); /* 44 */
 | 
 |   HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
 | 
 |   HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
 | 
 |   HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
 | 
 |   HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
 | 
 | 
 | 
 |   /* Round 4 */
 | 
 |   #define S41 6
 | 
 |   #define S42 10
 | 
 |   #define S43 15
 | 
 |   #define S44 21
 | 
 |   II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
 | 
 |   II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
 | 
 |   II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
 | 
 |   II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
 | 
 |   II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
 | 
 |   II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
 | 
 |   II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
 | 
 |   II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
 | 
 |   II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
 | 
 |   II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
 | 
 |   II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
 | 
 |   II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
 | 
 |   II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
 | 
 |   II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
 | 
 |   II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
 | 
 |   II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
 | 
 | 
 | 
 |   buf[0] += a;
 | 
 |   buf[1] += b;
 | 
 |   buf[2] += c;
 | 
 |   buf[3] += d;
 | 
 | }
 | 
 | 
 | 
 | static int is_mac_valid(char*macStr)
 | 
 | {
 | 
 |     int Macindex = 0;
 | 
 | 	for (; (macStr[Macindex] != '\0') && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE); Macindex++)
 | 
 |     {
 | 
 |         char chmac = macStr[Macindex];
 | 
 |         if (!(bInside(chmac, '0', '9') || bInside(chmac, 'a', 'f') || bInside(chmac, 'A', 'F')))
 | 
 |         {
 | 
 |             at_print(AT_DEBUG,"mac is not hex str\r");
 | 
 |             return FALSE;
 | 
 |         }
 | 
 | 	}
 | 
 |     return TRUE;
 | 
 | }
 | 
 | static char Ascii2BCD(char iAscii)
 | 
 | {
 | 
 |     char iBCD;
 | 
 | 
 | 
 |     if ( bInside(iAscii, '0', '9'))
 | 
 |     {
 | 
 |         iBCD = iAscii - '0';
 | 
 | 
 | 
 |     }
 | 
 |     else if (bInside(iAscii, 'a', 'f'))
 | 
 |     {
 | 
 |         iBCD = iAscii - 'a' + 0x0a;
 | 
 | 
 | 
 |     }
 | 
 |     else if (bInside(iAscii, 'A', 'F'))
 | 
 |     {
 | 
 |         iBCD = iAscii - 'A' + 0x0a;
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         return -1;
 | 
 |     }
 | 
 | 
 | 
 |     return iBCD;
 | 
 | 
 | 
 | }
 | 
 | 
 | 
 | static char BCD2Ascii(char iBCD)
 | 
 | {
 | 
 |     char iAscii;
 | 
 | 
 | 
 |     if (bInside(iBCD, 0x00, 0x09))
 | 
 |     {
 | 
 |         iAscii = (unsigned char)(iBCD + '0');
 | 
 |     }
 | 
 |     else if (bInside(iBCD, 0x0a, 0x0f))
 | 
 |     {
 | 
 |         iAscii = (unsigned char)((iBCD - 0x0a) + 'A');
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         return -1;
 | 
 |     }
 | 
 |     return iAscii;
 | 
 | }
 | 
 | 
 | 
 | static int IsImeiStrValid(char* imeiStr)
 | 
 | {
 | 
 |     int i = 0;
 | 
 |     for (; i < 15; ++i)
 | 
 |     {
 | 
 |         if (imeiStr[i] < '0' || imeiStr[i] > '9')
 | 
 |         {
 | 
 |             return FALSE;
 | 
 |         }
 | 
 |     }
 | 
 |     return TRUE;
 | 
 | }
 | 
 | 
 | 
 | static long Char2Int(char chr)
 | 
 | {
 | 
 |     long value = 0;
 | 
 |     value =  (chr - '0');
 | 
 |     return value;
 | 
 | }
 | 
 | 
 | 
 | static char Int2Char(long value)
 | 
 | {
 | 
 |     char ch = '0'+value;
 | 
 |     return ch;
 | 
 | }
 | 
 | 
 | 
 | static unsigned long DC_Writeimei(char * imeistr)
 | 
 | {
 | 
 |     int     Imeiindex =0,checkindex=0;
 | 
 |     BYTE    abImei[DC_ImeiLen]={0};
 | 
 |     BYTE    Index1=0,Index2=0;
 | 
 |     
 | 
 |     for(Imeiindex=0;imeistr[Imeiindex]!='\0';Imeiindex+=2)
 | 
 |     {    
 | 
 |         at_print(AT_DEBUG,"Imeiindex= %d\r\n",Imeiindex);
 | 
 |         at_print(AT_DEBUG,"imeistr[%d]= %c\r\n",Imeiindex,imeistr[Imeiindex]);
 | 
 | 
 | 
 |         Index1=Char2Int((char)imeistr[Imeiindex]);      
 | 
 |         at_print(AT_DEBUG,"Index1= %d\r",Index1);
 | 
 |         
 | 
 |         if((imeistr[Imeiindex+1])!='\0')
 | 
 |         {
 | 
 |         
 | 
 |             Index2= Char2Int((char)imeistr[Imeiindex+1]);
 | 
 |             at_print(AT_DEBUG,"Index2= %d, Index2<<4 =%x , (Index2<<4)&Index1 = %x\r\n",Index2,Index2<<4,(Index2<<4)|Index1);
 | 
 | 
 | 
 |             abImei[Imeiindex/2]=(Index2<<4)|Index1;
 | 
 |             at_print(AT_DEBUG,"abImei[%d]= %x\r\n",Imeiindex/2,abImei[Imeiindex/2]);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             abImei[Imeiindex/2]=0xF0|Index1;
 | 
 |             at_print(AT_DEBUG,"abImei[%d]= %x\r\n",Imeiindex/2,abImei[Imeiindex/2]);
 | 
 |             break;
 | 
 |         }
 | 
 |     }
 | 
 |     for(checkindex=0;checkindex<8;checkindex++)
 | 
 |     {
 | 
 |         at_print(AT_DEBUG,"abImei[%d] = %x\r\n",checkindex,abImei[checkindex]);
 | 
 |     }
 | 
 | 
 | 
 |     if(CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, sizeof(abImei), abImei))
 | 
 |     {
 | 
 |         at_print(AT_ERR,"Write amt imei failed\r\n");
 | 
 |         return  -1;
 | 
 |     }
 | 
 | 
 | 
 |     return 0;
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: DC_WriteMacAddr
 | 
 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | static unsigned long DC_WriteMacAddr(char *macstr)
 | 
 | {
 | 
 |     unsigned long   Macindex = 0;
 | 
 |     unsigned char   abMac[OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE] = {0};
 | 
 |     unsigned char   Index1 = 0;
 | 
 |     unsigned char   Index2 = 0;
 | 
 | 
 | 
 | 	if(!is_mac_valid(macstr))
 | 
 | 	{
 | 
 | 	     at_print(AT_DEBUG,"mac is not hex str\r");
 | 
 |          return -1;
 | 
 | 	}
 | 
 | 
 | 
 |     /*ASCIIÂëת»»³ÉBCDÂë*/
 | 
 |     for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE); Macindex += 2)
 | 
 |     {
 | 
 |         Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
 | 
 |         Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
 | 
 |         abMac[Macindex/2]=(Index1<<4)|Index2;
 | 
 |     }
 | 
 |     
 | 
 |     if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_WIFIMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE, abMac))
 | 
 |     {
 | 
 |         at_print(AT_DEBUG,"Write amt mac failed\r");
 | 
 |         return  -1;
 | 
 |     }
 | 
 | 
 | 
 |     return  0;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: DC_WriteMac2Addr
 | 
 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | static unsigned long DC_WriteMac2Addr(char *macstr)
 | 
 | {
 | 
 |     unsigned long   Macindex = 0;
 | 
 |     unsigned char   abMac[OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE] = {0};
 | 
 |     unsigned char   Index1 = 0;
 | 
 |     unsigned char   Index2 = 0;
 | 
 | 	
 | 
 | 	if(!is_mac_valid(macstr))
 | 
 | 	{
 | 
 | 	     at_print(AT_DEBUG,"mac is not hex str\r");
 | 
 |          return -1;
 | 
 | 	}
 | 
 | 
 | 
 |     /*ASCIIÂëת»»³ÉBCDÂë*/
 | 
 |     for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE); Macindex += 2)
 | 
 |     {
 | 
 |         Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
 | 
 |         Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
 | 
 | 		abMac[Macindex/2]=(Index1<<4)|Index2;
 | 
 |     }
 | 
 |     
 | 
 |     if (CPNV_ERROR== amt_nvro_write(OS_FLASH_AMT_COMM_RO_WIFIMAC2_ADDRESS, OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE, abMac))
 | 
 |     {
 | 
 |         at_print(AT_DEBUG,"Write amt mac failed\r");
 | 
 |         return -1;
 | 
 |     }
 | 
 | 
 | 
 |     return 0;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: DC_WriteRJ45MacAddr
 | 
 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | unsigned long DC_WriteRJ45MacAddr(char *macstr)
 | 
 | {
 | 
 |     unsigned long   Macindex = 0;
 | 
 |     unsigned char   abMac[OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE] = {0};
 | 
 |     unsigned char   Index1 = 0;
 | 
 |     unsigned char   Index2 = 0;
 | 
 | 
 | 
 | 	if(!is_mac_valid(macstr))
 | 
 | 	{
 | 
 | 	     at_print(AT_DEBUG,"mac is not hex str\r");
 | 
 |          return -1;
 | 
 | 	}
 | 
 | 
 | 
 |     /*ASCIIÂëת»»³ÉBCDÂë*/
 | 
 |     for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE); Macindex += 2)
 | 
 |     {
 | 
 |         Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
 | 
 |         Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
 | 
 |         abMac[Macindex/2]=(Index1<<4)|Index2;
 | 
 |     }
 | 
 | 
 | 
 |     if (CPNV_ERROR== amt_nvro_write(OS_FLASH_AMT_COMM_RO_ETHMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE, abMac))
 | 
 |     {
 | 
 |         at_print(AT_DEBUG,"Write amt ethmac failed\r");
 | 
 |         return -1;
 | 
 |     }
 | 
 | 
 | 
 |     return 0;
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: DC_WriteMacAddr
 | 
 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«USB MACµØÖ·Ð´Èëµ½NVÖÐ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | static unsigned long DC_WriteUSBMacAddr(char *macstr)
 | 
 | {
 | 
 |     unsigned long   Macindex = 0;
 | 
 |     unsigned char   abMac[OS_FLASH_AMT_COMM_RO_USBMAC_SIZE] = {0};
 | 
 |     unsigned char   Index1 = 0;
 | 
 |     unsigned char   Index2 = 0;
 | 
 | 
 | 
 | 	if(!is_mac_valid(macstr))
 | 
 | 	{
 | 
 | 	     at_print(AT_DEBUG,"mac is not hex str\r");
 | 
 |          return -1;
 | 
 | 	}
 | 
 | 
 | 
 |     /*ASCIIÂëת»»³ÉBCDÂë*/
 | 
 |     for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_USBMAC_SIZE); Macindex += 2)
 | 
 |     {
 | 
 |         Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
 | 
 |         Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
 | 
 |         abMac[Macindex/2]=(Index1<<4)|Index2;
 | 
 |     }
 | 
 |     
 | 
 |     if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_USBMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_USBMAC_SIZE, abMac))
 | 
 |     {
 | 
 |         at_print(AT_DEBUG,"Write amt usb mac failed\r");
 | 
 |         return  -1;
 | 
 |     }
 | 
 | 
 | 
 |     return  0;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: DC_WriteMacAddr
 | 
 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«GMACµØÖ·Ð´Èëµ½NVÖÐ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | static unsigned long DC_WriteGmacAddr(char *macstr)
 | 
 | {
 | 
 |     unsigned long   Macindex = 0;
 | 
 |     unsigned char   abMac[OS_FLASH_AMT_COMM_RO_GMAC_SIZE] = {0};
 | 
 |     unsigned char   Index1 = 0;
 | 
 |     unsigned char   Index2 = 0;
 | 
 | 
 | 
 | 	if(!is_mac_valid(macstr))
 | 
 | 	{
 | 
 | 	     at_print(AT_DEBUG,"mac is not hex str\r");
 | 
 |          return -1;
 | 
 | 	}
 | 
 | 
 | 
 |     /*ASCIIÂëת»»³ÉBCDÂë*/
 | 
 |     for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_GMAC_SIZE); Macindex += 2)
 | 
 |     {
 | 
 |         Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
 | 
 |         Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
 | 
 |         abMac[Macindex/2]=(Index1<<4)|Index2;
 | 
 |     }
 | 
 | 
 | 
 |     if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_GMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_GMAC_SIZE, abMac))
 | 
 |     {
 | 
 |         at_print(AT_DEBUG,"Write amt Gmac failed\r");
 | 
 |         return  -1;
 | 
 |     }
 | 
 | 
 | 
 |     return  0;
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | static int rkeydc_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
 | 
 | {
 | 
 |     int retCode = -1;
 | 
 |     //char pStr[8] = {0};
 | 
 |     char *at_str = NULL;
 | 
 |     struct flash_ddr_info flashInfo = {{0}};
 | 
 |     struct flash_ddr_info ddrInfo = {{0}};
 | 
 |     struct cpu_info cpuInfo = {{0}};
 | 
 |     struct wifi_info wifiInfo = {{0}};
 | 
 |     struct lcd_info lcdInfo = {{0}};
 | 
 |     
 | 
 |     at_print(AT_ERR,"rkeydc_act_func: \n");
 | 
 |     at_str = malloc(64);
 | 
 | 	if(at_str == NULL)
 | 
 | 		return AT_END;
 | 
 |     memset(at_str,0,64);
 | 
 |     if(strstr(at_paras, "DDR"))
 | 
 |     {
 | 
 |         retCode = syscall(GET_DDR_INFO,ddrInfo.manu,ddrInfo.size,ddrInfo.model);
 | 
 |         if(retCode < 0)
 | 
 |         {
 | 
 |             at_print(AT_ERR,"rkeydc_act_func: syscall GET_DDR_INFO failed \n");
 | 
 | 			free(at_str);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |         at_print(AT_ERR,"rkeydc_act_func: ddrInfo.manu = %s,size = %s,model =%s\n",ddrInfo.manu,ddrInfo.size,ddrInfo.model);
 | 
 |         snprintf((char*)at_str,64,"\r\n%s?NA?NA?%s?%s\r\n",ddrInfo.manu,ddrInfo.size,ddrInfo.model);
 | 
 |         *res_msg = at_str;
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else if(strstr(at_paras, "FLASH"))
 | 
 |     {
 | 
 |         retCode = syscall(GET_FLASH_INFO,flashInfo.manu,flashInfo.model,flashInfo.size);
 | 
 |         if(retCode < 0)
 | 
 |         {
 | 
 |             at_print(AT_ERR,"rkeydc_act_func: syscall GET_FLASH_INFO failed \n");
 | 
 | 			free(at_str);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |         at_print(AT_ERR,"rkeydc_act_func: flashInfo.manu = %s,model = %s,size =%s\n",flashInfo.manu,flashInfo.model,flashInfo.size);
 | 
 |         snprintf((char*)at_str,64,"\r\n%s?%s?NA?%s?NA\r\n",flashInfo.manu,flashInfo.model,flashInfo.size);
 | 
 |         *res_msg = at_str;
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else if(strstr(at_paras, "LCD"))
 | 
 |     {   
 | 
 |         retCode = syscall(GET_LCD_INFO,lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
 | 
 |         if(retCode < 0)
 | 
 |         {
 | 
 |             at_print(AT_ERR,"rkeydc_act_func: syscall GET_LCD_INFO failed \n");
 | 
 | 		    free(at_str);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |         at_print(AT_ERR,"rkeydc_act_func: lcdInfo.manu = %s,ic = %s,resolution =%s\n",lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
 | 
 |         snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?%s\r\n",lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
 | 
 |         *res_msg = at_str;
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else if(strstr(at_paras, "WIFI"))
 | 
 |     {   
 | 
 |         retCode = syscall(GET_WIFI_INFO,wifiInfo.manu,wifiInfo.ic);
 | 
 |         if(retCode < 0)
 | 
 |         {
 | 
 |             at_print(AT_ERR,"rkeydc_act_func: syscall GET_WIFI_INFO failed \n");
 | 
 | 			free(at_str);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |         at_print(AT_ERR,"rkeydc_act_func: wifiInfo.manu = %s,ic = %s\n",wifiInfo.manu,wifiInfo.ic);
 | 
 |         snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?NA\r\n",wifiInfo.manu,wifiInfo.ic);
 | 
 |         *res_msg = at_str;
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else if(strstr(at_paras, "CPU"))
 | 
 |     {   
 | 
 |         retCode = syscall(GET_CPU_INFO,cpuInfo.manu,cpuInfo.model);
 | 
 |         if(retCode < 0)
 | 
 |         {
 | 
 |             at_print(AT_ERR,"rkeydc_act_func: syscall GET_CPU_INFO failed \n");
 | 
 | 			free(at_str);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |         at_print(AT_ERR,"rkeydc_act_func: cpuInfo.manu = %s,model =%s\n",cpuInfo.manu,cpuInfo.model);
 | 
 |         snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?NA\r\n",cpuInfo.manu,cpuInfo.model);
 | 
 |         *res_msg = at_str;
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 | 	else
 | 
 | 	{
 | 
 | 	    free(at_str);
 | 
 | 	}
 | 
 |     
 | 
 |     return AT_END;
 | 
 |     
 | 
 | }
 | 
 | 
 | 
 | int poweroff_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
 | 
 | {
 | 
 |     system("poweroff");
 | 
 |     // add by houweifeng for zhangwei 20200707, systemº¯Êý²¢²»ÊÇÒ»¶¨Í¬²½Ö´ÐÐ
 | 
 |     *res_msg = at_ok_build();
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: chip_platform_read_act_func
 | 
 | * ¹¦ÄÜÃèÊö: return chip platform 1:7520V3 2:7100
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int chip_platform_read_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     char TmpChipPlatform[32]    ={0};
 | 
 |     snprintf((char *)TmpChipPlatform, 32,"1");
 | 
 |     *res_msg = at_query_result_build("PLATFORM",TmpChipPlatform);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |        
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: imeiRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ¶ÁimeiºÅ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int imeiRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode =  -1;
 | 
 |     char TmpImei[DC_ImeiLen]= {0}; //imei³¤¶È×î´óÖµ
 | 
 |     int abImeiindex = 0,imeistrindex = 0;
 | 
 |     static char imeistr[2*DC_ImeiLen] = {0};
 | 
 |     char *at_str = NULL;
 | 
 |     
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, (unsigned char *)TmpImei, OS_FLASH_AMT_COMM_RO_IMEI_SIZE);
 | 
 |     at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
 | 
 |     if(CPNV_ERROR == retCode )
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;  
 | 
 |     }
 | 
 |     
 | 
 |     for (abImeiindex=0; abImeiindex<DC_ImeiLen-1; abImeiindex++,imeistrindex+=2)
 | 
 |     {
 | 
 |         imeistr[imeistrindex] = Int2Char(TmpImei[abImeiindex]&0x0F);
 | 
 |         imeistr[imeistrindex+1] = Int2Char((TmpImei[abImeiindex]&0xF0)>>4);
 | 
 |     }
 | 
 |     
 | 
 |     imeistr[2*DC_ImeiLen-2]=Int2Char(TmpImei[DC_ImeiLen-1]&0x0F);
 | 
 |     imeistr[2*DC_ImeiLen-1] = '\0';
 | 
 | 
 | 
 |     //*res_msg = at_query_result_build(NULL,imeistr);
 | 
 |     at_str = malloc(32);
 | 
 | 	if(at_str)
 | 
 | 	{
 | 
 | 	    sprintf(at_str,"\r\n%s\r\nOK\r\n",imeistr);
 | 
 | 	    *res_msg = at_str;
 | 
 | 	    *res_msglen = strlen(*res_msg);
 | 
 | 	}
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: imeiWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дimeiºÅ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int imeiWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //long retCode = -1;
 | 
 |     char *at_str = NULL; 
 | 
 |     char Imeistr[2*DC_ImeiLen]= {0};
 | 
 | 
 | 
 |     
 | 
 |     at_str = at_paras;  
 | 
 |     
 | 
 |     at_print(AT_DEBUG,"imeiWrite_act_func = %s.\n", at_str);
 | 
 | 
 | 
 |     //if ((strstr((const char *)at_str,"\r")-(char *)at_str)!= (2*DC_ImeiLen-1) || !IsImeiStrValid(at_str))
 | 
 |     if (strlen(at_paras) != (2*DC_ImeiLen-1) || !IsImeiStrValid(at_str))
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         if (-1 ==DC_Writeimei((char *)at_str))
 | 
 |         {
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |             *res_msglen = strlen(*res_msg);     
 | 
 |             return AT_END;  
 | 
 |         }
 | 
 |         
 | 
 |         memcpy(Imeistr,at_str,2*DC_ImeiLen-1);
 | 
 |         Imeistr[2*DC_ImeiLen-1] = '\0';
 | 
 |         *res_msg = at_query_result_build("MODIMEI",Imeistr);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 | 
 | 
 |     return AT_END;  
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: ssidRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: »ñÈ¡SSIDºÅ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int ssidRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char TmpSSID[ZPS_REF_MSINFO_MAX_SSID_LEN+1]={0};
 | 
 |     
 | 
 |     retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_SSID_BASE_ADDR, (unsigned char*)TmpSSID, ZPS_REF_MSINFO_MAX_SSID_LEN);
 | 
 | 	TmpSSID[ZPS_REF_MSINFO_MAX_SSID_LEN] = '\0';
 | 
 | 	if(CPNV_ERROR == retCode)
 | 
 |     {
 | 
 |          at_print(AT_ERR,"cpnv_NvItemRead ssid fail !\n");
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |          return AT_END; 
 | 
 |     }
 | 
 |     //strcpy(TmpSSID, (const char*)cfg_get("zssid"));
 | 
 | 
 | 
 |     *res_msg = at_query_result_build("SSID",TmpSSID);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: ssidWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дSSIDºÅ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: µ±SSIDºÅ¸Ä±äʱatserverÖ÷¶¯Éϱ¨¸øctrm£¬ctrm½«SSIDºÅдÈëNVÖÐ
 | 
 | **************************************************************************/
 | 
 | int ssidWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char *at_str = NULL; 
 | 
 | 
 | 
 |     at_print(AT_ERR,"at_paras=%s\n",at_paras);
 | 
 |     
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_SSID_BASE_ADDR, (unsigned char*)at_str, strlen(at_str));
 | 
 |     at_print(AT_ERR,"at_str=%s\n",at_str);
 | 
 |     at_print(AT_ERR,"retCode=%d\n",retCode);
 | 
 | 
 | 
 |     if(CPNV_ERROR == retCode)
 | 
 |     {
 | 
 |         at_print(AT_ERR,"cpnv_NvItemWrite ssid fail !\n");
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;  
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         at_print(AT_ERR,"cpnv_NvItemWrite ssid success !\n");
 | 
 |     }
 | 
 | 
 | 
 |     sc_cfg_set("zssid",at_str);    
 | 
 | 
 | 
 |     retCode = cpnv_NvramFlush();
 | 
 |     
 | 
 |     if (retCode == CPNV_OK)
 | 
 |     {
 | 
 |         *res_msg = at_query_result_build("SSID",at_str);
 | 
 |     }
 | 
 |     else
 | 
 |     {   
 | 
 |         at_print(AT_ERR,"cpnv_NvramFlush ssid fail !\n");
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |     }
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | 
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: versionTypeSet_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ÉèÖð汾ÀàÐÍ£¬AMT°æ±¾/´ó°æ±¾
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: AT+ZVERSIONTYPE=0Ϊ´ó°æ±¾£¬AT+ZVERSIONTYPE=1ΪAMT°æ±¾
 | 
 | **************************************************************************/
 | 
 | int versionTypeSet_act_func(int at_fd, char * at_paras,void **res_msg, int * res_msglen)
 | 
 | {
 | 
 |     long    retCode =  -1;
 | 
 |     char   *at_str  = NULL; 
 | 
 |     int     ntype   = -1;   
 | 
 |     
 | 
 |     at_print(AT_ERR,"at_paras=%s\n", at_paras);
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     unsigned char bootmode[] = {0x54, 0x4D};
 | 
 | 	unsigned char atmode[] = {0x41, 0x54};
 | 
 |     get_at_cmd_param_int(at_str, &ntype, (const char **)&at_str);
 | 
 |     
 | 
 |     if(!is_at_cmd_end(at_str))
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID); 
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |         return AT_END;
 | 
 |     }   
 | 
 | 
 | 
 |     if(ntype == 1)
 | 
 |     {
 | 
 |         retCode = amt_set_bootmode(bootmode);
 | 
 |     }
 | 
 |     else if(ntype == 0)
 | 
 |     {
 | 
 |         memset(bootmode, 0xFF, 2);
 | 
 |         retCode = amt_set_bootmode(bootmode);
 | 
 |     }
 | 
 | 	else if(ntype == 2)
 | 
 | 	{
 | 
 | 		retCode = amt_set_amt_atmode(bootmode,atmode);
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID); 
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |         return AT_END;
 | 
 |     }
 | 
 |     if (retCode == 0)
 | 
 |     {
 | 
 |         if (ntype == 0)
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("versionType","0");
 | 
 |         }
 | 
 |         else if(ntype == 1)
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("versionType","1");
 | 
 |         }
 | 
 | 		else if(ntype == 2)
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("versionType","2");
 | 
 |         }
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED); 
 | 
 |     }  
 | 
 |     
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: macRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
 | 
 | **************************************************************************/
 | 
 | int macRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char TmpMacAddr[Comm_DEV_MSINFO_MAX_WIFIMAC_Area_Len] = {0};//imei³¤¶È×î´óÖµ
 | 
 |     char str[13];
 | 
 |     unsigned long abMacindex = 0;
 | 
 |     static char macstr[2 * AT_CMD_MAX - 1] = {0};
 | 
 | 
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_WIFIMAC_ADDRESS, (unsigned char *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE);
 | 
 |     at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
 | 
 |     if(CPNV_ERROR == retCode )
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;  
 | 
 |     }
 | 
 |     
 | 
 |     /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii  */
 | 
 |     memset(str, 0, 13);
 | 
 | 
 | 
 |     for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
 | 
 |     {
 | 
 |         str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
 | 
 |         str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
 | 
 | 
 | 
 |         macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
 | 
 |         macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
 | 
 |     }
 | 
 | 
 | 
 |     *res_msg = at_query_result_build("MAC",macstr);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | 
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: macWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int macWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //long retCode = CPNV_ERROR;
 | 
 |     char *at_str = NULL; 
 | 
 | 
 | 
 |     //zOss_ASSERT(at_paras!=NULL);
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     if (strlen(at_str) != DC_MacLen)
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         if (-1 == DC_WriteMacAddr((char *)at_str))
 | 
 |         {                
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             //*res_msg = at_query_result_build("MAC",at_str);
 | 
 |             *res_msg = at_ok_build();
 | 
 |         }
 | 
 |     }   
 | 
 |     
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: wifikeyRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: »ñÈ¡WifiKeyµÄÖµ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int wifikeyRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char TmpWifiKey[ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN+1]={0};
 | 
 |     
 | 
 |     retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_NEWWIFIKEY_BASE_ADDR, (unsigned char *)TmpWifiKey, ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN);
 | 
 | 	TmpWifiKey[ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN] = '\0';
 | 
 | 	//zOss_ASSERT(retCode!=ZOSS_ERROR); 
 | 
 |     if(CPNV_ERROR == retCode)
 | 
 |     {
 | 
 |          at_print(AT_ERR,"cpnv_NvItemRead wifikey fail !\n");
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |          return AT_END; 
 | 
 |     }
 | 
 |     //strcpy(TmpWifiKey, (const char*)cfg_get("zwifikey"));
 | 
 | 
 | 
 |     *res_msg = at_query_result_build("WIFIKEY",TmpWifiKey);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: wifikeyWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дWIFI KEYµÄÖµ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int wifikeyWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     char *at_str = NULL;
 | 
 |     //char *pStrValue = NULL;
 | 
 |     unsigned long retCode = CPNV_ERROR;
 | 
 | 
 | 
 |     //zOss_ASSERT(at_paras!=NULL);
 | 
 |     at_str = at_paras;  
 | 
 |     if(strlen(at_str)> ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN)
 | 
 |     {       
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);       
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_NEWWIFIKEY_BASE_ADDR, (unsigned char *)at_str, strlen(at_str));
 | 
 |     //sc_cfg_set("zwifikey",at_str);
 | 
 |     
 | 
 |     if (retCode == CPNV_OK)
 | 
 |     {
 | 
 |         retCode = cpnv_NvramFlush();
 | 
 | 
 | 
 |         if (retCode == CPNV_OK)
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("WIFIKEY",at_str);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         }
 | 
 |        
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |     }
 | 
 | 
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: rj45MacAddrRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
 | 
 | **************************************************************************/
 | 
 | int rj45MacAddrRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned long   retCode = CPNV_ERROR;
 | 
 |     char            TmpMacAddr[OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE] = {0};
 | 
 |     char            str[13];
 | 
 |     long            abMacindex = 0;
 | 
 |     static char     macstr[2 * OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE - 1] = {0};
 | 
 |     
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_ETHMAC_ADDRESS, (unsigned char *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE);
 | 
 |     at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
 | 
 |     if(CPNV_ERROR == retCode )
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg); 
 | 
 |         return AT_END;  
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii  */
 | 
 |     memset(str, 0, 13);
 | 
 | 
 | 
 |     for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
 | 
 |     {
 | 
 |         str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
 | 
 |         str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
 | 
 | 
 | 
 |         macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
 | 
 |         macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»½áÊø*/
 | 
 |     *res_msg = at_query_result_build("ETHMAC",macstr);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: rj45MacAddWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
 | 
 | **************************************************************************/
 | 
 | int rj45MacAddWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //long retCode = CPNV_ERROR;
 | 
 |     char *at_str = NULL; 
 | 
 | 
 | 
 |     //zOss_ASSERT(at_paras!=NULL);
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     if (strlen(at_str)!= DC_MacLen)
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         if (-1 == DC_WriteRJ45MacAddr((char *)at_str))
 | 
 |         {                
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("ETHMAC",at_str);
 | 
 |         }
 | 
 |     }   
 | 
 |     
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: mac2Read_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
 | 
 | **************************************************************************/
 | 
 | int mac2Read_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned long   retCode = CPNV_ERROR;
 | 
 |     char            TmpMacAddr[OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE] = {0};//imei³¤¶È×î´óÖµ
 | 
 |     char            str[13];
 | 
 |     long            abMacindex = 0;
 | 
 |     static char     macstr[2 * OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE - 1] = {0};
 | 
 | 
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_WIFIMAC2_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE);
 | 
 |     
 | 
 |     if (CPNV_ERROR == retCode )
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii  */
 | 
 |     memset(str, 0, 13);
 | 
 | 
 | 
 |     for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
 | 
 |     {
 | 
 |         str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
 | 
 |         str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
 | 
 | 
 | 
 |         macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
 | 
 |         macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»½áÊø*/
 | 
 |     *res_msg = at_query_result_build("MAC2",macstr);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: mac2Write_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int mac2Write_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //long     retCode = CPNV_ERROR;
 | 
 |     char     *at_str = NULL; 
 | 
 | 
 | 
 |     //zOss_ASSERT(at_paras!=NULL);
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     if (strlen(at_str)!= DC_MacLen)
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         if (-1 == DC_WriteMac2Addr((char *)at_str))
 | 
 |         {                
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("MAC2",at_str);
 | 
 |         }
 | 
 |     }   
 | 
 |     
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: usbmacRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ¶ÁUSB MACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
 | 
 | **************************************************************************/
 | 
 | int usbmacRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned long   retCode = CPNV_ERROR;
 | 
 |     char            TmpMacAddr[OS_FLASH_AMT_COMM_RO_USBMAC_SIZE] = {0};//imei³¤¶È×î´óÖµ
 | 
 |     char            str[13];
 | 
 |     long            abMacindex = 0;
 | 
 |     static char     macstr[2 * OS_FLASH_AMT_COMM_RO_USBMAC_SIZE - 1] = {0};
 | 
 | 
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_USBMAC_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_USBMAC_SIZE);
 | 
 |     
 | 
 |     if (CPNV_ERROR == retCode )
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii  */
 | 
 |     memset(str, 0, 13);
 | 
 | 
 | 
 |     for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
 | 
 |     {
 | 
 |         str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
 | 
 |         str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
 | 
 | 
 | 
 |         macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
 | 
 |         macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»½áÊø*/
 | 
 |     *res_msg = at_query_result_build("USBMAC",macstr);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: usbmacWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дUSB MACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int usbmacWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //long retCode = CPNV_ERROR;
 | 
 |     char *at_str = NULL; 
 | 
 | 
 | 
 |     //zOss_ASSERT(at_paras!=NULL);
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     if (strlen(at_str)!= DC_MacLen)
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         if (-1 == DC_WriteUSBMacAddr((char *)at_str))
 | 
 |         {                
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("USBMAC",at_str);
 | 
 |         }
 | 
 |     }   
 | 
 |     
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 | 
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: gmacRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ¶ÁGMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
 | 
 | **************************************************************************/
 | 
 | 
 | 
 | int gmacRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned long   retCode = CPNV_ERROR;
 | 
 |     char            TmpMacAddr[OS_FLASH_AMT_COMM_RO_GMAC_SIZE] = {0};//imei³¤¶È×î´óÖµ
 | 
 |     char            str[13];
 | 
 |     long            abMacindex = 0;
 | 
 |     static char     macstr[2 * OS_FLASH_AMT_COMM_RO_GMAC_SIZE - 1] = {0};
 | 
 | 
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_GMAC_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_GMAC_SIZE);
 | 
 |     
 | 
 |     if (CPNV_ERROR == retCode )
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);     
 | 
 |         return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii  */
 | 
 |     memset(str, 0, 13);
 | 
 | 
 | 
 |     for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
 | 
 |     {
 | 
 |         str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
 | 
 |         str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
 | 
 | 
 | 
 |         macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
 | 
 |         macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
 | 
 |     }
 | 
 | 
 | 
 |     /* MACµØÖ·×ª»»½áÊø*/
 | 
 |     *res_msg = at_query_result_build("GMAC",macstr);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: gmacWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дGMACµØÖ·
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int gmacWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //long retCode = CPNV_ERROR;
 | 
 |     char *at_str = NULL; 
 | 
 | 
 | 
 |     //zOss_ASSERT(at_paras!=NULL);
 | 
 |     at_str = at_paras;  
 | 
 | 
 | 
 |     if (strlen(at_str)!= DC_MacLen)
 | 
 |     {
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |     }
 | 
 |     else
 | 
 |     {
 | 
 |         if (-1 == DC_WriteGmacAddr((char *)at_str))
 | 
 |         {                
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("GMAC",at_str);
 | 
 |         }
 | 
 |     }   
 | 
 |     
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 |     return AT_END;
 | 
 |    
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: batdetRead_act_func
 | 
 | * ¹¦ÄÜÃèÊö: »ñÈ¡BATDETµÄÖµ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int batdetRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode        = CPNV_ERROR;
 | 
 |     char TmpBatdet[32]  = {0};
 | 
 |     int  nv_value       =  0;
 | 
 |         
 | 
 |     retCode = cpnv_NvItemRead(DRV_PERI_NV_ADDR, (unsigned char *)&nv_value, 1);
 | 
 |     
 | 
 |     at_print(AT_DEBUG, "batdetRead_act_func:nv_value = %d\n", nv_value);
 | 
 |     
 | 
 |     snprintf((char *)TmpBatdet, 32, "%d", nv_value);
 | 
 | 	if(retCode != CPNV_ERROR)
 | 
 | 	{
 | 
 |     	*res_msg = at_query_result_build("BATDET", TmpBatdet);
 | 
 |     	*res_msglen = strlen(*res_msg);
 | 
 | 	}
 | 
 | 	else
 | 
 | 	{
 | 
 | 		*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 | 	}
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: batdetWrite_act_func
 | 
 | * ¹¦ÄÜÃèÊö: дBATDETµÄÖµ
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷:
 | 
 | **************************************************************************/
 | 
 | int batdetWrite_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
 | 
 | {
 | 
 | 	char          *at_str         = NULL;
 | 
 |     //char          *pStrValue      = NULL;
 | 
 |     //char           TmpBatdet[32]  = {0};
 | 
 |     unsigned long  retCode        = CPNV_ERROR;
 | 
 |     int            nv_value       = -1;
 | 
 |         
 | 
 |     at_str = at_paras;  
 | 
 |     at_print(AT_DEBUG, "batdetWrite_act_func:at_str = %s\n", at_str);
 | 
 |              
 | 
 |     get_at_cmd_param_int(at_str, &nv_value, (const char **)&at_str);
 | 
 |          
 | 
 |     at_print(AT_DEBUG,"batdetWrite_act_func:at_str = %s\n", at_str);
 | 
 |     at_print(AT_DEBUG,"batdetWrite_act_func:nv_value = %d\n", nv_value);
 | 
 |          
 | 
 |     if(!(0 == nv_value || 1 == nv_value)) // szLanEnableÖ»ÓÐ0ºÍ1Á½¸öÖµ
 | 
 |     {
 | 
 |     	*res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |         return AT_END;
 | 
 |     }
 | 
 |     
 | 
 |     retCode =amt_set_batdet_flag(nv_value);   
 | 
 |     
 | 
 |     if (retCode == CPNV_OK)
 | 
 |     {
 | 
 |     	if(nv_value == 1)
 | 
 |         {
 | 
 |         	*res_msg = at_query_result_build("BATDET","1");
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             *res_msg = at_query_result_build("BATDET","0");
 | 
 |         }
 | 
 | 	}
 | 
 |     else
 | 
 |     {
 | 
 |     	*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |     }
 | 
 |                 
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | int msnRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char TmpMSN[MSN_MAX_NVINFO_LEN+1]= {0};
 | 
 |      
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_MSerialNum_ADDRESS, (UINT8 *)TmpMSN, MSN_MAX_NVINFO_LEN);
 | 
 | 	TmpMSN[MSN_MAX_NVINFO_LEN] = '\0';
 | 
 |     if(retCode != CPNV_ERROR)
 | 
 |     {
 | 
 |         *res_msg = at_query_result_build("MSN",TmpMSN);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else
 | 
 |     {   
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | int msnWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char *at_str = NULL; 
 | 
 | 
 | 
 |     if(NULL !=at_paras)
 | 
 |     {
 | 
 |         at_str = at_paras; 
 | 
 |         at_print(AT_DEBUG,"msnWrite_act_func = %s.\n", at_str);
 | 
 |         if((strlen(at_str) >= 12) && (strlen(at_str) <= 20))
 | 
 |         {
 | 
 |             retCode = amt_nvro_write(OS_FLASH_AMT_COMM_RO_MSerialNum_ADDRESS, MSN_MAX_NVINFO_LEN, (unsigned char *)at_str);
 | 
 |             if(retCode != CPNV_ERROR)
 | 
 |             {
 | 
 |                 *res_msg = at_ok_build();
 | 
 |                 *res_msglen = strlen(*res_msg);
 | 
 |                 return AT_END;
 | 
 |             }
 | 
 |         }
 | 
 |     }
 | 
 |     *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 |     
 | 
 | }
 | 
 | 
 | 
 | int testInfoRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     unsigned int retCode = CPNV_ERROR;
 | 
 |     char TmpTestInfo[MSINFO_MAX_NVINFO_LEN+1] = {0};
 | 
 |      
 | 
 |     retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_TestInfo_ADDRESS, (UINT8 *)TmpTestInfo, MSINFO_MAX_NVINFO_LEN);
 | 
 | 	TmpTestInfo[MSINFO_MAX_NVINFO_LEN] = '\0';
 | 
 |     if(retCode != CPNV_ERROR)
 | 
 |     {
 | 
 |         *res_msg = at_query_result_build("RTESTINFO",TmpTestInfo);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else
 | 
 |     {   
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | int closeAutoInd_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     if('1' == at_paras[0])
 | 
 |     {
 | 
 |         at_context_chn_info_mod("none");
 | 
 |         *res_msg = at_ok_build();
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     else
 | 
 |     {   
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |     }
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | int zphone_mode_query_req_act(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
 | 
 | {
 | 
 |     UINT32  retCode = CPNV_ERROR;
 | 
 |     UINT8   TmpPhoneMode = 0;
 | 
 |     char *pPtr = NULL;
 | 
 | 
 | 
 |     pPtr = malloc(256);
 | 
 |     if(pPtr == NULL)
 | 
 | 	{
 | 
 | 		softap_assert("");
 | 
 | 		return AT_END;
 | 
 | 	}
 | 
 |     memset(pPtr, 0x00, 256);
 | 
 |     
 | 
 |     retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR, &TmpPhoneMode, sizeof(UINT8));
 | 
 |     if(retCode == CPNV_ERROR){softap_assert("");}
 | 
 | 
 | 
 |     if( 1 == (TmpPhoneMode & 0x1)) //×îºóһλÊÇ1  ´¿modem°æ±¾
 | 
 |     {
 | 
 |         snprintf((char *)pPtr, 64,"\r\n+PHONEMODE: %d", 0);
 | 
 |     }
 | 
 |     else if (0 == (TmpPhoneMode & 0x1)) //×îºóһλÊÇ 0 Õý³£°æ±¾
 | 
 |     {
 | 
 |         snprintf((char *)pPtr, 64,"\r\n+PHONEMODE: %d", 1);  
 | 
 |     }
 | 
 | 
 | 
 |     strcat((char *)pPtr,"\r\n\r\nOK\r\n");
 | 
 |     
 | 
 | 
 | 
 |     *res_msg = pPtr;
 | 
 |     *res_msglen = strlen(pPtr);
 | 
 |     
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | int zphone_mode_set_req_act(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
 | 
 | {
 | 
 |     UINT8 phoneModeStatus = 0;
 | 
 |     UINT32 retCode = CPNV_ERROR;
 | 
 | 
 | 
 |     retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
 | 
 | 	if(retCode == CPNV_ERROR)
 | 
 | 	{
 | 
 | 	    softap_assert("");
 | 
 | 	}
 | 
 | 
 | 
 |     //Õý³£°æ±¾
 | 
 |     if('1' == at_paras[0])
 | 
 |     {
 | 
 |         phoneModeStatus = (0xfe & phoneModeStatus);    // ºóһλ0±íʾÕý³£°æ±¾
 | 
 |         sc_cfg_set("version_mode","0");
 | 
 |     }
 | 
 |     //´¿modem°æ±¾
 | 
 |     else if('0' == at_paras[0])
 | 
 |     {
 | 
 |         phoneModeStatus = (0x1 | phoneModeStatus);   // ºóһλ1±íʾÊÇ´¿modem°æ±¾
 | 
 |         sc_cfg_set("version_mode","1");                 //version_mode==1 phonemode==0 Ϊ´¿modem°æ±¾
 | 
 |     }
 | 
 |     else
 | 
 |     {       
 | 
 |         *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 |         return AT_END;
 | 
 |     }
 | 
 |     retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
 | 
 |     if(retCode == CPNV_ERROR){softap_assert("");}
 | 
 |     retCode = cpnv_NvramFlush();
 | 
 |     if(retCode == CPNV_ERROR){softap_assert("");}
 | 
 | 
 | 
 |     *res_msg = at_ok_build();   
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;    
 | 
 | }
 | 
 | 
 | 
 | /**************************************************************************
 | 
 | * º¯ÊýÃû³Æ: zsoftreset_act_func
 | 
 | * ¹¦ÄÜÃèÊö: ÉèÖÃÈí¼þÖØÆô
 | 
 | * ²ÎÊý˵Ã÷: (IN)
 | 
 | *                         (OUT)
 | 
 | * ·µ »Ø Öµ: ÎÞ
 | 
 | * ÆäËü˵Ã÷: 
 | 
 | **************************************************************************/
 | 
 | int zsoftreset_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
 | 
 | {
 | 
 |     //char *pPtr = NULL; 
 | 
 |     
 | 
 |     //zOss_SysSoftReset(SYS_RESET_TO_NORMAL);  
 | 
 |     ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL,0);
 | 
 | 
 | 
 |     *res_msg = at_query_result_build("ZSOFTRESET", "");
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     
 | 
 |     return AT_END;  
 | 
 | }
 | 
 | 
 | 
 | int ext_ramdump_func(char *at_paras, void ** res_msg)
 | 
 | {
 | 
 |     assert(0);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | int zmodeSet_act_func_check_mode(char *at_paras, void ** res_msg, int *res_msglen)
 | 
 | {
 | 
 |     int   iUsbMode = -1;
 | 
 |     char* at_str = NULL;
 | 
 |     
 | 
 |     
 | 
 |     if(at_paras==NULL)
 | 
 |         softap_assert("zmodeSet_act_func:at_paras is null");
 | 
 |     
 | 
 |     at_str = at_paras;
 | 
 |     get_at_cmd_param_int(at_str, &iUsbMode, (const char **)&at_str);
 | 
 |     at_print(AT_DEBUG,"zmodeSet_act_func:iUsbMode == %d\n", iUsbMode);
 | 
 |     
 | 
 | 	char strCfgGetItem[AT_CMD_MAX] = {0};
 | 
 | 	nv_get_item(NV_RO, "usb_modetype", strCfgGetItem, sizeof(strCfgGetItem));
 | 
 |     at_print(AT_ERR,"current usb mode type = %s\n", strCfgGetItem); 
 | 
 | 
 | 
 |     //´ÓÓû§Ä£Ê½Çе½ÆäËû·ÇÓû§Ä£Ê½¶¼ÐèÒª¼øÈ¨
 | 
 | /*	if((strcmp(strCfgGetItem,"user")== 0)&&(iUsbMode != 0))
 | 
 | 	{
 | 
 | 	 	if(auth_device_key_result != 1 && auth_device_key_init_value() != 1)
 | 
 | 	    {
 | 
 | 	    	at_print(AT_ERR,"auth_device_key_result=%d,device key verify fail!\n", auth_device_key_result);
 | 
 | 	        *res_msg = at_err_build(ATERR_NOT_ALLOWED);
 | 
 |             *res_msglen = strlen(*res_msg);
 | 
 | 
 | 
 | 			iUsbMode = -1;
 | 
 | 	    }
 | 
 | 	}*/
 | 
 | 
 | 
 | 	return iUsbMode;
 | 
 | }
 | 
 | 
 | 
 | 
 | 
 | int zmodeSet_act_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
 | 
 | {
 | 
 |     int   iUsbMode = 0;
 | 
 |     UINT8 bootmode[] = {0x54,0x4D};
 | 
 |     long  retCode = -1;
 | 
 | 
 | 
 |     at_print(AT_DEBUG,"ext_amt_func.c:zmodeSet_act_func\n");
 | 
 | 
 | 
 | 	iUsbMode = zmodeSet_act_func_check_mode(at_paras, res_msg, res_msglen);
 | 
 | 	if(iUsbMode < 0)
 | 
 | 	{
 | 
 | 		return AT_END;
 | 
 | 	}
 | 
 | 
 | 
 |     switch(iUsbMode)
 | 
 |     {
 | 
 |         case 0: //user mode
 | 
 |         {   
 | 
 |             nv_set_item(NV_RO, "usb_modetype", "user", 1);
 | 
 |             bootmode[1] =0x00;
 | 
 |             retCode = amt_set_bootmode(bootmode);
 | 
 |             break;
 | 
 |         }
 | 
 |         case 1://debug mode
 | 
 |         {
 | 
 |             nv_set_item(NV_RO, "usb_modetype", "debug", 1);
 | 
 |             bootmode[1] =0x01;
 | 
 |             retCode = amt_set_bootmode(bootmode);
 | 
 |             break;
 | 
 |         }
 | 
 |         case 2://factory mode
 | 
 |         {
 | 
 |             nv_set_item(NV_RO, "usb_modetype", "factory", 1);
 | 
 |             bootmode[1] =0x02;
 | 
 |             retCode = amt_set_bootmode(bootmode);
 | 
 |             break;
 | 
 |         }
 | 
 |         case 3://amt mode
 | 
 |         {
 | 
 |             //nv_set_item(NV_RO, "usb_modetype", "amt", 1);
 | 
 |             retCode = amt_set_bootmode(bootmode);
 | 
 |             break;
 | 
 |         }
 | 
 |         default:
 | 
 |         {
 | 
 |             *res_msg = at_err_build(ATERR_PARAM_INVALID);
 | 
 |             *res_msglen = strlen(*res_msg);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |     }
 | 
 | 
 | 
 |     nv_commit(NV_RO);
 | 
 |     
 | 
 |     at_print(AT_DEBUG,"zmodeSet_act_func:retCode == %d\n", retCode);
 | 
 |     if (retCode == 0)
 | 
 |     {
 | 
 |         *res_msg = at_ok_build();   
 | 
 |     }
 | 
 |     else
 | 
 |     {       
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED); 
 | 
 |     }  
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | 
 | 
 | int write_security_info(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
 | 
 | {
 | 
 |     UINT32 pubKeyHash[4] = {0};
 | 
 |     UINT32 secureFlag = 0xFF;
 | 
 |     T_ZDrvEfuse_Secure efuseInfo = {{0}};
 | 
 |     char strValue[16];
 | 
 |     char strLog[256] = {0};
 | 
 |     md5_ctx stStc;
 | 
 |     int i;
 | 
 | 	int efuse_fd = -1;
 | 
 | 	//int ret = -1;
 | 
 | 
 | 
 |     /*************************»ñÈ¡¹«Ô¿hash**************************/
 | 
 |     // »ñÈ¡¹«Ô¿
 | 
 | 	efuse_fd = open("/dev/efuse", O_RDWR);
 | 
 | 	if (efuse_fd < 0) {
 | 
 | 		at_print(AT_ERR,"open %s fail.\n","/dev/efuse");
 | 
 | 		*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 | 		*res_msglen = strlen(*res_msg);
 | 
 | 		return AT_END;
 | 
 | 	}
 | 
 | 
 | 
 | 	if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
 | 
 | 	{
 | 
 | 	    at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
 | 
 | 		*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 | 		*res_msglen = strlen(*res_msg);
 | 
 | 		close(efuse_fd);
 | 
 | 		return AT_END;
 | 
 | 	}
 | 
 | 	at_print(AT_NORMAL, "security flag in efuse: %08X\r", efuseInfo.secureFlag);
 | 
 | 	
 | 
 |     // ¼ÆË㹫ԿhashÖµ
 | 
 |     md5_init(&stStc);
 | 
 |     md5_update(&stStc, (unsigned char *)efuseInfo.pubKeyRsaE, sizeof(efuseInfo.pubKeyRsaE));
 | 
 |     md5_update(&stStc, (unsigned char *)efuseInfo.pubKeyRsaN, sizeof(efuseInfo.pubKeyRsaN));
 | 
 |     md5_final((UINT8 *)pubKeyHash, &stStc);
 | 
 | 
 | 
 |     // ´òÓ¡¹«Ô¿hash
 | 
 |     strLog[0] = '\0';
 | 
 |     for (i = 0; i < sizeof(pubKeyHash)/sizeof(UINT32); i++)
 | 
 |     {
 | 
 |         pubKeyHash[i] = ((pubKeyHash[i] & 0xff000000) >> 24)
 | 
 |                         | ((pubKeyHash[i] & 0x00ff0000) >>	8)
 | 
 |                         | ((pubKeyHash[i] & 0x0000ff00) <<	8)
 | 
 |                         | ((pubKeyHash[i] & 0x000000ff) << 24) ;
 | 
 | 
 | 
 |         sprintf(strValue, "%08lX", pubKeyHash[i]);
 | 
 |         strcat(strLog, strValue);
 | 
 |     }
 | 
 | 
 | 
 |     at_print(AT_NORMAL, "Public key hash: %s\r", strLog);
 | 
 | 	
 | 
 | 	/*************************½«°²È«ÐÅϢдÈëefuse**************************/
 | 
 | 	
 | 
 | 	if (memcmp(efuseInfo.pubKeyHash, pubKeyHash, sizeof(pubKeyHash)) != 0)
 | 
 | 	{
 | 
 | 		// ¹«Ô¿hashֵдÈëefuse
 | 
 | 		if (ioctl(efuse_fd , EFUSE_SET_PUB_KEY_HASH, pubKeyHash) != 0)
 | 
 | 		{
 | 
 | 	    	at_print(AT_ERR, "Write public key hash to efuse fail!\r");
 | 
 | 			*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 | 			*res_msglen = strlen(*res_msg);
 | 
 | 			close(efuse_fd);
 | 
 | 			return AT_END;
 | 
 | 		}
 | 
 | 		else
 | 
 | 		{
 | 
 | 			at_print(AT_NORMAL, "Write public key hash to efuse success!\r");
 | 
 | 		}
 | 
 |     }
 | 
 | 	else
 | 
 | 	{
 | 
 | 		at_print(AT_NORMAL, "Public key's hash value already exists!\r");
 | 
 | 	}
 | 
 | 	/*efuseInfo.secureFlagÇ°Ãæ3¸ö×Ö½ÚÊÇchip flag,×îºóÒ»¸ö×Ö½ÚÊǰ²È«Ê¹ÄܱêÖ¾*/
 | 
 | 	
 | 
 |     if ((efuseInfo.secureFlag&0xff) != secureFlag)
 | 
 |     {
 | 
 |         // ʹÄܱêʶλдÈëefuse
 | 
 |         if (ioctl(efuse_fd , EFUSE_SET_SECURE_EN, &secureFlag) != 0)
 | 
 |         {
 | 
 |             at_print(AT_ERR, "Write security flag to efuse fail!\r");
 | 
 |             *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |             *res_msglen = strlen(*res_msg);
 | 
 | 			close(efuse_fd);
 | 
 |             return AT_END;
 | 
 |         }
 | 
 |         else
 | 
 |         {
 | 
 |             at_print(AT_NORMAL, "Write security flag to efuse success!\r");
 | 
 |         }
 | 
 |     }
 | 
 | 
 | 
 |     else
 | 
 |     {
 | 
 |         at_print(AT_NORMAL, "Secure flag already exists!\r");
 | 
 |     }
 | 
 | 	
 | 
 |     /*************************ÅжÏдÈëµÄÐÅÏ¢ÊÇ·ñÕýÈ·**************************/
 | 
 |     // ´Óefuse¶ÁÈ¡
 | 
 |     memset(&efuseInfo, 0, sizeof(efuseInfo));
 | 
 |     if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
 | 
 |     {
 | 
 |         at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
 | 
 | 		*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 | 		*res_msglen = strlen(*res_msg);
 | 
 | 		close(efuse_fd);
 | 
 | 		return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     if ((efuseInfo.secureFlag&0xff) != secureFlag)
 | 
 |     {
 | 
 |         at_print(AT_ERR, "Security flag(%#08X) is not consistent!\r", efuseInfo.secureFlag);
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 | 		close(efuse_fd);
 | 
 |         return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     if (memcmp(efuseInfo.pubKeyHash, pubKeyHash, sizeof(pubKeyHash)) != 0)
 | 
 |     {
 | 
 |         at_print(AT_ERR, "Public key hash is not consistent!\r");
 | 
 |         *res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 |         *res_msglen = strlen(*res_msg);
 | 
 | 		close(efuse_fd);
 | 
 |         return AT_END;
 | 
 |     }
 | 
 | 
 | 
 |     *res_msg = at_query_result_build("write security infomation", NULL);
 | 
 |     *res_msglen = strlen(*res_msg);
 | 
 | 	close(efuse_fd);
 | 
 |     return AT_END;
 | 
 | }
 | 
 | /*
 | 
 | int auth_device_key(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
 | 
 | {
 | 
 | 	char *at_str = NULL; 
 | 
 | 	
 | 
 | 	at_print(AT_ERR,"at_paras=%s\n",at_paras);
 | 
 | 		
 | 
 | 	at_str = at_paras;	
 | 
 | 	char seed[] = SEED;
 | 
 | 	auth_device_key_result = verify_device_key(at_str,strlen(at_str),seed,strlen(seed));
 | 
 | 	at_print(AT_ERR,"auth_device_key_result=%d\n",auth_device_key_result);
 | 
 | 	
 | 
 | 	if (auth_device_key_result == 1)
 | 
 | 	{
 | 
 | 		*res_msg = at_ok_build();
 | 
 | 	}
 | 
 | 	else
 | 
 | 	{	
 | 
 | 		at_print(AT_ERR,"verify device key fail !\n");
 | 
 | 		*res_msg = at_err_build(ATERR_PROC_FAILED);
 | 
 | 	}
 | 
 | 	*res_msglen = strlen(*res_msg);
 | 
 | 	
 | 
 | 	return AT_END;
 | 
 | }
 | 
 | */
 | 
 | 
 | 
 | int ext_amt_regist(void)
 | 
 | {
 | 
 | 	if(!ext_is_usermode())
 | 
 | 	{
 | 
 | 		register_serv_func2("MODIMEI=",0,0,0,imeiWrite_act_func,NULL);
 | 
 | 		register_serv_func2("PHONEMODE=",0,0,0,zphone_mode_set_req_act, 0);
 | 
 | 		register_serv_func("ramdump",0,ext_ramdump_func);
 | 
 | 		// дÈ밲ȫÐÅÏ¢
 | 
 | 		register_serv_func2("WSCYINFO",0,0,0,write_security_info,NULL);
 | 
 | 	}
 | 
 |     register_serv_func2("RKEYDC=",0,0,0,rkeydc_act_func,NULL);
 | 
 |     register_serv_func2("ZPOWEROFF",0,0,0,poweroff_act_func,NULL);
 | 
 |     register_serv_func2("PLATFORM?",0,0,0,chip_platform_read_act_func,NULL);
 | 
 |     register_serv_func2("READIMEI",0,0,0,imeiRead_act_func,NULL);
 | 
 |     register_serv_func2("READIMEI?",0,0,0,imeiRead_act_func,NULL);
 | 
 |     register_serv_func2("SSID?",0,0,0,ssidRead_act_func,NULL);
 | 
 |     register_serv_func2("SSID=",0,0,0,ssidWrite_act_func,NULL);
 | 
 |     register_serv_func2("ZVERSIONTYPE=",0,0,0,versionTypeSet_act_func,NULL);
 | 
 |     register_serv_func2("MAC?",0,0,0,macRead_act_func,NULL);
 | 
 |     register_serv_func2("MAC=",0,0,0,macWrite_act_func,NULL);
 | 
 |     register_serv_func2("WIFIKEY?",0,0,0,wifikeyRead_act_func,NULL);
 | 
 |     register_serv_func2("WIFIKEY=",0,0,0,wifikeyWrite_act_func,NULL);
 | 
 |     register_serv_func2("ETHMAC?",0,0,0,rj45MacAddrRead_act_func,NULL);
 | 
 |     register_serv_func2("ETHMAC=",0,0,0,rj45MacAddWrite_act_func,NULL); 
 | 
 |     register_serv_func2("MAC2?",0,0,0,mac2Read_act_func,NULL);
 | 
 |     register_serv_func2("MAC2=",0,0,0,mac2Write_act_func,NULL);
 | 
 |     register_serv_func2("USBMAC?",0,0,0,usbmacRead_act_func,NULL);
 | 
 |     register_serv_func2("USBMAC=",0,0,0,usbmacWrite_act_func,NULL); 
 | 
 |     register_serv_func2("GMAC?",0,0,0,gmacRead_act_func,NULL);
 | 
 |     register_serv_func2("GMAC=",0,0,0,gmacWrite_act_func,NULL); 
 | 
 |     register_serv_func2("BATDET?",0,0,0,batdetRead_act_func,NULL); 
 | 
 |     register_serv_func2("BATDET=",0,0,0,batdetWrite_act_func,NULL); 
 | 
 |     register_serv_func2("MSN?",0,0,0,msnRead_act_func,NULL);
 | 
 |     register_serv_func2("MSN=",0,0,0,msnWrite_act_func,NULL);
 | 
 |     register_serv_func2("RTESTINFO",0,0,0,testInfoRead_act_func,NULL);
 | 
 |     register_serv_func2("ZAMTMODE=",0,0,0,closeAutoInd_act_func,NULL);
 | 
 |     
 | 
 |     //Çл»Õý³£°æ±¾ºÍ´¿modem°æ±¾
 | 
 |     register_serv_func2("PHONEMODE?",0,0,0,zphone_mode_query_req_act, 0);
 | 
 |     
 | 
 |     register_serv_func2("ZSOFTRESET",0,0,0,zsoftreset_act_func,NULL);
 | 
 |     
 | 
 |     register_serv_func2("zmode=",0,0,0,zmodeSet_act_func,NULL); 
 | 
 | 	//mdlÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨AT+ZAUTH=KEY
 | 
 | 	//register_serv_func2("ZAUTH=",0,0,0,auth_device_key,NULL);
 | 
 |     return 0;
 | 
 | }
 |