Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Gobi3000Translation/Gobi3000TranslationWMS.cpp

raw
1 /*===========================================================================
2 FILE:
3 Gobi3000TranslationWMS.cpp
4
5 DESCRIPTION:
6 QUALCOMM Translation for Gobi 3000 (WMS Service)
7
8 Copyright (c) 2012, 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 PackDeleteSMS
44
45 DESCRIPTION:
46 This function deletes one or more SMS messages from device memory
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 storageType [ I ] - SMS message storage type
54 pMessageIndex [ I ] - (Optional) message index
55 pMessageTag [ I ] - (Optional) message tag
56
57 RETURN VALUE:
58 ULONG - Return code
59 ===========================================================================*/
60 ULONG PackDeleteSMS(
61 ULONG * pOutLen,
62 BYTE * pOut,
63 ULONG storageType,
64 ULONG * pMessageIndex,
65 ULONG * pMessageTag )
66 {
67 // Validate arguments
68 if (pOut == 0)
69 {
70 return eGOBI_ERR_INVALID_ARG;
71 }
72
73 // Check size
74 WORD tlvx01Sz = sizeof( sWMSDeleteRequest_MemoryStorage );
75 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
76 {
77 return eGOBI_ERR_BUFFER_SZ;
78 }
79
80 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
81 pHeader->mTypeID = 0x01;
82 pHeader->mLength = tlvx01Sz;
83
84 ULONG offset = sizeof( sQMIRawContentHeader );
85
86 // The SPC
87 sWMSDeleteRequest_MemoryStorage * pTLVx01;
88 pTLVx01 = (sWMSDeleteRequest_MemoryStorage*)(pOut + offset);
89 memset( pTLVx01, 0, tlvx01Sz );
90
91 // Set the values
92 pTLVx01->mStorageType = (eQMIWMSStorageTypes)storageType;
93
94 offset += tlvx01Sz;
95
96 // Add the Message index, if specified
97 if (pMessageIndex != 0)
98 {
99 // Check size
100 WORD tlvx10Sz = sizeof( sWMSDeleteRequest_MessageIndex );
101 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
102 {
103 return eGOBI_ERR_BUFFER_SZ;
104 }
105
106 pHeader = (sQMIRawContentHeader*)(pOut + offset);
107 pHeader->mTypeID = 0x10;
108 pHeader->mLength = tlvx10Sz;
109
110 offset += sizeof( sQMIRawContentHeader );
111
112 // The SPC
113 sWMSDeleteRequest_MessageIndex * pTLVx10;
114 pTLVx10 = (sWMSDeleteRequest_MessageIndex*)(pOut + offset);
115 memset( pTLVx10, 0, tlvx10Sz );
116
117 // Set the values
118 pTLVx10->mStorageIndex = *pMessageIndex;
119
120 offset += tlvx10Sz;
121 }
122
123 // Add the Message tag, if specified
124 if (pMessageTag != 0)
125 {
126 // Check size
127 WORD tlvx11Sz = sizeof( sWMSDeleteRequest_MessageTag );
128 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx11Sz)
129 {
130 return eGOBI_ERR_BUFFER_SZ;
131 }
132
133 pHeader = (sQMIRawContentHeader*)(pOut + offset);
134 pHeader->mTypeID = 0x11;
135 pHeader->mLength = tlvx11Sz;
136
137 offset += sizeof( sQMIRawContentHeader );
138
139 // The SPC
140 sWMSDeleteRequest_MessageTag * pTLVx11;
141 pTLVx11 = (sWMSDeleteRequest_MessageTag*)(pOut + offset);
142 memset( pTLVx11, 0, tlvx11Sz );
143
144 // Set the values
145 pTLVx11->mMessageTag = (eQMIWMSMessageTags)*pMessageTag;
146
147 offset += tlvx11Sz;
148 }
149
150 *pOutLen = offset;
151 return eGOBI_ERR_NONE;
152 }
153
154 /*===========================================================================
155 METHOD:
156 PackGetSMSList
157
158 DESCRIPTION:
159 This function returns the list of SMS messages stored on the device
160
161 PARAMETERS:
162 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
163 contain, upon output the number of BYTEs copied
164 to pOut
165 pOut [ O ] - Output buffer
166 storageType [ I ] - SMS message storage type
167 pRequestedTag [ I ] - Message index
168
169 RETURN VALUE:
170 ULONG - Return code
171 ===========================================================================*/
172 ULONG PackGetSMSList(
173 ULONG * pOutLen,
174 BYTE * pOut,
175 ULONG storageType,
176 ULONG * pRequestedTag )
177 {
178 // Validate arguments
179 if (pOut == 0)
180 {
181 return eGOBI_ERR_INVALID_ARG;
182 }
183
184 // Check size
185 WORD tlvx01Sz = sizeof( sWMSListMessagesRequest_MemoryStorage );
186 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
187 {
188 return eGOBI_ERR_BUFFER_SZ;
189 }
190
191 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
192 pHeader->mTypeID = 0x01;
193 pHeader->mLength = tlvx01Sz;
194
195 ULONG offset = sizeof( sQMIRawContentHeader );
196
197 // The storage type
198 sWMSListMessagesRequest_MemoryStorage * pTLVx01;
199 pTLVx01 = (sWMSListMessagesRequest_MemoryStorage*)(pOut + offset);
200 memset( pTLVx01, 0, tlvx01Sz );
201
202 // Set the values
203 pTLVx01->mStorageType = (eQMIWMSStorageTypes)storageType;
204
205 offset += tlvx01Sz;
206
207 // Add the Message tag, if specified
208 if (pRequestedTag != 0)
209 {
210 // Check size
211 WORD tlvx10Sz = sizeof( sWMSListMessagesRequest_MessageTag );
212 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
213 {
214 return eGOBI_ERR_BUFFER_SZ;
215 }
216
217 pHeader = (sQMIRawContentHeader*)(pOut + offset);
218 pHeader->mTypeID = 0x10;
219 pHeader->mLength = tlvx10Sz;
220
221 offset += sizeof( sQMIRawContentHeader );
222
223 // The SPC
224 sWMSListMessagesRequest_MessageTag * pTLVx10;
225 pTLVx10 = (sWMSListMessagesRequest_MessageTag*)(pOut + offset);
226 memset( pTLVx10, 0, tlvx10Sz );
227
228 // Set the values
229 pTLVx10->mMessageTag = (eQMIWMSMessageTags)*pRequestedTag;
230
231 offset += tlvx10Sz;
232 }
233
234 *pOutLen = offset;
235 return eGOBI_ERR_NONE;
236 }
237
238 /*===========================================================================
239 METHOD:
240 ParseGetSMSList
241
242 DESCRIPTION:
243 This function returns the list of SMS messages stored on the device
244
245 PARAMETERS:
246 inLen [ I ] - Length of input buffer
247 pIn [ I ] - Input buffer
248 pMessageListSize [I/O] - Upon input the maximum number of elements that the
249 message list array can contain. Upon successful
250 output the actual number of elements in the message
251 list array
252 pMessageList [ O ] - The message list array
253
254 RETURN VALUE:
255 ULONG - Return code
256 ===========================================================================*/
257 ULONG ParseGetSMSList(
258 ULONG inLen,
259 const BYTE * pIn,
260 ULONG * pMessageListSize,
261 BYTE * pMessageList )
262 {
263 // Validate arguments
264 if (pIn == 0 || pMessageListSize == 0
265 || *pMessageListSize == 0 || pMessageList == 0)
266 {
267 return eGOBI_ERR_INVALID_ARG;
268 }
269
270 ULONG maxMessageListSz = *pMessageListSize;
271
272 // Assume failure
273 *pMessageListSize = 0;
274
275 // Find the messages
276 const sWMSListMessagesResponse_MessageList * pTLVx01;
277 ULONG outLenx01;
278 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
279 if (rc != eGOBI_ERR_NONE)
280 {
281 return rc;
282 }
283
284 if (outLenx01 < sizeof( sWMSListMessagesResponse_MessageList ))
285 {
286 return eGOBI_ERR_MALFORMED_RSP;
287 }
288
289 ULONG messageListSz = pTLVx01->mNumberOfMessages;
290 if (messageListSz == 0)
291 {
292 // No stored messages, but not necessarily a failure
293 return eGOBI_ERR_NONE;
294 }
295
296 if (maxMessageListSz < messageListSz)
297 {
298 messageListSz = maxMessageListSz;
299 }
300
301 const sWMSListMessagesResponse_MessageList::sMessage * pMessages;
302
303 // Verify there is room for the array in the TLV
304 if (outLenx01 < sizeof( sWMSListMessagesResponse_MessageList )
305 + sizeof( sWMSListMessagesResponse_MessageList::sMessage )
306 * messageListSz)
307 {
308 return eGOBI_ERR_MALFORMED_RSP;
309 }
310
311 // Align to the first array element
312 pMessages = (const sWMSListMessagesResponse_MessageList::sMessage *)
313 ((const BYTE *)pTLVx01
314 + sizeof( sWMSListMessagesResponse_MessageList ));
315
316 ULONG * pData = (ULONG *)pMessageList;
317 for (ULONG m = 0; m < messageListSz; m++)
318 {
319 *pData++ = pMessages->mStorageIndex;
320 *pData++ = pMessages->mMessageTag;
321 pMessages++;
322 }
323
324 *pMessageListSize = messageListSz;
325 return eGOBI_ERR_NONE;
326 }
327
328 /*===========================================================================
329 METHOD:
330 PackGetSMS
331
332 DESCRIPTION:
333 This function returns an SMS message from device memory
334
335 PARAMETERS:
336 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
337 contain, upon output the number of BYTEs copied
338 to pOut
339 pOut [ O ] - Output buffer
340 storageType [ I ] - SMS message storage type
341 messageIndex [ I ] - Message index
342
343 RETURN VALUE:
344 ULONG - Return code
345 ===========================================================================*/
346 ULONG PackGetSMS(
347 ULONG * pOutLen,
348 BYTE * pOut,
349 ULONG storageType,
350 ULONG messageIndex )
351 {
352 // Validate arguments
353 if (pOut == 0)
354 {
355 return eGOBI_ERR_INVALID_ARG;
356 }
357
358 // Check size
359 WORD tlvx01Sz = sizeof( sWMSRawReadRequest_MessageIndex );
360 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
361 {
362 return eGOBI_ERR_BUFFER_SZ;
363 }
364
365 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
366 pHeader->mTypeID = 0x01;
367 pHeader->mLength = tlvx01Sz;
368
369 ULONG offset = sizeof( sQMIRawContentHeader );
370
371 // The index
372 sWMSRawReadRequest_MessageIndex * pTLVx01;
373 pTLVx01 = (sWMSRawReadRequest_MessageIndex*)(pOut + offset);
374 memset( pTLVx01, 0, tlvx01Sz );
375
376 // Set the values
377 pTLVx01->mStorageType = (eQMIWMSStorageTypes)storageType;
378 pTLVx01->mStorageIndex = messageIndex;
379
380 offset += tlvx01Sz;
381 *pOutLen = offset;
382
383 return eGOBI_ERR_NONE;
384 }
385
386 /*===========================================================================
387 METHOD:
388 ParseGetSMS
389
390 DESCRIPTION:
391 This function returns an SMS message from device memory
392
393 PARAMETERS:
394 inLen [ I ] - Length of input buffer
395 pIn [ I ] - Input buffer
396 pMessageTag [ O ] - Message tag
397 pMessageFormat [ O ] - Message format
398 pMessageSize [I/O] - Upon input the maximum number of bytes that can be
399 written to the message array. Upon successful
400 output the actual number of bytes written to the
401 message array
402 pMessage [ O ] - The message contents array
403
404 RETURN VALUE:
405 ULONG - Return code
406 ===========================================================================*/
407 ULONG ParseGetSMS(
408 ULONG inLen,
409 const BYTE * pIn,
410 ULONG * pMessageTag,
411 ULONG * pMessageFormat,
412 ULONG * pMessageSize,
413 BYTE * pMessage )
414 {
415 // Validate arguments
416 if (pIn == 0
417 || pMessageTag == 0
418 || pMessageFormat == 0
419 || pMessageSize == 0
420 || *pMessageSize == 0
421 || pMessage == 0)
422 {
423 return eGOBI_ERR_INVALID_ARG;
424 }
425
426 ULONG maxMessageSz = *pMessageSize;
427
428 // Assume failure
429 *pMessageSize = 0;
430
431 // Find the messages
432 const sWMSRawReadResponse_MessageData * pTLVx01;
433 ULONG outLenx01;
434 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
435 if (rc != eGOBI_ERR_NONE)
436 {
437 return rc;
438 }
439
440 if (outLenx01 < sizeof( sWMSRawReadResponse_MessageData ))
441 {
442 return eGOBI_ERR_MALFORMED_RSP;
443 }
444
445 *pMessageTag = pTLVx01->mMessageTag;
446 *pMessageFormat = pTLVx01->mMessageFormat;
447
448 ULONG messageSz = pTLVx01->mRawMessageLength;
449 if (messageSz == 0)
450 {
451 // No stored messages, but not necessarily a failure
452 return eGOBI_ERR_NONE;
453 }
454
455 if (messageSz > maxMessageSz)
456 {
457 messageSz = maxMessageSz;
458 }
459
460 // Verify there is room for the array in the TLV
461 if (outLenx01 < sizeof( sWMSRawReadResponse_MessageData ) + messageSz)
462 {
463 return eGOBI_ERR_MALFORMED_RSP;
464 }
465
466 memcpy( pMessage,
467 pTLVx01 + sizeof( sWMSRawReadResponse_MessageData ),
468 messageSz );
469
470 *pMessageSize = messageSz;
471 return eGOBI_ERR_NONE;
472 }
473
474 /*===========================================================================
475 METHOD:
476 PackModifySMSStatus
477
478 DESCRIPTION:
479 This function modifies the status of an SMS message saved in storage on
480 the device
481
482 PARAMETERS:
483 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
484 contain, upon output the number of BYTEs copied
485 to pOut
486 pOut [ O ] - Output buffer
487 storageType [ I ] - SMS message storage type
488 messageIndex [ I ] - Message index
489 messageTag [ I ] - Message tag
490
491 RETURN VALUE:
492 ULONG - Return code
493 ===========================================================================*/
494 ULONG PackModifySMSStatus(
495 ULONG * pOutLen,
496 BYTE * pOut,
497 ULONG storageType,
498 ULONG messageIndex,
499 ULONG messageTag )
500 {
501 // Validate arguments
502 if (pOut == 0)
503 {
504 return eGOBI_ERR_INVALID_ARG;
505 }
506
507 // Check size
508 WORD tlvx01Sz = sizeof( sWMSModifyTagRequest_MessageTag );
509 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
510 {
511 return eGOBI_ERR_BUFFER_SZ;
512 }
513
514 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
515 pHeader->mTypeID = 0x01;
516 pHeader->mLength = tlvx01Sz;
517
518 ULONG offset = sizeof( sQMIRawContentHeader );
519
520 // The index
521 sWMSModifyTagRequest_MessageTag * pTLVx01;
522 pTLVx01 = (sWMSModifyTagRequest_MessageTag*)(pOut + offset);
523 memset( pTLVx01, 0, tlvx01Sz );
524
525 // Set the values
526 pTLVx01->mStorageType = (eQMIWMSStorageTypes)storageType;
527 pTLVx01->mStorageIndex = messageIndex;
528 pTLVx01->mMessageTag = (eQMIWMSMessageTags)messageTag;
529
530 offset += tlvx01Sz;
531 *pOutLen = offset;
532
533 return eGOBI_ERR_NONE;
534 }
535
536 /*===========================================================================
537 METHOD:
538 PackSaveSMS
539
540 DESCRIPTION:
541 This function saves an SMS message to device memory
542
543 PARAMETERS:
544 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
545 contain, upon output the number of BYTEs copied
546 to pOut
547 pOut [ O ] - Output buffer
548 storageType [ I ] - SMS message storage type
549 messageFormat [ I ] - Message format
550 messageSize [ I ] - The length of the message contents in bytes
551 pMessage [ I ] - The message contents
552
553 RETURN VALUE:
554 ULONG - Return code
555 ===========================================================================*/
556 ULONG PackSaveSMS(
557 ULONG * pOutLen,
558 BYTE * pOut,
559 ULONG storageType,
560 ULONG messageFormat,
561 ULONG messageSize,
562 BYTE * pMessage )
563 {
564 // Validate arguments
565 if (pOut == 0 || messageSize == 0 || pMessage == 0)
566 {
567 return eGOBI_ERR_INVALID_ARG;
568 }
569
570 // Check size
571 WORD tlvx01Sz = sizeof( sWMSRawWriteRequest_MessageData )
572 + (WORD)messageSize;
573 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
574 {
575 return eGOBI_ERR_BUFFER_SZ;
576 }
577
578 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
579 pHeader->mTypeID = 0x01;
580 pHeader->mLength = tlvx01Sz;
581
582 ULONG offset = sizeof( sQMIRawContentHeader );
583
584 // The index
585 sWMSRawWriteRequest_MessageData * pTLVx01;
586 pTLVx01 = (sWMSRawWriteRequest_MessageData*)(pOut + offset);
587 memset( pTLVx01, 0, tlvx01Sz );
588
589 // Set the values
590 pTLVx01->mStorageType = (eQMIWMSStorageTypes)storageType;
591 pTLVx01->mMessageFormat = (eQMIWMSMessageFormats)messageFormat;
592 pTLVx01->mRawMessageLength = (UINT16)messageSize;
593
594 offset += sizeof( sWMSRawWriteRequest_MessageData );
595
596 // Add the message
597 memcpy( (pOut + offset), pMessage, messageSize );
598
599 offset += messageSize;
600
601 *pOutLen = offset;
602
603 return eGOBI_ERR_NONE;
604 }
605
606 /*===========================================================================
607 METHOD:
608 ParseSaveSMS
609
610 DESCRIPTION:
611 This function saves an SMS message to device memory
612
613 PARAMETERS:
614 inLen [ I ] - Length of input buffer
615 pIn [ I ] - Input buffer
616 pMessageIndex [ O ] - The message index assigned by the device
617
618 RETURN VALUE:
619 ULONG - Return code
620 ===========================================================================*/
621 ULONG ParseSaveSMS(
622 ULONG inLen,
623 const BYTE * pIn,
624 ULONG * pMessageIndex )
625 {
626 // Validate arguments
627 if (pIn == 0 || pMessageIndex == 0)
628 {
629 return eGOBI_ERR_INVALID_ARG;
630 }
631
632 // Find the messages
633 const sWMSRawWriteResponse_MessageIndex * pTLVx01;
634 ULONG outLenx01;
635 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
636 if (rc != eGOBI_ERR_NONE)
637 {
638 return rc;
639 }
640
641 if (outLenx01 < sizeof( sWMSRawWriteResponse_MessageIndex ))
642 {
643 return eGOBI_ERR_MALFORMED_RSP;
644 }
645
646 *pMessageIndex = pTLVx01->mStorageIndex;
647
648 return eGOBI_ERR_NONE;
649 }
650
651 /*===========================================================================
652 METHOD:
653 PackSendSMS
654
655 DESCRIPTION:
656 This function sends an SMS message for immediate over the air transmission
657
658 PARAMETERS:
659 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
660 contain, upon output the number of BYTEs copied
661 to pOut
662 pOut [ O ] - Output buffer
663 messageFormat [ I ] - Message format
664 messageSize [ I ] - The length of the message contents in bytes
665 pMessage [ I ] - The message contents
666
667 RETURN VALUE:
668 ULONG - Return code
669 ===========================================================================*/
670 ULONG PackSendSMS(
671 ULONG * pOutLen,
672 BYTE * pOut,
673 ULONG messageFormat,
674 ULONG messageSize,
675 BYTE * pMessage )
676 {
677 // Validate arguments
678 if (pOut == 0 || messageSize == 0 || pMessage == 0)
679 {
680 return eGOBI_ERR_INVALID_ARG;
681 }
682
683 // Check size
684 WORD tlvx01Sz = sizeof( sWMSRawSendRequest_MessageData )
685 + (WORD)messageSize;
686 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
687 {
688 return eGOBI_ERR_BUFFER_SZ;
689 }
690
691 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
692 pHeader->mTypeID = 0x01;
693 pHeader->mLength = tlvx01Sz;
694
695 ULONG offset = sizeof( sQMIRawContentHeader );
696
697 // The index
698 sWMSRawSendRequest_MessageData * pTLVx01;
699 pTLVx01 = (sWMSRawSendRequest_MessageData*)(pOut + offset);
700 memset( pTLVx01, 0, tlvx01Sz );
701
702 // Set the values
703 pTLVx01->mMessageFormat = (eQMIWMSMessageFormats)messageFormat;
704 pTLVx01->mRawMessageLength = (UINT16)messageSize;
705
706 offset += sizeof( sWMSRawSendRequest_MessageData );
707
708 // Add the message
709 memcpy( (pOut + offset), pMessage, messageSize );
710
711 offset += messageSize;
712
713 *pOutLen = offset;
714
715 return eGOBI_ERR_NONE;
716 }
717
718 /*===========================================================================
719 METHOD:
720 ParseSendSMS
721
722 DESCRIPTION:
723 This function sends an SMS message for immediate over the air transmission
724
725 PARAMETERS:
726 inLen [ I ] - Length of input buffer
727 pIn [ I ] - Input buffer
728 pMessageFailureCode [ O ] - When the function fails due to an error sending
729 the message this parameter may contain the
730 message failure cause code (see 3GPP2 N.S0005
731 Section 6.5.2.125). If the cause code is not
732 provided then the value will be 0xFFFFFFFF
733
734 RETURN VALUE:
735 ULONG - Return code
736 ===========================================================================*/
737 ULONG ParseSendSMS(
738 ULONG inLen,
739 const BYTE * pIn,
740 ULONG * pMessageFailureCode )
741 {
742 // Validate arguments
743 if (pIn == 0 || pMessageFailureCode == 0)
744 {
745 return eGOBI_ERR_INVALID_ARG;
746 }
747
748 // Assume we have no message failure cause code
749 *pMessageFailureCode = 0xffffffff;
750
751 // Check mandatory response
752 const sResultCode * pTLVx02;
753 ULONG outLenx02;
754 ULONG rc = GetTLV( inLen, pIn, 0x02, &outLenx02, (const BYTE **)&pTLVx02 );
755 if (rc != eGOBI_ERR_NONE)
756 {
757 return rc;
758 }
759
760 if (outLenx02 < sizeof( sResultCode ))
761 {
762 return eGOBI_ERR_MALFORMED_RSP;
763 }
764
765 if (pTLVx02->mQMIResult != eQMIResults_Success)
766 {
767 rc = pTLVx02->mQMIError + eGOBI_ERR_QMI_OFFSET;
768 }
769
770 if (rc != eGOBI_ERR_NONE)
771 {
772 // Check for the failure code (optional)
773 const sWMSRawSendResponse_CauseCode * pTLVx10;
774 ULONG outLenx10;
775 ULONG rc2 = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 );
776 if (rc2 == eGOBI_ERR_NONE)
777 {
778 if (outLenx10 < sizeof( sWMSRawSendResponse_CauseCode ))
779 {
780 return eGOBI_ERR_MALFORMED_RSP;
781 }
782
783 *pMessageFailureCode = pTLVx10->mCauseCode;
784 }
785 }
786
787 return rc;
788 }
789
790 /*===========================================================================
791 METHOD:
792 ParseGetSMSCAddress
793
794 DESCRIPTION:
795 This function returns the SMS center address
796
797 PARAMETERS:
798 inLen [ I ] - Length of input buffer
799 pIn [ I ] - Input buffer
800 addressSize [ I ] - The maximum number of characters (including NULL
801 terminator) that the SMS center address array
802 can contain
803 pSMSCAddress [ O ] - The SMS center address represented as a NULL
804 terminated string
805 typeSize [ I ] - The maximum number of characters (including NULL
806 terminator) that the SMS center address type array
807 can contain
808 pSMSCType [ O ] - The SMS center address type represented as a NULL
809 terminated string
810
811 RETURN VALUE:
812 ULONG - Return code
813 ===========================================================================*/
814 ULONG ParseGetSMSCAddress(
815 ULONG inLen,
816 const BYTE * pIn,
817 BYTE addressSize,
818 CHAR * pSMSCAddress,
819 BYTE typeSize,
820 CHAR * pSMSCType )
821 {
822 // Validate arguments
823 if (pIn == 0
824 || addressSize == 0 || pSMSCAddress == 0
825 || typeSize == 0 || pSMSCType == 0)
826 {
827 return eGOBI_ERR_INVALID_ARG;
828 }
829
830 // Assume empty
831 pSMSCAddress[0] = 0;
832 pSMSCType[0] = 0;
833
834 // Get the address (mandatory)
835 const sWMSGetSMSCAddressResponse_Address * pTLVx01;
836 ULONG outLenx01;
837 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
838 if (rc != eGOBI_ERR_NONE)
839 {
840 return rc;
841 }
842
843 if (outLenx01 < sizeof( sWMSRawSendResponse_CauseCode ))
844 {
845 return eGOBI_ERR_MALFORMED_RSP;
846 }
847
848 // Handle the type as a string (maximum 3 chars)
849 std::string smscType( &pTLVx01->mSMSCAddressType[0], 3 );
850
851 // Is the SMSC type present? (optional)
852 ULONG smscTypeLen = (ULONG)smscType.size();
853 if (smscTypeLen > 0)
854 {
855 // Space to perform copy?
856 if (typeSize < smscTypeLen + 1)
857 {
858 return eGOBI_ERR_BUFFER_SZ;
859 }
860
861 memcpy( pSMSCType, &pTLVx01->mSMSCAddressType[0], smscTypeLen );
862 pSMSCType[smscTypeLen] = 0;
863 }
864
865 // Treat the address as a null terminated string
866 std::string smscAddr( (const CHAR *)pTLVx01
867 + sizeof( sWMSGetSMSCAddressResponse_Address ),
868 pTLVx01->mSMSCAddressLength );
869
870 ULONG smscAddrLen = (ULONG)smscAddr.size();
871 if (addressSize < smscAddrLen + 1)
872 {
873 return eGOBI_ERR_BUFFER_SZ;
874 }
875
876 memcpy( pSMSCAddress, smscAddr.c_str(), addressSize );
877 pSMSCAddress[addressSize] = 0;
878
879 return rc;
880 }
881
882 /*===========================================================================
883 METHOD:
884 PackSetSMSCAddress
885
886 DESCRIPTION:
887 This function sets the SMS center address
888
889 PARAMETERS:
890 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
891 contain, upon output the number of BYTEs copied
892 to pOut
893 pOut [ O ] - Output buffer
894 pSMSCAddress [ I ] - The SMS center address represented as a NULL
895 terminated string
896 pSMSCType [ I ] - The SMS center address type represented as a NULL
897 terminated string (optional)
898
899 RETURN VALUE:
900 ULONG - Return code
901 ===========================================================================*/
902 ULONG PackSetSMSCAddress(
903 ULONG * pOutLen,
904 BYTE * pOut,
905 CHAR * pSMSCAddress,
906 CHAR * pSMSCType )
907 {
908 // Validate arguments
909 if (pOut == 0 || pSMSCAddress == 0)
910 {
911 return eGOBI_ERR_INVALID_ARG;
912 }
913
914 // The TLV contains only the address
915 std::string smscAddr( pSMSCAddress );
916
917 // Check size
918 WORD tlvx01Sz = (WORD)smscAddr.size();
919 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
920 {
921 return eGOBI_ERR_BUFFER_SZ;
922 }
923
924 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
925 pHeader->mTypeID = 0x01;
926 pHeader->mLength = tlvx01Sz;
927
928 ULONG offset = sizeof( sQMIRawContentHeader );
929
930 memcpy( (pOut + offset), smscAddr.c_str(), tlvx01Sz );
931 offset += tlvx01Sz;
932
933 // smscType is optional
934 if (pSMSCType != 0)
935 {
936 // The TLV contains only the type
937 std::string smscType( pSMSCType );
938
939 if (smscType.size() != 0)
940 {
941 // Check size
942 WORD tlvx10Sz = (WORD)smscType.size();
943 if (*pOutLen < offset + sizeof( sQMIRawContentHeader ) + tlvx10Sz)
944 {
945 return eGOBI_ERR_BUFFER_SZ;
946 }
947
948 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
949 pHeader->mTypeID = 0x10;
950 pHeader->mLength = tlvx10Sz;
951
952 ULONG offset = sizeof( sQMIRawContentHeader );
953
954 memcpy( (pOut + offset), smscType.c_str(), tlvx10Sz );
955 offset += tlvx10Sz;
956 }
957 }
958
959
960 *pOutLen = offset;
961
962 return eGOBI_ERR_NONE;
963 }
964
965 /*===========================================================================
966 METHOD:
967 ParseGetSMSRoutes
968
969 DESCRIPTION:
970 This function gets the current incoming SMS routing information
971
972 PARAMETERS:
973 inLen [ I ] - Length of input buffer
974 pIn [ I ] - Input buffer
975 pRouteSize [I/O] - Upon input the maximum number of elements that the
976 SMS route array can contain. Upon succes the actual
977 number of elements in the SMS route array
978 pRoutes [ O ] - The SMS route array
979
980 RETURN VALUE:
981 ULONG - Return code
982 ===========================================================================*/
983 ULONG ParseGetSMSRoutes(
984 ULONG inLen,
985 const BYTE * pIn,
986 BYTE * pRouteSize,
987 BYTE * pRoutes )
988 {
989 // Validate arguments
990 if (pIn == 0 || pRouteSize == 0 || *pRouteSize == 0 || pRoutes == 0)
991 {
992 return eGOBI_ERR_INVALID_ARG;
993 }
994
995 // Assume failure
996 BYTE maxRoutes = *pRouteSize;
997 *pRouteSize = 0;
998
999 // Get the route list
1000 const sWMSGetRoutesResponse_RouteList * pTLVx01;
1001 ULONG outLenx01;
1002 ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 );
1003 if (rc != eGOBI_ERR_NONE)
1004 {
1005 return rc;
1006 }
1007
1008 if (outLenx01 < sizeof( sWMSGetRoutesResponse_RouteList ))
1009 {
1010 return eGOBI_ERR_MALFORMED_RSP;
1011 }
1012
1013 ULONG routeCount = pTLVx01->mNumberOfRoutes;
1014 if (routeCount > (ULONG)maxRoutes)
1015 {
1016 routeCount = (ULONG)maxRoutes;
1017 }
1018
1019 const sWMSGetRoutesResponse_RouteList::sRoute * pInRoute;
1020
1021 // Verify there is room for the array in the TLV
1022 if (outLenx01 < sizeof( sWMSGetRoutesResponse_RouteList )
1023 + sizeof( sWMSGetRoutesResponse_RouteList::sRoute )
1024 * routeCount)
1025 {
1026 return eGOBI_ERR_MALFORMED_RSP;
1027 }
1028
1029 // Align to the first array element
1030 pInRoute = (const sWMSGetRoutesResponse_RouteList::sRoute *)
1031 ((const BYTE *)pTLVx01
1032 + sizeof( sWMSGetRoutesResponse_RouteList ));
1033
1034 ULONG * pRouteArray = (ULONG *)pRoutes;
1035 for (ULONG r = 0; r < routeCount; r++)
1036 {
1037 *pRouteArray++ = pInRoute->mMessageType;
1038 *pRouteArray++ = pInRoute->mMessageClass;
1039 *pRouteArray++ = pInRoute->mStorageType;
1040 *pRouteArray++ = pInRoute->mRouteValue;
1041 pInRoute++;
1042 }
1043
1044 *pRouteSize = (BYTE)routeCount;
1045 return rc;
1046 }
1047
1048 /*===========================================================================
1049 METHOD:
1050 PackSetSMSRoutes
1051
1052 DESCRIPTION:
1053 This function sets the desired incoming SMS routing information
1054
1055 PARAMETERS:
1056 pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can
1057 contain, upon output the number of BYTEs copied to pOut
1058 pOut [ O ] - Output buffer
1059 pRouteSize [ I ] - The number of elements in the SMS route array
1060 pRoutes [ I ] - The SMS route array
1061
1062 RETURN VALUE:
1063 ULONG - Return code
1064 ===========================================================================*/
1065 ULONG PackSetSMSRoutes(
1066 ULONG * pOutLen,
1067 BYTE * pOut,
1068 BYTE * pRouteSize,
1069 BYTE * pRoutes )
1070 {
1071 // Validate arguments
1072 if (pOut == 0 || pRouteSize == 0 || *pRouteSize == 0 || pRoutes == 0)
1073 {
1074 return eGOBI_ERR_INVALID_ARG;
1075 }
1076
1077 UINT16 routeCount = (ULONG)*pRouteSize;
1078
1079 // Check size
1080 WORD tlvx01Sz = sizeof( sWMSSetRoutesRequest_RouteList )
1081 + sizeof( sWMSSetRoutesRequest_RouteList::sRoute ) * routeCount;
1082 if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz)
1083 {
1084 return eGOBI_ERR_BUFFER_SZ;
1085 }
1086
1087 sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut);
1088 pHeader->mTypeID = 0x01;
1089 pHeader->mLength = tlvx01Sz;
1090
1091 ULONG offset = sizeof( sQMIRawContentHeader );
1092
1093 // Add route count
1094 sWMSSetRoutesRequest_RouteList * pTLVx01;
1095 pTLVx01 = (sWMSSetRoutesRequest_RouteList*)(pOut + offset);
1096 memset( pTLVx01, 0, tlvx01Sz );
1097
1098 // Set the values
1099 pTLVx01->mNumberOfRoutes = routeCount;
1100 offset += sizeof( sWMSSetRoutesRequest_RouteList );
1101
1102 sWMSSetRoutesRequest_RouteList::sRoute * pOutRoute;
1103
1104 // Align to the first array element
1105 pOutRoute = (sWMSSetRoutesRequest_RouteList::sRoute *)(pOut + offset);
1106
1107 // Add the routes
1108 ULONG * pRouteArray = (ULONG *)pRoutes;
1109 for (ULONG r = 0; r < routeCount; r++)
1110 {
1111 pOutRoute->mMessageType = (eQMIWMSMessageTypes)*pRouteArray++;
1112 pOutRoute->mMessageClass = (eQMIWMSMessageClasses)*pRouteArray++;
1113 pOutRoute->mStorageType = (eQMIWMSStorageTypes)*pRouteArray++;
1114 pOutRoute->mReceiptAction = (eQMIWMSReceiptActions)*pRouteArray++;
1115 pOutRoute++;
1116 offset += sizeof( sWMSSetRoutesRequest_RouteList::sRoute );
1117 }
1118
1119 *pOutLen = offset;
1120 return eGOBI_ERR_NONE;
1121 }