void CBTControllerServerSession::ControllerDiscoverComplete(TInt aStatus, TBTDevAddr aAddr) { if(aStatus == KErrNone) { TL2CAPSockAddr a; a.SetBTAddr(aAddr); iController.ConnectDevice(a); } else { if(!iMessage.IsNull()) iMessage.Complete(aStatus); } }
bool QL2capServer::listen(const QBluetoothAddress &address, quint16 port) { Q_D(QL2capServer); // listen has already been called before if(d->socket) return true; d->socket = new QBluetoothSocket(QBluetoothSocket::L2capSocket,this); if(!d->socket) { return false; } d->ds = d->socket->d_ptr; if(!d->ds) { delete d->socket; d->socket = 0; return false; } TL2CAPSockAddr addr; if(!address.isNull()) { // TBTDevAddr constructor may panic TRAPD(err,addr.SetBTAddr(TBTDevAddr(address.toUInt64()))); if(err != KErrNone) { delete d->socket; d->socket = 0; return false; } } if (port == 0) addr.SetPort(KL2CAPPassiveAutoBind); else addr.SetPort(port); TBTServiceSecurity security; switch (d->securityFlags) { case QBluetooth::Authentication: security.SetAuthentication(EMitmDesired); break; case QBluetooth::Authorization: security.SetAuthorisation(ETrue); break; case QBluetooth::Encryption: // "Secure" is BlueZ specific we just make sure the code remain compatible case QBluetooth::Secure: // authentication required security.SetAuthentication(EMitmDesired); security.SetEncryption(ETrue); break; case QBluetooth::NoSecurity: default: break; } addr.SetSecurity(security); if(d->ds->iSocket->Bind(addr) == KErrNone) { d->socket->setSocketState(QBluetoothSocket::BoundState); } else { delete d->socket; d->socket = 0; return false; } if(d->ds->iSocket->Listen(d->maxPendingConnections) != KErrNone) { delete d->socket; d->socket = 0; return false; } // unknown socket type is used for blank socket QBluetoothSocket *pendingSocket = new QBluetoothSocket(QBluetoothSocket::UnknownSocketType, this); if(!pendingSocket) { delete d->socket; d->socket = 0; return false; } QBluetoothSocketPrivate *pd = pendingSocket->d_ptr; pd->ensureBlankNativeSocket(QBluetoothSocket::L2capSocket); connect(d->socket, SIGNAL(disconnected()), this, SLOT(_q_disconnected())); connect(d->socket, SIGNAL(connected()), this, SLOT(_q_connected())); connect(d->socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(_q_socketError(QBluetoothSocket::SocketError))); if (d->ds->iSocket->Accept(*pd->iSocket) == KErrNone) { d->socket->setSocketState(QBluetoothSocket::ListeningState); d->activeSockets.append(pendingSocket); return true; } else { delete d->socket, pendingSocket; d->socket = 0; return false; } }