wireless/bluetooth:add btsnoop for bt bridge
Signed-off-by: chengkai <chengkai@xiaomi.com>
This commit is contained in:
parent
7a7b5e5779
commit
40f7872668
@ -59,6 +59,13 @@ config BLUETOOTH_BRIDGE
|
|||||||
---help---
|
---help---
|
||||||
Enable Bluetooth BT/BLE Dual Mode Bridge Driver.
|
Enable Bluetooth BT/BLE Dual Mode Bridge Driver.
|
||||||
|
|
||||||
|
config BLUETOOTH_BRIDGE_BTSNOOP
|
||||||
|
bool "Bluetooth bridge btsnoop support"
|
||||||
|
default n
|
||||||
|
depends on BLUETOOTH_BRIDGE
|
||||||
|
---help---
|
||||||
|
Enable Bluetooth hci btsnoop log
|
||||||
|
|
||||||
config BLUETOOTH_NULL
|
config BLUETOOTH_NULL
|
||||||
bool "NULL Bluetooth device"
|
bool "NULL Bluetooth device"
|
||||||
default n
|
default n
|
||||||
|
@ -66,6 +66,9 @@ struct bt_bridge_s
|
|||||||
{
|
{
|
||||||
struct bt_bridge_device_s device[BT_FILTER_TYPE_COUNT];
|
struct bt_bridge_device_s device[BT_FILTER_TYPE_COUNT];
|
||||||
FAR struct bt_driver_s *driver;
|
FAR struct bt_driver_s *driver;
|
||||||
|
#ifdef CONFIG_BLUETOOTH_BRIDGE_BTSNOOP
|
||||||
|
FAR struct snoop_s *snoop;
|
||||||
|
#endif /* CONFIG_BLUETOOTH_BRIDGE_BTSNOOP */
|
||||||
uint8_t refs;
|
uint8_t refs;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -421,8 +424,17 @@ static int bt_bridge_send(FAR struct bt_driver_s *drv,
|
|||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
if (bt_filter_can_send(&device->filter, type, data, len))
|
if (bt_filter_can_send(&device->filter, type, data, len))
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
return driver->send(driver, type, data, len);
|
ret = driver->send(driver, type, data, len);
|
||||||
|
|
||||||
|
#ifdef CONFIG_BLUETOOTH_BRIDGE_BTSNOOP
|
||||||
|
snoop_dump(bridge->snoop, data - drv->head_reserve,
|
||||||
|
len + drv->head_reserve, 0,
|
||||||
|
SNOOP_DIRECTION_FLAG_SENT);
|
||||||
|
#endif /* CONFIG_BLUETOOTH_BRIDGE_BTSNOOP */
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
@ -459,8 +471,17 @@ static int bt_bridge_receive(FAR struct bt_driver_s *drv,
|
|||||||
driver = &device->driver;
|
driver = &device->driver;
|
||||||
if (bt_filter_can_recv(&device->filter, type, data, len))
|
if (bt_filter_can_recv(&device->filter, type, data, len))
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
return bt_netdev_receive(driver, type, data, len);
|
ret = bt_netdev_receive(driver, type, data, len);
|
||||||
|
|
||||||
|
#ifdef CONFIG_BLUETOOTH_BRIDGE_BTSNOOP
|
||||||
|
snoop_dump(bridge->snoop, data - drv->head_reserve,
|
||||||
|
len + drv->head_reserve, 0,
|
||||||
|
SNOOP_DIRECTION_FLAG_RECV);
|
||||||
|
#endif /* CONFIG_BLUETOOTH_BRIDGE_BTSNOOP */
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,14 +497,55 @@ static int bt_bridge_ioctl(FAR struct bt_driver_s *drv, int cmd,
|
|||||||
FAR struct bt_bridge_s *bridge = device->bridge;
|
FAR struct bt_bridge_s *bridge = device->bridge;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
switch (cmd)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_BLUETOOTH_BRIDGE_BTSNOOP
|
||||||
|
case SIOCBTSNOOPOPEN:
|
||||||
|
{
|
||||||
|
FAR const char *filename = (FAR const char *)((uintptr_t)arg);
|
||||||
|
FAR struct snoop_s *snoop = (FAR struct snoop_s *)
|
||||||
|
kmm_zalloc(sizeof(struct snoop_s));
|
||||||
|
if (!snoop)
|
||||||
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if (bridge->driver->ioctl)
|
ret = snoop_open(snoop, filename, SNOOP_DATALINK_HCI_UART, true);
|
||||||
{
|
if (ret == OK)
|
||||||
ret = bridge->driver->ioctl(drv, cmd, arg);
|
{
|
||||||
}
|
bridge->snoop = snoop;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
ret = -ENOTTY;
|
{
|
||||||
|
kmm_free(snoop);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SIOCBTSNOOPCLOSE:
|
||||||
|
{
|
||||||
|
FAR struct snoop_s *snoop = bridge->snoop;
|
||||||
|
|
||||||
|
bridge->snoop = NULL;
|
||||||
|
ret = snoop_close(snoop);
|
||||||
|
kmm_free(snoop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BLUETOOTH_BRIDGE_BTSNOOP */
|
||||||
|
|
||||||
|
/* hci ioctl operation */
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (bridge->driver->ioctl)
|
||||||
|
{
|
||||||
|
ret = bridge->driver->ioctl(drv, cmd, arg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = -ENOTTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user