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) 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 | |
| 36 | #include <cstdint> |
| 37 | #include <algorithm> |
| 38 | #include "SmsMessageConverter.h" |
| 39 | #include "SmsEnvelope.h" |
| 40 | #include "CdmaSmsAddress.h" |
| 41 | #include "CdmaSmsSubaddress.h" |
| 42 | #include "SmsMessage.h" |
| 43 | #include <log/log.h> |
| 44 | |
| 45 | #undef LOG_TAG |
| 46 | #define LOG_TAG "DEMO_CDMA_SMS" |
| 47 | SmsMessageConverter::SmsMessageConverter() { |
| 48 | // TODO Auto-generated constructor stub |
| 49 | |
| 50 | } |
| 51 | |
| 52 | SmsMessageConverter::~SmsMessageConverter() { |
| 53 | // TODO Auto-generated destructor stub |
| 54 | } |
| 55 | |
| 56 | std::shared_ptr<SmsMessage> SmsMessageConverter::newCdmaSmsMessageFromRil( |
| 57 | RIL_CDMA_SMS_Message *p_cur) { |
| 58 | // Note: Parcel.readByte actually reads one Int and masks to byte |
| 59 | auto env = std::make_shared<SmsEnvelope>(); |
| 60 | auto addr = std::make_shared<CdmaSmsAddress>(); |
| 61 | auto subaddr = std::make_shared<CdmaSmsSubaddress>(); |
| 62 | std::vector<uint8_t> data; |
| 63 | uint8_t count; |
| 64 | int countInt; |
| 65 | int addressDigitMode; |
| 66 | |
| 67 | //currently not supported by the modem-lib: env.mMessageType |
| 68 | env->teleService = p_cur->uTeleserviceID; |
| 69 | |
| 70 | if (p_cur->bIsServicePresent) { |
| 71 | env->messageType = SmsEnvelope::MESSAGE_TYPE_BROADCAST; |
| 72 | } else { |
| 73 | if (SmsEnvelope::TELESERVICE_NOT_SET == env->teleService) { |
| 74 | // assume type ACK |
| 75 | env->messageType = SmsEnvelope::MESSAGE_TYPE_ACKNOWLEDGE; |
| 76 | } else { |
| 77 | env->messageType = SmsEnvelope::MESSAGE_TYPE_POINT_TO_POINT; |
| 78 | } |
| 79 | } |
| 80 | env->serviceCategory = p_cur->uServicecategory; |
| 81 | |
| 82 | // address |
| 83 | addressDigitMode = p_cur->sAddress.digit_mode; |
| 84 | addr->digitMode = (uint8_t) (0xFF & addressDigitMode); |
| 85 | addr->numberMode = (uint8_t) (0xFF & p_cur->sAddress.number_mode); |
| 86 | addr->ton = p_cur->sAddress.number_type; |
| 87 | addr->numberPlan = (uint8_t) (0xFF & p_cur->sAddress.number_plan); |
| 88 | count = std::min((p_cur->sAddress.number_of_digits), (uint8_t) RIL_CDMA_SMS_ADDRESS_MAX); |
| 89 | addr->numberOfDigits = count; |
| 90 | //data = new byte[count]; |
| 91 | std::string str; |
| 92 | for (int index = 0; index < count; index++) { |
| 93 | data.push_back(p_cur->sAddress.digits[index]); |
| 94 | // convert the value if it is 4-bit DTMF to 8 bit |
| 95 | if (addressDigitMode == CdmaSmsAddress::DIGIT_MODE_4BIT_DTMF) { |
| 96 | data[index] = SmsMessage::convertDtmfToAscii(data[index]); |
| 97 | str.push_back((char)(data[index])); |
| 98 | } |
| 99 | } |
| 100 | if (addressDigitMode == CdmaSmsAddress::DIGIT_MODE_4BIT_DTMF) { |
| 101 | RLOGD("address: %s", str.empty() ? "": str.c_str()); |
| 102 | printf("address: %s\n", str.empty() ? "": str.c_str()); |
| 103 | } |
| 104 | |
| 105 | addr->origBytes = data; |
| 106 | |
| 107 | subaddr->type = p_cur->sSubAddress.subaddressType; |
| 108 | subaddr->odd = (uint8_t) (p_cur->sSubAddress.odd ? 1 : 0); |
| 109 | count = std::min((p_cur->sSubAddress.number_of_digits), |
| 110 | (uint8_t) RIL_CDMA_SMS_SUBADDRESS_MAX); |
| 111 | |
| 112 | if (count < 0) { |
| 113 | count = 0; |
| 114 | } |
| 115 | |
| 116 | // p_cur->sSubAddress.digits[digitCount] : |
| 117 | |
| 118 | data.clear(); |
| 119 | |
| 120 | for (int index = 0; index < count; ++index) { |
| 121 | data.push_back(p_cur->sSubAddress.digits[index]); |
| 122 | } |
| 123 | |
| 124 | subaddr->origBytes = data; |
| 125 | |
| 126 | /* currently not supported by the modem-lib: |
| 127 | env.bearerReply |
| 128 | env.replySeqNo |
| 129 | env.errorClass |
| 130 | env.causeCode |
| 131 | */ |
| 132 | |
| 133 | // bearer data |
| 134 | countInt = std::min((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX); |
| 135 | if (countInt < 0) { |
| 136 | countInt = 0; |
| 137 | } |
| 138 | |
| 139 | data.clear(); |
| 140 | for (int index = 0; index < countInt; index++) { |
| 141 | data.push_back(p_cur->aBearerData[index]); |
| 142 | } |
| 143 | // BD gets further decoded when accessed in SMSDispatcher |
| 144 | env->bearerData = data; |
| 145 | |
| 146 | // link the the filled objects to the SMS |
| 147 | env->origAddress = addr; |
| 148 | env->origSubaddress = subaddr; |
| 149 | |
| 150 | auto msg = std::make_shared<SmsMessage>(addr, env); |
| 151 | |
| 152 | return msg; |
| 153 | } |