[Replicant] [libsamsung-ril] [PATCH 6/8] Wrap RIL_*_v6 to reduce ifdefs

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Fri Aug 21 04:07:02 UTC 2020


Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 data.c                | 24 +++++----------
 network.c             | 45 +++++----------------------
 ril-versions-compat.h | 49 +++++++++++++++++++++++++++++
 samsung-ril.c         | 36 +++++++---------------
 sim.c                 | 72 +++++++++----------------------------------
 5 files changed, 90 insertions(+), 136 deletions(-)
 create mode 100644 ril-versions-compat.h

diff --git a/data.c b/data.c
index 11d0b47..dd39926 100644
--- a/data.c
+++ b/data.c
@@ -25,6 +25,7 @@
 #include <utils/Log.h>
 #include <netutils/ifc.h>
 
+#include <ril-versions-compat.h>
 #include <samsung-ril.h>
 #include <utils.h>
 
@@ -563,11 +564,7 @@ int ipc_gprs_pdp_context(struct ipc_message *message)
 {
 	struct ipc_gprs_pdp_context_request_get_data *data;
 	struct ril_data_connection *data_connection;
-#if RIL_VERSION >= 6
-	RIL_Data_Call_Response_v6 response[3];
-#else
-	RIL_Data_Call_Response response[3];
-#endif
+	RIL_Data_Call_Response_compat response[3];
 	unsigned int entries_count;
 	unsigned int index = 0;
 	size_t size;
@@ -623,11 +620,7 @@ int ipc_gprs_pdp_context(struct ipc_message *message)
 		index++;
 	}
 
-#if RIL_VERSION >= 6
-	size = index * sizeof(RIL_Data_Call_Response_v6);
-#else
-	size = index * sizeof(RIL_Data_Call_Response);
-#endif
+	size = index * sizeof(RIL_Data_Call_Response_compat);
 
 	if (!ipc_seq_valid(message->aseq))
 		ril_request_unsolicited(RIL_UNSOL_DATA_CALL_LIST_CHANGED, &response, size);
