From owner-freebsd-bluetooth@FreeBSD.ORG Mon Apr 24 09:34:56 2006 Return-Path: X-Original-To: freebsd-bluetooth@freebsd.org Delivered-To: freebsd-bluetooth@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 85AA916A401 for ; Mon, 24 Apr 2006 09:34:56 +0000 (UTC) (envelope-from cfernandezh@udc.es) Received: from mail.udc.es (mail.udc.es [193.147.41.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id 558F343D49 for ; Mon, 24 Apr 2006 09:34:55 +0000 (GMT) (envelope-from cfernandezh@udc.es) Received: from localhost (localhost [127.0.0.1]) by mail.udc.es ("Servidor de correo del SIAIN") with ESMTP id 8688915EB2C; Mon, 24 Apr 2006 11:33:53 +0200 (CEST) Received: from [193.144.50.98] (unknown [193.144.50.98]) by mail.udc.es ("Servidor de correo del SIAIN") with ESMTP id 4FF8F15EB2A; Mon, 24 Apr 2006 11:33:53 +0200 (CEST) Message-ID: <444C9BBA.4010206@udc.es> Date: Mon, 24 Apr 2006 11:34:50 +0200 From: =?ISO-8859-1?Q?Carlos_Fern=E1ndez_Herranz?= User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Maksim Yevmenkin References: <4423D096.2010205@udc.es> <44248823.3040907@savvis.net> <44291782.8010003@udc.es> <1143546159.980113.1641.nullmailer@galant.ukfsn.org> <44292470.5020803@udc.es> <1143547703.630752.2338.nullmailer@galant.ukfsn.org> <44294D1D.4010901@udc.es> <1143558548.478651.3242.nullmailer@galant.ukfsn.org> <4447A36C.8070201@udc.es> <4447BB29.906@savvis.net> In-Reply-To: <4447BB29.906@savvis.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-bluetooth@freebsd.org Subject: Re: About Inquiry_with_RSSI X-BeenThere: freebsd-bluetooth@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Using Bluetooth in FreeBSD environments List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Apr 2006 09:34:56 -0000 Firsly, the command packets and constants: #define NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22 *typedef* *struct* { u_int8_t num_responses; //* number of responses *// } __attribute__ ((packed)) ng_hci_inquiry_result_with_rssi_ep; *typedef* *struct* { bdaddr_t bdaddr; u_int8_t pagescan_rep_mode; u_int8_t pagescan_period_mode; u_int8_t uclass[NG_HCI_CLASS_SIZE]; u_int16_t clock_offset; char rssi; } __attribute__ ((packed)) ng_hci_inquiry_response_with_rssi; #define NG_HCI_OCF_WRITE_INQUIRY_MODE 0x0045 *typedef* *struct* { u_int8_t mode; } __attribute__ ((packed)) ng_hci_write_inquiry_mode_cp; #define NG_HCI_WRITE_INQUIRY_MODE_CP_SIZE 1 *typedef* *struct* { u_int8_t status; } __attribute__ ((packed)) ng_hci_write_inquiry_mode_rp; #define NG_HCI_WRITE_INQUIRY_MODE_RP_SIZE 1 #define NG_HCI_OCF_READ_INQUIRY_MODE 0x0044 *typedef* *struct* { u_int8_t status; u_int8_t mode; } __attribute__ ((packed)) ng_hci_read_inquiry_mode_rp; #define NG_HCI_READ_INQUIRY_MODE_RP_SIZE 2 To allow the reception of the inquiry results with rssi it's required to modify the event filter adding this line: bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI - 1); You can see here the implementation for the commands: static int hci_write_inquiry_mode(int s, int mode) { ng_hci_write_inquiry_mode_cp cp; ng_hci_write_inquiry_mode_rp rp; int n; int response; //* parse command parameters *// *switch* (mode) { *case* 0: cp.mode = (uint8_t) mode; *break*; *case* 1: cp.mode = (uint8_t) mode; *break*; *default*: *return* (ERROR); } n = *sizeof*(rp); *if* ((response=hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, NG_HCI_OCF_WRITE_INQUIRY_MODE), (char const *) &cp, *sizeof*(cp), (char *) &rp, &n)) == ERROR) { *return* (ERROR); } *if* (rp.status != 0x00) { fprintf(stdout, "Status: %s [%#02x]\n", hci_status2str(rp.status), rp.status); *return* (FAILED); } *return* (OK); } //* end hci_write_inquiry_mode *// static int hci_read_inquiry_mode(int s) { ng_hci_read_inquiry_mode_rp rp; int n; int response; n = *sizeof*(rp); *if* (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO, NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR) *return* (ERROR); *if* ((response=hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, NG_HCI_OCF_READ_INQUIRY_MODE), (char *) &rp, &n)) == ERROR) { *return* (ERROR); } printf("\nInquiry mode: %d\n", rp.mode); *if* (rp.status != 0x00) { fprintf(stdout, "Status: %s [%#02x]\n", hci_status2str(rp.status), rp.status); *return* (FAILED); } *return* (OK); } //* end hci_read_inquiry_mode *// You have also to modify the hci_inquiry function to support inquiry_with_rssi adding support for its events, adding: *case* NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: { ng_hci_inquiry_result_with_rssi_ep *ir = (ng_hci_inquiry_result_with_rssi_ep *)(e + 1); uint8_t *r = (uint8_t *)(ir + 1); *for* (n0 = 0; n0 < ir->num_responses; n0++) hci_inquiry_response_with_rssi(&r); *goto* wait_for_more; } Finally you have to provide an event processor, that is the function: static void hci_inquiry_response_with_rssi(uint8_t **b) { ng_hci_inquiry_response_with_rssi *ir = (ng_hci_inquiry_response_with_rssi *) (*b); printf("\n btaddr: %s \tRSSI: %d \n", hci_bdaddr2str(&ir->bdaddr), ir->rssi); } /* end hci_inquiry_response_with_rssi Hope you opinions. Maksim Yevmenkin wrote: > Carlos Fernández Herranz wrote: > >> The problem was in my Bluetooth adapter, D-LINK DBT-122 which are >> said to support Bluetooth 1.2 but it's not true. >> >> Now, I've tried with some Conceptronic BT 2.0 and it works well. I've >> given support for the commands from Bluetooth 1.2: >> >> Write_Inquiry_Mode >> Read_Inquiry_Mode >> >> and the reception of Inquiry results with RSSI. >> >> I'd like to collaborate providing the solutions I've found. How can I >> do it? Posting my code in this list or sending it to Maksim? > > > posting patches here for everyone to try/review would be a good start. > i will be happy to commit them for you (after appropriate testing of > course). > > thanks, > max > Maksim Yevmenkin wrote: > Carlos Fernández Herranz wrote: > >> The problem was in my Bluetooth adapter, D-LINK DBT-122 which are >> said to support Bluetooth 1.2 but it's not true. >> >> Now, I've tried with some Conceptronic BT 2.0 and it works well. I've >> given support for the commands from Bluetooth 1.2: >> >> Write_Inquiry_Mode >> Read_Inquiry_Mode >> >> and the reception of Inquiry results with RSSI. >> >> I'd like to collaborate providing the solutions I've found. How can I >> do it? Posting my code in this list or sending it to Maksim? > > > posting patches here for everyone to try/review would be a good start. > i will be happy to commit them for you (after appropriate testing of > course). > > thanks, > max >