blob: 372c0c6ebe8b5881fea665cd7e6bdfc47fe9d799 [file] [log] [blame]
/******************************************************************************
*(C) Copyright 2018 ASR Microelectronics
* All Rights Reserved
******************************************************************************/
/* ----------------------------------------------------------------------------
*
* Filename: mbim_stk.c
*
*
* Description: all stk mbim related functions should be added here
*
*
* Notes:
*
******************************************************************************/
#define LOG_TAG "MBIM"
/******************************************************************************
* Include files
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include "mbim_types.h"
#include "mbim_util.h"
#include "mbim_stk.h"
#include "mbim_ril.h"
#if defined MBIM_MTIL
#include "mbim_mtil.h"
#include "MtilAPI.h"
#endif
#ifndef MBIM_STK_UNUSEDPARAM
#define MBIM_STK_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p)
#endif
/******************************************************************************
* Macros
******************************************************************************/
#define CREATE_STK_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_STK_INDEX; \
pContext->hdr.indication= MBIM_REQUEST; \
pContext->body = mBuf; \
pContext->cmd = NULL; \
} \
else { \
if (mBuf != NULL) \
MBIM_FREE(mBuf); \
MBIM_LOGE("STK 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("STK UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
}
/******************************************************************************
* #defines
******************************************************************************/
#define DEFAULT_CONTEXT_ALLOC_SIZE (4000)
/******************************************************************************
* Global Variables
******************************************************************************/
extern MBIM_DATABASE mbimDb;
/******************************************************************************
* Function prototypes
******************************************************************************/
int CID_StkNotSupported(STK_CID_PARAMS);
int CID_StkPac(STK_CID_PARAMS);
int CID_StkTerminalResponse(STK_CID_PARAMS);
int CID_StkEnvelope(STK_CID_PARAMS);
/******************************************************************************
* External variables
******************************************************************************/
stkUuidProcessors stkCidProcessor[UUID_CID_STK_MAX] = {
CID_StkNotSupported, //0
CID_StkPac,
CID_StkTerminalResponse,
CID_StkEnvelope,
};
/******************************************************************************
* Code
******************************************************************************/
/*******************************************************************************\
* Function: CID_UssdNotSupported
* Description: This function sends Error to HOST when a unknown command is received
* Parameters: dataBuf - String
*
* Returns: 0=OK, <0=Error Code
\*******************************************************************************/
int CID_StkNotSupported(STK_CID_PARAMS)
{
int rc = MBIM_OK;
//Added for compilation uof unused parameters on Codeline
MBIM_STK_UNUSEDPARAM();
MBIM_LOGE("STK UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType);
//rc = MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); //Send Error to MBIM
rc = MbimSendCommandDone(transactionId, UUID_STK_INDEX,
cid, MBIM_STATUS_NO_DEVICE_SUPPORT, 0 , NULL);
return rc;
}
int CID_StkPac(STK_CID_PARAMS)
{
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
char *buf;
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_STK_CONTEXT(mContext, buf);
if (commandType == MBIM_SET_COMMAND)
MbimTelRequestStkPac((void *)mContext, (void *)infoBuf_p);
else
MbimTelRequestStkPac((void *)mContext, NULL);
return rc;
}
int CID_StkTerminalResponse(STK_CID_PARAMS)
{
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
char *buf;
if (commandType != MBIM_SET_COMMAND)
{
return CID_StkNotSupported(STK_CID_PARAMS_USAGE);
}
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_STK_CONTEXT(mContext, buf);
MbimTelRequestStkTR((void *)mContext, (void *)infoBuf_p);
return rc;
}
int CID_StkEnvelope(STK_CID_PARAMS)
{
int rc = MBIM_OK;
P_MBIM_MESSAGE_CONTEXT mContext = NULL;
char *buf;
//Allocate buffer for response
ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
//Creat the context for this command
CREATE_STK_CONTEXT(mContext, buf);
if (commandType == MBIM_SET_COMMAND)
MbimTelRequestStkEnv((void *)mContext, (void *)infoBuf_p);
else
MbimTelRequestStkEnv((void *)mContext, NULL);
return rc;
}