Skip to content

Commit

Permalink
RIL: Support SMS over IMS
Browse files Browse the repository at this point in the history
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: If0ecc9fa47661f6560171e472f3c464713e97968
  • Loading branch information
Sukanya Rajkhowa authored and Ed Tam committed Oct 10, 2013
1 parent 3492c6e commit a18b9d1
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 10 deletions.
88 changes: 87 additions & 1 deletion include/telephony/ril.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 */
Expand All @@ -27,7 +28,7 @@
extern "C" {
#endif

#define RIL_VERSION 8 /* Current version */
#define RIL_VERSION 9 /* Current version */
#define RIL_VERSION_MIN 6 /* Minimum RIL_VERSION supported */

#define CDMA_ALPHA_INFO_BUFFER_LENGTH 64
Expand Down Expand Up @@ -233,6 +234,28 @@ typedef struct {
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 tech is RADIO_TECH_3GPP2. See RIL_REQUEST_CDMA_SEND_SMS */
RIL_CDMA_SMS_Message* cdmaMessage;

/* Valid field if tech is RADIO_TECH_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
Expand Down Expand Up @@ -3498,6 +3521,50 @@ typedef struct {
*/
#define RIL_REQUEST_SET_INITIAL_ATTACH_APN 111

/**
* 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
* ((int *)response)[1] is bitmap of the supported services:
* & 0x1 - SMS supported
*
* If IMS is registered and supports SMS, then ((int *) response)[2]
* must follow with IMS SMS format:
*
* ((int *) response)[2] is of type const RIL_IMS_SMS_Format
*/
#define RIL_REQUEST_IMS_REGISTRATION_STATE 112

/**
* 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 113

/***********************************************************************/


Expand Down Expand Up @@ -3988,6 +4055,25 @@ typedef struct {
*/
#define RIL_UNSOL_CELL_INFO_LIST 1036

/*
* RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED
*
* Called when IMS registration state has changed
*
* "data" is int *
* ((int *)response)[0] is registration state:
* 0 - Not registered
* 1 - Registered
* ((int *)response)[1] is bitmap of the services supported:
* & 0x1 - SMS supported
*
* If IMS is registered and supports SMS, then ((int *) response)[2]
* must follow with IMS SMS format:
*
* ((int *) response)[2] is of type const RIL_IMS_SMS_Format
*/
#define RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED 1037

/***********************************************************************/


Expand Down
168 changes: 164 additions & 4 deletions libril/ril.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
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);
Expand Down Expand Up @@ -879,9 +882,8 @@ dispatchRaw(Parcel &p, RequestInfo *pRI) {
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;
Expand Down Expand Up @@ -945,7 +947,7 @@ dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
}

if (status != NO_ERROR) {
goto invalid;
return status;
}

startRequest;
Expand All @@ -957,6 +959,18 @@ dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {

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
Expand All @@ -970,6 +984,149 @@ dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
return;
}

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.format);
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;
Expand Down Expand Up @@ -3653,6 +3810,8 @@ requestToString(int request) {
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_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
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";
Expand Down Expand Up @@ -3689,6 +3848,7 @@ requestToString(int request) {
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>";
}
}
Expand Down
2 changes: 2 additions & 0 deletions libril/ril_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@
{RIL_REQUEST_GET_CELL_INFO_LIST, dispatchVoid, responseCellInfoList},
{RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, dispatchInts, responseVoid},
{RIL_REQUEST_SET_INITIAL_ATTACH_APN, dispatchSetInitialAttachApn, responseVoid},
{RIL_REQUEST_IMS_REGISTRATION_STATE, dispatchVoid, responseInts},
{RIL_REQUEST_IMS_SEND_SMS, dispatchImsSms, responseSMS},
1 change: 1 addition & 0 deletions libril/ril_unsol_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,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},
Loading

0 comments on commit a18b9d1

Please sign in to comment.