blob: 7b382d8f10271b18eb3bc678d2746c7952a637b0 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10/* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35#include <vendor-ril/telephony/ril.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <cutils/jstring.h>
39#include <log/log.h>
40#include <unistd.h>
41#include <math.h>
42#include "common.h"
43#include "em/em.h"
44#include "Radio_capability_switch_util.h"
45
46#if EM_MODE_SUPPORT
47
48#undef LOG_TAG
49#define LOG_TAG "EM_CFU"
50
51const int QUERY = 3;
52const int SET_DEFAULT = 0;
53const int SET_ON = 2;
54const int SET_OFF = 1;
55#define CFU_QUERY_CMD "AT+ESSP?"
56#define CFU_SET_CMD "AT+ESSP="
57int mCurrentEmcfuFlag = 0;
58int cfumode = -1;
59
60void sendATCommand_ecfu(const char *cmd,int msg)
61{
62 mCurrentEmcfuFlag = msg;
63 emSendATCommand(cmd, Radio_capability_switch_util::get_main_capability_phone_id());
64 return ;
65}
66
67void emCfuAtCmdHandle(char*response, int responselen) {
68 switch (mCurrentEmcfuFlag) {
69 case QUERY:
70 {
71 //parse hspa mode.
72 if ((responselen > 0) && (response != NULL)) {
73 RLOGD("emCfuAtCmdHandle QUERY response: %s\n",response);
74 }
75 else {
76 RLOGD("send fail ");
77 }
78 android::unregisterNetwork();
79 android::emResultNotify(RET_STRING_CFU_SUCCESS);
80 break;
81 }
82 case SET_DEFAULT:
83 {
84 if ((responselen > 0) && (response != NULL)) {
85 RLOGD("Set default success: %s.\n",response);
86 }
87 else {
88 RLOGD("send fail ");
89 }
90 break;
91 }
92 case SET_ON:
93 {
94 if ((responselen > 0) && (response != NULL)) {
95 RLOGD("Set on success: %s.\n",response);
96 }
97 else {
98 RLOGD("send fail ");
99 }
100 break;
101 }
102 case SET_OFF:
103 {
104 if ((responselen > 0) && (response != NULL)) {
105 RLOGD("Set off success: %s.\n",response);
106 }
107 else {
108 RLOGD("send fail ");
109 }
110 break;
111 }
112 default:
113 break;
114 }
115}
116
117
118//create thread to send command
119void * emCfuThread(void* arg)
120{
121 char cmd_str[32] = {0};
122 sprintf(cmd_str,"%s%d", CFU_SET_CMD,cfumode);
123 sendATCommand_ecfu(cmd_str,cfumode);
124 sendATCommand_ecfu(CFU_QUERY_CMD,QUERY);
125 pthread_exit(0);
126}
127
128int emCfuStart(int argc, int *item)
129{
130 RLOGD("emCfuStart called");
131 if(argc < 1)
132 {
133 RLOGD("emCfuStart: please select mode to test: \
134 0: default, 1: set on 2: set off");
135 android::emResultNotify(RET_STRING_CFU_FAIL);
136 return -1;
137 }
138 if((item[0] > 2 ) || (item[0] < 0)){
139 RLOGD("emCfuStart: invalid parameter %d",item[0]);
140 android::emResultNotify(RET_STRING_CFU_FAIL);
141 return -1;
142 }
143 int cfumapping[3] = {SET_DEFAULT,SET_ON,SET_OFF};
144 mCurrentEmcfuFlag = 0;
145 cfumode = cfumapping[item[0]];
146 android::registerForATcmdResponse(emCfuAtCmdHandle);
147 pthread_t emcfu_thread;
148 pthread_create(&emcfu_thread,NULL, emCfuThread, NULL);
149 return (0);
150}
151
152#endif
153