blob: b9d349430dea23dd3b2cf4292d6a9e1eb76c12a9 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/******************************************************************************
2*(C) Copyright 2014 Marvell International Ltd.
3* All Rights Reserved
4******************************************************************************/
5/* -------------------------------------------------------------------------------------------------------------------
6 *
7 * Filename: mbim_util.c
8 *
9 * Authors: Adrian Zelezniak
10 *
11 * Description: all utiliy functions and macros needed for the MIBM translator
12 *
13 * HISTORY:
14 * Jan 7, 2014 - Initial Version
15 *
16 * Notes:
17 *
18 ******************************************************************************/
19#define LOG_TAG "MBIM"
20
21/******************************************************************************
22 * Include files
23 ******************************************************************************/
24#include <stdio.h>
25#include <stdlib.h>
26#include <stddef.h>
27
28#include "mbim_types.h"
29#include "mbim_basic.h"
30#include "mbim_sms.h"
31#include "mbim_util.h"
32#include "mbim_ril.h"
33
34
35#ifndef MBIM_SMS_UNUSEDPARAM
36#define MBIM_SMS_UNUSEDPARAM() ((void) cid);((void) transactionId);((void) commandType);((void) infoBufLen);((void) infoBuf_p)
37#endif
38
39
40/******************************************************************************
41 * Macros
42 ******************************************************************************/
43#define CREATE_SMS_CONNECT_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_SMS_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("SMS 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("SMS UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
65 return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
66 } \
67 else \
68 memset(mBuf_p, 0, mSize);
69
70
71#define ALLOCATE_CMD_BUFFER(context_p, mBuf_p, mSize) \
72 mBuf_p = (char *)MBIM_MALLOC(mSize); \
73 if (mBuf_p == NULL) { \
74 if (context_p->body != NULL) \
75 MBIM_FREE(context_p->body); \
76 MBIM_LOGE("SMS UUID: OUT OF MEMORY CID %d (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType); \
77 return MbimSendFunctionErrorMsg(transactionId, MBIM_ERROR_UNKNOWN); \
78 } \
79 context_p->cmd = mBuf_p;
80
81
82/******************************************************************************
83 * #defines
84 ******************************************************************************/
85#define DEFAULT_CONTEXT_ALLOC_SIZE (4000)
86
87
88/******************************************************************************
89 * Global Variables
90 ******************************************************************************/
91extern MBIM_DATABASE mbimDb;
92
93
94/******************************************************************************
95 * Function prototypes
96 ******************************************************************************/
97int CID_SmsNotSupported(SMS_CID_PARAMS);
98int CID_SmsConfiguration(SMS_CID_PARAMS);
99int CID_SmsRead(SMS_CID_PARAMS);
100int CID_SmsSend(SMS_CID_PARAMS);
101int CID_SmsDelete(SMS_CID_PARAMS);
102int CID_SmsMessageStoreStatus(SMS_CID_PARAMS);
103
104
105
106/******************************************************************************
107 * External variables
108 ******************************************************************************/
109smsUuidProcessors smsCidProcessor[UUID_SMS_CID_MAX] = {
110 CID_SmsNotSupported, //0
111 CID_SmsConfiguration,
112 CID_SmsRead,
113 CID_SmsSend,
114 CID_SmsDelete,
115 CID_SmsMessageStoreStatus
116};
117
118
119
120/******************************************************************************
121 * Code
122 ******************************************************************************/
123
124
125/*******************************************************************************\
126* Function: CID_SmsNotSupported
127* Description: This function sends Error to HOST when a unknown command is received
128* Parameters: dataBuf - String
129*
130* Returns: 0=OK, <0=Error Code
131\*******************************************************************************/
132int CID_SmsNotSupported(SMS_CID_PARAMS)
133{
134 int rc = MBIM_OK;
135
136 //Added for compilation uof unused parameters on Codeline
137 MBIM_SMS_UNUSEDPARAM();
138
139 MBIM_LOGE("SMS UUID: Command %d not supported (TransactionId = %d, Cmd Type = %d)", cid, transactionId, commandType);
140 rc = MbimSendCommandDone(transactionId, UUID_SMS_INDEX,
141 cid, MBIM_STATUS_NO_DEVICE_SUPPORT, 0 , NULL);
142
143 return rc;
144}
145
146
147
148/*******************************************************************************\
149* Function: CID_SmsConfiguration
150* Description: MBIM_CID_SMS_CONFIGURATION (Chapter 10.5.15)
151* Parameters: SMS_CID_PARAMS - See description at the start of file
152*
153* Returns: 0=OK, <0=Error Code
154\*******************************************************************************/
155int CID_SmsConfiguration(SMS_CID_PARAMS)
156{
157 //Added for compilation of unused parameters on Codeline
158 MBIM_SMS_UNUSEDPARAM();
159
160 int rc = MBIM_OK;
161 P_MBIM_MESSAGE_CONTEXT mContext = NULL;
162 char *buf;
163
164 //We only support Query for this command
165 if (commandType != MBIM_SET_COMMAND)
166 {
167 return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
168 }
169
170 //Allocate buffer for response
171 ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
172
173 //Creat the context for this command
174 CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
175
176 MbimTelRequestGetSmsConfig((void *)mContext);
177
178 return rc;
179}
180
181
182/*******************************************************************************\
183* Function: CID_SmsRead
184* Description: MBIM_CID_SMS_READ (Chapter 10.5.16)
185* Parameters: SMS_CID_PARAMS - See description at the start of file
186*
187* Returns: 0=OK, <0=Error Code
188\*******************************************************************************/
189int CID_SmsRead(SMS_CID_PARAMS)
190{
191 //Added for compilation of unused parameters on Codeline
192 MBIM_SMS_UNUSEDPARAM();
193
194 int rc = MBIM_OK;
195 P_MBIM_MESSAGE_CONTEXT mContext = NULL;
196 P_MBIM_CID_SMS_READ pSmsRead = NULL;
197 char *buf;
198
199 //Added for compilation of unused parameters on Codeline
200 MBIM_SMS_UNUSEDPARAM();
201
202 //We only support Query for this command
203 if (commandType != MBIM_QUERY_COMMAND)
204 {
205 return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
206 }
207
208 //Pick up pointer to SMS read query
209 pSmsRead = (P_MBIM_CID_SMS_READ)infoBuf_p;
210
211 //We support only PDU message type
212 if ( pSmsRead->smsFormat == MBIMSmsFormatPdu)
213 {
214 //Allocate buffer for response
215 ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
216
217 //Creat the context for this command
218 CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
219
220 if (pSmsRead->flag == MBIMSmsFlagIndex)
221 {
222 //Save command for data extraction at response
223 ALLOCATE_CMD_BUFFER(mContext, mContext->cmd, infoBufLen);
224 memcpy( mContext->cmd, (char *)infoBuf_p, infoBufLen);
225
226 MbimTelSendCmgrSet((void *)mContext, pSmsRead->messageIndex);
227 }
228 else
229 {
230 /* NOT SUPPORT->READ All SMS!!! */
231 MBIM_FREE(buf);
232 rc = CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
233 }
234 }
235 else
236 {
237 //Send the Command Done back to MBIM Host
238 MbimSendCommandDone( transactionId,
239 UUID_SMS_INDEX,
240 cid,
241 MBIM_STATUS_SMS_FORMAT_NOT_SUPPORTED,
242 0,
243 NULL);
244 }
245
246 return rc;
247}
248
249
250/*******************************************************************************\
251* Function: CID_SmsSend
252* Description: MBIM_CID_SMS_SEND (Chapter 10.5.17)
253* Parameters: SMS_CID_PARAMS - See description at the start of file
254*
255* Returns: 0=OK, <0=Error Code
256\*******************************************************************************/
257int CID_SmsSend(SMS_CID_PARAMS)
258{
259 //Added for compilation uof unused parameters on Codeline
260 MBIM_SMS_UNUSEDPARAM();
261
262 int rc = MBIM_OK;
263 P_MBIM_MESSAGE_CONTEXT mContext = NULL;
264 P_MBIM_SET_SMS_SEND pSetSmsSend = NULL;
265 P_MBIM_SMS_SEND_PDU pSmsSendPdu = NULL;
266 char *buf;
267
268
269 //We only support Query for this command
270 if (commandType != MBIM_SET_COMMAND)
271 {
272 return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
273 }
274
275 //Allocate buffer for response
276 ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
277
278 //Creat the context for this command
279 CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
280
281 //Pick up pointer to SMS delete set command
282 pSetSmsSend = (P_MBIM_SET_SMS_SEND)infoBuf_p;
283 pSmsSendPdu = (P_MBIM_SMS_SEND_PDU)(&pSetSmsSend->dataBuffer);
284
285 //Send SMS
286 MbimTelSendCmgsSet((void *)mContext, (char *)pSmsSendPdu + pSmsSendPdu->pduDataOffset, pSmsSendPdu->pduDataSize);
287
288 return rc;
289}
290
291
292/*******************************************************************************\
293* Function: CID_SmsDelete
294* Description: MBIM_CID_SMS_DELETE (Chapter 10.5.18)
295* Parameters: SMS_CID_PARAMS - See description at the start of file
296*
297* Returns: 0=OK, <0=Error Code
298\*******************************************************************************/
299int CID_SmsDelete(SMS_CID_PARAMS)
300{
301 //Added for compilation uof unused parameters on Codeline
302 MBIM_SMS_UNUSEDPARAM();
303
304 int rc = MBIM_OK;
305 P_MBIM_MESSAGE_CONTEXT mContext = NULL;
306 P_MBIM_SET_SMS_DELETE pSetSmsDelete = NULL;
307 char *buf;
308
309 //We only support Query for this command
310 if (commandType != MBIM_SET_COMMAND)
311 {
312 return CID_SmsNotSupported(BASIC_CID_PARAMS_USAGE);
313 }
314
315 //Allocate buffer for response
316 ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
317
318 //Creat the context for this command
319 CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
320
321 //Pick up pointer to SMS delete set command
322 pSetSmsDelete = (P_MBIM_SET_SMS_DELETE)infoBuf_p;
323
324 //send Delete message to MTIL
325 MbimTelSendCmgdSet((void *)mContext, pSetSmsDelete->MessageIndex, pSetSmsDelete->flags);
326
327 return rc;
328}
329
330
331
332
333/*******************************************************************************\
334* Function: CID_SmsMessageStoreStatus
335* Description: MBIM_CID_SMS_MESSAGE_STORE_STATUS (Chapter 10.5.19)
336* Parameters: SMS_CID_PARAMS - See description at the start of file
337*
338* Returns: 0=OK, <0=Error Code
339\*******************************************************************************/
340int CID_SmsMessageStoreStatus(SMS_CID_PARAMS)
341{
342 //Added for compilation uof unused parameters on Codeline
343 MBIM_SMS_UNUSEDPARAM();
344
345 int rc = MBIM_OK;
346 P_MBIM_MESSAGE_CONTEXT mContext = NULL;
347 char *buf;
348
349 if (commandType != MBIM_QUERY_COMMAND)
350 {
351 return CID_SmsNotSupported(SMS_CID_PARAMS_USAGE);
352 }
353
354 //Allocate buffer for response
355 ALLOCATE_RESPONSE_BUFFER(buf, DEFAULT_CONTEXT_ALLOC_SIZE);
356
357 //Creat the context for this command
358 CREATE_SMS_CONNECT_CONTEXT(mContext, buf);
359
360 MbimTelSmsStoreStatus((void *)mContext);
361
362 return rc;
363}
364