Debian Codegraph @

gobi-api/Gobi_2011-11-28-1533/Gobi3000Translation/Gobi3000TranslationRMS.cpp

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000TranslationRMS.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000 (Remote Management Service)
7
8 Copyright (c) 2011, 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 ParseGetSMSWake
44
45 DESCRIPTION:
46 This function queries the state of the SMS wake functionality
47
48 PARAMETERS:
49 inLen [ I ] - Length of input buffer
50 pIn [ I ] - Input buffer
51 pbEnabled [ O ] - SMS wake functionality enabled?
52 pWakeMask [ O ] - SMS wake mask (only relevant when enabled)
53
54 RETURN VALUE:
55 ULONG - Return code
56 ===========================================================================*/
57 ULONG ParseGetSMSWake(
58 ULONG inLen,
59 const BYTE * pIn,
60 ULONG * pbEnabled,
61 ULONG * pWakeMask )
62 {
63 // Validate arguments
64 if (pIn == 0 || pbEnabled == 0 || pWakeMask == 0)
65 {
66 return eGOBI_ERR_INVALID_ARG;
67 }
68
69 // Find the first TLV
70 const sRMSGetSMSWakeResponse_State * pTLVx10;
71 ULONG outLenx10;
72 ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
73 if (rc != eGOBI_ERR_NONE)
74 {
75 return rc;
76 }
77
78 // Is the TLV large enough?
79 if (outLenx10 < sizeof( sRMSGetSMSWakeResponse_State ))
80 {
81 return eGOBI_ERR_MALFORMED_RSP;
82 }
83
84 // Find the second TLV
85 const sRMSGetSMSWakeRequest_Mask * pTLVx11;
86 ULONG outLenx11;
87 rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 );
88 if (rc != eGOBI_ERR_NONE)
89 {
90 return rc;
91 }
92
93 // Is the TLV large enough?
94 if (outLenx11 < sizeof( sRMSGetSMSWakeRequest_Mask ))
95 {
96 return eGOBI_ERR_MALFORMED_RSP;
97 }
98
99 *pbEnabled = pTLVx10->mSMSWakeEnabled;
100 *pWakeMask = pTLVx11->mMask;
101
102 return eGOBI_ERR_NONE;
103 }
104
105 /*===========================================================================
106 METHOD:
107 PackSetSMSWake
108
109 DESCRIPTION:
110 This function enables/disables the SMS wake functionality
111
112 PARAMETERS:
113 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
114 contain, upon output the number of BYTEs copied
115 to pOut
116 pOut [ O ] - Output buffer
117 bEnable [ I ] - Enable SMS wake functionality?
118 wakeMask [ I ] - SMS wake mask (only relevant when enabling)
119
120 RETURN VALUE:
121 ULONG - Return code
122 ===========================================================================*/
123 ULONG PackSetSMSWake(
124 ULONG * pOutLen,
125 BYTE * pOut,
126 ULONG bEnable,
127 ULONG wakeMask )
128 {
129 // Validate arguments
130 if (pOut == 0)
131 {
132 return eGOBI_ERR_INVALID_ARG;
133 }
134
135 // Add bEnable
136
137 // Check size
138 WORD tlvx10Sz = sizeof( sRMSSetSMSWakeRequest_State );
139 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx10Sz)
140 {
141 return eGOBI_ERR_BUFFER_SZ;
142 }
143
144 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
145 pHeader->mTypeID = 0x10;
146 pHeader->mLength = tlvx10Sz;
147
148 ULONG offset = sizeof( sQMIRawContentHeader );
149
150 sRMSSetSMSWakeRequest_State * pTLVx10;
151 pTLVx10 = (sRMSSetSMSWakeRequest_State*)(pOut + offset);
152 memset( pTLVx10, 0, tlvx10Sz );
153
154 // Set the value
155 pTLVx10->mSMSWakeEnabled = (INT8)bEnable;
156
157 offset += tlvx10Sz;
158
159 // Add wakeMask if enabled
160 if (bEnable != 0)
161 {
162 // Check size
163 WORD tlvx11Sz = sizeof( sRMSSetSMSWakeRequest_Mask );
164 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
165 {
166 return eGOBI_ERR_BUFFER_SZ;
167 }
168
169 pHeader = (sQMIRawContentHeader*)(pOut + offset);
170 pHeader->mTypeID = 0x11;
171 pHeader->mLength = tlvx11Sz;
172
173 offset += sizeof( sQMIRawContentHeader );
174
175 sRMSSetSMSWakeRequest_Mask * pTLVx11;
176 pTLVx11 = (sRMSSetSMSWakeRequest_Mask*)(pOut + offset);
177 memset( pTLVx11, 0, tlvx11Sz );
178
179 // Set the value
180 pTLVx11->mMask = wakeMask;
181
182 offset += tlvx11Sz;
183 }
184
185 *pOutLen = offset;
186
187 return eGOBI_ERR_NONE;
188 }