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