Exemplo n.º 1
0
nsresult
BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
                         const BluetoothUuid& aServiceUuid,
                         BluetoothSocketType aType,
                         int aChannel,
                         bool aAuth, bool aEncrypt)
{
  MOZ_ASSERT(!aDeviceAddress.IsCleared());

  nsAutoPtr<BluetoothUnixSocketConnector> connector(
    new BluetoothUnixSocketConnector(aDeviceAddress, aType, aChannel,
                                     aAuth, aEncrypt));

  nsresult rv = Connect(connector);
  if (NS_FAILED(rv)) {
    BluetoothAddress address;
    GetAddress(address);

    nsAutoString addressStr;
    AddressToString(address, addressStr);

    BT_LOGD("%s failed. Current connected device address: %s",
           __FUNCTION__, NS_ConvertUTF16toUTF8(addressStr).get());
    return rv;
  }
  connector.forget();

  return NS_OK;
}
void
BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
                              BluetoothProfileController* aController)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!aDeviceAddress.IsCleared());
  MOZ_ASSERT(aController);

  BluetoothService* bs = BluetoothService::Get();
  if (!bs || sInShutdown) {
    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
    return;
  }

  if (mA2dpConnected) {
    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
    return;
  }

  mDeviceAddress = aDeviceAddress;
  mController = aController;

  if (!sBtA2dpInterface) {
    BT_LOGR("sBluetoothA2dpInterface is null");
    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
    return;
  }

  sBtA2dpInterface->Connect(mDeviceAddress, new ConnectResultHandler());
}
Exemplo n.º 3
0
void
BluetoothHidManager::Connect(const BluetoothAddress& aDeviceAddress,
                             BluetoothProfileController* aController)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!aDeviceAddress.IsCleared());
  MOZ_ASSERT(aController && !mController);

  BluetoothService* bs = BluetoothService::Get();
  if (!bs || sInShutdown) {
    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
    return;
  }

  if (mConnected) {
    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
    return;
  }

  mDeviceAddress = aDeviceAddress;
  mController = aController;

  nsAutoString deviceAddressStr;
  AddressToString(mDeviceAddress, deviceAddressStr);

  if (NS_FAILED(bs->SendInputMessage(deviceAddressStr,
                                     NS_LITERAL_STRING("Connect")))) {
    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
    return;
  }
}
Exemplo n.º 4
0
void
BluetoothSocket::BluetoothSocketIO::GetSocketAddr(
  BluetoothAddress& aAddress) const
{
  if (!mConnector) {
    NS_WARNING("No connector to get socket address from!");
    aAddress.Clear();
    return;
  }

  nsresult rv = mConnector->ConvertAddress(
    *reinterpret_cast<const struct sockaddr*>(&mAddress), sizeof(mAddress),
    aAddress);
  if (NS_FAILED(rv)) {
    aAddress.Clear();
    return;
  }
}
Exemplo n.º 5
0
void
BluetoothSocket::GetAddress(BluetoothAddress& aAddress)
{
  if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
    NS_WARNING("No socket currently open!");
    aAddress.Clear();
    return;
  }

  mIO->GetSocketAddr(aAddress);
}
Exemplo n.º 6
0
void
BluetoothAvrcpManager::Connect(const BluetoothAddress& aDeviceAddress,
                               BluetoothProfileController* aController)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!aDeviceAddress.IsCleared());
  MOZ_ASSERT(aController);

  // AVRCP doesn't require connecting. We just set the remote address here.
  mDeviceAddress = aDeviceAddress;
  mController = aController;
  SetConnected(true);

  NS_DispatchToMainThread(new ConnectRunnable(this));
}
Exemplo n.º 7
0
ProtocolEvent ProtocolRFCOMMClient::connectToPeer()
{
	struct sockaddr_bt peerAddr;
	BluetoothAddress *addr;
	
	if (!peerIface)
		return PROT_EVENT_ERROR;

	addr = peerIface->getAddress<BluetoothAddress>();

	if(!addr)
		return PROT_EVENT_ERROR;

	memset(&peerAddr, 0, sizeof(peerAddr));
	peerAddr.bt_family = AF_BLUETOOTH;

	BDADDR_swap(&peerAddr.bt_bdaddr, mac);
	peerAddr.bt_channel = channel & 0xff;

	HAGGLE_DBG("%s Trying to connect over RFCOMM to [%s] channel=%u\n", 
		   getName(), addr->getStr(), channel);

	ProtocolEvent ret = openConnection((struct sockaddr *) &peerAddr, 
					   sizeof(peerAddr));

	if (ret != PROT_EVENT_SUCCESS) {
		HAGGLE_DBG("%s Connection failed to [%s] channel=%u\n", 
			   getName(), addr->getStr(), channel);
		return ret;
	}

	HAGGLE_DBG("%s Connected to [%s] channel=%u\n", 
		   getName(), addr->getStr(), channel);

	return ret;
}
Exemplo n.º 8
0
void
BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
{
  aDeviceAddress.Clear();
}