From owner-freebsd-bluetooth@FreeBSD.ORG Sun Oct 4 04:57:00 2009 Return-Path: Delivered-To: freebsd-bluetooth@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 848B91065670 for ; Sun, 4 Oct 2009 04:57:00 +0000 (UTC) (envelope-from masoom.shaikh@gmail.com) Received: from mail-pz0-f202.google.com (mail-pz0-f202.google.com [209.85.222.202]) by mx1.freebsd.org (Postfix) with ESMTP id 57F1C8FC0A for ; Sun, 4 Oct 2009 04:56:59 +0000 (UTC) Received: by pzk40 with SMTP id 40so2116817pzk.7 for ; Sat, 03 Oct 2009 21:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=AdDP8yBZ1h5x/J4XnoXLFQwMlzvo45q7zAosmM2Wbko=; b=HTbjBE9T+vrv0i0cgNPLlAUFwu/wDahnKQe40VYVUb0G+zHc91vfdGTD6ZD8YTJnW1 ucw8VppxlDog5w9j5n/qLq8NqW2+hMNuIxIxW64AXRhxZXQzMbURfECue+hH0ZtD63nd K8W4hgPn/Q4b0FH66elfpP9yTuTffMFJ27fio= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=fGMfSPO0xymxlYUEMn87diBx+/GkpYQp7HF5JRvF3urruyOfNFwNS1QIRDeJlQK2zW 1qtGeJQcPbEoHE8jQsQzaO5ndgSdgzSIwDNZaWrFPWz76XASIqXsWoC5s07CJqGXnN+m 1n8pO2pqcUuAx1j2fV/SmOaWm9i5SCp8hbf0I= MIME-Version: 1.0 Received: by 10.115.117.39 with SMTP id u39mr6533525wam.116.1254632219680; Sat, 03 Oct 2009 21:56:59 -0700 (PDT) In-Reply-To: <1254600808.002635.1652.nullmailer@galant.ukfsn.org> References: <1254600808.002635.1652.nullmailer@galant.ukfsn.org> Date: Sun, 4 Oct 2009 04:56:59 +0000 Message-ID: From: Masoom Shaikh To: Iain Hibbert Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-bluetooth@freebsd.org Subject: Re: remote_name_request, using libbluetooth 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: Sun, 04 Oct 2009 04:57:00 -0000 On Sat, Oct 3, 2009 at 8:13 PM, Iain Hibbert wrote: > On Sat, 3 Oct 2009, Masoom Shaikh wrote: > > > Hi, > > > > today i spent ages hacking hccontrol to do something similar it does when > > invoked as below > > > > hccontrol remote_name_request > > > > somehow i couldn't succeed ;-( > > you didn't say exactly the failure you have reached, did you use hcidump > to check the actions? > > > what really i want is to search for devices and request their names > > i have a ruby script which does the same by using hccontrol and > manipulating > > it console output > > but am interested in C version. > > > > pasted below is full source. > > > > #include > > #include > > #include > > #include > > #include > > > > /* > > * removes duplicate entries from result and returns the new size > > * free()'s the original array, result is calloc()ed > > * TODO: implement in a better way > > */ > > int do_uniq( const int size, struct bt_devinquiry** result) > > { > > struct bt_devinquiry* newResult = (struct bt_devinquiry*)calloc( > size, > > sizeof(struct bt_devinquiry)); > > > > struct bt_devinquiry* srcCurr = *result; > > struct bt_devinquiry* dstCurr = newResult; > > > > int count = 0; > > int index = 0; > > for ( ; index < size; ++index) > > { > > int j = 0; > > int found = 0; > > while ( j < count) > > { > > if ( bdaddr_same( &( newResult[j++].bdaddr), &( > > srcCurr->bdaddr))) > > { > > found = 1; > > break; > > } > > } > > > > if ( !found) > > { > > *dstCurr = *srcCurr; > > ++dstCurr; > > ++count; > > } > > ++srcCurr; > > } > > free(*result); > > *result = newResult; > > return count; > > } > > > > int main( int argc, char* argv[]) > > { > > /* search devices */ > > struct bt_devinquiry* result = 0; > > int num = bt_devinquiry( 0, 0, 0, &result); > > if ( num <= 0) > > { > > if ( h_errno) > > what is h_errno? I think these checks are uninvolved with the code at > hand.. > > > herror( "no devices found"); > > else > > printf( "no devices found\n"); > > return num; > > } > > /* remove duplicate entries */ > > num = do_uniq( num, &result); > > printf( "%d device(s) found\n", num); > > also, I don't think the do_uniq() step should be necessary -- we did > discuss it at least and in the version i wrote for NetBSD it doesn't > return duplicate results > > > /* try to query device's name */ > > int s = bt_devopen( "ubt0hci"); > > if ( s == -1) > > { > > if ( h_errno) > > herror( "bt_devopen error\n"); > > else > > printf( "bt_devopen error\n"); > > return -1; > > } > > int i = 0; > > for ( ; i < num; ++i) > > { > > struct bt_devreq request; > > memset( &request, 0, sizeof(request)); > > request.opcode = NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, > > NG_HCI_OCF_REMOTE_NAME_REQ); > > request.event = NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL; > > > > ng_hci_remote_name_req_cp cp; > > memset(&cp, 0, sizeof(cp)); > > bdaddr_copy( &cp.bdaddr, &result->bdaddr); > > cp.page_scan_rep_mode = NG_HCI_SCAN_REP_MODE0; > > cp.page_scan_mode = NG_HCI_MANDATORY_PAGE_SCAN_MODE; > > request.cparam = (void*)&cp; > > request.clen = sizeof(cp); > > > > char buffer[512]; > > memset( buffer, 0, 512); > > request.rparam = (void*)buffer; > > request.rlen = 512; > > > > int status = bt_devreq( s, &request, 0); > > if ( status == 0) > > { > > ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t*)buffer; > > ng_hci_remote_name_req_compl_ep *ep = > > (ng_hci_remote_name_req_compl_ep*)(e + 1); > > printf( "status: %d\n", ep->status); > > printf( "name: %s\n", ep->name); > > } > > I think your problem might be here. The event header is not returned, only > the remote_name_req_compl_ep event packet.. (I would have used that > directly in the rparam field rather than a separate buffer -- bt_devreq > will not overflow the given space) > > > else if (status == -1) > > { > > if ( h_errno) > > herror( "bt_devreq error\n"); > > else > > printf( "bt_devreq error\n"); > > } > > else > > { > > printf("bt_devreq unknown return value\n"); > > } > > } > > bt_devclose(s); > > return 0; > > } > > iain > > > thanks for replying yes, i did forgot to say where it failed, devices are inquired properly no issues there but bt_devreq() fails with status == -1 comment taken i will remove the separate buffer, thank you again here is the hcidump output HCIDump - HCI packet analyzer ver 1.5 device: any snap_len: 65535 filter: 0xffffffffffffffff < HCI Command: Inquiry(0x01|0x0001) plen 5 > HCI Event: Command Status(0x0f) plen 4 > HCI Event: Inquiry Result(0x02) plen 15 > HCI Event: Inquiry Result(0x02) plen 15 > HCI Event: Inquiry Complete(0x01) plen 1 < HCI Command: Remote Name Request(0x01|0x0019) plen 10 > HCI Event: Command Status(0x0f) plen 4 > HCI Event: Remote Name Req Complete(0x07) plen 255 i guess the last line indicates that we does receive device name but some how bt_devreq() returns fails i will poke around bt_devreq() for clues