Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Core/QMIBuffers.h

raw
1 /*===========================================================================
2 FILE:
3 QMIBuffers.h
4
5 DESCRIPTION:
6 QMI service protocol related structures and affliated methods
7
8 PUBLIC CLASSES AND METHODS:
9 sQMUXHeader
10 sQMIControlRawTransactionHeader
11 sQMIServiceRawTransactionHeader
12 sQMIRawMessageHeader
13 sQMIRawContentHeader
14
15 sQMIServiceBuffer
16
17 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
18
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions are met:
21 * Redistributions of source code must retain the above copyright
22 notice, this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
26 * Neither the name of Code Aurora Forum nor
27 the names of its contributors may be used to endorse or promote
28 products derived from this software without specific prior written
29 permission.
30
31
32 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
36 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 POSSIBILITY OF SUCH DAMAGE.
43 ===========================================================================*/
44
45 //---------------------------------------------------------------------------
46 // Pragmas
47 //---------------------------------------------------------------------------
48 #pragma once
49
50 //---------------------------------------------------------------------------
51 // Include Files
52 //---------------------------------------------------------------------------
53 #include "ProtocolBuffer.h"
54 #include "QMIEnum.h"
55
56 #include <map>
57 #include <vector>
58
59 //---------------------------------------------------------------------------
60 // Definitions
61 //---------------------------------------------------------------------------
62
63 // QMI maximum buffer size (cannot be larger than MAX_SHARED_BUFFER_SIZE)
64 const ULONG QMI_MAX_BUFFER_SIZE = MAX_SHARED_BUFFER_SIZE;
65
66 // Content ID for mandatory result TLV
67 const ULONG QMI_TLV_ID_RESULT = 2;
68
69 /*===========================================================================
70 METHOD:
71 MapQMIServiceToProtocol (Inline Method)
72
73 DESCRIPTION:
74 Map QMI service type (eQMIService) and direction to a protocol type
75 (eProtocolType)
76
77 PARAMETERS:
78 serviceType [ I ] - Enum value being mapped
79 bTransmission [ I ] - Is this a transmission (TX vs. RX)?
80
81 RETURN VALUE:
82 eProtocolType
83 ===========================================================================*/
84 inline eProtocolType MapQMIServiceToProtocol(
85 eQMIService serviceType,
86 bool bTransmission = true )
87 {
88 eProtocolType pt = ePROTOCOL_ENUM_BEGIN;
89 if (IsValid( serviceType ) == false)
90 {
91 return pt;
92 }
93
94 DWORD tmp = ((DWORD)serviceType * 2) + (DWORD)ePROTOCOL_QMI_CTL_RX;
95 if (bTransmission == true)
96 {
97 tmp++;
98 }
99
100 if (IsQMIProtocol( (eProtocolType)tmp ) == true)
101 {
102 pt = (eProtocolType)tmp;
103 }
104
105 return pt;
106 };
107
108 /*===========================================================================
109 METHOD:
110 MapProtocolToQMIService (Inline Method)
111
112 DESCRIPTION:
113 Map protocol type (eProtocolType) to QMI service type (eQMIService)
114
115 PARAMETERS:
116 protocolType [ I ] - Enum value being mapped
117
118 RETURN VALUE:
119 bool
120 ===========================================================================*/
121 inline eQMIService MapProtocolToQMIService( eProtocolType protocolType )
122 {
123 eQMIService st = eQMI_SVC_ENUM_BEGIN;
124 if (IsQMIProtocol( protocolType ) == false)
125 {
126 return st;
127 }
128
129 DWORD tmp = ((DWORD)protocolType - (DWORD)ePROTOCOL_QMI_CTL_RX) / 2;
130 if (IsValid( (eQMIService)tmp ) == true)
131 {
132 st = (eQMIService)tmp;
133 }
134
135 return st;
136 };
137
138 //---------------------------------------------------------------------------
139 // Pragmas (pack structs)
140 //---------------------------------------------------------------------------
141 #pragma pack( push, 1 )
142
143 /*=========================================================================*/
144 // Struct sQMUXHeader
145 // Struct to represent a QMUX transaction header (raw)
146 /*=========================================================================*/
147 struct sQMUXHeader
148 {
149 public:
150 WORD mLength;
151 BYTE mFlags;
152 BYTE mServiceType;
153 BYTE mClientID;
154 };
155
156 /*=========================================================================*/
157 // Struct sQMIControlRawTransactionHeader
158 // Struct to represent a QMI control transaction header (raw)
159 /*=========================================================================*/
160 struct sQMIControlRawTransactionHeader
161 {
162 public:
163 BYTE mResponse : 1; // Is this a response transaction?
164 BYTE mIndication : 1; // Is this an indication transaction?
165 BYTE mReserved : 6;
166
167 BYTE mTransactionID; // Transaction ID
168 };
169
170 /*=========================================================================*/
171 // Struct sQMIServiceRawTransactionHeader
172 // Struct to represent a QMI service transaction header (raw)
173 /*=========================================================================*/
174 struct sQMIServiceRawTransactionHeader
175 {
176 public:
177 BYTE mCompound : 1; // Is this a compound transaction?
178 BYTE mResponse : 1; // Is this a response transaction?
179 BYTE mIndication : 1; // Is this an indication transaction?
180 BYTE mReserved : 5;
181
182 WORD mTransactionID; // Transaction ID
183 };
184
185 /*=========================================================================*/
186 // Struct sQMIRawMessageHeader
187 // Struct to represent a QMI (control/service) message header (raw)
188 /*=========================================================================*/
189 struct sQMIRawMessageHeader
190 {
191 public:
192 WORD mMessageID; // Message ID
193 WORD mLength; // Length of message (not including this header)
194 };
195
196 /*=========================================================================*/
197 // Struct sQMIRawContentHeader
198 // Struct to represent a QMI (control/service) content
199 // (i.e Type/Length/Value, TLV) header (raw)
200 /*=========================================================================*/
201 struct sQMIRawContentHeader
202 {
203 public:
204 BYTE mTypeID; // Content type ID
205 WORD mLength; // Content length (not including this header)
206 };
207
208 //---------------------------------------------------------------------------
209 // Pragmas
210 //---------------------------------------------------------------------------
211 #pragma pack( pop )
212
213
214 /*=========================================================================*/
215 // Struct sQMIServiceBuffer
216 // Struct to represent a QMI service channel request/response/indication
217 // (shared buffer)
218 /*=========================================================================*/
219 struct sQMIServiceBuffer : public sProtocolBuffer
220 {
221 public:
222 // Constructor
223 sQMIServiceBuffer( sSharedBuffer * pBuffer );
224
225 // Destructor
226 virtual ~sQMIServiceBuffer();
227
228 // (Inline) Is this a request?
229 bool IsRequest() const
230 {
231 bool bRequest = false;
232
233 const sQMIServiceRawTransactionHeader * pHdr = GetHeader();
234 if (pHdr != 0)
235 {
236 bRequest = (pHdr->mResponse == 0 && pHdr->mIndication == 0);
237 }
238
239 return bRequest;
240 };
241
242 // (Inline) Is this a response?
243 bool IsResponse() const
244 {
245 bool bResponse = false;
246
247 const sQMIServiceRawTransactionHeader * pHdr = GetHeader();
248 if (pHdr != 0)
249 {
250 bResponse = (pHdr->mResponse == 1);
251 }
252
253 return bResponse;
254 };
255
256 // (Inline) Is this an indication?
257 bool IsIndication() const
258 {
259 bool bInd = false;
260
261 const sQMIServiceRawTransactionHeader * pHdr = GetHeader();
262 if (pHdr != 0)
263 {
264 bInd = (pHdr->mIndication == 1);
265 }
266
267 return bInd;
268 };
269
270 // (Inline) Return raw header
271 const sQMIServiceRawTransactionHeader * GetHeader() const
272 {
273 const sQMIServiceRawTransactionHeader * pHdr = 0;
274 if (IsValid() == true)
275 {
276 pHdr = (const sQMIServiceRawTransactionHeader *)GetBuffer();
277 }
278
279 return pHdr;
280 };
281
282 // (Inline) Return the message ID
283 ULONG GetMessageID() const
284 {
285 ULONG id = (ULONG)0xffffffff;
286
287 const sQMIServiceRawTransactionHeader * pHdr = GetHeader();
288 if (pHdr != 0)
289 {
290 pHdr++;
291 const sQMIRawMessageHeader * pMsgHdr = 0;
292 pMsgHdr = (sQMIRawMessageHeader *)pHdr;
293
294 id = pMsgHdr->mMessageID;
295 }
296
297 return id;
298 };
299
300 // (Inline) Return the transaction ID
301 WORD GetTransactionID() const
302 {
303 WORD id = (WORD)INVALID_QMI_TRANSACTION_ID;
304
305 const sQMIServiceRawTransactionHeader * pHdr = GetHeader();
306 if (pHdr != 0)
307 {
308 id = pHdr->mTransactionID;
309 }
310
311 return id;
312 };
313
314 // (Inline) Return raw content array
315 const sQMIRawContentHeader * GetRawContents( ULONG & contentLen ) const
316 {
317 // Assume failure
318 ULONG len = 0;
319 const sQMIRawContentHeader * pRaw = 0;
320
321 const sQMIServiceRawTransactionHeader * pHdr = GetHeader();
322 if (pHdr != 0)
323 {
324 pHdr++;
325 const sQMIRawMessageHeader * pMsgHdr = 0;
326 pMsgHdr = (sQMIRawMessageHeader *)pHdr;
327
328 len = pMsgHdr->mLength;
329 pMsgHdr++;
330 if (len > 0)
331 {
332 pRaw = (const sQMIRawContentHeader *)pMsgHdr;
333 }
334 }
335
336 contentLen = len;
337 return pRaw;
338 };
339
340 // (Inline) Return content structures
341 std::map <ULONG, const sQMIRawContentHeader *> GetContents() const
342 {
343 return mContents;
344 };
345
346 // Return contents of mandatory result content
347 bool GetResult(
348 ULONG & returnCode,
349 ULONG & errorCode );
350
351 // Build a QMI request/response/indication
352 static sSharedBuffer * BuildBuffer(
353 eQMIService serviceType,
354 WORD msgID,
355 bool bResponse = false,
356 bool bIndication = false,
357 const BYTE * pData = 0,
358 ULONG dataLen = 0 );
359
360 protected:
361 // QMI protocol server has to be able to set the transaction ID
362 friend class cQMIProtocolServer;
363
364 // Set the transaction ID
365 void SetTransactionID( WORD tid ) const
366 {
367 if (tid == (WORD)INVALID_QMI_TRANSACTION_ID || IsValid() == false)
368 {
369 return;
370 }
371
372 sQMIServiceRawTransactionHeader * pHdr = 0;
373 pHdr = (sQMIServiceRawTransactionHeader *)GetHeader();
374 if (pHdr != 0)
375 {
376 pHdr->mTransactionID = tid;
377 }
378 };
379
380 // Is this QMI request/response/indication packet valid?
381 virtual bool Validate();
382
383 /* Content TLV structures (indexed by type ID) */
384 std::map <ULONG, const sQMIRawContentHeader *> mContents;
385
386 private:
387 // Prevent 'upcopying'
388 sQMIServiceBuffer( const sProtocolBuffer & );
389 sQMIServiceBuffer & operator = ( const sProtocolBuffer & );
390 };
391