Debian Codegraph @

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

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000TranslationCAT.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000 (Card Application Toolkit 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 PackCATSendTerminalResponse
43
44 DESCRIPTION:
45 This function sends the terminal response to the device
46
47 PARAMETERS:
48 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
49 contain, upon output the number of BYTEs copied
50 to pOut
51 pOut [ O ] - Output buffer
52 refID [ I ] - UIM reference ID (from CAT event)
53 dataLen [ I ] - Terminal response data length
54 pData [ I ] - Terminal response data
55
56 RETURN VALUE:
57 ULONG - Return code
58 ===========================================================================*/
59 ULONG PackCATSendTerminalResponse(
60 ULONG * pOutLen,
61 BYTE * pOut,
62 ULONG refID,
63 ULONG dataLen,
64 BYTE * pData )
65 {
66 // Validate arguments
67 if (pOut == 0 || pData == 0)
68 {
69 return eGOBI_ERR_INVALID_ARG;
70 }
71
72 // Add arguments
73
74 // Check size
75 WORD tlvx01Sz = sizeof( sCATSendTerminalResponseRequest_TerminalResponseType )
76 + (WORD)dataLen;
77 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
78 {
79 return eGOBI_ERR_BUFFER_SZ;
80 }
81
82 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
83 pHeader->mTypeID = 0x01;
84 pHeader->mLength = tlvx01Sz;
85
86 ULONG offset = sizeof( sQMIRawContentHeader );
87
88 sCATSendTerminalResponseRequest_TerminalResponseType * pTLVx01;
89 pTLVx01 = (sCATSendTerminalResponseRequest_TerminalResponseType*)(pOut + offset);
90 memset( pTLVx01, 0, tlvx01Sz );
91
92 // Set the value
93 pTLVx01->mReferenceID = refID;
94 pTLVx01->mTerminalResponseLength = (UINT16)dataLen;
95
96 offset += sizeof( sCATSendTerminalResponseRequest_TerminalResponseType );
97
98 if (dataLen > 0)
99 {
100 memcpy( pOut + offset, pData, dataLen );
101 offset += dataLen;
102 }
103
104 *pOutLen = offset;
105
106 return eGOBI_ERR_NONE;
107 }
108
109 /*===========================================================================
110 METHOD:
111 PackCATSendEnvelopeCommand
112
113 DESCRIPTION:
114 This function sends the envelope command to the device
115
116 PARAMETERS:
117 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
118 contain, upon output the number of BYTEs copied
119 to pOut
120 pOut [ O ] - Output buffer
121 cmdID [ I ] - Envelope command ID
122 dataLen [ I ] - Envelope command data length
123 pData [ I ] - Envelope command data
124
125 RETURN VALUE:
126 ULONG - Return code
127 ===========================================================================*/
128 ULONG PackCATSendEnvelopeCommand(
129 ULONG * pOutLen,
130 BYTE * pOut,
131 ULONG cmdID,
132 ULONG dataLen,
133 BYTE * pData )
134 {
135 // Validate arguments
136 if (pOut == 0 || dataLen == 0 || pData == 0)
137 {
138 return eGOBI_ERR_INVALID_ARG;
139 }
140
141 // Add arguments
142
143 // Check size
144 WORD tlvx01Sz = sizeof( sCATEnvelopeCommandRequest_EnvelopeCommand )
145 + (WORD)dataLen;
146 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
147 {
148 return eGOBI_ERR_BUFFER_SZ;
149 }
150
151 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut;
152 pHeader->mTypeID = 0x01;
153 pHeader->mLength = tlvx01Sz;
154
155 ULONG offset = sizeof( sQMIRawContentHeader );
156
157 sCATEnvelopeCommandRequest_EnvelopeCommand * pTLVx01;
158 pTLVx01 = (sCATEnvelopeCommandRequest_EnvelopeCommand*)(pOut + offset);
159 memset( pTLVx01, 0, tlvx01Sz );
160
161 // Set the value
162 pTLVx01->mEnvelopeCommandType = (eQMICATEnvelopeCommandType)cmdID;
163 pTLVx01->mEnvelopeLength = (UINT16)dataLen;
164
165 offset += sizeof( sCATEnvelopeCommandRequest_EnvelopeCommand );
166
167 if (dataLen > 0)
168 {
169 memcpy( pOut + offset, pData, dataLen );
170 offset += dataLen;
171 }
172
173 *pOutLen = offset;
174
175 return eGOBI_ERR_NONE;
176 }