| /****************************************************************************** |
| *(C) Copyright 2014 Marvell International Ltd. |
| * All Rights Reserved |
| ******************************************************************************/ |
| /* ------------------------------------------------------------------------------------------------------------------- |
| * |
| * Filename: mbim_ussd.c |
| * |
| * Authors: Adrian Zelezniak |
| * |
| * Description: all utiliy functions and macros needed for the MIBM translator |
| * |
| * HISTORY: |
| * Apr 3, 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_util.h" |
| #include "mbim_ussd.h" |
| |
| #if defined MBIM_MTIL |
| #include "mbim_mtil.h" |
| #include "MtilAPI.h" |
| #endif |
| |
| #ifndef MBIM_USSD_UNUSEDPARAM |
| #define MBIM_USSD_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p) |
| #endif |
| |
| |
| /****************************************************************************** |
| * Macros |
| ******************************************************************************/ |
| #define CREATE_USSD_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_USSD_INDEX; \ |
| pContext->hdr.indication= MBIM_REQUEST; \ |
| pContext->body = mBuf; \ |
| pContext->cmd = NULL; \ |
| } \ |
| else { \ |
| if (mBuf != NULL) \ |
| MBIM_FREE(mBuf); \ |
| MBIM_LOGE("USSD 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("USSD 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_UssdNotSupported(USSD_CID_PARAMS); |
| int CID_Ussd(USSD_CID_PARAMS); |
| |
| |
| /****************************************************************************** |
| * External variables |
| ******************************************************************************/ |
| ussdUuidProcessors ussdCidProcessor[UUID_USSD_CID_MAX] = { |
| CID_UssdNotSupported, //0 |
| CID_Ussd |
| }; |
| |
| |
| |
| /****************************************************************************** |
| * 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_UssdNotSupported(USSD_CID_PARAMS) |
| { |
| int rc = MBIM_OK; |
| |
| //Added for compilation uof unused parameters on Codeline |
| MBIM_USSD_UNUSEDPARAM(); |
| |
| MBIM_LOGE("USSD UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); |
| rc = MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); //Send Error to MBIM |
| |
| return rc; |
| } |
| |
| |
| |
| /*******************************************************************************\ |
| * Function: CID_Ussd |
| * Description: MBIM_CID_USSD (Chapter 10.5.21) |
| * Parameters: USSD_CID_PARAMS - See description at the start of file |
| * |
| * Returns: 0=OK, <0=Error Code |
| \*******************************************************************************/ |
| int CID_Ussd(USSD_CID_PARAMS) |
| { |
| //Added for compilation of unused parameters on Codeline |
| MBIM_USSD_UNUSEDPARAM(); |
| |
| #if defined MBIM_MTIL |
| int rc = MBIM_OK; |
| P_MBIM_MESSAGE_CONTEXT mContext = NULL; |
| P_MBIM_SET_USSD pSetUssd = NULL; |
| P_MBIM_USSD_INFO pUssdInfo = NULL; |
| char *buf; |
| |
| |
| //We only support Query for this command |
| if (commandType == MBIM_QUERY_COMMAND) |
| { |
| return CID_UssdNotSupported(USSD_CID_PARAMS_USAGE); |
| } |
| |
| //Allocate buffer for response |
| ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE); |
| |
| //Creat the context for this command |
| CREATE_USSD_CONTEXT(mContext, buf); |
| |
| //pick up pointer to command |
| pSetUssd = (P_MBIM_SET_USSD)infoBuf_p; |
| pUssdInfo = (P_MBIM_USSD_INFO)buf; |
| |
| //Get used Coding Scheme |
| pUssdInfo->ussdDataCodingScheme = pSetUssd->ussdDataCodingScheme; |
| |
| if (MBIMUSSDInitiate == pSetUssd->ussdAction) |
| { |
| //Send the CUSD |
| mtilSendCusdSet( (char *)mContext, pSetUssd->ussdDataCodingScheme, (char *)infoBuf_p + pSetUssd->ussdPayloadOffset, pSetUssd->ussdPayloadLength); |
| } |
| else |
| { |
| MBIM_LOGD("USSD Action: %d NOT SUPPORTED", pSetUssd->ussdAction); |
| MBIM_FREE_CONTEXT(mContext); |
| } |
| |
| return rc; |
| #else |
| return CID_UssdNotSupported(USSD_CID_PARAMS_USAGE); |
| #endif |
| } |