lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /**
|
| 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"
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 31 | #include "drv_msg.h"
|
| 32 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 33 | #include "at_com.h"
|
| 34 | #include <unistd.h>
|
| 35 | #include <sys/syscall.h>
|
| 36 | #include "RONvParam_AMT.h"
|
| 37 | #include "ref_nv_def.h"
|
| 38 | #include "nv_api.h"
|
| 39 | #include "amtnv.h"
|
| 40 | #include <linux/soc/zte/efuse/efuse_zx.h>
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 41 | #include <linux/soc/zte/otp/otp_zx.h>
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 42 | #include "NvParam_drv.h"
|
| 43 | #include "libkey.h"
|
| 44 |
|
| 45 | //mdlÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨½á¹û
|
| 46 | static int auth_device_key_result = 0;
|
| 47 |
|
| 48 | #define GET_LCD_INFO 378
|
| 49 | #define GET_WIFI_INFO 379
|
| 50 | #define GET_FLASH_INFO 380
|
| 51 | #define GET_CPU_INFO 381
|
| 52 | #define GET_DDR_INFO 382
|
| 53 | //CP
|
| 54 | typedef unsigned char BYTE;
|
| 55 |
|
| 56 | #define DC_MacLen (BYTE)12
|
| 57 | #define DC_ImeiLen (BYTE)8
|
| 58 | #define MSN_MAX_NVINFO_LEN 20
|
| 59 | #define MSINFO_MAX_NVINFO_LEN 200
|
| 60 | #define MDMVERSION_MAX_LEN 64
|
| 61 | #define bInside(data, up, down) (((data) <= (up) && (data) >= (down)) || \
|
| 62 | ((data) >= (up) && (data) <= (down)))
|
| 63 | typedef unsigned long u32_t;
|
| 64 |
|
| 65 | #ifndef SMEMCPY
|
| 66 | #define SMEMCPY(dst,src,len) memcpy(dst,src,len)
|
| 67 | #endif
|
| 68 |
|
| 69 | /**
|
| 70 | * @brief ZMDMVERSIONÏìÓ¦ÏûÏ¢½á¹¹Ìå
|
| 71 | * @param result ½á¹ûÂë AT_RSP_OK/AT_RSP_ERR
|
| 72 | * @param mdmVer modem°æ±¾ºÅ
|
| 73 | */
|
| 74 | typedef struct
|
| 75 | {
|
| 76 | char mdmVer[MDMVERSION_MAX_LEN];
|
| 77 | int result;
|
| 78 | }AT_MDMVERSION_RSP_INFO;
|
| 79 |
|
| 80 | //static char mdmVer[MDMVERSION_MAX_LEN] = {0};//ÓÃÓڼǼZGMR »Ø¸´½á¹û
|
| 81 |
|
| 82 | struct flash_ddr_info{
|
| 83 | char manu[32];
|
| 84 | char model[32];
|
| 85 | char size[32];
|
| 86 | char other[32];
|
| 87 | };
|
| 88 |
|
| 89 | struct lcd_info
|
| 90 | {
|
| 91 | char manu[32];
|
| 92 | char ic[32];
|
| 93 | char resolution[32];
|
| 94 | };
|
| 95 |
|
| 96 | struct wifi_info
|
| 97 | {
|
| 98 | char manu[32];
|
| 99 | char ic[32];
|
| 100 | };
|
| 101 | struct cpu_info{
|
| 102 | char manu[32];
|
| 103 | char model[32];
|
| 104 | };
|
| 105 |
|
| 106 | /* Data structure for MD5 (Message-Digest) computation */
|
| 107 | typedef struct {
|
| 108 | u32_t i[2]; /* number of _bits_ handled mod 2^64 */
|
| 109 | u32_t buf[4]; /* scratch buffer */
|
| 110 | unsigned char in[64]; /* input buffer */
|
| 111 | unsigned char digest[16]; /* actual digest after md5_final call */
|
| 112 | } md5_ctx;
|
| 113 |
|
| 114 |
|
| 115 | extern void at_context_chn_info_mod(char *at_paras);
|
| 116 |
|
| 117 | /*
|
| 118 | ***********************************************************************
|
| 119 | ** Message-digest routines: **
|
| 120 | ** To form the message digest for a message M **
|
| 121 | ** (1) Initialize a context buffer ctx using md5_init **
|
| 122 | ** (2) Call md5_update on ctx and M **
|
| 123 | ** (3) Call md5_final on ctx **
|
| 124 | ** The message digest is now in ctx->digest[0...15] **
|
| 125 | ***********************************************************************
|
| 126 | */
|
| 127 |
|
| 128 | /* forward declaration */
|
| 129 | static void transform(u32_t *buf, u32_t *in);
|
| 130 |
|
| 131 | static unsigned char PADDING[64] = {
|
| 132 | 0x80, 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 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| 138 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| 139 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
| 140 | };
|
| 141 |
|
| 142 | /* F, G, H and I are basic MD5 functions */
|
| 143 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
| 144 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
| 145 | #define H(x, y, z) ((x) ^ (y) ^ (z))
|
| 146 | #define I(x, y, z) ((y) ^ ((x) | (~z)))
|
| 147 |
|
| 148 | /* ROTATE_LEFT rotates x left n bits */
|
| 149 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
| 150 |
|
| 151 | /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
|
| 152 | /* Rotation is separate from addition to prevent recomputation */
|
| 153 | #define FF(a, b, c, d, x, s, ac) \
|
| 154 | {(a) += F ((b), (c), (d)) + (x) + (u32_t)(ac); \
|
| 155 | (a) = ROTATE_LEFT ((a), (s)); \
|
| 156 | (a) += (b); \
|
| 157 | }
|
| 158 | #define GG(a, b, c, d, x, s, ac) \
|
| 159 | {(a) += G ((b), (c), (d)) + (x) + (u32_t)(ac); \
|
| 160 | (a) = ROTATE_LEFT ((a), (s)); \
|
| 161 | (a) += (b); \
|
| 162 | }
|
| 163 | #define HH(a, b, c, d, x, s, ac) \
|
| 164 | {(a) += H ((b), (c), (d)) + (x) + (u32_t)(ac); \
|
| 165 | (a) = ROTATE_LEFT ((a), (s)); \
|
| 166 | (a) += (b); \
|
| 167 | }
|
| 168 | #define II(a, b, c, d, x, s, ac) \
|
| 169 | {(a) += I ((b), (c), (d)) + (x) + (u32_t)(ac); \
|
| 170 | (a) = ROTATE_LEFT ((a), (s)); \
|
| 171 | (a) += (b); \
|
| 172 | }
|
| 173 |
|
| 174 | #ifdef __STDC__
|
| 175 | #define UL(x) x##UL
|
| 176 | #else
|
| 177 | #ifdef WIN32
|
| 178 | #define UL(x) x##UL
|
| 179 | #else
|
| 180 | #define UL(x) x
|
| 181 | #endif
|
| 182 | #endif
|
| 183 |
|
| 184 | /* The routine md5_init initializes the message-digest context
|
| 185 | mdContext. All fields are set to zero.
|
| 186 | */
|
| 187 | void md5_init(md5_ctx *ctx)
|
| 188 | {
|
| 189 | ctx->i[0] = ctx->i[1] = (u32_t)0;
|
| 190 |
|
| 191 | /* Load magic initialization constants. */
|
| 192 | ctx->buf[0] = (u32_t)0x67452301UL;
|
| 193 | ctx->buf[1] = (u32_t)0xefcdab89UL;
|
| 194 | ctx->buf[2] = (u32_t)0x98badcfeUL;
|
| 195 | ctx->buf[3] = (u32_t)0x10325476UL;
|
| 196 | }
|
| 197 |
|
| 198 | /* The routine md5_update updates the message-digest context to
|
| 199 | account for the presence of each of the characters buf[0..inLen-1]
|
| 200 | in the message whose digest is being computed.
|
| 201 | */
|
| 202 |
|
| 203 | void md5_update(md5_ctx *ctx, unsigned char *buf, unsigned int len)
|
| 204 | {
|
| 205 | u32_t in[16];
|
| 206 | int mdi;
|
| 207 | unsigned int i, ii;
|
| 208 |
|
| 209 | #if 0
|
| 210 | ppp_trace(LOG_INFO, "MD5Update: %u:%.*H\n", len, MIN(len, 20) * 2, buf);
|
| 211 | ppp_trace(LOG_INFO, "MD5Update: %u:%s\n", len, buf);
|
| 212 | #endif
|
| 213 |
|
| 214 | /* compute number of bytes mod 64 */
|
| 215 | mdi = (int)((ctx->i[0] >> 3) & 0x3F);
|
| 216 |
|
| 217 | /* update number of bits */
|
| 218 | if ((ctx->i[0] + ((u32_t)len << 3)) < ctx->i[0]) {
|
| 219 | ctx->i[1]++;
|
| 220 | }
|
| 221 | ctx->i[0] += ((u32_t)len << 3);
|
| 222 | ctx->i[1] += ((u32_t)len >> 29);
|
| 223 |
|
| 224 | while (len--) {
|
| 225 | /* add new character to buffer, increment mdi */
|
| 226 | ctx->in[mdi++] = *buf++;
|
| 227 |
|
| 228 | /* transform if necessary */
|
| 229 | if (mdi == 0x40) {
|
| 230 | for (i = 0, ii = 0; i < 16; i++, ii += 4) {
|
| 231 | in[i] = (((u32_t)ctx->in[ii+3]) << 24) |
|
| 232 | (((u32_t)ctx->in[ii+2]) << 16) |
|
| 233 | (((u32_t)ctx->in[ii+1]) << 8) |
|
| 234 | ((u32_t)ctx->in[ii]);
|
| 235 | }
|
| 236 | transform (ctx->buf, in);
|
| 237 | mdi = 0;
|
| 238 | }
|
| 239 | }
|
| 240 | }
|
| 241 |
|
| 242 | /* The routine md5_final terminates the message-digest computation and
|
| 243 | ends with the desired message digest in ctx->digest[0...15].
|
| 244 | */
|
| 245 |
|
| 246 | void md5_final(unsigned char hash[], md5_ctx *ctx)
|
| 247 | {
|
| 248 | u32_t in[16];
|
| 249 | int mdi;
|
| 250 | unsigned int i, ii;
|
| 251 | unsigned int pad_len;
|
| 252 |
|
| 253 | /* save number of bits */
|
| 254 | in[14] = ctx->i[0];
|
| 255 | in[15] = ctx->i[1];
|
| 256 |
|
| 257 | /* compute number of bytes mod 64 */
|
| 258 | mdi = (int)((ctx->i[0] >> 3) & 0x3F);
|
| 259 |
|
| 260 | /* pad out to 56 mod 64 */
|
| 261 | pad_len = (mdi < 56) ? (56 - mdi) : (120 - mdi);
|
| 262 | md5_update (ctx, PADDING, pad_len);
|
| 263 |
|
| 264 | /* append length in bits and transform */
|
| 265 | for (i = 0, ii = 0; i < 14; i++, ii += 4) {
|
| 266 | in[i] = (((u32_t)ctx->in[ii+3]) << 24) |
|
| 267 | (((u32_t)ctx->in[ii+2]) << 16) |
|
| 268 | (((u32_t)ctx->in[ii+1]) << 8) |
|
| 269 | ((u32_t)ctx->in[ii]);
|
| 270 | }
|
| 271 | transform (ctx->buf, in);
|
| 272 |
|
| 273 | /* store buffer in digest */
|
| 274 | for (i = 0, ii = 0; i < 4; i++, ii += 4) {
|
| 275 | ctx->digest[ii] = (unsigned char)(ctx->buf[i] & 0xFF);
|
| 276 | ctx->digest[ii+1] =
|
| 277 | (unsigned char)((ctx->buf[i] >> 8) & 0xFF);
|
| 278 | ctx->digest[ii+2] =
|
| 279 | (unsigned char)((ctx->buf[i] >> 16) & 0xFF);
|
| 280 | ctx->digest[ii+3] =
|
| 281 | (unsigned char)((ctx->buf[i] >> 24) & 0xFF);
|
| 282 | }
|
| 283 | SMEMCPY(hash, ctx->digest, 16);
|
| 284 | }
|
| 285 |
|
| 286 | /* Basic MD5 step. Transforms buf based on in.
|
| 287 | */
|
| 288 | static void transform (u32_t *buf, u32_t *in)
|
| 289 | {
|
| 290 | u32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
| 291 |
|
| 292 | /* Round 1 */
|
| 293 | #define S11 7
|
| 294 | #define S12 12
|
| 295 | #define S13 17
|
| 296 | #define S14 22
|
| 297 | FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
|
| 298 | FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
|
| 299 | FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
|
| 300 | FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
|
| 301 | FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
|
| 302 | FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
|
| 303 | FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
|
| 304 | FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
|
| 305 | FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
|
| 306 | FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
|
| 307 | FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
|
| 308 | FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
|
| 309 | FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
|
| 310 | FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
|
| 311 | FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
|
| 312 | FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
|
| 313 |
|
| 314 | /* Round 2 */
|
| 315 | #define S21 5
|
| 316 | #define S22 9
|
| 317 | #define S23 14
|
| 318 | #define S24 20
|
| 319 | GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
|
| 320 | GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
|
| 321 | GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
|
| 322 | GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
|
| 323 | GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
|
| 324 | GG ( d, a, b, c, in[10], S22, UL( 38016083)); /* 22 */
|
| 325 | GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
|
| 326 | GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
|
| 327 | GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
|
| 328 | GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
|
| 329 | GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
|
| 330 | GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
|
| 331 | GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
|
| 332 | GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
|
| 333 | GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
|
| 334 | GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
|
| 335 |
|
| 336 | /* Round 3 */
|
| 337 | #define S31 4
|
| 338 | #define S32 11
|
| 339 | #define S33 16
|
| 340 | #define S34 23
|
| 341 | HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
|
| 342 | HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
|
| 343 | HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
|
| 344 | HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
|
| 345 | HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
|
| 346 | HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
|
| 347 | HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
|
| 348 | HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
|
| 349 | HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
|
| 350 | HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
|
| 351 | HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
|
| 352 | HH ( b, c, d, a, in[ 6], S34, UL( 76029189)); /* 44 */
|
| 353 | HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
|
| 354 | HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
|
| 355 | HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
|
| 356 | HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
|
| 357 |
|
| 358 | /* Round 4 */
|
| 359 | #define S41 6
|
| 360 | #define S42 10
|
| 361 | #define S43 15
|
| 362 | #define S44 21
|
| 363 | II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
|
| 364 | II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
|
| 365 | II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
|
| 366 | II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
|
| 367 | II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
|
| 368 | II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
|
| 369 | II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
|
| 370 | II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
|
| 371 | II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
|
| 372 | II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
|
| 373 | II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
|
| 374 | II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
|
| 375 | II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
|
| 376 | II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
|
| 377 | II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
|
| 378 | II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
|
| 379 |
|
| 380 | buf[0] += a;
|
| 381 | buf[1] += b;
|
| 382 | buf[2] += c;
|
| 383 | buf[3] += d;
|
| 384 | }
|
| 385 |
|
| 386 | static int is_mac_valid(char*macStr)
|
| 387 | {
|
| 388 | int Macindex = 0;
|
| 389 | for (; (macStr[Macindex] != '\0') && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE); Macindex++)
|
| 390 | {
|
| 391 | char chmac = macStr[Macindex];
|
| 392 | if (!(bInside(chmac, '0', '9') || bInside(chmac, 'a', 'f') || bInside(chmac, 'A', 'F')))
|
| 393 | {
|
| 394 | at_print(AT_DEBUG,"mac is not hex str\r");
|
| 395 | return FALSE;
|
| 396 | }
|
| 397 | }
|
| 398 | return TRUE;
|
| 399 | }
|
| 400 | static char Ascii2BCD(char iAscii)
|
| 401 | {
|
| 402 | char iBCD;
|
| 403 |
|
| 404 | if ( bInside(iAscii, '0', '9'))
|
| 405 | {
|
| 406 | iBCD = iAscii - '0';
|
| 407 |
|
| 408 | }
|
| 409 | else if (bInside(iAscii, 'a', 'f'))
|
| 410 | {
|
| 411 | iBCD = iAscii - 'a' + 0x0a;
|
| 412 |
|
| 413 | }
|
| 414 | else if (bInside(iAscii, 'A', 'F'))
|
| 415 | {
|
| 416 | iBCD = iAscii - 'A' + 0x0a;
|
| 417 | }
|
| 418 | else
|
| 419 | {
|
| 420 | return -1;
|
| 421 | }
|
| 422 |
|
| 423 | return iBCD;
|
| 424 |
|
| 425 | }
|
| 426 |
|
| 427 | static char BCD2Ascii(char iBCD)
|
| 428 | {
|
| 429 | char iAscii;
|
| 430 |
|
| 431 | if (bInside(iBCD, 0x00, 0x09))
|
| 432 | {
|
| 433 | iAscii = (unsigned char)(iBCD + '0');
|
| 434 | }
|
| 435 | else if (bInside(iBCD, 0x0a, 0x0f))
|
| 436 | {
|
| 437 | iAscii = (unsigned char)((iBCD - 0x0a) + 'A');
|
| 438 | }
|
| 439 | else
|
| 440 | {
|
| 441 | return -1;
|
| 442 | }
|
| 443 | return iAscii;
|
| 444 | }
|
| 445 |
|
| 446 | static int IsImeiStrValid(char* imeiStr)
|
| 447 | {
|
| 448 | int i = 0;
|
| 449 | for (; i < 15; ++i)
|
| 450 | {
|
| 451 | if (imeiStr[i] < '0' || imeiStr[i] > '9')
|
| 452 | {
|
| 453 | return FALSE;
|
| 454 | }
|
| 455 | }
|
| 456 | return TRUE;
|
| 457 | }
|
| 458 |
|
| 459 | static long Char2Int(char chr)
|
| 460 | {
|
| 461 | long value = 0;
|
| 462 | value = (chr - '0');
|
| 463 | return value;
|
| 464 | }
|
| 465 |
|
| 466 | static char Int2Char(long value)
|
| 467 | {
|
| 468 | char ch = '0'+value;
|
| 469 | return ch;
|
| 470 | }
|
| 471 |
|
| 472 | static unsigned long DC_Writeimei(char * imeistr)
|
| 473 | {
|
| 474 | int Imeiindex =0,checkindex=0;
|
| 475 | BYTE abImei[DC_ImeiLen]={0};
|
| 476 | BYTE Index1=0,Index2=0;
|
| 477 |
|
| 478 | for(Imeiindex=0;imeistr[Imeiindex]!='\0';Imeiindex+=2)
|
| 479 | {
|
| 480 | at_print(AT_DEBUG,"Imeiindex= %d\r\n",Imeiindex);
|
| 481 | at_print(AT_DEBUG,"imeistr[%d]= %c\r\n",Imeiindex,imeistr[Imeiindex]);
|
| 482 |
|
| 483 | Index1=Char2Int((char)imeistr[Imeiindex]);
|
| 484 | at_print(AT_DEBUG,"Index1= %d\r",Index1);
|
| 485 |
|
| 486 | if((imeistr[Imeiindex+1])!='\0')
|
| 487 | {
|
| 488 |
|
| 489 | Index2= Char2Int((char)imeistr[Imeiindex+1]);
|
| 490 | at_print(AT_DEBUG,"Index2= %d, Index2<<4 =%x , (Index2<<4)&Index1 = %x\r\n",Index2,Index2<<4,(Index2<<4)|Index1);
|
| 491 |
|
| 492 | abImei[Imeiindex/2]=(Index2<<4)|Index1;
|
| 493 | at_print(AT_DEBUG,"abImei[%d]= %x\r\n",Imeiindex/2,abImei[Imeiindex/2]);
|
| 494 | }
|
| 495 | else
|
| 496 | {
|
| 497 | abImei[Imeiindex/2]=0xF0|Index1;
|
| 498 | at_print(AT_DEBUG,"abImei[%d]= %x\r\n",Imeiindex/2,abImei[Imeiindex/2]);
|
| 499 | break;
|
| 500 | }
|
| 501 | }
|
| 502 | for(checkindex=0;checkindex<8;checkindex++)
|
| 503 | {
|
| 504 | at_print(AT_DEBUG,"abImei[%d] = %x\r\n",checkindex,abImei[checkindex]);
|
| 505 | }
|
| 506 |
|
| 507 | if(CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, sizeof(abImei), abImei))
|
| 508 | {
|
| 509 | at_print(AT_ERR,"Write amt imei failed\r\n");
|
| 510 | return -1;
|
| 511 | }
|
| 512 |
|
| 513 | return 0;
|
| 514 | }
|
| 515 |
|
| 516 |
|
| 517 | /**************************************************************************
|
| 518 | * º¯ÊýÃû³Æ: DC_WriteMacAddr
|
| 519 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
|
| 520 | * ²ÎÊý˵Ã÷: (IN)
|
| 521 | * (OUT)
|
| 522 | * ·µ »Ø Öµ: ÎÞ
|
| 523 | * ÆäËü˵Ã÷:
|
| 524 | **************************************************************************/
|
| 525 | static unsigned long DC_WriteMacAddr(char *macstr)
|
| 526 | {
|
| 527 | unsigned long Macindex = 0;
|
| 528 | unsigned char abMac[OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE] = {0};
|
| 529 | unsigned char Index1 = 0;
|
| 530 | unsigned char Index2 = 0;
|
| 531 |
|
| 532 | if(!is_mac_valid(macstr))
|
| 533 | {
|
| 534 | at_print(AT_DEBUG,"mac is not hex str\r");
|
| 535 | return -1;
|
| 536 | }
|
| 537 |
|
| 538 | /*ASCIIÂëת»»³ÉBCDÂë*/
|
| 539 | for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE); Macindex += 2)
|
| 540 | {
|
| 541 | Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
|
| 542 | Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
|
| 543 | abMac[Macindex/2]=(Index1<<4)|Index2;
|
| 544 | }
|
| 545 |
|
| 546 | if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_WIFIMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE, abMac))
|
| 547 | {
|
| 548 | at_print(AT_DEBUG,"Write amt mac failed\r");
|
| 549 | return -1;
|
| 550 | }
|
| 551 |
|
| 552 | return 0;
|
| 553 | }
|
| 554 |
|
| 555 | /**************************************************************************
|
| 556 | * º¯ÊýÃû³Æ: DC_WriteMac2Addr
|
| 557 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
|
| 558 | * ²ÎÊý˵Ã÷: (IN)
|
| 559 | * (OUT)
|
| 560 | * ·µ »Ø Öµ: ÎÞ
|
| 561 | * ÆäËü˵Ã÷:
|
| 562 | **************************************************************************/
|
| 563 | static unsigned long DC_WriteMac2Addr(char *macstr)
|
| 564 | {
|
| 565 | unsigned long Macindex = 0;
|
| 566 | unsigned char abMac[OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE] = {0};
|
| 567 | unsigned char Index1 = 0;
|
| 568 | unsigned char Index2 = 0;
|
| 569 |
|
| 570 | if(!is_mac_valid(macstr))
|
| 571 | {
|
| 572 | at_print(AT_DEBUG,"mac is not hex str\r");
|
| 573 | return -1;
|
| 574 | }
|
| 575 |
|
| 576 | /*ASCIIÂëת»»³ÉBCDÂë*/
|
| 577 | for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE); Macindex += 2)
|
| 578 | {
|
| 579 | Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
|
| 580 | Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
|
| 581 | abMac[Macindex/2]=(Index1<<4)|Index2;
|
| 582 | }
|
| 583 |
|
| 584 | if (CPNV_ERROR== amt_nvro_write(OS_FLASH_AMT_COMM_RO_WIFIMAC2_ADDRESS, OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE, abMac))
|
| 585 | {
|
| 586 | at_print(AT_DEBUG,"Write amt mac failed\r");
|
| 587 | return -1;
|
| 588 | }
|
| 589 |
|
| 590 | return 0;
|
| 591 | }
|
| 592 |
|
| 593 | /**************************************************************************
|
| 594 | * º¯ÊýÃû³Æ: DC_WriteRJ45MacAddr
|
| 595 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«MACµØÖ·Ð´Èëµ½NVÖÐ
|
| 596 | * ²ÎÊý˵Ã÷: (IN)
|
| 597 | * (OUT)
|
| 598 | * ·µ »Ø Öµ: ÎÞ
|
| 599 | * ÆäËü˵Ã÷:
|
| 600 | **************************************************************************/
|
| 601 | unsigned long DC_WriteRJ45MacAddr(char *macstr)
|
| 602 | {
|
| 603 | unsigned long Macindex = 0;
|
| 604 | unsigned char abMac[OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE] = {0};
|
| 605 | unsigned char Index1 = 0;
|
| 606 | unsigned char Index2 = 0;
|
| 607 |
|
| 608 | if(!is_mac_valid(macstr))
|
| 609 | {
|
| 610 | at_print(AT_DEBUG,"mac is not hex str\r");
|
| 611 | return -1;
|
| 612 | }
|
| 613 |
|
| 614 | /*ASCIIÂëת»»³ÉBCDÂë*/
|
| 615 | for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE); Macindex += 2)
|
| 616 | {
|
| 617 | Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
|
| 618 | Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
|
| 619 | abMac[Macindex/2]=(Index1<<4)|Index2;
|
| 620 | }
|
| 621 |
|
| 622 | if (CPNV_ERROR== amt_nvro_write(OS_FLASH_AMT_COMM_RO_ETHMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE, abMac))
|
| 623 | {
|
| 624 | at_print(AT_DEBUG,"Write amt ethmac failed\r");
|
| 625 | return -1;
|
| 626 | }
|
| 627 |
|
| 628 | return 0;
|
| 629 | }
|
| 630 |
|
| 631 |
|
| 632 | /**************************************************************************
|
| 633 | * º¯ÊýÃû³Æ: DC_WriteMacAddr
|
| 634 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«USB MACµØÖ·Ð´Èëµ½NVÖÐ
|
| 635 | * ²ÎÊý˵Ã÷: (IN)
|
| 636 | * (OUT)
|
| 637 | * ·µ »Ø Öµ: ÎÞ
|
| 638 | * ÆäËü˵Ã÷:
|
| 639 | **************************************************************************/
|
| 640 | static unsigned long DC_WriteUSBMacAddr(char *macstr)
|
| 641 | {
|
| 642 | unsigned long Macindex = 0;
|
| 643 | unsigned char abMac[OS_FLASH_AMT_COMM_RO_USBMAC_SIZE] = {0};
|
| 644 | unsigned char Index1 = 0;
|
| 645 | unsigned char Index2 = 0;
|
| 646 |
|
| 647 | if(!is_mac_valid(macstr))
|
| 648 | {
|
| 649 | at_print(AT_DEBUG,"mac is not hex str\r");
|
| 650 | return -1;
|
| 651 | }
|
| 652 |
|
| 653 | /*ASCIIÂëת»»³ÉBCDÂë*/
|
| 654 | for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_USBMAC_SIZE); Macindex += 2)
|
| 655 | {
|
| 656 | Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
|
| 657 | Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
|
| 658 | abMac[Macindex/2]=(Index1<<4)|Index2;
|
| 659 | }
|
| 660 |
|
| 661 | if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_USBMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_USBMAC_SIZE, abMac))
|
| 662 | {
|
| 663 | at_print(AT_DEBUG,"Write amt usb mac failed\r");
|
| 664 | return -1;
|
| 665 | }
|
| 666 |
|
| 667 | return 0;
|
| 668 | }
|
| 669 |
|
| 670 | /**************************************************************************
|
| 671 | * º¯ÊýÃû³Æ: DC_WriteMacAddr
|
| 672 | * ¹¦ÄÜÃèÊö: ASCIIÂëת»»³ÉBCDÂ룬²¢ ½«GMACµØÖ·Ð´Èëµ½NVÖÐ
|
| 673 | * ²ÎÊý˵Ã÷: (IN)
|
| 674 | * (OUT)
|
| 675 | * ·µ »Ø Öµ: ÎÞ
|
| 676 | * ÆäËü˵Ã÷:
|
| 677 | **************************************************************************/
|
| 678 | static unsigned long DC_WriteGmacAddr(char *macstr)
|
| 679 | {
|
| 680 | unsigned long Macindex = 0;
|
| 681 | unsigned char abMac[OS_FLASH_AMT_COMM_RO_GMAC_SIZE] = {0};
|
| 682 | unsigned char Index1 = 0;
|
| 683 | unsigned char Index2 = 0;
|
| 684 |
|
| 685 | if(!is_mac_valid(macstr))
|
| 686 | {
|
| 687 | at_print(AT_DEBUG,"mac is not hex str\r");
|
| 688 | return -1;
|
| 689 | }
|
| 690 |
|
| 691 | /*ASCIIÂëת»»³ÉBCDÂë*/
|
| 692 | for (Macindex = 0; macstr[Macindex] != '\0' && (Macindex < OS_FLASH_AMT_COMM_RO_GMAC_SIZE); Macindex += 2)
|
| 693 | {
|
| 694 | Index1 = (unsigned char)Ascii2BCD((char)macstr[Macindex]);
|
| 695 | Index2 = (unsigned char)Ascii2BCD((char)macstr[Macindex + 1]);
|
| 696 | abMac[Macindex/2]=(Index1<<4)|Index2;
|
| 697 | }
|
| 698 |
|
| 699 | if (CPNV_ERROR == amt_nvro_write(OS_FLASH_AMT_COMM_RO_GMAC_ADDRESS, OS_FLASH_AMT_COMM_RO_GMAC_SIZE, abMac))
|
| 700 | {
|
| 701 | at_print(AT_DEBUG,"Write amt Gmac failed\r");
|
| 702 | return -1;
|
| 703 | }
|
| 704 |
|
| 705 | return 0;
|
| 706 | }
|
| 707 |
|
| 708 |
|
| 709 | static int rkeydc_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
|
| 710 | {
|
| 711 | int retCode = -1;
|
| 712 | //char pStr[8] = {0};
|
| 713 | char *at_str = NULL;
|
| 714 | struct flash_ddr_info flashInfo = {{0}};
|
| 715 | struct flash_ddr_info ddrInfo = {{0}};
|
| 716 | struct cpu_info cpuInfo = {{0}};
|
| 717 | struct wifi_info wifiInfo = {{0}};
|
| 718 | struct lcd_info lcdInfo = {{0}};
|
| 719 |
|
| 720 | at_print(AT_ERR,"rkeydc_act_func: \n");
|
| 721 | at_str = malloc(64);
|
| 722 | if(at_str == NULL)
|
| 723 | return AT_END;
|
| 724 | memset(at_str,0,64);
|
| 725 | if(strstr(at_paras, "DDR"))
|
| 726 | {
|
| 727 | retCode = syscall(GET_DDR_INFO,ddrInfo.manu,ddrInfo.size,ddrInfo.model);
|
| 728 | if(retCode < 0)
|
| 729 | {
|
| 730 | at_print(AT_ERR,"rkeydc_act_func: syscall GET_DDR_INFO failed \n");
|
| 731 | free(at_str);
|
| 732 | return AT_END;
|
| 733 | }
|
| 734 | at_print(AT_ERR,"rkeydc_act_func: ddrInfo.manu = %s,size = %s,model =%s\n",ddrInfo.manu,ddrInfo.size,ddrInfo.model);
|
| 735 | snprintf((char*)at_str,64,"\r\n%s?NA?NA?%s?%s\r\n",ddrInfo.manu,ddrInfo.size,ddrInfo.model);
|
| 736 | *res_msg = at_str;
|
| 737 | *res_msglen = strlen(*res_msg);
|
| 738 | }
|
| 739 | else if(strstr(at_paras, "FLASH"))
|
| 740 | {
|
| 741 | retCode = syscall(GET_FLASH_INFO,flashInfo.manu,flashInfo.model,flashInfo.size);
|
| 742 | if(retCode < 0)
|
| 743 | {
|
| 744 | at_print(AT_ERR,"rkeydc_act_func: syscall GET_FLASH_INFO failed \n");
|
| 745 | free(at_str);
|
| 746 | return AT_END;
|
| 747 | }
|
| 748 | at_print(AT_ERR,"rkeydc_act_func: flashInfo.manu = %s,model = %s,size =%s\n",flashInfo.manu,flashInfo.model,flashInfo.size);
|
| 749 | snprintf((char*)at_str,64,"\r\n%s?%s?NA?%s?NA\r\n",flashInfo.manu,flashInfo.model,flashInfo.size);
|
| 750 | *res_msg = at_str;
|
| 751 | *res_msglen = strlen(*res_msg);
|
| 752 | }
|
| 753 | else if(strstr(at_paras, "LCD"))
|
| 754 | {
|
| 755 | retCode = syscall(GET_LCD_INFO,lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
|
| 756 | if(retCode < 0)
|
| 757 | {
|
| 758 | at_print(AT_ERR,"rkeydc_act_func: syscall GET_LCD_INFO failed \n");
|
| 759 | free(at_str);
|
| 760 | return AT_END;
|
| 761 | }
|
| 762 | at_print(AT_ERR,"rkeydc_act_func: lcdInfo.manu = %s,ic = %s,resolution =%s\n",lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
|
| 763 | snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?%s\r\n",lcdInfo.manu,lcdInfo.ic,lcdInfo.resolution);
|
| 764 | *res_msg = at_str;
|
| 765 | *res_msglen = strlen(*res_msg);
|
| 766 | }
|
| 767 | else if(strstr(at_paras, "WIFI"))
|
| 768 | {
|
| 769 | retCode = syscall(GET_WIFI_INFO,wifiInfo.manu,wifiInfo.ic);
|
| 770 | if(retCode < 0)
|
| 771 | {
|
| 772 | at_print(AT_ERR,"rkeydc_act_func: syscall GET_WIFI_INFO failed \n");
|
| 773 | free(at_str);
|
| 774 | return AT_END;
|
| 775 | }
|
| 776 | at_print(AT_ERR,"rkeydc_act_func: wifiInfo.manu = %s,ic = %s\n",wifiInfo.manu,wifiInfo.ic);
|
| 777 | snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?NA\r\n",wifiInfo.manu,wifiInfo.ic);
|
| 778 | *res_msg = at_str;
|
| 779 | *res_msglen = strlen(*res_msg);
|
| 780 | }
|
| 781 | else if(strstr(at_paras, "CPU"))
|
| 782 | {
|
| 783 | retCode = syscall(GET_CPU_INFO,cpuInfo.manu,cpuInfo.model);
|
| 784 | if(retCode < 0)
|
| 785 | {
|
| 786 | at_print(AT_ERR,"rkeydc_act_func: syscall GET_CPU_INFO failed \n");
|
| 787 | free(at_str);
|
| 788 | return AT_END;
|
| 789 | }
|
| 790 | at_print(AT_ERR,"rkeydc_act_func: cpuInfo.manu = %s,model =%s\n",cpuInfo.manu,cpuInfo.model);
|
| 791 | snprintf((char*)at_str,64,"\r\n%s?%s?NA?NA?NA\r\n",cpuInfo.manu,cpuInfo.model);
|
| 792 | *res_msg = at_str;
|
| 793 | *res_msglen = strlen(*res_msg);
|
| 794 | }
|
| 795 | else
|
| 796 | {
|
| 797 | free(at_str);
|
| 798 | }
|
| 799 |
|
| 800 | return AT_END;
|
| 801 |
|
| 802 | }
|
| 803 |
|
| 804 | int poweroff_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
|
| 805 | {
|
| 806 | system("poweroff");
|
| 807 | // add by houweifeng for zhangwei 20200707, systemº¯Êý²¢²»ÊÇÒ»¶¨Í¬²½Ö´ÐÐ
|
| 808 | *res_msg = at_ok_build();
|
| 809 | *res_msglen = strlen(*res_msg);
|
| 810 | return AT_END;
|
| 811 | }
|
| 812 |
|
| 813 | /**************************************************************************
|
| 814 | * º¯ÊýÃû³Æ: chip_platform_read_act_func
|
| 815 | * ¹¦ÄÜÃèÊö: return chip platform 1:7520V3 2:7100
|
| 816 | * ²ÎÊý˵Ã÷: (IN)
|
| 817 | * (OUT)
|
| 818 | * ·µ »Ø Öµ: ÎÞ
|
| 819 | * ÆäËü˵Ã÷:
|
| 820 | **************************************************************************/
|
| 821 | int chip_platform_read_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 822 | {
|
| 823 | char TmpChipPlatform[32] ={0};
|
| 824 | snprintf((char *)TmpChipPlatform, 32,"1");
|
| 825 | *res_msg = at_query_result_build("PLATFORM",TmpChipPlatform);
|
| 826 | *res_msglen = strlen(*res_msg);
|
| 827 |
|
| 828 | return AT_END;
|
| 829 | }
|
| 830 |
|
| 831 | /**************************************************************************
|
| 832 | * º¯ÊýÃû³Æ: imeiRead_act_func
|
| 833 | * ¹¦ÄÜÃèÊö: ¶ÁimeiºÅ
|
| 834 | * ²ÎÊý˵Ã÷: (IN)
|
| 835 | * (OUT)
|
| 836 | * ·µ »Ø Öµ: ÎÞ
|
| 837 | * ÆäËü˵Ã÷:
|
| 838 | **************************************************************************/
|
| 839 | int imeiRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 840 | {
|
| 841 | unsigned int retCode = -1;
|
| 842 | char TmpImei[DC_ImeiLen]= {0}; //imei³¤¶È×î´óÖµ
|
| 843 | int abImeiindex = 0,imeistrindex = 0;
|
| 844 | static char imeistr[2*DC_ImeiLen] = {0};
|
| 845 | char *at_str = NULL;
|
| 846 |
|
| 847 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, (unsigned char *)TmpImei, OS_FLASH_AMT_COMM_RO_IMEI_SIZE);
|
| 848 | at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
|
| 849 | if(CPNV_ERROR == retCode )
|
| 850 | {
|
| 851 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 852 | *res_msglen = strlen(*res_msg);
|
| 853 | return AT_END;
|
| 854 | }
|
| 855 |
|
| 856 | for (abImeiindex=0; abImeiindex<DC_ImeiLen-1; abImeiindex++,imeistrindex+=2)
|
| 857 | {
|
| 858 | imeistr[imeistrindex] = Int2Char(TmpImei[abImeiindex]&0x0F);
|
| 859 | imeistr[imeistrindex+1] = Int2Char((TmpImei[abImeiindex]&0xF0)>>4);
|
| 860 | }
|
| 861 |
|
| 862 | imeistr[2*DC_ImeiLen-2]=Int2Char(TmpImei[DC_ImeiLen-1]&0x0F);
|
| 863 | imeistr[2*DC_ImeiLen-1] = '\0';
|
| 864 |
|
| 865 | //*res_msg = at_query_result_build(NULL,imeistr);
|
| 866 | at_str = malloc(32);
|
| 867 | if(at_str)
|
| 868 | {
|
| 869 | sprintf(at_str,"\r\n%s\r\nOK\r\n",imeistr);
|
| 870 | *res_msg = at_str;
|
| 871 | *res_msglen = strlen(*res_msg);
|
| 872 | }
|
| 873 | return AT_END;
|
| 874 | }
|
| 875 |
|
| 876 |
|
| 877 | /**************************************************************************
|
| 878 | * º¯ÊýÃû³Æ: imeiWrite_act_func
|
| 879 | * ¹¦ÄÜÃèÊö: дimeiºÅ
|
| 880 | * ²ÎÊý˵Ã÷: (IN)
|
| 881 | * (OUT)
|
| 882 | * ·µ »Ø Öµ: ÎÞ
|
| 883 | * ÆäËü˵Ã÷:
|
| 884 | **************************************************************************/
|
| 885 | int imeiWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 886 | {
|
| 887 | //long retCode = -1;
|
| 888 | char *at_str = NULL;
|
| 889 | char Imeistr[2*DC_ImeiLen]= {0};
|
| 890 |
|
| 891 |
|
| 892 | at_str = at_paras;
|
| 893 |
|
| 894 | at_print(AT_DEBUG,"imeiWrite_act_func = %s.\n", at_str);
|
| 895 |
|
| 896 | //if ((strstr((const char *)at_str,"\r")-(char *)at_str)!= (2*DC_ImeiLen-1) || !IsImeiStrValid(at_str))
|
| 897 | if (strlen(at_paras) != (2*DC_ImeiLen-1) || !IsImeiStrValid(at_str))
|
| 898 | {
|
| 899 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 900 | *res_msglen = strlen(*res_msg);
|
| 901 | }
|
| 902 | else
|
| 903 | {
|
| 904 | if (-1 ==DC_Writeimei((char *)at_str))
|
| 905 | {
|
| 906 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 907 | *res_msglen = strlen(*res_msg);
|
| 908 | return AT_END;
|
| 909 | }
|
| 910 |
|
| 911 | memcpy(Imeistr,at_str,2*DC_ImeiLen-1);
|
| 912 | Imeistr[2*DC_ImeiLen-1] = '\0';
|
| 913 | *res_msg = at_query_result_build("MODIMEI",Imeistr);
|
| 914 | *res_msglen = strlen(*res_msg);
|
| 915 | }
|
| 916 |
|
| 917 | return AT_END;
|
| 918 | }
|
| 919 |
|
| 920 | /**************************************************************************
|
| 921 | * º¯ÊýÃû³Æ: ssidRead_act_func
|
| 922 | * ¹¦ÄÜÃèÊö: »ñÈ¡SSIDºÅ
|
| 923 | * ²ÎÊý˵Ã÷: (IN)
|
| 924 | * (OUT)
|
| 925 | * ·µ »Ø Öµ: ÎÞ
|
| 926 | * ÆäËü˵Ã÷:
|
| 927 | **************************************************************************/
|
| 928 | int ssidRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 929 | {
|
| 930 | unsigned int retCode = CPNV_ERROR;
|
| 931 | char TmpSSID[ZPS_REF_MSINFO_MAX_SSID_LEN+1]={0};
|
| 932 |
|
| 933 | retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_SSID_BASE_ADDR, (unsigned char*)TmpSSID, ZPS_REF_MSINFO_MAX_SSID_LEN);
|
| 934 | TmpSSID[ZPS_REF_MSINFO_MAX_SSID_LEN] = '\0';
|
| 935 | if(CPNV_ERROR == retCode)
|
| 936 | {
|
| 937 | at_print(AT_ERR,"cpnv_NvItemRead ssid fail !\n");
|
| 938 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 939 | *res_msglen = strlen(*res_msg);
|
| 940 | return AT_END;
|
| 941 | }
|
| 942 | //strcpy(TmpSSID, (const char*)cfg_get("zssid"));
|
| 943 |
|
| 944 | *res_msg = at_query_result_build("SSID",TmpSSID);
|
| 945 | *res_msglen = strlen(*res_msg);
|
| 946 | return AT_END;
|
| 947 | }
|
| 948 |
|
| 949 | /**************************************************************************
|
| 950 | * º¯ÊýÃû³Æ: ssidWrite_act_func
|
| 951 | * ¹¦ÄÜÃèÊö: дSSIDºÅ
|
| 952 | * ²ÎÊý˵Ã÷: (IN)
|
| 953 | * (OUT)
|
| 954 | * ·µ »Ø Öµ: ÎÞ
|
| 955 | * ÆäËü˵Ã÷: µ±SSIDºÅ¸Ä±äʱatserverÖ÷¶¯Éϱ¨¸øctrm£¬ctrm½«SSIDºÅдÈëNVÖÐ
|
| 956 | **************************************************************************/
|
| 957 | int ssidWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 958 | {
|
| 959 | unsigned int retCode = CPNV_ERROR;
|
| 960 | char *at_str = NULL;
|
| 961 |
|
| 962 | at_print(AT_ERR,"at_paras=%s\n",at_paras);
|
| 963 |
|
| 964 | at_str = at_paras;
|
| 965 |
|
| 966 | retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_SSID_BASE_ADDR, (unsigned char*)at_str, strlen(at_str));
|
| 967 | at_print(AT_ERR,"at_str=%s\n",at_str);
|
| 968 | at_print(AT_ERR,"retCode=%d\n",retCode);
|
| 969 |
|
| 970 | if(CPNV_ERROR == retCode)
|
| 971 | {
|
| 972 | at_print(AT_ERR,"cpnv_NvItemWrite ssid fail !\n");
|
| 973 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 974 | *res_msglen = strlen(*res_msg);
|
| 975 | return AT_END;
|
| 976 | }
|
| 977 | else
|
| 978 | {
|
| 979 | at_print(AT_ERR,"cpnv_NvItemWrite ssid success !\n");
|
| 980 | }
|
| 981 |
|
| 982 | sc_cfg_set("zssid",at_str);
|
| 983 |
|
| 984 | retCode = cpnv_NvramFlush();
|
| 985 |
|
| 986 | if (retCode == CPNV_OK)
|
| 987 | {
|
| 988 | *res_msg = at_query_result_build("SSID",at_str);
|
| 989 | }
|
| 990 | else
|
| 991 | {
|
| 992 | at_print(AT_ERR,"cpnv_NvramFlush ssid fail !\n");
|
| 993 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 994 | }
|
| 995 | *res_msglen = strlen(*res_msg);
|
| 996 |
|
| 997 | return AT_END;
|
| 998 |
|
| 999 | }
|
| 1000 |
|
| 1001 |
|
| 1002 | /**************************************************************************
|
| 1003 | * º¯ÊýÃû³Æ: versionTypeSet_act_func
|
| 1004 | * ¹¦ÄÜÃèÊö: ÉèÖð汾ÀàÐÍ£¬AMT°æ±¾/´ó°æ±¾
|
| 1005 | * ²ÎÊý˵Ã÷: (IN)
|
| 1006 | * (OUT)
|
| 1007 | * ·µ »Ø Öµ: ÎÞ
|
| 1008 | * ÆäËü˵Ã÷: AT+ZVERSIONTYPE=0Ϊ´ó°æ±¾£¬AT+ZVERSIONTYPE=1ΪAMT°æ±¾
|
| 1009 | **************************************************************************/
|
| 1010 | int versionTypeSet_act_func(int at_fd, char * at_paras,void **res_msg, int * res_msglen)
|
| 1011 | {
|
| 1012 | long retCode = -1;
|
| 1013 | char *at_str = NULL;
|
| 1014 | int ntype = -1;
|
| 1015 |
|
| 1016 | at_print(AT_ERR,"at_paras=%s\n", at_paras);
|
| 1017 | at_str = at_paras;
|
| 1018 |
|
| 1019 | unsigned char bootmode[] = {0x54, 0x4D};
|
| 1020 | unsigned char atmode[] = {0x41, 0x54};
|
| 1021 | get_at_cmd_param_int(at_str, &ntype, (const char **)&at_str);
|
| 1022 |
|
| 1023 | if(!is_at_cmd_end(at_str))
|
| 1024 | {
|
| 1025 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1026 | *res_msglen = strlen(*res_msg);
|
| 1027 | return AT_END;
|
| 1028 | }
|
| 1029 |
|
| 1030 | if(ntype == 1)
|
| 1031 | {
|
| 1032 | retCode = amt_set_bootmode(bootmode);
|
| 1033 | }
|
| 1034 | else if(ntype == 0)
|
| 1035 | {
|
| 1036 | memset(bootmode, 0xFF, 2);
|
| 1037 | retCode = amt_set_bootmode(bootmode);
|
| 1038 | }
|
| 1039 | else if(ntype == 2)
|
| 1040 | {
|
| 1041 | retCode = amt_set_amt_atmode(bootmode,atmode);
|
| 1042 | }
|
| 1043 | else
|
| 1044 | {
|
| 1045 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1046 | *res_msglen = strlen(*res_msg);
|
| 1047 | return AT_END;
|
| 1048 | }
|
| 1049 | if (retCode == 0)
|
| 1050 | {
|
| 1051 | if (ntype == 0)
|
| 1052 | {
|
| 1053 | *res_msg = at_query_result_build("versionType","0");
|
| 1054 | }
|
| 1055 | else if(ntype == 1)
|
| 1056 | {
|
| 1057 | *res_msg = at_query_result_build("versionType","1");
|
| 1058 | }
|
| 1059 | else if(ntype == 2)
|
| 1060 | {
|
| 1061 | *res_msg = at_query_result_build("versionType","2");
|
| 1062 | }
|
| 1063 | }
|
| 1064 | else
|
| 1065 | {
|
| 1066 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1067 | }
|
| 1068 |
|
| 1069 | *res_msglen = strlen(*res_msg);
|
| 1070 |
|
| 1071 | return AT_END;
|
| 1072 | }
|
| 1073 |
|
| 1074 | /**************************************************************************
|
| 1075 | * º¯ÊýÃû³Æ: macRead_act_func
|
| 1076 | * ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
|
| 1077 | * ²ÎÊý˵Ã÷: (IN)
|
| 1078 | * (OUT)
|
| 1079 | * ·µ »Ø Öµ: ÎÞ
|
| 1080 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
|
| 1081 | **************************************************************************/
|
| 1082 | int macRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1083 | {
|
| 1084 | unsigned int retCode = CPNV_ERROR;
|
| 1085 | char TmpMacAddr[Comm_DEV_MSINFO_MAX_WIFIMAC_Area_Len] = {0};//imei³¤¶È×î´óÖµ
|
| 1086 | char str[13];
|
| 1087 | unsigned long abMacindex = 0;
|
| 1088 | static char macstr[2 * AT_CMD_MAX - 1] = {0};
|
| 1089 |
|
| 1090 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_WIFIMAC_ADDRESS, (unsigned char *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_WIFIMAC_SIZE);
|
| 1091 | at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
|
| 1092 | if(CPNV_ERROR == retCode )
|
| 1093 | {
|
| 1094 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1095 | *res_msglen = strlen(*res_msg);
|
| 1096 | return AT_END;
|
| 1097 | }
|
| 1098 |
|
| 1099 | /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
|
| 1100 | memset(str, 0, 13);
|
| 1101 |
|
| 1102 | for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
|
| 1103 | {
|
| 1104 | str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
|
| 1105 | str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
|
| 1106 |
|
| 1107 | macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
|
| 1108 | macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
|
| 1109 | }
|
| 1110 |
|
| 1111 | *res_msg = at_query_result_build("MAC",macstr);
|
| 1112 | *res_msglen = strlen(*res_msg);
|
| 1113 |
|
| 1114 | return AT_END;
|
| 1115 |
|
| 1116 | }
|
| 1117 |
|
| 1118 | /**************************************************************************
|
| 1119 | * º¯ÊýÃû³Æ: macWrite_act_func
|
| 1120 | * ¹¦ÄÜÃèÊö: дMACµØÖ·
|
| 1121 | * ²ÎÊý˵Ã÷: (IN)
|
| 1122 | * (OUT)
|
| 1123 | * ·µ »Ø Öµ: ÎÞ
|
| 1124 | * ÆäËü˵Ã÷:
|
| 1125 | **************************************************************************/
|
| 1126 | int macWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1127 | {
|
| 1128 | //long retCode = CPNV_ERROR;
|
| 1129 | char *at_str = NULL;
|
| 1130 |
|
| 1131 | //zOss_ASSERT(at_paras!=NULL);
|
| 1132 | at_str = at_paras;
|
| 1133 |
|
| 1134 | if (strlen(at_str) != DC_MacLen)
|
| 1135 | {
|
| 1136 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1137 | }
|
| 1138 | else
|
| 1139 | {
|
| 1140 | if (-1 == DC_WriteMacAddr((char *)at_str))
|
| 1141 | {
|
| 1142 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1143 | }
|
| 1144 | else
|
| 1145 | {
|
| 1146 | //*res_msg = at_query_result_build("MAC",at_str);
|
| 1147 | *res_msg = at_ok_build();
|
| 1148 | }
|
| 1149 | }
|
| 1150 |
|
| 1151 | *res_msglen = strlen(*res_msg);
|
| 1152 |
|
| 1153 | return AT_END;
|
| 1154 | }
|
| 1155 |
|
| 1156 | /**************************************************************************
|
| 1157 | * º¯ÊýÃû³Æ: wifikeyRead_act_func
|
| 1158 | * ¹¦ÄÜÃèÊö: »ñÈ¡WifiKeyµÄÖµ
|
| 1159 | * ²ÎÊý˵Ã÷: (IN)
|
| 1160 | * (OUT)
|
| 1161 | * ·µ »Ø Öµ: ÎÞ
|
| 1162 | * ÆäËü˵Ã÷:
|
| 1163 | **************************************************************************/
|
| 1164 | int wifikeyRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1165 | {
|
| 1166 | unsigned int retCode = CPNV_ERROR;
|
| 1167 | char TmpWifiKey[ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN+1]={0};
|
| 1168 |
|
| 1169 | retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_NEWWIFIKEY_BASE_ADDR, (unsigned char *)TmpWifiKey, ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN);
|
| 1170 | TmpWifiKey[ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN] = '\0';
|
| 1171 | //zOss_ASSERT(retCode!=ZOSS_ERROR);
|
| 1172 | if(CPNV_ERROR == retCode)
|
| 1173 | {
|
| 1174 | at_print(AT_ERR,"cpnv_NvItemRead wifikey fail !\n");
|
| 1175 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1176 | *res_msglen = strlen(*res_msg);
|
| 1177 | return AT_END;
|
| 1178 | }
|
| 1179 | //strcpy(TmpWifiKey, (const char*)cfg_get("zwifikey"));
|
| 1180 |
|
| 1181 | *res_msg = at_query_result_build("WIFIKEY",TmpWifiKey);
|
| 1182 | *res_msglen = strlen(*res_msg);
|
| 1183 |
|
| 1184 | return AT_END;
|
| 1185 | }
|
| 1186 |
|
| 1187 | /**************************************************************************
|
| 1188 | * º¯ÊýÃû³Æ: wifikeyWrite_act_func
|
| 1189 | * ¹¦ÄÜÃèÊö: дWIFI KEYµÄÖµ
|
| 1190 | * ²ÎÊý˵Ã÷: (IN)
|
| 1191 | * (OUT)
|
| 1192 | * ·µ »Ø Öµ: ÎÞ
|
| 1193 | * ÆäËü˵Ã÷:
|
| 1194 | **************************************************************************/
|
| 1195 | int wifikeyWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1196 | {
|
| 1197 | char *at_str = NULL;
|
| 1198 | //char *pStrValue = NULL;
|
| 1199 | unsigned long retCode = CPNV_ERROR;
|
| 1200 |
|
| 1201 | //zOss_ASSERT(at_paras!=NULL);
|
| 1202 | at_str = at_paras;
|
| 1203 | if(strlen(at_str)> ZPS_REF_MSINFO_MAX_NEWWIFIKEY_LEN)
|
| 1204 | {
|
| 1205 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1206 | *res_msglen = strlen(*res_msg);
|
| 1207 | return AT_END;
|
| 1208 | }
|
| 1209 |
|
| 1210 | retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_NEWWIFIKEY_BASE_ADDR, (unsigned char *)at_str, strlen(at_str));
|
| 1211 | //sc_cfg_set("zwifikey",at_str);
|
| 1212 |
|
| 1213 | if (retCode == CPNV_OK)
|
| 1214 | {
|
| 1215 | retCode = cpnv_NvramFlush();
|
| 1216 |
|
| 1217 | if (retCode == CPNV_OK)
|
| 1218 | {
|
| 1219 | *res_msg = at_query_result_build("WIFIKEY",at_str);
|
| 1220 | }
|
| 1221 | else
|
| 1222 | {
|
| 1223 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1224 | }
|
| 1225 |
|
| 1226 | }
|
| 1227 | else
|
| 1228 | {
|
| 1229 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1230 | }
|
| 1231 |
|
| 1232 | *res_msglen = strlen(*res_msg);
|
| 1233 | return AT_END;
|
| 1234 | }
|
| 1235 |
|
| 1236 | /**************************************************************************
|
| 1237 | * º¯ÊýÃû³Æ: rj45MacAddrRead_act_func
|
| 1238 | * ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
|
| 1239 | * ²ÎÊý˵Ã÷: (IN)
|
| 1240 | * (OUT)
|
| 1241 | * ·µ »Ø Öµ: ÎÞ
|
| 1242 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
|
| 1243 | **************************************************************************/
|
| 1244 | int rj45MacAddrRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1245 | {
|
| 1246 | unsigned long retCode = CPNV_ERROR;
|
| 1247 | char TmpMacAddr[OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE] = {0};
|
| 1248 | char str[13];
|
| 1249 | long abMacindex = 0;
|
| 1250 | static char macstr[2 * OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE - 1] = {0};
|
| 1251 |
|
| 1252 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_ETHMAC_ADDRESS, (unsigned char *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_ETHMAC_SIZE);
|
| 1253 | at_print(AT_DEBUG,"retCode = %d\r\n",retCode );
|
| 1254 | if(CPNV_ERROR == retCode )
|
| 1255 | {
|
| 1256 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1257 | *res_msglen = strlen(*res_msg);
|
| 1258 | return AT_END;
|
| 1259 | }
|
| 1260 |
|
| 1261 | /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
|
| 1262 | memset(str, 0, 13);
|
| 1263 |
|
| 1264 | for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
|
| 1265 | {
|
| 1266 | str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
|
| 1267 | str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
|
| 1268 |
|
| 1269 | macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
|
| 1270 | macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
|
| 1271 | }
|
| 1272 |
|
| 1273 | /* MACµØÖ·×ª»»½áÊø*/
|
| 1274 | *res_msg = at_query_result_build("ETHMAC",macstr);
|
| 1275 | *res_msglen = strlen(*res_msg);
|
| 1276 |
|
| 1277 | return AT_END;
|
| 1278 | }
|
| 1279 |
|
| 1280 | /**************************************************************************
|
| 1281 | * º¯ÊýÃû³Æ: rj45MacAddWrite_act_func
|
| 1282 | * ¹¦ÄÜÃèÊö: дMACµØÖ·
|
| 1283 | * ²ÎÊý˵Ã÷: (IN)
|
| 1284 | * (OUT)
|
| 1285 | * ·µ »Ø Öµ: ÎÞ
|
| 1286 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
|
| 1287 | **************************************************************************/
|
| 1288 | int rj45MacAddWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1289 | {
|
| 1290 | //long retCode = CPNV_ERROR;
|
| 1291 | char *at_str = NULL;
|
| 1292 |
|
| 1293 | //zOss_ASSERT(at_paras!=NULL);
|
| 1294 | at_str = at_paras;
|
| 1295 |
|
| 1296 | if (strlen(at_str)!= DC_MacLen)
|
| 1297 | {
|
| 1298 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1299 | }
|
| 1300 | else
|
| 1301 | {
|
| 1302 | if (-1 == DC_WriteRJ45MacAddr((char *)at_str))
|
| 1303 | {
|
| 1304 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1305 | }
|
| 1306 | else
|
| 1307 | {
|
| 1308 | *res_msg = at_query_result_build("ETHMAC",at_str);
|
| 1309 | }
|
| 1310 | }
|
| 1311 |
|
| 1312 | *res_msglen = strlen(*res_msg);
|
| 1313 |
|
| 1314 | return AT_END;
|
| 1315 | }
|
| 1316 |
|
| 1317 | /**************************************************************************
|
| 1318 | * º¯ÊýÃû³Æ: mac2Read_act_func
|
| 1319 | * ¹¦ÄÜÃèÊö: ¶ÁMACµØÖ·
|
| 1320 | * ²ÎÊý˵Ã÷: (IN)
|
| 1321 | * (OUT)
|
| 1322 | * ·µ »Ø Öµ: ÎÞ
|
| 1323 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
|
| 1324 | **************************************************************************/
|
| 1325 | int mac2Read_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1326 | {
|
| 1327 | unsigned long retCode = CPNV_ERROR;
|
| 1328 | char TmpMacAddr[OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE] = {0};//imei³¤¶È×î´óÖµ
|
| 1329 | char str[13];
|
| 1330 | long abMacindex = 0;
|
| 1331 | static char macstr[2 * OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE - 1] = {0};
|
| 1332 |
|
| 1333 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_WIFIMAC2_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_WIFIMAC2_SIZE);
|
| 1334 |
|
| 1335 | if (CPNV_ERROR == retCode )
|
| 1336 | {
|
| 1337 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1338 | *res_msglen = strlen(*res_msg);
|
| 1339 | return AT_END;
|
| 1340 | }
|
| 1341 |
|
| 1342 | /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
|
| 1343 | memset(str, 0, 13);
|
| 1344 |
|
| 1345 | for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
|
| 1346 | {
|
| 1347 | str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
|
| 1348 | str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
|
| 1349 |
|
| 1350 | macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
|
| 1351 | macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
|
| 1352 | }
|
| 1353 |
|
| 1354 | /* MACµØÖ·×ª»»½áÊø*/
|
| 1355 | *res_msg = at_query_result_build("MAC2",macstr);
|
| 1356 | *res_msglen = strlen(*res_msg);
|
| 1357 | return AT_END;
|
| 1358 | }
|
| 1359 |
|
| 1360 | /**************************************************************************
|
| 1361 | * º¯ÊýÃû³Æ: mac2Write_act_func
|
| 1362 | * ¹¦ÄÜÃèÊö: дMACµØÖ·
|
| 1363 | * ²ÎÊý˵Ã÷: (IN)
|
| 1364 | * (OUT)
|
| 1365 | * ·µ »Ø Öµ: ÎÞ
|
| 1366 | * ÆäËü˵Ã÷:
|
| 1367 | **************************************************************************/
|
| 1368 | int mac2Write_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1369 | {
|
| 1370 | //long retCode = CPNV_ERROR;
|
| 1371 | char *at_str = NULL;
|
| 1372 |
|
| 1373 | //zOss_ASSERT(at_paras!=NULL);
|
| 1374 | at_str = at_paras;
|
| 1375 |
|
| 1376 | if (strlen(at_str)!= DC_MacLen)
|
| 1377 | {
|
| 1378 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1379 | }
|
| 1380 | else
|
| 1381 | {
|
| 1382 | if (-1 == DC_WriteMac2Addr((char *)at_str))
|
| 1383 | {
|
| 1384 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1385 | }
|
| 1386 | else
|
| 1387 | {
|
| 1388 | *res_msg = at_query_result_build("MAC2",at_str);
|
| 1389 | }
|
| 1390 | }
|
| 1391 |
|
| 1392 | *res_msglen = strlen(*res_msg);
|
| 1393 |
|
| 1394 | return AT_END;
|
| 1395 | }
|
| 1396 |
|
| 1397 | /**************************************************************************
|
| 1398 | * º¯ÊýÃû³Æ: usbmacRead_act_func
|
| 1399 | * ¹¦ÄÜÃèÊö: ¶ÁUSB MACµØÖ·
|
| 1400 | * ²ÎÊý˵Ã÷: (IN)
|
| 1401 | * (OUT)
|
| 1402 | * ·µ »Ø Öµ: ÎÞ
|
| 1403 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
|
| 1404 | **************************************************************************/
|
| 1405 | int usbmacRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1406 | {
|
| 1407 | unsigned long retCode = CPNV_ERROR;
|
| 1408 | char TmpMacAddr[OS_FLASH_AMT_COMM_RO_USBMAC_SIZE] = {0};//imei³¤¶È×î´óÖµ
|
| 1409 | char str[13];
|
| 1410 | long abMacindex = 0;
|
| 1411 | static char macstr[2 * OS_FLASH_AMT_COMM_RO_USBMAC_SIZE - 1] = {0};
|
| 1412 |
|
| 1413 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_USBMAC_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_USBMAC_SIZE);
|
| 1414 |
|
| 1415 | if (CPNV_ERROR == retCode )
|
| 1416 | {
|
| 1417 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1418 | *res_msglen = strlen(*res_msg);
|
| 1419 | return AT_END;
|
| 1420 | }
|
| 1421 |
|
| 1422 | /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
|
| 1423 | memset(str, 0, 13);
|
| 1424 |
|
| 1425 | for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
|
| 1426 | {
|
| 1427 | str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
|
| 1428 | str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
|
| 1429 |
|
| 1430 | macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
|
| 1431 | macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
|
| 1432 | }
|
| 1433 |
|
| 1434 | /* MACµØÖ·×ª»»½áÊø*/
|
| 1435 | *res_msg = at_query_result_build("USBMAC",macstr);
|
| 1436 | *res_msglen = strlen(*res_msg);
|
| 1437 | return AT_END;
|
| 1438 | }
|
| 1439 |
|
| 1440 | /**************************************************************************
|
| 1441 | * º¯ÊýÃû³Æ: usbmacWrite_act_func
|
| 1442 | * ¹¦ÄÜÃèÊö: дUSB MACµØÖ·
|
| 1443 | * ²ÎÊý˵Ã÷: (IN)
|
| 1444 | * (OUT)
|
| 1445 | * ·µ »Ø Öµ: ÎÞ
|
| 1446 | * ÆäËü˵Ã÷:
|
| 1447 | **************************************************************************/
|
| 1448 | int usbmacWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1449 | {
|
| 1450 | //long retCode = CPNV_ERROR;
|
| 1451 | char *at_str = NULL;
|
| 1452 |
|
| 1453 | //zOss_ASSERT(at_paras!=NULL);
|
| 1454 | at_str = at_paras;
|
| 1455 |
|
| 1456 | if (strlen(at_str)!= DC_MacLen)
|
| 1457 | {
|
| 1458 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1459 | }
|
| 1460 | else
|
| 1461 | {
|
| 1462 | if (-1 == DC_WriteUSBMacAddr((char *)at_str))
|
| 1463 | {
|
| 1464 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1465 | }
|
| 1466 | else
|
| 1467 | {
|
| 1468 | *res_msg = at_query_result_build("USBMAC",at_str);
|
| 1469 | }
|
| 1470 | }
|
| 1471 |
|
| 1472 | *res_msglen = strlen(*res_msg);
|
| 1473 |
|
| 1474 | return AT_END;
|
| 1475 |
|
| 1476 | }
|
| 1477 |
|
| 1478 | /**************************************************************************
|
| 1479 | * º¯ÊýÃû³Æ: gmacRead_act_func
|
| 1480 | * ¹¦ÄÜÃèÊö: ¶ÁGMACµØÖ·
|
| 1481 | * ²ÎÊý˵Ã÷: (IN)
|
| 1482 | * (OUT)
|
| 1483 | * ·µ »Ø Öµ: ÎÞ
|
| 1484 | * ÆäËü˵Ã÷: NVÖÐMACµØÖ·ÎªBCDÂ룬ÐèҪת³ÉASCIIÂë
|
| 1485 | **************************************************************************/
|
| 1486 |
|
| 1487 | int gmacRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1488 | {
|
| 1489 | unsigned long retCode = CPNV_ERROR;
|
| 1490 | char TmpMacAddr[OS_FLASH_AMT_COMM_RO_GMAC_SIZE] = {0};//imei³¤¶È×î´óÖµ
|
| 1491 | char str[13];
|
| 1492 | long abMacindex = 0;
|
| 1493 | static char macstr[2 * OS_FLASH_AMT_COMM_RO_GMAC_SIZE - 1] = {0};
|
| 1494 |
|
| 1495 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_GMAC_ADDRESS, (UINT8 *)TmpMacAddr, OS_FLASH_AMT_COMM_RO_GMAC_SIZE);
|
| 1496 |
|
| 1497 | if (CPNV_ERROR == retCode )
|
| 1498 | {
|
| 1499 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1500 | *res_msglen = strlen(*res_msg);
|
| 1501 | return AT_END;
|
| 1502 | }
|
| 1503 |
|
| 1504 | /* MACµØÖ·×ª»»BCDÂëת»»ÎªAscii */
|
| 1505 | memset(str, 0, 13);
|
| 1506 |
|
| 1507 | for (abMacindex = 0; abMacindex< 12; abMacindex += 2)
|
| 1508 | {
|
| 1509 | str[abMacindex] = ((TmpMacAddr[abMacindex/2]) >> 4) & 0x0F;
|
| 1510 | str[abMacindex+1] = TmpMacAddr[abMacindex/2] & 0x0F;
|
| 1511 |
|
| 1512 | macstr[abMacindex] = BCD2Ascii(str[abMacindex]);
|
| 1513 | macstr[abMacindex+1] = BCD2Ascii(str[abMacindex+1]);
|
| 1514 | }
|
| 1515 |
|
| 1516 | /* MACµØÖ·×ª»»½áÊø*/
|
| 1517 | *res_msg = at_query_result_build("GMAC",macstr);
|
| 1518 | *res_msglen = strlen(*res_msg);
|
| 1519 | return AT_END;
|
| 1520 | }
|
| 1521 |
|
| 1522 | /**************************************************************************
|
| 1523 | * º¯ÊýÃû³Æ: gmacWrite_act_func
|
| 1524 | * ¹¦ÄÜÃèÊö: дGMACµØÖ·
|
| 1525 | * ²ÎÊý˵Ã÷: (IN)
|
| 1526 | * (OUT)
|
| 1527 | * ·µ »Ø Öµ: ÎÞ
|
| 1528 | * ÆäËü˵Ã÷:
|
| 1529 | **************************************************************************/
|
| 1530 | int gmacWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1531 | {
|
| 1532 | //long retCode = CPNV_ERROR;
|
| 1533 | char *at_str = NULL;
|
| 1534 |
|
| 1535 | //zOss_ASSERT(at_paras!=NULL);
|
| 1536 | at_str = at_paras;
|
| 1537 |
|
| 1538 | if (strlen(at_str)!= DC_MacLen)
|
| 1539 | {
|
| 1540 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1541 | }
|
| 1542 | else
|
| 1543 | {
|
| 1544 | if (-1 == DC_WriteGmacAddr((char *)at_str))
|
| 1545 | {
|
| 1546 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1547 | }
|
| 1548 | else
|
| 1549 | {
|
| 1550 | *res_msg = at_query_result_build("GMAC",at_str);
|
| 1551 | }
|
| 1552 | }
|
| 1553 |
|
| 1554 | *res_msglen = strlen(*res_msg);
|
| 1555 |
|
| 1556 | return AT_END;
|
| 1557 |
|
| 1558 | }
|
| 1559 |
|
| 1560 | /**************************************************************************
|
| 1561 | * º¯ÊýÃû³Æ: batdetRead_act_func
|
| 1562 | * ¹¦ÄÜÃèÊö: »ñÈ¡BATDETµÄÖµ
|
| 1563 | * ²ÎÊý˵Ã÷: (IN)
|
| 1564 | * (OUT)
|
| 1565 | * ·µ »Ø Öµ: ÎÞ
|
| 1566 | * ÆäËü˵Ã÷:
|
| 1567 | **************************************************************************/
|
| 1568 | int batdetRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1569 | {
|
| 1570 | unsigned int retCode = CPNV_ERROR;
|
| 1571 | char TmpBatdet[32] = {0};
|
| 1572 | int nv_value = 0;
|
| 1573 |
|
| 1574 | retCode = cpnv_NvItemRead(DRV_PERI_NV_ADDR, (unsigned char *)&nv_value, 1);
|
| 1575 |
|
| 1576 | at_print(AT_DEBUG, "batdetRead_act_func:nv_value = %d\n", nv_value);
|
| 1577 |
|
| 1578 | snprintf((char *)TmpBatdet, 32, "%d", nv_value);
|
| 1579 | if(retCode != CPNV_ERROR)
|
| 1580 | {
|
| 1581 | *res_msg = at_query_result_build("BATDET", TmpBatdet);
|
| 1582 | *res_msglen = strlen(*res_msg);
|
| 1583 | }
|
| 1584 | else
|
| 1585 | {
|
| 1586 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1587 | *res_msglen = strlen(*res_msg);
|
| 1588 | }
|
| 1589 | return AT_END;
|
| 1590 | }
|
| 1591 |
|
| 1592 | /**************************************************************************
|
| 1593 | * º¯ÊýÃû³Æ: batdetWrite_act_func
|
| 1594 | * ¹¦ÄÜÃèÊö: дBATDETµÄÖµ
|
| 1595 | * ²ÎÊý˵Ã÷: (IN)
|
| 1596 | * (OUT)
|
| 1597 | * ·µ »Ø Öµ: ÎÞ
|
| 1598 | * ÆäËü˵Ã÷:
|
| 1599 | **************************************************************************/
|
| 1600 | int batdetWrite_act_func(int at_fd,char * at_paras,void **res_msg,int * res_msglen)
|
| 1601 | {
|
| 1602 | char *at_str = NULL;
|
| 1603 | //char *pStrValue = NULL;
|
| 1604 | //char TmpBatdet[32] = {0};
|
| 1605 | unsigned long retCode = CPNV_ERROR;
|
| 1606 | int nv_value = -1;
|
| 1607 |
|
| 1608 | at_str = at_paras;
|
| 1609 | at_print(AT_DEBUG, "batdetWrite_act_func:at_str = %s\n", at_str);
|
| 1610 |
|
| 1611 | get_at_cmd_param_int(at_str, &nv_value, (const char **)&at_str);
|
| 1612 |
|
| 1613 | at_print(AT_DEBUG,"batdetWrite_act_func:at_str = %s\n", at_str);
|
| 1614 | at_print(AT_DEBUG,"batdetWrite_act_func:nv_value = %d\n", nv_value);
|
| 1615 |
|
| 1616 | if(!(0 == nv_value || 1 == nv_value)) // szLanEnableÖ»ÓÐ0ºÍ1Á½¸öÖµ
|
| 1617 | {
|
| 1618 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1619 | *res_msglen = strlen(*res_msg);
|
| 1620 | return AT_END;
|
| 1621 | }
|
| 1622 |
|
| 1623 | retCode =amt_set_batdet_flag(nv_value);
|
| 1624 |
|
| 1625 | if (retCode == CPNV_OK)
|
| 1626 | {
|
| 1627 | if(nv_value == 1)
|
| 1628 | {
|
| 1629 | *res_msg = at_query_result_build("BATDET","1");
|
| 1630 | }
|
| 1631 | else
|
| 1632 | {
|
| 1633 | *res_msg = at_query_result_build("BATDET","0");
|
| 1634 | }
|
| 1635 | }
|
| 1636 | else
|
| 1637 | {
|
| 1638 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1639 | }
|
| 1640 |
|
| 1641 | *res_msglen = strlen(*res_msg);
|
| 1642 | return AT_END;
|
| 1643 | }
|
| 1644 |
|
| 1645 | int msnRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1646 | {
|
| 1647 | unsigned int retCode = CPNV_ERROR;
|
| 1648 | char TmpMSN[MSN_MAX_NVINFO_LEN+1]= {0};
|
| 1649 |
|
| 1650 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_MSerialNum_ADDRESS, (UINT8 *)TmpMSN, MSN_MAX_NVINFO_LEN);
|
| 1651 | TmpMSN[MSN_MAX_NVINFO_LEN] = '\0';
|
| 1652 | if(retCode != CPNV_ERROR)
|
| 1653 | {
|
| 1654 | *res_msg = at_query_result_build("MSN",TmpMSN);
|
| 1655 | *res_msglen = strlen(*res_msg);
|
| 1656 | }
|
| 1657 | else
|
| 1658 | {
|
| 1659 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1660 | *res_msglen = strlen(*res_msg);
|
| 1661 | }
|
| 1662 | return AT_END;
|
| 1663 | }
|
| 1664 |
|
| 1665 | int msnWrite_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1666 | {
|
| 1667 | unsigned int retCode = CPNV_ERROR;
|
| 1668 | char *at_str = NULL;
|
| 1669 |
|
| 1670 | if(NULL !=at_paras)
|
| 1671 | {
|
| 1672 | at_str = at_paras;
|
| 1673 | at_print(AT_DEBUG,"msnWrite_act_func = %s.\n", at_str);
|
| 1674 | if((strlen(at_str) >= 12) && (strlen(at_str) <= 20))
|
| 1675 | {
|
| 1676 | retCode = amt_nvro_write(OS_FLASH_AMT_COMM_RO_MSerialNum_ADDRESS, MSN_MAX_NVINFO_LEN, (unsigned char *)at_str);
|
| 1677 | if(retCode != CPNV_ERROR)
|
| 1678 | {
|
| 1679 | *res_msg = at_ok_build();
|
| 1680 | *res_msglen = strlen(*res_msg);
|
| 1681 | return AT_END;
|
| 1682 | }
|
| 1683 | }
|
| 1684 | }
|
| 1685 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1686 | *res_msglen = strlen(*res_msg);
|
| 1687 | return AT_END;
|
| 1688 |
|
| 1689 | }
|
| 1690 |
|
| 1691 | int testInfoRead_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1692 | {
|
| 1693 | unsigned int retCode = CPNV_ERROR;
|
| 1694 | char TmpTestInfo[MSINFO_MAX_NVINFO_LEN+1] = {0};
|
| 1695 |
|
| 1696 | retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_TestInfo_ADDRESS, (UINT8 *)TmpTestInfo, MSINFO_MAX_NVINFO_LEN);
|
| 1697 | TmpTestInfo[MSINFO_MAX_NVINFO_LEN] = '\0';
|
| 1698 | if(retCode != CPNV_ERROR)
|
| 1699 | {
|
| 1700 | *res_msg = at_query_result_build("RTESTINFO",TmpTestInfo);
|
| 1701 | *res_msglen = strlen(*res_msg);
|
| 1702 | }
|
| 1703 | else
|
| 1704 | {
|
| 1705 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1706 | *res_msglen = strlen(*res_msg);
|
| 1707 | }
|
| 1708 | return AT_END;
|
| 1709 | }
|
| 1710 |
|
| 1711 | int closeAutoInd_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1712 | {
|
| 1713 | if('1' == at_paras[0])
|
| 1714 | {
|
| 1715 | at_context_chn_info_mod("none");
|
| 1716 | *res_msg = at_ok_build();
|
| 1717 | *res_msglen = strlen(*res_msg);
|
| 1718 | }
|
| 1719 | else
|
| 1720 | {
|
| 1721 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1722 | *res_msglen = strlen(*res_msg);
|
| 1723 | }
|
| 1724 | return AT_END;
|
| 1725 | }
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 | int zphone_mode_query_req_act(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
|
| 1730 | {
|
| 1731 | UINT32 retCode = CPNV_ERROR;
|
| 1732 | UINT8 TmpPhoneMode = 0;
|
| 1733 | char *pPtr = NULL;
|
| 1734 |
|
| 1735 | pPtr = malloc(256);
|
| 1736 | if(pPtr == NULL)
|
| 1737 | {
|
| 1738 | softap_assert("");
|
| 1739 | return AT_END;
|
| 1740 | }
|
| 1741 | memset(pPtr, 0x00, 256);
|
| 1742 |
|
| 1743 | retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR, &TmpPhoneMode, sizeof(UINT8));
|
| 1744 | if(retCode == CPNV_ERROR){softap_assert("");}
|
| 1745 |
|
| 1746 | if( 1 == (TmpPhoneMode & 0x1)) //×îºóһλÊÇ1 ´¿modem°æ±¾
|
| 1747 | {
|
| 1748 | snprintf((char *)pPtr, 64,"\r\n+PHONEMODE: %d", 0);
|
| 1749 | }
|
| 1750 | else if (0 == (TmpPhoneMode & 0x1)) //×îºóһλÊÇ 0 Õý³£°æ±¾
|
| 1751 | {
|
| 1752 | snprintf((char *)pPtr, 64,"\r\n+PHONEMODE: %d", 1);
|
| 1753 | }
|
| 1754 |
|
| 1755 | strcat((char *)pPtr,"\r\n\r\nOK\r\n");
|
| 1756 |
|
| 1757 |
|
| 1758 | *res_msg = pPtr;
|
| 1759 | *res_msglen = strlen(pPtr);
|
| 1760 |
|
| 1761 | return AT_END;
|
| 1762 | }
|
| 1763 |
|
| 1764 | int zphone_mode_set_req_act(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
|
| 1765 | {
|
| 1766 | UINT8 phoneModeStatus = 0;
|
| 1767 | UINT32 retCode = CPNV_ERROR;
|
| 1768 |
|
| 1769 | retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
|
| 1770 | if(retCode == CPNV_ERROR)
|
| 1771 | {
|
| 1772 | softap_assert("");
|
| 1773 | }
|
| 1774 |
|
| 1775 | //Õý³£°æ±¾
|
| 1776 | if('1' == at_paras[0])
|
| 1777 | {
|
| 1778 | phoneModeStatus = (0xfe & phoneModeStatus); // ºóһλ0±íʾÕý³£°æ±¾
|
| 1779 | sc_cfg_set("version_mode","0");
|
| 1780 | }
|
| 1781 | //´¿modem°æ±¾
|
| 1782 | else if('0' == at_paras[0])
|
| 1783 | {
|
| 1784 | phoneModeStatus = (0x1 | phoneModeStatus); // ºóһλ1±íʾÊÇ´¿modem°æ±¾
|
| 1785 | sc_cfg_set("version_mode","1"); //version_mode==1 phonemode==0 Ϊ´¿modem°æ±¾
|
| 1786 | }
|
| 1787 | else
|
| 1788 | {
|
| 1789 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1790 | *res_msglen = strlen(*res_msg);
|
| 1791 | return AT_END;
|
| 1792 | }
|
| 1793 | retCode = cpnv_NvItemWrite(ZPS_REF_MSINFO_VERSIONMODE_BASE_ADDR,&phoneModeStatus,sizeof(UINT8));
|
| 1794 | if(retCode == CPNV_ERROR){softap_assert("");}
|
| 1795 | retCode = cpnv_NvramFlush();
|
| 1796 | if(retCode == CPNV_ERROR){softap_assert("");}
|
| 1797 |
|
| 1798 | *res_msg = at_ok_build();
|
| 1799 | *res_msglen = strlen(*res_msg);
|
| 1800 | return AT_END;
|
| 1801 | }
|
| 1802 |
|
| 1803 | /**************************************************************************
|
| 1804 | * º¯ÊýÃû³Æ: zsoftreset_act_func
|
| 1805 | * ¹¦ÄÜÃèÊö: ÉèÖÃÈí¼þÖØÆô
|
| 1806 | * ²ÎÊý˵Ã÷: (IN)
|
| 1807 | * (OUT)
|
| 1808 | * ·µ »Ø Öµ: ÎÞ
|
| 1809 | * ÆäËü˵Ã÷:
|
| 1810 | **************************************************************************/
|
| 1811 | int zsoftreset_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 1812 | {
|
| 1813 | //char *pPtr = NULL;
|
| 1814 |
|
| 1815 | //zOss_SysSoftReset(SYS_RESET_TO_NORMAL);
|
| 1816 | ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL,0);
|
| 1817 |
|
| 1818 | *res_msg = at_query_result_build("ZSOFTRESET", "");
|
| 1819 | *res_msglen = strlen(*res_msg);
|
| 1820 |
|
| 1821 | return AT_END;
|
| 1822 | }
|
| 1823 |
|
| 1824 | int ext_ramdump_func(char *at_paras, void ** res_msg)
|
| 1825 | {
|
| 1826 | assert(0);
|
| 1827 | return AT_END;
|
| 1828 | }
|
| 1829 |
|
| 1830 | int zmodeSet_act_func_check_mode(char *at_paras, void ** res_msg, int *res_msglen)
|
| 1831 | {
|
| 1832 | int iUsbMode = -1;
|
| 1833 | char* at_str = NULL;
|
| 1834 |
|
| 1835 |
|
| 1836 | if(at_paras==NULL)
|
| 1837 | softap_assert("zmodeSet_act_func:at_paras is null");
|
| 1838 |
|
| 1839 | at_str = at_paras;
|
| 1840 | get_at_cmd_param_int(at_str, &iUsbMode, (const char **)&at_str);
|
| 1841 | at_print(AT_DEBUG,"zmodeSet_act_func:iUsbMode == %d\n", iUsbMode);
|
| 1842 |
|
| 1843 | char strCfgGetItem[AT_CMD_MAX] = {0};
|
| 1844 | nv_get_item(NV_RO, "usb_modetype", strCfgGetItem, sizeof(strCfgGetItem));
|
| 1845 | at_print(AT_ERR,"current usb mode type = %s\n", strCfgGetItem);
|
| 1846 |
|
| 1847 | //´ÓÓû§Ä£Ê½Çе½ÆäËû·ÇÓû§Ä£Ê½¶¼ÐèÒª¼øÈ¨
|
| 1848 | /* if((strcmp(strCfgGetItem,"user")== 0)&&(iUsbMode != 0))
|
| 1849 | {
|
| 1850 | if(auth_device_key_result != 1 && auth_device_key_init_value() != 1)
|
| 1851 | {
|
| 1852 | at_print(AT_ERR,"auth_device_key_result=%d,device key verify fail!\n", auth_device_key_result);
|
| 1853 | *res_msg = at_err_build(ATERR_NOT_ALLOWED);
|
| 1854 | *res_msglen = strlen(*res_msg);
|
| 1855 |
|
| 1856 | iUsbMode = -1;
|
| 1857 | }
|
| 1858 | }*/
|
| 1859 |
|
| 1860 | return iUsbMode;
|
| 1861 | }
|
| 1862 |
|
| 1863 |
|
| 1864 | int zmodeSet_act_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
|
| 1865 | {
|
| 1866 | int iUsbMode = 0;
|
| 1867 | UINT8 bootmode[] = {0x54,0x4D};
|
| 1868 | long retCode = -1;
|
| 1869 |
|
| 1870 | at_print(AT_DEBUG,"ext_amt_func.c:zmodeSet_act_func\n");
|
| 1871 |
|
| 1872 | iUsbMode = zmodeSet_act_func_check_mode(at_paras, res_msg, res_msglen);
|
| 1873 | if(iUsbMode < 0)
|
| 1874 | {
|
| 1875 | return AT_END;
|
| 1876 | }
|
| 1877 |
|
| 1878 | switch(iUsbMode)
|
| 1879 | {
|
| 1880 | case 0: //user mode
|
| 1881 | {
|
| 1882 | nv_set_item(NV_RO, "usb_modetype", "user", 1);
|
| 1883 | bootmode[1] =0x00;
|
| 1884 | retCode = amt_set_bootmode(bootmode);
|
| 1885 | break;
|
| 1886 | }
|
| 1887 | case 1://debug mode
|
| 1888 | {
|
| 1889 | nv_set_item(NV_RO, "usb_modetype", "debug", 1);
|
| 1890 | bootmode[1] =0x01;
|
| 1891 | retCode = amt_set_bootmode(bootmode);
|
| 1892 | break;
|
| 1893 | }
|
| 1894 | case 2://factory mode
|
| 1895 | {
|
| 1896 | nv_set_item(NV_RO, "usb_modetype", "factory", 1);
|
| 1897 | bootmode[1] =0x02;
|
| 1898 | retCode = amt_set_bootmode(bootmode);
|
| 1899 | break;
|
| 1900 | }
|
| 1901 | case 3://amt mode
|
| 1902 | {
|
| 1903 | //nv_set_item(NV_RO, "usb_modetype", "amt", 1);
|
| 1904 | retCode = amt_set_bootmode(bootmode);
|
| 1905 | break;
|
| 1906 | }
|
| 1907 | default:
|
| 1908 | {
|
| 1909 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 1910 | *res_msglen = strlen(*res_msg);
|
| 1911 | return AT_END;
|
| 1912 | }
|
| 1913 | }
|
| 1914 |
|
| 1915 | nv_commit(NV_RO);
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 1916 | #ifdef USE_CAP_SUPPORT
|
| 1917 | if((iUsbMode>= 0) && (iUsbMode<= 3)){
|
| 1918 | iUsbMode += 3;
|
| 1919 | ipc_send_message2(MODULE_ID_HOTPLUG, MODULE_ID_USBHOTPLUG, MSG_CMD_DRV_USB_CHANGE,
|
| 1920 | sizeof(iUsbMode), &iUsbMode, 0);
|
| 1921 | }
|
| 1922 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1923 | at_print(AT_DEBUG,"zmodeSet_act_func:retCode == %d\n", retCode);
|
| 1924 | if (retCode == 0)
|
| 1925 | {
|
| 1926 | *res_msg = at_ok_build();
|
| 1927 | }
|
| 1928 | else
|
| 1929 | {
|
| 1930 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 1931 | }
|
| 1932 | *res_msglen = strlen(*res_msg);
|
| 1933 | return AT_END;
|
| 1934 | }
|
| 1935 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 1936 |
|
| 1937 | #define SHA256_ROTL(a,b) (((a>>(32-b))&(0x7fffffff>>(31-b)))|(a<<b))
|
| 1938 | #define SHA256_SR(a,b) ((a>>b)&(0x7fffffff>>(b-1)))
|
| 1939 | #define SHA256_Ch(x,y,z) ((x&y)^((~x)&z))
|
| 1940 | #define SHA256_Maj(x,y,z) ((x&y)^(x&z)^(y&z))
|
| 1941 | #define SHA256_E0(x) (SHA256_ROTL(x,30)^SHA256_ROTL(x,19)^SHA256_ROTL(x,10))
|
| 1942 | #define SHA256_E1(x) (SHA256_ROTL(x,26)^SHA256_ROTL(x,21)^SHA256_ROTL(x,7))
|
| 1943 | #define SHA256_O0(x) (SHA256_ROTL(x,25)^SHA256_ROTL(x,14)^SHA256_SR(x,3))
|
| 1944 | #define SHA256_O1(x) (SHA256_ROTL(x,15)^SHA256_ROTL(x,13)^SHA256_SR(x,10))
|
| 1945 |
|
| 1946 |
|
| 1947 | /**
|
| 1948 | * @brief ¼ÆËãSHA-256
|
| 1949 | * @param[in,out] str ÐèÒª¼ÆËãSHA-256 hashÖµµÄÂëÁ÷Ö¸Õë
|
| 1950 | * @param[in,out] length ÂëÁ÷³¤¶È
|
| 1951 | * @param[in,out] sha256 ÓÃÓÚ±£´æSHA-256µÄÖ¸Õë
|
| 1952 | * @return ³É¹¦·µ»Øsha256£¬Ê§°Ü·µ»Ø0
|
| 1953 | * @note
|
| 1954 | * @see
|
| 1955 | */
|
| 1956 |
|
| 1957 | unsigned char* StrSHA256(const unsigned char* str, long long length, unsigned char* sha256)
|
| 1958 | {
|
| 1959 | /*
|
| 1960 | ¼ÆËã×Ö·û´®SHA-256
|
| 1961 | ²ÎÊý˵Ã÷£º
|
| 1962 | str ×Ö·û´®Ö¸Õë
|
| 1963 | length ×Ö·û´®³¤¶È
|
| 1964 | sha256 ÓÃÓÚ±£´æSHA-256µÄ×Ö·û´®Ö¸Õë
|
| 1965 | ·µ»ØÖµÎª²ÎÊýsha256
|
| 1966 | */
|
| 1967 | unsigned char *pp, *ppend;
|
| 1968 | long l, i, W[64], T1, T2, A, B, C, D, E, F, G, H, H0, H1, H2, H3, H4, H5, H6, H7;
|
| 1969 | H0 = 0x6a09e667, H1 = 0xbb67ae85, H2 = 0x3c6ef372, H3 = 0xa54ff53a;
|
| 1970 | H4 = 0x510e527f, H5 = 0x9b05688c, H6 = 0x1f83d9ab, H7 = 0x5be0cd19;
|
| 1971 | long K[64] = {
|
| 1972 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
| 1973 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
| 1974 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
| 1975 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
| 1976 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
| 1977 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
| 1978 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
| 1979 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
| 1980 | };
|
| 1981 | l = length + ((length % 64 >= 56) ? (128 - length % 64) : (64 - length % 64));
|
| 1982 | if (!(pp = (unsigned char*)malloc((unsigned long)l))) return 0;
|
| 1983 | for (i = 0; i < length; pp[i + 3 - 2 * (i % 4)] = str[i], i++);
|
| 1984 | for (pp[i + 3 - 2 * (i % 4)] = 128, i++; i < l; pp[i + 3 - 2 * (i % 4)] = 0, i++);
|
| 1985 | *((long*)(pp + l - 4)) = length << 3;
|
| 1986 | *((long*)(pp + l - 8)) = length >> 29;
|
| 1987 | for (ppend = pp + l; pp < ppend; pp += 64){
|
| 1988 | for (i = 0; i < 16; W[i] = ((long*)pp)[i], i++);
|
| 1989 | for (i = 16; i < 64; W[i] = (SHA256_O1(W[i - 2]) + W[i - 7] + SHA256_O0(W[i - 15]) + W[i - 16]), i++);
|
| 1990 | A = H0, B = H1, C = H2, D = H3, E = H4, F = H5, G = H6, H = H7;
|
| 1991 | for (i = 0; i < 64; i++){
|
| 1992 | T1 = H + SHA256_E1(E) + SHA256_Ch(E, F, G) + K[i] + W[i];
|
| 1993 | T2 = SHA256_E0(A) + SHA256_Maj(A, B, C);
|
| 1994 | H = G, G = F, F = E, E = D + T1, D = C, C = B, B = A, A = T1 + T2;
|
| 1995 | }
|
| 1996 | H0 += A, H1 += B, H2 += C, H3 += D, H4 += E, H5 += F, H6 += G, H7 += H;
|
| 1997 | }
|
| 1998 | free(pp - l);
|
| 1999 | memcpy(sha256,&H0,sizeof(H0));
|
| 2000 | memcpy(sha256 + sizeof(H0),&H1,sizeof(H1));
|
| 2001 | memcpy(sha256 + sizeof(H0) + sizeof(H1),&H2,sizeof(H2));
|
| 2002 | memcpy(sha256 + sizeof(H0) + sizeof(H1) + sizeof(H2),&H3,sizeof(H3));
|
| 2003 | memcpy(sha256 + sizeof(H0) + sizeof(H1) + sizeof(H2) + sizeof(H3),&H4,sizeof(H4));
|
| 2004 | memcpy(sha256 + sizeof(H0) + sizeof(H1) + sizeof(H2) + sizeof(H3) + sizeof(H4),&H5,sizeof(H5));
|
| 2005 | memcpy(sha256 + sizeof(H0) + sizeof(H1) + sizeof(H2) + sizeof(H3) + sizeof(H4) + sizeof(H5),&H6,sizeof(H6));
|
| 2006 | memcpy(sha256 + sizeof(H0) + sizeof(H1) + sizeof(H2) + sizeof(H3) + sizeof(H4) + sizeof(H5) + sizeof(H6),&H7,sizeof(H7));
|
| 2007 | return sha256;
|
| 2008 | }
|
| 2009 |
|
| 2010 | static int IsEnhancedSecurity()
|
| 2011 | {
|
| 2012 | #define CMDLINE_MAX_SIZE (4*1024)
|
| 2013 | int cmdline_fd = -1;
|
| 2014 | char*cmdline_buf = malloc(CMDLINE_MAX_SIZE);
|
| 2015 | char*temp = NULL;
|
| 2016 | int ret_size = 0;
|
| 2017 | if(cmdline_buf == NULL)
|
| 2018 | {
|
| 2019 | at_print(AT_ERR,"malloc cmdline_buf fail.\n");
|
| 2020 | return -1;
|
| 2021 | }
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2022 | memset(cmdline_buf,0,CMDLINE_MAX_SIZE);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2023 | //²éÕÒcmdlineÖеÄEnhancedSecurityÊÇ·ñ´æÔÚ
|
| 2024 | cmdline_fd = open("/proc/cmdline", O_RDONLY);
|
| 2025 | if (cmdline_fd < 0) {
|
| 2026 | at_print(AT_ERR,"open %s fail.\n","/proc/cmdline");
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2027 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2028 | return -1;
|
| 2029 | }
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2030 | ret_size = read(cmdline_fd, cmdline_buf, CMDLINE_MAX_SIZE - 1);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2031 | if(ret_size <= 0)
|
| 2032 | {
|
| 2033 | at_print(AT_ERR,"read /proc/cmdline fail.\n");
|
| 2034 | close(cmdline_fd);
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2035 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2036 | return -1;
|
| 2037 | }
|
| 2038 | close(cmdline_fd);
|
| 2039 | temp = strstr(cmdline_buf,"EnhancedSecurity=");
|
| 2040 | if(temp == NULL)
|
| 2041 | {
|
| 2042 | at_print(AT_ERR,"can not find EnhancedSecurity=\n");
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2043 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2044 | return -1;
|
| 2045 | }
|
| 2046 | temp = temp + strlen("EnhancedSecurity=");
|
| 2047 | if(temp == NULL)
|
| 2048 | {
|
| 2049 | at_print(AT_ERR,"temp = NULL\n");
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2050 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2051 | return -1;
|
| 2052 | }
|
| 2053 | if(*temp == '0')
|
| 2054 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2055 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2056 | return 0;
|
| 2057 | }
|
| 2058 | else if(*temp == '1')
|
| 2059 | {
|
| 2060 | at_print(AT_ERR,"EnhancedSecurity=1\n");
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2061 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2062 | return 1;
|
| 2063 | }
|
| 2064 | else
|
| 2065 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2066 | free(cmdline_buf);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2067 | return -1;
|
| 2068 | }
|
| 2069 | }
|
| 2070 |
|
| 2071 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2072 | int write_security_info(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
|
| 2073 | {
|
| 2074 | UINT32 pubKeyHash[4] = {0};
|
| 2075 | UINT32 secureFlag = 0xFF;
|
| 2076 | T_ZDrvEfuse_Secure efuseInfo = {{0}};
|
| 2077 | char strValue[16];
|
| 2078 | char strLog[256] = {0};
|
| 2079 | md5_ctx stStc;
|
| 2080 | int i;
|
| 2081 | int efuse_fd = -1;
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2082 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2083 | UINT32 pubKeyHash_otp[8] = {0};
|
| 2084 | UINT32 secureFlag_otp = 0x00;
|
| 2085 | T_ZDrvOtp_Secure otpInfo = {{0}};
|
| 2086 | int otp_fd = -1;
|
| 2087 | int is_Enhanced_Security = -1;
|
| 2088 |
|
| 2089 | is_Enhanced_Security = IsEnhancedSecurity();
|
| 2090 | at_print(AT_ERR,"is_Enhanced_Security = %d.\n",is_Enhanced_Security);
|
| 2091 | if(is_Enhanced_Security == -1)
|
| 2092 | {
|
| 2093 | at_print(AT_ERR,"IsEnhancedSecurity() fail.\n");
|
| 2094 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2095 | *res_msglen = strlen(*res_msg);
|
| 2096 | return AT_END;
|
| 2097 | }
|
| 2098 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2099 | /*************************»ñÈ¡¹«Ô¿hash**************************/
|
| 2100 | // »ñÈ¡¹«Ô¿
|
| 2101 | efuse_fd = open("/dev/efuse", O_RDWR);
|
| 2102 | if (efuse_fd < 0) {
|
| 2103 | at_print(AT_ERR,"open %s fail.\n","/dev/efuse");
|
| 2104 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2105 | *res_msglen = strlen(*res_msg);
|
| 2106 | return AT_END;
|
| 2107 | }
|
| 2108 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2109 | at_print(AT_ERR,"open %s success.\n","/dev/efuse");
|
| 2110 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2111 | if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
|
| 2112 | {
|
| 2113 | at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
|
| 2114 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2115 | *res_msglen = strlen(*res_msg);
|
| 2116 | close(efuse_fd);
|
| 2117 | return AT_END;
|
| 2118 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2119 | at_print(AT_ERR, "security flag in efuse: %08X\n", efuseInfo.secureFlag);
|
| 2120 |
|
| 2121 | //ÅжÏefuseÀïÃæµÄ¹«Ô¿ÊÇ·ñºÏ·¨£¬Èç¹ûÊÇÈ«0£¬Ö±½ÓÍ˳ö
|
| 2122 | for (i = 0; i < sizeof(efuseInfo.pubKeyRsaE)/sizeof(UINT32); i++)
|
| 2123 | {
|
| 2124 | if(efuseInfo.pubKeyRsaE[i] != 0)
|
| 2125 | {
|
| 2126 | break;
|
| 2127 | }
|
| 2128 | }
|
| 2129 | if(i == sizeof(efuseInfo.pubKeyRsaE)/sizeof(UINT32))
|
| 2130 | {
|
| 2131 | at_print(AT_ERR,"efuse pubkey E is all zero.\n");
|
| 2132 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2133 | *res_msglen = strlen(*res_msg);
|
| 2134 | close(efuse_fd);
|
| 2135 | return AT_END;
|
| 2136 | }
|
| 2137 |
|
| 2138 | for (i = 0; i < sizeof(efuseInfo.pubKeyRsaN)/sizeof(UINT32); i++)
|
| 2139 | {
|
| 2140 | if(efuseInfo.pubKeyRsaN[i] != 0)
|
| 2141 | {
|
| 2142 | break;
|
| 2143 | }
|
| 2144 | }
|
| 2145 | if(i == sizeof(efuseInfo.pubKeyRsaN)/sizeof(UINT32))
|
| 2146 | {
|
| 2147 | at_print(AT_ERR,"efuse pubkey N is all zero.\n");
|
| 2148 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2149 | *res_msglen = strlen(*res_msg);
|
| 2150 | close(efuse_fd);
|
| 2151 | return AT_END;
|
| 2152 | }
|
| 2153 |
|
| 2154 |
|
| 2155 | // ´òÓ¡¹«Ô¿
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2156 | #if 0
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2157 | strLog[0] = '\0';
|
| 2158 | for (i = 0; i < 16; i++)
|
| 2159 | {
|
| 2160 | sprintf(strValue, "%08lX", efuseInfo.pubKeyRsaE[i]);
|
| 2161 | strcat(strLog, strValue);
|
| 2162 | }
|
| 2163 |
|
| 2164 | at_print(AT_ERR, "efuse Pubkey E1: %s\n", strLog);
|
| 2165 |
|
| 2166 | memset(strLog, 0, sizeof(strLog));
|
| 2167 | for (i = 16; i < 32; i++)
|
| 2168 | {
|
| 2169 | sprintf(strValue, "%08lX", efuseInfo.pubKeyRsaE[i]);
|
| 2170 | strcat(strLog, strValue);
|
| 2171 | }
|
| 2172 |
|
| 2173 | at_print(AT_ERR, "efuse Pubkey E2: %s\n", strLog);
|
| 2174 |
|
| 2175 | memset(strLog, 0, sizeof(strLog));
|
| 2176 | for (i = 0; i < 16; i++)
|
| 2177 | {
|
| 2178 | sprintf(strValue, "%08lX", efuseInfo.pubKeyRsaN[i]);
|
| 2179 | strcat(strLog, strValue);
|
| 2180 | }
|
| 2181 |
|
| 2182 | at_print(AT_ERR, "efuse Pubkey N1: %s\n", strLog);
|
| 2183 |
|
| 2184 | memset(strLog, 0, sizeof(strLog));
|
| 2185 | for (i = 16; i < 32; i++)
|
| 2186 | {
|
| 2187 | sprintf(strValue, "%08lX", efuseInfo.pubKeyRsaN[i]);
|
| 2188 | strcat(strLog, strValue);
|
| 2189 | }
|
| 2190 |
|
| 2191 | at_print(AT_ERR, "efuse Pubkey N2: %s\n", strLog);
|
| 2192 | #endif
|
| 2193 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2194 |
|
| 2195 | // ¼ÆË㹫ԿhashÖµ
|
| 2196 | md5_init(&stStc);
|
| 2197 | md5_update(&stStc, (unsigned char *)efuseInfo.pubKeyRsaE, sizeof(efuseInfo.pubKeyRsaE));
|
| 2198 | md5_update(&stStc, (unsigned char *)efuseInfo.pubKeyRsaN, sizeof(efuseInfo.pubKeyRsaN));
|
| 2199 | md5_final((UINT8 *)pubKeyHash, &stStc);
|
| 2200 |
|
| 2201 | // ´òÓ¡¹«Ô¿hash
|
| 2202 | strLog[0] = '\0';
|
| 2203 | for (i = 0; i < sizeof(pubKeyHash)/sizeof(UINT32); i++)
|
| 2204 | {
|
| 2205 | pubKeyHash[i] = ((pubKeyHash[i] & 0xff000000) >> 24)
|
| 2206 | | ((pubKeyHash[i] & 0x00ff0000) >> 8)
|
| 2207 | | ((pubKeyHash[i] & 0x0000ff00) << 8)
|
| 2208 | | ((pubKeyHash[i] & 0x000000ff) << 24) ;
|
| 2209 |
|
| 2210 | sprintf(strValue, "%08lX", pubKeyHash[i]);
|
| 2211 | strcat(strLog, strValue);
|
| 2212 | }
|
| 2213 |
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2214 | at_print(AT_ERR, "efuse Public key hash: %s\n", strLog);
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2215 |
|
| 2216 | /*************************½«°²È«ÐÅϢдÈëefuse**************************/
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2217 | if (memcmp(efuseInfo.pubKeyHash, pubKeyHash, sizeof(pubKeyHash)) != 0)
|
| 2218 | {
|
| 2219 | // ¹«Ô¿hashֵдÈëefuse
|
| 2220 | if (ioctl(efuse_fd , EFUSE_SET_PUB_KEY_HASH, pubKeyHash) != 0)
|
| 2221 | {
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2222 | at_print(AT_ERR, "Write public key hash to efuse fail!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2223 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2224 | *res_msglen = strlen(*res_msg);
|
| 2225 | close(efuse_fd);
|
| 2226 | return AT_END;
|
| 2227 | }
|
| 2228 | else
|
| 2229 | {
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2230 | at_print(AT_ERR, "Write public key hash to efuse success!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2231 | }
|
| 2232 | }
|
| 2233 | else
|
| 2234 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2235 | at_print(AT_ERR, "efuse Public key's hash value already exists!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2236 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2237 |
|
| 2238 | /*************************ÅжÏдÈëµÄ¹«Ô¿hashÖµÊÇ·ñÕýÈ·**************************/
|
| 2239 | // ´Óefuse¶ÁÈ¡
|
| 2240 | memset(&efuseInfo, 0, sizeof(efuseInfo));
|
| 2241 | if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
|
| 2242 | {
|
| 2243 | at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
|
| 2244 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2245 | *res_msglen = strlen(*res_msg);
|
| 2246 | close(efuse_fd);
|
| 2247 | return AT_END;
|
| 2248 | }
|
| 2249 | if (memcmp(efuseInfo.pubKeyHash, pubKeyHash, sizeof(pubKeyHash)) != 0)
|
| 2250 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2251 | at_print(AT_ERR, "efuse Public key hash is not consistent!\n");
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2252 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2253 | *res_msglen = strlen(*res_msg);
|
| 2254 | close(efuse_fd);
|
| 2255 | return AT_END;
|
| 2256 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2257 |
|
| 2258 | if(is_Enhanced_Security == 1)
|
| 2259 | {
|
| 2260 | /*************************»ñÈ¡¹«Ô¿hash**************************/
|
| 2261 | // »ñÈ¡¹«Ô¿
|
| 2262 | otp_fd = open("/dev/otp", O_RDWR);
|
| 2263 | if (otp_fd < 0) {
|
| 2264 | at_print(AT_ERR,"open %s fail.\n","/dev/otp");
|
| 2265 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2266 | *res_msglen = strlen(*res_msg);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2267 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2268 | return AT_END;
|
| 2269 | }
|
| 2270 | at_print(AT_ERR,"open %s success.\n","/dev/otp");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2271 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2272 | if(ioctl(otp_fd , OTP_GET_DATA, &otpInfo)!= 0)
|
| 2273 | {
|
| 2274 | at_print(AT_ERR,"ioctl: OTP_GET_DATA fail.\n");
|
| 2275 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2276 | *res_msglen = strlen(*res_msg);
|
| 2277 | close(otp_fd);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2278 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2279 | return AT_END;
|
| 2280 | }
|
| 2281 |
|
| 2282 | at_print(AT_ERR, "security flag in otp: %08X\n", otpInfo.secureFlag);
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2283 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2284 | // ´òÓ¡¹«Ô¿
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2285 | #if 0
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2286 | strLog[0] = '\0';
|
| 2287 | for (i = 0; i < 16; i++)
|
| 2288 | {
|
| 2289 | sprintf(strValue, "%08lX", otpInfo.pubKey[i]);
|
| 2290 | strcat(strLog, strValue);
|
| 2291 | }
|
| 2292 |
|
| 2293 | at_print(AT_ERR, "OTP Public key1: %s\n", strLog);
|
| 2294 |
|
| 2295 | memset(strLog, 0, sizeof(strLog));
|
| 2296 | for (i = 16; i < 32; i++)
|
| 2297 | {
|
| 2298 | sprintf(strValue, "%08lX", otpInfo.pubKey[i]);
|
| 2299 | strcat(strLog, strValue);
|
| 2300 | }
|
| 2301 |
|
| 2302 | at_print(AT_ERR, "OTP Public key2: %s\n", strLog);
|
| 2303 |
|
| 2304 | memset(strLog, 0, sizeof(strLog));
|
| 2305 | for (i = 32; i < 48; i++)
|
| 2306 | {
|
| 2307 | sprintf(strValue, "%08lX", otpInfo.pubKey[i]);
|
| 2308 | strcat(strLog, strValue);
|
| 2309 | }
|
| 2310 |
|
| 2311 | at_print(AT_ERR, "OTP Public key3: %s\n", strLog);
|
| 2312 |
|
| 2313 | memset(strLog, 0, sizeof(strLog));
|
| 2314 | for (i = 48; i < 64; i++)
|
| 2315 | {
|
| 2316 | sprintf(strValue, "%08lX", otpInfo.pubKey[i]);
|
| 2317 | strcat(strLog, strValue);
|
| 2318 | }
|
| 2319 |
|
| 2320 | at_print(AT_ERR, "OTP Public key4: %s\n", strLog);
|
| 2321 |
|
| 2322 | memset(strLog, 0, sizeof(strLog));
|
| 2323 | for (i = 64; i < 80; i++)
|
| 2324 | {
|
| 2325 | sprintf(strValue, "%08lX", otpInfo.pubKey[i]);
|
| 2326 | strcat(strLog, strValue);
|
| 2327 | }
|
| 2328 |
|
| 2329 | at_print(AT_ERR, "OTP Public key5: %s\n", strLog);
|
| 2330 |
|
| 2331 | memset(strLog, 0, sizeof(strLog));
|
| 2332 | for (i = 80; i < sizeof(otpInfo.pubKey)/sizeof(UINT32); i++)
|
| 2333 | {
|
| 2334 | sprintf(strValue, "%08lX", otpInfo.pubKey[i]);
|
| 2335 | strcat(strLog, strValue);
|
| 2336 | }
|
| 2337 |
|
| 2338 | at_print(AT_ERR, "OTP Public key6: %s\n", strLog);
|
| 2339 | #endif
|
| 2340 | //¼ÆË㹫ԿhashÖµ
|
| 2341 | StrSHA256((const unsigned char*)otpInfo.pubKey, sizeof(otpInfo.pubKey), (unsigned char*)pubKeyHash_otp);
|
| 2342 | // ´òÓ¡¹«Ô¿hash
|
| 2343 | memset(strLog, 0, sizeof(strLog));
|
| 2344 | for (i = 0; i < sizeof(pubKeyHash_otp)/sizeof(UINT32); i++)
|
| 2345 | {
|
| 2346 | sprintf(strValue, "%08lX", pubKeyHash_otp[i]);
|
| 2347 | strcat(strLog, strValue);
|
| 2348 | }
|
| 2349 |
|
| 2350 | at_print(AT_ERR, "OTP Public key hash: %s\n", strLog);
|
| 2351 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2352 | /*************************½«°²È«ÐÅϢдÈëotp**************************/
|
| 2353 |
|
| 2354 | if (memcmp(otpInfo.pubKeyHash, pubKeyHash_otp, sizeof(pubKeyHash_otp)) != 0)
|
| 2355 | {
|
| 2356 | // ¹«Ô¿hashֵдÈëotp
|
| 2357 | if (ioctl(otp_fd , OTP_SET_PUB_KEY_HASH, pubKeyHash_otp) != 0)
|
| 2358 | {
|
| 2359 | at_print(AT_ERR, "Write public key hash to otp fail!\n");
|
| 2360 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2361 | *res_msglen = strlen(*res_msg);
|
| 2362 | close(otp_fd);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2363 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2364 | return AT_END;
|
| 2365 | }
|
| 2366 | else
|
| 2367 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2368 | at_print(AT_ERR, "Write public key hash to otp success!\n");
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2369 | }
|
| 2370 | }
|
| 2371 | else
|
| 2372 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2373 | at_print(AT_ERR, "Public key's hash value in otp already exists!\n");
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2374 | }
|
| 2375 |
|
| 2376 | /*************************ÅжÏдÈëµÄ¹«Ô¿hashÖµÊÇ·ñÕýÈ·**************************/
|
| 2377 | // ´Óotp¶ÁÈ¡
|
| 2378 | memset(&otpInfo, 0, sizeof(otpInfo));
|
| 2379 | if(ioctl(otp_fd , OTP_GET_DATA, &otpInfo)!= 0)
|
| 2380 | {
|
| 2381 | at_print(AT_ERR,"ioctl: OTP_GET_DATA fail.\n");
|
| 2382 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2383 | *res_msglen = strlen(*res_msg);
|
| 2384 | close(otp_fd);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2385 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2386 | return AT_END;
|
| 2387 | }
|
| 2388 | //±£Ö¤Ç°Ã湫Կhashֵд³É¹¦ÁË£¬ÔÙдÈ밲ȫboot flag
|
| 2389 | if (memcmp(otpInfo.pubKeyHash, pubKeyHash_otp, sizeof(pubKeyHash_otp)) != 0)
|
| 2390 | {
|
| 2391 | at_print(AT_ERR, "Public key hash in otp is not consistent!\n");
|
| 2392 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2393 | *res_msglen = strlen(*res_msg);
|
| 2394 | close(otp_fd);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2395 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2396 | return AT_END;
|
| 2397 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2398 |
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2399 | /*otpInfo.secureFlag×îºóÒ»¸ö×Ö½ÚÊǰ²È«Ê¹ÄܱêÖ¾*/
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2400 |
|
| 2401 | if ((otpInfo.secureFlag&0xff) != secureFlag_otp)
|
| 2402 | {
|
| 2403 | // ʹÄܱêʶλдÈëotp
|
| 2404 | if (ioctl(otp_fd , OTP_SET_SECURE_EN, &secureFlag_otp) != 0)
|
| 2405 | {
|
| 2406 | at_print(AT_ERR, "Write security flag to otp fail!\n");
|
| 2407 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2408 | *res_msglen = strlen(*res_msg);
|
| 2409 | close(otp_fd);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2410 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2411 | return AT_END;
|
| 2412 | }
|
| 2413 | else
|
| 2414 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2415 | at_print(AT_ERR, "Write security flag to otp success!\n");
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2416 | }
|
| 2417 | }
|
| 2418 | else
|
| 2419 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2420 | at_print(AT_ERR, "Secure flag in otp already exists!\n");
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2421 | }
|
| 2422 |
|
| 2423 | /*************************ÅжÏдÈëµÄsecure flagÊÇ·ñÕýÈ·**************************/
|
| 2424 | // ´Óotp¶ÁÈ¡
|
| 2425 | memset(&otpInfo, 0, sizeof(otpInfo));
|
| 2426 | if(ioctl(otp_fd , OTP_GET_DATA, &otpInfo)!= 0)
|
| 2427 | {
|
| 2428 | at_print(AT_ERR,"ioctl: OTP_GET_DATA fail.\n");
|
| 2429 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2430 | *res_msglen = strlen(*res_msg);
|
| 2431 | close(otp_fd);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2432 | close(efuse_fd);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2433 | return AT_END;
|
| 2434 | }
|
| 2435 |
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2436 | close(otp_fd);
|
| 2437 |
|
| 2438 | if ((otpInfo.secureFlag&0xff) != secureFlag_otp)
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2439 | {
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2440 | at_print(AT_ERR, "Security flag(%#08X) in otp is not consistent!\n", otpInfo.secureFlag);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2441 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2442 | *res_msglen = strlen(*res_msg);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 2443 | close(efuse_fd);
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2444 | return AT_END;
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2445 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2446 | }
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2447 |
|
| 2448 | //×îºóдefuse°²È«flag
|
| 2449 | /*efuseInfo.secureFlagÇ°Ãæ3¸ö×Ö½ÚÊÇchip flag,×îºóÒ»¸ö×Ö½ÚÊǰ²È«Ê¹ÄܱêÖ¾*/
|
| 2450 |
|
| 2451 | if ((efuseInfo.secureFlag&0xff) != secureFlag)
|
| 2452 | {
|
| 2453 | // ʹÄܱêʶλдÈëefuse
|
| 2454 | if (ioctl(efuse_fd , EFUSE_SET_SECURE_EN, &secureFlag) != 0)
|
| 2455 | {
|
| 2456 | at_print(AT_ERR, "Write security flag to efuse fail!\n");
|
| 2457 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2458 | *res_msglen = strlen(*res_msg);
|
| 2459 | close(efuse_fd);
|
| 2460 | return AT_END;
|
| 2461 | }
|
| 2462 | else
|
| 2463 | {
|
| 2464 | at_print(AT_ERR, "Write security flag to efuse success!\n");
|
| 2465 | }
|
| 2466 | }
|
| 2467 | else
|
| 2468 | {
|
| 2469 | at_print(AT_ERR, "Secure flag in efuse already exists!\n");
|
| 2470 | }
|
| 2471 |
|
| 2472 | /*************************ÅжÏдÈëµÄÐÅÏ¢ÊÇ·ñÕýÈ·**************************/
|
| 2473 | // ´Óefuse¶ÁÈ¡
|
| 2474 | memset(&efuseInfo, 0, sizeof(efuseInfo));
|
| 2475 | if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
|
| 2476 | {
|
| 2477 | at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
|
| 2478 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2479 | *res_msglen = strlen(*res_msg);
|
| 2480 | close(efuse_fd);
|
| 2481 | return AT_END;
|
| 2482 | }
|
| 2483 |
|
| 2484 | close(efuse_fd);
|
| 2485 |
|
| 2486 | if ((efuseInfo.secureFlag&0xff) != secureFlag)
|
| 2487 | {
|
| 2488 | at_print(AT_ERR, "Security flag(%#08X) in efuse is not consistent!\n", efuseInfo.secureFlag);
|
| 2489 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2490 | *res_msglen = strlen(*res_msg);
|
| 2491 | return AT_END;
|
| 2492 | }
|
| 2493 |
|
| 2494 | *res_msg = at_query_result_build("write security infomation", NULL);
|
| 2495 | *res_msglen = strlen(*res_msg);
|
| 2496 | return AT_END;
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2497 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2498 |
|
| 2499 | int read_security_info(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
|
| 2500 | {
|
| 2501 | char strValue[16];
|
| 2502 | char strLog[256] = {0};
|
| 2503 | int i;
|
| 2504 | int ret = 0;
|
| 2505 | T_ZDrvEfuse_Secure efuseInfo = {{0}};
|
| 2506 | int efuse_fd = -1;
|
| 2507 |
|
| 2508 | T_ZDrvOtp_Secure otpInfo = {{0}};
|
| 2509 | int otp_fd = -1;
|
| 2510 | int is_Enhanced_Security = -1;
|
| 2511 |
|
| 2512 | is_Enhanced_Security = IsEnhancedSecurity();
|
| 2513 | at_print(AT_ERR,"is_Enhanced_Security = %d.\n",is_Enhanced_Security);
|
| 2514 | if(is_Enhanced_Security == -1)
|
| 2515 | {
|
| 2516 | at_print(AT_ERR,"IsEnhancedSecurity() fail.\n");
|
| 2517 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2518 | *res_msglen = strlen(*res_msg);
|
| 2519 | return AT_END;
|
| 2520 | }
|
| 2521 |
|
| 2522 | efuse_fd = open("/dev/efuse", O_RDWR);
|
| 2523 | if (efuse_fd < 0)
|
| 2524 | {
|
| 2525 | at_print(AT_ERR,"open %s fail.\n","/dev/efuse");
|
| 2526 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2527 | *res_msglen = strlen(*res_msg);
|
| 2528 | return AT_END;
|
| 2529 | }
|
| 2530 |
|
| 2531 | at_print(AT_ERR,"open %s success.\n","/dev/efuse");
|
| 2532 |
|
| 2533 | // ´Óefuse¶ÁÈ¡
|
| 2534 | if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuseInfo)!= 0)
|
| 2535 | {
|
| 2536 | at_print(AT_ERR,"ioctl: EFUSE_GET_DATA fail.\n");
|
| 2537 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2538 | *res_msglen = strlen(*res_msg);
|
| 2539 | close(efuse_fd);
|
| 2540 | return AT_END;
|
| 2541 | }
|
| 2542 | else
|
| 2543 | {
|
| 2544 | at_print(AT_ERR,"ioctl: EFUSE_GET_DATA success.\n");
|
| 2545 | strLog[0] = '\0';
|
| 2546 | sprintf(strValue, "%02X,", efuseInfo.secureFlag&0xFF);
|
| 2547 | strcat(strLog, strValue);
|
| 2548 | for (i = 0; i < sizeof(efuseInfo.pubKeyHash)/sizeof(UINT32); i++)
|
| 2549 | {
|
| 2550 | sprintf(strValue, "%08lX", efuseInfo.pubKeyHash[i]);
|
| 2551 | strcat(strLog, strValue);
|
| 2552 | }
|
| 2553 | at_print(AT_ERR, "Secure Flag,Public key hash: %s\n", strLog);
|
| 2554 | close(efuse_fd);
|
| 2555 | if(is_Enhanced_Security == 0)
|
| 2556 | {
|
| 2557 | *res_msg = at_query_result_build("read security information", strLog);
|
| 2558 | *res_msglen = strlen(*res_msg);
|
| 2559 | return AT_END;
|
| 2560 | }
|
| 2561 | }
|
| 2562 |
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2563 | if(is_Enhanced_Security == 1)
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2564 | {
|
| 2565 | otp_fd = open("/dev/otp", O_RDWR);
|
| 2566 | if (otp_fd < 0)
|
| 2567 | {
|
| 2568 | at_print(AT_ERR,"open %s fail.\n","/dev/otp");
|
| 2569 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2570 | *res_msglen = strlen(*res_msg);
|
| 2571 | return AT_END;
|
| 2572 | }
|
| 2573 |
|
| 2574 | at_print(AT_ERR,"open %s success.\n","/dev/otp");
|
| 2575 |
|
| 2576 | // ´Óotp¶ÁÈ¡
|
| 2577 | if(ioctl(otp_fd , OTP_GET_DATA, &otpInfo)!= 0)
|
| 2578 | {
|
| 2579 | at_print(AT_ERR,"ioctl: OTP_GET_DATA fail.\n");
|
| 2580 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2581 | *res_msglen = strlen(*res_msg);
|
| 2582 | close(otp_fd);
|
| 2583 | return AT_END;
|
| 2584 | }
|
| 2585 | else
|
| 2586 | {
|
| 2587 | memset(strLog, 0, sizeof(strLog));
|
| 2588 | sprintf(strValue, "%02X,", efuseInfo.secureFlag&0xFF);
|
| 2589 | strcat(strLog, strValue);
|
| 2590 | for (i = 0; i < sizeof(otpInfo.pubKeyHash)/sizeof(UINT32); i++)
|
| 2591 | {
|
| 2592 | sprintf(strValue, "%08lX", otpInfo.pubKeyHash[i]);
|
| 2593 | strcat(strLog, strValue);
|
| 2594 | }
|
| 2595 | at_print(AT_ERR, "Secure Flag,Public key hash: %s\n", strLog);
|
| 2596 | *res_msg = at_query_result_build("read security information", strLog);
|
| 2597 | *res_msglen = strlen(*res_msg);
|
| 2598 | close(otp_fd);
|
| 2599 | return AT_END;
|
| 2600 | }
|
| 2601 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2602 |
|
| 2603 | }
|
| 2604 |
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2605 | #ifdef USE_NVRO_BACKUP
|
| 2606 | int backup_nvro_func(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
|
| 2607 | {
|
| 2608 | unsigned int ret = CPNV_ERROR;
|
| 2609 |
|
| 2610 | ret = cpnv_NvroBackup();
|
| 2611 | if (CPNV_ERROR== ret)
|
| 2612 | {
|
| 2613 | at_print(AT_ERR,"nvro backup failed\n");
|
| 2614 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2615 | }
|
| 2616 | else
|
| 2617 | {
|
| 2618 | at_print(AT_ERR, "nvro backup success\n");
|
| 2619 | *res_msg = at_ok_build();
|
| 2620 | }
|
| 2621 |
|
| 2622 | *res_msglen = strlen(*res_msg);
|
| 2623 | return AT_END;
|
| 2624 | }
|
| 2625 | #endif
|
| 2626 |
|
| 2627 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2628 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2629 | /*
|
| 2630 | int auth_device_key(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
|
| 2631 | {
|
| 2632 | char *at_str = NULL;
|
| 2633 |
|
| 2634 | at_print(AT_ERR,"at_paras=%s\n",at_paras);
|
| 2635 |
|
| 2636 | at_str = at_paras;
|
| 2637 | char seed[] = SEED;
|
| 2638 | auth_device_key_result = verify_device_key(at_str,strlen(at_str),seed,strlen(seed));
|
| 2639 | at_print(AT_ERR,"auth_device_key_result=%d\n",auth_device_key_result);
|
| 2640 |
|
| 2641 | if (auth_device_key_result == 1)
|
| 2642 | {
|
| 2643 | *res_msg = at_ok_build();
|
| 2644 | }
|
| 2645 | else
|
| 2646 | {
|
| 2647 | at_print(AT_ERR,"verify device key fail !\n");
|
| 2648 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 2649 | }
|
| 2650 | *res_msglen = strlen(*res_msg);
|
| 2651 |
|
| 2652 | return AT_END;
|
| 2653 | }
|
| 2654 | */
|
| 2655 |
|
| 2656 | int ext_amt_regist(void)
|
| 2657 | {
|
| 2658 | if(!ext_is_usermode())
|
| 2659 | {
|
| 2660 | register_serv_func2("MODIMEI=",0,0,0,imeiWrite_act_func,NULL);
|
| 2661 | register_serv_func2("PHONEMODE=",0,0,0,zphone_mode_set_req_act, 0);
|
| 2662 | register_serv_func("ramdump",0,ext_ramdump_func);
|
| 2663 | // дÈ밲ȫÐÅÏ¢
|
| 2664 | register_serv_func2("WSCYINFO",0,0,0,write_security_info,NULL);
|
| 2665 | }
|
| 2666 | register_serv_func2("RKEYDC=",0,0,0,rkeydc_act_func,NULL);
|
| 2667 | register_serv_func2("ZPOWEROFF",0,0,0,poweroff_act_func,NULL);
|
| 2668 | register_serv_func2("PLATFORM?",0,0,0,chip_platform_read_act_func,NULL);
|
| 2669 | register_serv_func2("READIMEI",0,0,0,imeiRead_act_func,NULL);
|
| 2670 | register_serv_func2("READIMEI?",0,0,0,imeiRead_act_func,NULL);
|
| 2671 | register_serv_func2("SSID?",0,0,0,ssidRead_act_func,NULL);
|
| 2672 | register_serv_func2("SSID=",0,0,0,ssidWrite_act_func,NULL);
|
| 2673 | register_serv_func2("ZVERSIONTYPE=",0,0,0,versionTypeSet_act_func,NULL);
|
| 2674 | register_serv_func2("MAC?",0,0,0,macRead_act_func,NULL);
|
| 2675 | register_serv_func2("MAC=",0,0,0,macWrite_act_func,NULL);
|
| 2676 | register_serv_func2("WIFIKEY?",0,0,0,wifikeyRead_act_func,NULL);
|
| 2677 | register_serv_func2("WIFIKEY=",0,0,0,wifikeyWrite_act_func,NULL);
|
| 2678 | register_serv_func2("ETHMAC?",0,0,0,rj45MacAddrRead_act_func,NULL);
|
| 2679 | register_serv_func2("ETHMAC=",0,0,0,rj45MacAddWrite_act_func,NULL);
|
| 2680 | register_serv_func2("MAC2?",0,0,0,mac2Read_act_func,NULL);
|
| 2681 | register_serv_func2("MAC2=",0,0,0,mac2Write_act_func,NULL);
|
| 2682 | register_serv_func2("USBMAC?",0,0,0,usbmacRead_act_func,NULL);
|
| 2683 | register_serv_func2("USBMAC=",0,0,0,usbmacWrite_act_func,NULL);
|
| 2684 | register_serv_func2("GMAC?",0,0,0,gmacRead_act_func,NULL);
|
| 2685 | register_serv_func2("GMAC=",0,0,0,gmacWrite_act_func,NULL);
|
| 2686 | register_serv_func2("BATDET?",0,0,0,batdetRead_act_func,NULL);
|
| 2687 | register_serv_func2("BATDET=",0,0,0,batdetWrite_act_func,NULL);
|
| 2688 | register_serv_func2("MSN?",0,0,0,msnRead_act_func,NULL);
|
| 2689 | register_serv_func2("MSN=",0,0,0,msnWrite_act_func,NULL);
|
| 2690 | register_serv_func2("RTESTINFO",0,0,0,testInfoRead_act_func,NULL);
|
| 2691 | register_serv_func2("ZAMTMODE=",0,0,0,closeAutoInd_act_func,NULL);
|
| 2692 |
|
| 2693 | //Çл»Õý³£°æ±¾ºÍ´¿modem°æ±¾
|
| 2694 | register_serv_func2("PHONEMODE?",0,0,0,zphone_mode_query_req_act, 0);
|
| 2695 |
|
| 2696 | register_serv_func2("ZSOFTRESET",0,0,0,zsoftreset_act_func,NULL);
|
| 2697 |
|
| 2698 | register_serv_func2("zmode=",0,0,0,zmodeSet_act_func,NULL);
|
| 2699 | //mdlÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨AT+ZAUTH=KEY
|
| 2700 | //register_serv_func2("ZAUTH=",0,0,0,auth_device_key,NULL);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2701 | register_serv_func2("RSCYINFO",0,0,0,read_security_info,NULL);
|
| 2702 |
|
xf.li | 9d1a0e1 | 2023-09-20 01:43:20 -0700 | [diff] [blame] | 2703 | #ifdef USE_NVRO_BACKUP
|
| 2704 | register_serv_func2("NVROBACKUP",0,0,0,backup_nvro_func,NULL);
|
| 2705 | #endif
|
| 2706 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2707 | return 0;
|
| 2708 | }
|