rjw | 1f88458 | 2022-01-06 17:20:42 +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) 2016. 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 | |
| 36 | #include <vendor-ril/telephony/ril.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <stdio.h> |
| 39 | #include <cutils/jstring.h> |
| 40 | #include <log/log.h> |
| 41 | #include <unistd.h> |
| 42 | #include <math.h> |
| 43 | #include "em/em_el1_public_struct.h" |
| 44 | #include "common.h" |
| 45 | #include "em/em.h" |
| 46 | #include "Radio_capability_switch_util.h" |
| 47 | |
| 48 | #if EM_MODE_SUPPORT |
| 49 | |
| 50 | #undef LOG_TAG |
| 51 | #define LOG_TAG "EM_EL1" |
| 52 | |
| 53 | static int mItemCount = 0; |
| 54 | static int mFlag = 0;// at cmd flag |
| 55 | static int mCurrentFlag = 0; // at cmd handle flag |
| 56 | |
| 57 | static const int MSG_NW_INFO = 1; |
| 58 | static const int MSG_NW_INFO_OPEN = 4; |
| 59 | static const int MSG_NW_INFO_CLOSE = 5; |
| 60 | |
| 61 | static void sendATCommand(const char *cmd,int msg) |
| 62 | { |
| 63 | mCurrentFlag = msg; |
| 64 | emSendATCommand(cmd, get_default_sim_all_except_data()); |
| 65 | return ; |
| 66 | } |
| 67 | |
| 68 | static char hex2char(unsigned int hex) { |
| 69 | if (hex >= '0' && hex <= '9') { |
| 70 | return hex - '0'; |
| 71 | } |
| 72 | if (hex >= 'A' && hex <= 'F') { |
| 73 | return 0xA + hex - 'A'; |
| 74 | } |
| 75 | if (hex >= 'a' && hex <= 'f') { |
| 76 | return 0xA + hex - 'a'; |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static void hex2char(char *input, int input_len, char *buf, int buf_size) { |
| 82 | RLOGD("hex2char, input_len: %d, buf_size: %d", input_len, buf_size); |
| 83 | memset(buf, 0, buf_size); |
| 84 | //respose data lack of 8 byte, corresponding to header |
| 85 | //ref_count(1)+lp_reserved(1)+ msg_len(2) + em_info(4) |
| 86 | if (input_len < (buf_size-8) * 2) { // should not happen |
| 87 | buf_size = input_len / 2; |
| 88 | } |
| 89 | for (int i = 0; i < buf_size; i++) { |
| 90 | buf[i+8] = (hex2char(input[i * 2]) << 4) + hex2char(input[i * 2 + 1]); |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |
| 95 | static void el1_at_cmd_handle(char*response, int responselen) { |
| 96 | switch (mCurrentFlag) { |
| 97 | case MSG_NW_INFO: |
| 98 | if ((responselen > 0) && (response != NULL)) { |
| 99 | RLOGD("el1_at_cmd_handle response %s\n",response); |
| 100 | //mFlag = FLAG_OFFSET_BIT; |
| 101 | } |
| 102 | else { |
| 103 | RLOGD("send fail "); |
| 104 | } |
| 105 | break; |
| 106 | case MSG_NW_INFO_OPEN: |
| 107 | case MSG_NW_INFO_CLOSE: |
| 108 | break; |
| 109 | default: |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static void el1_parse(char *output,char * input){ |
| 115 | em_el1_status_ind_struct buf; |
| 116 | hex2char(input, strlen(input), (char *)&buf, sizeof(em_el1_status_ind_struct)); |
| 117 | snprintf(output, 8192, |
| 118 | "[Cell Info]\n" |
| 119 | " band: %u,%u,%u,%u\n" |
| 120 | " DL_BW: %u,%u,%u,%u\n" |
| 121 | " UL_BW: %u,%u,%u,%u\n" |
| 122 | " TM: %u,%u,%u,%u\n" |
| 123 | " PCI: %d,%d,%d,%d\n" |
| 124 | " EARFCN: %u,%u,%u,%u\n" |
| 125 | "[DL]\n" |
| 126 | " dl_rssi: (%d,%d),(%d,%d),(%d,%d),(%d,%d)\n" |
| 127 | " dl_rsrp: (%d,%d),(%d,%d),(%d,%d),(%d,%d)\n" |
| 128 | " dl_rsrq: (%d,%d),(%d,%d),(%d,%d),(%d,%d)\n" |
| 129 | " dl_sinr: (%d,%d),(%d,%d),(%d,%d),(%d,%d)\n" |
| 130 | " rsrp: %d,%d,%d,%d\n" |
| 131 | " rsrq: %d,%d,%d,%d\n" |
| 132 | " sinr: %d,%d,%d,%d\n" |
| 133 | " rsSNR: %d,%d,%d,%d\n" |
| 134 | " tm: %d,%d,%d,%d\n" |
| 135 | " rsrp_l1_rxpath_sum_dBm: %d,%d,%d,%d\n" |
| 136 | " rsrq_l1_rxpath_sum_dB: %d,%d,%d,%d\n" |
| 137 | " snr_l1_rxpath_sum_dB: %d,%d,%d,%d\n", |
| 138 | buf.cell_info[0].band, buf.cell_info[1].band,buf.cell_info[2].band,buf.cell_info[3].band, |
| 139 | buf.cell_info[0].dl_bw, buf.cell_info[1].dl_bw,buf.cell_info[2].dl_bw,buf.cell_info[3].dl_bw, |
| 140 | buf.cell_info[0].ul_bw, buf.cell_info[1].ul_bw,buf.cell_info[2].ul_bw,buf.cell_info[3].ul_bw, |
| 141 | buf.cell_info[0].tm, buf.cell_info[1].tm,buf.cell_info[2].tm,buf.cell_info[3].tm, |
| 142 | buf.cell_info[0].pci, buf.cell_info[1].pci,buf.cell_info[2].pci,buf.cell_info[3].pci, |
| 143 | buf.cell_info[0].earfcn, buf.cell_info[1].earfcn,buf.cell_info[2].earfcn,buf.cell_info[3].earfcn, |
| 144 | buf.dl_info[0].dl_rssi[0],buf.dl_info[0].dl_rssi[1],buf.dl_info[1].dl_rssi[0],buf.dl_info[1].dl_rssi[1], |
| 145 | buf.dl_info[2].dl_rssi[0],buf.dl_info[2].dl_rssi[1],buf.dl_info[3].dl_rssi[0],buf.dl_info[3].dl_rssi[1], |
| 146 | buf.dl_info[0].dl_rsrp[0],buf.dl_info[0].dl_rsrp[1],buf.dl_info[1].dl_rsrp[0],buf.dl_info[1].dl_rsrp[1], |
| 147 | buf.dl_info[2].dl_rsrp[0],buf.dl_info[2].dl_rsrp[1],buf.dl_info[3].dl_rsrp[0],buf.dl_info[3].dl_rsrp[1], |
| 148 | buf.dl_info[0].dl_rsrq[0],buf.dl_info[0].dl_rsrq[1],buf.dl_info[1].dl_rsrq[0],buf.dl_info[1].dl_rsrq[1], |
| 149 | buf.dl_info[2].dl_rsrq[0],buf.dl_info[2].dl_rsrq[1],buf.dl_info[3].dl_rsrq[0],buf.dl_info[3].dl_rsrq[1], |
| 150 | buf.dl_info[0].dl_sinr[0],buf.dl_info[0].dl_sinr[1],buf.dl_info[1].dl_sinr[0],buf.dl_info[1].dl_sinr[1], |
| 151 | buf.dl_info[2].dl_sinr[0],buf.dl_info[2].dl_sinr[1],buf.dl_info[3].dl_sinr[0],buf.dl_info[3].dl_sinr[1], |
| 152 | buf.dl_info[0].rsrp, buf.dl_info[1].rsrp, buf.dl_info[2].rsrp, buf.dl_info[3].rsrp, |
| 153 | buf.dl_info[0].rsrq, buf.dl_info[1].rsrq, buf.dl_info[2].rsrq, buf.dl_info[3].rsrq, |
| 154 | buf.dl_info[0].sinr, buf.dl_info[1].sinr, buf.dl_info[2].sinr, buf.dl_info[3].sinr, |
| 155 | buf.dl_info[0].rsSNR, buf.dl_info[1].rsSNR, buf.dl_info[2].rsSNR, buf.dl_info[3].rsSNR, |
| 156 | buf.dl_info[0].tm, buf.dl_info[1].tm, buf.dl_info[2].tm, buf.dl_info[3].tm, |
| 157 | buf.dl_info[0].rsrp_l1_rxpath_sum_dBm, buf.dl_info[1].rsrp_l1_rxpath_sum_dBm, buf.dl_info[2].rsrp_l1_rxpath_sum_dBm, buf.dl_info[3].rsrp_l1_rxpath_sum_dBm, |
| 158 | buf.dl_info[0].rsrq_l1_rxpath_sum_dB, buf.dl_info[1].rsrq_l1_rxpath_sum_dB, buf.dl_info[2].rsrq_l1_rxpath_sum_dB, buf.dl_info[3].rsrq_l1_rxpath_sum_dB, |
| 159 | buf.dl_info[0].snr_l1_rxpath_sum_dB, buf.dl_info[1].snr_l1_rxpath_sum_dB, buf.dl_info[2].snr_l1_rxpath_sum_dB, buf.dl_info[3].snr_l1_rxpath_sum_dB |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | static void el1_urc_handle(int type, char *data){ |
| 164 | RLOGD("el1_urc_handle type %d data %s\n",type,data); |
| 165 | if(type == EM_EL1_INFO) { |
| 166 | char outbuf[8192] = {0}; |
| 167 | el1_parse(outbuf,data); |
| 168 | android::emResultNotify(outbuf); |
| 169 | android::emResultNotify(RET_STRING_LTE_SUCCESS); |
| 170 | android::unregisterNetwork(); |
| 171 | char atcommand[32] = {0}; |
| 172 | sprintf(atcommand,"AT+EINFO=%d,%d,1",mFlag,EM_EL1_INFO); |
| 173 | sendATCommand(atcommand, MSG_NW_INFO_CLOSE); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | int em_el1_start(int argc, int multicnt,int *item) |
| 178 | { |
| 179 | RLOGD("em_el1_start called"); |
| 180 | if(argc < 1) |
| 181 | { |
| 182 | RLOGD("em_el1_start: please select page to show info"); |
| 183 | android::emResultNotify(RET_STRING_LTE_FAIL); |
| 184 | return -1; |
| 185 | } |
| 186 | mItemCount = multicnt + 1; |
| 187 | RLOGD("mItemCount: %d, item[%d]: %d", mItemCount, multicnt, item[multicnt]); |
| 188 | android::registerForNetworkInfo(el1_urc_handle); |
| 189 | android::registerForATcmdResponse(el1_at_cmd_handle); |
| 190 | //sendATCommand("AT+EINFO?",MSG_NW_INFO); |
| 191 | mFlag = 8; |
| 192 | char atcommand[32] = {0}; |
| 193 | sprintf(atcommand,"AT+EINFO=%d,%d,0",mFlag,EM_EL1_INFO); |
| 194 | sendATCommand(atcommand, MSG_NW_INFO_OPEN); |
| 195 | return (0); |
| 196 | } |
| 197 | #endif |
| 198 | |