Debian Codegraph @

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

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000Translation.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000
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 // Free Methods
42 /*=========================================================================*/
43
44 /*===========================================================================
45 METHOD:
46 GetTLV
47
48 DESCRIPTION:
49 Return the starting location and size of TLV buffer.
50
51 NOTE: does not include the TLV header
52
53 PARAMETERS:
54 inLen [ I ] - Length of input buffer
55 pIn [ I ] - Input buffer
56 type [ I ] - Type ID
57 pOutLen [ O ] - Length of the output buffer
58 ppOut [ O ] - Pointer to output buffer
59
60 RETURN VALUE:
61 ULONG - Return code
62 ===========================================================================*/
63 ULONG GetTLV(
64 ULONG inLen,
65 const BYTE * pIn,
66 BYTE typeID,
67 ULONG * pOutLen,
68 const BYTE ** ppOut )
69 {
70 if (pIn == 0 || pOutLen == 0 || ppOut == 0)
71 {
72 return eGOBI_ERR_INVALID_ARG;
73 }
74
75 for (ULONG offset = 0;
76 offset + sizeof( sQMIRawContentHeader ) <= inLen;
77 offset += sizeof( sQMIRawContentHeader ))
78 {
79 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pIn + offset);
80
81 // Is it big enough to contain this TLV?
82 if (offset + sizeof( sQMIRawContentHeader ) + pHeader->mLength > inLen)
83 {
84 return eGOBI_ERR_MALFORMED_RSP;
85 }
86
87 if (pHeader->mTypeID == typeID)
88 {
89 *pOutLen = pHeader->mLength;
90 *ppOut = pIn + offset + sizeof( sQMIRawContentHeader );
91
92 return eGOBI_ERR_NONE;
93 }
94
95 offset += pHeader->mLength;
96 }
97
98 // TLV not found
99 return eGOBI_ERR_INVALID_RSP;
100 }