From 178f58281d40eaa2fc18a18293614040d4277270 Mon Sep 17 00:00:00 2001 From: Ziyan Date: Thu, 8 Sep 2016 22:00:15 +0200 Subject: libsecril-shim: fix RIL_REQUEST_QUERY_AVAILABLE_NETWORKS Remove the extra (unused) element from the operator info, freaking out the framework. Formerly, this is know as the mQANElements override. Change-Id: I2f2ed984383a6656bfd39d419f0b8702d66a7e16 --- rilsrc/libsecril-shim/secril-shim.c | 59 ++++++++++++++++++++++++++++++++++++- rilsrc/libsecril-shim/secril-shim.h | 17 +++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/rilsrc/libsecril-shim/secril-shim.c b/rilsrc/libsecril-shim/secril-shim.c index 50723e3..ed703c1 100644 --- a/rilsrc/libsecril-shim/secril-shim.c +++ b/rilsrc/libsecril-shim/secril-shim.c @@ -59,13 +59,70 @@ static void onRequestShim(int request, void *data, size_t datalen, RIL_Token t) origRilFunctions->onRequest(request, data, datalen, t); } +static void onCompleteQueryAvailableNetworks(RIL_Token t, RIL_Errno e, void *response, size_t responselen) { + /* Response is a char **, pointing to an array of char *'s */ + size_t numStrings = responselen / sizeof(char *); + size_t numNeededStrings = numStrings - (numStrings / 5); + size_t newResponseLen = numNeededStrings * sizeof(char *); + + void *newResponse = malloc(newResponseLen); + + /* Remove every 5th string (qan element) */ + char **p_cur = (char **) response; + char **p_new = (char **) newResponse; + size_t i, j; + for (i = 0, j = 0; i < numStrings; ++i) { + if ((i + 1) % 5 != 0) { + p_new[j] = p_cur[i]; + ++j; + } + } + + /* Send the fixed response to libril */ + rilEnv->OnRequestComplete(t, e, newResponse, newResponseLen); + + free(newResponse); +} + +static void onRequestCompleteShim(RIL_Token t, RIL_Errno e, void *response, size_t responselen) { + int request; + RequestInfo *pRI; + + pRI = (RequestInfo *)t; + + /* If pRI is null, this entire function is useless. */ + if (pRI == NULL) + goto null_token_exit; + + request = pRI->pCI->requestNumber; + + switch (request) { + case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: + /* Remove the extra (unused) element from the operator info, freaking out the framework. + * Formerly, this is know as the mQANElements override. */ + if (response != NULL && responselen != 0 && (responselen % sizeof(char *) == 0)) { + onCompleteQueryAvailableNetworks(t, e, response, responselen); + return; + } + break; + } + + RLOGD("%s: got request %s: forwarded to libril.\n", __func__, requestToString(request)); +null_token_exit: + rilEnv->OnRequestComplete(t, e, response, responselen); +} + const RIL_RadioFunctions* RIL_Init(const struct RIL_Env *env, int argc, char **argv) { RIL_RadioFunctions const* (*origRilInit)(const struct RIL_Env *env, int argc, char **argv); static RIL_RadioFunctions shimmedFunctions; + static struct RIL_Env shimmedEnv; void *origRil; + /* Shim the RIL_Env passed to the real RIL, saving a copy of the original */ rilEnv = env; + shimmedEnv = *env; + shimmedEnv.OnRequestComplete = onRequestCompleteShim; /* Open and Init the original RIL. */ @@ -81,7 +138,7 @@ const RIL_RadioFunctions* RIL_Init(const struct RIL_Env *env, int argc, char **a goto fail_after_dlopen; } - origRilFunctions = origRilInit(env, argc, argv); + origRilFunctions = origRilInit(&shimmedEnv, argc, argv); if (CC_UNLIKELY(!origRilFunctions)) { RLOGE("%s: the original RIL_Init derped.\n", __func__); goto fail_after_dlopen; diff --git a/rilsrc/libsecril-shim/secril-shim.h b/rilsrc/libsecril-shim/secril-shim.h index ad409db..a938f4b 100644 --- a/rilsrc/libsecril-shim/secril-shim.h +++ b/rilsrc/libsecril-shim/secril-shim.h @@ -21,4 +21,21 @@ extern const char * requestToString(int request); +/* TODO: Do we really need to redefine these? They aren't in a header... */ +typedef struct { + int requestNumber; + void (*dispatchFunction) (void *p, void *pRI); + int(*responseFunction) (void *p, void *response, size_t responselen); +} CommandInfo; + +typedef struct RequestInfo { + int32_t token; + CommandInfo *pCI; + struct RequestInfo *p_next; + char cancelled; + char local; + RIL_SOCKET_ID socket_id; + int wasAckSent; +} RequestInfo; + #endif /* __SECRIL_SHIM_H__ */ -- cgit v1.1