Debian Codegraph @

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