From bf6f08843667d90413addaf12e2a485cfc82d1fb Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Tue, 15 Apr 2008 22:49:05 +0000 Subject: [PATCH] The stack is already discovering devices, this is the small tool I used to test. The stack calls for the moment hooks at starting and finishing and discovering each BT deviceNeeds still some polishing as some devices reply multiple times, and they should be filtered. And its nice to know the name after discovering not only the address. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24978 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/bt_discovery.cpp | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/bin/bt_discovery.cpp diff --git a/src/bin/bt_discovery.cpp b/src/bin/bt_discovery.cpp new file mode 100644 index 0000000000..ad0df13ea6 --- /dev/null +++ b/src/bin/bt_discovery.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include + +#include +#include + +#include +#include + +class simpleDiscoveryListener : public DiscoveryListener { + +public: + +simpleDiscoveryListener(LocalDevice *ld) : DiscoveryListener() +{ + SetLocalDeviceOwner(ld); +} + + +void +DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) +{ + printf("Device Discovered!!\n"); +} + + +void +InquiryCompleted(int discType) +{ + printf("%s: Inquiry process has finished ...\n",__FUNCTION__); +} + + +void +InquiryStarted(status_t status) +{ + printf("%s: Inquiry process has started ...\n",__FUNCTION__); +} + + +}; + + +void +DumpInfo(LocalDevice* device) +{ + DiscoveryAgent* da = device->GetDiscoveryAgent(); + + if (da == NULL) { + printf("DiscoveryAgent could not be located\n"); + return; + } + +/* printf("Discovering for [LocalDevice] %s\t%s\n", + (device->GetFriendlyName()).String(), + bdaddrUtils::ToString(device->GetBluetoothAddress())); +*/ + simpleDiscoveryListener* sdl = new simpleDiscoveryListener(device); + + da->StartInquiry(BT_GIAC, sdl); + + getchar(); + +} + +static status_t +LocalDeviceError(status_t status) +{ + fprintf(stderr,"No Device/s found"); + + return status; +} + + +int +main(int argc, char *argv[]) +{ + if(argc == 2) { + // device specified + LocalDevice* ld = LocalDevice::GetLocalDevice(atoi(argv[0])); + if (ld == NULL) + return LocalDeviceError(ENODEV); + + DumpInfo(ld); + + } else if (argc == 1) { + // show all devices + LocalDevice* ld = NULL; + + printf("Performing discovery for %ld Bluetooth Local Devices ...\n", LocalDevice::GetLocalDeviceCount()); + + for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) { + + ld = LocalDevice::GetLocalDevice(); + if (ld == NULL) { + LocalDeviceError(ENODEV); + continue; + } + DumpInfo(ld); + + } + + return B_OK; + + } else { + fprintf(stderr,"Usage: bt_dev_info [device]\n"); + return B_ERROR; + } +}