RIL: Support SMS on IMS, DO NOT MERGE
RIL_REQUEST_IMS_REGISTRATION_STATE is used to aquire IMS registration state.
RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED is called when IMS registration
state has changed.
RIL_REQUEST_IMS_SEND_SMS is used to send MO SMS over IMS. However, if retry
field is set in case of failure, RIL_REQUEST_IMS_SEND_SMS sets messageRef from
RIL_SMS_RESPONSE of corresponding failed MO SMS, and sets retry field to
non-zero. If voice is available, sends RIL_REQUEST_IMS_SEND_SMS retries with
data encoded based on voice tech available.
Bug: 9626411
Change-Id: I87ca9841b4ace931c55e2d379fe6d7589b2dc8a5
diff --git a/include/telephony/ril.h b/include/telephony/ril.h
index 68656fa..9586254 100644
--- a/include/telephony/ril.h
+++ b/include/telephony/ril.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006 The Android Open Source Project
+ * Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +20,7 @@
#include <stdlib.h>
#include <stdint.h>
+#include <telephony/ril_cdma_sms.h>
#ifndef FEATURE_UNIT_TEST
#include <sys/time.h>
#endif /* !FEATURE_UNIT_TEST */
@@ -232,6 +234,28 @@
to point connections. */
} RIL_Data_Call_Response_v6;
+typedef enum {
+ RADIO_TECH_3GPP = 1, /* 3GPP Technologies - GSM, WCDMA */
+ RADIO_TECH_3GPP2 = 2 /* 3GPP2 Technologies - CDMA */
+} RIL_RadioTechnologyFamily;
+
+typedef struct {
+ RIL_RadioTechnologyFamily tech;
+ unsigned char retry; /* 0 == not retry, nonzero == retry */
+ int messageRef; /* Valid field if retry is set to nonzero.
+ Contains messageRef from RIL_SMS_Response
+ corresponding to failed MO SMS.
+ */
+
+ union {
+ /* Valid field if format is FORMAT_3GPP2. See RIL_REQUEST_CDMA_SEND_SMS */
+ RIL_CDMA_SMS_Message* cdmaMessage;
+
+ /* Valid field if format is FORMAT_3GPP. See RIL_REQUEST_SEND_SMS */
+ char** gsmMessage;
+ } message;
+} RIL_IMS_SMS_Message;
+
typedef struct {
int messageRef; /* TP-Message-Reference for GSM,
and BearerData MessageId for CDMA
@@ -3482,6 +3506,53 @@
*/
#define RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE 110
+/**
+ * RIL_REQUEST_IMS_REGISTRATION_STATE
+ *
+ * Request current IMS registration state
+ *
+ * "data" is NULL
+ *
+ * "response" is int *
+ * ((int *)response)[0] is registration state:
+ * 0 - Not registered
+ * 1 - Registered
+ *
+ * If ((int*)response)[0] is = 1, then ((int *) response)[1]
+ * must follow with IMS SMS format:
+ *
+ * ((int *) response)[1] is of type const RIL_IMS_SMS_Format
+ *
+ * Valid errors:
+ * SUCCESS
+ * RADIO_NOT_AVAILABLE
+ * GENERIC_FAILURE
+ */
+#define RIL_REQUEST_IMS_REGISTRATION_STATE 111
+
+/**
+ * RIL_REQUEST_IMS_SEND_SMS
+ *
+ * Send a SMS message over IMS
+ *
+ * "data" is const RIL_IMS_SMS_Message *
+ *
+ * "response" is a const RIL_SMS_Response *
+ *
+ * Based on the return error, caller decides to resend if sending sms
+ * fails. SMS_SEND_FAIL_RETRY means retry, and other errors means no retry.
+ * In case of retry, data is encoded based on Voice Technology available.
+ *
+ * Valid errors:
+ * SUCCESS
+ * RADIO_NOT_AVAILABLE
+ * SMS_SEND_FAIL_RETRY
+ * FDN_CHECK_FAILURE
+ * GENERIC_FAILURE
+ *
+ */
+#define RIL_REQUEST_IMS_SEND_SMS 112
+
/***********************************************************************/
@@ -3972,6 +4043,20 @@
*/
#define RIL_UNSOL_CELL_INFO_LIST 1036
+/**
+ * RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED
+ *
+ * Called when IMS registration state has changed
+ *
+ * Callee will invoke the following requests on main thread:
+ *
+ * RIL_REQUEST_IMS_REGISTRATION_STATE
+ *
+ * "data" is NULL
+ *
+ */
+#define RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED 1037
+
/***********************************************************************/
diff --git a/libril/ril.cpp b/libril/ril.cpp
index e1877a1..04ca858 100644
--- a/libril/ril.cpp
+++ b/libril/ril.cpp
@@ -1,6 +1,7 @@
/* //device/libs/telephony/ril.cpp
**
** Copyright 2006, The Android Open Source Project
+** Copyright (c) 2012, The Linux Foundation. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -207,6 +208,9 @@
static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
+static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
+static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
+static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
@@ -878,9 +882,8 @@
return;
}
-static void
-dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
- RIL_CDMA_SMS_Message rcsm;
+static status_t
+constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
int32_t t;
uint8_t ut;
status_t status;
@@ -944,7 +947,7 @@
}
if (status != NO_ERROR) {
- goto invalid;
+ return status;
}
startRequest;
@@ -956,6 +959,18 @@
printRequest(pRI->token, pRI->pCI->requestNumber);
+ return status;
+}
+
+static void
+dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
+ RIL_CDMA_SMS_Message rcsm;
+
+ ALOGD("dispatchCdmaSms");
+ if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
+ goto invalid;
+ }
+
s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
#ifdef MEMSET_FREED
@@ -970,6 +985,149 @@
}
static void
+dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
+ RIL_IMS_SMS_Message rism;
+ RIL_CDMA_SMS_Message rcsm;
+
+ ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
+
+ if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
+ goto invalid;
+ }
+ memset(&rism, 0, sizeof(rism));
+ rism.tech = RADIO_TECH_3GPP2;
+ rism.retry = retry;
+ rism.messageRef = messageRef;
+ rism.message.cdmaMessage = &rcsm;
+
+ s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
+ sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
+ +sizeof(rcsm),pRI);
+
+#ifdef MEMSET_FREED
+ memset(&rcsm, 0, sizeof(rcsm));
+ memset(&rism, 0, sizeof(rism));
+#endif
+
+ return;
+
+invalid:
+ invalidCommandBlock(pRI);
+ return;
+}
+
+static void
+dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
+ RIL_IMS_SMS_Message rism;
+ int32_t countStrings;
+ status_t status;
+ size_t datalen;
+ char **pStrings;
+ ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
+
+ status = p.readInt32 (&countStrings);
+
+ if (status != NO_ERROR) {
+ goto invalid;
+ }
+
+ memset(&rism, 0, sizeof(rism));
+ rism.tech = RADIO_TECH_3GPP;
+ rism.retry = retry;
+ rism.messageRef = messageRef;
+
+ startRequest;
+ appendPrintBuf("%sformat=%d,", printBuf, rism.tech);
+ if (countStrings == 0) {
+ // just some non-null pointer
+ pStrings = (char **)alloca(sizeof(char *));
+ datalen = 0;
+ } else if (((int)countStrings) == -1) {
+ pStrings = NULL;
+ datalen = 0;
+ } else {
+ datalen = sizeof(char *) * countStrings;
+
+ pStrings = (char **)alloca(datalen);
+
+ for (int i = 0 ; i < countStrings ; i++) {
+ pStrings[i] = strdupReadString(p);
+ appendPrintBuf("%s%s,", printBuf, pStrings[i]);
+ }
+ }
+ removeLastChar;
+ closeRequest;
+ printRequest(pRI->token, pRI->pCI->requestNumber);
+
+ rism.message.gsmMessage = pStrings;
+ s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
+ sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
+ +datalen, pRI);
+
+ if (pStrings != NULL) {
+ for (int i = 0 ; i < countStrings ; i++) {
+#ifdef MEMSET_FREED
+ memsetString (pStrings[i]);
+#endif
+ free(pStrings[i]);
+ }
+
+#ifdef MEMSET_FREED
+ memset(pStrings, 0, datalen);
+#endif
+ }
+
+#ifdef MEMSET_FREED
+ memset(&rism, 0, sizeof(rism));
+#endif
+ return;
+invalid:
+ ALOGE("dispatchImsGsmSms invalid block");
+ invalidCommandBlock(pRI);
+ return;
+}
+
+static void
+dispatchImsSms(Parcel &p, RequestInfo *pRI) {
+ int32_t t;
+ status_t status = p.readInt32(&t);
+ RIL_RadioTechnologyFamily format;
+ uint8_t retry;
+ int32_t messageRef;
+
+ ALOGD("dispatchImsSms");
+ if (status != NO_ERROR) {
+ goto invalid;
+ }
+ format = (RIL_RadioTechnologyFamily) t;
+
+ // read retry field
+ status = p.read(&retry,sizeof(retry));
+ if (status != NO_ERROR) {
+ goto invalid;
+ }
+ // read messageRef field
+ status = p.read(&messageRef,sizeof(messageRef));
+ if (status != NO_ERROR) {
+ goto invalid;
+ }
+
+ if (RADIO_TECH_3GPP == format) {
+ dispatchImsGsmSms(p, pRI, retry, messageRef);
+ } else if (RADIO_TECH_3GPP2 == format) {
+ dispatchImsCdmaSms(p, pRI, retry, messageRef);
+ } else {
+ ALOGE("requestImsSendSMS invalid format value =%d", format);
+ }
+
+ return;
+
+invalid:
+ invalidCommandBlock(pRI);
+ return;
+}
+
+static void
dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
RIL_CDMA_SMS_Ack rcsa;
int32_t t;
@@ -3601,6 +3759,8 @@
case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
+ case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
+ case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
@@ -3637,6 +3797,7 @@
case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
+ case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
default: return "<unknown request>";
}
}
diff --git a/libril/ril_commands.h b/libril/ril_commands.h
index 0519a2a..bc1c7f3 100644
--- a/libril/ril_commands.h
+++ b/libril/ril_commands.h
@@ -1,6 +1,7 @@
/* //device/libs/telephony/ril_commands.h
**
** Copyright 2006, The Android Open Source Project
+** Copyright (c) 2012, The Linux Foundation. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -125,3 +126,5 @@
{RIL_REQUEST_VOICE_RADIO_TECH, dispatchVoiceRadioTech, responseInts},
{RIL_REQUEST_GET_CELL_INFO_LIST, dispatchVoid, responseCellInfoList},
{RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, dispatchInts, responseVoid},
+ {RIL_REQUEST_IMS_REGISTRATION_STATE, dispatchVoid, responseInts},
+ {RIL_REQUEST_IMS_SEND_SMS, dispatchImsSms, responseSMS},
diff --git a/libril/ril_unsol_commands.h b/libril/ril_unsol_commands.h
index 0711225..b491cf2 100644
--- a/libril/ril_unsol_commands.h
+++ b/libril/ril_unsol_commands.h
@@ -1,6 +1,7 @@
/* //device/libs/telephony/ril_unsol_commands.h
**
** Copyright 2006, The Android Open Source Project
+** Copyright (c) 2012, The Linux Foundation. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -51,3 +52,4 @@
{RIL_UNSOL_RIL_CONNECTED, responseInts, WAKE_PARTIAL},
{RIL_UNSOL_VOICE_RADIO_TECH_CHANGED, responseInts, WAKE_PARTIAL},
{RIL_UNSOL_CELL_INFO_LIST, responseCellInfoList, WAKE_PARTIAL},
+ {RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
diff --git a/reference-ril/reference-ril.c b/reference-ril/reference-ril.c
index 77c6f31..7253eb0 100644
--- a/reference-ril/reference-ril.c
+++ b/reference-ril/reference-ril.c
@@ -1,6 +1,7 @@
/* //device/system/reference-ril/reference-ril.c
**
** Copyright 2006, The Android Open Source Project
+** Copyright (c) 2012, The Linux Foundation. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -211,6 +212,14 @@
static const struct timeval TIMEVAL_CALLSTATEPOLL = {0,500000};
static const struct timeval TIMEVAL_0 = {0,0};
+static int s_ims_registered = 0; // 0==unregistered
+static int s_ims_services = 1; // & 0x1 == sms over ims supported
+static int s_ims_format = 1; // FORMAT_3GPP(1) vs FORMAT_3GPP2(2);
+static int s_ims_cause_retry = 0; // 1==causes sms over ims to temp fail
+static int s_ims_cause_perm_failure = 0; // 1==causes sms over ims to permanent fail
+static int s_ims_gsm_retry = 0; // 1==causes sms over gsm to temp fail
+static int s_ims_gsm_fail = 0; // 1==causes sms over gsm to permanent fail
+
#ifdef WORKAROUND_ERRONEOUS_ANSWER
// Max number of times we'll try to repoll when we think
// we have a AT+CLCC race condition
@@ -1499,12 +1508,14 @@
// But it is not implemented yet.
memset(&response, 0, sizeof(response));
+ response.messageRef = 1;
RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response));
return;
error:
// Cdma Send SMS will always cause send retry error.
- RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, NULL, 0);
+ response.messageRef = -1;
+ RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, &response, sizeof(response));
}
static void requestSendSMS(void *data, size_t datalen, RIL_Token t)
@@ -1517,6 +1528,12 @@
RIL_SMS_Response response;
ATResponse *p_response = NULL;
+ memset(&response, 0, sizeof(response));
+ ALOGD("requestSendSMS datalen =%d", datalen);
+
+ if (s_ims_gsm_fail != 0) goto error;
+ if (s_ims_gsm_retry != 0) goto error2;
+
smsc = ((const char **)data)[0];
pdu = ((const char **)data)[1];
@@ -1534,17 +1551,68 @@
if (err != 0 || p_response->success == 0) goto error;
- memset(&response, 0, sizeof(response));
-
/* FIXME fill in messageRef and ackPDU */
-
+ response.messageRef = 1;
RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response));
at_response_free(p_response);
return;
error:
- RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
+ response.messageRef = -2;
+ RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, &response, sizeof(response));
at_response_free(p_response);
+ return;
+error2:
+ // send retry error.
+ response.messageRef = -1;
+ RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, &response, sizeof(response));
+ at_response_free(p_response);
+ return;
+}
+
+static void requestImsSendSMS(void *data, size_t datalen, RIL_Token t)
+{
+ RIL_IMS_SMS_Message *p_args;
+ RIL_SMS_Response response;
+
+ memset(&response, 0, sizeof(response));
+
+ ALOGD("requestImsSendSMS: datalen=%d, "
+ "registered=%d, service=%d, format=%d, ims_perm_fail=%d, "
+ "ims_retry=%d, gsm_fail=%d, gsm_retry=%d",
+ datalen, s_ims_registered, s_ims_services, s_ims_format,
+ s_ims_cause_perm_failure, s_ims_cause_retry, s_ims_gsm_fail,
+ s_ims_gsm_retry);
+
+ // figure out if this is gsm/cdma format
+ // then route it to requestSendSMS vs requestCdmaSendSMS respectively
+ p_args = (RIL_IMS_SMS_Message *)data;
+
+ if (0 != s_ims_cause_perm_failure ) goto error;
+
+ // want to fail over ims and this is first request over ims
+ if (0 != s_ims_cause_retry && 0 == p_args->retry) goto error2;
+
+ if (RADIO_TECH_3GPP == p_args->tech) {
+ return requestSendSMS(p_args->message.gsmMessage,
+ datalen - sizeof(RIL_RadioTechnologyFamily),
+ t);
+ } else if (RADIO_TECH_3GPP2 == p_args->tech) {
+ return requestCdmaSendSMS(p_args->message.cdmaMessage,
+ datalen - sizeof(RIL_RadioTechnologyFamily),
+ t);
+ } else {
+ ALOGE("requestImsSendSMS invalid format value =%d", p_args->tech);
+ }
+
+error:
+ response.messageRef = -2;
+ RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, &response, sizeof(response));
+ return;
+
+error2:
+ response.messageRef = -1;
+ RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, &response, sizeof(response));
}
static void requestSetupDataCall(void *data, size_t datalen, RIL_Token t)
@@ -2051,6 +2119,9 @@
case RIL_REQUEST_CDMA_SEND_SMS:
requestCdmaSendSMS(data, datalen, t);
break;
+ case RIL_REQUEST_IMS_SEND_SMS:
+ requestImsSendSMS(data, datalen, t);
+ break;
case RIL_REQUEST_SETUP_DATA_CALL:
requestSetupDataCall(data, datalen, t);
break;
@@ -2168,6 +2239,28 @@
requestEnterSimPin(data, datalen, t);
break;
+ case RIL_REQUEST_IMS_REGISTRATION_STATE:
+ {
+ int reply[2];
+ //0==unregistered, 1==registered
+ reply[0] = s_ims_registered;
+
+ //to be used when changed to include service supporated info
+ //reply[1] = s_ims_services;
+
+ // FORMAT_3GPP(1) vs FORMAT_3GPP2(2);
+ reply[1] = s_ims_format;
+
+ ALOGD("IMS_REGISTRATION=%d, format=%d ",
+ reply[0], reply[1]);
+ if (reply[1] != -1) {
+ RIL_onRequestComplete(t, RIL_E_SUCCESS, reply, sizeof(reply));
+ } else {
+ RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
+ }
+ break;
+ }
+
case RIL_REQUEST_VOICE_RADIO_TECH:
{
int tech = techFromModemType(TECH(sMdmInfo));
@@ -2927,6 +3020,18 @@
pthread_mutex_unlock(&s_state_mutex);
}
+static void sendUnsolImsNetworkStateChanged()
+{
+#if 0 // to be used when unsol is changed to return data.
+ int reply[2];
+ reply[0] = s_ims_registered;
+ reply[1] = s_ims_services;
+ reply[1] = s_ims_format;
+#endif
+ RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED,
+ NULL, 0);
+}
+
/**
* Called by atchannel when an unsolicited line appears
* This is called on atchannel's reader thread. AT commands may