BluetoothRadio: add more props; remove hciVersion; code cleanup

This commit is contained in:
Carter Li
2024-07-28 15:26:37 +08:00
committed by 李通洲
parent 7a75615d9e
commit c14ba32b82
6 changed files with 68 additions and 37 deletions
+1 -4
View File
@@ -27,10 +27,7 @@ const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */)
}, &btdi);
if(!hFind)
{
if (GetLastError() == ERROR_NO_MORE_ITEMS)
return "No Bluetooth devices found";
else
return "BluetoothFindFirstDevice() failed";
return "BluetoothFindFirstDevice() failed";
}
do {
@@ -6,11 +6,12 @@ typedef struct FFBluetoothRadioResult
{
FFstrbuf name;
FFstrbuf address;
uint8_t lmpVersion;
uint8_t hciVersion;
uint16_t lmpSubversion;
uint16_t hciRevision;
int32_t lmpVersion;
int32_t lmpSubversion;
const char* vendor;
bool enabled;
bool discoverable;
bool connectable;
} FFBluetoothRadioResult;
const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */);
@@ -11,10 +11,11 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothResult */)
FFBluetoothRadioResult* device = ffListAdd(devices);
ffStrbufInitS(&device->name, ctrl.nameAsString.UTF8String);
ffStrbufInitS(&device->address, ctrl.addressAsString.UTF8String);
device->lmpVersion = 0;
device->hciVersion = 0;
device->lmpSubversion = 0;
device->hciRevision = 0;
device->lmpVersion = -1;
device->lmpSubversion = -1;
device->enabled = ctrl.powerState == kBluetoothHCIPowerStateON;
device->discoverable = false;
device->connectable = true;
#ifdef __aarch64__
device->vendor = "Apple";
@@ -51,8 +51,8 @@ static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBlue
DBusMessageIter dictIter;
dbus->lib->ffdbus_message_iter_recurse(iter, &dictIter);
// if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING)
// return;
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING)
return;
const char* deviceProperty;
dbus->lib->ffdbus_message_iter_get_basic(&dictIter, &deviceProperty);
@@ -61,7 +61,7 @@ static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBlue
if(ffStrEquals(deviceProperty, "Address"))
ffDBusGetString(dbus, &dictIter, &device->address);
else if(ffStrEquals(deviceProperty, "Name"))
else if(ffStrEquals(deviceProperty, "Alias"))
ffDBusGetString(dbus, &dictIter, &device->name);
else if(ffStrEquals(deviceProperty, "Manufacturer"))
{
@@ -70,7 +70,17 @@ static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBlue
device->vendor = ffBluetoothRadioGetVendor(detection);
}
else if(ffStrEquals(deviceProperty, "Version"))
ffDBusGetByte(dbus, &dictIter, &device->lmpVersion);
{
uint8_t byte;
if (ffDBusGetByte(dbus, &dictIter, &byte))
device->lmpVersion = byte;
}
else if(ffStrEquals(deviceProperty, "Powered"))
ffDBusGetBool(dbus, &dictIter, &device->enabled);
else if(ffStrEquals(deviceProperty, "Discoverable"))
ffDBusGetBool(dbus, &dictIter, &device->discoverable);
else if(ffStrEquals(deviceProperty, "Pairable"))
ffDBusGetBool(dbus, &dictIter, &device->connectable);
}
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothRadioResult* device)
@@ -134,11 +144,10 @@ static void detectBluetoothObject(FFlist* devices, FFDBusData* dbus, DBusMessage
FFBluetoothRadioResult* device = ffListAdd(devices);
ffStrbufInit(&device->name);
ffStrbufInit(&device->address);
device->lmpVersion = 0;
device->hciVersion = 0;
device->lmpSubversion = 0;
device->hciRevision = 0;
device->lmpVersion = -1;
device->lmpSubversion = -1;
device->vendor = "Unknown";
device->enabled = false;
while(true)
{
@@ -58,6 +58,8 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindFirstRadio)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindNextRadio)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindRadioClose)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothIsConnectable)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothIsDiscoverable)
HANDLE hRadio = NULL;
HBLUETOOTH_DEVICE_FIND hFind = ffBluetoothFindFirstRadio(&(BLUETOOTH_FIND_RADIO_PARAMS) {
@@ -66,7 +68,7 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
if(!hFind)
{
if (GetLastError() == ERROR_NO_MORE_ITEMS)
return "No Bluetooth radios found";
return "No Bluetooth radios found or service disabled";
else
return "BluetoothFindFirstRadio() failed";
}
@@ -91,9 +93,10 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
device->lmpVersion = blri.radioInfo.lmpVersion;
device->lmpSubversion = blri.radioInfo.lmpSubversion;
device->hciVersion = blri.hciVersion;
device->hciRevision = blri.hciRevision;
device->vendor = ffBluetoothRadioGetVendor(blri.radioInfo.mfg);
device->enabled = true;
device->connectable = ffBluetoothIsConnectable(hRadio);
device->discoverable = ffBluetoothIsDiscoverable(hRadio);
} while (ffBluetoothFindNextRadio(hFind, &hRadio));
ffBluetoothFindRadioClose(hFind);