Bluetooth: AVDTP: Module Initialization
- Data Structure Definition - Registration and Initialization Change-Id: Icca95ccbd2692a7d41fd41ef2c99e34761e864b3 Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
This commit is contained in:
parent
f976decdfa
commit
3afc05d816
5 changed files with 300 additions and 1 deletions
|
@ -467,6 +467,12 @@ config BLUETOOTH_HFP_HF
|
|||
help
|
||||
This option enables Bluetooth HF support
|
||||
|
||||
config BLUETOOTH_AVDTP
|
||||
bool "Bluetooth AVDTP protocol support [EXPERIMENTAL]"
|
||||
default n
|
||||
help
|
||||
This option enables Bluetooth AVDTP support
|
||||
|
||||
config BLUETOOTH_BREDR_NAME
|
||||
string "Bluetooth BR/EDR device name"
|
||||
default "Zephyr"
|
||||
|
|
|
@ -22,9 +22,11 @@ ifeq ($(CONFIG_BLUETOOTH_CONN),y)
|
|||
obj-y += smp_null.o
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_BLUETOOTH_BREDR) += keys_br.o l2cap_br.o
|
||||
obj-$(CONFIG_BLUETOOTH_BREDR) += keys_br.o l2cap_br.o avdtp.o
|
||||
|
||||
obj-$(CONFIG_BLUETOOTH_RFCOMM) += rfcomm.o
|
||||
|
||||
obj-$(CONFIG_BLUETOOTH_HFP_HF) += hfp_hf.o
|
||||
|
||||
obj-$(CONFIG_BLUETOOTH_AVDTP) += avdtp.o
|
||||
endif
|
||||
|
|
136
net/bluetooth/avdtp.c
Normal file
136
net/bluetooth/avdtp.c
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Audio Video Distribution Protocol
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <nanokernel.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <toolchain.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <atomic.h>
|
||||
#include <misc/byteorder.h>
|
||||
#include <misc/util.h>
|
||||
#include <misc/nano_work.h>
|
||||
|
||||
#include <bluetooth/log.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/l2cap.h>
|
||||
|
||||
#include "hci_core.h"
|
||||
#include "conn_internal.h"
|
||||
#include "l2cap_internal.h"
|
||||
#include "avdtp_internal.h"
|
||||
|
||||
#if !defined(CONFIG_BLUETOOTH_DEBUG_AVDTP)
|
||||
#undef BT_DBG
|
||||
#define BT_DBG(fmt, ...)
|
||||
#endif
|
||||
|
||||
/* TODO add config file*/
|
||||
#define CONFIG_BLUETOOTH_AVDTP_CONN CONFIG_BLUETOOTH_MAX_CONN
|
||||
|
||||
/* Pool for outgoing BR/EDR signaling packets, min MTU is 48 */
|
||||
static struct nano_fifo avdtp_sig;
|
||||
static NET_BUF_POOL(avdtp_sig_pool, CONFIG_BLUETOOTH_AVDTP_CONN,
|
||||
BT_AVDTP_BUF_SIZE(BT_AVDTP_MIN_MTU),
|
||||
&avdtp_sig, NULL, BT_BUF_USER_DATA_MIN);
|
||||
|
||||
static struct bt_avdtp bt_avdtp_pool[CONFIG_BLUETOOTH_AVDTP_CONN];
|
||||
|
||||
static struct bt_avdtp_event_cb *event_cb;
|
||||
|
||||
#define AVDTP_CHAN(_ch) CONTAINER_OF(_ch, struct bt_avdtp, br_chan.chan)
|
||||
|
||||
/* L2CAP Interface callbacks */
|
||||
void bt_avdtp_l2cap_connected(struct bt_l2cap_chan *chan)
|
||||
{
|
||||
BT_DBG("");
|
||||
}
|
||||
|
||||
void bt_avdtp_l2cap_disconnected(struct bt_l2cap_chan *chan)
|
||||
{
|
||||
BT_DBG("");
|
||||
}
|
||||
|
||||
void bt_avdtp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||
{
|
||||
BT_DBG("");
|
||||
}
|
||||
|
||||
int bt_avdtp_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
{
|
||||
int i;
|
||||
static struct bt_l2cap_chan_ops ops = {
|
||||
.connected = bt_avdtp_l2cap_connected,
|
||||
.disconnected = bt_avdtp_l2cap_disconnected,
|
||||
.recv = bt_avdtp_l2cap_recv,
|
||||
};
|
||||
|
||||
BT_DBG("conn %p, handle %u", conn, conn->handle);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_avdtp_pool); i++) {
|
||||
struct bt_avdtp *avdtp = &bt_avdtp_pool[i];
|
||||
|
||||
if (avdtp->br_chan.chan.conn) {
|
||||
continue;
|
||||
}
|
||||
|
||||
avdtp->br_chan.chan.ops = &ops;
|
||||
avdtp->br_chan.rx.mtu = BT_AVDTP_MAX_MTU;
|
||||
*chan = &avdtp->br_chan.chan;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Application will register its callback */
|
||||
int bt_avdtp_register(struct bt_avdtp_event_cb *cb)
|
||||
{
|
||||
BT_DBG("");
|
||||
|
||||
if (event_cb) {
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
event_cb = cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* init function */
|
||||
int bt_avdtp_init(void)
|
||||
{
|
||||
int err;
|
||||
static struct bt_l2cap_server avdtp_l2cap = {
|
||||
.psm = BT_L2CAP_PSM_AVDTP,
|
||||
.accept = bt_avdtp_l2cap_accept,
|
||||
};
|
||||
|
||||
BT_DBG("");
|
||||
|
||||
/* Memory Initialization */
|
||||
net_buf_pool_init(avdtp_sig_pool);
|
||||
|
||||
/* Register AVDTP PSM with L2CAP */
|
||||
err = bt_l2cap_br_server_register(&avdtp_l2cap);
|
||||
if (err < 0) {
|
||||
BT_ERR("AVDTP L2CAP Registration failed %d", err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
151
net/bluetooth/avdtp_internal.h
Normal file
151
net/bluetooth/avdtp_internal.h
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* avdtp_internal.h - avdtp handling
|
||||
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* @brief A2DP ROLE's */
|
||||
#define A2DP_SRC_ROLE 0x00
|
||||
#define A2DP_SNK_ROLE 0x01
|
||||
|
||||
/* @brief AVDTP Role */
|
||||
#define BT_AVDTP_INT 0x00
|
||||
#define BT_AVDTP_ACP 0x01
|
||||
|
||||
#define BT_L2CAP_PSM_AVDTP 0x0019
|
||||
|
||||
/* AVDTP SIGNAL HEADER - Packet Type*/
|
||||
#define BT_AVDTP_PACKET_TYPE_SINGLE 0x00
|
||||
#define BT_AVDTP_PACKET_TYPE_START 0x01
|
||||
#define BT_AVDTP_PACKET_TYPE_CONTINUE 0x02
|
||||
#define BT_AVDTP_PACKET_TYPE_END 0x03
|
||||
|
||||
/* AVDTP SIGNAL HEADER - MESSAGE TYPE */
|
||||
#define BT_AVDTP_MSG_TYPE_CMD 0x00
|
||||
#define BT_AVDTP_MSG_TYPE_GEN_REJECT 0x01
|
||||
#define BT_AVDTP_MSG_TYPE_ACCEPT 0x02
|
||||
#define BT_AVDTP_MSG_TYPE_REJECT 0x03
|
||||
|
||||
/* @brief AVDTP SIGNAL HEADER - Signal Identifier */
|
||||
#define BT_AVDTP_DISCOVER 0x01
|
||||
#define BT_AVDTP_GET_CAPABILITIES 0x02
|
||||
#define BT_AVDTP_SET_CONFIGURATION 0x03
|
||||
#define BT_AVDTP_GET_CONFIGURATION 0x04
|
||||
#define BT_AVDTP_RECONFIGURE 0x05
|
||||
#define BT_AVDTP_OPEN 0x06
|
||||
#define BT_AVDTP_START 0x07
|
||||
#define BT_AVDTP_CLOSE 0x08
|
||||
#define BT_AVDTP_SUSPEND 0x09
|
||||
#define BT_AVDTP_ABORT 0x0a
|
||||
#define BT_AVDTP_SECURITY_CONTROL 0x0b
|
||||
#define BT_AVDTP_GET_ALL_CAPABILITIES 0x0c
|
||||
#define BT_AVDTP_DELAYREPORT 0x0d
|
||||
|
||||
/* @brief AVDTP STATE */
|
||||
#define BT_AVDTP_STATE_IDLE 0x01
|
||||
#define BT_AVDTP_STATE_CONFIGURED 0x02
|
||||
#define BT_AVDTP_STATE_OPEN 0x03
|
||||
#define BT_AVDTP_STATE_STREAMING 0x04
|
||||
#define BT_AVDTP_STATE_CLOSING 0x05
|
||||
#define BT_AVDTP_STATE_ABORT 0x06
|
||||
#define BT_AVDTP_STATE_SIG_CONNECTED 0x07
|
||||
#define BT_AVDTP_STATE_INVALID 0x00
|
||||
|
||||
/* @brief AVDTP Media TYPE */
|
||||
#define BT_AVDTP_SERVICE_CAT_MEDIA_TRANSPORT 0x01
|
||||
#define BT_AVDTP_SERVICE_CAT_REPORTING 0x02
|
||||
#define BT_AVDTP_SERVICE_CAT_RECOVERY 0x03
|
||||
#define BT_AVDTP_SERVICE_CAT_CONTENT_PROTECTION 0x04
|
||||
#define BT_AVDTP_SERVICE_CAT_HDR_COMPRESSION 0x05
|
||||
#define BT_AVDTP_SERVICE_CAT_MULTIPLEXING 0x06
|
||||
#define BT_AVDTP_SERVICE_CAT_MEDIA_CODEC 0x07
|
||||
#define BT_AVDTP_SERVICE_CAT_DELAYREPORTING 0x08
|
||||
|
||||
/* AVDTP Error Codes */
|
||||
#define BT_AVDTP_SUCCESS 0x00
|
||||
#define BT_AVDTP_ERR_BAD_HDR_FORMAT 0x01
|
||||
#define BT_AVDTP_ERR_BAD_LENGTH 0x11
|
||||
#define BT_AVDTP_ERR_BAD_ACP_SEID 0x12
|
||||
#define BT_AVDTP_ERR_SEP_IN_USE 0x13
|
||||
#define BT_AVDTP_ERR_SEP_NOT_IN_USE 0x14
|
||||
#define BT_AVDTP_ERR_BAD_SERV_CATEGORY 0x17
|
||||
#define BT_AVDTP_ERR_BAD_PAYLOAD_FORMAT 0x18
|
||||
#define BT_AVDTP_ERR_NOT_SUPPORTED_COMMAND 0x19
|
||||
#define BT_AVDTP_ERR_INVALID_CAPABILITIES 0x1a
|
||||
#define BT_AVDTP_ERR_BAD_RECOVERY_TYPE 0x22
|
||||
#define BT_AVDTP_ERR_BAD_MEDIA_TRANSPORT_FORMAT 0x23
|
||||
#define BT_AVDTP_ERR_BAD_RECOVERY_FORMAT 0x25
|
||||
#define BT_AVDTP_ERR_BAD_ROHC_FORMAT 0x26
|
||||
#define BT_AVDTP_ERR_BAD_CP_FORMAT 0x27
|
||||
#define BT_AVDTP_ERR_BAD_MULTIPLEXING_FORMAT 0x28
|
||||
#define BT_AVDTP_ERR_UNSUPPORTED_CONFIGURAION 0x29
|
||||
#define BT_AVDTP_ERR_BAD_STATE 0x31
|
||||
|
||||
#define BT_AVDTP_MIN_MTU 48
|
||||
#define BT_AVDTP_MAX_MTU CONFIG_BLUETOOTH_L2CAP_IN_MTU
|
||||
|
||||
/* Helper to calculate needed outgoing buffer size. */
|
||||
#define BT_AVDTP_BUF_SIZE(mtu) (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
|
||||
sizeof(struct bt_hci_acl_hdr) + \
|
||||
sizeof(struct bt_l2cap_hdr) + \
|
||||
BT_AVDTP_SIG_HDR_LEN + (mtu))
|
||||
|
||||
struct bt_avdtp_single_sig_hdr {
|
||||
uint8_t hdr;
|
||||
uint8_t signal_id;
|
||||
} __packed;
|
||||
|
||||
#define BT_AVDTP_SIG_HDR_LEN sizeof(struct bt_avdtp_single_sig_hdr)
|
||||
|
||||
struct bt_avdtp_cfm_cb {
|
||||
/*
|
||||
* Discovery_cfm;
|
||||
* get_capabilities_cfm;
|
||||
* set_configuration_cfm;
|
||||
* open_cfm;
|
||||
* start_cfm;
|
||||
* suspend_cfm;
|
||||
* close_cfm;
|
||||
*/
|
||||
};
|
||||
|
||||
struct bt_avdtp_ind_cb {
|
||||
/*
|
||||
* discovery_ind;
|
||||
* get_capabilities_ind;
|
||||
* set_configuration_ind;
|
||||
* open_ind;
|
||||
* start_ind;
|
||||
* suspend_ind;
|
||||
* close_ind;
|
||||
*/
|
||||
};
|
||||
|
||||
struct bt_avdtp_event_cb {
|
||||
struct bt_avdtp_ind_cb *ind;
|
||||
struct bt_avdtp_cfm_cb *cfm;
|
||||
};
|
||||
|
||||
/** @brief Global AVDTP session structure. */
|
||||
struct bt_avdtp {
|
||||
struct bt_l2cap_br_chan br_chan;
|
||||
uint8_t state; /* current state of AVDTP*/
|
||||
};
|
||||
|
||||
/* Initialize AVDTP layer*/
|
||||
int bt_avdtp_init(void);
|
||||
|
||||
/* Application register with AVDTP layer */
|
||||
int bt_avdtp_register(struct bt_avdtp_event_cb *cb);
|
|
@ -35,6 +35,7 @@
|
|||
#include "hci_core.h"
|
||||
#include "conn_internal.h"
|
||||
#include "l2cap_internal.h"
|
||||
#include "avdtp_internal.h"
|
||||
#if defined(CONFIG_BLUETOOTH_RFCOMM)
|
||||
#include "rfcomm_internal.h"
|
||||
#endif
|
||||
|
@ -1625,4 +1626,7 @@ void bt_l2cap_br_init(void)
|
|||
#if defined(CONFIG_BLUETOOTH_RFCOMM)
|
||||
bt_rfcomm_init();
|
||||
#endif /* CONFIG_BLUETOOTH_RFCOMM */
|
||||
#if defined(CONFIG_BLUETOOTH_AVDTP)
|
||||
bt_avdtp_init();
|
||||
#endif /* CONFIG_BLUETOOTH_AVDTP */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue