Exemplo n.º 1
0
void CMyService::ConstructL()
	{
	User::LeaveIfError(iSocketServ.Connect());
	iSCOConnection = new(ELeave) CMySCOService(iSocketServ);
	iSCOConnection->ConstructL();
	User::LeaveIfError(iSdpSession.Connect());
	TBTServiceSecurity sec;
	sec.SetAuthentication(EMitmNotRequired);
	sec.SetAuthorisation(EFalse);
	sec.SetEncryption(EFalse);
	sec.SetDenied(EFalse);
	iBtService = CBtService::NewL(TUUID(KSerialPortUUID), //register as a serial port so we can be easily seen
								iSdpSession,
								iSocketServ,
								*this,
								KRFCOMM,
								&sec);
	iConnection = CBluetoothSocket::NewL(*this, iSocketServ);
	iBtService->AcceptConnection(*iConnection);
	}
Exemplo n.º 2
0
// ----------------------------------------------------------------------------
// CChatBt::SetSecurityWithChannelL( )
// Sets the security on the channel port and returns the available port.
// ----------------------------------------------------------------------------
//
void CChatBt::SetSecurityWithChannelL( 
    TBool aAuthentication,
    TBool aEncryption,
    TBool aAuthorisation,
    TBool aDenied,
    TInt& aChannel )

    {

    // Local variable to channel to listen to.
    TInt channel;


    User::LeaveIfError( iSocket.GetOpt( 
        KRFCOMMGetAvailableServerChannel, 
        KSolBtRFCOMM, 
        channel ) );

    TBTSockAddr listeningAddress;
    // Set the Port to listen to.
    listeningAddress.SetPort( channel );

    // Write Log events
    HBufC* strGetPort = StringLoader::LoadLC ( R_CHAT_STR_GET_PORT );

    iLog.LogL( *strGetPort, channel );
    CleanupStack::PopAndDestroy( strGetPort );


    User::LeaveIfError( iSocket.Bind( listeningAddress ) );
    User::LeaveIfError( iSocket.Listen( KListeningQueSize ) );

     // close old connection - if any
    iAcceptedSocket.Close();

    // Open abstract socket
    User::LeaveIfError( iAcceptedSocket.Open( iSocketServer ) );  

    // Set the Active Object's State to Connecting indicated.
    SetState( EConnecting );

    iSocket.Accept( iAcceptedSocket, iStatus );
  
    iActiveSocket = &iAcceptedSocket;
  
    // Set the Active Object Active again,
    SetActive();

    // Write Log events
    HBufC* acceptNextConn = StringLoader::LoadLC ( 
        R_CHAT_ACCEPT_NEXT_CONN );
    iLog.LogL( *acceptNextConn );
    CleanupStack::PopAndDestroy( acceptNextConn );

 
    // Set the security according to.
    TBTServiceSecurity serviceSecurity;
    serviceSecurity.SetUid ( KUidChatApp );
    serviceSecurity.SetAuthentication ( aAuthentication );
    serviceSecurity.SetEncryption ( aEncryption );
    serviceSecurity.SetAuthorisation ( aAuthorisation );
    serviceSecurity.SetDenied( aDenied );

    // Attach the security settings.
    listeningAddress.SetSecurity(serviceSecurity);

    // Return the port to listen to.
    aChannel = channel;
  
    }