ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/marvell/services/mbim/mbim_auth.c b/marvell/services/mbim/mbim_auth.c
new file mode 100644
index 0000000..22c44b3
--- /dev/null
+++ b/marvell/services/mbim/mbim_auth.c
@@ -0,0 +1,181 @@
+/******************************************************************************
+*(C) Copyright 2018 ASR Microelectronics
+* All Rights Reserved
+******************************************************************************/
+/* ----------------------------------------------------------------------------
+ *
+ *  Filename: mbim_auth.c
+ *
+ *
+ *  Description: all auth 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_auth.h"
+#include "mbim_ril.h"
+
+#if defined MBIM_MTIL
+#include "mbim_mtil.h"
+#include "MtilAPI.h"
+#endif
+
+#define MBIM_AUTH_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p)
+
+
+
+/******************************************************************************
+ *   Macros
+ ******************************************************************************/
+#define CREATE_AUTH_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_AUTH_INDEX;													\
+				pContext->hdr.indication= MBIM_REQUEST;														\
+				pContext->body 			= mBuf;																\
+				pContext->cmd			= NULL;																\
+			}																								\
+			else {																							\
+				if (mBuf != NULL)																			\
+					MBIM_FREE(mBuf);																		\
+				MBIM_LOGE("AUTH 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("AUTH 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_AuthNotSupported(AUTH_CID_PARAMS);
+int	CID_AKAAuth(AUTH_CID_PARAMS);
+int	CID_AKAPAuth(AUTH_CID_PARAMS);
+int	CID_SIMAuth(AUTH_CID_PARAMS);
+
+/******************************************************************************
+ *   External variables
+ ******************************************************************************/
+authUuidProcessors authCidProcessor[UUID_CID_AUTH_MAX] = {
+	CID_AuthNotSupported,
+	CID_AKAAuth,
+	CID_AKAPAuth,
+	CID_SIMAuth,
+};
+
+
+
+/******************************************************************************
+ *  Code
+ ******************************************************************************/
+
+
+/*******************************************************************************\
+*	Function:		CID_AuthNotSupported
+*	Description:	This function sends Error to HOST when a unknown command is received
+*	Parameters:   dataBuf - String
+*
+*	Returns:		0=OK, <0=Error Code
+\*******************************************************************************/
+int CID_AuthNotSupported(AUTH_CID_PARAMS)
+{
+	int rc = MBIM_OK;
+
+	//Added for compilation uof unused parameters on Codeline
+	MBIM_AUTH_UNUSEDPARAM();
+
+	MBIM_LOGE("AUTH UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType);
+	rc = MbimSendCommandDone(transactionId, UUID_AUTH_INDEX, 
+			cid, MBIM_STATUS_NO_DEVICE_SUPPORT, 0 , NULL);
+
+	return rc;
+}
+
+int	CID_AKAAuth(AUTH_CID_PARAMS)
+{
+	int rc = MBIM_OK;
+	P_MBIM_MESSAGE_CONTEXT mContext = NULL;
+	char *buf;
+
+	if (commandType != MBIM_QUERY_COMMAND)
+	{
+		return CID_AuthNotSupported(AUTH_CID_PARAMS_USAGE);
+	}
+
+	//Allocate buffer for response
+	ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
+
+	//Creat the context for this command
+	CREATE_AUTH_CONTEXT(mContext, buf);
+
+	MbimTelRequestAkaAuth((void *)mContext, (void *)infoBuf_p);
+
+	return rc;
+}
+
+int	CID_AKAPAuth(AUTH_CID_PARAMS)
+{
+	int rc = MBIM_OK;
+
+	//Added for compilation uof unused parameters on Codeline
+	MBIM_AUTH_UNUSEDPARAM();
+
+	MBIM_LOGE("AUTH 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;
+}
+int	CID_SIMAuth(AUTH_CID_PARAMS)
+{
+	int rc = MBIM_OK;
+	P_MBIM_MESSAGE_CONTEXT mContext = NULL;
+	char *buf;
+
+	if (commandType != MBIM_QUERY_COMMAND)
+	{
+		return CID_AuthNotSupported(AUTH_CID_PARAMS_USAGE);
+	}
+
+	//Allocate buffer for response
+	ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
+
+	//Creat the context for this command
+	CREATE_AUTH_CONTEXT(mContext, buf);
+
+	MbimTelRequestSIMAuth((void *)mContext, (void *)infoBuf_p);
+
+	return rc;
+}
\ No newline at end of file