b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /****************************************************************************** |
| 2 | *(C) Copyright 2018 ASR Microelectronics |
| 3 | * All Rights Reserved |
| 4 | ******************************************************************************/ |
| 5 | /* ---------------------------------------------------------------------------- |
| 6 | * |
| 7 | * Filename: mbim_auth.c |
| 8 | * |
| 9 | * |
| 10 | * Description: all auth mbim related functions should be added here |
| 11 | * |
| 12 | * |
| 13 | * Notes: |
| 14 | * |
| 15 | ******************************************************************************/ |
| 16 | |
| 17 | #define LOG_TAG "MBIM" |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * Include files |
| 21 | ******************************************************************************/ |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <stddef.h> |
| 25 | |
| 26 | #include "mbim_types.h" |
| 27 | #include "mbim_util.h" |
| 28 | #include "mbim_auth.h" |
| 29 | #include "mbim_ril.h" |
| 30 | |
| 31 | #if defined MBIM_MTIL |
| 32 | #include "mbim_mtil.h" |
| 33 | #include "MtilAPI.h" |
| 34 | #endif |
| 35 | |
| 36 | #define MBIM_AUTH_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p) |
| 37 | |
| 38 | |
| 39 | |
| 40 | /****************************************************************************** |
| 41 | * Macros |
| 42 | ******************************************************************************/ |
| 43 | #define CREATE_AUTH_CONTEXT(pContext, mBuf) \ |
| 44 | pContext = (P_MBIM_MESSAGE_CONTEXT)MBIM_MALLOC(sizeof(MBIM_MESSAGE_CONTEXT)); \ |
| 45 | if (pContext != NULL) { \ |
| 46 | pContext->hdr.cid = cid; \ |
| 47 | pContext->hdr.transId = transactionId; \ |
| 48 | pContext->hdr.uuidIndex = UUID_AUTH_INDEX; \ |
| 49 | pContext->hdr.indication= MBIM_REQUEST; \ |
| 50 | pContext->body = mBuf; \ |
| 51 | pContext->cmd = NULL; \ |
| 52 | } \ |
| 53 | else { \ |
| 54 | if (mBuf != NULL) \ |
| 55 | MBIM_FREE(mBuf); \ |
| 56 | MBIM_LOGE("AUTH UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \ |
| 57 | return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \ |
| 58 | } |
| 59 | |
| 60 | |
| 61 | #define ALLOCATE_RESPONSE_BUFFER(mBuf_p, mSize) \ |
| 62 | mBuf_p = (char *)MBIM_MALLOC(mSize); \ |
| 63 | if (mBuf_p == NULL) { \ |
| 64 | MBIM_LOGE("AUTH UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \ |
| 65 | return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \ |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /****************************************************************************** |
| 70 | * #defines |
| 71 | ******************************************************************************/ |
| 72 | #define DEFAULT_CONTEXT_ALLOC_SIZE (4000) |
| 73 | |
| 74 | |
| 75 | /****************************************************************************** |
| 76 | * Global Variables |
| 77 | ******************************************************************************/ |
| 78 | extern MBIM_DATABASE mbimDb; |
| 79 | |
| 80 | |
| 81 | /****************************************************************************** |
| 82 | * Function prototypes |
| 83 | ******************************************************************************/ |
| 84 | int CID_AuthNotSupported(AUTH_CID_PARAMS); |
| 85 | int CID_AKAAuth(AUTH_CID_PARAMS); |
| 86 | int CID_AKAPAuth(AUTH_CID_PARAMS); |
| 87 | int CID_SIMAuth(AUTH_CID_PARAMS); |
| 88 | |
| 89 | /****************************************************************************** |
| 90 | * External variables |
| 91 | ******************************************************************************/ |
| 92 | authUuidProcessors authCidProcessor[UUID_CID_AUTH_MAX] = { |
| 93 | CID_AuthNotSupported, |
| 94 | CID_AKAAuth, |
| 95 | CID_AKAPAuth, |
| 96 | CID_SIMAuth, |
| 97 | }; |
| 98 | |
| 99 | |
| 100 | |
| 101 | /****************************************************************************** |
| 102 | * Code |
| 103 | ******************************************************************************/ |
| 104 | |
| 105 | |
| 106 | /*******************************************************************************\ |
| 107 | * Function: CID_AuthNotSupported |
| 108 | * Description: This function sends Error to HOST when a unknown command is received |
| 109 | * Parameters: dataBuf - String |
| 110 | * |
| 111 | * Returns: 0=OK, <0=Error Code |
| 112 | \*******************************************************************************/ |
| 113 | int CID_AuthNotSupported(AUTH_CID_PARAMS) |
| 114 | { |
| 115 | int rc = MBIM_OK; |
| 116 | |
| 117 | //Added for compilation uof unused parameters on Codeline |
| 118 | MBIM_AUTH_UNUSEDPARAM(); |
| 119 | |
| 120 | MBIM_LOGE("AUTH UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); |
| 121 | rc = MbimSendCommandDone(transactionId, UUID_AUTH_INDEX, |
| 122 | cid, MBIM_STATUS_NO_DEVICE_SUPPORT, 0 , NULL); |
| 123 | |
| 124 | return rc; |
| 125 | } |
| 126 | |
| 127 | int CID_AKAAuth(AUTH_CID_PARAMS) |
| 128 | { |
| 129 | int rc = MBIM_OK; |
| 130 | P_MBIM_MESSAGE_CONTEXT mContext = NULL; |
| 131 | char *buf; |
| 132 | |
| 133 | if (commandType != MBIM_QUERY_COMMAND) |
| 134 | { |
| 135 | return CID_AuthNotSupported(AUTH_CID_PARAMS_USAGE); |
| 136 | } |
| 137 | |
| 138 | //Allocate buffer for response |
| 139 | ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE); |
| 140 | |
| 141 | //Creat the context for this command |
| 142 | CREATE_AUTH_CONTEXT(mContext, buf); |
| 143 | |
| 144 | MbimTelRequestAkaAuth((void *)mContext, (void *)infoBuf_p); |
| 145 | |
| 146 | return rc; |
| 147 | } |
| 148 | |
| 149 | int CID_AKAPAuth(AUTH_CID_PARAMS) |
| 150 | { |
| 151 | int rc = MBIM_OK; |
| 152 | |
| 153 | //Added for compilation uof unused parameters on Codeline |
| 154 | MBIM_AUTH_UNUSEDPARAM(); |
| 155 | |
| 156 | MBIM_LOGE("AUTH UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); |
| 157 | rc = MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); //Send Error to MBIM |
| 158 | |
| 159 | return rc; |
| 160 | } |
| 161 | int CID_SIMAuth(AUTH_CID_PARAMS) |
| 162 | { |
| 163 | int rc = MBIM_OK; |
| 164 | P_MBIM_MESSAGE_CONTEXT mContext = NULL; |
| 165 | char *buf; |
| 166 | |
| 167 | if (commandType != MBIM_QUERY_COMMAND) |
| 168 | { |
| 169 | return CID_AuthNotSupported(AUTH_CID_PARAMS_USAGE); |
| 170 | } |
| 171 | |
| 172 | //Allocate buffer for response |
| 173 | ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE); |
| 174 | |
| 175 | //Creat the context for this command |
| 176 | CREATE_AUTH_CONTEXT(mContext, buf); |
| 177 | |
| 178 | MbimTelRequestSIMAuth((void *)mContext, (void *)infoBuf_p); |
| 179 | |
| 180 | return rc; |
| 181 | } |