Debian Codegraph @

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