Loading system/bta/dm/bta_dm_act.cc +4 −3 Original line number Diff line number Diff line Loading @@ -253,8 +253,6 @@ const tBTM_APPL_INFO bta_security = { #define MAX_DISC_RAW_DATA_BUF (4096) uint8_t g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF]; extern DEV_CLASS local_device_default_class; // Stores the local Input/Output Capabilities of the Bluetooth device. static uint8_t btm_local_io_caps; Loading Loading @@ -359,7 +357,10 @@ void BTA_dm_on_hw_on() { memset(&bta_dm_conn_srvcs, 0, sizeof(bta_dm_conn_srvcs)); memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB)); memcpy(dev_class, p_bta_dm_cfg->dev_class, sizeof(dev_class)); btif_dm_get_local_class_of_device(dev_class); LOG_INFO("%s: Read default class of device {0x%x, 0x%x, 0x%x}", __func__, dev_class[0], dev_class[1], dev_class[2]); if (bluetooth::shim::is_gd_security_enabled()) { bluetooth::shim::BTM_SetDeviceClass(dev_class); } else { Loading system/bta/dm/bta_dm_cfg.cc +0 −2 Original line number Diff line number Diff line Loading @@ -53,8 +53,6 @@ #endif const tBTA_DM_CFG bta_dm_cfg = { /* mobile phone COD */ BTA_DM_COD, /* page timeout in 625uS */ BTA_DM_PAGE_TIMEOUT, /* true to avoid scatternet when av is streaming (be the central) */ Loading system/bta/dm/bta_dm_int.h +0 −1 Original line number Diff line number Diff line Loading @@ -393,7 +393,6 @@ enum { }; typedef struct { DEV_CLASS dev_class; /* local device class */ uint16_t page_timeout; /* timeout for page in slots */ bool avoid_scatter; /* true to avoid scatternet when av is streaming (be the central) */ Loading system/btif/include/btif_dm.h +5 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,11 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig); void btif_dm_proc_io_rsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob_data, tBTM_AUTH_REQ auth_req); /** * Device Configuration Queries */ void btif_dm_get_local_class_of_device(DEV_CLASS device_class); /** * Out-of-band functions */ Loading system/btif/src/btif_dm.cc +139 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,10 @@ const bool enable_address_consolidate = true; // TODO remove #define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2 #ifndef PROPERTY_CLASS_OF_DEVICE #define PROPERTY_CLASS_OF_DEVICE "bluetooth.device.class_of_device" #endif #define NUM_TIMEOUT_RETRIES 5 #ifndef PROPERTY_DEFAULT_DEVICE_NAME #define PROPERTY_DEFAULT_DEVICE_NAME "bluetooth.device.default_name" Loading Loading @@ -2188,6 +2192,139 @@ void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant, } } /******************************************************************************* * * Function btif_dm_get_local_class_of_device * * Description Reads the system property configured class of device * * Inputs A pointer to a DEV_CLASS that you want filled with the * current class of device. Size is assumed to be 3. * * Returns Nothing. device_class will contain the current class of * device. If no value is present, or the value is malformed * the default "unclassified" value will be used * ******************************************************************************/ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) { /* A class of device is a {SERVICE_CLASS, MAJOR_CLASS, MINOR_CLASS} * * The input is expected to be a string of the following format: * <decimal number>,<decimal number>,<decimal number> * * For example, "90,2,12" (Hex: 0x5A, 0x2, 0xC) * * Notice there is always two commas and no spaces. */ device_class[0] = 0x00; device_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; device_class[2] = BTM_COD_MINOR_UNCLASSIFIED; #ifdef OS_ANDROID std::vector<std::optional<std::uint32_t>> local_device_class = android::sysprop::BluetoothProperties::getClassOfDevice(); // Error check the inputs. Use the default if problems are found if (local_device_class.size() != 3) { LOG_ERROR("COD malformed, must have unsigned 3 integers."); } else if (local_device_class[0].has_value() || local_device_class[0].value() > 0xFF) { LOG_ERROR("COD malformed, first value is missing or too large."); } else if (local_device_class[1].has_value() || local_device_class[1].value() > 0xFF) { LOG_ERROR("COD malformed, second value is missing or too large."); } else if (local_device_class[2].has_value() || local_device_class[2].value() > 0xFF) { LOG_ERROR("COD malformed, third value is missing or too large."); } else { device_class[0] = (uint8_t) local_device_class[0].value(); device_class[1] = (uint8_t) local_device_class[1].value(); device_class[2] = (uint8_t) local_device_class[2].value(); } #else char prop_cod[PROPERTY_VALUE_MAX]; osi_property_get(PROPERTY_CLASS_OF_DEVICE, prop_cod, ""); // If the property is empty, use the default if (prop_cod[0] == '\0') { LOG_ERROR("%s: COD property is empty", __func__); return; } // Start reading the contents of the property string. If at any point anything // is malformed, use the default. DEV_CLASS temp_device_class; int i = 0; int j = 0; for (;;) { // Build a string of all the chars until the next comma, null, or end of the // buffer is reached. If any char is not a digit, then return the default. std::string value; while (i < PROPERTY_VALUE_MAX && prop_cod[i] != ',' && prop_cod[i] != '\0') { char c = prop_cod[i++]; if (!std::isdigit(c)) { LOG_ERROR("%s: COD malformed, '%c' is a non-digit", __func__, c); return; } value += c; } // If we hit the end and it wasn't null terminated then return the default if (i == PROPERTY_VALUE_MAX && prop_cod[PROPERTY_VALUE_MAX - 1] != '\0') { LOG_ERROR("%s: COD malformed, value was truncated", __func__); return; } // Each number in the list must be one byte, meaning 0 (0x00) -> 255 (0xFF) if (value.size() > 3 || value.size() == 0) { LOG_ERROR("%s: COD malformed, '%s' must be between [0, 255]", __func__, value.c_str()); return; } // Grab the value. If it's too large, then return the default uint32_t uint32_val = static_cast<uint32_t>(std::stoul(value.c_str())); if (uint32_val > 0xFF) { LOG_ERROR("%s: COD malformed, '%s' must be between [0, 255]", __func__, value.c_str()); return; } // Otherwise, it's safe to use temp_device_class[j++] = uint32_val; // If we've reached 3 numbers then make sure we're at a null terminator if (j >= 3) { if (prop_cod[i] != '\0') { LOG_ERROR("%s: COD malformed, more than three numbers", __func__); return; } break; } // If we're at a null terminator then we're done if (prop_cod[i] == '\0') { break; } // Otherwise, skip over the comma ++i; } // We must have read exactly 3 numbers if (j == 3) { device_class[0] = temp_device_class[0]; device_class[1] = temp_device_class[1]; device_class[2] = temp_device_class[2]; } else { LOG_ERROR("%s: COD malformed, fewer than three numbers", __func__); } #endif LOG_DEBUG("%s: Using class of device '0x%x, 0x%x, 0x%x'", __func__, device_class[0], device_class[1], device_class[2]); } /******************************************************************************* * * Function btif_dm_get_adapter_property Loading Loading @@ -2223,7 +2360,8 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t* prop) { } break; case BT_PROPERTY_CLASS_OF_DEVICE: { DEV_CLASS dev_class = BTA_DM_COD; DEV_CLASS dev_class; btif_dm_get_local_class_of_device(dev_class); memcpy(prop->val, dev_class, sizeof(DEV_CLASS)); prop->len = sizeof(DEV_CLASS); } break; Loading Loading
system/bta/dm/bta_dm_act.cc +4 −3 Original line number Diff line number Diff line Loading @@ -253,8 +253,6 @@ const tBTM_APPL_INFO bta_security = { #define MAX_DISC_RAW_DATA_BUF (4096) uint8_t g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF]; extern DEV_CLASS local_device_default_class; // Stores the local Input/Output Capabilities of the Bluetooth device. static uint8_t btm_local_io_caps; Loading Loading @@ -359,7 +357,10 @@ void BTA_dm_on_hw_on() { memset(&bta_dm_conn_srvcs, 0, sizeof(bta_dm_conn_srvcs)); memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB)); memcpy(dev_class, p_bta_dm_cfg->dev_class, sizeof(dev_class)); btif_dm_get_local_class_of_device(dev_class); LOG_INFO("%s: Read default class of device {0x%x, 0x%x, 0x%x}", __func__, dev_class[0], dev_class[1], dev_class[2]); if (bluetooth::shim::is_gd_security_enabled()) { bluetooth::shim::BTM_SetDeviceClass(dev_class); } else { Loading
system/bta/dm/bta_dm_cfg.cc +0 −2 Original line number Diff line number Diff line Loading @@ -53,8 +53,6 @@ #endif const tBTA_DM_CFG bta_dm_cfg = { /* mobile phone COD */ BTA_DM_COD, /* page timeout in 625uS */ BTA_DM_PAGE_TIMEOUT, /* true to avoid scatternet when av is streaming (be the central) */ Loading
system/bta/dm/bta_dm_int.h +0 −1 Original line number Diff line number Diff line Loading @@ -393,7 +393,6 @@ enum { }; typedef struct { DEV_CLASS dev_class; /* local device class */ uint16_t page_timeout; /* timeout for page in slots */ bool avoid_scatter; /* true to avoid scatternet when av is streaming (be the central) */ Loading
system/btif/include/btif_dm.h +5 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,11 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig); void btif_dm_proc_io_rsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob_data, tBTM_AUTH_REQ auth_req); /** * Device Configuration Queries */ void btif_dm_get_local_class_of_device(DEV_CLASS device_class); /** * Out-of-band functions */ Loading
system/btif/src/btif_dm.cc +139 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,10 @@ const bool enable_address_consolidate = true; // TODO remove #define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2 #ifndef PROPERTY_CLASS_OF_DEVICE #define PROPERTY_CLASS_OF_DEVICE "bluetooth.device.class_of_device" #endif #define NUM_TIMEOUT_RETRIES 5 #ifndef PROPERTY_DEFAULT_DEVICE_NAME #define PROPERTY_DEFAULT_DEVICE_NAME "bluetooth.device.default_name" Loading Loading @@ -2188,6 +2192,139 @@ void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant, } } /******************************************************************************* * * Function btif_dm_get_local_class_of_device * * Description Reads the system property configured class of device * * Inputs A pointer to a DEV_CLASS that you want filled with the * current class of device. Size is assumed to be 3. * * Returns Nothing. device_class will contain the current class of * device. If no value is present, or the value is malformed * the default "unclassified" value will be used * ******************************************************************************/ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) { /* A class of device is a {SERVICE_CLASS, MAJOR_CLASS, MINOR_CLASS} * * The input is expected to be a string of the following format: * <decimal number>,<decimal number>,<decimal number> * * For example, "90,2,12" (Hex: 0x5A, 0x2, 0xC) * * Notice there is always two commas and no spaces. */ device_class[0] = 0x00; device_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; device_class[2] = BTM_COD_MINOR_UNCLASSIFIED; #ifdef OS_ANDROID std::vector<std::optional<std::uint32_t>> local_device_class = android::sysprop::BluetoothProperties::getClassOfDevice(); // Error check the inputs. Use the default if problems are found if (local_device_class.size() != 3) { LOG_ERROR("COD malformed, must have unsigned 3 integers."); } else if (local_device_class[0].has_value() || local_device_class[0].value() > 0xFF) { LOG_ERROR("COD malformed, first value is missing or too large."); } else if (local_device_class[1].has_value() || local_device_class[1].value() > 0xFF) { LOG_ERROR("COD malformed, second value is missing or too large."); } else if (local_device_class[2].has_value() || local_device_class[2].value() > 0xFF) { LOG_ERROR("COD malformed, third value is missing or too large."); } else { device_class[0] = (uint8_t) local_device_class[0].value(); device_class[1] = (uint8_t) local_device_class[1].value(); device_class[2] = (uint8_t) local_device_class[2].value(); } #else char prop_cod[PROPERTY_VALUE_MAX]; osi_property_get(PROPERTY_CLASS_OF_DEVICE, prop_cod, ""); // If the property is empty, use the default if (prop_cod[0] == '\0') { LOG_ERROR("%s: COD property is empty", __func__); return; } // Start reading the contents of the property string. If at any point anything // is malformed, use the default. DEV_CLASS temp_device_class; int i = 0; int j = 0; for (;;) { // Build a string of all the chars until the next comma, null, or end of the // buffer is reached. If any char is not a digit, then return the default. std::string value; while (i < PROPERTY_VALUE_MAX && prop_cod[i] != ',' && prop_cod[i] != '\0') { char c = prop_cod[i++]; if (!std::isdigit(c)) { LOG_ERROR("%s: COD malformed, '%c' is a non-digit", __func__, c); return; } value += c; } // If we hit the end and it wasn't null terminated then return the default if (i == PROPERTY_VALUE_MAX && prop_cod[PROPERTY_VALUE_MAX - 1] != '\0') { LOG_ERROR("%s: COD malformed, value was truncated", __func__); return; } // Each number in the list must be one byte, meaning 0 (0x00) -> 255 (0xFF) if (value.size() > 3 || value.size() == 0) { LOG_ERROR("%s: COD malformed, '%s' must be between [0, 255]", __func__, value.c_str()); return; } // Grab the value. If it's too large, then return the default uint32_t uint32_val = static_cast<uint32_t>(std::stoul(value.c_str())); if (uint32_val > 0xFF) { LOG_ERROR("%s: COD malformed, '%s' must be between [0, 255]", __func__, value.c_str()); return; } // Otherwise, it's safe to use temp_device_class[j++] = uint32_val; // If we've reached 3 numbers then make sure we're at a null terminator if (j >= 3) { if (prop_cod[i] != '\0') { LOG_ERROR("%s: COD malformed, more than three numbers", __func__); return; } break; } // If we're at a null terminator then we're done if (prop_cod[i] == '\0') { break; } // Otherwise, skip over the comma ++i; } // We must have read exactly 3 numbers if (j == 3) { device_class[0] = temp_device_class[0]; device_class[1] = temp_device_class[1]; device_class[2] = temp_device_class[2]; } else { LOG_ERROR("%s: COD malformed, fewer than three numbers", __func__); } #endif LOG_DEBUG("%s: Using class of device '0x%x, 0x%x, 0x%x'", __func__, device_class[0], device_class[1], device_class[2]); } /******************************************************************************* * * Function btif_dm_get_adapter_property Loading Loading @@ -2223,7 +2360,8 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t* prop) { } break; case BT_PROPERTY_CLASS_OF_DEVICE: { DEV_CLASS dev_class = BTA_DM_COD; DEV_CLASS dev_class; btif_dm_get_local_class_of_device(dev_class); memcpy(prop->val, dev_class, sizeof(DEV_CLASS)); prop->len = sizeof(DEV_CLASS); } break; Loading