[Replicant] [PATCH 1/2] Wrap RIL_*_v6 to reduce ifdefs
Denis 'GNUtoo' Carikli
GNUtoo at cyberdimension.org
Thu Jun 20 19:41:38 UTC 2019
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
data.c | 25 +++++----------
network.c | 45 +++++----------------------
ril-versions-compat.h | 49 +++++++++++++++++++++++++++++
samsung-ril.c | 36 +++++++---------------
sim.c | 72 +++++++++----------------------------------
5 files changed, 90 insertions(+), 137 deletions(-)
create mode 100644 ril-versions-compat.h
diff --git a/data.c b/data.c
index 5fedf92..00a467d 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,17 +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
- char *setup_data_call_response[3];
- 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 dff666b..f8213d3 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;
@@ -413,11 +392,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))
@@ -471,11 +446,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 84e3074..b15c1b8 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>
@@ -1329,38 +1329,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 c503b27..1ce95aa 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);
@@ -917,11 +896,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;
unsigned char *p;
unsigned int offset;
unsigned int i;
@@ -946,18 +921,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;
@@ -1068,11 +1036,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;
@@ -1080,11 +1044,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_radio_state_check(RADIO_STATE_SIM_READY);
@@ -1100,11 +1060,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.21.0
More information about the Replicant
mailing list