@@ -868,16 +861,15 @@ int ipc_gprs_hsdpa_status(struct ipc_message *message)
 
 int ipc_gprs_call_status(struct ipc_message *message)
 {
-#if RIL_VERSION >= 6
-	RIL_Data_Call_Response_v6 response;
-#else
-	int fail_cause;
-	unsigned int i;
-#endif
+	RIL_Data_Call_Response_compat response;
 	struct ipc_gprs_call_status_data *data;
 	struct ril_data_connection *data_connection;
 	struct ril_request *request;
 	int rc;
+#if RIL_VERSION < 6
+	int fail_cause;
+	unsigned int i;
+#endif
 
 	if (message == NULL || message->data == NULL || message->size < sizeof(struct ipc_gprs_call_status_data))
 		return -1;
diff --git a/network.c b/network.c
index a5caf7a..1ce903e 100644
--- a/network.c
+++ b/network.c
@@ -27,26 +27,19 @@
 #define LOG_TAG "RIL"
 #include <utils/Log.h>
 
+#include <ril-versions-compat.h>
 #include <samsung-ril.h>
 #include <utils.h>
 #include <plmn_list.h>
 
-#if RIL_VERSION >= 6
-int ipc2ril_disp_rssi(unsigned char rssi, RIL_SignalStrength_v6 *strength)
-#else
-int ipc2ril_disp_rssi(unsigned char rssi, RIL_SignalStrength *strength)
-#endif
+int ipc2ril_disp_rssi(unsigned char rssi, RIL_SignalStrength_compat *strength)
 {
 	int asu;
 
 	if (strength == NULL)
 		return -1;
 
-#if RIL_VERSION >= 6
-	memset(strength, -1, sizeof(RIL_SignalStrength_v6));
-#else
-	memset(strength, -1, sizeof(RIL_SignalStrength));
-#endif
+	memset(strength, -1, sizeof(RIL_SignalStrength_compat));
 
 	asu = (int) rssi / -2 + 56;
 
@@ -63,13 +56,8 @@ int ipc2ril_disp_rssi(unsigned char rssi, RIL_SignalStrength *strength)
 	return 0;
 }
 
-#if RIL_VERSION >= 6
-int ipc2ril_disp_icon_info(struct ipc_disp_icon_info_response_data *data,
-	RIL_SignalStrength_v6 *strength)
-#else
 int ipc2ril_disp_icon_info(struct ipc_disp_icon_info_response_data *data,
-	RIL_SignalStrength *strength)
-#endif
+	RIL_SignalStrength_compat *strength)
 {
 	int asu_bars[] = { 1, 3, 5, 8, 12, 15 };
 	unsigned int asu_bars_count = sizeof(asu_bars) / sizeof(int);
@@ -81,11 +69,7 @@ int ipc2ril_disp_icon_info(struct ipc_disp_icon_info_response_data *data,
 	if (!(data->flags & IPC_DISP_ICON_INFO_FLAG_RSSI))
 		return -1;
 
-#if RIL_VERSION >= 6
-	memset(strength, -1, sizeof(RIL_SignalStrength_v6));
-#else
-	memset(strength, -1, sizeof(RIL_SignalStrength));
-#endif
+	memset(strength, -1, sizeof(RIL_SignalStrength_compat));
 
 	asu_bars_index = data->rssi;
 	if (asu_bars_index >= asu_bars_count)
@@ -100,13 +84,8 @@ int ipc2ril_disp_icon_info(struct ipc_disp_icon_info_response_data *data,
 	return 0;
 }
 
-#if RIL_VERSION >= 6
-int ipc2ril_disp_rssi_info(struct ipc_disp_rssi_info_data *data,
-	RIL_SignalStrength_v6 *strength)
-#else
 int ipc2ril_disp_rssi_info(struct ipc_disp_rssi_info_data *data,
-	RIL_SignalStrength *strength)
-#endif
+	RIL_SignalStrength_compat *strength)
 {
 	int rc;
 
@@ -412,11 +391,7 @@ unsigned char ril2ipc_net_mode_sel(int type)
 int ipc_disp_icon_info(struct ipc_message *message)
 {
 	struct ipc_disp_icon_info_response_data *data;
-#if RIL_VERSION >= 6
-	RIL_SignalStrength_v6 strength;
-#else
-	RIL_SignalStrength strength;
-#endif
+	RIL_SignalStrength_compat strength;
 	int rc;
 
 	if (message == NULL || message->data == NULL || message->size < sizeof(struct ipc_disp_icon_info_response_data))
@@ -470,11 +445,7 @@ int ril_request_signal_strength(__attribute__((unused)) void *data,
 int ipc_disp_rssi_info(struct ipc_message *message)
 {
 	struct ipc_disp_rssi_info_data *data;
-#if RIL_VERSION >= 6
-	RIL_SignalStrength_v6 strength;
-#else
-	RIL_SignalStrength strength;
-#endif
+	RIL_SignalStrength_compat strength;
 	int rc;
 
 	if (message == NULL || message->data == NULL || message->size < sizeof(struct ipc_disp_rssi_info_data))
diff --git a/ril-versions-compat.h b/ril-versions-compat.h
new file mode 100644
index 0000000..7c791ae
--- /dev/null
+++ b/ril-versions-compat.h
@@ -0,0 +1,49 @@
+/*
+ * This file is part of Samsung-RIL.
+ *
+ * Copyright (C) 2019 Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
+ *
+ * Samsung-RIL is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Samsung-RIL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Samsung-RIL.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _RIL_VERSIONS_H_
+#define _RIL_VERSIONS_H_
+
+#include <telephony/ril.h>
+
+#if RIL_VERSION >= 6
+#define RIL_Data_Call_Response_compat RIL_Data_Call_Response_v6
+#else
+#define RIL_Data_Call_Response_compat RIL_Data_Call_Response
+#endif
+
+#if RIL_VERSION >= 6
+#define RIL_CardStatus_compat RIL_CardStatus_v6
+#else
+#define RIL_CardStatus_compat RIL_CardStatus_v6
+#endif
+
+#if RIL_VERSION >= 6
+#define RIL_SignalStrength_compat RIL_SignalStrength_v6
+#else
+#define RIL_SignalStrength_compat RIL_SignalStrength
+#endif
+
+#if RIL_VERSION >= 6
+#define RIL_SIM_IO_compat RIL_SIM_IO_v6
+#else
+#define RIL_SIM_IO_compat RIL_SIM_IO
+#endif
+
+#endif /* _RIL_VERSIONS_H_ */
diff --git a/samsung-ril.c b/samsung-ril.c
index a9cc224..0f829df 100644
--- a/samsung-ril.c
+++ b/samsung-ril.c
@@ -23,8 +23,8 @@
 
 #define LOG_TAG "RIL"
 #include <utils/Log.h>
-#include <telephony/ril.h>
 
+#include <ril-versions-compat.h>
 #include <samsung-ril.h>
 #include <utils.h>
 
@@ -1338,38 +1338,24 @@ void ril_on_request(int request, void *data, size_t size, RIL_Token token)
 			strings_count = size / sizeof(char *);
 			break;
 		case RIL_REQUEST_SIM_IO:
-#if RIL_VERSION >= 6
-			if (data == NULL || size < sizeof(RIL_SIM_IO_v6))
-#else
-			if (data == NULL || size < sizeof(RIL_SIM_IO))
-#endif
+			if (data == NULL || size < sizeof(RIL_SIM_IO_compat))
 				break;
 
 			buffer = calloc(1, size);
 
 			memcpy(buffer, data, size);
 
-#if RIL_VERSION >= 6
-			if (((RIL_SIM_IO_v6 *) data)->path != NULL)
-				((RIL_SIM_IO_v6 *) buffer)->path = strdup(((RIL_SIM_IO_v6 *) data)->path);
-
-			if (((RIL_SIM_IO_v6 *) data)->data != NULL)
-				((RIL_SIM_IO_v6 *) buffer)->data = strdup(((RIL_SIM_IO_v6 *) data)->data);
+			if (((RIL_SIM_IO_compat *) data)->path != NULL)
+				((RIL_SIM_IO_compat *) buffer)->path = strdup(((RIL_SIM_IO_compat *) data)->path);
 
-			if (((RIL_SIM_IO_v6 *) data)->pin2 != NULL)
-				((RIL_SIM_IO_v6 *) buffer)->pin2 = strdup(((RIL_SIM_IO_v6 *) data)->pin2);
+			if (((RIL_SIM_IO_compat *) data)->data != NULL)
+				((RIL_SIM_IO_compat *) buffer)->data = strdup(((RIL_SIM_IO_compat *) data)->data);
 
-			if (((RIL_SIM_IO_v6 *) data)->aidPtr != NULL)
-				((RIL_SIM_IO_v6 *) buffer)->aidPtr = strdup(((RIL_SIM_IO_v6 *) data)->aidPtr);
-#else
-			if (((RIL_SIM_IO *) data)->path != NULL)
-				((RIL_SIM_IO *) buffer)->path = strdup(((RIL_SIM_IO *) data)->path);
-
-			if (((RIL_SIM_IO *) data)->data != NULL)
-				((RIL_SIM_IO *) buffer)->data = strdup(((RIL_SIM_IO *) data)->data);
-
-			if (((RIL_SIM_IO *) data)->pin2 != NULL)
-				((RIL_SIM_IO *) buffer)->pin2 = strdup(((RIL_SIM_IO *) data)->pin2);
+			if (((RIL_SIM_IO_compat *) data)->pin2 != NULL)
+				((RIL_SIM_IO_compat *) buffer)->pin2 = strdup(((RIL_SIM_IO_compat *) data)->pin2);
+#if RIL_VERSION >= 6
+			if (((RIL_SIM_IO_compat *) data)->aidPtr != NULL)
+				((RIL_SIM_IO_compat *) buffer)->aidPtr = strdup(((RIL_SIM_IO_compat *) data)->aidPtr);
 #endif
 
 			data = buffer;
diff --git a/sim.c b/sim.c
index f0fb89e..536ea47 100644
--- a/sim.c
+++ b/sim.c
@@ -23,17 +23,13 @@
 #define LOG_TAG "RIL"
 #include <utils/Log.h>
 
+#include <ril-versions-compat.h>
 #include <samsung-ril.h>
 #include <utils.h>
 #include <sim.h>
 
-#if RIL_VERSION >= 6
-RIL_RadioState ipc2ril_sec_pin_status_response(struct ipc_sec_pin_status_response_data *data,
-	RIL_CardStatus_v6 *card_status)
-#else
 RIL_RadioState ipc2ril_sec_pin_status_response(struct ipc_sec_pin_status_response_data *data,
-	RIL_CardStatus *card_status)
-#endif
+	RIL_CardStatus_compat *card_status)
 {
 	RIL_AppStatus app_statuses[] = {
 		// Absent
@@ -126,11 +122,7 @@ RIL_RadioState ipc2ril_sec_pin_status_response(struct ipc_sec_pin_status_respons
 			radio_state = RADIO_STATE_SIM_LOCKED_OR_ABSENT;
 	}
 
-#if RIL_VERSION >= 6
-	memset(card_status, 0, sizeof(RIL_CardStatus_v6));
-#else
-	memset(card_status, 0, sizeof(RIL_CardStatus));
-#endif
+	memset(card_status, 0, sizeof(RIL_CardStatus_compat));
 
 	if (index == 0)
 		card_status->card_state = RIL_CARDSTATE_ABSENT;
@@ -201,11 +193,7 @@ int ipc_sec_pin_status(struct ipc_message *message)
 {
 	struct ipc_sec_pin_status_response_data *data;
 	struct ipc_sec_pin_status_request_data request_data;
-#if RIL_VERSION >= 6
-	RIL_CardStatus_v6 card_status;
-#else
-	RIL_CardStatus card_status;
-#endif
+	RIL_CardStatus_compat card_status;
 	RIL_RadioState radio_state;
 	int rc;
 
@@ -263,11 +251,7 @@ int ril_request_get_sim_status(__attribute__((unused)) void *data,
 {
 	void *card_status_data;
 	size_t card_status_size;
-#if RIL_VERSION >= 6
-	RIL_CardStatus_v6 *card_status;
-#else
-	RIL_CardStatus *card_status;
-#endif
+	RIL_CardStatus_compat *card_status;
 	struct ril_request *request;
 	int rc;
 
@@ -282,13 +266,8 @@ int ril_request_get_sim_status(__attribute__((unused)) void *data,
 	card_status_size = ril_request_data_size_get(RIL_REQUEST_GET_SIM_STATUS);
 	card_status_data = ril_request_data_get(RIL_REQUEST_GET_SIM_STATUS);
 
-#if RIL_VERSION >= 6
-	if (card_status_data != NULL && card_status_size >= sizeof(RIL_CardStatus_v6)) {
-		card_status = (RIL_CardStatus_v6 *) ril_request_data_get(RIL_REQUEST_GET_SIM_STATUS);
-#else
-	if (card_status_data != NULL && card_status_size >= sizeof(RIL_CardStatus)) {
-		card_status = (RIL_CardStatus *) ril_request_data_get(RIL_REQUEST_GET_SIM_STATUS);
-#endif
+	if (card_status_data != NULL && card_status_size >= sizeof(RIL_CardStatus_compat)) {
+		card_status = (RIL_CardStatus_compat *) ril_request_data_get(RIL_REQUEST_GET_SIM_STATUS);
 		ril_request_complete(token, RIL_E_SUCCESS, card_status_data, card_status_size);
 
 		free(card_status_data);
@@ -915,11 +894,7 @@ int ipc_sec_rsim_access(struct ipc_message *message)
 	struct ril_client *client;
 	struct ipc_fmt_data *ipc_fmt_data;
 	RIL_SIM_IO_Response response;
-#if RIL_VERSION >= 6
-	RIL_SIM_IO_v6 *sim_io;
-#else
-	RIL_SIM_IO *sim_io;
-#endif
+	RIL_SIM_IO_compat *sim_io;
 	void *data;
 	size_t size;
 
@@ -941,18 +916,11 @@ int ipc_sec_rsim_access(struct ipc_message *message)
 	data = ipc_sec_rsim_access_extract(message->data, message->size);
 
 	request = ril_request_find_token(ipc_fmt_request_token(message->aseq));
-#if RIL_VERSION >= 6
-	if (request == NULL || request->data == NULL || request->size < sizeof(RIL_SIM_IO_v6))
-#else
-	if (request == NULL || request->data == NULL || request->size < sizeof(RIL_SIM_IO))
-#endif
+
+	if (request == NULL || request->data == NULL || request->size < sizeof(RIL_SIM_IO_compat))
 		return 0;
 
-#if RIL_VERSION >= 6
-	sim_io = (RIL_SIM_IO_v6 *) request->data;
-#else
-	sim_io = (RIL_SIM_IO *) request->data;
-#endif
+	sim_io = (RIL_SIM_IO_compat *) request->data;
 
 	memset(&response, 0, sizeof(response));
 	response.sw1 = header->sw1;
@@ -988,11 +956,7 @@ int ril_request_sim_io(void *data, size_t size, RIL_Token token)
 	struct ipc_sec_rsim_access_request_header request_header;
 	struct ipc_sec_pin_status_request_data pin_request_data;
 	struct ril_request *request;
-#if RIL_VERSION >= 6
-	RIL_SIM_IO_v6 *sim_io = NULL;
-#else
-	RIL_SIM_IO *sim_io = NULL;
-#endif
+	RIL_SIM_IO_compat *sim_io = NULL;
 	void *sim_io_data = NULL;
 	size_t sim_io_size = 0;
 	void *request_data = NULL;
@@ -1000,11 +964,7 @@ int ril_request_sim_io(void *data, size_t size, RIL_Token token)
 	int pin_request = 0;
 	int rc;
 
-#if RIL_VERSION >= 6
-	if (data == NULL || size < sizeof(RIL_SIM_IO_v6))
-#else
-	if (data == NULL || size < sizeof(RIL_SIM_IO))
-#endif
+	if (data == NULL || size < sizeof(RIL_SIM_IO_compat))
 		goto error;
 
 	rc = ril_has_reached_state(RADIO_STATE_SIM_READY);
@@ -1020,11 +980,7 @@ int ril_request_sim_io(void *data, size_t size, RIL_Token token)
 	if (request != NULL)
 		return RIL_REQUEST_UNHANDLED;
 
-#if RIL_VERSION >= 6
-	sim_io = (RIL_SIM_IO_v6 *) data;
-#else
-	sim_io = (RIL_SIM_IO *) data;
-#endif
+	sim_io = (RIL_SIM_IO_compat *) data;
 
 	if (sim_io->data != NULL) {
 		sim_io_size = string2data_size(sim_io->data);
-- 
2.28.0



More information about the Replicant mailing list