blob: b9d349430dea23dd3b2cf4292d6a9e1eb76c12a9 [file] [log] [blame]
/******************************************************************************
*(C) Copyright 2014 Marvell International Ltd.
* All Rights Reserved
******************************************************************************/
/* -------------------------------------------------------------------------------------------------------------------
*
* Filename: mbim_util.c
*
* Authors: Adrian Zelezniak
*
* Description: all utiliy functions and macros needed for the MIBM translator
*
* HISTORY:
* Jan 7, 2014 - Initial Version
*
* Notes:
*
******************************************************************************/
#define LOG_TAG "MBIM"
/******************************************************************************
* Include files
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include "mbim_types.h"
#include "mbim_basic.h"
#include "mbim_sms.h"
#include "mbim_util.h"
#include "mbim_ril.h"
#ifndef MBIM_SMS_UNUSEDPARAM
#define MBIM_SMS_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p)
#endif
/******************************************************************************
* Macros
******************************************************************************/
#define CREATE_SMS_CONNECT_CONTEXT(pContext, mBuf) \
pContext = (P_MBIM_MESSAGE_CONTEXT)MBIM_MALLOC(sizeof(MBIM_MESSAGE_CONTEXT)); \
if (pContext != NULL) { \
pContext->hdr.cid = cid; \
pContext->hdr.transId = transactionId; \
pContext->hdr.uuidIndex = UUID_SMS_INDEX; \
pContext->hdr.indication= MBIM_REQUEST; \
pContext->body = mBuf; \
pContext->cmd = NULL; \
} \
else { \
if (mBuf != NULL) \
MBIM_FREE(mBuf); \
MBIM_LOGE("SMS UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
}
#define ALLOCATE_RESPONSE_BUFFER(mBuf_p, mSize) \
mBuf_p = (char *)MBIM_MALLOC(mSize); \
if (mBuf_p == NULL) { \
MBIM_LOGE("SMS UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
} \
else \
memset(mBuf_p, 0, mSize);
#define ALLOCATE_CMD_BUFFER(context_p, mBuf_p, mSize) \
mBuf_p = (char *)MBIM_MALLOC(mSize); \
if (mBuf_p == NULL) { \
if (context_p->body != NULL) \
MBIM_FREE(context_p->body); \
MBIM_LOGE("SMS UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
} \
context_p->cmd = mBuf_p;
/******************************************************************************
* #defines
******************************************************************************/
#define DEFAULT_CONTEXT_ALLOC_SIZE (4000)
/******************************************************************************
* Global Variables
******************************************************************************/
extern MBIM_DATABASE mbimDb;
/******************************************************************************
* Function prototypes
******************************************************************************/
int CID_SmsNotSupported(SMS_CID_PARAMS);
int CID_SmsConfiguration(SMS_CID_PARAMS);
int CID_SmsRead(SMS_CID_PARAMS);
int CID_SmsSend(SMS_CID_PARAMS);
int CID_SmsDelete(SMS_CID_PARAMS);
int CID_SmsMessageStoreStatus(SMS_CID_PARAMS);
/******************************************************************************
* External variables
******************************************************************************/
smsUuidProcessors smsCidProcessor[UUID_SMS_CID_MAX] = {
CID_SmsNotSupported, //0
CID_SmsConfiguration,
CID_SmsRead,
CID_SmsSend,
CID_SmsDelete,
CID_SmsMessageStoreStatus
};
/******************************************************************************
* Code
******************************************************************************/
/*******************************************************************************\
* Function: CID_SmsNotSupported
* Description: This function sends Error to HOST when a unknown command is received
* Parameters: dataBuf - String
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_SmsNotSupported(SMS_CID_PARAMS)
{
int rc = MBIM_OK;
//Added for compilation uof unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
MBIM_LOGE("SMS UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType);
rc = MbimSendCommandDone(transactionId, UUID_SMS_INDEX,
cid, MBIM_STATUS_NO_DEVICE_SUPPORT, 0 , NULL);
return rc;
}
/*******************************************************************************\
* Function: CID_SmsConfiguration
* Description: MBIM_CID_SMS_CONFIGURATION (Chapter 10.5.15)
* Parameters: SMS_CID_PARAMS - See description at the start of file
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_SmsConfiguration(SMS_CID_PARAMS)
{
//Added for compilation of unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
char *buf;
//We only support Query for this command
if (commandType != MBIM_SET_COMMAND)
{
return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
}
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
MbimTelRequestGetSmsConfig((void *)mContext);
return rc;
}
/*******************************************************************************\
* Function: CID_SmsRead
* Description: MBIM_CID_SMS_READ (Chapter 10.5.16)
* Parameters: SMS_CID_PARAMS - See description at the start of file
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_SmsRead(SMS_CID_PARAMS)
{
//Added for compilation of unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
P_MBIM_CID_SMS_READ pSmsRead = NULL;
char *buf;
//Added for compilation of unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
//We only support Query for this command
if (commandType != MBIM_QUERY_COMMAND)
{
return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
}
//Pick up pointer to SMS read query
pSmsRead = (P_MBIM_CID_SMS_READ)infoBuf_p;
//We support only PDU message type
if ( pSmsRead->smsFormat == MBIMSmsFormatPdu)
{
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
if (pSmsRead->flag == MBIMSmsFlagIndex)
{
//Save command for data extraction at response
ALLOCATE_CMD_BUFFER(mContext, mContext->cmd, infoBufLen);
memcpy( mContext->cmd, (char *)infoBuf_p, infoBufLen);
MbimTelSendCmgrSet((void *)mContext, pSmsRead->messageIndex);
}
else
{
/* NOT SUPPORT->READ All SMS!!! */
MBIM_FREE(buf);
rc = CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
}
}
else
{
//Send the Command Done back to MBIM Host
MbimSendCommandDone( transactionId,
UUID_SMS_INDEX,
cid,
MBIM_STATUS_SMS_FORMAT_NOT_SUPPORTED,
0,
NULL);
}
return rc;
}
/*******************************************************************************\
* Function: CID_SmsSend
* Description: MBIM_CID_SMS_SEND (Chapter 10.5.17)
* Parameters: SMS_CID_PARAMS - See description at the start of file
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_SmsSend(SMS_CID_PARAMS)
{
//Added for compilation uof unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
P_MBIM_SET_SMS_SEND pSetSmsSend = NULL;
P_MBIM_SMS_SEND_PDU pSmsSendPdu = NULL;
char *buf;
//We only support Query for this command
if (commandType != MBIM_SET_COMMAND)
{
return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
}
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
//Pick up pointer to SMS delete set command
pSetSmsSend = (P_MBIM_SET_SMS_SEND)infoBuf_p;
pSmsSendPdu = (P_MBIM_SMS_SEND_PDU)(&pSetSmsSend->dataBuffer);
//Send SMS
MbimTelSendCmgsSet((void *)mContext, (char *)pSmsSendPdu + pSmsSendPdu->pduDataOffset, pSmsSendPdu->pduDataSize);
return rc;
}
/*******************************************************************************\
* Function: CID_SmsDelete
* Description: MBIM_CID_SMS_DELETE (Chapter 10.5.18)
* Parameters: SMS_CID_PARAMS - See description at the start of file
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_SmsDelete(SMS_CID_PARAMS)
{
//Added for compilation uof unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
P_MBIM_SET_SMS_DELETE pSetSmsDelete = NULL;
char *buf;
//We only support Query for this command
if (commandType != MBIM_SET_COMMAND)
{
return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
}
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
//Pick up pointer to SMS delete set command
pSetSmsDelete = (P_MBIM_SET_SMS_DELETE)infoBuf_p;
//send Delete message to MTIL
MbimTelSendCmgdSet((void *)mContext, pSetSmsDelete->MessageIndex, pSetSmsDelete->flags);
return rc;
}
/*******************************************************************************\
* Function: CID_SmsMessageStoreStatus
* Description: MBIM_CID_SMS_MESSAGE_STORE_STATUS (Chapter 10.5.19)
* Parameters: SMS_CID_PARAMS - See description at the start of file
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_SmsMessageStoreStatus(SMS_CID_PARAMS)
{
//Added for compilation uof unused parameters on Codeline
MBIM_SMS_UNUSEDPARAM();
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
char *buf;
if (commandType != MBIM_QUERY_COMMAND)
{
return CID_SmsNotSupported(SMS_CID_PARAMS_USAGE);
}
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
MbimTelSmsStoreStatus((void *)mContext);
return rc;
}