Skip to content

Commit dfbeba3

Browse files
more36xiaoxiang781216
authored andcommitted
filter redundant hci reset commands due to dual Bluetooth protocol stacks
Signed-off-by: duqunbo <[email protected]>
1 parent 8b68f9d commit dfbeba3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

drivers/wireless/bluetooth/bt_bridge.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
#define BT_FILTER_TYPE_BLE 1
4545
#define BT_FILTER_TYPE_COUNT 2
4646

47+
#define BT_FILTER_CMD_RESET 0
48+
#define BT_FILTER_CMD_COUNT 1
49+
4750
/****************************************************************************
4851
* Private Types
4952
****************************************************************************/
@@ -70,6 +73,7 @@ struct bt_bridge_s
7073
FAR struct snoop_s *snoop;
7174
#endif /* CONFIG_BLUETOOTH_BRIDGE_BTSNOOP */
7275
atomic_uint refs;
76+
bool dispatched[BT_FILTER_CMD_COUNT];
7377
};
7478

7579
/****************************************************************************
@@ -427,6 +431,45 @@ static int bt_bridge_open(FAR struct bt_driver_s *drv)
427431
return OK;
428432
}
429433

434+
static int bt_bridge_send_reset_response(FAR struct bt_driver_s *driver)
435+
{
436+
uint8_t reset_response[6];
437+
438+
reset_response[0] = BT_HCI_EVT_CMD_COMPLETE;
439+
reset_response[1] = 0x04;
440+
reset_response[2] = 0x01;
441+
reset_response[3] = BT_HCI_OP_RESET & 0xff;
442+
reset_response[4] = (BT_HCI_OP_RESET >> 8) & 0xff;
443+
reset_response[5] = BT_HCI_SUCCESS;
444+
445+
return bt_netdev_receive(driver, BT_EVT, reset_response,
446+
sizeof(reset_response));
447+
}
448+
449+
static bool bt_bridge_filter_command(FAR struct bt_bridge_s *bridge,
450+
FAR struct bt_driver_s *driver,
451+
FAR uint8_t *data)
452+
{
453+
uint16_t opcode = BT_LE162HOST(((uint16_t *)data)[0]);
454+
455+
switch (opcode)
456+
{
457+
case BT_HCI_OP_RESET:
458+
if (bridge->dispatched[BT_FILTER_CMD_RESET])
459+
{
460+
bt_bridge_send_reset_response(driver);
461+
return true;
462+
}
463+
464+
bridge->dispatched[BT_FILTER_CMD_RESET] = true;
465+
break;
466+
default:
467+
break;
468+
}
469+
470+
return false;
471+
}
472+
430473
static int bt_bridge_send(FAR struct bt_driver_s *drv,
431474
enum bt_buf_type_e type,
432475
FAR void *data, size_t len)
@@ -438,6 +481,13 @@ static int bt_bridge_send(FAR struct bt_driver_s *drv,
438481
irqstate_t flags;
439482

440483
flags = enter_critical_section();
484+
485+
if (bt_bridge_filter_command(bridge, drv, data))
486+
{
487+
leave_critical_section(flags);
488+
return len;
489+
}
490+
441491
if (bt_filter_can_send(&device->filter, type, data, len))
442492
{
443493
leave_critical_section(flags);

0 commit comments

Comments
 (0)