From nobody Thu Feb 08 20:57:49 2024 X-Original-To: freebsd-bluetooth@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TW8Sx33hlz5BNVf for ; Thu, 8 Feb 2024 20:57:53 +0000 (UTC) (envelope-from gergely.czuczy@harmless.hu) Received: from marvin.harmless.hu (marvin.harmless.hu [195.56.55.204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4TW8Sw0QX3z4xYj for ; Thu, 8 Feb 2024 20:57:51 +0000 (UTC) (envelope-from gergely.czuczy@harmless.hu) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=harmless.hu header.s=marvin header.b=mi7nOu8O; dmarc=pass (policy=quarantine) header.from=harmless.hu; spf=pass (mx1.freebsd.org: domain of gergely.czuczy@harmless.hu designates 195.56.55.204 as permitted sender) smtp.mailfrom=gergely.czuczy@harmless.hu DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=harmless.hu ; s=marvin; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OCK+7K2QkrrFTRoTkmeTQbFe0In6+1dep+64+3j4vzA=; b=mi7nOu8Oz5yCFzzD7BggHp28zc dZewBgkyTOHY5pnc/No5J/MScxCJeMOfvaSluH4UzoN81NDjZbXQM0HV/IPk1WGtIUdN8OOh1Yrpw GHxI51yV9A7RnfxR5G3NhAgWzD5mQ0vfgIv4c4XZTny5KQ5KSlHDZWnZtr3aDNaqkNJg=; Received: from 87-97-12-22.pool.digikabel.hu ([87.97.12.22] helo=[10.219.18.1]) by marvin.harmless.hu with esmtpsa (TLS1.3) tls TLS_AES_128_GCM_SHA256 (envelope-from ) id 1rYBSu-000AuR-0V for freebsd-bluetooth@freebsd.org; Thu, 08 Feb 2024 20:57:48 +0000 Message-ID: <2ceca8ac-2ca0-4c97-b241-dd2ef2843c32@harmless.hu> Date: Thu, 8 Feb 2024 21:57:49 +0100 List-Id: Using Bluetooth in FreeBSD environments List-Archive: https://lists.freebsd.org/archives/freebsd-bluetooth List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bluetooth@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Help with Bluetooth LE stack Content-Language: en-US To: freebsd-bluetooth@freebsd.org References: <6bf90a8f-5ccb-4ea9-b509-97acfe0a74ac@harmless.hu> From: Gergely Czuczy In-Reply-To: <6bf90a8f-5ccb-4ea9-b509-97acfe0a74ac@harmless.hu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-HD-Spam-Score: -0.1 X-HD-Spam-Report: Action: no action Symbol: ARC_NA(0.00) Symbol: RCVD_VIA_SMTP_AUTH(0.00) Symbol: XM_UA_NO_VERSION(0.01) Symbol: FROM_HAS_DN(0.00) Symbol: TO_MATCH_ENVRCPT_ALL(0.00) Symbol: MIME_GOOD(-0.10) Symbol: TO_DN_NONE(0.00) Symbol: RCPT_COUNT_ONE(0.00) Symbol: NEURAL_HAM(-0.00) Symbol: RCVD_COUNT_ONE(0.00) Symbol: FROM_EQ_ENVFROM(0.00) Symbol: MIME_TRACE(0.00) Symbol: ASN(0.00) Symbol: RCVD_TLS_ALL(0.00) Symbol: MID_RHS_MATCH_FROM(0.00) Message-ID: 2ceca8ac-2ca0-4c97-b241-dd2ef2843c32@harmless.hu X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.89 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_POLICY_ALLOW(-0.50)[harmless.hu,quarantine]; R_SPF_ALLOW(-0.20)[+mx]; R_DKIM_ALLOW(-0.20)[harmless.hu:s=marvin]; MIME_GOOD(-0.10)[text/plain]; ONCE_RECEIVED(0.10)[]; XM_UA_NO_VERSION(0.01)[]; RCPT_COUNT_ONE(0.00)[1]; ASN(0.00)[asn:5588, ipnet:195.56.0.0/16, country:CZ]; RCVD_TLS_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-bluetooth@freebsd.org]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DKIM_TRACE(0.00)[harmless.hu:+] X-Rspamd-Queue-Id: 4TW8Sw0QX3z4xYj In the meantime I've noticed some messages from the kernel: ng_hci_process_command_complete: ubt0hci - HCI command failed, OGF=0x8, OCF=0xb, status=0x12 I think it might be originating from here: https://github.com/freebsd/freebsd-src/blob/d5677b0b8b8a1505edeaafab5606c4f890c1a42d/sys/netgraph/bluetooth/hci/ng_hci_cmds.c#L863C11-L863C17 But EINVAL has the value of dec22, and 0x12 points to EXDEV, which does not seem related here. Also, this is not an errno, but a status code. The same calls are succeeding with the example code at [1], and the difference is, i'm using libbluetooth instead of manually implementing the communication over the device. What might be causing this? On 2024. 02. 08. 20:09, Gergely Czuczy wrote: > Hello, > > I would like to ask for a bit of help. I'm absolutely not familiar > with bluetooth, and one of my components for my project is a bluetooth > LE device[1], and I'm having some troubles with the BT stack. > > Initially I've based my code on the FreeBSD-BLE[2] examples, and my > stack worked. However, there was a power outage and the device > restarted, and this example stuff is still getting data, but my stack > is not anymore. What so far I have (and used to work but doesn't > anymore) is at [3]. > > I've tried reading through the manuals and docs, but it's absolutely > blurry. Like NG_HCI(4) tells me to do 3 things during HCI init > (Read_BD_ADDR, Read_Local_Supported_Features, Read_Buffer_Size) but > doesn't exactly tells me how. I'm using the bluetooth(4), and it's > told the bt_* calls return -1 on error, but how do I get the actual > error is nowhere explained. Especially for things like > NGM_HCI_NODE_GET_BDADDR, I don't know what the output data structure > to bt_devreq looks like, and how to get any error codes out, the call > like I do is not touching the output buffer. > > Also, what I couldn't get done using the example code in [2] is to > make this work from userspace, even the example only returns data as > root. > > I'm on FreeBSD 14.0-STABLE arm64 if it matters. > > Could I please get some help on how to work with the BTLE stack properly? > > Best regards, > Gergely > > [1] https://kvurd.com/blog/tilt-hydrometer-ibeacon-data-format/ > [2] https://github.com/takawata/FreeBSD-BLE/tree/master/le_enable > [3] > https://github.com/gczuczy/aegir/blob/fermd/controllers/fermd/Bluetooth.cc > >