shared/mcp: Add initial code for handling MCP

This adds initial code for Media Control Profile for Client Role.
This commit is contained in:
Abhay Maheta 2022-10-18 10:08:29 +05:30 committed by Luiz Augusto von Dentz
parent d3a204b8a2
commit 3973147aa8
4 changed files with 1546 additions and 0 deletions

View File

@ -231,6 +231,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \
src/shared/gap.h src/shared/gap.c \
src/shared/log.h src/shared/log.c \
src/shared/bap.h src/shared/bap.c src/shared/ascs.h \
src/shared/mcs.h src/shared/mcp.h src/shared/mcp.c \
src/shared/vcp.c src/shared/vcp.h \
src/shared/lc3.h src/shared/tty.h

1419
src/shared/mcp.c Normal file

File diff suppressed because it is too large Load Diff

61
src/shared/mcp.h Normal file
View File

@ -0,0 +1,61 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2020 Intel Corporation. All rights reserved.
*
*/
#include <stdbool.h>
#include <inttypes.h>
#ifndef __packed
#define __packed __attribute__((packed))
#endif
struct bt_mcp;
struct bt_mcp_db;
struct bt_mcp_session_info;
typedef void (*bt_mcp_debug_func_t)(const char *str, void *user_data);
typedef void (*bt_mcp_destroy_func_t)(void *user_data);
struct bt_mcp_event_callback {
void (*player_name)(struct bt_mcp *mcp, const uint8_t *value,
uint16_t length);
void (*track_changed)(struct bt_mcp *mcp);
void (*track_title)(struct bt_mcp *mcp, const uint8_t *value,
uint16_t length);
void (*track_duration)(struct bt_mcp *mcp, int32_t duration);
void (*track_position)(struct bt_mcp *mcp, int32_t position);
void (*playback_speed)(struct bt_mcp *mcp, int8_t speed);
void (*seeking_speed)(struct bt_mcp *mcp, int8_t speed);
void (*play_order)(struct bt_mcp *mcp, uint8_t order);
void (*play_order_supported)(struct bt_mcp *mcp,
uint16_t order_supported);
void (*media_state)(struct bt_mcp *mcp, uint8_t state);
void (*content_control_id)(struct bt_mcp *mcp, uint8_t cc_id);
};
void bt_mcp_set_event_callbacks(struct bt_mcp *mcp,
const struct bt_mcp_event_callback *cbs,
void *user_data);
bool bt_mcp_set_debug(struct bt_mcp *mcp, bt_mcp_debug_func_t cb,
void *user_data, bt_mcp_destroy_func_t destroy);
void bt_mcp_register(struct gatt_db *db);
bool bt_mcp_attach(struct bt_mcp *mcp, struct bt_gatt_client *client);
void bt_mcp_detach(struct bt_mcp *mcp);
struct bt_mcp *bt_mcp_new(struct gatt_db *ldb, struct gatt_db *rdb);
struct bt_mcp *bt_mcp_ref(struct bt_mcp *mcp);
void bt_mcp_unref(struct bt_mcp *mcp);
bool bt_mcp_set_user_data(struct bt_mcp *mcp, void *user_data);
void *bt_mcp_get_user_data(struct bt_mcp *mcp);
unsigned int bt_mcp_play(struct bt_mcp *mcp);
unsigned int bt_mcp_pause(struct bt_mcp *mcp);
unsigned int bt_mcp_stop(struct bt_mcp *mcp);

65
src/shared/mcs.h Normal file
View File

@ -0,0 +1,65 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2020 Intel Corporation. All rights reserved.
*
*/
/* MCP Media State */
#define BT_MCS_STATUS_INACTIVE 0x00
#define BT_MCS_STATUS_PLAYING 0x01
#define BT_MCS_STATUS_PAUSED 0x02
#define BT_MCS_STATUS_SEEKING 0x03
/* MCP Control Point Opcodes */
#define BT_MCS_CMD_PLAY 0x01
#define BT_MCS_CMD_PAUSE 0x02
#define BT_MCS_CMD_FAST_REWIND 0x03
#define BT_MCS_CMD_FAST_FORWARD 0x04
#define BT_MCS_CMD_STOP 0x05
#define BT_MCS_CMD_MOVE_RELATIVE 0x10
#define BT_MCS_CMD_PREV_SEGMENT 0x20
#define BT_MCS_CMD_NEXT_SEGMENT 0x21
#define BT_MCS_CMD_FIRST_SEGMENT 0x22
#define BT_MCS_CMD_LAST_SEGMENT 0x23
#define BT_MCS_CMD_GOTO_SEGMENT 0x24
#define BT_MCS_CMD_PREV_TRACK 0x30
#define BT_MCS_CMD_NEXT_TRACK 0x31
#define BT_MCS_CMD_FIRST_TRACK 0x32
#define BT_MCS_CMD_LAST_TRACK 0x33
#define BT_MCS_CMD_GOTO_TRACK 0x34
#define BT_MCS_CMD_PREV_GROUP 0x40
#define BT_MCS_CMD_NEXT_GROUP 0x41
#define BT_MCS_CMD_FIRST_GROUP 0x42
#define BT_MCS_CMD_LAST_GROUP 0x43
#define BT_MCS_CMD_GOTO_GROUP 0x44
/* MCP Control Point Opcodes Supported */
#define BT_MCS_CMD_PLAY_SUPPORTED 0x00000001
#define BT_MCS_CMD_PAUSE_SUPPORTED 0x00000002
#define BT_MCS_CMD_FAST_REWIND_SUPPORTED 0x00000004
#define BT_MCS_CMD_FAST_FORWARD_SUPPORTED 0x00000008
#define BT_MCS_CMD_STOP_SUPPORTED 0x00000010
#define BT_MCS_CMD_MOVE_RELATIVE_SUPPORTED 0x00000020
#define BT_MCS_CMD_PREV_SEGMENT_SUPPORTED 0x00000040
#define BT_MCS_CMD_NEXT_SEGMENT_SUPPORTED 0x00000080
#define BT_MCS_CMD_FIRST_SEGMENT_SUPPORTED 0x00000100
#define BT_MCS_CMD_LAST_SEGMENT_SUPPORTED 0x00000200
#define BT_MCS_CMD_GOTO_SEGMENT_SUPPORTED 0x00000400
#define BT_MCS_CMD_PREV_TRACK_SUPPORTED 0x00000800
#define BT_MCS_CMD_NEXT_TRACK_SUPPORTED 0x00001000
#define BT_MCS_CMD_FIRST_TRACK_SUPPORTED 0x00002000
#define BT_MCS_CMD_LAST_TRACK_SUPPORTED 0x00004000
#define BT_MCS_CMD_GOTO_TRACK_SUPPORTED 0x00008000
#define BT_MCS_CMD_PREV_GROUP_SUPPORTED 0x00010000
#define BT_MCS_CMD_NEXT_GROUP_SUPPORTED 0x00020000
#define BT_MCS_CMD_FIRST_GROUP_SUPPORTED 0x00040000
#define BT_MCS_CMD_LAST_GROUP_SUPPORTED 0x00080000
#define BT_MCS_CMD_GOTO_GROUP_SUPPORTED 0x00100000