Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1518574lqp; Mon, 15 Apr 2024 08:40:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX+L4CPp0QCwO5R+jdAy/N97PlcB4/8gZ7CiBdHqwJTs3g4PTF0ZraZc+G3B4c6nTyAnm9k//59Bwy0xk28tbZcoyyijEHPLv2O3HvGnQ== X-Google-Smtp-Source: AGHT+IGhDBfYyf4HtTsL7+mWKHkhppNS7cBbjVKZhMHaiHYWHjNpHeZXKvUkRPxZzUHiIiv+LoP7 X-Received: by 2002:ae9:f112:0:b0:78d:6be3:4c01 with SMTP id k18-20020ae9f112000000b0078d6be34c01mr10854030qkg.4.1713195626764; Mon, 15 Apr 2024 08:40:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713195626; cv=pass; d=google.com; s=arc-20160816; b=wEZFu8TZIe0PH0WCpcVOOanU+UFFOEOmyKSvP7pQyg+TZkoutwoVbimIwph7hBu7Es PFvtdQ+H6InLY0ADRSDYdrIJxF+7uDQbcyGYvKHv2p31K4GOse4B2zb9PXP5rt1mU5Ln urqWazSHJvRZNcSbh1+tB+L8WPBMbpV5wsu4nRxehZCjrKNYIVBGJmLX8o2A/u+oz54s 9LOeOZhbL8k+ncq5bRqkxV0OC6SuyvF8DFLARd8wvHs3vfKsSEbh0Ags5+uG4K/Y/E4V uTxMw15Sk7q4RKmPALgHm9vTGegsxeLmllXPpI396kai4unDsilkMiSyW9A2o7DYsbzu Dgvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=rabRSDRGz2ka0OSKSPVR7Njpy9wM18fSoKOnRfgaEMI=; fh=+9Wb+Sd3maA0yLBHXlEOjaTp0c8+RJdoYmbmZI4oJ9Q=; b=0m/HONQlzQGgQqSQzASwjuRPQK2CXeqlDTpJIA1yLPTqWnMAGaDJ137skiqCPQg5LK zovBeExc6UmvtwFv+HDecTDVTsEY5hmPU0yl8sMZj4BnaorRp73oayCg887wLsDvRwP5 eeuJ/c6vFdoMZYkAhsDHRWiC52TAX+6Y9lzK0IX80MbJ8LafEGlNeBe9VUu+2bpaQVDE 2xj+ndELqAM4pjm9PWa+E/AaIUXz7MiQ9e2us9oFzQOhVFGUOpHT+BAWUOfSioFcjHnd ESHpJ83tWqmm4luaiwZ3Oizh65SS+6i9RE+n1zaTLlY25UvZFDxnM0tZyoOolJwF0aRN F+AA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iiYOGP9c; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-3591-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vy19-20020a05620a491300b0078d6b96115csi10025640qkn.553.2024.04.15.08.40.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 08:40:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-3591-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iiYOGP9c; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-3591-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 22DE51C2197C for ; Mon, 15 Apr 2024 15:40:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 419F279B8E; Mon, 15 Apr 2024 15:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iiYOGP9c" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13D4A78C77 for ; Mon, 15 Apr 2024 15:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713195617; cv=none; b=rPIEOAklginDxtpkN2CcpKUUbIxcZzEaq6KuAdGI8J2Jg2qj1Kn5N5Fne4qek5KT4DreSzA0dfAAGbzfm3nNXdIolVqiJEpQ+bn8h+aCBKsDU0djByiDwTCWi+fs2zNgFhKMMriGtyNr1XgPgf3vrvDnTFfekkwHpsxKXLJ71FE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713195617; c=relaxed/simple; bh=jZyvmZnRydCJOoVt3gmE+y6KHhkY/gX1aPFrxiTs86M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=c9vnhs1XLJe2c3779QUI64uQ2GCdhLa4zMt3vFowWjoV8Ze7YMNURT2gl2Jo9H3NuGnpKFb5PuH6N0agwfCQBrQu3vhpBQ3vFMNiamsoYng7kyTW2JWG2FIV/1dB/8woIgBh19VJKrqgx7A3OOZ0onp9sPJNKGq7pwogHsXVc4Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iiYOGP9c; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2da68af6c6fso17022891fa.3 for ; Mon, 15 Apr 2024 08:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713195614; x=1713800414; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rabRSDRGz2ka0OSKSPVR7Njpy9wM18fSoKOnRfgaEMI=; b=iiYOGP9cKQ21QnRHsPJMXzuFvHQF4Sa3iNEmmvfMzyoptBlUxougt503Dnkq3ks+qN 0PkyhOmlk2zysjVwUO8+9zs2CWBcOeq8HCaOJ7ubAGtL4JadhAqnLYfO0IWqFqco0vqq IoZcJ7eTnbTabdex/JTFsULGLNMApwbrpjfgJcd0lK8j40GlQR5fA/3wouusnLzbdWRq krAvRJT4/3Pu+dYV5XtdkO/grq3r5NOq7/DbLc25scu4DBwMKymhvs2HxoAVcMgWCATq 1Mp49cOqjS2pg4TdmG0YQ2g3OSWFogV8DDkJVDmgR1AwFW+cDP/ULLVFYCl+gzFaK9VC NQ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713195614; x=1713800414; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rabRSDRGz2ka0OSKSPVR7Njpy9wM18fSoKOnRfgaEMI=; b=VPrEOO6QNxm5NIGlUa91qEByge6QsUNDMHkxT/DWx5w7pPIYyLtnu54pA97Hzim41J A36ynrpbHmpLClOo0XRRWFsCNfdxGuK4Z6chDVlsX6VfYf6/x7jTr53H3dB2HQ0zVwG0 zpb+Y3Og8XKX4RV8v8+S2IRbJFsNh7Z7sSDj5zHBLoEzWnRIo6wv2u3/nr40LBLWnXCw T2cUUeXALzEPVEhz1Ts4v/zCP/sjlYAW/pUaksILEgU6atCV0alf91BAmt9fsCYsdosk LFTlhs/tZHEZOOR3n6ZsuNli1wAy7m3q7bQIANJLS+LgWAaQlQdKD92Y7xYIa0nf0Kd0 7Xkw== X-Gm-Message-State: AOJu0Yy2OP8glhhPw8cAvPW41umB6gkejAv371ceW+HA6x2obIgCi8fF wxOQ/u9EQUf4D3iiJLYP6mQEcSw/dIBRDQVC5yx5Pg6UDKPwagBKpXAqdCAXH0wker4p8G66Zss Gu9sn6cY67oHof9hUm5VrfDeRoG0= X-Received: by 2002:a05:651c:205:b0:2da:78fc:6418 with SMTP id y5-20020a05651c020500b002da78fc6418mr1938217ljn.19.1713195613831; Mon, 15 Apr 2024 08:40:13 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Luiz Augusto von Dentz Date: Mon, 15 Apr 2024 11:40:00 -0400 Message-ID: Subject: Re: Bluetooth from Windows to Linux using BlueZ To: Peter Mortier Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Peter, On Mon, Apr 15, 2024 at 11:19=E2=80=AFAM Peter Mortier wrote: > > Dear all, > I want to set up a simple bluetooth connection between 2 PC=E2=80=99s, cl= ient running Windows and server running Linux. > There is no need for a lot of overhead such as pairing. > I am running the server software on Linux Ubuntu with the following code: > > int serverSocket, clientSocket; > struct sockaddr_rc serverAddr =3D {0}, clientAddr=3D{0}; > > socklen_t clientAddrSize =3D sizeof(sockaddr_rc); > > // Create Bluetooth socket > serverSocket=3Dsocket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); > if (serverSocket<0) > { > perror("socket creation failed: "); > return false; > } > bdaddr_t bdaddr_any=3D{{0,0,0,0,0,0}}; > > // Bind the socket to any local Bluetooth adapter > serverAddr.rc_family =3D AF_BLUETOOTH; > serverAddr.rc_bdaddr =3D bdaddr_any; // bind to any local Bluetooth a= dapter > serverAddr.rc_channel =3D 25; > > if (bind(serverSocket,(struct sockaddr*)&serverAddr,sizeof(serverAddr= ))<0) > { > perror("Bind failed"); > close(serverSocket); > exit(EXIT_FAILURE); > } > > // listen for incoming connections > if (listen(serverSocket,1) <0) > { > perror("Listen failed"); > close(serverSocket); > exit(EXIT_FAILURE); > }; > > while (true) > { > wxPrintf("Waiting for incoming Bluetooth connections...\n"); > > // Accept incoming connection > clientSocket =3D accept(serverSocket, (struct sockaddr*) &clientAdd= r,&clientAddrSize); > if (clientSocket<0) > { > perror("accept failed"); > continue; > } > > I am running the client software on Windows 10 with the following code: > > // Create a Bluetooth socket > m_serverSocket =3D socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); > SOCKADDR_BTH serverAddr =3D { 0 }; > if (m_serverSocket =3D=3D INVALID_SOCKET) { > return false; > } > > // Set the address of the remote Bluetooth device to connect to > serverAddr.addressFamily =3D AF_BTH; > serverAddr.btAddr =3D *reinterpret_cast(&m_Server.Address.= ullLong); // this is the addres found by function BluetoothFindFirstDevice(= ) > serverAddr.serviceClassId =3D RFCOMM_PROTOCOL_UUID; // I also tried = GUID_NULL > serverAddr.port =3D 25; // I also tried 0 > > // Connect to the remote Bluetooth device > if (connect(m_serverSocket, reinterpret_cast(&serverAddr),= sizeof(serverAddr)) =3D=3D SOCKET_ERROR) { > std::cout << "error: " << WSAGeLastError() << std::endl; > return false; > } > > The Linux server is listening on port 25 while the Windows client tries t= o connect to the same port. The client first searches for the server with B= luetoothFindFirstDevice and BluetoothFindNextDevice, finds the server bluet= oooth address and uses that address to connect. > The connection on the client then fails with error code 10051 (or sometim= es 10060) > > On Linux there is no firewall installed, using bluetoothclt I see it is r= egistered and pairable. The bluetooth dongle is plugged into a USB port and= is seen as USB2.0-BT. I have tried different ports without success. > > I've done some testing with my code. It seems bluetooth is working well w= ith code above in the following circumstances : > - windows =E2=86=92 windows > - linux =E2=86=92 linux > - linux =E2=86=92 windows > The only thing that doesn't work is: windows =E2=86=92 linux > > I am told the problem lies in the BlueZ library, but I find this hard to = believe. My guesses are I am doing something wrong. We probably need to HCI trace to tell what is going on, no idea what are the errors that windows stack is throwing, besides if you manage to connect Linux to Linux I assume the server is listening, but perhaps there is a different problem, anyway I would recommend using rctest instead before attempting to write your own version of it: https://github.com/bluez/bluez/blob/master/tools/rctest.rst > Any help is much appreciated! > > Best regards, > Peter --=20 Luiz Augusto von Dentz