Contribute
Register

Handoff (Bluetooth Low Energy) Tester

Status
Not open for further replies.
Joined
Dec 3, 2010
Messages
460
Motherboard
Gigabyte GA-H55M-S2V
CPU
Intel i3-530
Graphics
HIS HD 6570
Mac
  1. iMac
Mobile Phone
  1. Android
This is a quick command line tool which I think tests correctly for Handoff (Bluetooth Low Energy) support. So far I've only seen posts referring to the LMP version, which is unhelpful; the Link Manager Protocol version corresponds directly to the Bluetooth marketing version, and even then each version has plenty of optional features. This tool checks "CoreBluetooth"'s functionality, but instead of trying to correlate the CB*Manager states with BLE support, it queries some private methods of IOBluetoothHostController, including -lowEnergySupport. The manager routines are still run, since they test the functionality, but the device information should be enough to make a decision.
If you get an abnormal result, please post it below. As usual the source is open (link against IOBluetooth if you compile), binary is compiled for Mountain Lion and higher.
Code:
//
//  main.m
//  BluetoothLowEnergyCheck
//
//  Created by PHPdev32 on 7/24/14.
//  Licensed under GPLv3, full text at http://www.gnu.org/licenses/gpl-3.0.txt
//

#import <Foundation/Foundation.h>
#import <IOBluetooth/IOBluetooth.h>
#define info(x, ...) printf(x"\n", ##__VA_ARGS__)
#define err(x, ...) { info(x, ##__VA_ARGS__); return EXIT_FAILURE; }

@interface IOBluetoothHostController ()

@property (readonly) bool lowEnergySupported, isReady, powerChangeSupported;
@property (readonly) UInt16 USBProductID, USBVendorID;

-(IOReturn)BluetoothHCIReadLocalVersionInformation:(BluetoothLMPVersion *)hciVersion outHCIRevision:(BluetoothLMPSubversion *)hciRevision outLMPVersion:(BluetoothLMPVersion *)lmpVersion outManufacturerName:(BluetoothManufacturerName *)manufacturerName outLMPSubversion:(BluetoothLMPSubversion *)lmpSubVersion;
-(IOReturn)BluetoothHCIReadLocalSupportedFeatures:(struct BluetoothHCISupportedFeatures *)arg1;
-(IOReturn)enableRemoteWake:(bool)flag;

@end

@interface Delegate : NSObject <CBCentralManagerDelegate>
@end

#ifdef MAC_OS_X_VERSION_10_9
@interface Delegate () <CBPeripheralManagerDelegate>
@end
#endif

@implementation Delegate

-(void)printState:(NSUInteger)state {
    const char *s;
    switch (state) {
        case CBCentralManagerStateUnknown: s = "Unknown"; break;
        case CBCentralManagerStateUnsupported: s = "Unsupported"; break;
        case CBCentralManagerStateUnauthorized: s = "Unauthorized"; break;
        case CBCentralManagerStatePoweredOff: s = "Powered Off"; break;
        case CBCentralManagerStatePoweredOn: s = "Powered On"; break;
        case CBCentralManagerStateResetting: s = "Resetting"; break;
        default: s = "Bad state"; break;
    }
    info("State is: %s", s);
}

-(void)centralManagerDidUpdateState:(CBCentralManager *)central {
    [self printState:central.state];
    [central stopScan];
    dispatch_async(dispatch_get_main_queue(), ^{ exit(EXIT_SUCCESS); });
}

#ifdef MAC_OS_X_VERSION_10_9
-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
    [self printState:peripheral.state];
    [peripheral stopAdvertising];
    dispatch_async(dispatch_get_main_queue(), ^{ exit(EXIT_SUCCESS); });
}
#endif

@end

int main(int argc, const char * argv[])
{
    
    @autoreleasepool {
        
        // insert code here...
        close(STDERR_FILENO);
        info("Built %s", __DATE__);
        IOBluetoothHostController *controller = [IOBluetoothHostController defaultController];
        BluetoothHCIVersionInfo i;
        if (controller && [controller BluetoothHCIReadLocalVersionInformation:&i.hciVersion outHCIRevision:&i.hciRevision outLMPVersion:&i.lmpVersion outManufacturerName:&i.manufacturerName outLMPSubversion:&i.lmpSubVersion] == kIOReturnSuccess) {
            info("Found (0x%hX%hX) named '%s', turned %s, %sready", controller.USBVendorID, controller.USBProductID, controller.nameAsString.UTF8String, controller.powerState ? "on" : "off", controller.isReady ? "" : "not ");
            info("HCI %#x:%#hx, LMP %#x:%#x, MAC %s", i.hciVersion, i.hciRevision, i.lmpVersion, i.lmpSubVersion, controller.addressAsString.UTF8String);
            info("Low Energy %ssupported, Power Change %ssupported", controller.lowEnergySupported ? "" : "un", controller.powerChangeSupported ? "" : "un");
        }
        else
            err("No controller found")
        id manager, delegate = [Delegate new];
#ifdef MAC_OS_X_VERSION_10_9
        if (&CBPeripheralManagerOptionShowPowerAlertKey) {
            info("Using Peripheral Manager, Mavericks or higher");
            CBPeripheralManager *pm = manager = [[CBPeripheralManager alloc] initWithDelegate:delegate queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) options:@{CBPeripheralManagerOptionShowPowerAlertKey:@YES}];
            [pm startAdvertising:nil];
        } else
#endif
        if (&CBCentralManagerScanOptionAllowDuplicatesKey) {
            info("Using Central Manager, Lion or Mountain Lion");
            CBCentralManager *cm = manager = [[CBCentralManager alloc] initWithDelegate:delegate queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
            [cm scanForPeripheralsWithServices:nil options:nil];
        }
        else
            err("No Bluetooth managers found");
        dispatch_main();
    }
    return 0;
}
 

