Skip to content

Commit

Permalink
Merge branch 'contrib/github_pr_14286_v5.3' into 'release/v5.3'
Browse files Browse the repository at this point in the history
fix(bt): Add a parameter in the two least significant bits of Class of Device (backport v5.3)

See merge request espressif/esp-idf!33164
  • Loading branch information
jack0c committed Sep 4, 2024
2 parents 59380fe + 020276b commit 90f1111
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/api/esp_gap_bt_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ esp_err_t esp_bt_gap_set_cod(esp_bt_cod_t cod, esp_bt_cod_mode_t mode)
}

switch (mode) {
case ESP_BT_SET_COD_RESERVED_2:
case ESP_BT_SET_COD_MAJOR_MINOR:
case ESP_BT_SET_COD_SERVICE_CLASS:
case ESP_BT_CLR_COD_SERVICE_CLASS:
Expand Down
5 changes: 3 additions & 2 deletions components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ typedef enum {
ESP_BT_SET_COD_MAJOR_MINOR = 0x01, /*!< overwrite major, minor class */
ESP_BT_SET_COD_SERVICE_CLASS = 0x02, /*!< set the bits in the input, the current bit will remain */
ESP_BT_CLR_COD_SERVICE_CLASS = 0x04, /*!< clear the bits in the input, others will remain */
ESP_BT_SET_COD_ALL = 0x08, /*!< overwrite major, minor, set the bits in service class */
ESP_BT_INIT_COD = 0x0a, /*!< overwrite major, minor, and service class */
ESP_BT_SET_COD_ALL = 0x08, /*!< overwrite major, minor, set the bits in service class, reserved_2 remain unchanged */
ESP_BT_INIT_COD = 0x0a, /*!< overwrite major, minor, and service class, reserved_2 remain unchanged */
ESP_BT_SET_COD_RESERVED_2 = 0x10, /*!< overwrite the two least significant bits reserved_2 whose default value is 0b00; other values of reserved_2 are invalid according to Bluetooth Core Specification 5.4 */
} esp_bt_cod_mode_t;

#define ESP_BT_GAP_AFH_CHANNELS_LEN 10
Expand Down
7 changes: 5 additions & 2 deletions components/bt/host/bluedroid/bta/include/bta/utl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
#define BTA_UTL_CLR_COD_SERVICE_CLASS 0x04
#define BTA_UTL_SET_COD_ALL 0x08 /* take service class as the input (may clear some set bits!!) */
#define BTA_UTL_INIT_COD 0x0a
#define BTA_UTL_SET_COD_RESERVED_2 0x10 /* overwrite the two least significant bits reserved_2 */

/*****************************************************************************
** Type Definitions
*****************************************************************************/

/** for utl_set_device_class() **/
typedef struct {
UINT8 reserved_2;
UINT8 minor;
UINT8 major;
UINT16 service;
Expand Down Expand Up @@ -125,11 +127,12 @@ extern void utl_freebuf(void **p);
** p_cod - Pointer to the device class to set to
**
** cmd - the fields of the device class to update.
** BTA_UTL_SET_COD_RESERVED_2 - overwrite the two least significant bits reserved_2
** BTA_UTL_SET_COD_MAJOR_MINOR, - overwrite major, minor class
** BTA_UTL_SET_COD_SERVICE_CLASS - set the bits in the input
** BTA_UTL_CLR_COD_SERVICE_CLASS - clear the bits in the input
** BTA_UTL_SET_COD_ALL - overwrite major, minor, set the bits in service class
** BTA_UTL_INIT_COD - overwrite major, minor, and service class
** BTA_UTL_SET_COD_ALL - overwrite major, minor, set the bits in service class, reserved_2 remain unchanged
** BTA_UTL_INIT_COD - overwrite major, minor, and service class, reserved_2 remain unchanged
**
** Returns TRUE if successful, Otherwise FALSE
**
Expand Down
17 changes: 12 additions & 5 deletions components/bt/host/bluedroid/bta/sys/utl.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ void utl_freebuf(void **p)
** p_cod - Pointer to the device class to set to
**
** cmd - the fields of the device class to update.
** BTA_UTL_SET_COD_RESERVED_2 - overwrite the two least significant bits reserved_2
** BTA_UTL_SET_COD_MAJOR_MINOR, - overwrite major, minor class
** BTA_UTL_SET_COD_SERVICE_CLASS - set the bits in the input
** BTA_UTL_CLR_COD_SERVICE_CLASS - clear the bits in the input
** BTA_UTL_SET_COD_ALL - overwrite major, minor, set the bits in service class
** BTA_UTL_INIT_COD - overwrite major, minor, and service class
** BTA_UTL_SET_COD_ALL - overwrite major, minor, set the bits in service class, reserved_2 remain unchanged
** BTA_UTL_INIT_COD - overwrite major, minor, and service class, reserved_2 remain unchanged
**
** Returns TRUE if successful, Otherwise FALSE
**
Expand All @@ -183,15 +184,19 @@ BOOLEAN utl_set_device_class(tBTA_UTL_COD *p_cod, UINT8 cmd)
{
UINT8 *dev;
UINT16 service;
UINT8 minor, major;
UINT8 minor, major, reserved_2;
DEV_CLASS dev_class;

dev = BTM_ReadDeviceClass();
BTM_COD_SERVICE_CLASS( service, dev );
BTM_COD_MINOR_CLASS(minor, dev );
BTM_COD_MAJOR_CLASS(major, dev );
BTM_COD_RESERVED_2(reserved_2, dev);

switch (cmd) {
case BTA_UTL_SET_COD_RESERVED_2:
reserved_2 = p_cod->reserved_2 & BTM_COD_RESERVED_2_MASK;
break;
case BTA_UTL_SET_COD_MAJOR_MINOR:
minor = p_cod->minor & BTM_COD_MINOR_CLASS_MASK;
major = p_cod->major & BTM_COD_MAJOR_CLASS_MASK;
Expand Down Expand Up @@ -226,7 +231,7 @@ BOOLEAN utl_set_device_class(tBTA_UTL_COD *p_cod, UINT8 cmd)
}

/* convert the fields into the device class type */
FIELDS_TO_COD(dev_class, minor, major, service);
FIELDS_TO_COD(dev_class, reserved_2, minor, major, service);

if (BTM_SetDeviceClass(dev_class) == BTM_SUCCESS) {
return TRUE;
Expand All @@ -252,16 +257,18 @@ BOOLEAN utl_get_device_class(tBTA_UTL_COD *p_cod)
{
UINT8 *dev;
UINT16 service;
UINT8 minor, major;
UINT8 minor, major, reserved_2;

dev = BTM_ReadDeviceClass();
BTM_COD_SERVICE_CLASS( service, dev );
BTM_COD_MINOR_CLASS(minor, dev );
BTM_COD_MAJOR_CLASS(major, dev );
BTM_COD_RESERVED_2(reserved_2, dev );

p_cod->minor = minor;
p_cod->major = major;
p_cod->service = service;
p_cod->reserved_2 = reserved_2;

return TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ static void btc_gap_bt_set_cod(btc_gap_bt_args_t *arg)
{
tBTA_UTL_COD p_cod;
esp_bt_cod_t *cod = &(arg->set_cod.cod);
p_cod.reserved_2 = cod->reserved_2;
p_cod.minor = cod->minor << 2;
p_cod.major = cod->major;
p_cod.service = cod->service << 5;
Expand All @@ -602,6 +603,7 @@ esp_err_t btc_gap_bt_get_cod(esp_bt_cod_t *cod)
BTC_TRACE_ERROR("%s get class of device failed!",__func__);
return ESP_BT_STATUS_FAIL;
}
cod->reserved_2 = p_cod.reserved_2;
cod->minor = p_cod.minor >> 2;
cod->major = p_cod.major;
cod->service = p_cod.service >> 5;
Expand Down
13 changes: 7 additions & 6 deletions components/bt/host/bluedroid/stack/btm/btm_inq.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ tBTM_STATUS BTM_SetDiscoverability (UINT16 inq_mode, UINT16 window, UINT16 inter
UINT8 scan_mode = 0;
UINT16 service_class;
UINT8 *p_cod;
UINT8 major, minor;
UINT8 major, minor, reserved_2;
DEV_CLASS cod;
LAP temp_lap[2];
BOOLEAN is_limited;
Expand Down Expand Up @@ -255,13 +255,14 @@ tBTM_STATUS BTM_SetDiscoverability (UINT16 inq_mode, UINT16 window, UINT16 inter
if (is_limited ^ cod_limited) {
BTM_COD_MINOR_CLASS(minor, p_cod );
BTM_COD_MAJOR_CLASS(major, p_cod );
BTM_COD_RESERVED_2(reserved_2, p_cod);
if (is_limited) {
service_class |= BTM_COD_SERVICE_LMTD_DISCOVER;
} else {
service_class &= ~BTM_COD_SERVICE_LMTD_DISCOVER;
}

FIELDS_TO_COD(cod, minor, major, service_class);
FIELDS_TO_COD(cod, reserved_2, minor, major, service_class);
(void) BTM_SetDeviceClass (cod);
}

Expand Down Expand Up @@ -515,7 +516,7 @@ tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, UINT16 max_d

/* Before beginning the inquiry the current filter must be cleared, so initiate the command */
if ((status = btm_set_inq_event_filter (p_inqparms->filter_cond_type, &p_inqparms->filter_cond)) != BTM_CMD_STARTED) {
/* If set filter command is not succesful reset the state */
/* If set filter command is not successful reset the state */
p_inq->p_inq_results_cb = NULL;
p_inq->state = BTM_INQ_INACTIVE_STATE;

Expand Down Expand Up @@ -688,7 +689,7 @@ UINT16 BTM_ReadConnectability (UINT16 *p_window, UINT16 *p_interval)
** Description This function returns a bit mask of the current inquiry state
**
** Returns BTM_INQUIRY_INACTIVE if inactive (0)
** BTM_LIMITED_INQUIRY_ACTIVE if a limted inquiry is active
** BTM_LIMITED_INQUIRY_ACTIVE if a limited inquiry is active
** BTM_GENERAL_INQUIRY_ACTIVE if a general inquiry is active
** BTM_PERIODIC_INQUIRY_ACTIVE if a periodic inquiry is active
**
Expand Down Expand Up @@ -783,7 +784,7 @@ tBTM_STATUS BTM_CancelInquiry(void)
** Description This function is called to start an inquiry.
**
** Parameters: p_inqparms - pointer to the inquiry information
** mode - GENERAL or LIMITED inquiry, BR/LE bit mask seperately
** mode - GENERAL or LIMITED inquiry, BR/LE bit mask separately
** duration - length in 1.28 sec intervals (If '0', the inquiry is CANCELLED)
** max_resps - maximum amount of devices to search for before ending the inquiry
** filter_cond_type - BTM_CLR_INQUIRY_FILTER, BTM_FILTER_COND_DEVICE_CLASS, or
Expand Down Expand Up @@ -1858,7 +1859,7 @@ void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode)
#if BLE_INCLUDED == TRUE
/* new device response */
&& ( p_i == NULL ||
/* exisiting device with BR/EDR info */
/* existing device with BR/EDR info */
(p_i && (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0)
)
#endif
Expand Down
10 changes: 5 additions & 5 deletions components/bt/host/bluedroid/stack/include/stack/btm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,22 +456,22 @@ typedef enum {
#define BTM_COD_SERVICE_INFORMATION 0x8000

/* class of device field macros */
#define BTM_COD_FORMAT_TYPE(u8, pd) {u8 = pd[2]&0x03;}
#define BTM_COD_RESERVED_2(u8, pd) {u8 = pd[2]&0x03;}
#define BTM_COD_MINOR_CLASS(u8, pd) {u8 = pd[2]&0xFC;}
#define BTM_COD_MAJOR_CLASS(u8, pd) {u8 = pd[1]&0x1F;}
#define BTM_COD_SERVICE_CLASS(u16, pd) {u16 = pd[0]; u16<<=8; u16 += pd[1]&0xE0;}

/* to set the fields (assumes that format type is always 0) */
#define FIELDS_TO_COD(pd, mn, mj, sv) {pd[2] = mn; pd[1] = \
mj+ ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \
pd[0] = (sv) >> 8;}
#define FIELDS_TO_COD(pd, rs, mn, mj, sv) {pd[2] = (mn & BTM_COD_MINOR_CLASS_MASK) + (rs & BTM_COD_RESERVED_2_MASK); \
pd[1] = mj+ ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \
pd[0] = (sv) >> 8;}

/* the COD masks */
#define BTM_COD_FORMAT_TYPE_MASK 0x03
#define BTM_COD_MINOR_CLASS_MASK 0xFC
#define BTM_COD_MAJOR_CLASS_MASK 0x1F
#define BTM_COD_SERVICE_CLASS_LO_B 0x00E0
#define BTM_COD_SERVICE_CLASS_MASK 0xFFE0
#define BTM_COD_RESERVED_2_MASK 0x03

/* BTM service definitions
** Used for storing EIR data to bit mask
Expand Down

0 comments on commit 90f1111

Please sign in to comment.