Debian Codegraph @

gobi-api/GobiAPI_2013-07-31-1347/Gobi3000Translation/Gobi3000TranslationOMA.cpp

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000TranslationOMA.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000 (OMADM Service)
7
8 Copyright (c) 2013, The Linux Foundation. All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 * Neither the name of The Linux Foundation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 ==========================================================================*/
34
35 //---------------------------------------------------------------------------
36 // Include Files
37 //---------------------------------------------------------------------------
38 #include "Gobi3000Translation.h"
39
40 /*===========================================================================
41 METHOD:
42 PackOMADMStartSession
43
44 DESCRIPTION:
45 This function starts an OMA-DM session
46
47 PARAMETERS:
48 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
49 contain, upon output the number of BYTEs copied
50 to pOut
51 pOut [ O ] - Output buffer
52 sessionType [ I ] - Type of session to initiate
53
54 RETURN VALUE:
55 ULONG - Return code
56 ===========================================================================*/
57 ULONG PackOMADMStartSession(
58 ULONG * pOutLen,
59 BYTE * pOut,
60 ULONG sessionType )
61 {
62 // Validate arguments
63 if (pOut == 0)
64 {
65 return eGOBI_ERR_INVALID_ARG;
66 }
67
68 // Add sessionType
69
70 // Check size
71 WORD tlvx10Sz = sizeof( sOMAStartSessionRequest_Type );
72 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx10Sz)
73 {
74 return eGOBI_ERR_BUFFER_SZ;
75 }
76
77 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
78 pHeader->mTypeID = 0x10;
79 pHeader->mLength = tlvx10Sz;
80
81 ULONG offset = sizeof( sQMIRawContentHeader );
82
83 sOMAStartSessionRequest_Type * pTLVx10;
84 pTLVx10 = (sOMAStartSessionRequest_Type*)(pOut + offset);
85 memset( pTLVx10, 0, tlvx10Sz );
86
87 // Set the value
88 pTLVx10->mSessionType = (eQMIOMASessionTypes)sessionType;
89
90 offset += tlvx10Sz;
91
92 *pOutLen = offset;
93
94 return eGOBI_ERR_NONE;
95 }
96
97 /*===========================================================================
98 METHOD:
99 ParseOMADMGetSessionInfo
100
101 DESCRIPTION:
102 This function returns information related to the current (or previous
103 if no session is active) OMA-DM session
104
105 PARAMETERS:
106 inLen [ I ] - Length of input buffer
107 pIn [ I ] - Input buffer
108 pSessionState [ O ] - State of session
109 pSessionType [ O ] - Type of session
110 pFailureReason [ O ] - Session failure reason (when state indicates failure)
111 pRetryCount [ O ] - Session retry count (when state indicates retrying)
112 pSessionPause [ O ] - Session pause timer (when state indicates retrying)
113 pTimeRemaining [ O ] - Pause time remaining (when state indicates retrying)
114
115 RETURN VALUE:
116 ULONG - Return code
117 ===========================================================================*/
118 ULONG ParseOMADMGetSessionInfo(
119 ULONG inLen,
120 const BYTE * pIn,
121 ULONG * pSessionState,
122 ULONG * pSessionType,
123 ULONG * pFailureReason,
124 BYTE * pRetryCount,
125 WORD * pSessionPause,
126 WORD * pTimeRemaining )
127 {
128 // Validate arguments
129 if (pIn == 0 || pSessionState == 0 || pSessionType == 0
130 || pFailureReason == 0 || pRetryCount == 0 || pSessionPause == 0
131 || pTimeRemaining == 0)
132 {
133 return eGOBI_ERR_INVALID_ARG;
134 }
135
136 // Find the first TLV
137 const sOMAGetSessionInfoResponse_Info * pTLVx10;
138 ULONG outLenx10;
139 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
140 if (rc != eGOBI_ERR_NONE)
141 {
142 return rc;
143 }
144
145 // Is the TLV large enough?
146 if (outLenx10 < sizeof( sOMAGetSessionInfoResponse_Info ))
147 {
148 return eGOBI_ERR_MALFORMED_RSP;
149 }
150
151 *pSessionState = pTLVx10->mSessionState;
152 *pSessionType = pTLVx10->mSessionType;
153
154 // Find the second TLV
155 const sOMAGetSessionInfoResponse_Failure * pTLVx11;
156 ULONG outLenx11;
157 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
158 if (rc != eGOBI_ERR_NONE)
159 {
160 return rc;
161 }
162
163 // Is the TLV large enough?
164 if (outLenx11 < sizeof( sOMAGetSessionInfoResponse_Failure ))
165 {
166 return eGOBI_ERR_MALFORMED_RSP;
167 }
168
169 *pFailureReason = pTLVx11->mSessionFailure;
170
171 // Find the third TLV
172 const sOMAGetSessionInfoResponse_Retry * pTLVx12;
173 ULONG outLenx12;
174 rc = GetTLV( inLen, pIn, 0x12, &outLenx12, (const BYTE **)&pTLVx12 );
175 if (rc != eGOBI_ERR_NONE)
176 {
177 return rc;
178 }
179
180 // Is the TLV large enough?
181 if (outLenx12 < sizeof( sOMAGetSessionInfoResponse_Retry ))
182 {
183 return eGOBI_ERR_MALFORMED_RSP;
184 }
185
186 *pRetryCount = pTLVx12->mRetryCount;
187 *pSessionPause = pTLVx12->mRetryPauseTimer;
188 *pTimeRemaining = pTLVx12->mRemainingTime;
189
190 return eGOBI_ERR_NONE;
191 }
192
193 /*===========================================================================
194 METHOD:
195 ParseOMADMGetPendingNIA
196
197 DESCRIPTION:
198 This function returns information about the pending network initiated
199 alert
200
201 PARAMETERS:
202 inLen [ I ] - Length of input buffer
203 pIn [ I ] - Input buffer
204 pSessionType [ O ] - Type of session
205 pSessionID [ O ] - Unique session ID
206
207 RETURN VALUE:
208 ULONG - Return code
209 ===========================================================================*/
210 ULONG ParseOMADMGetPendingNIA(
211 ULONG inLen,
212 const BYTE * pIn,
213 ULONG * pSessionType,
214 USHORT * pSessionID )
215 {
216 // Validate arguments
217 if (pIn == 0 || pSessionType == 0 || pSessionID == 0)
218 {
219 return eGOBI_ERR_INVALID_ARG;
220 }
221
222 // Find the TLV
223 const sOMAGetSessionInfoResponse_NIA * pTLVx13;
224 ULONG outLenx13;
225 ULONG rc = GetTLV( inLen, pIn, 0x13, &outLenx13, (const BYTE **)&pTLVx13 );
226 if (rc != eGOBI_ERR_NONE)
227 {
228 return rc;
229 }
230
231 // Is the TLV large enough?
232 if (outLenx13 < sizeof( sOMAGetSessionInfoResponse_NIA ))
233 {
234 return eGOBI_ERR_MALFORMED_RSP;
235 }
236
237 *pSessionID = pTLVx13->mSessionID;
238 *pSessionType = pTLVx13->mSessionType;
239
240 return eGOBI_ERR_NONE;
241 }
242
243 /*===========================================================================
244 METHOD:
245 PackOMADMSendSelection
246
247 DESCRIPTION:
248 This function sends the specified OMA-DM selection for the current
249 network initiated session
250
251 PARAMETERS:
252 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
253 contain, upon output the number of BYTEs copied
254 to pOut
255 pOut [ O ] - Output buffer
256 selection [ I ] - Selection
257 sessionID [ I ] - Unique session ID
258
259 RETURN VALUE:
260 ULONG - Return code
261 ===========================================================================*/
262 ULONG PackOMADMSendSelection(
263 ULONG * pOutLen,
264 BYTE * pOut,
265 ULONG selection,
266 USHORT sessionID )
267 {
268 // Validate arguments
269 if (pOut == 0)
270 {
271 return eGOBI_ERR_INVALID_ARG;
272 }
273
274 // Add selection and session ID
275
276 // Check size
277 WORD tlvx10Sz = sizeof( sOMASendSelectionRequest_Type );
278 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx10Sz)
279 {
280 return eGOBI_ERR_BUFFER_SZ;
281 }
282
283 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
284 pHeader->mTypeID = 0x10;
285 pHeader->mLength = tlvx10Sz;
286
287 ULONG offset = sizeof( sQMIRawContentHeader );
288
289 sOMASendSelectionRequest_Type * pTLVx10;
290 pTLVx10 = (sOMASendSelectionRequest_Type*)(pOut + offset);
291 memset( pTLVx10, 0, tlvx10Sz );
292
293 // Set the values
294 pTLVx10->mSelection = (eQMIOMASelections)selection;
295 pTLVx10->mSessionID = sessionID;
296
297 offset += tlvx10Sz;
298
299 *pOutLen = offset;
300
301 return eGOBI_ERR_NONE;
302 }
303
304 /*===========================================================================
305 METHOD:
306 ParseOMADMGetFeatureSettings
307
308 DESCRIPTION:
309 This function returns the OMA-DM feature settings
310
311 PARAMETERS:
312 inLen [ I ] - Length of input buffer
313 pIn [ I ] - Input buffer
314 pbProvisioning [ O ] - Device provisioning service update enabled
315 pbPRLUpdate [ O ] - PRL service update enabled
316
317 RETURN VALUE:
318 ULONG - Return code
319 ===========================================================================*/
320 ULONG ParseOMADMGetFeatureSettings(
321 ULONG inLen,
322 const BYTE * pIn,
323 ULONG * pbProvisioning,
324 ULONG * pbPRLUpdate )
325 {
326 // Validate arguments
327 if (pIn == 0 || pbProvisioning == 0 || pbPRLUpdate == 0)
328 {
329 return eGOBI_ERR_INVALID_ARG;
330 }
331
332 // Find the first TLV
333 const sOMAGetFeaturesResponse_Provisioning * pTLVx10;
334 ULONG outLenx10;
335 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
336 if (rc != eGOBI_ERR_NONE)
337 {
338 return rc;
339 }
340
341 // Is the TLV large enough?
342 if (outLenx10 < sizeof( sOMAGetFeaturesResponse_Provisioning ))
343 {
344 return eGOBI_ERR_MALFORMED_RSP;
345 }
346
347 *pbProvisioning = pTLVx10->mDeviceProvisioningServiceUpdateEnabled;
348
349 // Find the second TLV
350 const sOMAGetFeaturesResponse_PRLUpdate * pTLVx11;
351 ULONG outLenx11;
352 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
353 if (rc != eGOBI_ERR_NONE)
354 {
355 return rc;
356 }
357
358 // Is the TLV large enough?
359 if (outLenx10 < sizeof( sOMAGetFeaturesResponse_PRLUpdate ))
360 {
361 return eGOBI_ERR_MALFORMED_RSP;
362 }
363
364 *pbPRLUpdate = pTLVx11->mPRLServiceUpdateEnabled;
365
366 return eGOBI_ERR_NONE;
367 }
368
369 /*===========================================================================
370 METHOD:
371 PackOMADMSetProvisioningFeature
372
373 DESCRIPTION:
374 This function sets the OMA-DM device provisioning service
375 update feature setting
376
377 PARAMETERS:
378 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
379 contain, upon output the number of BYTEs copied
380 to pOut
381 pOut [ O ] - Output buffer
382 bProvisioning [ I ] - Device provisioning service update enabled
383
384 RETURN VALUE:
385 ULONG - Return code
386 ===========================================================================*/
387 ULONG PackOMADMSetProvisioningFeature(
388 ULONG * pOutLen,
389 BYTE * pOut,
390 ULONG bProvisioning )
391 {
392 // Validate arguments
393 if (pOut == 0)
394 {
395 return eGOBI_ERR_INVALID_ARG;
396 }
397
398 // Add bProvisioning
399
400 // Check size
401 WORD tlvx10Sz = sizeof( sOMASetFeaturesRequest_Provisioning );
402 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx10Sz)
403 {
404 return eGOBI_ERR_BUFFER_SZ;
405 }
406
407 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
408 pHeader->mTypeID = 0x10;
409 pHeader->mLength = tlvx10Sz;
410
411 ULONG offset = sizeof( sQMIRawContentHeader );
412
413 sOMASetFeaturesRequest_Provisioning * pTLVx10;
414 pTLVx10 = (sOMASetFeaturesRequest_Provisioning*)(pOut + offset);
415 memset( pTLVx10, 0, tlvx10Sz );
416
417 // Set the value
418 pTLVx10->mDeviceProvisioningServiceUpdateEnabled = (INT8)bProvisioning;
419
420 offset += tlvx10Sz;
421 *pOutLen = offset;
422
423 return eGOBI_ERR_NONE;
424 }
425
426 /*===========================================================================
427 METHOD:
428 PackOMADMSetPRLUpdateFeature
429
430 DESCRIPTION:
431 This function sets the OMA-DM PRL service update feature setting
432
433 PARAMETERS:
434 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
435 contain, upon output the number of BYTEs copied
436 to pOut
437 pOut [ O ] - Output buffer
438 bPRLUpdate [ I ] - PRL service update enabled
439
440 RETURN VALUE:
441 ULONG - Return code
442 ===========================================================================*/
443 ULONG PackOMADMSetPRLUpdateFeature(
444 ULONG * pOutLen,
445 BYTE * pOut,
446 ULONG bPRLUpdate )
447 {
448 // Validate arguments
449 if (pOut == 0)
450 {
451 return eGOBI_ERR_INVALID_ARG;
452 }
453
454 // Add bPRLUpdate
455
456 // Check size
457 WORD tlvx11Sz = sizeof( sOMASetFeaturesRequest_PRLUpdate );
458 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx11Sz)
459 {
460 return eGOBI_ERR_BUFFER_SZ;
461 }
462
463 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
464 pHeader->mTypeID = 0x11;
465 pHeader->mLength = tlvx11Sz;
466
467 ULONG offset = sizeof( sQMIRawContentHeader );
468
469 sOMASetFeaturesRequest_PRLUpdate * pTLVx11;
470 pTLVx11 = (sOMASetFeaturesRequest_PRLUpdate*)(pOut + offset);
471 memset( pTLVx11, 0, tlvx11Sz );
472
473 // Set the value
474 pTLVx11->mPRLServiceUpdateEnabled = (INT8)bPRLUpdate;
475
476 offset += tlvx11Sz;
477 *pOutLen = offset;
478
479 return eGOBI_ERR_NONE;
480 }