| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
Gobi3000TranslationVoice.cpp |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
QUALCOMM Translation for Gobi 3000 (Voice Service for USSD) |
| 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 |
// Pragmas (pack structs) |
| 43 |
//--------------------------------------------------------------------------- |
| 44 |
#pragma pack( push, 1 ) |
| 45 |
|
| 46 |
/*=========================================================================*/ |
| 47 |
// Struct sUSSDInfo |
| 48 |
// Struct to represent USSD/Alpha information header |
| 49 |
/*=========================================================================*/ |
| 50 |
struct sUSSDInfoHdr |
| 51 |
{ |
| 52 |
public: |
| 53 |
BYTE mDCS; |
| 54 |
BYTE mLength; |
| 55 |
|
| 56 |
// Data of 'mLength' follows |
| 57 |
}; |
| 58 |
|
| 59 |
//--------------------------------------------------------------------------- |
| 60 |
// Pragmas |
| 61 |
//--------------------------------------------------------------------------- |
| 62 |
#pragma pack( pop ) |
| 63 |
|
| 64 |
/*=========================================================================== |
| 65 |
METHOD: |
| 66 |
PackOriginateUSSD |
| 67 |
|
| 68 |
DESCRIPTION: |
| 69 |
This function initiates a USSD operation |
| 70 |
|
| 71 |
PARAMETERS: |
| 72 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 73 |
contain, upon output the number of BYTEs copied |
| 74 |
to pOut |
| 75 |
pOut [ O ] - Output buffer |
| 76 |
pInfo [ I ] - USSD information |
| 77 |
|
| 78 |
RETURN VALUE: |
| 79 |
ULONG - Return code |
| 80 |
===========================================================================*/ |
| 81 |
ULONG PackOriginateUSSD( |
| 82 |
ULONG * pOutLen, |
| 83 |
BYTE * pOut, |
| 84 |
BYTE * pInfo ) |
| 85 |
{ |
| 86 |
// Validate arguments |
| 87 |
if (pOut == 0 || pInfo == 0) |
| 88 |
{ |
| 89 |
return eGOBI_ERR_INVALID_ARG; |
| 90 |
} |
| 91 |
|
| 92 |
const WORD INFO_HDR_SZ = sizeof( sUSSDInfoHdr ); |
| 93 |
|
| 94 |
// This assumes that pInfo is at least 2 bytes long |
| 95 |
sUSSDInfoHdr * pInInfo = (sUSSDInfoHdr *)pInfo; |
| 96 |
WORD infoLen = pInInfo->mLength + INFO_HDR_SZ; |
| 97 |
|
| 98 |
// Check size |
| 99 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + infoLen) |
| 100 |
{ |
| 101 |
return eGOBI_ERR_BUFFER_SZ; |
| 102 |
} |
| 103 |
|
| 104 |
// Add pInfo |
| 105 |
|
| 106 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 107 |
pHeader->mTypeID = 0x01; |
| 108 |
pHeader->mLength = infoLen; |
| 109 |
|
| 110 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 111 |
|
| 112 |
// No pTLVx01 since pInfo is our TLV |
| 113 |
memcpy( (pOut + offset), pInfo, infoLen ); |
| 114 |
|
| 115 |
offset += infoLen; |
| 116 |
*pOutLen = offset; |
| 117 |
|
| 118 |
return eGOBI_ERR_NONE; |
| 119 |
} |
| 120 |
|
| 121 |
/*=========================================================================== |
| 122 |
METHOD: |
| 123 |
PackAnswerUSSD |
| 124 |
|
| 125 |
DESCRIPTION: |
| 126 |
This function responds to a USSD request from the network |
| 127 |
|
| 128 |
PARAMETERS: |
| 129 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 130 |
contain, upon output the number of BYTEs copied |
| 131 |
to pOut |
| 132 |
pOut [ O ] - Output buffer |
| 133 |
pInfo [ I ] - USSD information |
| 134 |
|
| 135 |
RETURN VALUE: |
| 136 |
ULONG - Return code |
| 137 |
===========================================================================*/ |
| 138 |
ULONG PackAnswerUSSD( |
| 139 |
ULONG * pOutLen, |
| 140 |
BYTE * pOut, |
| 141 |
BYTE * pInfo ) |
| 142 |
{ |
| 143 |
// Validate arguments |
| 144 |
if (pOut == 0 || pInfo == 0) |
| 145 |
{ |
| 146 |
return eGOBI_ERR_INVALID_ARG; |
| 147 |
} |
| 148 |
|
| 149 |
const WORD INFO_HDR_SZ = sizeof( sUSSDInfoHdr ); |
| 150 |
|
| 151 |
// This assumes that pInfo is at least 2 bytes long |
| 152 |
sUSSDInfoHdr * pInInfo = (sUSSDInfoHdr *)pInfo; |
| 153 |
WORD infoLen = pInInfo->mLength + INFO_HDR_SZ; |
| 154 |
|
| 155 |
// Check size |
| 156 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + infoLen) |
| 157 |
{ |
| 158 |
return eGOBI_ERR_BUFFER_SZ; |
| 159 |
} |
| 160 |
|
| 161 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 162 |
pHeader->mTypeID = 0x01; |
| 163 |
pHeader->mLength = infoLen; |
| 164 |
|
| 165 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 166 |
|
| 167 |
// No pTLVx01 since pInfo is our TLV |
| 168 |
memcpy( (pOut + offset), pInfo, infoLen ); |
| 169 |
|
| 170 |
offset += infoLen; |
| 171 |
*pOutLen = offset; |
| 172 |
|
| 173 |
return eGOBI_ERR_NONE; |
| 174 |
} |