Debian Codegraph @

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