Attachments

  • BluetoothLowEnergyCheck.zip
    4.3 KB · Views: 690
Possible Bluetooth Low Energy Tester

On my machine, with a BT4.0 device (which I think supports BLE):
Code:
Built Jul 28 2014
Found (0xA5C21E8) named '<machineName>', turned on, ready
HCI 0x6:0x1000, LMP 0x6:0x220e, MAC <macAddress>
Low Energy supported, Power Change supported
Using Central Manager, Lion or Mountain Lion
State is: Powered On
--edit
Updated
 
Handoff Bluetooth Tester

This is on my mid-2012 15" MacBook Pro:

Code:
Last login: Thu Jul 24 19:55:38 on consoleBeelzebozos-MacBook-Pro:~ Beelzebozo$ /Users/Beelzebozo/Downloads/BluetoothLowEnergyCheck ; exit;
Built Jul 28 2014
Found (0x5AC821D) named 'Beelzebozo’s MacBook Pro', turned on, ready
HCI 0x6:0x1619, LMP 0x6:0x228b, MAC 00-23-12-13-49-98
Low Energy supported, Power Change supported
Using Peripheral Manager, Mavericks or higher
State is: Powered On
logout

My ASUS P7P55D build with a Belkin Mini BT adapter:

Code:
Last login: Sat Jul 26 15:27:33 on consolep7p55ds-mac-pro:~ P7P55D$ /Volumes/Mac\ HD/Users/P7P55D/Downloads/BluetoothLowEnergyCheck ; exit;
Built Jul 28 2014
Found (0xA5C2101) named 'P7P55D’s iMac', turned on, ready
HCI 0x3:0x4000, LMP 0x3:0x430e, MAC 00-02-72-17-89-02
Low Energy unsupported, Power Change supported
Using Peripheral Manager, Mavericks or higher
State is: Powered Off
logout

My H67N-USB3-B3 build with a GMYLE low power BT adapter:

Code:
Last login: Wed Jul 30 16:30:42 on consoleh67nusb3b3smini:~ H67N-USB3-B3$ /Users/H67N-USB3-B3/Desktop/BluetoothLowEnergyCheck\ 2 ; exit;
Built Jul 28 2014
Found (0xA5C21E8) named 'H67N-USB3-B3’s Mac Mini', turned on, ready
HCI 0x6:0x1000, LMP 0x6:0x220e, MAC 00-02-72-c6-c9-91
Low Energy supported, Power Change supported
Using Peripheral Manager, Mavericks or higher
State is: Powered On
logout
 
Handoff Bluetooth Tester

bt4.1.jpg
I have the IOGear USB 4.0 Bluetooth dongle- here's my output-

Code:
CustoMac:~ CustoMac$ /Users/CustoMac/Downloads/BluetoothLowEnergyCheck ; exit;Built Jul 28 2014
Found (0xA5C21E8) named 'CustoMac', turned on, ready
HCI 0x6:0x1000, LMP 0x6:0x220e, MAC 00-02-72-c5-f3-bb
Low Energy supported, Power Change supported
Using Peripheral Manager, Mavericks or higher
State is: Powered On
logout
 
Last login: Fri Aug 1 13:25:59 on ttys001
localhost:~ Balta$ /Users/Balta/Desktop/BluetoothLowEnergyCheck ; exit;
Built Jul 28 2014
Found (0xA121) named 'Bluetooth Mac (00-15-83-64-dd-6f)', turned on, ready
HCI 0x6:0x1d86, LMP 0x6:0x1d86, MAC 00-15-83-64-dd-6f
Low Energy supported, Power Change supported
Using Central Manager, Lion or Mountain Lion
State is: Powered On
logout

[Proceso completado]



using a BT adapter that i bought from china.
 
Not sure this is normal.
Code:
mackrap:Downloads shpokas$ ./BluetoothLowEnergyCheck
Built Jul 28 2014
No controller found
Your screenshot says the power is off, and the chipset is Unknown. Since this tool reads from the same information, and stops if there is no current controller (chipset), this is the normal response. Turn it on and try again, if you want to test it
The whole point of this thread is that that's not enough. Did you read the first post? I mention that LMP (Link Manager Protocol) versions only directly correspond to marketing versions, i.e. LMP v6 is Bluetooth 4--that's it. Quoting from that article's title, "Bluetooth 4.0 (BT LE)" is exactly what's wrong with those kinds of assumptions. Here is a tool that reads directly from the software responsible for allowing Handoff, and tests its functionality to boot. That can't be a bad thing, and its only a double-click to try it out.
 
This is on my mid-2010 15" MacBook Pro:

Code:
Last login: Sat Aug  2 04:10:21 on ttys000
MacBook-Pro:~ Yoyo$ /Users/Yoyo/Desktop/BluetoothLowEnergyCheck ; exit;
Built Jul 28 2014
Found (0x5AC8218) named '-----’s MacBook Pro', turned on, ready
HCI 0x4:0x34e, LMP 0x4:0x422a, MAC -----
Low Energy unsupported, Power Change supported
Using Peripheral Manager, Mavericks or higher
State is: Unsupported
logout
 
Indeed. I kinda forgot how seldom I use Bluetooth on this hack.
Thanks for the tool.

mackrap: Downloads shpokas$ ./BluetoothLowEnergyCheck
Built Jul 28 2014
Found (0xA5C21E1) named 'mackrap', turned on, ready
HCI 0x6:0x1000, LMP 0x6:0x220e, MAC a4-17-31-b7-5c-5f
Low Energy supported, Power Change supported
Using Peripheral Manager, Mavericks or higher
State is: Powered On
 
Status
Not open for further replies.
Back
Top