bluez/emulator/btdev.h
Luiz Augusto von Dentz 4a00535fa3 emulator: Add support for vendor commands
This adds support for vendor commands reserving a single opcode (0xfc10)
so it can be extended using subcommands, similar to how MSFT works.

The first subcommand (0x00) enables the emulator to generate arbitrary
events using the commands parameters:

> tools/hcitool cmd 3f 10 00 22 24 d0 d0 d0 d0 d0 d0 ff ff
< HCI Command: Vendor (0x3f|0x0010) plen 11
        00 22 24 d0 d0 d0 d0 d0 d0 ff ff
	."$........
Bluetooth: hci0: Malformed HCI Event: 0x22
> HCI Event: Inquiry Result with R.. (0x22) plen 9
        Num responses: 36
        Page scan repetition mode: Reserved (0xff)
        Page period mode: Reserved (0xff)
        Class: 0xffffd0
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x34
          Limited Discoverable Mode
          invalid service class
        Clock offset: 0x6368
        RSSI: 105 dBm (0x69)
> HCI Event: Command Complete (0x0e) plen 4
      Vendor (0x3f|0x0010) ncmd 1
        Status: Success (0x00)
2022-01-05 15:06:40 -08:00

106 lines
3.0 KiB
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2011-2012 Intel Corporation
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
*
*
*/
#include <stdint.h>
#include <stdbool.h>
#define BTDEV_RESPONSE_DEFAULT 0
#define BTDEV_RESPONSE_COMMAND_STATUS 1
#define BTDEV_RESPONSE_COMMAND_COMPLETE 2
typedef struct btdev_callback * btdev_callback;
void btdev_command_response(btdev_callback callback, uint8_t response,
uint8_t status, const void *data, uint8_t len);
#define btdev_command_default(callback) \
btdev_command_response(callback, \
BTDEV_RESPONSE_DEFAULT, 0x00, NULL, 0);
#define btdev_command_status(callback, status) \
btdev_command_response(callback, \
BTDEV_RESPONSE_COMMAND_STATUS, status, NULL, 0);
#define btdev_command_complete(callback, data, len) \
btdev_command_response(callback, \
BTDEV_RESPONSE_COMMAND_COMPLETE, 0x00, data, len);
typedef void (*btdev_command_func) (uint16_t opcode,
const void *data, uint8_t len,
btdev_callback callback, void *user_data);
typedef void (*btdev_send_func) (const struct iovec *iov, int iovlen,
void *user_data);
typedef bool (*btdev_hook_func) (const void *data, uint16_t len,
void *user_data);
enum btdev_type {
BTDEV_TYPE_BREDRLE,
BTDEV_TYPE_BREDR,
BTDEV_TYPE_LE,
BTDEV_TYPE_AMP,
BTDEV_TYPE_BREDR20,
BTDEV_TYPE_BREDRLE50,
BTDEV_TYPE_BREDRLE52,
};
enum btdev_hook_type {
BTDEV_HOOK_PRE_CMD,
BTDEV_HOOK_POST_CMD,
BTDEV_HOOK_PRE_EVT,
BTDEV_HOOK_POST_EVT,
};
struct btdev;
struct btdev *btdev_create(enum btdev_type type, uint16_t id);
void btdev_destroy(struct btdev *btdev);
typedef void (*btdev_debug_func_t)(const char *str, void *user_data);
typedef void (*btdev_destroy_func_t)(void *user_data);
bool btdev_set_debug(struct btdev *btdev, btdev_debug_func_t callback,
void *user_data, btdev_destroy_func_t destroy);
const uint8_t *btdev_get_bdaddr(struct btdev *btdev);
uint8_t *btdev_get_features(struct btdev *btdev);
uint8_t btdev_get_scan_enable(struct btdev *btdev);
uint8_t btdev_get_le_scan_enable(struct btdev *btdev);
const uint8_t *btdev_get_adv_addr(struct btdev *btdev, uint8_t handle);
void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states);
void btdev_set_al_len(struct btdev *btdev, uint8_t len);
void btdev_set_rl_len(struct btdev *btdev, uint8_t len);
void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler,
void *user_data);
void btdev_set_send_handler(struct btdev *btdev, btdev_send_func handler,
void *user_data);
void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len);
int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
uint16_t opcode, btdev_hook_func handler,
void *user_data);
bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
uint16_t opcode);
int btdev_set_msft_opcode(struct btdev *btdev, uint16_t opcode);
int btdev_set_aosp_capable(struct btdev *btdev, bool enable);
int btdev_set_emu_opcode(struct btdev *btdev, uint16_t opcode);