blob: 80882e131d9d35d37b692a5e111354584310bc67 [file] [log] [blame]
/******************************************************************************
*(C) Copyright 2018 ASR Microelectronics
* All Rights Reserved
******************************************************************************/
/* -------------------------------------------------------------------------------------------------------------------
*
* Filename: mbim_basic_connect_ext.c
*
* Authors: Lei yang
*
* Description: all auth mbim related functions should be added here
*
* HISTORY:
* Mar 28, 2018 - Initial Version
*
* Notes:
*
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include "mbim_types.h"
#include "mbim_util.h"
#include "mbim_basic_extension.h"
#include "mbim_ril.h"
#define MBIM_BASICEXT_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p)
/******************************************************************************
* Macros
******************************************************************************/
#define CREATE_BASICEXT_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_BASIC_CONNECT_EXTENSIONS_INDEX; \
pContext->hdr.indication= MBIM_REQUEST; \
pContext->body = mBuf; \
pContext->cmd = NULL; \
} \
else { \
if (mBuf != NULL) \
MBIM_FREE(mBuf); \
MBIM_LOGE("BASICEXT 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("BASICEXT UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
}
#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); \
if (context_p != NULL) \
MBIM_FREE(context_p); \
MBIM_LOGE("BASICEXT 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); \
context_p->cmd = mBuf_p; \
}
/******************************************************************************
* #defines
******************************************************************************/
#define DEFAULT_CONTEXT_ALLOC_SIZE (4000)
/******************************************************************************
* Global Variables
******************************************************************************/
/******************************************************************************
* Function prototypes
******************************************************************************/
int CID_BasicExtNotSupported(BASIC_CONNECT_EXT_CID_PARAMS);
int CID_MsProvisionedContextsV2(BASIC_CONNECT_EXT_CID_PARAMS);
int CID_MBIMVersion(BASIC_CONNECT_EXT_CID_PARAMS);
int CID_MS_ModemConfig(BASIC_CONNECT_EXT_CID_PARAMS);
int CID_MS_RegistrationParam(BASIC_CONNECT_EXT_CID_PARAMS);
/******************************************************************************
* External variables
******************************************************************************/
basicExtUuidProcessors basicExtCidProcessor[UUID_CID_BASICEXT_MAX] = {
CID_BasicExtNotSupported, /* 0 */
CID_MsProvisionedContextsV2, /* 1 */
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_BasicExtNotSupported,
CID_MBIMVersion, /* 15 */
CID_MS_ModemConfig, /* 16 */
CID_MS_RegistrationParam, /* 17 */
};
/******************************************************************************
* Code
******************************************************************************/
/*******************************************************************************\
* Function: CID_BasicExtNotSupported
* Description: This function sends Error to HOST when a unknown command is received
* Parameters: dataBuf - String
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_BasicExtNotSupported(BASIC_CONNECT_EXT_CID_PARAMS)
{
int rc = MBIM_OK;
//Added for compilation uof unused parameters on Codeline
MBIM_BASICEXT_UNUSEDPARAM();
MBIM_LOGE("BASIC CONNECT EXT UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType);
rc = MbimSendCommandDone(transactionId, UUID_BASIC_CONNECT_EXTENSIONS_INDEX,
cid, MBIM_STATUS_NO_DEVICE_SUPPORT, 0 , NULL);
return rc;
}
int CID_MsProvisionedContextsV2(BASIC_CONNECT_EXT_CID_PARAMS)
{
char *buf = NULL;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
int rc = MBIM_STATUS_SUCCESS;
MBIM_LOGD("CID_MsProvisionedContextsV2:commandType = %d", commandType);
if (commandType != MBIM_QUERY_COMMAND)
{
return CID_BasicExtNotSupported(BASIC_CONNECT_EXT_CID_PARAMS_USAGE);
}
//Added for compilation uof unused parameters on Codeline
MBIM_BASICEXT_UNUSEDPARAM();
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_BASICEXT_CONTEXT(mContext, buf);
MbimTelRequestDataCallList((void *)mContext);
return rc;
}
int CID_MBIMVersion(BASIC_CONNECT_EXT_CID_PARAMS)
{
char *buf = NULL;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
int rc = MBIM_STATUS_SUCCESS;
P_MBIM_VERSION_INFO pversion = NULL;
MBIM_LOGD("CID_Version:commandType = %d", commandType);
if (commandType != MBIM_QUERY_COMMAND)
{
return CID_BasicExtNotSupported(BASIC_CONNECT_EXT_CID_PARAMS_USAGE);
}
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
CREATE_BASICEXT_CONTEXT(mContext, buf);
pversion = (P_MBIM_VERSION_INFO)infoBuf_p;
MBIM_LOGD("OS support MBIMEx version:0x%x,0x%x", pversion->bcdMBIMVersion, pversion->bcdMBIMExtendedVersion);
MBIM_LOGD("Device support MBIMEx version:0x%x", mbimDb.mbimExVersion);
mbimDb.mbimNegVersion = MIN(mbimDb.mbimExVersion, pversion->bcdMBIMExtendedVersion);
pversion = (P_MBIM_VERSION_INFO)buf;
pversion->bcdMBIMVersion = 0x0100;
pversion->bcdMBIMExtendedVersion = mbimDb.mbimNegVersion;
rc = MbimSendCommandDone(mContext->hdr.transId,
mContext->hdr.uuidIndex,
mContext->hdr.cid,
(MBIM_STATUS_CODE_ENUM)rc,
sizeof(MBIM_VERSION_INFO), (char *)pversion);
MBIM_FREE_CONTEXT(mContext);
return rc;
}
int CID_MS_ModemConfig(BASIC_CONNECT_EXT_CID_PARAMS)
{
char *buf = NULL;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
int rc = MBIM_STATUS_SUCCESS;
MBIM_LOGD("CID_MS_MODEM_CONFIG:commandType = %d", commandType);
if (commandType != MBIM_QUERY_COMMAND)
{
return CID_BasicExtNotSupported(BASIC_CONNECT_EXT_CID_PARAMS_USAGE);
}
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
CREATE_BASICEXT_CONTEXT(mContext, buf);
rc = MbimTelRequestSimStatus(mContext);
return rc;
}
int CID_MS_RegistrationParam(BASIC_CONNECT_EXT_CID_PARAMS)
{
int rc = MBIM_STATUS_SUCCESS;
char *buf = NULL;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
CREATE_BASICEXT_CONTEXT(mContext, buf);
if (commandType == MBIM_SET_COMMAND)
{
ALLOCATE_CMD_BUFFER(mContext, mContext->cmd, infoBufLen);
memcpy( mContext->cmd, (char *)infoBuf_p, infoBufLen);
}
rc = MbimTelRequestMsRegParam(mContext, commandType, infoBufLen);
return rc;
}