lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /**
|
| 2 | *
|
| 3 | * @file amt.c
|
| 4 | * @brief
|
| 5 | * This file is part of FTM.
|
| 6 | * AMT´úÀíÓ¦Óòã
|
| 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 | * 2015/04/28 1.0 lu.xieji Create file
|
| 24 | * 2019/02/02 1.1 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
|
| 25 | * ---------------------------------------------------------------------------
|
| 26 | *
|
| 27 | *
|
| 28 | */
|
| 29 |
|
| 30 | #include <stdlib.h>
|
| 31 | #include <stdio.h>
|
| 32 | #include <string.h>
|
| 33 | #include <pthread.h>
|
| 34 | #include <sys/types.h>
|
| 35 | #include <sys/stat.h>
|
| 36 | #include <sys/ioctl.h>
|
| 37 | #include <sys/msg.h>
|
| 38 | #include <fcntl.h>
|
| 39 | #include <unistd.h>
|
| 40 | #include "linux/rpmsg_zx29.h"
|
| 41 | #include <sys/socket.h>
|
| 42 | #include <netdb.h>
|
| 43 | #include <netinet/in.h>
|
| 44 | #include <linux/netlink.h>
|
| 45 | #include <arpa/inet.h>
|
| 46 | #include <netinet/in.h>
|
| 47 | #include <signal.h>
|
| 48 | #include <errno.h>
|
| 49 | #include "port_com.h"
|
| 50 | #include "amt.h"
|
| 51 | #include "os_type_def.h"
|
| 52 | #include "softap_api.h"
|
| 53 | #include "other_msg.h"
|
| 54 | #include "message.h"
|
| 55 | #include "amt_agent_devicetest.h"
|
| 56 | #include "kwatch_msg.h"
|
| 57 | #include "amtnv.h"
|
| 58 | #include "libcpnv.h"
|
| 59 | #include <sys/prctl.h>
|
| 60 | #include "ref_nv_def.h"
|
| 61 | #include "nv_api.h"
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 | /**
|
| 67 | * Íⲿº¯ÊýÒýÓÃ
|
| 68 | */
|
| 69 | extern int Amt_Wifi_Init(void);
|
| 70 | extern int Amt_Wifi_ProcessMsg(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len);
|
| 71 | extern int Amt_Gps_ProcessMsg(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len);
|
| 72 | extern int Amt_DeviceTest_ProcessMsg(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len);
|
| 73 | extern int Amt_Process_Gps_Rsp(MSG_BUF *msg,unsigned int msg_id);
|
| 74 | extern int Amt_FuncTest_ProcessMsg(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len);
|
| 75 | extern int wifi_ioctl_handle(int cmd);
|
| 76 |
|
| 77 |
|
| 78 | /**
|
| 79 | * È«¾Ö±äÁ¿ÉùÃ÷
|
| 80 | */
|
| 81 | static int g_amt_fd_cp = -1;
|
| 82 | static int g_amt_fd_usb = -1;
|
| 83 | static int g_amt_fd_usb_hotplug = -1;
|
| 84 | static int g_amt_fd_socket_client = -1;
|
| 85 | static int g_amt_fd_socket_server = -1;
|
| 86 | static fd_set g_amt_fdsread;
|
| 87 | static int g_amt_fd_max = 0;
|
| 88 | static volatile int *g_amt_fd_current = NULL;
|
| 89 | static int g_amt_iMsgHandle = 0;
|
| 90 | unsigned int g_amt_at_mode = 0;
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 | /**
|
| 95 | * @brief AMTÏûÏ¢·¢Ë͸øPC
|
| 96 | * @param[in] fd ÎļþÃèÊö·û
|
| 97 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 98 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 99 | * @return ·µ»Ø·¢Ë͵ÄÊý¾Ý³¤¶È
|
| 100 | * @note
|
| 101 | * @see
|
| 102 | */
|
| 103 | static int Amt_SendData(int fd, unsigned char* buf, unsigned int buf_len)
|
| 104 | {
|
| 105 | int write_len = PortSend(fd, (unsigned char*)&buf_len, sizeof(unsigned int), WAIT_ALL);
|
| 106 |
|
| 107 | //if (write_len > 0)
|
| 108 | {
|
| 109 | write_len = PortSend(fd, buf, buf_len, WAIT_ALL);
|
| 110 |
|
| 111 | if (write_len <= 0)
|
| 112 | {
|
| 113 | AmtPrintf(AMT_ERROR "%s: PortSend 'data' to device(fd = %d): write_len(%d) is wrong.\n", __FUNCTION__, fd, write_len);
|
| 114 | }
|
| 115 | }
|
| 116 | /*
|
| 117 | else
|
| 118 | {
|
| 119 | AmtPrintf(AMT_ERROR "%s: PortSend 'length' to device(fd = %d): write_len(%d) is wrong.\n", __FUNCTION__, fd, write_len);
|
| 120 | }
|
| 121 | */
|
| 122 |
|
| 123 | return write_len;
|
| 124 | }
|
| 125 |
|
| 126 | /**
|
| 127 | * @brief AMTÏûÏ¢·¢ËÍ
|
| 128 | * @param[in] fd ÎļþÃèÊö·û
|
| 129 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 130 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 131 | * @return ·µ»Ø·¢Ë͵ÄÊý¾Ý³¤¶È
|
| 132 | * @note
|
| 133 | * @see
|
| 134 | */
|
| 135 | static int Amt_SendDataToAmtagent(int fd, unsigned char* buf, unsigned int buf_len)
|
| 136 | {
|
| 137 | int write_len = PortSend(fd, buf, buf_len, NO_WAIT);
|
| 138 |
|
| 139 | if (write_len <= 0)
|
| 140 | {
|
| 141 | AmtPrintf(AMT_ERROR "%s: PortSend 'data' to device(fd = %d): write_len(%d) is wrong.\n", __FUNCTION__, fd, write_len);
|
| 142 | }
|
| 143 | else
|
| 144 | {
|
| 145 | AmtPrintf(AMT_INFO "%s: PortSend 'data' to device(fd = %d): write_len(%d),buf_len(%d) \n", __FUNCTION__, fd, write_len,buf_len);
|
| 146 | }
|
| 147 | return write_len;
|
| 148 | }
|
| 149 |
|
| 150 |
|
| 151 | /**
|
| 152 | * @brief AMTÏûÏ¢½ÓÊÕ
|
| 153 | * @param[in] fd ÎļþÃèÊö·û
|
| 154 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 155 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 156 | * @return ·µ»Ø½ÓÊÕµ½µÄÊý¾Ý³¤¶È
|
| 157 | * @note
|
| 158 | * @see
|
| 159 | */
|
| 160 | static int Amt_ReceiveData(int fd, unsigned char* buf, unsigned int buf_len)
|
| 161 | {
|
| 162 | int read_len = PortRecv(fd, buf, sizeof(unsigned int), WAIT_ALL);
|
| 163 |
|
| 164 | if (read_len > 0)
|
| 165 | {
|
| 166 | unsigned int packet_len = *((unsigned int *)buf);
|
| 167 | if (packet_len > 0 && packet_len <= buf_len)
|
| 168 | {
|
| 169 | read_len = PortRecv(fd, buf, packet_len, WAIT_ALL);
|
| 170 |
|
| 171 | if (read_len <= 0)
|
| 172 | {
|
| 173 | AmtPrintf(AMT_ERROR "%s: PortRecv 'data' from device(fd = %d): read_len(%d) is wrong.\n", __FUNCTION__, fd, read_len);
|
| 174 | }
|
| 175 | }
|
| 176 | else
|
| 177 | {
|
| 178 | AmtPrintf(AMT_ERROR "%s: fd = %d, packet_len(%d) is wrong.\n", __FUNCTION__, fd, packet_len);
|
| 179 | read_len = -1;
|
| 180 | }
|
| 181 | }
|
| 182 | else
|
| 183 | {
|
| 184 | AmtPrintf(AMT_ERROR "%s: PortRecv 'length' from device(fd = %d): read_len(%d) is wrong.\n", __FUNCTION__, fd, read_len);
|
| 185 | }
|
| 186 |
|
| 187 | return read_len;
|
| 188 | }
|
| 189 |
|
| 190 | #if 0
|
| 191 | static void str_to_int( int *data, char *str )
|
| 192 | {
|
| 193 | int Lc = 0;
|
| 194 | int Len = 0;
|
| 195 | char *Begb = NULL;
|
| 196 | char *Endb = NULL;
|
| 197 | char *ptr = NULL;
|
| 198 | char s1[100] = "";
|
| 199 | char s2[50] = "";
|
| 200 | memset(s1, 0, sizeof(s1));
|
| 201 | strcpy(s1, str);
|
| 202 | strcat(s1, ",");
|
| 203 | Begb = s1; //ÆðʼµØÖ·
|
| 204 | Endb = strchr(s1,','); //µÚÒ»¸ö¶ººÅλÖÃ
|
| 205 | if (Endb == NULL)
|
| 206 | return;
|
| 207 | Lc = 0;
|
| 208 | do
|
| 209 | {
|
| 210 | Len = 0;
|
| 211 | Len = Endb - Begb; //³¤¶È
|
| 212 | memset(s2, 0, sizeof(s2)); //½ØÈ¡Á½¸ö¶ººÅ¼äµÄ×Ö·û´®
|
| 213 | strncpy(s2, Begb, Len); //½ØÈ¡Á½¸ö¶ººÅ¼äµÄ×Ö·û´®
|
| 214 | data[Lc] = atoi(s2); //string to int
|
| 215 | ptr = Endb + 1; //Ö¸ÏòϸöÊýµÄÆðʼµØÖ·
|
| 216 | strcpy(s1, ptr); //È¥µôÒÑת»¯µÄ×Ö·û´®
|
| 217 | Begb = s1; //ÆðʼµØÖ·¸üÐÂ
|
| 218 | Endb = strchr(s1,','); //ϸö¶ººÅλÖÃ
|
| 219 | Lc++;
|
| 220 | }while(Endb!=NULL);
|
| 221 | }
|
| 222 | #endif
|
| 223 |
|
| 224 | static void str_to_double( double *data, char *str )
|
| 225 | {
|
| 226 | int Lc = 0;
|
| 227 | int Len = 0;
|
| 228 | char *Begb = NULL;
|
| 229 | char *Endb = NULL;
|
| 230 | char *ptr = NULL;
|
| 231 | char s1[100] = "";
|
| 232 | char s2[50] = "";
|
| 233 | memset(s1, 0, sizeof(s1));
|
| 234 | strncpy(s1, str,sizeof(s1) - 1);
|
| 235 | strcat(s1, ",");
|
| 236 | Begb = s1; //ÆðʼµØÖ·
|
| 237 | Endb = strchr(s1,','); //µÚÒ»¸ö¶ººÅλÖÃ
|
| 238 | if (Endb == NULL)
|
| 239 | return;
|
| 240 | Lc = 0;
|
| 241 | do
|
| 242 | {
|
| 243 | Len = 0;
|
| 244 | Len = Endb - Begb; //³¤¶È
|
| 245 | memset(s2, 0, sizeof(s2)); //½ØÈ¡Á½¸ö¶ººÅ¼äµÄ×Ö·û´®
|
| 246 | strncpy(s2, Begb, sizeof(s2) - 1); //½ØÈ¡Á½¸ö¶ººÅ¼äµÄ×Ö·û´®
|
| 247 | data[Lc] = atof(s2); //string to int
|
| 248 | ptr = Endb + 1; //Ö¸ÏòϸöÊýµÄÆðʼµØÖ·
|
| 249 | strncpy(s1, ptr, sizeof(s1) - 1); //È¥µôÒÑת»¯µÄ×Ö·û´®
|
| 250 | Begb = s1; //ÆðʼµØÖ·¸üÐÂ
|
| 251 | Endb = strchr(s1,','); //ϸö¶ººÅλÖÃ
|
| 252 | Lc++;
|
| 253 | }while(Endb!=NULL);
|
| 254 | }
|
| 255 |
|
| 256 | /**
|
| 257 | * @brief ¶ÁÈ¡cp²àµÄ·´À¡ÏûÏ¢Ï̺߳¯Êý
|
| 258 | * @param[in] args Ï̺߳¯Êý²ÎÊý
|
| 259 | * @return N/A
|
| 260 | * @note
|
| 261 | * @see
|
| 262 | */
|
| 263 | static void* ReadFromCPThread(void* args)
|
| 264 | {
|
| 265 | // Read from AP-CP channel
|
| 266 | char *receive_buffer = NULL;
|
| 267 |
|
| 268 | UNUSED(args);
|
| 269 |
|
| 270 | receive_buffer = malloc(MAX_PACKET_LENGTH);
|
| 271 | if (receive_buffer == NULL)
|
| 272 | {
|
| 273 | return NULL;
|
| 274 | }
|
| 275 |
|
| 276 | prctl(PR_SET_NAME, "AmtReadFromCP");
|
| 277 |
|
| 278 | while (1)
|
| 279 | {
|
| 280 | int read_len = Amt_ReceiveData(g_amt_fd_cp, (unsigned char *)receive_buffer, MAX_PACKET_LENGTH);
|
| 281 |
|
| 282 | if (read_len > 0)
|
| 283 | {
|
| 284 | AmtPrintf(AMT_INFO "%s: Receive cp data, read_len = %d!.\n", __FUNCTION__, read_len);
|
| 285 |
|
| 286 | if (g_amt_fd_current && *g_amt_fd_current >= 0)
|
| 287 | {
|
| 288 | if(g_amt_at_mode != 1)
|
| 289 | {
|
| 290 | Amt_SendData(*g_amt_fd_current, (unsigned char *)receive_buffer, read_len);
|
| 291 | }
|
| 292 | }
|
| 293 | else
|
| 294 | {
|
| 295 | AmtPrintf(AMT_ERROR "%s: Current fd is wrong.\n", __FUNCTION__);
|
| 296 | }
|
| 297 |
|
| 298 |
|
| 299 | unsigned int status = cpnv_FsGcWait(FS_NVROFS);
|
| 300 | if(status != CPNV_OK)
|
| 301 | AmtPrintf(AMT_INFO "%s: cpnv_FsGcWait fail, err = %d.\n", __FUNCTION__, status);
|
| 302 | }
|
| 303 | }
|
| 304 |
|
| 305 | free(receive_buffer);
|
| 306 | return NULL;
|
| 307 | }
|
| 308 |
|
| 309 |
|
| 310 | /**
|
| 311 | * @brief ¶ÁÈ¡ÆäËûappµÄÏûÏ¢Ï̺߳¯Êý
|
| 312 | * @param[in] args Ï̺߳¯Êý²ÎÊý
|
| 313 | * @return N/A
|
| 314 | * @note
|
| 315 | * @see
|
| 316 | */
|
| 317 | static void* RecvMsgFromAppThread(void* args)
|
| 318 | {
|
| 319 | int iRet ;
|
| 320 | MSG_BUF stMsg = {0};
|
| 321 | LONG msgSize = sizeof(MSG_BUF) - sizeof(LONG);
|
| 322 |
|
| 323 | UNUSED(args);
|
| 324 |
|
| 325 | prctl(PR_SET_NAME, "AmtRecvAppMsg");
|
| 326 | while(1)
|
| 327 | {
|
| 328 | iRet = 0;
|
| 329 | memset(&stMsg, 0x00, sizeof(MSG_BUF));
|
| 330 |
|
| 331 | iRet = msgrcv(g_amt_iMsgHandle, &stMsg, msgSize, 0, 0);
|
| 332 | if(iRet >= 0)
|
| 333 | {
|
| 334 | AmtPrintf(AMT_INFO "%s: msgcmd = 0x%x,datalen=%d.\n", __FUNCTION__,stMsg.usMsgCmd,stMsg.usDataLen);
|
| 335 |
|
| 336 | switch (stMsg.usMsgCmd)
|
| 337 | {
|
| 338 | case MSG_CMD_AMT_BATTERY_VOLTAGE_TEST_RSP:
|
| 339 | {
|
| 340 | AmtPrintf(AMT_INFO "%s: recv MSG_CMD_AMT_BATTERY_VOLTAGE_TEST_RSP.\n", __FUNCTION__);
|
| 341 | int result = AMT_SUCCESS_RET;
|
| 342 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_BATTERY_VOLTAGE, result, (unsigned char *)stMsg.aucDataBuf, stMsg.usDataLen);
|
| 343 | break;
|
| 344 | }
|
| 345 |
|
| 346 | case MSG_CMD_AMT_KEY_TEST_START_RSP:
|
| 347 | {
|
| 348 | int result = AMT_ERROR_RET;
|
| 349 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 350 | result = *pAucDataBuf;
|
| 351 | if (result == 0)
|
| 352 | {
|
| 353 | result = AMT_SUCCESS_RET;
|
| 354 | }
|
| 355 | else
|
| 356 | {
|
| 357 | result = AMT_ERROR_RET;
|
| 358 | AmtPrintf(AMT_INFO "%s: KEY_TEST_START fail.", __FUNCTION__);
|
| 359 | }
|
| 360 |
|
| 361 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_KEYBOARD_START, result, NULL, 0);
|
| 362 | break;
|
| 363 | }
|
| 364 |
|
| 365 | case MSG_CMD_AMT_KEY_TEST_STOP_RSP:
|
| 366 | {
|
| 367 | int result = AMT_SUCCESS_RET;
|
| 368 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_KEYBOARD_STOP, result, (unsigned char *)stMsg.aucDataBuf, stMsg.usDataLen);
|
| 369 | break;
|
| 370 | }
|
| 371 |
|
| 372 | case MSG_CMD_AMT_LCD_TEST_START_RSP:
|
| 373 | {
|
| 374 | int result = AMT_ERROR_RET;
|
| 375 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 376 | result = *pAucDataBuf;
|
| 377 | if (result == 0)
|
| 378 | {
|
| 379 | result = AMT_SUCCESS_RET;
|
| 380 | }
|
| 381 | else
|
| 382 | {
|
| 383 | result = AMT_ERROR_RET;
|
| 384 | AmtPrintf(AMT_INFO "%s: LCD_TEST_START fail.", __FUNCTION__);
|
| 385 | }
|
| 386 |
|
| 387 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_LCD_START, result, NULL, 0);
|
| 388 | break;
|
| 389 | }
|
| 390 |
|
| 391 | case MSG_CMD_AMT_LCD_TEST_STOP_RSP:
|
| 392 | {
|
| 393 | int result = AMT_ERROR_RET;
|
| 394 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 395 | result = *pAucDataBuf;
|
| 396 | AmtPrintf(AMT_INFO "%s: LCD_TEST_STOP result=%d\n", __FUNCTION__,result);
|
| 397 | if (result == 0)
|
| 398 | {
|
| 399 | result = AMT_SUCCESS_RET;
|
| 400 | }
|
| 401 | else
|
| 402 | {
|
| 403 | result = AMT_ERROR_RET;
|
| 404 | AmtPrintf(AMT_INFO "%s: LCD_TEST_STOP fail.", __FUNCTION__);
|
| 405 | }
|
| 406 |
|
| 407 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_LCD_STOP, result, NULL, 0);
|
| 408 | break;
|
| 409 | }
|
| 410 |
|
| 411 | case MSG_CMD_AMT_LCD_BACKLIGHT_TEST_START_RSP:
|
| 412 | {
|
| 413 | int result = AMT_ERROR_RET;
|
| 414 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 415 | result = *pAucDataBuf;
|
| 416 | if (result == 1)
|
| 417 | {
|
| 418 | result = AMT_SUCCESS_RET;
|
| 419 | }
|
| 420 | else
|
| 421 | {
|
| 422 | result = AMT_ERROR_RET;
|
| 423 | AmtPrintf(AMT_INFO "%s: LCD_BACKLIGHT_TEST_START fail.", __FUNCTION__);
|
| 424 | }
|
| 425 |
|
| 426 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_LCDBACKLIGHT_START, result, NULL, 0);
|
| 427 | break;
|
| 428 | }
|
| 429 |
|
| 430 | case MSG_CMD_AMT_LCD_BACKLIGHT_TEST_STOP_RSP:
|
| 431 | {
|
| 432 | int result = AMT_ERROR_RET;
|
| 433 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 434 | result = *pAucDataBuf;
|
| 435 | if (result == 0)
|
| 436 | {
|
| 437 | result = AMT_SUCCESS_RET;
|
| 438 | }
|
| 439 | else
|
| 440 | {
|
| 441 | result = AMT_ERROR_RET;
|
| 442 | AmtPrintf(AMT_INFO "%s: LCD_BACKLIGHT_TEST_STOP fail.", __FUNCTION__);
|
| 443 | }
|
| 444 |
|
| 445 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_LCDBACKLIGHT_STOP, result, NULL, 0);
|
| 446 | break;
|
| 447 | }
|
| 448 |
|
| 449 | case MSG_CMD_AMT_VIBRATOR_TEST_START_RSP:
|
| 450 | {
|
| 451 | int result = AMT_ERROR_RET;
|
| 452 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 453 | result = *pAucDataBuf;
|
| 454 | if (result == 1)
|
| 455 | {
|
| 456 | result = AMT_SUCCESS_RET;
|
| 457 | }
|
| 458 | else
|
| 459 | {
|
| 460 | result = AMT_ERROR_RET;
|
| 461 | AmtPrintf(AMT_INFO "%s: VIBRATOR_TEST_START fail.", __FUNCTION__);
|
| 462 | }
|
| 463 |
|
| 464 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_VIBRATOR_START, result, NULL, 0);
|
| 465 | break;
|
| 466 | }
|
| 467 |
|
| 468 | case MSG_CMD_AMT_VIBRATOR_TEST_STOP_RSP:
|
| 469 | {
|
| 470 | int result = AMT_ERROR_RET;
|
| 471 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 472 | result = *pAucDataBuf;
|
| 473 | if (result == 0)
|
| 474 | {
|
| 475 | result = AMT_SUCCESS_RET;
|
| 476 | }
|
| 477 | else
|
| 478 | {
|
| 479 | result = AMT_ERROR_RET;
|
| 480 | AmtPrintf(AMT_INFO "%s: VIBRATOR_TEST_STOP fail.", __FUNCTION__);
|
| 481 | }
|
| 482 |
|
| 483 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_VIBRATOR_STOP, result, NULL, 0);
|
| 484 | break;
|
| 485 | }
|
| 486 |
|
| 487 | case MSG_CMD_AMT_CAMERA_TEST_START_RSP:
|
| 488 | {
|
| 489 | int result = AMT_ERROR_RET;
|
| 490 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 491 | result = *pAucDataBuf;
|
| 492 | if (result == 1)
|
| 493 | {
|
| 494 | result = AMT_SUCCESS_RET;
|
| 495 | }
|
| 496 | else
|
| 497 | {
|
| 498 | result = AMT_ERROR_RET;
|
| 499 | AmtPrintf(AMT_INFO "%s: CAMERA_TEST_START fail.", __FUNCTION__);
|
| 500 | }
|
| 501 |
|
| 502 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_CAMERA_BACK_START, result, NULL, 0);
|
| 503 | break;
|
| 504 | }
|
| 505 |
|
| 506 | case MSG_CMD_AMT_CAMERA_TEST_STOP_RSP:
|
| 507 | {
|
| 508 | int result = AMT_ERROR_RET;
|
| 509 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 510 | result = *pAucDataBuf;
|
| 511 | if (result == 0)
|
| 512 | {
|
| 513 | result = AMT_SUCCESS_RET;
|
| 514 | }
|
| 515 | else
|
| 516 | {
|
| 517 | result = AMT_ERROR_RET;
|
| 518 | AmtPrintf(AMT_INFO "%s: CAMERA_TEST_STOP fail.", __FUNCTION__);
|
| 519 | }
|
| 520 |
|
| 521 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_CAMERA_BACK_STOP, result, NULL, 0);
|
| 522 | break;
|
| 523 | }
|
| 524 |
|
| 525 | case MSG_CMD_AMT_SPEAKER_TEST_RSP:
|
| 526 | {
|
| 527 | AmtPrintf(AMT_INFO "%s: recv MSG_CMD_AMT_SPEAKER_TEST_RSP.\n", __FUNCTION__);
|
| 528 | int result = AMT_ERROR_RET;
|
| 529 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 530 | result = *pAucDataBuf;
|
| 531 | if (result == 1)
|
| 532 | {
|
| 533 | result = AMT_SUCCESS_RET;
|
| 534 | }
|
| 535 | else
|
| 536 | {
|
| 537 | result = AMT_ERROR_RET;
|
| 538 | AmtPrintf(AMT_INFO "%s: SPEAKER_TEST fail.", __FUNCTION__);
|
| 539 | }
|
| 540 |
|
| 541 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_AUDIO_MIC_SPEAKER, result, NULL, 0);
|
| 542 | break;
|
| 543 | }
|
| 544 |
|
| 545 | case MSG_CMD_AMT_SPEAKER_TEST_STOP_RSP:
|
| 546 | {
|
| 547 | AmtPrintf(AMT_INFO "%s: recv MSG_CMD_AMT_SPEAKER_TEST_STOP_RSP.\n", __FUNCTION__);
|
| 548 | int result = AMT_SUCCESS_RET;
|
| 549 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_AUDIO_MIC_SPEAKER_STOP, result, NULL, 0);
|
| 550 | break;
|
| 551 | }
|
| 552 |
|
| 553 | case MSG_CMD_AMT_RECEIVER_TEST_RSP:
|
| 554 | {
|
| 555 | AmtPrintf(AMT_INFO "%s: recv MSG_CMD_AMT_RECEIVER_TEST_RSP.\n", __FUNCTION__);
|
| 556 | int result = AMT_ERROR_RET;
|
| 557 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 558 | result = *pAucDataBuf;
|
| 559 | if (result == 1)
|
| 560 | {
|
| 561 | result = AMT_SUCCESS_RET;
|
| 562 | }
|
| 563 | else
|
| 564 | {
|
| 565 | result = AMT_ERROR_RET;
|
| 566 | AmtPrintf(AMT_INFO "%s: RECEIVER_TEST fail.", __FUNCTION__);
|
| 567 | }
|
| 568 |
|
| 569 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_AUDIO_MIC_RECEIVER, result, NULL, 0);
|
| 570 | break;
|
| 571 | }
|
| 572 |
|
| 573 | case MSG_CMD_AMT_RECEIVER_TEST_STOP_RSP:
|
| 574 | {
|
| 575 | AmtPrintf(AMT_INFO "%s: recv MSG_CMD_AMT_RECEIVER_TEST_STOP_RSP.\n", __FUNCTION__);
|
| 576 | int result = AMT_SUCCESS_RET;
|
| 577 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_AUDIO_MIC_RECEIVER_STOP, result, NULL, 0);
|
| 578 | break;
|
| 579 | }
|
| 580 |
|
| 581 | case MSG_CMD_AMT_TP_TEST_START_RSP:
|
| 582 | {
|
| 583 | int result = AMT_ERROR_RET;
|
| 584 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 585 | result = *pAucDataBuf;
|
| 586 | if (result == 1)
|
| 587 | {
|
| 588 | result = AMT_SUCCESS_RET;
|
| 589 | }
|
| 590 | else
|
| 591 | {
|
| 592 | result = AMT_ERROR_RET;
|
| 593 | AmtPrintf(AMT_INFO "%s: TP_TEST_START fail.", __FUNCTION__);
|
| 594 | }
|
| 595 |
|
| 596 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_TP_START, result, NULL, 0);
|
| 597 | break;
|
| 598 | }
|
| 599 |
|
| 600 | case MSG_CMD_AMT_TP_TEST_STOP_RSP:
|
| 601 | {
|
| 602 | int result = AMT_ERROR_RET;
|
| 603 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 604 | result = *pAucDataBuf;
|
| 605 | if (result == 0)
|
| 606 | {
|
| 607 | result = AMT_SUCCESS_RET;
|
| 608 | }
|
| 609 | else
|
| 610 | {
|
| 611 | result = AMT_ERROR_RET;
|
| 612 | AmtPrintf(AMT_INFO "%s: TP_TEST_STOP fail.", __FUNCTION__);
|
| 613 | }
|
| 614 |
|
| 615 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_TP_STOP, result, NULL, 0);
|
| 616 | break;
|
| 617 | }
|
| 618 |
|
| 619 | case MSG_CMD_AMT_GSENSOR_TEST_START_RSP:
|
| 620 | {
|
| 621 | break;
|
| 622 | }
|
| 623 |
|
| 624 | case MSG_CMD_AMT_GSENSOR_TEST_STOP_RSP:
|
| 625 | {
|
| 626 | break;
|
| 627 | }
|
| 628 |
|
| 629 | case MSG_CMD_AMT_WIFI_TEST_START_RSP:
|
| 630 | {
|
| 631 | int result = AMT_ERROR_RET;
|
| 632 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 633 | result = *pAucDataBuf;
|
| 634 | if (result == 1)
|
| 635 | {
|
| 636 | result = AMT_SUCCESS_RET;
|
| 637 | }
|
| 638 | else
|
| 639 | {
|
| 640 | result = AMT_ERROR_RET;
|
| 641 | AmtPrintf(AMT_INFO "%s: Wifi test fail!", __FUNCTION__);
|
| 642 | }
|
| 643 |
|
| 644 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_WIFI, result, NULL, 0);
|
| 645 | break;
|
| 646 | }
|
| 647 |
|
| 648 | case MSG_CMD_AMT_FLASHLIGHT_START_RSP:
|
| 649 | {
|
| 650 | int result = AMT_ERROR_RET;
|
| 651 | int* pAucDataBuf = (int*)stMsg.aucDataBuf;
|
| 652 | result = *pAucDataBuf;
|
| 653 | if (result == 1)
|
| 654 | {
|
| 655 | result = AMT_SUCCESS_RET;
|
| 656 | }
|
| 657 | else
|
| 658 | {
|
| 659 | result = AMT_ERROR_RET;
|
| 660 | AmtPrintf(AMT_INFO "%s: flashlight test fail!", __FUNCTION__);
|
| 661 | }
|
| 662 |
|
| 663 | Amt_DeviceTest_SendMsg(MSG_DEVICETEST_FLASHLIGHT_START, result, NULL, 0);
|
| 664 | break;
|
| 665 | }
|
| 666 | //gps²âÊÔÏûÏ¢»ØÓ¦
|
| 667 | case KWATCH_MSG_GPS_RSP:
|
| 668 | {
|
| 669 | Amt_Process_Gps_Rsp(&stMsg,FID_GPS_MODULE_TEST);
|
| 670 | break;
|
| 671 | }
|
| 672 | default:
|
| 673 | break;
|
| 674 | }
|
| 675 | }
|
| 676 | }
|
| 677 | return NULL;
|
| 678 | }
|
| 679 |
|
| 680 |
|
| 681 | /**
|
| 682 | * @brief AMTÏûÏ¢´ò°ü·¢¸øCP
|
| 683 | * @param[in] fd ÎļþÃèÊö·û
|
| 684 | * @param[in] msg_id FID
|
| 685 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 686 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 687 | * @return ³É¹¦·µ»Ø0
|
| 688 | * @note
|
| 689 | * @see
|
| 690 | */
|
| 691 | static int Amt_SendMessageToAmtagent(int fd, unsigned int msg_id, unsigned char* buf, unsigned int buf_len)
|
| 692 | {
|
| 693 | // STX TID FID Data Check ETX
|
| 694 | unsigned int CmdCount = 1 + 1 + 1 + buf_len + 1 + 1;
|
| 695 | unsigned char *pRsp = NULL;
|
| 696 | unsigned char *pSTX = NULL;
|
| 697 | unsigned char *pETX = NULL;
|
| 698 | unsigned char *pTID = NULL;
|
| 699 | unsigned char *pFID = NULL;
|
| 700 | unsigned char *pCheck = NULL;
|
| 701 | unsigned char *pData = NULL;
|
| 702 | unsigned char CheckSum = 0;
|
| 703 | unsigned int i = 0;
|
| 704 |
|
| 705 | pRsp = malloc(CmdCount);
|
| 706 | if(pRsp == NULL)
|
| 707 | return -1;
|
| 708 | memset(pRsp, 0, CmdCount);
|
| 709 |
|
| 710 | pSTX = &pRsp[0];
|
| 711 | pETX = &pRsp[1 + 1 + 1 + buf_len + 1];
|
| 712 | pTID = &pRsp[1];
|
| 713 | pFID = &pRsp[1 + 1];
|
| 714 | pCheck = &pRsp[1 + 1 + 1 + buf_len];
|
| 715 | pData = &pRsp[1 + 1 + 1];
|
| 716 |
|
| 717 | *pSTX = 0x02;
|
| 718 | *pETX = 0x02;
|
| 719 | *pTID = (msg_id & 0xFF00) >> 8;
|
| 720 | *pFID = (msg_id & 0xFF);
|
| 721 |
|
| 722 | if (buf != NULL && buf_len > 0)
|
| 723 | {
|
| 724 | memcpy(pData, buf, buf_len);
|
| 725 | }
|
| 726 |
|
| 727 | CheckSum = 0;
|
| 728 |
|
| 729 | for (i = 0; i < (1 + 1 + buf_len); i++)
|
| 730 | CheckSum ^= pRsp[1 + i];
|
| 731 |
|
| 732 | *pCheck = CheckSum;
|
| 733 |
|
| 734 | Amt_SendDataToAmtagent(fd, pRsp, CmdCount);
|
| 735 |
|
| 736 | free(pRsp);
|
| 737 | return 0;
|
| 738 | }
|
| 739 |
|
| 740 |
|
| 741 | /**
|
| 742 | * @brief AMTÏûÏ¢´ò°ü·¢¸øPC
|
| 743 | * @param[in] fd ÎļþÃèÊö·û
|
| 744 | * @param[in] msg_id FID
|
| 745 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 746 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 747 | * @return ³É¹¦·µ»Ø0
|
| 748 | * @note
|
| 749 | * @see
|
| 750 | */
|
| 751 | static int Amt_SendMessage(int fd, unsigned int msg_id, unsigned char* buf, unsigned int buf_len)
|
| 752 | {
|
| 753 | // STX TID FID Data Check ETX
|
| 754 | unsigned int CmdCount = 1 + 1 + 1 + buf_len + 1 + 1;
|
| 755 | unsigned char *pRsp = NULL;
|
| 756 | unsigned char *pSTX = NULL;
|
| 757 | unsigned char *pETX = NULL;
|
| 758 | unsigned char *pTID = NULL;
|
| 759 | unsigned char *pFID = NULL;
|
| 760 | unsigned char *pCheck = NULL;
|
| 761 | unsigned char *pData = NULL;
|
| 762 | unsigned char CheckSum = 0;
|
| 763 | unsigned int i = 0;
|
| 764 |
|
| 765 | pRsp = malloc(CmdCount);
|
| 766 | if(pRsp == NULL)
|
| 767 | return -1;
|
| 768 | memset(pRsp, 0, CmdCount);
|
| 769 |
|
| 770 | pSTX = &pRsp[0];
|
| 771 | pETX = &pRsp[1 + 1 + 1 + buf_len + 1];
|
| 772 | pTID = &pRsp[1];
|
| 773 | pFID = &pRsp[1 + 1];
|
| 774 | pCheck = &pRsp[1 + 1 + 1 + buf_len];
|
| 775 | pData = &pRsp[1 + 1 + 1];
|
| 776 |
|
| 777 | *pSTX = 0x02;
|
| 778 | *pETX = 0x02;
|
| 779 | *pTID = (msg_id & 0xFF00) >> 8;
|
| 780 | *pFID = (msg_id & 0xFF);
|
| 781 |
|
| 782 | if (buf != NULL && buf_len > 0)
|
| 783 | {
|
| 784 | memcpy(pData, buf, buf_len);
|
| 785 | }
|
| 786 |
|
| 787 | CheckSum = 0;
|
| 788 |
|
| 789 | for (i = 0; i < (1 + 1 + buf_len); i++)
|
| 790 | CheckSum ^= pRsp[1 + i];
|
| 791 |
|
| 792 | *pCheck = CheckSum;
|
| 793 |
|
| 794 | Amt_SendData(fd, pRsp, CmdCount);
|
| 795 |
|
| 796 | free(pRsp);
|
| 797 | return 0;
|
| 798 | }
|
| 799 |
|
| 800 |
|
| 801 | /**
|
| 802 | * @brief AMTÏûÏ¢´¦Àíº¯Êý
|
| 803 | * @param[in] msg_id FID
|
| 804 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 805 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 806 | * @return ³É¹¦·µ»Ø0
|
| 807 | * @note
|
| 808 | * @see
|
| 809 | */
|
| 810 | static int Amt_ProcessMessage(unsigned int msg_id, unsigned char* buf, unsigned int buf_len)
|
| 811 | {
|
| 812 | if (msg_id >= FID_WIFI_CMD_NORTN && msg_id <= FID_WIFI_CMD_END) // wifi test
|
| 813 | {
|
| 814 | Amt_Wifi_ProcessMsg(msg_id, buf, buf_len);
|
| 815 | }
|
| 816 | else if (msg_id == FID_GET_CHIP_PLATFORM)
|
| 817 | {
|
| 818 | //
|
| 819 | if(is_amt_mode())
|
| 820 | {
|
| 821 | AmtPrintf(AMT_ERROR "AMT MODE!\n");
|
| 822 | }
|
| 823 | else
|
| 824 | {
|
| 825 | AmtPrintf(AMT_ERROR "Normal MODE!\n");
|
| 826 | }
|
| 827 | unsigned char chipType = 0;
|
| 828 | AmtPrintf(AMT_INFO "%s: Get chip platform msg_id = %#04x, buf_len = %d.\n",
|
| 829 | __FUNCTION__, msg_id, buf_len);
|
| 830 | chipType = 1; /*1:7520V3 2:7100*/
|
| 831 |
|
| 832 | if (Amt_CreateResponse(msg_id, &chipType, sizeof(unsigned char)) == -1)
|
| 833 | {
|
| 834 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 835 | }
|
| 836 | else
|
| 837 | {
|
| 838 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 839 | }
|
| 840 | }
|
| 841 | else if (msg_id >= FID_GPS_MODULE_TEST && msg_id <= FID_GPS_CMD_END) // gps test
|
| 842 | {
|
| 843 | Amt_Gps_ProcessMsg(msg_id, buf, buf_len);
|
| 844 | }
|
| 845 | else if (msg_id >= MSG_DEVICETEST_START && msg_id <= MSG_DEVICETEST_END)
|
| 846 | {
|
| 847 | Amt_DeviceTest_ProcessMsg(msg_id, buf, buf_len);
|
| 848 | }
|
| 849 | else if (msg_id == FID_AMT_END)
|
| 850 | {
|
| 851 | unsigned int status = CPNV_OK;//cpnv_ChangeFsPartitionAttr(FS_NVROFS, 1);
|
| 852 | /*
|
| 853 | if(status != CPNV_OK)
|
| 854 | {
|
| 855 | AmtPrintf(AMT_ERROR "%s: cpnv_ChangeFsPartitionAttr RW nvrofs failed!\n", __FUNCTION__);
|
| 856 | return -1;
|
| 857 | }*/
|
| 858 |
|
| 859 | status = cpnv_FsGcWait(FS_NVROFS);
|
| 860 | if(status == CPNV_OK)
|
| 861 | AmtPrintf(AMT_INFO "%s: cpnv_FsGcWait ok.\n", __FUNCTION__);
|
| 862 | else
|
| 863 | AmtPrintf(AMT_INFO "%s: cpnv_FsGcWait fail, err = %d.\n", __FUNCTION__, status);
|
| 864 |
|
| 865 | if (Amt_CreateResponse(msg_id, (unsigned char*)&status, sizeof(unsigned int)) == -1)
|
| 866 | {
|
| 867 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 868 | }
|
| 869 | else
|
| 870 | {
|
| 871 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 872 | }
|
| 873 | }
|
| 874 | else if (msg_id == FID_AMT_EXIT)
|
| 875 | {
|
| 876 | unsigned int status = 0;
|
| 877 | if (Amt_CreateResponse(msg_id, (unsigned char*)&status, sizeof(unsigned int)) == -1)
|
| 878 | {
|
| 879 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 880 | }
|
| 881 | else
|
| 882 | {
|
| 883 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 884 | }
|
| 885 | }
|
| 886 | else if (msg_id == FID_EX_COMMON_SETBOOTMODE)
|
| 887 | {
|
| 888 | // set normal mode
|
| 889 | unsigned char bootmode[] = {0xFF, 0xFF};
|
| 890 | unsigned int dwRet = CPNV_OK;
|
| 891 |
|
| 892 | //struct timespec ts;
|
| 893 | //clock_gettime(CLOCK_MONOTONIC, &ts);
|
| 894 | //AmtPrintf(AMT_INFO "[%8d.%03d] %s: cpnv_FsGcWait start.\n", ts.tv_sec, ts.tv_nsec / 1000000,__FUNCTION__);
|
| 895 | unsigned char mode = 4;
|
| 896 | if(buf_len == sizeof(mode))
|
| 897 | {
|
| 898 | memcpy(&mode, buf, sizeof(mode));
|
| 899 | }
|
| 900 | AmtPrintf(AMT_INFO "%s: boot mode=%d\n", __FUNCTION__,mode);
|
| 901 | switch(mode)
|
| 902 | {
|
| 903 | case 0: //user mode
|
| 904 | {
|
| 905 | nv_set_item(NV_RO, "usb_modetype", "user", 1);
|
| 906 | nv_commit(NV_RO);
|
| 907 | bootmode[0] =0x54;
|
| 908 | bootmode[1] =0x00;
|
| 909 | break;
|
| 910 | }
|
| 911 | case 1://debug mode
|
| 912 | {
|
| 913 | nv_set_item(NV_RO, "usb_modetype", "debug", 1);
|
| 914 | nv_commit(NV_RO);
|
| 915 | bootmode[0] =0x54;
|
| 916 | bootmode[1] =0x01;
|
| 917 | break;
|
| 918 | }
|
| 919 | case 2://factory mode
|
| 920 | {
|
| 921 | nv_set_item(NV_RO, "usb_modetype", "factory", 1);
|
| 922 | nv_commit(NV_RO);
|
| 923 | bootmode[0] =0x54;
|
| 924 | bootmode[1] =0x02;
|
| 925 | break;
|
| 926 | }
|
| 927 | case 3://amt mode
|
| 928 | {
|
| 929 | //nv_set_item(NV_RO, "usb_modetype", "amt", 1);
|
| 930 | //nv_commit(NV_RO);
|
| 931 | bootmode[0] =0x54;
|
| 932 | bootmode[1] =0x4D;
|
| 933 | break;
|
| 934 | }
|
| 935 | default:
|
| 936 | {
|
| 937 | break;
|
| 938 | }
|
| 939 | }
|
| 940 |
|
| 941 | dwRet = amt_set_bootmode(bootmode);
|
| 942 | if (dwRet == CPNV_OK)
|
| 943 | {
|
| 944 | AmtPrintf(AMT_INFO "%s: set boot mode: sucess.\n", __FUNCTION__);
|
| 945 | }
|
| 946 | else
|
| 947 | {
|
| 948 | AmtPrintf(AMT_ERROR "%s: set boot mode: failed.\n", __FUNCTION__);
|
| 949 | }
|
| 950 | //clock_gettime(CLOCK_MONOTONIC, &ts);
|
| 951 | //AmtPrintf(AMT_INFO "[%8d.%03d] %s: cpnv_FsGcWait ok.\n", ts.tv_sec, ts.tv_nsec / 1000000, __FUNCTION__);
|
| 952 |
|
| 953 | if (Amt_CreateResponse(msg_id, (unsigned char*)&dwRet, sizeof(unsigned int)) == -1)
|
| 954 | {
|
| 955 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 956 | }
|
| 957 | else
|
| 958 | {
|
| 959 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 960 | }
|
| 961 | }
|
| 962 | else if(msg_id == FID_CHECK_SOFTDOG_CIPHER_TEXT)
|
| 963 | {
|
| 964 | UINT8 softdog_cipher_texts[OS_FLASH_AMT_COMM_RO_SOFTDOG_CIPHER_TEXT_SIZE] = {0};
|
| 965 | if(!amt_read_nv_item(ABSOFTDOG_CIPHER_TEXT_NVPARAM,softdog_cipher_texts,sizeof(softdog_cipher_texts)))
|
| 966 | {
|
| 967 | if (Amt_CreateResponse(msg_id, softdog_cipher_texts, sizeof(softdog_cipher_texts)) == -1)
|
| 968 | {
|
| 969 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 970 | }
|
| 971 | else
|
| 972 | {
|
| 973 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 974 | }
|
| 975 | }
|
| 976 | else
|
| 977 | {
|
| 978 | AmtPrintf(AMT_ERROR "%s: read softdog cipher text in address:0x%x failure.\n", __FUNCTION__,OS_FLASH_AMT_COMM_RO_SOFTDOG_CIPHER_TEXT_ADDRESS);
|
| 979 | }
|
| 980 | }
|
| 981 | else if(msg_id == FID_SET_BAT_DET_FLAG)
|
| 982 | {
|
| 983 | unsigned int retCode = CPNV_ERROR;
|
| 984 | int bat_value = -1;
|
| 985 | memcpy(&bat_value, buf, sizeof(int));
|
| 986 | retCode =amt_set_batdet_flag(bat_value);
|
| 987 |
|
| 988 | if (retCode == CPNV_OK)
|
| 989 | {
|
| 990 | AmtPrintf(AMT_INFO "%s: amt_set_batdet_flag success.\n", __FUNCTION__);
|
| 991 | }
|
| 992 | else
|
| 993 | {
|
| 994 | AmtPrintf(AMT_INFO "%s: amt_set_batdet_flag fail.\n", __FUNCTION__);
|
| 995 | }
|
| 996 | if (Amt_CreateResponse(msg_id, (unsigned char*)&retCode, sizeof(retCode)) == -1)
|
| 997 | {
|
| 998 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 999 | }
|
| 1000 | else
|
| 1001 | {
|
| 1002 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 1003 | }
|
| 1004 | }
|
| 1005 | else if(msg_id == FID_GET_BAT_DET_FLAG)
|
| 1006 | {
|
| 1007 | unsigned int retCode = CPNV_ERROR;
|
| 1008 | int bat_value = 0;
|
| 1009 | retCode =amt_get_batdet_flag(&bat_value);
|
| 1010 |
|
| 1011 | if (retCode == CPNV_OK)
|
| 1012 | {
|
| 1013 | AmtPrintf(AMT_INFO "%s: amt_get_batdet_flag success.bat_value=%d\n", __FUNCTION__,bat_value);
|
| 1014 | if (Amt_CreateResponse(msg_id, (unsigned char*)&bat_value, sizeof(bat_value)) == -1)
|
| 1015 | {
|
| 1016 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 1017 | }
|
| 1018 | else
|
| 1019 | {
|
| 1020 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 1021 | }
|
| 1022 | }
|
| 1023 | else
|
| 1024 | {
|
| 1025 | AmtPrintf(AMT_INFO "%s: amt_get_batdet_flag fail.\n", __FUNCTION__);
|
| 1026 | }
|
| 1027 | }
|
| 1028 | else if(msg_id == FID_RINISOFTVERSION)
|
| 1029 | {
|
| 1030 | unsigned int retCode = CPNV_ERROR;
|
| 1031 | char TmpSoftVersion[ZPS_REF_MSINFO_MAX_SOFTVERSION_INT_LEN+1]={0};
|
| 1032 |
|
| 1033 | retCode = cpnv_NvItemRead(ZPS_REF_MSINFO_SOFTVERSION_INT_BASE_ADDR, (unsigned char*)TmpSoftVersion, ZPS_REF_MSINFO_MAX_SOFTVERSION_INT_LEN);
|
| 1034 | if (retCode == CPNV_OK)
|
| 1035 | {
|
| 1036 | TmpSoftVersion[ZPS_REF_MSINFO_MAX_SOFTVERSION_INT_LEN] = '\0';
|
| 1037 | AmtPrintf(AMT_INFO "%s: inner version=%s\n", __FUNCTION__,TmpSoftVersion);
|
| 1038 | if (Amt_CreateResponse(msg_id, (unsigned char*)TmpSoftVersion, sizeof(TmpSoftVersion)) == -1)
|
| 1039 | {
|
| 1040 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 1041 | }
|
| 1042 | else
|
| 1043 | {
|
| 1044 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 1045 | }
|
| 1046 | }
|
| 1047 | else
|
| 1048 | {
|
| 1049 | AmtPrintf(AMT_INFO "%s: get inner version fail!\n", __FUNCTION__);
|
| 1050 | }
|
| 1051 | }
|
| 1052 | else if(msg_id == FID_ROUTSOFTVERSION)
|
| 1053 | {
|
| 1054 | unsigned int retCode = CPNV_ERROR;
|
| 1055 | char TmpExtcgmr[ZPS_REF_MSINFO_MAX_SOFTVERSION_EXT_LEN+1]={0};
|
| 1056 |
|
| 1057 | retCode =cpnv_NvItemRead(ZPS_REF_MSINFO_SOFTVERSION_EXT_BASE_ADDR, (unsigned char *)TmpExtcgmr, ZPS_REF_MSINFO_MAX_SOFTVERSION_EXT_LEN);
|
| 1058 | if (retCode == CPNV_OK)
|
| 1059 | {
|
| 1060 | TmpExtcgmr[ZPS_REF_MSINFO_MAX_SOFTVERSION_EXT_LEN] = '\0';
|
| 1061 | AmtPrintf(AMT_INFO "%s: outer version=%s\n", __FUNCTION__,TmpExtcgmr);
|
| 1062 | if (Amt_CreateResponse(msg_id, (unsigned char*)TmpExtcgmr, sizeof(TmpExtcgmr)) == -1)
|
| 1063 | {
|
| 1064 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 1065 | }
|
| 1066 | else
|
| 1067 | {
|
| 1068 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 1069 | }
|
| 1070 | }
|
| 1071 | else
|
| 1072 | {
|
| 1073 | AmtPrintf(AMT_INFO "%s: get outer version fail!\n", __FUNCTION__);
|
| 1074 | }
|
| 1075 | }
|
| 1076 | else if((msg_id >= FID_FUN_TEST_START)&&(msg_id <= FID_FUN_TEST_END))
|
| 1077 | {
|
| 1078 | Amt_FuncTest_ProcessMsg(msg_id, buf, buf_len);
|
| 1079 | }
|
| 1080 | else // CP message
|
| 1081 | {
|
| 1082 | AmtPrintf(AMT_INFO "%s: receive old cp msg.\n", __FUNCTION__);
|
| 1083 | // Send message to CP
|
| 1084 | if (Amt_SendMessageToAmtagent(g_amt_fd_cp, msg_id, buf, buf_len) == -1)
|
| 1085 | {
|
| 1086 | AmtPrintf(AMT_ERROR "%s: Failed to send data to cp, msg_id = %#04x, buf_len = %d.\n",
|
| 1087 | __FUNCTION__, msg_id, buf_len);
|
| 1088 | }
|
| 1089 | else
|
| 1090 | {
|
| 1091 | AmtPrintf(AMT_INFO "%s: Send data to cp, msg_id = %#04x, buf_len = %d.\n",
|
| 1092 | __FUNCTION__, msg_id, buf_len);
|
| 1093 | }
|
| 1094 | }
|
| 1095 |
|
| 1096 | return 0;
|
| 1097 | }
|
| 1098 |
|
| 1099 |
|
| 1100 | /**
|
| 1101 | * @brief AMTÏûÏ¢½â°ü
|
| 1102 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 1103 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 1104 | * @return N/A
|
| 1105 | * @note
|
| 1106 | * @see
|
| 1107 | */
|
| 1108 | static void Amt_ComposeAndProcess(unsigned char *buf, unsigned int buf_len)
|
| 1109 | {
|
| 1110 | unsigned char *pSTX = NULL;
|
| 1111 | unsigned char *pETX = NULL;
|
| 1112 | unsigned char *pTID = NULL;
|
| 1113 | unsigned char *pFID = NULL;
|
| 1114 | unsigned char *pCheck = NULL;
|
| 1115 | unsigned char *pData = NULL;
|
| 1116 | unsigned char CheckSum = 0;
|
| 1117 | unsigned int msg_id;
|
| 1118 | unsigned int i = 0;
|
| 1119 | pTID = pTID;
|
| 1120 | pCheck = pCheck;
|
| 1121 | pData = pData;
|
| 1122 |
|
| 1123 | pSTX = &buf[0];
|
| 1124 | pETX = &buf[buf_len - 1];
|
| 1125 | pTID = &buf[1];
|
| 1126 | pFID = &buf[1 + 1];
|
| 1127 | pCheck = &buf[buf_len - 2];
|
| 1128 | pData = &buf[1 + 1 + 1];
|
| 1129 |
|
| 1130 | if (!((0x02 == *pSTX) && (0x02 == *pETX)))
|
| 1131 | {
|
| 1132 | return;
|
| 1133 | }
|
| 1134 |
|
| 1135 | CheckSum = 0;
|
| 1136 |
|
| 1137 | for (i = 0; i < (buf_len - 2); i++)
|
| 1138 | CheckSum ^= buf[1 + i];
|
| 1139 |
|
| 1140 | if (CheckSum != 0)
|
| 1141 | {
|
| 1142 | return;
|
| 1143 | }
|
| 1144 |
|
| 1145 | // TIDÓëFID×éºÏʹÓÃÒÑÀ©Õ¹¹¦ÄܺÅ
|
| 1146 | msg_id = (*pTID << 8) | *pFID;
|
| 1147 |
|
| 1148 | AmtPrintf(AMT_INFO "%s: msg_id = %#04x, buf_len = %d.\n", __FUNCTION__, msg_id, buf_len);
|
| 1149 | Amt_ProcessMessage(msg_id, pFID + 1, (buf_len - 1 - 1 - 1 - 1 - 1));
|
| 1150 | }
|
| 1151 |
|
| 1152 |
|
| 1153 | /**
|
| 1154 | * @brief AMTÏûÏ¢·´À¡
|
| 1155 | * @param[in] msg_id FID
|
| 1156 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 1157 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 1158 | * @return ³É¹¦·µ»Ø0, ʧ°Ü·µ»Ø-1
|
| 1159 | * @note
|
| 1160 | * @see
|
| 1161 | */
|
| 1162 | int Amt_CreateResponse(unsigned int msg_id, unsigned char* buf, unsigned int buf_len)
|
| 1163 | {
|
| 1164 | if (g_amt_fd_current && *g_amt_fd_current >= 0)
|
| 1165 | {
|
| 1166 | return Amt_SendMessage(*g_amt_fd_current, msg_id, buf, buf_len);
|
| 1167 | }
|
| 1168 | else
|
| 1169 | {
|
| 1170 | AmtPrintf(AMT_ERROR "%s: Current fd is wrong.\n", __FUNCTION__);
|
| 1171 | return -1;
|
| 1172 | }
|
| 1173 | }
|
| 1174 |
|
| 1175 | int Amt_ExecuteCmd(char *pcmd, char *pbuffer, int len)
|
| 1176 | {
|
| 1177 | FILE *pPipe;
|
| 1178 |
|
| 1179 | AmtPrintf(AMT_INFO "%s: execute \"%s\"!\n", __FUNCTION__, pcmd);
|
| 1180 |
|
| 1181 | if ((pPipe = popen(pcmd, "rb")) == NULL)
|
| 1182 | {
|
| 1183 | AmtPrintf(AMT_ERROR "popen \"%s\" failure.\n", pcmd);
|
| 1184 | return -1;
|
| 1185 | }
|
| 1186 |
|
| 1187 | int read_len = fread(pbuffer, 1, len, pPipe);
|
| 1188 | //AmtPrintf(AMT_INFO "fread, read_len = %d, pbuffer = %s.\n", read_len, pbuffer);
|
| 1189 |
|
| 1190 | pclose(pPipe);
|
| 1191 | return read_len;
|
| 1192 | }
|
| 1193 |
|
| 1194 | static int init_cp_channel(void)
|
| 1195 | {
|
| 1196 | int fd = open(AMT_CP_CHANNEL, O_RDWR);
|
| 1197 |
|
| 1198 | if (fd < 0)
|
| 1199 | {
|
| 1200 | AmtPrintf(AMT_ERROR "Failed to open \"%s\"!\n", AMT_CP_CHANNEL);
|
| 1201 | return -1;
|
| 1202 | }
|
| 1203 |
|
| 1204 | if(ioctl(fd, RPMSG_CREATE_CHANNEL, (8*1024))!= 0) // ´´½¨Í¨µÀ´óС8K
|
| 1205 | {
|
| 1206 | AmtPrintf(AMT_ERROR "ioctrl:RPMSG_CREATE_CHANNEL fail!\n");
|
| 1207 | }
|
| 1208 | if(ioctl(fd, RPMSG_SET_INT_FLAG, NULL)!= 0) // ·¢ËÍÏûϢʱ£¬´¥·¢ÖжÏ
|
| 1209 | {
|
| 1210 | AmtPrintf(AMT_ERROR "ioctrl:RPMSG_SET_INT_FLAG fail!\n");
|
| 1211 | }
|
| 1212 | if(ioctl(fd, RPMSG_CLEAR_POLL_FLAG, NULL)!= 0) // ×èÈûµÄ·½Ê½¶Á
|
| 1213 | {
|
| 1214 | AmtPrintf(AMT_ERROR "ioctrl:RPMSG_CLEAR_POLL_FLAG fail!\n");
|
| 1215 | }
|
| 1216 | return fd;
|
| 1217 | }
|
| 1218 |
|
| 1219 | static int init_usb_device(void)
|
| 1220 | {
|
| 1221 | int fd = open(AMT_USB_DEV, O_RDWR);
|
| 1222 |
|
| 1223 | if (fd < 0)
|
| 1224 | {
|
| 1225 | AmtPrintf(AMT_ERROR "Failed to open \"%s\"!\n", AMT_USB_DEV);
|
| 1226 | return -1;
|
| 1227 | }
|
| 1228 |
|
| 1229 | PortSet(fd);
|
| 1230 | return fd;
|
| 1231 | }
|
| 1232 |
|
| 1233 | static int init_hotplug_nl(void)
|
| 1234 | {
|
| 1235 | struct sockaddr_nl snl;
|
| 1236 | bzero(&snl, sizeof(snl));
|
| 1237 | snl.nl_family = AF_NETLINK;
|
| 1238 | snl.nl_pid = getpid();
|
| 1239 | snl.nl_groups = 1;
|
| 1240 |
|
| 1241 | int s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
|
| 1242 | if (s == -1)
|
| 1243 | {
|
| 1244 | AmtPrintf(AMT_ERROR "Can't create hotplug socket!\n");
|
| 1245 | return -1;
|
| 1246 | }
|
| 1247 |
|
| 1248 | if (bind(s, (struct sockaddr *)&snl, sizeof(snl)) < 0)
|
| 1249 | {
|
| 1250 | AmtPrintf(AMT_ERROR "Can't bind hotplug socket!\n");
|
| 1251 | close(s);
|
| 1252 | return -1;
|
| 1253 | }
|
| 1254 |
|
| 1255 | return s;
|
| 1256 | }
|
| 1257 |
|
| 1258 | static int init_socket(int port)
|
| 1259 | {
|
| 1260 | struct sockaddr_in seraddr;
|
| 1261 | int sockfd = -1;
|
| 1262 |
|
| 1263 | AmtPrintf(AMT_INFO "port = %d.\n", port);
|
| 1264 |
|
| 1265 | sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
| 1266 | if (sockfd == -1)
|
| 1267 | {
|
| 1268 | AmtPrintf(AMT_ERROR "Can't create socket!\n");
|
| 1269 | return -1;
|
| 1270 | }
|
| 1271 |
|
| 1272 | memset(&seraddr,0,sizeof(seraddr));
|
| 1273 | seraddr.sin_family = AF_INET;
|
| 1274 | seraddr.sin_addr.s_addr = 0;
|
| 1275 | seraddr.sin_port = htons(port);
|
| 1276 |
|
| 1277 | if (bind(sockfd, (struct sockaddr*)(&seraddr), sizeof(seraddr)) < 0)
|
| 1278 | {
|
| 1279 | AmtPrintf(AMT_ERROR "Can't bind port %d!\n", port);
|
| 1280 | close(sockfd);
|
| 1281 | return -1;
|
| 1282 | }
|
| 1283 |
|
| 1284 | if (listen(sockfd, 1) == -1)
|
| 1285 | {
|
| 1286 | AmtPrintf(AMT_ERROR "Socket listen failed!\n");
|
| 1287 | close(sockfd);
|
| 1288 | return -1;
|
| 1289 | }
|
| 1290 |
|
| 1291 | return sockfd;
|
| 1292 | }
|
| 1293 |
|
| 1294 | static void set_fd(int fd)
|
| 1295 | {
|
| 1296 | FD_SET(fd, &g_amt_fdsread);
|
| 1297 | if (fd >= g_amt_fd_max)
|
| 1298 | {
|
| 1299 | g_amt_fd_max = fd + 1;
|
| 1300 | }
|
| 1301 | }
|
| 1302 |
|
| 1303 | static void clr_fd(int fd)
|
| 1304 | {
|
| 1305 | FD_CLR(fd, &g_amt_fdsread);
|
| 1306 | }
|
| 1307 |
|
| 1308 | static int CreateSendPacket(unsigned short fid, unsigned char *data_buf, int data_len, unsigned char*packet_buf)
|
| 1309 | {
|
| 1310 | int bRet = 0;
|
| 1311 | BYTE *pSTX = NULL;
|
| 1312 | BYTE *pETX = NULL;
|
| 1313 | //FIDµÄ¸ß×Ö½Ú
|
| 1314 | BYTE *pHFID = NULL;
|
| 1315 | //FIDµÄµÍ×Ö½Ú
|
| 1316 | BYTE *pLFID = NULL;
|
| 1317 | BYTE *pCheck = NULL;
|
| 1318 | BYTE *pData = NULL;
|
| 1319 | BYTE CheckSum = 0;
|
| 1320 | int i = 0;
|
| 1321 |
|
| 1322 | // STX FID Data Check ETX
|
| 1323 | int CmdCount = 1 + 2 + data_len + 1 + 1;
|
| 1324 |
|
| 1325 | if ((data_len != 0) && (NULL == data_buf))
|
| 1326 | {
|
| 1327 | return bRet;
|
| 1328 | }
|
| 1329 |
|
| 1330 | pSTX = &packet_buf[0];
|
| 1331 | pETX = &packet_buf[1 + 2 + data_len + 1];
|
| 1332 | pHFID = &packet_buf[1];
|
| 1333 | pLFID = &packet_buf[1+1];
|
| 1334 | pCheck = &packet_buf[1 + 2 + data_len];
|
| 1335 | pData = &packet_buf[1 + 2];
|
| 1336 |
|
| 1337 | *pSTX = 0x02;
|
| 1338 | *pETX = 0x02;
|
| 1339 | *pHFID = (fid>>8)&0x00FF;
|
| 1340 | *pLFID = fid&0x00FF;
|
| 1341 | memcpy(pData, data_buf, data_len);
|
| 1342 | CheckSum = 0;
|
| 1343 | //CheckSumÊÇFIDºÍDATA×ֶεÄУÑé
|
| 1344 | for (i = 0; i < (2 + data_len); i++)
|
| 1345 | CheckSum ^= packet_buf[1 + i];
|
| 1346 | *pCheck = CheckSum;
|
| 1347 | bRet = 1;
|
| 1348 | return bRet;
|
| 1349 | }
|
| 1350 |
|
| 1351 | static void send_enter_amt_mode_packet()
|
| 1352 | {
|
| 1353 | u32 enter_amt_req[5] = {0};
|
| 1354 | enter_amt_req[0] = 0x0100;
|
| 1355 | enter_amt_req[1] = 1;
|
| 1356 | enter_amt_req[2] = 1;
|
| 1357 | enter_amt_req[3] = 0;
|
| 1358 | enter_amt_req[4] = 0;
|
| 1359 |
|
| 1360 | unsigned char enter_amt_packet[25] = {0};
|
| 1361 | unsigned short fid = 0x005f;
|
| 1362 | CreateSendPacket(fid,(unsigned char*)enter_amt_req,sizeof(enter_amt_req),enter_amt_packet);
|
| 1363 | Amt_ComposeAndProcess(enter_amt_packet, sizeof(enter_amt_packet));
|
| 1364 | }
|
| 1365 |
|
| 1366 | static void send_exit_amt_mode_packet()
|
| 1367 | {
|
| 1368 | u32 exit_amt_req[5] = {0};
|
| 1369 | exit_amt_req[0] = 0x0100;
|
| 1370 | exit_amt_req[1] = 0;
|
| 1371 | exit_amt_req[2] = 1;
|
| 1372 | exit_amt_req[3] = 0;
|
| 1373 | exit_amt_req[4] = 0;
|
| 1374 |
|
| 1375 | unsigned char exit_amt_packet[25] = {0};
|
| 1376 | unsigned short fid = 0x005f;
|
| 1377 | CreateSendPacket(fid,(unsigned char*)exit_amt_req,sizeof(exit_amt_req),exit_amt_packet);
|
| 1378 | Amt_ComposeAndProcess(exit_amt_packet, sizeof(exit_amt_packet));
|
| 1379 |
|
| 1380 | }
|
| 1381 |
|
| 1382 |
|
| 1383 | static void send_tx_start_packet(unsigned int band,unsigned int channel,short int_power,short dec_power)
|
| 1384 | {
|
| 1385 | typedef struct
|
| 1386 | {
|
| 1387 | UINT32 MsgId;
|
| 1388 | UINT32 wBandNum; // Ƶ¶Î
|
| 1389 | UINT32 dwEarfcn;
|
| 1390 | UINT32 wFreq; // ÖÐÐÄÆµµã£¬100kHzΪµ¥Î»
|
| 1391 | UINT32 wBandWidth; // ´ø¿í£¬100kHzΪµ¥Î»
|
| 1392 | UINT32 wAntennaPort; // ÌìÏß¶Ë¿Ú £¿£¿£¿
|
| 1393 | UINT32 wModulation; // µ÷ÖÆ·½Ê½£¬0£ºQPSK£¬1£º16QAM£¬2£º64QAM
|
| 1394 | UINT32 wRBNum; // RB¸öÊý
|
| 1395 | UINT32 wRBStartPosition; // RBÆðÊ¼Æ«ÒÆ
|
| 1396 | UINT32 wSingleWave; // ÊÇ·ñΪµ¥Ôز¨
|
| 1397 | SINT16 swRfIntPower; //¹¦ÂÊÕûÊý
|
| 1398 | SINT16 swRfDecPower; //¹¦ÂÊСÊý,[-2 -1 0 1 2 ]´ú±í[-0.5 -0.25 0 0.25 0.5]
|
| 1399 | }T_zAMT_LTEA_SetTxInit_Req;
|
| 1400 |
|
| 1401 | T_zAMT_LTEA_SetTxInit_Req stTxInitReq = {0};
|
| 1402 | stTxInitReq.MsgId = 0x0700;
|
| 1403 | stTxInitReq.wBandNum = band;
|
| 1404 | stTxInitReq.dwEarfcn = channel;
|
| 1405 | stTxInitReq.wFreq = 0;
|
| 1406 | stTxInitReq.wBandWidth = 9;
|
| 1407 | stTxInitReq.wAntennaPort = 0;
|
| 1408 | stTxInitReq.wModulation = 0;
|
| 1409 | stTxInitReq.wRBNum = 50;
|
| 1410 | stTxInitReq.wRBStartPosition = 0;
|
| 1411 | stTxInitReq.wSingleWave = 0;
|
| 1412 | stTxInitReq.swRfIntPower = int_power;
|
| 1413 | stTxInitReq.swRfDecPower = dec_power;
|
| 1414 |
|
| 1415 | unsigned char tx_start_packet[sizeof(stTxInitReq)+5] = {0};
|
| 1416 | unsigned short fid = 0x005f;
|
| 1417 | CreateSendPacket(fid,(unsigned char*)&stTxInitReq,sizeof(stTxInitReq),tx_start_packet);
|
| 1418 | Amt_ComposeAndProcess(tx_start_packet, sizeof(tx_start_packet));
|
| 1419 |
|
| 1420 | }
|
| 1421 |
|
| 1422 | static void send_tx_stop_packet()
|
| 1423 | {
|
| 1424 | u32 tx_close_req[1] = {0};
|
| 1425 | tx_close_req[0] = 0x0201;
|
| 1426 | unsigned char tx_stop_packet[1*4+5] = {0};
|
| 1427 | unsigned short fid = 0x005f;
|
| 1428 | CreateSendPacket(fid,(unsigned char*)tx_close_req,sizeof(tx_close_req),tx_stop_packet);
|
| 1429 | Amt_ComposeAndProcess(tx_stop_packet, sizeof(tx_stop_packet));
|
| 1430 |
|
| 1431 | }
|
| 1432 |
|
| 1433 | static void send_switch_to_user_mode_packet()
|
| 1434 | {
|
| 1435 | unsigned char bootmode[] = {0x54, 0x00};
|
| 1436 | unsigned char atmode[] = {0xFF, 0xFF};
|
| 1437 | nv_set_item(NV_RO, "usb_modetype", "user", 1);
|
| 1438 | nv_commit(NV_RO);
|
| 1439 | amt_set_amt_atmode(bootmode,atmode);
|
| 1440 | }
|
| 1441 |
|
| 1442 | static void send_ok(int fd)
|
| 1443 | {
|
| 1444 | char rep_ok[] = "OK\r\n";
|
| 1445 | PortSend(fd, (unsigned char*)rep_ok, strlen(rep_ok), WAIT_ALL);
|
| 1446 | }
|
| 1447 |
|
| 1448 | /**
|
| 1449 | * @brief ATÃüÁî½ÓÊÕ
|
| 1450 | * @param[in] fd ÎļþÃèÊö·û
|
| 1451 | * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
|
| 1452 | * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 1453 | * @return ·µ»Ø½ÓÊÕµ½µÄÊý¾Ý³¤¶È
|
| 1454 | * @note
|
| 1455 | * @see
|
| 1456 | */
|
| 1457 | static int At_ReceiveData(int fd, char* buf, unsigned int buf_len)
|
| 1458 | {
|
| 1459 | int read_len = 0;
|
| 1460 | int i = 0;
|
| 1461 | read_len = PortRecv(fd, buf, 100, NO_WAIT);
|
| 1462 | AmtPrintf(AMT_INFO "%s: read_len=%d.\n", __FUNCTION__, read_len);
|
| 1463 | if (read_len > 0)
|
| 1464 | {
|
| 1465 | buf[read_len] = '\0';
|
| 1466 | AmtPrintf(AMT_INFO "%s: receive [%s]\n", __FUNCTION__, buf);
|
| 1467 | //ת»»ÎªÐ¡Ð´
|
| 1468 | for(i = 0; i < read_len; i++)
|
| 1469 | {
|
| 1470 | char at = tolower(buf[i]);
|
| 1471 | buf[i] = at;
|
| 1472 | }
|
| 1473 | AmtPrintf(AMT_INFO "%s: after tolower [%s]\n", __FUNCTION__, buf);
|
| 1474 | //at+txstart=band,channel,power
|
| 1475 | if(strstr(buf,"at+txstart") != NULL)
|
| 1476 | {
|
| 1477 | AmtPrintf(AMT_INFO "%s: receive at+txstart\n", __FUNCTION__);
|
| 1478 | double data[3] = {0.0};
|
| 1479 | unsigned int band = 0;
|
| 1480 | unsigned int channel = 0;
|
| 1481 | short int_power = 0;
|
| 1482 | short idec_power = 0;
|
| 1483 | double dec_power = 0.0;
|
| 1484 | //»ñÈ¡²ÎÊý
|
| 1485 | buf = buf + strlen("at+txstart=");
|
| 1486 | if(buf != NULL)
|
| 1487 | {
|
| 1488 | str_to_double(data,buf);
|
| 1489 | band = data[0];
|
| 1490 | channel = data[1];
|
| 1491 | int_power = data[2];
|
| 1492 | dec_power = data[2] - int_power;
|
| 1493 | idec_power = dec_power*4;
|
| 1494 | AmtPrintf(AMT_INFO "%s: band=%d,channel=%d,int_power=%d,dec_power=%f,idec_power=%d\n", __FUNCTION__, band,channel,int_power,dec_power,idec_power);
|
| 1495 | if(band == 0)
|
| 1496 | {
|
| 1497 | AmtPrintf(AMT_ERROR "%s: invalid band!\n", __FUNCTION__);
|
| 1498 | return read_len;
|
| 1499 |
|
| 1500 | }
|
| 1501 | if(channel == 0 )
|
| 1502 | {
|
| 1503 | AmtPrintf(AMT_ERROR "%s: invalid channel!\n", __FUNCTION__);
|
| 1504 | return read_len;
|
| 1505 | }
|
| 1506 | }
|
| 1507 | //ת»¯Îª½øÈëamtģʽºÍtxinitÁ½ÌõAMTÖ¸Áî
|
| 1508 | send_enter_amt_mode_packet();
|
| 1509 | sleep(1);
|
| 1510 | send_tx_start_packet(band,channel,int_power,idec_power);
|
| 1511 | send_ok(fd); //Ö±½Ó¸øATÃüÁî·¢ËÍÕ߻ظ´ok
|
| 1512 |
|
| 1513 | }
|
| 1514 | else if(strstr(buf,"at+txstop") != NULL)
|
| 1515 | {
|
| 1516 | //ת»¯Îª¹Ø±Õ·¢Éä»úºÍÍ˳öamtģʽÁ½ÌõAMTÖ¸Áî
|
| 1517 | send_tx_stop_packet();
|
| 1518 | sleep(1);
|
| 1519 | send_exit_amt_mode_packet();
|
| 1520 | send_ok(fd);
|
| 1521 | }
|
| 1522 | else if(strstr(buf,"at+zversiontype=3") != NULL)
|
| 1523 | {
|
| 1524 | send_switch_to_user_mode_packet();
|
| 1525 | send_ok(fd);
|
| 1526 | }
|
| 1527 | else
|
| 1528 | {
|
| 1529 | AmtPrintf(AMT_ERROR "%s: unknown at %s.\n", __FUNCTION__, buf);
|
| 1530 | }
|
| 1531 | }
|
| 1532 | else
|
| 1533 | {
|
| 1534 | AmtPrintf(AMT_ERROR "%s: PortRecv from device(fd = %d): read_len(%d) is wrong.\n", __FUNCTION__, fd, read_len);
|
| 1535 | }
|
| 1536 |
|
| 1537 | return read_len;
|
| 1538 | }
|
| 1539 |
|
| 1540 | /**
|
| 1541 | * Main Function
|
| 1542 | */
|
| 1543 | int main (int argc, char *argv[])
|
| 1544 | {
|
| 1545 | extern char *optarg;
|
| 1546 | extern int optind;
|
| 1547 | int c;
|
| 1548 | int socket_port = -1;
|
| 1549 |
|
| 1550 | /********************** Get arguments ********************/
|
| 1551 | while ((c = getopt(argc,argv,"p:r:")) != EOF)
|
| 1552 | {
|
| 1553 | switch (c)
|
| 1554 | {
|
| 1555 | case 'p':
|
| 1556 | socket_port = atoi(optarg);
|
| 1557 | break;
|
| 1558 | case '?':
|
| 1559 | AmtPrintf(AMT_INFO "Usage: zte_amt [options]\n");
|
| 1560 | AmtPrintf(AMT_INFO "-p ipport - Set IP port number to listen on\n");
|
| 1561 | exit(1);
|
| 1562 | }
|
| 1563 | }
|
| 1564 |
|
| 1565 | AmtPrintf(AMT_INFO "start AMT!\n");
|
| 1566 |
|
| 1567 | FD_ZERO(&g_amt_fdsread);
|
| 1568 |
|
| 1569 | /********************** Init AP-CP channel ********************/
|
| 1570 | g_amt_fd_cp = init_cp_channel();
|
| 1571 | if (g_amt_fd_cp < 0)
|
| 1572 | {
|
| 1573 | return -1;
|
| 1574 | }
|
| 1575 | else
|
| 1576 | {
|
| 1577 | AmtPrintf(AMT_INFO "g_amt_fd_cp = %d.\n", g_amt_fd_cp);
|
| 1578 | }
|
| 1579 |
|
| 1580 | /********************** Init USB device ***********************/
|
| 1581 | g_amt_fd_usb = init_usb_device();
|
| 1582 | if (g_amt_fd_usb >= 0)
|
| 1583 | {
|
| 1584 | AmtPrintf(AMT_INFO "g_amt_fd_usb = %d.\n", g_amt_fd_usb);
|
| 1585 | set_fd(g_amt_fd_usb);
|
| 1586 |
|
| 1587 | //Init hotplug netlink
|
| 1588 | g_amt_fd_usb_hotplug = init_hotplug_nl();
|
| 1589 | if (g_amt_fd_usb_hotplug >= 0)
|
| 1590 | {
|
| 1591 | AmtPrintf(AMT_INFO "g_amt_fd_usb_hotplug = %d.\n", g_amt_fd_usb_hotplug);
|
| 1592 | set_fd(g_amt_fd_usb_hotplug);
|
| 1593 | }
|
| 1594 | }
|
| 1595 |
|
| 1596 | /*********************** Create socket ***********************/
|
| 1597 | if (socket_port > 0)
|
| 1598 | {
|
| 1599 | g_amt_fd_socket_server = init_socket(socket_port);
|
| 1600 | if (g_amt_fd_socket_server >= 0)
|
| 1601 | {
|
| 1602 | AmtPrintf(AMT_INFO "g_amt_fd_socket_server = %d.\n", g_amt_fd_socket_server);
|
| 1603 | set_fd(g_amt_fd_socket_server);
|
| 1604 | }
|
| 1605 | }
|
| 1606 |
|
| 1607 | // Create CP read thread
|
| 1608 | pthread_t cp_read_thread;
|
| 1609 | if (pthread_create(&cp_read_thread, NULL, ReadFromCPThread, NULL) != 0)
|
| 1610 | {
|
| 1611 | AmtPrintf(AMT_ERROR "Failed to create CP read thread!\n");
|
| 1612 | return -1;
|
| 1613 | }
|
| 1614 |
|
| 1615 | // Wifi init
|
| 1616 | Amt_Wifi_Init();
|
| 1617 | g_amt_iMsgHandle = msgget(MODULE_ID_AMT, IPC_CREAT|0600);
|
| 1618 | if(-1 == g_amt_iMsgHandle)
|
| 1619 | {
|
| 1620 | AmtPrintf(AMT_ERROR "%s: can not create msg queue for AMT!\n", __FUNCTION__);
|
| 1621 | return -1;
|
| 1622 | }
|
| 1623 |
|
| 1624 | pthread_t msg_recv_thread;
|
| 1625 | if (pthread_create(&msg_recv_thread, NULL, RecvMsgFromAppThread, NULL) != 0)
|
| 1626 | {
|
| 1627 | AmtPrintf(AMT_ERROR "Failed to create RecvMsgFromAppThread thread!\n");
|
| 1628 | return -1;
|
| 1629 | }
|
| 1630 | // malloc receive buffer
|
| 1631 | char *receive_buffer = malloc(MAX_PACKET_LENGTH);
|
| 1632 | if (receive_buffer == NULL)
|
| 1633 | {
|
| 1634 | return -1;
|
| 1635 | }
|
| 1636 |
|
| 1637 | int ret = -1;
|
| 1638 | int read_len = 0;
|
| 1639 | fd_set tmpfds;
|
| 1640 |
|
| 1641 | ret = cpnv_ChangeFsPartitionAttr(FS_NVROFS, 1);
|
| 1642 | if(ret != CPNV_OK)
|
| 1643 | {
|
| 1644 | AmtPrintf(AMT_ERROR "%s: cpnv_ChangeFsPartitionAttr RW nvrofs failed!\n", __FUNCTION__);
|
| 1645 | return -1;
|
| 1646 | }
|
| 1647 | else
|
| 1648 | {
|
| 1649 | AmtPrintf(AMT_INFO"%s: cpnv_ChangeFsPartitionAttr RW nvrofs ok!\n", __FUNCTION__);
|
| 1650 | }
|
| 1651 |
|
| 1652 | //¼ÓÔØaic8800¹Ì¼þ
|
| 1653 | #if (defined(__AIC_8800DW_CHIP__))
|
| 1654 | ret = wifi_ioctl_handle(3); //¼ÓÔØ²âÊԹ̼þ
|
| 1655 | if(ret < 0)
|
| 1656 | {
|
| 1657 | AmtPrintf(AMT_ERROR "%s: load AIC_8800DW firmware fail! ret=%d.\n", __FUNCTION__, ret);
|
| 1658 | }
|
| 1659 | else
|
| 1660 | {
|
| 1661 | AmtPrintf(AMT_INFO "%s: load AIC_8800DW firmware success! ret=%d.\n", __FUNCTION__, ret);
|
| 1662 | }
|
| 1663 | #endif
|
| 1664 |
|
| 1665 | g_amt_at_mode = is_amt_atmode();
|
| 1666 | AmtPrintf(AMT_INFO"%s: g_amt_at_mode=%d\n", __FUNCTION__,g_amt_at_mode);
|
| 1667 |
|
| 1668 | while (1)
|
| 1669 | {
|
| 1670 | tmpfds = g_amt_fdsread;
|
| 1671 | ret = select(g_amt_fd_max, &tmpfds, NULL, NULL, NULL);
|
| 1672 | if (ret <= 0)
|
| 1673 | {
|
| 1674 | AmtPrintf(AMT_ERROR "select error: %s!\n", strerror(errno));
|
| 1675 | continue;
|
| 1676 | }
|
| 1677 |
|
| 1678 | if (g_amt_fd_usb_hotplug >= 0 && FD_ISSET(g_amt_fd_usb_hotplug, &tmpfds))
|
| 1679 | {
|
| 1680 | read_len = PortRecv(g_amt_fd_usb_hotplug, (unsigned char *)receive_buffer, MAX_PACKET_LENGTH - 1, NO_WAIT);
|
| 1681 | if(read_len >= 0)
|
| 1682 | receive_buffer[read_len] = '\0';
|
| 1683 |
|
| 1684 | // Ç¿ÖÆÔö¼Ó½áÊø·û, read_len < MAX_PACKET_LENGTH
|
| 1685 | receive_buffer[MAX_PACKET_LENGTH - 1] = '\0';
|
| 1686 |
|
| 1687 | if (strstr(receive_buffer, AMT_DETECT_USB_HOTREMOVE))
|
| 1688 | {
|
| 1689 | AmtPrintf(AMT_INFO "USB remove!\n");
|
| 1690 | system("poweroff");
|
| 1691 | break;
|
| 1692 | }
|
| 1693 |
|
| 1694 | if (strstr(receive_buffer, AMT_DETECT_USB_OFFLINE))
|
| 1695 | {
|
| 1696 | AmtPrintf(AMT_INFO "USB offline!\n");
|
| 1697 |
|
| 1698 | if (g_amt_fd_usb >= 0)
|
| 1699 | {
|
| 1700 | close(g_amt_fd_usb);
|
| 1701 | clr_fd(g_amt_fd_usb);
|
| 1702 | g_amt_fd_usb = -1;
|
| 1703 | }
|
| 1704 | }
|
| 1705 |
|
| 1706 | if (strstr(receive_buffer, AMT_DETECT_USB_ONLINE))
|
| 1707 | {
|
| 1708 | AmtPrintf(AMT_INFO "USB online!\n");
|
| 1709 |
|
| 1710 | if (g_amt_fd_usb >= 0)
|
| 1711 | {
|
| 1712 | close(g_amt_fd_usb);
|
| 1713 | clr_fd(g_amt_fd_usb);
|
| 1714 | g_amt_fd_usb = -1;
|
| 1715 | }
|
| 1716 |
|
| 1717 | g_amt_fd_usb = init_usb_device();
|
| 1718 | if (g_amt_fd_usb >= 0)
|
| 1719 | {
|
| 1720 | AmtPrintf(AMT_INFO "g_amt_fd_usb = %d.\n", g_amt_fd_usb);
|
| 1721 | set_fd(g_amt_fd_usb);
|
| 1722 | }
|
| 1723 | }
|
| 1724 | }
|
| 1725 |
|
| 1726 | if (g_amt_fd_socket_server >= 0 && FD_ISSET(g_amt_fd_socket_server, &tmpfds))
|
| 1727 | {
|
| 1728 | struct sockaddr_in cliaddr;
|
| 1729 | int addrlen = sizeof(cliaddr);
|
| 1730 |
|
| 1731 | if (g_amt_fd_socket_client >= 0)
|
| 1732 | {
|
| 1733 | close(g_amt_fd_socket_client);
|
| 1734 | clr_fd(g_amt_fd_socket_client);
|
| 1735 | g_amt_fd_socket_client = -1;
|
| 1736 | }
|
| 1737 |
|
| 1738 | if ((g_amt_fd_socket_client = accept(g_amt_fd_socket_server, (struct sockaddr*)&cliaddr, (socklen_t *)&addrlen)) == -1)
|
| 1739 | {
|
| 1740 | AmtPrintf(AMT_ERROR "Accept failed!\n");
|
| 1741 | }
|
| 1742 | else
|
| 1743 | {
|
| 1744 | unsigned long ip = ntohl(cliaddr.sin_addr.s_addr);
|
| 1745 | AmtPrintf(AMT_INFO "Connect from %lu.%lu.%lu.%lu\n", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, (ip>>0)&0xff);
|
| 1746 | set_fd(g_amt_fd_socket_client);
|
| 1747 | }
|
| 1748 | }
|
| 1749 |
|
| 1750 | if (g_amt_fd_usb >= 0 && FD_ISSET(g_amt_fd_usb, &tmpfds))
|
| 1751 | {
|
| 1752 | g_amt_fd_current = &g_amt_fd_usb;
|
| 1753 | }
|
| 1754 | else if (g_amt_fd_socket_client >= 0 && FD_ISSET(g_amt_fd_socket_client, &tmpfds))
|
| 1755 | {
|
| 1756 | g_amt_fd_current = &g_amt_fd_socket_client;
|
| 1757 | }
|
| 1758 | else
|
| 1759 | {
|
| 1760 | continue;
|
| 1761 | }
|
| 1762 |
|
| 1763 | //¶ÁNVÅжÏÊÇ·ñÊǽâÎöATÃüÁʽ
|
| 1764 | if(g_amt_at_mode == 1)
|
| 1765 | {
|
| 1766 | //½âÎö²¢´¦ÀíATÃüÁî
|
| 1767 | At_ReceiveData(*g_amt_fd_current, receive_buffer, MAX_PACKET_LENGTH);
|
| 1768 | continue;
|
| 1769 | }
|
| 1770 |
|
| 1771 | read_len = Amt_ReceiveData(*g_amt_fd_current, (unsigned char *)receive_buffer, MAX_PACKET_LENGTH);
|
| 1772 |
|
| 1773 | if (read_len > 0)
|
| 1774 | {
|
| 1775 | Amt_ComposeAndProcess((unsigned char *)receive_buffer, read_len);
|
| 1776 | }
|
| 1777 | else if (read_len == 0)
|
| 1778 | {
|
| 1779 | AmtPrintf(AMT_ERROR "%s: read_len = 0, close fd(%d)\n", __FUNCTION__, *g_amt_fd_current);
|
| 1780 | close(*g_amt_fd_current);
|
| 1781 | clr_fd(*g_amt_fd_current);
|
| 1782 | *g_amt_fd_current = -1;
|
| 1783 | g_amt_fd_current = NULL;
|
| 1784 | }
|
| 1785 |
|
| 1786 |
|
| 1787 | //struct timespec ts;
|
| 1788 | //clock_gettime(CLOCK_MONOTONIC, &ts);
|
| 1789 | //AmtPrintf(AMT_INFO "[%8d.%03d] %s: cpnv_FsGcWait start.\n", ts.tv_sec, ts.tv_nsec / 1000000,__FUNCTION__);
|
| 1790 | //unsigned int status = cpnv_FsGcWait(FS_NVROFS);
|
| 1791 | //if(status != CPNV_OK)
|
| 1792 | // AmtPrintf(AMT_INFO "%s: cpnv_FsGcWait fail, err = %d.\n", __FUNCTION__, status);
|
| 1793 | //else
|
| 1794 | //{
|
| 1795 | // clock_gettime(CLOCK_MONOTONIC, &ts);
|
| 1796 | // AmtPrintf(AMT_INFO "[%8d.%03d] %s: cpnv_FsGcWait ok.\n", ts.tv_sec, ts.tv_nsec / 1000000, __FUNCTION__);
|
| 1797 | //}
|
| 1798 |
|
| 1799 | }
|
| 1800 |
|
| 1801 | free(receive_buffer);
|
| 1802 | pthread_join(cp_read_thread, NULL);
|
| 1803 | #if 1
|
| 1804 | cpnv_FsGcWait(FS_NVROFS);
|
| 1805 | AmtPrintf(AMT_INFO "%s: cpnv_FsGcWait return.\n", __FUNCTION__);
|
| 1806 |
|
| 1807 | ret = cpnv_ChangeFsPartitionAttr(FS_NVROFS, 0);
|
| 1808 | if(ret != CPNV_OK)
|
| 1809 | {
|
| 1810 | AmtPrintf(AMT_ERROR "%s: cpnv_ChangeFsPartitionAttr RO nvrofs failed!\n", __FUNCTION__);
|
| 1811 | return -1;
|
| 1812 | }
|
| 1813 | #endif
|
| 1814 | close(g_amt_fd_cp);
|
| 1815 |
|
| 1816 | if (g_amt_fd_usb >= 0)
|
| 1817 | {
|
| 1818 | close(g_amt_fd_usb);
|
| 1819 | }
|
| 1820 |
|
| 1821 | //if (g_amt_fd_usb_hotplug >= 0)
|
| 1822 | {
|
| 1823 | close(g_amt_fd_usb_hotplug);
|
| 1824 | }
|
| 1825 |
|
| 1826 | if (g_amt_fd_socket_client >= 0)
|
| 1827 | {
|
| 1828 | close(g_amt_fd_socket_client);
|
| 1829 | }
|
| 1830 |
|
| 1831 | if (g_amt_fd_socket_server >= 0)
|
| 1832 | {
|
| 1833 | close(g_amt_fd_socket_server);
|
| 1834 | }
|
| 1835 |
|
| 1836 | AmtPrintf(AMT_INFO "AMT exit!\n");
|
| 1837 | return 0;
|
| 1838 | }
|
| 1839 |
|