blob: 6407939d997008420832292af735b9dfecb3aa4a [file] [log] [blame]
xjde81d1d2021-11-25 15:01:52 +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 "stateManager/stateManager.h"
36
37#include <string>
38#include <alloca.h>
39#include <stdlib.h>
40#include <vector>
41#include <arpa/inet.h>
42#include <string.h>
43
44#include "../util/AtLine.h"
45#include "powerManager.h"
46#include "util/utils.h"
47
48#undef LOG_TAG
49#define LOG_TAG "DEMO_MANAGER"
50
51//RIL_REQUEST_DEVICE_IDENTITY
52int getDeviceIdentity(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
53{
54 android::Parcel p;
55 pRI->pCI->dispatchFunction(p, pRI);
56 return 0;
57}
58// RIL_REQUEST_GET_IMEI
59int getIMEI(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
60{
61 android::Parcel p;
62 pRI->pCI->dispatchFunction(p, pRI);
63 return 0;
64}
65
66//RIL_REQUEST_GET_IMEISV
67int getIMEISV(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
68{
69 android::Parcel p;
70 pRI->pCI->dispatchFunction(p, pRI);
71 return 0;
72}
73
74//RIL_REQUEST_BASEBAND_VERSION
75int getBasebandVersion(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
76{
77 android::Parcel p;
78 pRI->pCI->dispatchFunction(p, pRI);
79 return 0;
80}
81
82//RIL_REQUEST_RESET_RADIO
83int resetRadio(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
84{
85 android::Parcel p;
86 pRI->pCI->dispatchFunction(p, pRI);
87 return 0;
88}
89
90//RIL_REQUEST_SCREEN_STATE
91int getScreenState(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
92{
93 android::Parcel p;
94 size_t pos = p.dataPosition();
95
96 p.writeInt32(1);
97 p.writeInt32(atoi(argv[1]));
98
99 p.setDataPosition(pos);
100 pRI->pCI->dispatchFunction(p, pRI);
101 return 0;
102}
103
104//RIL_REQUEST_SET_TRM
105int setTRM(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
106{
107// android::Parcel p;
108
109// pRI->pCI->dispatchFunction(p, pRI);
110 free(pRI);
111 return 0;
112}
113//RIL_REQUEST_SET_IMS_ENABLE
114int setIMSEnable(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
115{
116 android::Parcel p;
117 size_t pos = p.dataPosition();
118
119 p.writeInt32(1);
120 p.writeInt32(atoi(argv[1]));
121 p.setDataPosition(pos);
122 pRI->pCI->dispatchFunction(p, pRI);
123 return 0;
124}
125//RIL_REQUEST_OEM_HOOK_RAW
126int sendATCMD(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
127{
128 android::Parcel p;
129 char *cmd = (char *)argv[1];
130 size_t pos = p.dataPosition();
131 if (cmd == NULL){
132 RLOGD("sendATCMD:cmd is null\n");
133 free(pRI);
134 return -1;
135 }
136 int len = strlen(cmd);
137 p.writeInt32(len);
138 p.write((const void*)cmd,len);
139 RLOGD("sendATCMD: %s %d",cmd,strlen(cmd));
140
141 p.setDataPosition(pos);
142 pRI->pCI->dispatchFunction(p, pRI);
143 return 0;
144}
145#ifdef KEEP_ALIVE
146//RIL_REQUEST_START_KEEPALIVE_PRO
147void tranferToNetByteOrder(int type, char* addr, std::vector<uint8_t> & dest) {
148 RLOGD("type is %d, addr: %s", type ,addr);
149 int ret;
150 int len = 0;
151 int domain;
152 if(type == static_cast<int>(RIL_PacketType::IPV4_TCP) || type == static_cast<int>(RIL_PacketType::IPV4_UDP)) {
153 len = sizeof(struct in_addr);
154 domain = AF_INET;
155 } else if(type == static_cast<int>(RIL_PacketType::IPV6_TCP) || type == static_cast<int>(RIL_PacketType::IPV6_UDP)) {
156 int len = sizeof(struct in6_addr);
157 domain = AF_INET6;
158 }
159 if (len > 0) {
160 unsigned char buf[len];
161 ret = inet_pton(domain, addr, &buf);
162 if (ret <= 0) {
163 if (ret == 0)
164 RLOGE("Not in presentation format");
165 else
166 RLOGE("inet_pton");
167 return;
168 }
169 for (int i = 0 ; i < len; i++ ) {
170 dest.push_back(buf[i]);
171 RLOGD("tranferToNetByteOrder[%d]: %d", i,buf[i]);
172 }
173 }
174
175}
176
177int startKeepAlivePro(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
178 if (argc != 10){
179 RLOGD("startKeepAlivePro parameters number isn't enough");
180 free(pRI);
181 return -1;
182 }
183 RLOGD("startKeepAlivePro");
184 std::vector<uint8_t> sourceAddress;
185 std::vector<uint8_t> destinationAddress;
186 int type = atoi(argv[1]);
187 tranferToNetByteOrder(type, argv[2], sourceAddress);
188 int sourcePort = atoi(argv[3]);
189 tranferToNetByteOrder(type, argv[4], destinationAddress);
190 int destinationPort = atoi(argv[5]);
191 int netif_id = atoi(argv[6]);
192 int keepIdleTime = atoi(argv[7]);
193 int keepIntervalTime = atoi(argv[8]);
194 int retryCount = atoi(argv[9]);
195
196 android::Parcel p;
197 size_t pos = p.dataPosition();
198
199 p.writeInt32(type);
200 p.writeByteVector(sourceAddress);
201 p.writeInt32(sourcePort);
202 p.writeByteVector(destinationAddress);
203 p.writeInt32(destinationPort);
204 p.writeInt32(netif_id);
205 p.writeInt32(keepIdleTime);
206 p.writeInt32(keepIntervalTime);
207 p.writeInt32(retryCount);
208
209 p.setDataPosition(pos);
210 pRI->pCI->dispatchFunction(p, pRI);
211 return 0;
212}
213
214//RIL_REQUEST_STOP_KEEPALIVE_PRO
215int stopKeepAlivePro(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
216 if (argc != 2){
217 RLOGD("stopKeepAlivePro parameters number isn't enough");
218 free(pRI);
219 return -1;
220 }
221 RLOGD("stopKeepAlivePro");
222 android::Parcel p;
223 uint32_t id = atoi(argv[1]);
224 RLOGD("stopKeepAlivePro sesssion id:%d", id);
225 size_t pos = p.dataPosition();
226 p.writeInt32(1);
227 p.writeInt32(id);
228
229 p.setDataPosition(pos);
230 pRI->pCI->dispatchFunction(p, pRI);
231 return 0;
232}
233
234void composeMsg(int request,const void* data, size_t datalen) {
235 int* p_int = (int*) (data);
236 int numInts = datalen / sizeof(int);
237 if (numInts < 2) {
238 RLOGD("%s error.", android::requestToString(request));
239 std::string fail(android::requestToString(request));
240 fail.append(",fail");
241 sendKeepAlive(fail.c_str());
242 return;
243 }
244 std::string msg(android::requestToString(request));
245 if(request == RIL_REQUEST_START_KEEPALIVE_PRO) {
246 msg.append(",ok");
247 }
248 int sessionHandle = p_int[0];
249 int code = p_int[1];
250 msg.append(",");
251 msg.append(std::to_string(sessionHandle));
252 msg.append(",");
253 msg.append(std::to_string(code));
254 RLOGD("%s response(%s)", android::requestToString(request),msg.c_str());
255 sendKeepAlive(msg.c_str());
256}
257
258void handleKeepAliveResponse(int request, const void* data, size_t datalen, RIL_SOCKET_ID soc_id, bool is_error) {
259 RLOGD("handleKeepAliveResponse(%s) is_error: %d", android::requestToString(request),is_error);
260 if(is_error) {
261 if(request == RIL_REQUEST_START_KEEPALIVE_PRO) {
262 sendKeepAlive("RIL_REQUEST_START_KEEPALIVE_PRO,fail");
263 } else if(request == RIL_REQUEST_STOP_KEEPALIVE_PRO) {
264 sendKeepAlive("RIL_REQUEST_STOP_KEEPALIVE_PRO,fail");
265 }
266 } else {
267 if(request == RIL_REQUEST_START_KEEPALIVE_PRO) {
268 composeMsg(request, data, datalen);
269 } else if(request == RIL_REQUEST_STOP_KEEPALIVE_PRO) {
270 sendKeepAlive("RIL_REQUEST_STOP_KEEPALIVE_PRO,ok");
271 } else if (request == RIL_UNSOL_KEEPALIVE_STATUS_PRO) {
272 composeMsg(request, data, datalen);
273 }
274 }
275}
276#endif /*KEEP_ALIVE*/
277
278void parseAtCmd(const char* line) {
279 if (strstr(line, "+ETHERMAL") != NULL) {
280 RLOGD("parse at command: ETHERMAL");
281 AtLine* atLine = new AtLine(line, NULL);
282 int err;
283 atLine->atTokStart(&err);
284 if (err < 0) {
285 delete atLine;
286 RLOGW("this is not a valid response string");
287 return;
288 }
289 int rat = atLine->atTokNextint(&err);
290 if (err < 0) {
291 delete atLine;
292 RLOGW("parse rat fail");
293 return;
294 }
295 int temperature = atLine->atTokNextint(&err);
296 if (err < 0) {
297 delete atLine;
298 RLOGW("parse temperature fail");
299 return;
300 }
301 int tx_power = atLine->atTokNextint(&err);
302 if (err < 0) {
303 delete atLine;
304 RLOGW("parse tx_power fail");
305 return;
306 }
307 RLOGD("[tx_power]rat: %d, temperature: %d, tx_power: %d", rat, temperature, tx_power);
308 printf("[tx_power]rat: %d, temperature: %d, tx_power: %d\n", rat, temperature, tx_power);
309 delete atLine;
310 } else if (strstr(line, "+ECAL") != NULL) {
311 RLOGD("parse at command: ECAL");
312 AtLine* atLine = new AtLine(line, NULL);
313 int err;
314 atLine->atTokStart(&err);
315 if (err < 0) {
316 delete atLine;
317 RLOGW("this is not a valid response string");
318 return;
319 }
320 int cal = atLine->atTokNextint(&err);
321 if (err < 0) {
322 delete atLine;
323 RLOGW("parse rat fail");
324 return;
325 }
326 RLOGD("calibration data is %s", cal == 1 ? "download" : "not download");
327 if (cal == 0) {
328 printf(
329 "************************************************\n*** NOTICE: calibration data is not download ***\n************************************************\n");
330 }
331 delete atLine;
332 }
333}
334
335//RIL_REQUEST_SET_IMSCFG
336int setIMSCfg(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
337{
338 android::Parcel p;
339 size_t pos = p.dataPosition();
340
341 p.writeInt32(6);
342 p.writeInt32(atoi(argv[1]));
343 p.writeInt32(atoi(argv[2]));
344 p.writeInt32(atoi(argv[3]));
345 p.writeInt32(atoi(argv[4]));
346 p.writeInt32(atoi(argv[5]));
347 p.writeInt32(atoi(argv[6]));
348 p.setDataPosition(pos);
349 pRI->pCI->dispatchFunction(p, pRI);
350 return 0;
351}
352/*mobiletek add*/
353frameworkState *g_framework_state=NULL;
354frameworkState::frameworkState()
355{
356 RLOGD("frameworkState init success!!");
357 return;
358}
359
360frameworkState::~ frameworkState()
361{
362 RLOGD("frameworkState clean success!!");
363 return;
364}
365
366int frameworkState::getCallState(void)
367{
368 return callState;
369}
370int frameworkState::setCallState(const int state)
371{
372 callState = state;
373 return 0;
374}
375int initFrameworkState()
376{
377 g_framework_state = new frameworkState();
378 if(g_framework_state==NULL)
379 {
380 RLOGE("init class framework fial!!!");
381 exit(EXIT_FAILURE);
382 }
383 RLOGD("init class framework success!!!");
384 return 0;
385}
386
387/*mobiletek end*/
388