diff -r 000000000000 -r 63b37f68c1ce adaptationlayer/modematadaptation/modematcontroller_exe/src/cmodematpipecontroller.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/adaptationlayer/modematadaptation/modematcontroller_exe/src/cmodematpipecontroller.cpp Fri Nov 06 17:28:23 2009 +0000 @@ -0,0 +1,718 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#include //For ISC +#include //isc definitions +#include +#ifndef NCP_COMMON_BRIDGE_FAMILY +#include +#endif +#include //for isimessage +#include //pipe +#include //pipe +#include "cmodematpipecontroller.h" +#include "cmodemathandler.h" +#include //redirectreq error codes +#include "modemattrace.h" +#include "cmodematsrv.h" + +const TInt KInvalidPipeHandle = -1; +#ifndef NCP_COMMON_BRIDGE_FAMILY +const TUint8 PEP_COMM_IND_ID_ESCAPE(0x07); +const TInt KInvalidDteId = -1; +const TUint8 KFiller = 0; +const TUint8 KDefaultTrId(0); +const TUint8 KTaskIdQuerySize(20); +#endif + +CModemAtPipeController* CModemAtPipeController::NewL( RIscApi& aIscApi, + TUint& aObjId, + CModemAtHandler& aHandler ) + { + CModemAtPipeController* self = new (ELeave) CModemAtPipeController( aIscApi,aObjId, aHandler ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +void CModemAtPipeController::ConstructL() + { + C_TRACE (( _T("CModemAtPipeController::ConstructL()") )); + } + +CModemAtPipeController::~CModemAtPipeController() + { + C_TRACE((_L(">>CModemAtPipeController::~CModemAtPipeController()"))); + if( iSchedulerWait ) + { + C_TRACE((_L("CModemAtPipeController::~CModemAtPipeController() iSchedulerWait->Stop"))); + iSchedulerWait->AsyncStop(); + delete iSchedulerWait; + iSchedulerWait = NULL; + } + C_TRACE((_L("<Des(); + TIsiSend isimessage( messageptr, ISI_HEADER_SIZE + SIZE_PNS_PIPE_CREATE_REQ ); + isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_PIPE ); + + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_UTID, 0); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_SUBFUNCTION, PNS_PIPE_CREATE_REQ ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_STATEAFTERCREATION ,PN_PIPE_DISABLE ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_PRIORITY ,0 ); + + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_FIRSTPEPDEV, aDevId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_FIRSTPEPOBJ, aObjId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_FIRSTPEPTYPE, PN_PEP_TYPE_COMMON ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_FILLERBYTE1, KFiller ); + + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_SECONDPEPDEV, THIS_DEVICE ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_SECONDPEPOBJ, iModemAtObjId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_CREATE_REQ_OFFSET_SECONDPEPTYPE, PN_PEP_TYPE_COMMON ); + isimessage.Complete(); + + C_TRACE(_L("Created ISI-message")); + DUMP_MESSAGE( messageptr ); + TInt retVal = iIscApi.Send( messageptr ); + ASSERT_PANIC_ALWAYS( retVal == KErrNone ); + delete message; + } + + + void CModemAtPipeController::HandlePipeCreateResp( const TIsiReceiveC& aReceivedMessage ) + { + C_TRACE (( _T("CModemAtPipeController::HandlePipeCreateResp()") )); + TInt error = aReceivedMessage.Get8bit(ISI_HEADER_SIZE + PNS_PIPE_CREATE_RESP_OFFSET_ERRORCODE ); + C_TRACE((_L("Pipe create resp: %d"), error )); + TRACE_ASSERT( iDteId != KInitialDteId ); + + if( error == PN_PIPE_NO_ERROR) + { + iPipeHandle = aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PIPE_CREATE_RESP_OFFSET_PIPEHANDLE ); + C_TRACE( (_L("handle %d"), iPipeHandle )); + iPipeTable[iDteId].iHandle = iPipeHandle; + iPipeTable[iDteId].iFirstDevId = iDataportDevId; + iPipeTable[iDteId].iFirstObjId = iDataportObjId; + iPipeTable[iDteId].iSecondDevId = THIS_DEVICE; + iPipeTable[iDteId].iSecondObjId = iModemAtObjId; + ChangePipeState( iDteId, TPipeInfo::EPipeCreated ); + iPipeHandle = KInvalidPipeHandle; + iDteId = KInitialDteId; + } + else + { + C_TRACE (( _T("iPipeHandle == KInvalidPipeHandle "))); + iPipeTable[iDteId].iHandle = KInvalidPipeHandle; + iPipeTable[iDteId].iFirstDevId = 0; + iPipeTable[iDteId].iFirstObjId = 0; + iPipeTable[iDteId].iSecondDevId = 0; + iPipeTable[iDteId].iSecondObjId = 0; + ChangePipeState( iDteId, TPipeInfo::EPipeNoPipe ); + ASSERT_ALWAYS; + } + } + + void CModemAtPipeController::LinkDteIdToPipe( const TUint8 aDteId ) + { + C_TRACE (( _T("CModemAtPipeController::LinkDteIdToPipe(0x%x)"), aDteId )); + TRACE_ASSERT( aDteId < KMaxDteIdCount ); + iDteId = aDteId; + if( iDataportDevId == THIS_DEVICE ) + { + C_TRACE((_L("CREATE PIPE FROM DATAPORT (plugins are connecting) (devid %x o-bjid %x) "),iDataportDevId,iDataportObjId)); + SendCreatePipeMessage( iDataportDevId, iDataportObjId ); + } + else + { + C_TRACE((_L("Dataport has not been created (devid %x o-bjid %x) "), iDataportDevId, iDataportObjId )); + C_TRACE (( _T("iPipeHandle == KInvalidPipeHandle "))); + iPipeTable[aDteId].iHandle = KInvalidPipeHandle; + iPipeTable[aDteId].iFirstDevId = 0; + iPipeTable[aDteId].iFirstObjId = 0; + iPipeTable[aDteId].iSecondDevId = 0; + iPipeTable[aDteId].iSecondObjId = 0; + ChangePipeState( aDteId, TPipeInfo::EPipeNoPipe ); + } + } + + +void CModemAtPipeController::HandlePipeRemoveResp( const TIsiReceiveC& aReceivedMessage ) + { + C_TRACE (( _T(">>CModemAtPipeController::HandlePipeRemoveResp()") )); + TInt error = aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PIPE_REMOVE_RESP_OFFSET_ERRORCODE ); + TInt pipehandle = aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PIPE_REMOVE_RESP_OFFSET_PIPEHANDLE ); + + TInt dteId = FindDteId( pipehandle ); + ASSERT_PANIC_ALWAYS( dteId < KMaxDteIdCount ) + ASSERT_PANIC_ALWAYS( error == PN_PIPE_NO_ERROR ) + ChangePipeState( dteId, TPipeInfo::EPipeNoPipe ); + + iPipeTable[ dteId ].iHandle = KInvalidPipeHandle; + + if( iSchedulerWait ) + { + C_TRACE((_L("CModemAtPipeController::HandlePipeRemoveResp() iSchedulerWait->Stop"))); + iSchedulerWait->AsyncStop(); + delete iSchedulerWait; + iSchedulerWait = NULL; + } + C_TRACE((_L("<>CModemAtPipeController::SendRemovePipeReq()") )); + C_TRACE((_L("Remove pipe handle %d"), aPipeHandle)); + TInt size = ISI_HEADER_SIZE + SIZE_PNS_PIPE_REMOVE_REQ; + HBufC8* message = HBufC8::New( size ); + ASSERT_PANIC_ALWAYS( message ); + + TPtr8 messageptr = message->Des(); + TIsiSend isimessage( messageptr, size ); + isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_PIPE ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REMOVE_REQ_OFFSET_UTID, 0 ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REMOVE_REQ_OFFSET_SUBFUNCTION, + PNS_PIPE_REMOVE_REQ ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REMOVE_REQ_OFFSET_PIPEHANDLE, + aPipeHandle ); //disabled + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REMOVE_REQ_OFFSET_FILLERBYTE1 ,0 ); + isimessage.Complete(); + C_TRACE(_L("Created ISI-message")); + + TInt retVal = iIscApi.Send( messageptr ); + ASSERT_PANIC_ALWAYS( retVal == KErrNone ); + delete message; + if( !iSchedulerWait ) + { + C_TRACE(_L("CModemAtPipeController::SendRemovePipeReq() iSchedulerWait->Start()")); + TRAPD(err, iSchedulerWait = new (ELeave) CActiveSchedulerWait); + ASSERT_PANIC_ALWAYS( err == KErrNone ); + iSchedulerWait->Start(); + } + C_TRACE (( _T("< cant redirect")); + return; + } + + if( aNewDevId == THIS_DEVICE && aNewObjId == iModemAtObjId ) + { + C_TRACE((_L("CModemAtPipeController::RedirectPipe() EPipeDisabled. iModemAtObjId: 0x%x"), iModemAtObjId)); + ChangePipeState( aDteId, TPipeInfo::EPipeDisabled ); + } + else + { + C_TRACE(_L("CModemAtPipeController::RedirectPipe() EPipeRedirected")); + ChangePipeState( aDteId, TPipeInfo::EPipeRedirected ); + } + + C_TRACE(_L("CModemAtPipeController::RedirectPipe() Redirecting pipe")); + + HBufC8* message = HBufC8::New( ISI_HEADER_SIZE + SIZE_PNS_PIPE_REDIRECT_REQ ); + ASSERT_PANIC_ALWAYS( message ) + TPtr8 messageptr = message->Des(); + TIsiSend isimessage( messageptr, ISI_HEADER_SIZE + SIZE_PNS_PIPE_REDIRECT_REQ ); + isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID,PN_PIPE); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_UTID, 0); + + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_SUBFUNCTION, + PNS_PIPE_REDIRECT_REQ ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_PIPEHANDLE, + iPipeTable[aDteId].iHandle ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_STATEAFTERCREATION, + PN_PIPE_DISABLE ); + //old pep + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_OLDPEPDEV, + iPipeTable[aDteId].iSecondDevId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_OLDPEPOBJ, + iPipeTable[aDteId].iSecondObjId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_OLDPEPTYPE, PN_PEP_TYPE_COMMON); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_FILLERBYTE1, KFiller ); + + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_REPLACEMENTPEPDEV, aNewDevId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_REPLACEMENTPEPOBJ, aNewObjId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_REPLACEMENTPEPTYPE, + PN_PEP_TYPE_COMMON ); + + iPipeTable[aDteId].iSecondDevId = aNewDevId; + iPipeTable[aDteId].iSecondObjId = aNewObjId; + + isimessage.Set8bit(ISI_HEADER_SIZE + PNS_PIPE_REDIRECT_REQ_OFFSET_NSB, KFiller ); + isimessage.Complete(); + + C_TRACE(_L("Created ISI-message")); + TInt retVal = iIscApi.Send( messageptr ); + ASSERT_PANIC_ALWAYS( retVal == KErrNone ); + delete message; + } + +void CModemAtPipeController::HandlePipeRedirectResp( const TIsiReceiveC& aReceivedMessage ) + { + C_TRACE (( _T("CModemAtPipeController::HandlePipeRedirectResp()") )); + TInt error = aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PIPE_REDIRECT_RESP_OFFSET_ERRORCODE ); + TInt pipeHandle = aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PIPE_REDIRECT_RESP_OFFSET_PIPEHANDLE ); + C_TRACE((_L("CModemAtPipeController::HandlePipeRedirectResp() pipehandle: %d"), pipeHandle )); + TInt dteId = FindDteId( pipeHandle ); + + if( error != PN_PIPE_NO_ERROR ) + { + if( dteId != KInvalidDteId ) + { + C_TRACE(( _L("CModemAtPipeController::HandlePipeRedirectResp() pipe error: %d"), error )); + iAtHandler.SendAtModemDataRedirectResultReq( dteId, AT_MODEM_REDIRECT_RESULT_ERROR); + RemovePipe( dteId ); + return; + } + else + { + C_TRACE(( _L("CModemAtPipeController::HandlePipeRedirectResp() dteId not found, pipe error: %d"), error )); + TRACE_ASSERT_ALWAYS; + return; + } + } + + iAtHandler.SendAtModemDataRedirectResultReq( dteId, AT_MODEM_REDIRECT_RESULT_OK ); + + if( iPipeTable[ dteId ].iPipeState != TPipeInfo::EPipeDisabled ) + { + SendEnablePipeReq( pipeHandle ); + } + + } + +void CModemAtPipeController::SendTaskIdQuery() + { + C_TRACE (( _T("CModemAtPipeController::SendTaskIdQuery()") )); + HBufC8* message = HBufC8::New( KTaskIdQuerySize ); + TRACE_ASSERT( message ); + if( message ) + { + TPtr8 messageptr = message->Des(); + TIsiSend isimessage( messageptr, KTaskIdQuerySize ); + isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_NAMESERVICE ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_UTID, KDefaultTrId ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_SUBFUNCTION, PNS_NAME_QUERY_REQ ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_RESERVED1, 0 ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_RESERVED2, 0); + isimessage.Set32bit( ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_NAME, PN_AT_MODEM ); + isimessage.Set32bit( ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_BITMASK, PN_AT_MODEM ); + isimessage.Complete(); + + DUMP_MESSAGE( messageptr ); + TInt retVal = iIscApi.Send( messageptr ); + ASSERT_PANIC_ALWAYS( retVal == KErrNone ); + delete message; + } + } + +void CModemAtPipeController::SendEnablePipeReq( const TUint8 aPipeHandle ) + { + C_TRACE (( _T("CModemAtPipeController::SendEnablePipeReq()") )); + HBufC8* message = HBufC8::New( ISI_HEADER_SIZE + SIZE_PNS_PIPE_ENABLE_REQ ); + ASSERT_PANIC_ALWAYS( message ) + TPtr8 messageptr = message->Des(); + TIsiSend isimessage( messageptr, ISI_HEADER_SIZE + SIZE_PNS_PIPE_ENABLE_REQ ); + isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_PIPE ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_ENABLE_REQ_OFFSET_UTID, 0 ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_ENABLE_REQ_OFFSET_SUBFUNCTION, PNS_PIPE_ENABLE_REQ ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_ENABLE_REQ_OFFSET_PIPEHANDLE , aPipeHandle ); + isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PIPE_ENABLE_REQ_OFFSET_FILLERBYTE1 , 0 ); + isimessage.Complete(); + + DUMP_MESSAGE( messageptr ); + TInt retVal = iIscApi.Send( messageptr ); + ASSERT_PANIC_ALWAYS( retVal == KErrNone ); + delete message; + } + + TInt CModemAtPipeController::FindDteId( const TInt aHandle ) + { + C_TRACE (( _T("CModemAtPipeController::FindDteId()") )); + TInt dteId = KInvalidDteId; + for( TInt i = 0 ; i < KMaxDteIdCount ; i++ ) + { + if( iPipeTable[i].iHandle == aHandle ) + { + dteId = i; + break; + } + } + + TRACE_ASSERT( dteId != KInvalidDteId ); + C_TRACE((_L("CModemAtPipeController::FindDteId() returns dteid: %d"),dteId)); + return dteId; + } + + +void CModemAtPipeController::HandlePipeEnabledResp( const TIsiReceiveC& aReceivedMessage ) + { + C_TRACE (( _T("CModemAtPipeController::HandlePipeEnabledResp()") )); + TInt error = aReceivedMessage.Get8bit(ISI_HEADER_SIZE + + PNS_PIPE_ENABLE_RESP_OFFSET_ERRORCODE); + TInt pipeHandle = aReceivedMessage.Get8bit(ISI_HEADER_SIZE + + PNS_PIPE_ENABLE_RESP_OFFSET_PIPEHANDLE); + TInt dteId = FindDteId(pipeHandle); + C_TRACE((_L("CModemAtPipeController::HandlePipeEnabledResp() pipehandle %d"), pipeHandle)); + + if( error == PN_PIPE_NO_ERROR ) + { + ChangePipeState( dteId, TPipeInfo::EPipeEnabled ); + } + else + { + C_TRACE((_L("CModemAtPipeController::HandlePipeEnabledResp() pipe error: %d"), error)); + TRACE_ASSERT_ALWAYS; + } + } + + +void CModemAtPipeController::ChangePipeState( + const TInt aDteId, + TPipeInfo::EPipeState aState ) + { + C_TRACE((_L("CModemAtPipeController::ChangePipeState(%d, %d)"), aDteId, aState)); + C_TRACE(( _L("Was: iPipeTable[ %d ].iPipeState = %d"), aDteId, (TInt)iPipeTable[ aDteId ].iPipeState )); + iPipeTable[ aDteId ].iPipeState = aState; + if( aState == TPipeInfo::EPipeEnabled ) + { + C_TRACE(( _T("DATA MODE") )); + iAtHandler.HandleCommandModeChange( aDteId, EDataMode ); + } + else if( aState == TPipeInfo::EPipeDisabled ) + { + C_TRACE(( _T("COMMAND MODE") )); + iAtHandler.HandleCommandModeChange( aDteId, ECommandMode ); + } + } + +void CModemAtPipeController::HandlePepStatusInd( const TIsiReceiveC& aReceivedMessage ) + { + C_TRACE(( _L("CModemAtPipeController::HandlePepStatusInd"))); + TUint8 pepType( aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PEP_STATUS_IND_OFFSET_PEPTYPE ) ); + if( pepType == PN_PEP_TYPE_COMM ) + { + TUint8 indicationId( aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PEP_STATUS_IND_OFFSET_INDICATIONID ) ); + if( indicationId == PEP_COMM_IND_ID_ESCAPE ) + { + TUint8 pipeHandle( aReceivedMessage.Get8bit( ISI_HEADER_SIZE + + PNS_PEP_STATUS_IND_OFFSET_PIPEHANDLE ) ); + TInt dteId( FindDteId( pipeHandle ) ); + C_TRACE( (_L("CModemAtPipeController PEP_COMM_IND_ID_ESCAPE received, pipehandle %d dteid %d"), pipeHandle, dteId )); + + if( dteId != KInvalidDteId ) + { + C_TRACE( (_L("SendEscapeSignalDetection dteid %d"), dteId )); + iAtHandler.SendEscapeSignalDetection( dteId ); + } + } + // Not know should any other indicationid from comm pep type to be handled + else + { + C_TRACE((_L("CModemAtPipeController Indication ignored pepType %d indicationId: %d "), pepType, indicationId)); + } + } + // pep type comm only supported one + else + { + C_TRACE((_L("CModemAtPipeController Peptype ignored %d "), pepType)); + } + } + + #endif // NCP_COMMON_BRIDGE_FAMILY +