1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "structs.h"
18 
19 #include "collections.h"
20 
21 #include <aidl/android/hardware/radio/messaging/CdmaSmsAddress.h>
22 #include <android-base/logging.h>
23 
24 namespace android::hardware::radio::compat {
25 
26 namespace aidl = ::aidl::android::hardware::radio::messaging;
27 
toHidl(const aidl::CdmaSmsAck & smsAck)28 V1_0::CdmaSmsAck toHidl(const aidl::CdmaSmsAck& smsAck) {
29     return {
30             .errorClass = (smsAck.errorClass ? V1_0::CdmaSmsErrorClass::ERROR
31                                              : V1_0::CdmaSmsErrorClass::NO_ERROR),
32             .smsCauseCode = smsAck.smsCauseCode,
33     };
34 }
35 
toAidl(const V1_0::CdmaSmsAddress & addr)36 static aidl::CdmaSmsAddress toAidl(const V1_0::CdmaSmsAddress& addr) {
37     return {
38             .digitMode = static_cast<int32_t>(addr.digitMode),
39             .isNumberModeDataNetwork = addr.numberMode == V1_0::CdmaSmsNumberMode::DATA_NETWORK,
40             .numberType = static_cast<int32_t>(addr.numberType),
41             .numberPlan = static_cast<int32_t>(addr.numberPlan),
42             .digits = addr.digits,
43     };
44 }
45 
toHidl(const aidl::CdmaSmsAddress & addr)46 static V1_0::CdmaSmsAddress toHidl(const aidl::CdmaSmsAddress& addr) {
47     return {
48             .digitMode = static_cast<V1_0::CdmaSmsDigitMode>(addr.digitMode),
49             .numberMode = addr.isNumberModeDataNetwork ? V1_0::CdmaSmsNumberMode::DATA_NETWORK
50                                                        : V1_0::CdmaSmsNumberMode::NOT_DATA_NETWORK,
51             .numberType = static_cast<V1_0::CdmaSmsNumberType>(addr.numberType),
52             .numberPlan = static_cast<V1_0::CdmaSmsNumberPlan>(addr.numberPlan),
53             .digits = addr.digits,
54     };
55 }
56 
toAidl(const V1_0::CdmaSmsSubaddress & addr)57 static aidl::CdmaSmsSubaddress toAidl(const V1_0::CdmaSmsSubaddress& addr) {
58     return {
59             .subaddressType = static_cast<int32_t>(addr.subaddressType),
60             .odd = addr.odd,
61             .digits = addr.digits,
62     };
63 }
64 
toHidl(const aidl::CdmaSmsSubaddress & addr)65 static V1_0::CdmaSmsSubaddress toHidl(const aidl::CdmaSmsSubaddress& addr) {
66     return {
67             .subaddressType = static_cast<V1_0::CdmaSmsSubaddressType>(addr.subaddressType),
68             .odd = addr.odd,
69             .digits = addr.digits,
70     };
71 }
72 
toAidl(const V1_0::CdmaSmsMessage & m)73 ::aidl::android::hardware::radio::messaging::CdmaSmsMessage toAidl(const V1_0::CdmaSmsMessage& m) {
74     return {
75             .teleserviceId = m.teleserviceId,
76             .isServicePresent = m.isServicePresent,
77             .serviceCategory = m.serviceCategory,
78             .address = toAidl(m.address),
79             .subAddress = toAidl(m.subAddress),
80             .bearerData = m.bearerData,
81     };
82 }
83 
toHidl(const aidl::CdmaSmsMessage & msg)84 V1_0::CdmaSmsMessage toHidl(const aidl::CdmaSmsMessage& msg) {
85     return {
86             .teleserviceId = msg.teleserviceId,
87             .isServicePresent = msg.isServicePresent,
88             .serviceCategory = msg.serviceCategory,
89             .address = toHidl(msg.address),
90             .subAddress = toHidl(msg.subAddress),
91             .bearerData = msg.bearerData,
92     };
93 }
94 
toHidl(const aidl::ImsSmsMessage & msg)95 V1_0::ImsSmsMessage toHidl(const aidl::ImsSmsMessage& msg) {
96     return {
97             .tech = static_cast<V1_0::RadioTechnologyFamily>(msg.tech),
98             .retry = msg.retry,
99             .messageRef = msg.messageRef,
100             .cdmaMessage = toHidl(msg.cdmaMessage),
101             .gsmMessage = toHidl(msg.gsmMessage),
102     };
103 }
104 
toHidl(const aidl::GsmSmsMessage & msg)105 V1_0::GsmSmsMessage toHidl(const aidl::GsmSmsMessage& msg) {
106     return {
107             .smscPdu = msg.smscPdu,
108             .pdu = msg.pdu,
109     };
110 }
111 
toAidl(const V1_0::CdmaBroadcastSmsConfigInfo & info)112 aidl::CdmaBroadcastSmsConfigInfo toAidl(const V1_0::CdmaBroadcastSmsConfigInfo& info) {
113     return {
114             .serviceCategory = info.serviceCategory,
115             .language = info.language,
116             .selected = info.selected,
117     };
118 }
119 
toHidl(const aidl::CdmaBroadcastSmsConfigInfo & info)120 V1_0::CdmaBroadcastSmsConfigInfo toHidl(const aidl::CdmaBroadcastSmsConfigInfo& info) {
121     return {
122             .serviceCategory = info.serviceCategory,
123             .language = info.language,
124             .selected = info.selected,
125     };
126 }
127 
toAidl(const V1_0::GsmBroadcastSmsConfigInfo & info)128 aidl::GsmBroadcastSmsConfigInfo toAidl(const V1_0::GsmBroadcastSmsConfigInfo& info) {
129     return {
130             .fromServiceId = info.fromServiceId,
131             .toServiceId = info.toServiceId,
132             .fromCodeScheme = info.fromCodeScheme,
133             .toCodeScheme = info.toCodeScheme,
134             .selected = info.selected,
135     };
136 }
137 
toHidl(const aidl::GsmBroadcastSmsConfigInfo & info)138 V1_0::GsmBroadcastSmsConfigInfo toHidl(const aidl::GsmBroadcastSmsConfigInfo& info) {
139     return {
140             .fromServiceId = info.fromServiceId,
141             .toServiceId = info.toServiceId,
142             .fromCodeScheme = info.fromCodeScheme,
143             .toCodeScheme = info.toCodeScheme,
144             .selected = info.selected,
145     };
146 }
147 
toHidl(const aidl::CdmaSmsWriteArgs & args)148 V1_0::CdmaSmsWriteArgs toHidl(const aidl::CdmaSmsWriteArgs& args) {
149     return {
150             .status = static_cast<V1_0::CdmaSmsWriteArgsStatus>(args.status),
151             .message = toHidl(args.message),
152     };
153 }
154 
toHidl(const aidl::SmsWriteArgs & args)155 V1_0::SmsWriteArgs toHidl(const aidl::SmsWriteArgs& args) {
156     return {
157             .status = static_cast<V1_0::SmsWriteArgsStatus>(args.status),
158             .pdu = args.pdu,
159             .smsc = args.smsc,
160     };
161 }
162 
toAidl(const V1_0::SendSmsResult & result)163 ::aidl::android::hardware::radio::messaging::SendSmsResult toAidl(
164         const V1_0::SendSmsResult& result) {
165     return {
166             .messageRef = result.messageRef,
167             .ackPDU = result.ackPDU,
168             .errorCode = result.errorCode,
169     };
170 }
171 
172 }  // namespace android::hardware::radio::compat
173