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