1 /* 2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 9 #include <bluetooth/LocalDevice.h> 10 #include <bluetooth/bdaddrUtils.h> 11 12 13 static void 14 DumpInfo(LocalDevice* device) 15 { 16 printf("[LocalDevice] %s\t%s\n", (device->GetFriendlyName()).String(), 17 bdaddrUtils::ToString(device->GetBluetoothAddress())); 18 19 BString classString; 20 DeviceClass cod = device->GetDeviceClass(); 21 22 cod.GetServiceClass(classString); 23 classString << " |"; 24 cod.GetMajorDeviceClass(classString); 25 classString << " |"; 26 cod.GetMinorDeviceClass(classString); 27 printf("\t\t%s: \n", classString.String()); 28 29 } 30 31 32 static status_t 33 LocalDeviceError(status_t status) 34 { 35 fprintf(stderr,"No Device/s found"); 36 37 return status; 38 } 39 40 41 int 42 main(int argc, char *argv[]) 43 { 44 if (argc == 2) { 45 // device specified 46 LocalDevice* ld = LocalDevice::GetLocalDevice(atoi(argv[0])); 47 if (ld == NULL) 48 return LocalDeviceError(ENODEV); 49 50 DumpInfo(ld); 51 52 } else if (argc == 1) { 53 // show all devices 54 LocalDevice* ld = NULL; 55 56 printf("Listing %ld Bluetooth Local Devices ...\n", 57 LocalDevice::GetLocalDeviceCount()); 58 for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) { 59 60 ld = LocalDevice::GetLocalDevice(); 61 if (ld == NULL) 62 return LocalDeviceError(ENODEV); 63 DumpInfo(ld); 64 } 65 66 return B_OK; 67 68 } else { 69 fprintf(stderr,"Usage: bt_dev_info [device]\n"); 70 return B_ERROR; 71 } 72 } 73