From owner-freebsd-bluetooth@FreeBSD.ORG Sat Oct 3 14:27:02 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 9AABB106566B for ; Sat, 3 Oct 2009 14:27:02 +0000 (UTC) (envelope-from masoom.shaikh@gmail.com) Received: from mail-pz0-f185.google.com (mail-pz0-f185.google.com [209.85.222.185]) by mx1.freebsd.org (Postfix) with ESMTP id 726748FC08 for ; Sat, 3 Oct 2009 14:27:02 +0000 (UTC) Received: by pzk15 with SMTP id 15so1063379pzk.3 for ; Sat, 03 Oct 2009 07:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=wDIkoWB5T7/RXfGUBnO0pWaCLdD85pxl6VdTDHfy8a4=; b=pKVlZ48qkb1KwADeiEpKThfDmcTd/dO1c4nG1Bz+VFxAp0ar/QRHesrD4Mv8nk34VK GgoQCPC9n1vmuKqO2s26H3rNteoLi7Bq1HXKX+651kTSAgTnRznLerUWoeQpKvdd8I/y xvdIXvez78HTzOOZieVob1vr7X5hHmmr8v6ck= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=pj0/WGpny/pCLItoDWe4Vs2PJWlvmJxJCHV74dLDEPhbIhzall6F2jyF3ZN/e/lUby ONhxg90WkXDGBW4YEQPHIEx5EV9sPhfrBjspoxqurgmd+V8WPQKsR4OSEd3to/uLlCal cH9o/YzRti70bKazDL9ncOrE7ea8n9uL2wVcE= MIME-Version: 1.0 Received: by 10.114.6.3 with SMTP id 3mr5476923waf.166.1254578770673; Sat, 03 Oct 2009 07:06:10 -0700 (PDT) Date: Sat, 3 Oct 2009 14:06:10 +0000 Message-ID: From: Masoom Shaikh To: freebsd-bluetooth@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: 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: Sat, 03 Oct 2009 14:27:02 -0000 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 ;-( 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) 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); /* 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); } 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; }