--- a/cbsatplugin/atmisccmdplugin/src/cusdcommandhandler.cpp Tue May 25 12:53:11 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/cusdcommandhandler.cpp Wed Jun 09 09:52:54 2010 +0300
@@ -15,8 +15,10 @@
#include <exterror.h>
+#include "ussdreadmessageimpl.h"
+#include "ussdsendmessageimpl.h"
+
#include "atmisccmdpluginconsts.h"
-#include "cusdreadwriteimp.h"
#include "debug.h"
const TUint8 KPhCltUssdCarriageReturn = 0x0d;
@@ -42,7 +44,7 @@
}
CCUSDCommandHandler::CCUSDCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
- CATCmdAsyncBase(aCallback, aATCmdParser, aPhone)
+ CATCmdSyncBase(aCallback, aATCmdParser, aPhone)
{
TRACE_FUNC_ENTRY
iSendAttributes.iDcs = KPhCltUssdDcsNotSet;
@@ -54,10 +56,12 @@
void CCUSDCommandHandler::ConstructL()
{
TRACE_FUNC_ENTRY
+ iReply.CreateL(KDefaultCmdBufLength);
+
User::LeaveIfError(iUssdMessaging.Open(iPhone));
- iUSSDSender = CCUSSDSendMessageImpl::NewL(this, iUssdMessaging);
- iUSSDReader = CCUSSDReadMessageImpl::NewL(this, iUssdMessaging);
+ iUSSDSender = CUSSDSendMessageImpl::NewL(this, iUssdMessaging);
+ iUSSDReader = CUSSDReadMessageImpl::NewL(this, iUssdMessaging);
//start a read session for network based ussd requests
User::LeaveIfError(iUSSDReader->ReadUSSDMessage(iReceivedData, iReceiveAttributes));
@@ -75,25 +79,18 @@
TRACE_FUNC_EXIT
}
-void CCUSDCommandHandler::DoCancel()
- {
- TRACE_FUNC_ENTRY
- // This would never get called as the AO is never activated
- TRACE_FUNC_EXIT
- }
-
-void CCUSDCommandHandler::HandleCommand( const TDesC8& aCmd,
+void CCUSDCommandHandler::HandleCommand( const TDesC8& /*aCmd*/,
RBuf8& /*aReply*/,
TBool /*aReplyNeeded*/ )
{
TRACE_FUNC_ENTRY
TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
-
+ iReply.Zero();
+
switch (cmdHandlerType)
{
case (TAtCommandParser::ECmdHandlerTypeTest):
{
- iReply.Create(KDefaultCmdBufLength);
iReply.Append(KCRLF);
iReply.Append(KCUSDSupportedCmdsList);
iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
@@ -101,7 +98,6 @@
}
case (TAtCommandParser::ECmdHandlerTypeRead):
{
- iReply.Create(KDefaultCmdBufLength);
iReply.Append(KCRLF);
iReply.Append(KAtCUSD);
iReply.AppendNum(iDisplayRetMessage);
@@ -112,28 +108,23 @@
}
case (TAtCommandParser::ECmdHandlerTypeSet):
{
- if(ParseCUSDCmd(aCmd) == KErrNone)
+ if(ParseCUSDCmd() == KErrNone)
{
if(iUSSDCommand.Length() == 0)
{
Trace(KDebugPrintD, "No USSD command: ", iUSSDCommand.Length());
-
+
// the USSD command is not set then this is a set
- iReply.Create(KDefaultCmdBufLength);
- iReply.Append(KCRLF);
- iReply.Append(KAtCUSD);
- iReply.AppendNum(iDisplayRetMessage);
- iReply.Append(KCRLF);
-
- iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
+ iReply.Append( KOKCRLF );
+ iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply);
}
else
{
- if(iUSSDSender->HandleSendUSSDCmd(iUSSDCommand, iSendAttributes) == KErrNone)
+ if(iUSSDSender->SendUSSDCmd(iUSSDCommand, iSendAttributes) == KErrNone)
{
iSendCommandSent = ETrue;
}
- else
+ else
{
iCallback->CreateReplyAndComplete(EReplyTypeError);
}
@@ -155,121 +146,131 @@
TRACE_FUNC_EXIT
}
-void CCUSDCommandHandler::RunL()
- {
- TRACE_FUNC_ENTRY
- // This would never get called as the AO is never activated
- TRACE_FUNC_EXIT
- }
-
-
void CCUSDCommandHandler::HandleCommandCancel()
{
TRACE_FUNC_ENTRY
iUSSDSender->Cancel();
+ iSendCommandSent = EFalse;
TRACE_FUNC_EXIT
}
-TInt CCUSDCommandHandler::ParseCUSDCmd(const TDesC8& aCmd)
+TInt CCUSDCommandHandler::ParseCUSDCmd()
{
TRACE_FUNC_ENTRY
- iReply.Create(KDefaultCmdBufLength);
- TBool tempRetMessage = EFalse;
- TInt ret = iATCmdParser.NextIntParam(tempRetMessage);
-
- if(ret == KErrNone)
+ TInt tempDispValue;
+ TInt ret = iATCmdParser.NextIntParam(tempDispValue);
+
+
+ if (ret == KErrNone && tempDispValue >= 0 && tempDispValue < 3)
{
- if(tempRetMessage < 0 || tempRetMessage > 2)
- {
- Trace(KDebugPrintD, "Display mode invalid: ", tempRetMessage);
- TRACE_FUNC_EXIT
- return KErrGeneral;
- }
- else
- {
- iDisplayRetMessage = tempRetMessage;
- }
+ Trace(KDebugPrintD, "tempDispValue: ", tempDispValue);
+ iDisplayRetMessage = tempDispValue;
+ }
+ else if (ret != KErrNotFound)
+ {
+ Trace(KDebugPrintD, "First NextIntParam failed: ", ret);
+ TRACE_FUNC_EXIT
+ return KErrGeneral;
}
// now parse the USSD command
- TPtrC8 command = iATCmdParser.NextTextParam(ret);
-
- if (ret == KErrNone)
+ TPtrC8 command;
+ ret = iATCmdParser.NextTextParam(command);
+ if (ret == KErrNone )
{
if(iUSSDCommand.Create(command.Length()) != KErrNone)
- {
- TRACE_FUNC_EXIT
- return KErrGeneral;
- }
-
- if(Pack(command, iUSSDCommand) < 0)
- {
- Trace(KDebugPrintS, "Pack() returned error, command: ", &command);
- TRACE_FUNC_EXIT
- return KErrGeneral;
- }
- }
-
- TInt tempDcs = -1;
- ret = iATCmdParser.NextIntParam(tempDcs);
-
- if(ret == KErrNone)
- {
- if(!IsDcsValid(tempDcs))
{
- Trace(KDebugPrintD, "Invalid coding standard: ", tempDcs);
+ Trace(KDebugPrintD, "iUSSDCommand.Create() failed ", ret);
TRACE_FUNC_EXIT
return KErrGeneral;
}
- else
+
+ Trace(KDebugPrintS, "command: ", &command);
+ if(Pack(command, iUSSDCommand) < 0)
{
- iSendAttributes.iDcs = tempDcs;
- }
- }
+ Trace(KDebugPrintS, "Pack() returned error, command: ", &command);
+ TRACE_FUNC_EXIT
+ return KErrGeneral;
+ }
+ }
+ else if (ret != KErrNotFound)
+ {
+ TRACE_FUNC_EXIT
+ return KErrGeneral;
+ }
+ TInt dcs = 0; // 3GPP TS 23.038 [25] Cell Broadcast Data Coding Scheme in integer format (default 0)
+ ret = iATCmdParser.NextIntParam(dcs);
+
+ Trace(KDebugPrintD, "ret: ", ret);
+ Trace(KDebugPrintD, "IsDcsValid(dcs): ", IsDcsValid(dcs));
+ Trace(KDebugPrintD, "iATCmdParser.NextParam().Length(): ", iATCmdParser.NextParam().Length());
+ if(ret != KErrNone && ret != KErrNotFound || !IsDcsValid(dcs) ||
+ iATCmdParser.NextParam().Length() != 0)
+ {
+ Trace(KDebugPrintD, "Second NextIntParam failed: ", ret);
+ TRACE_FUNC_EXIT
+ return KErrGeneral;
+ }
+ else
+ {
+ // dcs will have the default value if no parameter is given in the command line
+ Trace(KDebugPrintD, "dcs ", dcs);
+ iSendAttributes.iDcs = dcs;
+ }
+
TRACE_FUNC_EXIT
return KErrNone;
}
-void CCUSDCommandHandler::HandleSendMessageComplete(TInt aResult)
+void CCUSDCommandHandler::HandleSendMessageComplete(TInt aError)
+ {
+ TRACE_FUNC_ENTRY
+ if (aError != KErrNone)
+ {
+ // Only respond from a Send USSD request if there has been an error
+ iCallback->CreateReplyAndComplete(EReplyTypeError);
+ }
+ else if (iDisplayRetMessage == 0)
+ {
+ // if display mode is 0 then no response apart from OK should be displayed
+ iCallback->CreateReplyAndComplete( EReplyTypeOther, KOKCRLF );
+ }
+
+ iUSSDCommand.Close();
+ TRACE_FUNC_EXIT
+ }
+
+void CCUSDCommandHandler::HandleReadMessageComplete(TInt aError)
{
TRACE_FUNC_ENTRY
- if(aResult == KErrNone)
+ if(aError == KErrNone)
{
- iReply.Create(KDefaultCmdBufLength);
- iReply.Append(KCRLF);
- iReply.Append(KAtCUSD);
- iReply.Append(KCRLF);
- iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
+ if(iDisplayRetMessage)
+ {
+ FormatUSSDReceivedData();
+
+ if(iSendCommandSent)
+ {
+ iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
+ }
+ else
+ {
+ iCallback->HandleUnsolicitedRequest(iReply);
+ }
+ }
+
+ // as we have received the data initiated by the send USSD request we set
+ // this parameter to EFalse
+ iSendCommandSent = EFalse;
+
+ // re-issue the read request
+ iUSSDReader->ReadUSSDMessage(iReceivedData, iReceiveAttributes);
}
else
{
iCallback->CreateReplyAndComplete(EReplyTypeError);
}
-
- iSendCommandSent = EFalse;
- iUSSDCommand.Close();
- TRACE_FUNC_EXIT
- }
-
-void CCUSDCommandHandler::HandleReadMessageComplete(TInt aResult)
- {
- TRACE_FUNC_ENTRY
- if(iDisplayRetMessage)
- {
- FormatUSSDReceivedData();
-
- if(iSendCommandSent)
- {
- iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
- }
- else
- {
- iCallback->HandleUnsolicitedRequest(iReply);
- }
- }
- // re-issue the read request
- iUSSDReader->ReadUSSDMessage(iReceivedData, iReceiveAttributes);
TRACE_FUNC_EXIT
}
@@ -280,7 +281,7 @@
// Ensure we've got the right length
TInt packedOctetsRequired = PackedOctetsRequired( aIn.Length() );
- if ( packedOctetsRequired > ( aOut.MaxLength() - aOut.Length() ) )
+ if (packedOctetsRequired > ( aOut.MaxLength() - aOut.Length() ) )
{
Trace(KDebugPrintD, "packedOctetsRequired: ", packedOctetsRequired);
TRACE_FUNC_EXIT
@@ -289,72 +290,84 @@
// Do the conversion
TInt elementSizeInBits = ElementSizeInBits(TSmsDataCodingScheme::ESmsAlphabet7Bit);
- if ( elementSizeInBits == 8 ) // 8 bit data
+
+ Trace(KDebugPrintD, "elementSizeInBits = : ", elementSizeInBits);
+ if (elementSizeInBits == 8) // 8 bit data
{
// Straight copy here
aOut.Append( aIn );
}
- else if ( elementSizeInBits == 7 ) // Need packing to 7-bit
- {
- // Get raw pointers and do packing
- TUint8* outPtr = ( TUint8* )aOut.Ptr() + aOut.Length();
- const TUint8* inPtr = aIn.Ptr();
+ else if (elementSizeInBits == 7) // Need packing to 7-bit
+ {
+ Trace(KDebugPrintS, "aOut: ", &aOut);
+ Trace(KDebugPrintS, "aIn: ", &aIn);
+
+ // Get raw pointers and do packing
+ TUint8* outPtr = ( TUint8* )aOut.Ptr() + aOut.Length();
+ const TUint8* inPtr = aIn.Ptr();
- outPtr[0] = 0;
- for ( TInt i = 0; i < aIn.Length() ; ++i )
- {
- TUint8 to = inPtr[i];
- *outPtr |= ( to << startBit );
- if ( startBit )
+ TInt inLength = aIn.Length();
+ outPtr[0] = 0;
+
+ Trace(KDebugPrintD, "inLength = : ", inLength);
+ for (TInt i = 0; i < inLength; ++i)
+ {
+ TUint8 to = inPtr[i];
+ *outPtr |= ( to << startBit );
+
+ if (startBit)
+ {
+ ++outPtr;
+ *outPtr = ( TUint8 ) ( to >> ( 8 - startBit ) );
+ }
+
+ startBit = (startBit + 7) % 8; // roll 0,1,2,3,4,5,6,7,0,1,2,...
+ }
+
+ Trace(KDebugPrintD, "startBit = : ", startBit);
+
+ if ((inPtr[inLength - 1] == KPhCltUssdCarriageReturn && startBit == 0) || startBit == 1 )
+ {
+ //We have to add one CR more
+ *outPtr |= ( KPhCltUssdCarriageReturn << startBit );
+
+ if (startBit)
{
++outPtr;
- *outPtr = ( TUint8 ) ( to >> ( 8 - startBit ) );
+ *outPtr = (TUint8) (KPhCltUssdCarriageReturn >> (8 - startBit));
+ }
+ else
+ {
+ ++packedOctetsRequired;
}
- startBit = ( startBit + 7 )%8; // roll 0,1,2,3,4,5,6,7,0,1,2,...
-
- if ( i == aIn.Length() - 1 ) // if this is the last time
- {
- if ( ( to == KPhCltUssdCarriageReturn && startBit == 0 ) ||
- startBit == 1 )
- {
- //We have to add one CR more
- *outPtr |= ( KPhCltUssdCarriageReturn << startBit );
- if ( startBit )
- {
- ++outPtr;
- *outPtr = ( TUint8 ) ( KPhCltUssdCarriageReturn >> ( 8 - startBit ) );
- }
- else
- {
- ++packedOctetsRequired;
- }
- startBit = ( startBit + 7 )%8;
- }
- }
- }
- // Increment the length for the packed data
- aOut.SetLength( aOut.Length() + packedOctetsRequired );
+ startBit = (startBit + 7)%8;
}
+
+ // Increment the length for the packed data
+ aOut.SetLength(aOut.Length() + packedOctetsRequired);
+
+ Trace(KDebugPrintD, "aOut.Length() = : ", aOut.Length());
+ }
// Return number of bytes used
TRACE_FUNC_EXIT
return packedOctetsRequired;
}
- TInt CCUSDCommandHandler::PackedOctetsRequired( TInt aNumUDUnits ) const
+ TInt CCUSDCommandHandler::PackedOctetsRequired(TInt aNumUDUnits) const
{
TRACE_FUNC_ENTRY
TInt startBit = 0;
TInt octetsRequired = 0;
TInt elementSizeInBits = ElementSizeInBits(TSmsDataCodingScheme::ESmsAlphabet7Bit);
- if ( elementSizeInBits == 8 )
+ if (elementSizeInBits == 8)
{
octetsRequired=aNumUDUnits;
}
else
{
- octetsRequired = ( startBit + aNumUDUnits*elementSizeInBits + 7 )/8; // Rounds up
+ octetsRequired = (startBit + aNumUDUnits*elementSizeInBits + 7 )/8; // Rounds up
}
TRACE_FUNC_EXIT
return octetsRequired;
@@ -363,13 +376,13 @@
TBool CCUSDCommandHandler::IsDcsValid( const TUint8 aDcs ) const
{
TRACE_FUNC_ENTRY
- TBool isDcsValid( EFalse );
+ TBool isDcsValid(EFalse);
// 76543210
TUint8 codingGroup = ( aDcs & 0xF0 ) >> KHighNibbleShift; // bits XXXX____
TUint8 characterSet = ( aDcs & 0x0C ) >> KQuarterShift; // bits ____XX__
TUint8 lowQuartet = ( aDcs & 0x0F ); // bits ____XXXX
- switch ( codingGroup )
+ switch (codingGroup)
{
case 0x00:
case 0x02:
@@ -404,6 +417,10 @@
}
break;
}
+ default:
+ {
+ break;
+ }
}
TRACE_FUNC_EXIT
return isDcsValid;
@@ -413,7 +430,7 @@
{
TRACE_FUNC_ENTRY
TInt ret;
- switch ( aAlphabet )
+ switch (aAlphabet)
{
case TSmsDataCodingScheme::ESmsAlphabet7Bit:
{
@@ -438,8 +455,8 @@
void CCUSDCommandHandler::FormatUSSDReceivedData()
{
TRACE_FUNC_ENTRY
- iReply.Create(KDefaultCmdBufLength);
-
+ iReply.Zero();
+
iReply.Append(KCRLF);
iReply.Append(KAtCUSD);
iReply.AppendNum(iDisplayRetMessage);