From owner-freebsd-bluetooth@FreeBSD.ORG Tue Mar 28 11:01:41 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 8FEB516A424 for ; Tue, 28 Mar 2006 11:01:41 +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 5457343D67 for ; Tue, 28 Mar 2006 11:01:31 +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 5771615EBB6; Tue, 28 Mar 2006 13:00: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 0743015EBB2; Tue, 28 Mar 2006 13:00:53 +0200 (CEST) Message-ID: <44291782.8010003@udc.es> Date: Tue, 28 Mar 2006 13:01:22 +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> In-Reply-To: <44248823.3040907@savvis.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: Tue, 28 Mar 2006 11:01:41 -0000 Hello. In the bluetooth specification there isn't neither a specific command to carry out an inquiry with rssi nor a command packet. I've tried to implement the "write_inquiry_mode" command and then make an usual inquiry. The problem is that the "write_inquiry_mode" command doesn't seem to work, because I only receive " NG_HCI_EVENT_INQUIRY_RESULT" events instead of "NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI" ones. Could you tell me if I'm doing something wrong?: #define NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22 *typedef* *struct* { u_int8_t num_responses; //* number of responses *// //* ng_hci_inquiry_response[num_responses] -- see below *// } __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 page_scan_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* { uint8_t mode; } __attribute__ ((packed)) ng_hci_write_inquiry_mode_cp; #define NG_HCI_WRITE_INQUIRY_MODE_CP_SIZE 1 *typedef* *struct* { uint8_t status; } __attribute__ ((packed)) ng_hci_write_inquiry_mode_rp; #define NG_HCI_WRITE_INQUIRY_MODE_RP_SIZE 1 ...................... static int socket_open(char const *node) { *struct* sockaddr_hci addr; *struct* ng_btsocket_hci_raw_filter filter; int s, mib[4]; size_t size; s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI); *if* (s < 0) fprintf(stderr, "Could not create socket\n"); memset(&addr, 0, *sizeof*(addr)); addr.hci_len = *sizeof*(addr); addr.hci_family = AF_BLUETOOTH; strncpy(addr.hci_node, node, *sizeof*(addr.hci_node)); *if* (bind(s, (*struct* sockaddr *) &addr, *sizeof*(addr)) < 0) fprintf(stderr, "Could not bind socket, node=%s\n", node); *if* (connect(s, (*struct* sockaddr *) &addr, *sizeof*(addr)) < 0) fprintf(stderr, "Could not connect socket, node=%s\n", node); memset(&filter, 0, *sizeof*(filter)); bit_set(filter.event_mask, NG_HCI_EVENT_COMMAND_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_COMMAND_STATUS - 1); bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_RESULT - 1); ///Inquiry_rssi modification/ bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI - 1); bit_set(filter.event_mask, NG_HCI_EVENT_CON_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_DISCON_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_RETURN_LINK_KEYS - 1); bit_set(filter.event_mask, NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL - 1); bit_set(filter.event_mask, NG_HCI_EVENT_CON_PKT_TYPE_CHANGED - 1); bit_set(filter.event_mask, NG_HCI_EVENT_ROLE_CHANGE - 1); *if* (setsockopt(s, SOL_HCI_RAW, SO_HCI_RAW_FILTER, (void * const) &filter, *sizeof*(filter)) < 0) fprintf(stderr, "Could not setsockopt()\n"); size = (*sizeof*(mib)/*sizeof*(mib[0])); *if* (sysctlnametomib("net.bluetooth.hci.command_timeout",mib,&size) < 0) fprintf(stderr, "Could not sysctlnametomib()\n"); ; *if* (sysctl(mib, *sizeof*(mib)/*sizeof*(mib[0]), (void *) &timeout, &size, NULL, 0) < 0) fprintf(stderr, "Could not sysctl()\n"); timeout ++; *return* (s); } //* socket_open *// ................. //* Send Write_Inquiry_Mode command to the unit (Bluetooth v1.2 upgrade)*// 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; //* 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* (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); } //* hci_write_inquiry_mode *// ............................ static int hci_inquiry(int s) { int n0, timo; uint8_t b[512]; ng_hci_inquiry_cp cp; ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; //* set defaults *// cp.lap[2] = 0x9e; cp.lap[1] = 0x8b; cp.lap[0] = 0x33; cp.inquiry_length = INQ_LENGHT; cp.num_responses = NUM_RESPONSES; //* send request and expect status back *// n0 = *sizeof*(b); *if* (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, NG_HCI_OCF_INQUIRY), (char const *) &cp, *sizeof*(cp), b, &n0) == ERROR) *return* (ERROR); *if* (*b != 0x00) *return* (FAILED); timo = timeout; timeout = cp.inquiry_length * 1.28 + 1; wait_for_more: //* wait for inquiry events *// n0 = *sizeof*(b); *if* (hci_recv(s, b, &n0) == ERROR) { timeout = timo; *return* (ERROR); } *if* (n0 < *sizeof*(*e)) { timeout = timo; errno = EIO; *return* (ERROR); } *switch* (e->event) { *case* NG_HCI_EVENT_INQUIRY_RESULT: { ng_hci_inquiry_result_ep *ir = (ng_hci_inquiry_result_ep *)(e + 1); uint8_t *r = (uint8_t *)(ir + 1); *for* (n0 = 0; n0 < ir->num_responses; n0++) hci_inquiry_response(&r); *goto* wait_for_more; } *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; } *case* NG_HCI_EVENT_INQUIRY_COMPL: *break*; *default*: *goto* wait_for_more; } timeout = timo; *return* (OK); } //* hci_inquiry *// ................. static void hci_inquiry_response_with_rssi(uint8_t **b) { ng_hci_inquiry_response_with_rssi *ir = (ng_hci_inquiry_response_with_rssi *)(*b); strcpy(respuesta,hci_bdaddr2str(&ir->bdaddr)); printf("BTADDR: %s \t RSSI: %d", hci_bdaddr2str(&ir->bdaddr), ir->rssi); write_cmd(respuesta, strlen(respuesta)); } //* hci_inquiry_response_with_rssi *// .......................... Best regards. Carlos. Maksim Yevmenkin wrote: > [...] > >> >> I would like to know if it could be possible upgrade the Bluetooth >> stack so the command Inquiry_with_RSSI could be supported and the way >> I could > > > strictly speaking it should be already supported. all you need to do > is to create proper hci command packet and send it via hci raw socket. > you also might need to adjust filter settings on the hci raw socket to > allow command to be sent. > > whats missing is the definition of new bluetooth v1.2 hci commands and > events, but nothing prevents you from defining those locally and > creating valid hci command packet. > > of course, the device itself must support bluetooth v1.2 hci > commands/events. > >> do it. Can I follow the BlueZ stack to adapt the FreeBSD one? > > > i'm not sure what are you asking here. > > thanks, > max >