feat(bt/bluedroid): Support OBEX over L2CAP
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bt_target.h"
|
||||
|
||||
#include "stack/obex_api.h"
|
||||
#include "obex_tl.h"
|
||||
#include "obex_tl_l2cap.h"
|
||||
|
||||
#if (OBEX_INCLUDED == TRUE)
|
||||
|
||||
#define OBEX_BT_HDR_MIN_OFFSET OBEX_TL_L2CAP_BT_HDR_MIN_OFFSET /* should set to max value of all transport layer */
|
||||
|
||||
#define OBEX_ROLE_CLIENT 0x01
|
||||
#define OBEX_ROLE_SERVER 0x02
|
||||
|
||||
/* OBEX connection state */
|
||||
#define OBEX_STATE_IDLE 0 /* No connection */
|
||||
#define OBEX_STATE_OPENING 1 /* Starting to open a connection */
|
||||
#define OBEX_STATE_OPENED 2 /* Connection opened */
|
||||
|
||||
/* Store 16 bits data in big endian format, not modify the p_buf */
|
||||
#define STORE16BE(p_buf, data) do { *p_buf = ((data)>>8)&0xff; \
|
||||
*(p_buf+1) = (data)&0xff;} while(0)
|
||||
|
||||
/* OBEX Connection Control block */
|
||||
typedef struct {
|
||||
tOBEX_MSG_CBACK *callback; /* Connection msg callback function */
|
||||
UINT16 tl_hdl; /* Transport layer non-zeros connection handle*/
|
||||
UINT16 tl_peer_mtu; /* Transport layer peer mtu */
|
||||
UINT16 tl_our_mtu; /* Transport layer our mtu */
|
||||
UINT8 tl_cong; /* 1 if transport layer congestion, otherwise 0 */
|
||||
UINT8 tl; /* OBEX_OVER_L2CAP or OBEX_OVER_RFCOMM */
|
||||
UINT8 allocated; /* 0, not allocated. index+1, otherwise. equal to api handle */
|
||||
UINT8 state; /* This OBEX connection state */
|
||||
UINT8 role; /* This OBEX connection role */
|
||||
} tOBEX_CCB;
|
||||
|
||||
/* OBEX Server Control block */
|
||||
typedef struct {
|
||||
tOBEX_MSG_CBACK *callback; /* Connection msg callback function */
|
||||
UINT16 tl_hdl; /* Transport layer non-zeros server handle*/
|
||||
UINT8 tl; /* OBEX_OVER_L2CAP or OBEX_OVER_RFCOMM */
|
||||
UINT8 allocated; /* 0, not allocated. index+1, otherwise. */
|
||||
} tOBEX_SCB;
|
||||
|
||||
/* OBEX Control block */
|
||||
typedef struct {
|
||||
tOBEX_CCB ccb[OBEX_MAX_CONNECTION]; /* connection control blocks */
|
||||
tOBEX_SCB scb[OBEX_MAX_SERVER]; /* server control blocks */
|
||||
tOBEX_TL_OPS *tl_ops[OBEX_NUM_TL]; /* transport operation function pointer */
|
||||
UINT8 trace_level; /* trace level */
|
||||
} tOBEX_CB;
|
||||
|
||||
#if OBEX_DYNAMIC_MEMORY == FALSE
|
||||
extern tOBEX_CB obex_cb;
|
||||
#else
|
||||
extern tOBEX_CB *obex_cb_ptr;
|
||||
#define obex_cb (*obex_cb_ptr)
|
||||
#endif
|
||||
|
||||
void obex_tl_l2cap_callback(tOBEX_TL_EVT evt, tOBEX_TL_MSG *msg);
|
||||
tOBEX_CCB *obex_allocate_ccb(void);
|
||||
tOBEX_SCB *obex_allocate_scb(void);
|
||||
void obex_free_ccb(tOBEX_CCB *p_ccb);
|
||||
void obex_free_scb(tOBEX_SCB *p_scb);
|
||||
|
||||
#endif /* #if (OBEX_INCLUDED == TRUE) */
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bt_target.h"
|
||||
|
||||
#if (OBEX_INCLUDED == TRUE)
|
||||
|
||||
/* Return code of obex_tl_send_data */
|
||||
#define OBEX_TL_FAILED FALSE
|
||||
#define OBEX_TL_SUCCESS TRUE
|
||||
#define OBEX_TL_CONGESTED 2
|
||||
|
||||
typedef enum {
|
||||
OBEX_TL_CONN_OPEN_EVT,
|
||||
OBEX_TL_CONN_INCOME_EVT,
|
||||
OBEX_TL_DIS_CONN_EVT,
|
||||
OBEX_TL_CONGEST_EVT,
|
||||
OBEX_TL_UNCONGEST_EVT,
|
||||
OBEX_TL_MTU_CHANGE_EVT,
|
||||
OBEX_TL_DATA_EVT
|
||||
} tOBEX_TL_EVT;
|
||||
|
||||
typedef union {
|
||||
/* general struct, used to retrieve handle */
|
||||
struct {
|
||||
UINT16 hdl;
|
||||
} any;
|
||||
|
||||
/* struct for OBEX_TL_CONN_OPEN_EVT */
|
||||
struct {
|
||||
UINT16 hdl;
|
||||
UINT16 peer_mtu;
|
||||
UINT16 our_mtu;
|
||||
} conn_open;
|
||||
|
||||
/* struct for OBEX_TL_CONN_INCOME_EVT */
|
||||
struct {
|
||||
UINT16 hdl;
|
||||
UINT16 peer_mtu;
|
||||
UINT16 our_mtu;
|
||||
UINT16 svr_hdl;
|
||||
} conn_income;
|
||||
|
||||
/* struct for OBEX_TL_MTU_CHANGE_EVT */
|
||||
struct {
|
||||
UINT16 hdl;
|
||||
UINT16 peer_mtu;
|
||||
UINT16 our_mtu;
|
||||
} mtu_chg;
|
||||
|
||||
/* struct for OBEX_TL_DATA_EVT */
|
||||
struct {
|
||||
UINT16 hdl;
|
||||
BT_HDR *p_buf;
|
||||
} data;
|
||||
} tOBEX_TL_MSG;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT16 psm; /* l2cap psm */
|
||||
UINT16 sec_mask; /* security mask */
|
||||
UINT16 pref_mtu; /* preferred mtu, limited by L2CAP_MTU_SIZE */
|
||||
BD_ADDR addr; /* peer bluetooth device address */
|
||||
} tOBEX_TL_L2CAP_SVR;
|
||||
|
||||
typedef union
|
||||
{
|
||||
tOBEX_TL_L2CAP_SVR l2cap;
|
||||
} tOBEX_TL_SVR_INFO;
|
||||
|
||||
typedef void (tOBEX_TL_CBACK)(tOBEX_TL_EVT evt, tOBEX_TL_MSG *msg);
|
||||
|
||||
typedef struct {
|
||||
void (*init)(tOBEX_TL_CBACK *callback);
|
||||
void (*deinit)(void);
|
||||
UINT16 (*connect)(tOBEX_TL_SVR_INFO *server);
|
||||
void (*disconnect)(UINT16 tl_hdl);
|
||||
UINT16 (*send)(UINT16 tl_hdl, BT_HDR *p_buf);
|
||||
UINT16 (*bind)(tOBEX_TL_SVR_INFO *server);
|
||||
void (*unbind)(UINT16 tl_hdl);
|
||||
} tOBEX_TL_OPS;
|
||||
|
||||
#endif /* #if (OBEX_INCLUDED == TRUE) */
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "obex_tl.h"
|
||||
|
||||
#if (OBEX_INCLUDED == TRUE)
|
||||
|
||||
#define OBEX_TL_L2CAP_BT_HDR_MIN_OFFSET 13 /* L2CAP_MIN_OFFSET */
|
||||
|
||||
tOBEX_TL_OPS *obex_tl_l2cap_ops_get(void);
|
||||
|
||||
#endif /* #if (OBEX_INCLUDED == TRUE) */
|
||||
Reference in New Issue
Block a user