Blame src/shared/btp.h

Packit 34410b
/*
Packit 34410b
 *
Packit 34410b
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 34410b
 *
Packit 34410b
 *  Copyright (C) 2012-2017  Intel Corporation. All rights reserved.
Packit 34410b
 *
Packit 34410b
 *
Packit 34410b
 *  This library is free software; you can redistribute it and/or
Packit 34410b
 *  modify it under the terms of the GNU Lesser General Public
Packit 34410b
 *  License as published by the Free Software Foundation; either
Packit 34410b
 *  version 2.1 of the License, or (at your option) any later version.
Packit 34410b
 *
Packit 34410b
 *  This library is distributed in the hope that it will be useful,
Packit 34410b
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 34410b
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 34410b
 *  Lesser General Public License for more details.
Packit 34410b
 *
Packit 34410b
 *  You should have received a copy of the GNU Lesser General Public
Packit 34410b
 *  License along with this library; if not, write to the Free Software
Packit 34410b
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit 34410b
 *
Packit 34410b
 */
Packit 34410b
Packit 34410b
#include <stdbool.h>
Packit 34410b
Packit 34410b
#ifndef __packed
Packit 34410b
#define __packed __attribute__((packed))
Packit 34410b
#endif
Packit 34410b
Packit 34410b
#define BTP_INDEX_NON_CONTROLLER 0xff
Packit 34410b
Packit 34410b
#define BTP_ERROR_FAIL		0x01
Packit 34410b
#define BTP_ERROR_UNKNOWN_CMD	0x02
Packit 34410b
#define BTP_ERROR_NOT_READY	0x03
Packit 34410b
#define BTP_ERROR_INVALID_INDEX	0x04
Packit 34410b
Packit 34410b
#define BTP_CORE_SERVICE	0
Packit 34410b
#define BTP_GAP_SERVICE		1
Packit 34410b
#define BTP_GATT_SERVICE	2
Packit 34410b
#define BTP_L2CAP_SERVICE	3
Packit 34410b
#define BTP_MESH_NODE_SERVICE	4
Packit 34410b
Packit 34410b
struct btp_hdr {
Packit 34410b
	uint8_t service;
Packit 34410b
	uint8_t opcode;
Packit 34410b
	uint8_t index;
Packit 34410b
	uint16_t data_len;
Packit 34410b
	uint8_t data[0];
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_error {
Packit 34410b
	uint8_t status;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_ERROR				0x00
Packit 34410b
Packit 34410b
#define BTP_OP_CORE_READ_SUPPORTED_COMMANDS	0x01
Packit 34410b
Packit 34410b
#define BTP_OP_CORE_READ_SUPPORTED_SERVICES	0x02
Packit 34410b
Packit 34410b
#define BTP_OP_CORE_REGISTER			0x03
Packit 34410b
struct btp_core_register_cp {
Packit 34410b
	uint8_t service_id;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_CORE_UNREGISTER			0x04
Packit 34410b
struct btp_core_unregister_cp {
Packit 34410b
	uint8_t service_id;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_CORE_READY			0x80
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_READ_SUPPORTED_COMMANDS	0x01
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_READ_CONTROLLER_INDEX_LIST	0x02
Packit 34410b
struct btp_gap_read_index_rp {
Packit 34410b
	uint8_t num;
Packit 34410b
	uint8_t indexes[0];
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_GAP_SETTING_POWERED			0x00000001
Packit 34410b
#define BTP_GAP_SETTING_CONNECTABLE		0x00000002
Packit 34410b
#define BTP_GAP_SETTING_FAST_CONNECTABLE	0x00000004
Packit 34410b
#define BTP_GAP_SETTING_DISCOVERABLE		0x00000008
Packit 34410b
#define BTP_GAP_SETTING_BONDABLE		0x00000010
Packit 34410b
#define BTP_GAP_SETTING_LL_SECURITY		0x00000020
Packit 34410b
#define BTP_GAP_SETTING_SSP			0x00000040
Packit 34410b
#define BTP_GAP_SETTING_BREDR			0x00000080
Packit 34410b
#define BTP_GAP_SETTING_HS			0x00000100
Packit 34410b
#define BTP_GAP_SETTING_LE			0x00000200
Packit 34410b
#define BTP_GAP_SETTING_ADVERTISING		0x00000400
Packit 34410b
#define BTP_GAP_SETTING_SC			0x00000800
Packit 34410b
#define BTP_GAP_SETTING_DEBUG_KEYS		0x00001000
Packit 34410b
#define BTP_GAP_SETTING_PRIVACY			0x00002000
Packit 34410b
#define BTP_GAP_SETTING_CONTROLLER_CONF		0x00004000
Packit 34410b
#define BTP_GAP_SETTING_STATIC_ADDRESS		0x00008000
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_READ_COTROLLER_INFO		0x03
Packit 34410b
struct btp_gap_read_info_rp {
Packit 34410b
	bdaddr_t address;
Packit 34410b
	uint32_t supported_settings;
Packit 34410b
	uint32_t current_settings;
Packit 34410b
	uint8_t cod[3];
Packit 34410b
	uint8_t name[249];
Packit 34410b
	uint8_t short_name[11];
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_RESET			0x04
Packit 34410b
struct btp_gap_reset_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_SET_POWERED			0x05
Packit 34410b
struct btp_gap_set_powered_cp {
Packit 34410b
	uint8_t powered;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_gap_set_powered_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_SET_CONNECTABLE		0x06
Packit 34410b
struct btp_gap_set_connectable_cp {
Packit 34410b
	uint8_t connectable;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_gap_set_connectable_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_SET_FAST_CONNECTABLE		0x07
Packit 34410b
struct btp_gap_set_fast_connectable_cp {
Packit 34410b
	uint8_t fast_connectable;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_gap_set_fast_connectable_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_SET_DISCOVERABLE		0x08
Packit 34410b
struct btp_gap_set_discoverable_cp {
Packit 34410b
	uint8_t discoverable;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_gap_set_discoverable_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_SET_BONDABLE			0x09
Packit 34410b
struct btp_gap_set_bondable_cp {
Packit 34410b
	uint8_t bondable;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_gap_set_bondable_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_START_ADVERTISING		0x0a
Packit 34410b
struct btp_gap_start_adv_cp {
Packit 34410b
	uint8_t adv_data_len;
Packit 34410b
	uint8_t scan_rsp_len;
Packit 34410b
	uint8_t data[0];
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp_gap_start_adv_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_STOP_ADVERTISING		0x0b
Packit 34410b
struct btp_gap_stop_adv_rp {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_GAP_DISCOVERY_FLAG_LE		0x01
Packit 34410b
#define BTP_GAP_DISCOVERY_FLAG_BREDR		0x02
Packit 34410b
#define BTP_GAP_DISCOVERY_FLAG_LIMITED		0x04
Packit 34410b
#define BTP_GAP_DISCOVERY_FLAG_ACTIVE		0x08
Packit 34410b
#define BTP_GAP_DISCOVERY_FLAG_OBSERVATION	0x10
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_START_DISCOVERY		0x0c
Packit 34410b
struct btp_gap_start_discovery_cp {
Packit 34410b
	uint8_t flags;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_STOP_DISCOVERY		0x0d
Packit 34410b
Packit 34410b
#define BTP_GAP_ADDR_PUBLIC			0x00
Packit 34410b
#define BTP_GAP_ADDR_RANDOM			0x01
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_CONNECT			0x0e
Packit 34410b
struct btp_gap_connect_cp {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_DISCONNECT			0x0f
Packit 34410b
struct btp_gap_disconnect_cp {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_GAP_IOCAPA_DISPLAY_ONLY		0x00
Packit 34410b
#define BTP_GAP_IOCAPA_DISPLAY_YESNO		0x01
Packit 34410b
#define BTP_GAP_IOCAPA_KEYBOARD_ONLY		0x02
Packit 34410b
#define BTP_GAP_IOCAPA_NO_INPUT_NO_OUTPUT	0x03
Packit 34410b
#define BTP_GAP_IOCAPA_KEYBOARD_DISPLAY		0x04
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_SET_IO_CAPA			0x10
Packit 34410b
struct btp_gap_set_io_capa_cp {
Packit 34410b
	uint8_t capa;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_PAIR				0x11
Packit 34410b
struct btp_gap_pair_cp {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_UNPAIR			0x12
Packit 34410b
struct btp_gap_unpair_cp {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_PASSKEY_ENTRY_RSP		0x13
Packit 34410b
struct btp_gap_passkey_entry_rsp_cp {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
	uint32_t passkey;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_OP_GAP_PASSKEY_CONFIRM_RSP		0x14
Packit 34410b
struct btp_gap_passkey_confirm_rsp_cp {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
	uint8_t match;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_NEW_SETTINGS			0x80
Packit 34410b
struct btp_new_settings_ev {
Packit 34410b
	uint32_t current_settings;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_DEVICE_FOUND_FLAG_RSSI	0x01
Packit 34410b
#define BTP_EV_GAP_DEVICE_FOUND_FLAG_AD		0x02
Packit 34410b
#define BTP_EV_GAP_DEVICE_FOUND_FLAG_SR		0x04
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_DEVICE_FOUND			0x81
Packit 34410b
struct btp_device_found_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
	int8_t rssi;
Packit 34410b
	uint8_t flags;
Packit 34410b
	uint16_t eir_len;
Packit 34410b
	uint8_t eir[0];
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_DEVICE_CONNECTED		0x82
Packit 34410b
struct btp_gap_device_connected_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_DEVICE_DISCONNECTED		0x83
Packit 34410b
struct btp_gap_device_disconnected_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_PASSKEY_DISPLAY		0x84
Packit 34410b
struct btp_gap_passkey_display_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
	uint32_t passkey;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_PASSKEY_REQUEST		0x85
Packit 34410b
struct btp_gap_passkey_req_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_PASSKEY_CONFIRM		0x86
Packit 34410b
struct btp_gap_passkey_confirm_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
	uint32_t passkey;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
#define BTP_EV_GAP_IDENTITY_RESOLVED		0x87
Packit 34410b
struct btp_gap_identity_resolved_ev {
Packit 34410b
	uint8_t address_type;
Packit 34410b
	bdaddr_t address;
Packit 34410b
	uint8_t identity_address_type;
Packit 34410b
	bdaddr_t identity_address;
Packit 34410b
} __packed;
Packit 34410b
Packit 34410b
struct btp;
Packit 34410b
Packit 34410b
typedef void (*btp_destroy_func_t)(void *user_data);
Packit 34410b
typedef void (*btp_disconnect_func_t)(struct btp *btp, void *user_data);
Packit 34410b
typedef void (*btp_cmd_func_t)(uint8_t index, const void *param,
Packit 34410b
					uint16_t length, void *user_data);
Packit 34410b
Packit 34410b
struct btp *btp_new(const char *path);
Packit 34410b
void btp_cleanup(struct btp *btp);
Packit 34410b
Packit 34410b
bool btp_set_disconnect_handler(struct btp *btp, btp_disconnect_func_t callback,
Packit 34410b
				void *user_data, btp_destroy_func_t destroy);
Packit 34410b
Packit 34410b
bool btp_send_error(struct btp *btp, uint8_t service, uint8_t index,
Packit 34410b
								uint8_t status);
Packit 34410b
bool btp_send(struct btp *btp, uint8_t service, uint8_t opcode, uint8_t index,
Packit 34410b
					uint16_t length, const void *param);
Packit 34410b
Packit 34410b
unsigned int btp_register(struct btp *btp, uint8_t service, uint8_t opcode,
Packit 34410b
				btp_cmd_func_t callback, void *user_data,
Packit 34410b
				btp_destroy_func_t destroy);
Packit 34410b
bool btp_unregister(struct btp *btp, unsigned int id);
Packit 34410b
void btp_unregister_service(struct btp *btp, uint8_t service);