Debian Codegraph @

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

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000TranslationVoice.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000 (Voice Service for USSD)
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 // Pragmas (pack structs)
42 //---------------------------------------------------------------------------
43 #pragma pack( push, 1 )
44
45 /*=========================================================================*/
46 // Struct sUSSDInfo
47 // Struct to represent USSD/Alpha information header
48 /*=========================================================================*/
49 struct sUSSDInfoHdr
50 {
51 public:
52 BYTE mDCS;
53 BYTE mLength;
54
55 // Data of 'mLength' follows
56 };
57
58 //---------------------------------------------------------------------------
59 // Pragmas
60 //---------------------------------------------------------------------------
61 #pragma pack( pop )
62
63 /*===========================================================================
64 METHOD:
65 PackOriginateUSSD
66
67 DESCRIPTION:
68 This function initiates a USSD operation
69
70 PARAMETERS:
71 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
72 contain, upon output the number of BYTEs copied
73 to pOut
74 pOut [ O ] - Output buffer
75 pInfo [ I ] - USSD information
76
77 RETURN VALUE:
78 ULONG - Return code
79 ===========================================================================*/
80 ULONG PackOriginateUSSD(
81 ULONG * pOutLen,
82 BYTE * pOut,
83 BYTE * pInfo )
84 {
85 // Validate arguments
86 if (pOut == 0 || pInfo == 0)
87 {
88 return eGOBI_ERR_INVALID_ARG;
89 }
90
91 const WORD INFO_HDR_SZ = sizeof( sUSSDInfoHdr );
92
93 // This assumes that pInfo is at least 2 bytes long
94 sUSSDInfoHdr * pInInfo = (sUSSDInfoHdr *)pInfo;
95 WORD infoLen = pInInfo->mLength + INFO_HDR_SZ;
96
97 // Check size
98 if (*pOutLen < sizeof( sQMIRawContentHeader ) + infoLen)
99 {
100 return eGOBI_ERR_BUFFER_SZ;
101 }
102
103 // Add pInfo
104
105 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
106 pHeader->mTypeID = 0x01;
107 pHeader->mLength = infoLen;
108
109 ULONG offset = sizeof( sQMIRawContentHeader );
110
111 // No pTLVx01 since pInfo is our TLV
112 memcpy( (pOut + offset), pInfo, infoLen );
113
114 offset += infoLen;
115 *pOutLen = offset;
116
117 return eGOBI_ERR_NONE;
118 }
119
120 /*===========================================================================
121 METHOD:
122 PackAnswerUSSD
123
124 DESCRIPTION:
125 This function responds to a USSD request from the network
126
127 PARAMETERS:
128 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
129 contain, upon output the number of BYTEs copied
130 to pOut
131 pOut [ O ] - Output buffer
132 pInfo [ I ] - USSD information
133
134 RETURN VALUE:
135 ULONG - Return code
136 ===========================================================================*/
137 ULONG PackAnswerUSSD(
138 ULONG * pOutLen,
139 BYTE * pOut,
140 BYTE * pInfo )
141 {
142 // Validate arguments
143 if (pOut == 0 || pInfo == 0)
144 {
145 return eGOBI_ERR_INVALID_ARG;
146 }
147
148 const WORD INFO_HDR_SZ = sizeof( sUSSDInfoHdr );
149
150 // This assumes that pInfo is at least 2 bytes long
151 sUSSDInfoHdr * pInInfo = (sUSSDInfoHdr *)pInfo;
152 WORD infoLen = pInInfo->mLength + INFO_HDR_SZ;
153
154 // Check size
155 if (*pOutLen < sizeof( sQMIRawContentHeader ) + infoLen)
156 {
157 return eGOBI_ERR_BUFFER_SZ;
158 }
159
160 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
161 pHeader->mTypeID = 0x01;
162 pHeader->mLength = infoLen;
163
164 ULONG offset = sizeof( sQMIRawContentHeader );
165
166 // No pTLVx01 since pInfo is our TLV
167 memcpy( (pOut + offset), pInfo, infoLen );
168
169 offset += infoLen;
170 *pOutLen = offset;
171
172 return eGOBI_ERR_NONE;
173 }