Debian Codegraph @

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