Skip to content

Commit

Permalink
bt: Added esp_spp_enhance_init() API to indicate whether to enable L2…
Browse files Browse the repository at this point in the history
…CAP ERTM
  • Loading branch information
xiongweichao authored and espressif-bot committed Dec 7, 2022
1 parent 6d57e78 commit c2c9b09
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 50 deletions.
14 changes: 13 additions & 1 deletion components/bt/host/bluedroid/api/esp_spp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ esp_err_t esp_spp_register_callback(esp_spp_cb_t callback)


esp_err_t esp_spp_init(esp_spp_mode_t mode)
{
esp_spp_cfg_t bt_spp_cfg = {
.mode = mode,
.enable_l2cap_ertm = true,
};

return esp_spp_enhanced_init(&bt_spp_cfg);
}

esp_err_t esp_spp_enhanced_init(const esp_spp_cfg_t *cfg)
{
btc_msg_t msg;
btc_spp_args_t arg;
Expand All @@ -43,7 +53,9 @@ esp_err_t esp_spp_init(esp_spp_mode_t mode)
msg.pid = BTC_PID_SPP;
msg.act = BTC_SPP_ACT_INIT;

arg.init.mode = mode;
arg.init.mode = cfg->mode;
arg.init.enable_l2cap_ertm = cfg->enable_l2cap_ertm;

return (btc_transfer_context(&msg, &arg, sizeof(btc_spp_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

Expand Down
76 changes: 55 additions & 21 deletions components/bt/host/bluedroid/api/include/api/esp_spp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
extern "C" {
#endif

typedef enum {
ESP_SPP_SUCCESS = 0, /*!< Successful operation. */
ESP_SPP_FAILURE, /*!< Generic failure. */
ESP_SPP_BUSY, /*!< Temporarily can not handle this request. */
ESP_SPP_NO_DATA, /*!< No data */
ESP_SPP_NO_RESOURCE, /*!< No more resource */
ESP_SPP_NEED_INIT, /*!< SPP module shall init first */
ESP_SPP_NEED_DEINIT, /*!< SPP module shall deinit first */
ESP_SPP_NO_CONNECTION, /*!< Connection may have been closed */
ESP_SPP_NO_SERVER, /*!< No SPP server */
} esp_spp_status_t;
#define ESP_SPP_MAX_MTU (3*330) /*!< SPP max MTU */
#define ESP_SPP_MAX_SCN 31 /*!< SPP max SCN */

/**
* @brief SPP default configuration
*/
#define BT_SPP_DEFAULT_CONFIG() { \
.mode = ESP_SPP_MODE_VFS, \
.enable_l2cap_ertm = true, \
}

/* Security Setting Mask
Use these three mask mode:
Expand All @@ -41,6 +40,18 @@ Use these three mask mode:
#define ESP_SPP_SEC_IN_16_DIGITS 0x4000 /*!< Min 16 digit for pin code relate to BTA_SEC_IN_16_DIGITS in bta/bta_api.h*/
typedef uint16_t esp_spp_sec_t;

typedef enum {
ESP_SPP_SUCCESS = 0, /*!< Successful operation. */
ESP_SPP_FAILURE, /*!< Generic failure. */
ESP_SPP_BUSY, /*!< Temporarily can not handle this request. */
ESP_SPP_NO_DATA, /*!< No data */
ESP_SPP_NO_RESOURCE, /*!< No more resource */
ESP_SPP_NEED_INIT, /*!< SPP module shall init first */
ESP_SPP_NEED_DEINIT, /*!< SPP module shall deinit first */
ESP_SPP_NO_CONNECTION, /*!< Connection may have been closed */
ESP_SPP_NO_SERVER, /*!< No SPP server */
} esp_spp_status_t;

typedef enum {
ESP_SPP_ROLE_MASTER = 0, /*!< Role: master */
ESP_SPP_ROLE_SLAVE = 1, /*!< Role: slave */
Expand All @@ -51,8 +62,14 @@ typedef enum {
ESP_SPP_MODE_VFS = 1, /*!< Use VFS to write/read data */
} esp_spp_mode_t;

#define ESP_SPP_MAX_MTU (3*330) /*!< SPP max MTU */
#define ESP_SPP_MAX_SCN 31 /*!< SPP max SCN */
/**
* @brief SPP configuration parameters
*/
typedef struct {
esp_spp_mode_t mode; /*!< Choose the mode of SPP, ESP_SPP_MODE_CB or ESP_SPP_MODE_VFS. */
bool enable_l2cap_ertm; /*!< Enable/disable Logical Link Control and Adaptation Layer Protocol enhanced retransmission mode. */
} esp_spp_cfg_t;

/**
* @brief SPP callback function events
*/
Expand Down Expand Up @@ -221,14 +238,31 @@ esp_err_t esp_spp_register_callback(esp_spp_cb_t callback);
* - ESP_OK: success
* - other: failed
*/
esp_err_t esp_spp_init(esp_spp_mode_t mode);
esp_err_t esp_spp_init(esp_spp_mode_t mode) __attribute__((deprecated("Please use esp_spp_enhanced_init")));


/**
* @brief This function is called to init SPP module.
* When the operation is completed, the callback function will be called with ESP_SPP_INIT_EVT.
* This function should be called after esp_bluedroid_enable() completes successfully.
*
* @param[in] cfg: SPP configuration.
*
* @note The member variable enable_l2cap_etrm in esp_spp_cfg_t can affect all L2CAP channel
* configurations of the upper layer RFCOMM protocol.
*
* @return
* - ESP_OK: success
* - other: failed
*/
esp_err_t esp_spp_enhanced_init(const esp_spp_cfg_t *cfg);

/**
* @brief This function is called to uninit SPP module.
* The operation will close all active SPP connection first, then the callback function will be called
* with ESP_SPP_CLOSE_EVT, and the number of ESP_SPP_CLOSE_EVT is equal to the number of connection.
* When the operation is completed, the callback function will be called with ESP_SPP_UNINIT_EVT.
* This function should be called after esp_spp_init() completes successfully.
* This function should be called after esp_spp_init()/esp_spp_enhanced_init() completes successfully.
*
* @return
* - ESP_OK: success
Expand All @@ -240,7 +274,7 @@ esp_err_t esp_spp_deinit(void);
/**
* @brief This function is called to performs service discovery for the services provided by the given peer device.
* When the operation is completed, the callback function will be called with ESP_SPP_DISCOVERY_COMP_EVT.
* This function must be called after esp_spp_init() successful and before esp_spp_deinit().
* This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit().
*
* @param[in] bd_addr: Remote device bluetooth device address.
*
Expand All @@ -254,7 +288,7 @@ esp_err_t esp_spp_start_discovery(esp_bd_addr_t bd_addr);
* @brief This function makes an SPP connection to a remote BD Address.
* When the connection is initiated or failed to initiate, the callback is called with ESP_SPP_CL_INIT_EVT.
* When the connection is established or failed, the callback is called with ESP_SPP_OPEN_EVT.
* This function must be called after esp_spp_init() successful and before esp_spp_deinit().
* This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit().
*
* @param[in] sec_mask: Security Setting Mask. Suggest to use ESP_SPP_SEC_NONE, ESP_SPP_SEC_AUTHORIZE or ESP_SPP_SEC_AUTHENTICATE only.
* @param[in] role: Master or slave.
Expand All @@ -270,7 +304,7 @@ esp_err_t esp_spp_connect(esp_spp_sec_t sec_mask, esp_spp_role_t role, uint8_t r
/**
* @brief This function closes an SPP connection.
* When the operation is completed, the callback function will be called with ESP_SPP_CLOSE_EVT.
* This function must be called after esp_spp_init() successful and before esp_spp_deinit().
* This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit().
*
* @param[in] handle: The connection handle.
*
Expand All @@ -285,7 +319,7 @@ esp_err_t esp_spp_disconnect(uint32_t handle);
* SPP connection request from a remote Bluetooth device.
* When the server is started successfully, the callback is called with ESP_SPP_START_EVT.
* When the connection is established, the callback is called with ESP_SPP_SRV_OPEN_EVT.
* This function must be called after esp_spp_init() successful and before esp_spp_deinit().
* This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit().
*
* @param[in] sec_mask: Security Setting Mask. Suggest to use ESP_SPP_SEC_NONE, ESP_SPP_SEC_AUTHORIZE or ESP_SPP_SEC_AUTHENTICATE only.
* @param[in] role: Master or slave.
Expand All @@ -304,7 +338,7 @@ esp_err_t esp_spp_start_srv(esp_spp_sec_t sec_mask, esp_spp_role_t role, uint8_t
* The operation will close all active SPP connection first, then the callback function will be called
* with ESP_SPP_CLOSE_EVT, and the number of ESP_SPP_CLOSE_EVT is equal to the number of connection.
* When the operation is completed, the callback is called with ESP_SPP_SRV_STOP_EVT.
* This function must be called after esp_spp_init() successful and before esp_spp_deinit().
* This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit().
*
* @return
* - ESP_OK: success
Expand All @@ -318,7 +352,7 @@ esp_err_t esp_spp_stop_srv(void);
* The operation will close all active SPP connection first on the specific SPP server, then the callback function will be called
* with ESP_SPP_CLOSE_EVT, and the number of ESP_SPP_CLOSE_EVT is equal to the number of connection.
* When the operation is completed, the callback is called with ESP_SPP_SRV_STOP_EVT.
* This function must be called after esp_spp_init() successful and before esp_spp_deinit().
* This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit().
*
* @param[in] scn: Server channel number.
*
Expand Down
13 changes: 13 additions & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_jv_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,19 @@ extern tBTA_JV_STATUS BTA_JvL2capWriteFixed(UINT16 channel, BD_ADDR *addr, UINT3
#endif /* BTA_JV_L2CAP_INCLUDED */

#if BTA_JV_RFCOMM_INCLUDED
/*******************************************************************************
**
** Function BTA_JvRfcommConfig
**
** Description This function is to configure RFCOMM.
**
**
** Returns BTA_JV_SUCCESS, if the request is being processed.
** BTA_JV_FAILURE, otherwise.
**
*******************************************************************************/
extern tBTA_JV_STATUS BTA_JvRfcommConfig(BOOLEAN enable_l2cap_ertm);

/*******************************************************************************
**
** Function BTA_JvRfcommConnect
Expand Down
16 changes: 16 additions & 0 deletions components/bt/host/bluedroid/bta/jv/bta_jv_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,22 @@ static void bta_jv_port_event_cl_cback(UINT32 code, UINT16 port_handle)
}
}

/*******************************************************************************
**
** Function bta_jv_rfcomm_config
**
** Description Configure RFCOMM
**
** Returns void
**
*******************************************************************************/
void bta_jv_rfcomm_config(tBTA_JV_MSG *p_data)
{
APPL_TRACE_DEBUG("%s enable_l2cap_ertm:%d", __func__, p_data->rfcomm_config.enable_l2cap_ertm);

PORT_SetL2capErtm(p_data->rfcomm_config.enable_l2cap_ertm);
}

/*******************************************************************************
**
** Function bta_jv_rfcomm_connect
Expand Down
27 changes: 27 additions & 0 deletions components/bt/host/bluedroid/bta/jv/bta_jv_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,33 @@ tBTA_JV_STATUS BTA_JvL2capWriteFixed(UINT16 channel, BD_ADDR *addr, UINT32 req_i
#endif /* BTA_JV_L2CAP_INCLUDED */

#if BTA_JV_RFCOMM_INCLUDED
/*******************************************************************************
**
** Function BTA_JvRfcommConfig
**
** Description This function is to configure RFCOMM.
**
** Returns BTA_JV_SUCCESS, if the request is being processed.
** BTA_JV_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommConfig(BOOLEAN enable_l2cap_ertm)
{
tBTA_JV_STATUS status = BTA_JV_FAILURE;
tBTA_JV_API_RFCOMM_CONFIG *p_msg;

APPL_TRACE_API( "%s", __func__);

if ((p_msg = (tBTA_JV_API_RFCOMM_CONFIG *)osi_malloc(sizeof(tBTA_JV_API_RFCOMM_CONFIG))) != NULL) {
p_msg->hdr.event = BTA_JV_API_RFCOMM_CONFIG_EVT;
p_msg->enable_l2cap_ertm = enable_l2cap_ertm;
bta_sys_sendmsg(p_msg);
status = BTA_JV_SUCCESS;
}

return (status);
}

/*******************************************************************************
**
** Function BTA_JvRfcommConnect
Expand Down
3 changes: 2 additions & 1 deletion components/bt/host/bluedroid/bta/jv/bta_jv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ const tBTA_JV_ACTION bta_jv_action[] = {
bta_jv_l2cap_write, /* BTA_JV_API_L2CAP_WRITE_EVT */
#endif /* BTA_JV_L2CAP_INCLUDED */
#if BTA_JV_RFCOMM_INCLUDED
bta_jv_rfcomm_config, /* BTA_JV_API_RFCOMM_CONFIG_EVT */
bta_jv_rfcomm_connect, /* BTA_JV_API_RFCOMM_CONNECT_EVT */
bta_jv_rfcomm_close, /* BTA_JV_API_RFCOMM_CLOSE_EVT */
bta_jv_rfcomm_start_server, /* BTA_JV_API_RFCOMM_START_SERVER_EVT */
bta_jv_rfcomm_stop_server, /* BTA_JV_API_RFCOMM_STOP_SERVER_EVT */
bta_jv_rfcomm_read, /* BTA_JV_API_RFCOMM_READ_EVT */
bta_jv_rfcomm_write, /* BTA_JV_API_RFCOMM_WRITE_EVT */
bta_jv_rfcomm_flow_control, /* BTA_JV_API_RFCOMM_FLOW_CONTROL_EVT */
#endif /* BTA_JV_RFCOMM_INCLUDED */
#endif /* BTA_JV_RFCOMM_INCLUDED */
bta_jv_set_pm_profile, /* BTA_JV_API_SET_PM_PROFILE_EVT */
bta_jv_change_pm_state, /* BTA_JV_API_PM_STATE_CHANGE_EVT */
#if BTA_JV_L2CAP_INCLUDED
Expand Down
11 changes: 10 additions & 1 deletion components/bt/host/bluedroid/bta/jv/include/bta_jv_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum {
BTA_JV_API_L2CAP_WRITE_EVT,
#endif /* BTA_JV_L2CAP_INCLUDED */
#if BTA_JV_RFCOMM_INCLUDED
BTA_JV_API_RFCOMM_CONFIG_EVT,
BTA_JV_API_RFCOMM_CONNECT_EVT,
BTA_JV_API_RFCOMM_CLOSE_EVT,
BTA_JV_API_RFCOMM_START_SERVER_EVT,
Expand All @@ -83,7 +84,7 @@ enum {

/* data type for BTA_JV_API_ENABLE_EVT */
typedef struct {
BT_HDR hdr;
BT_HDR hdr;
tBTA_JV_DM_CBACK *p_cback;
} tBTA_JV_API_ENABLE;

Expand Down Expand Up @@ -257,6 +258,12 @@ typedef struct {
#endif /* BTA_JV_L2CAP_INCLUDED */

#if BTA_JV_RFCOMM_INCLUDED
/* data type for BTA_JV_API_RFCOMM_CONFIG_EVT */
typedef struct {
BT_HDR hdr;
BOOLEAN enable_l2cap_ertm;
} tBTA_JV_API_RFCOMM_CONFIG;

/* data type for BTA_JV_API_RFCOMM_CONNECT_EVT */
typedef struct {
BT_HDR hdr;
Expand Down Expand Up @@ -392,6 +399,7 @@ typedef union {
tBTA_JV_API_L2CAP_WRITE_FIXED l2cap_write_fixed;
#endif /* BTA_JV_L2CAP_INCLUDED */
#if BTA_JV_RFCOMM_INCLUDED
tBTA_JV_API_RFCOMM_CONFIG rfcomm_config;
tBTA_JV_API_RFCOMM_CONNECT rfcomm_connect;
tBTA_JV_API_RFCOMM_READ rfcomm_read;
tBTA_JV_API_RFCOMM_WRITE rfcomm_write;
Expand Down Expand Up @@ -463,6 +471,7 @@ extern void bta_jv_l2cap_read (tBTA_JV_MSG *p_data);
extern void bta_jv_l2cap_write (tBTA_JV_MSG *p_data);
#endif /* BTA_JV_L2CAP_INCLUDED */
#if BTA_JV_RFCOMM_INCLUDED
extern void bta_jv_rfcomm_config (tBTA_JV_MSG *p_data);
extern void bta_jv_rfcomm_connect (tBTA_JV_MSG *p_data);
extern void bta_jv_rfcomm_close (tBTA_JV_MSG *p_data);
extern void bta_jv_rfcomm_start_server (tBTA_JV_MSG *p_data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef union {
//BTC_SPP_ACT_INIT
struct init_arg {
esp_spp_mode_t mode;
bool enable_l2cap_ertm;
} init;
//BTC_SPP_ACT_UNINIT
struct uninit_arg {
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ static void btc_spp_init(btc_spp_args_t *arg)
spp_local_param.spp_mode = arg->init.mode;
spp_local_param.spp_slot_id = 0;
BTA_JvEnable((tBTA_JV_DM_CBACK *)btc_spp_dm_inter_cb);
BTA_JvRfcommConfig(arg->init.enable_l2cap_ertm);
} while (0);

if (ret != ESP_SPP_SUCCESS) {
Expand Down
11 changes: 11 additions & 0 deletions components/bt/host/bluedroid/stack/include/stack/port_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ extern UINT8 PORT_SetTraceLevel (UINT8 new_level);
*******************************************************************************/
extern const char *PORT_GetResultString (const uint8_t result_code);

/*******************************************************************************
**
** Function PORT_SetL2capErtm
**
** Description This function sets whether RFCOMM uses L2CAP ERTM.
**
** Returns void
**
*******************************************************************************/
extern void PORT_SetL2capErtm (BOOLEAN enable_l2cap_ertm);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ typedef struct t_port_info tPORT;
typedef struct {
tPORT port[MAX_RFC_PORTS]; /* Port info pool */
tRFC_MCB rfc_mcb[MAX_BD_CONNECTIONS]; /* RFCOMM bd_connections pool */
BOOLEAN enable_l2cap_ertm; /* enable/disable l2cap ertm */
} tPORT_CB;

#ifdef __cplusplus
Expand Down
14 changes: 14 additions & 0 deletions components/bt/host/bluedroid/stack/rfcomm/port_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1866,4 +1866,18 @@ const char *PORT_GetResultString (const uint8_t result_code)
return result_code_strings[result_code];
}

/*******************************************************************************
**
** Function PORT_SetL2capErtm
**
** Description This function sets whether RFCOMM uses L2CAP ERTM.
**
** Returns void
**
*******************************************************************************/
void PORT_SetL2capErtm (BOOLEAN enable_l2cap_ertm)
{
rfc_cb.port.enable_l2cap_ertm = enable_l2cap_ertm;
}

#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
Loading

0 comments on commit c2c9b09

Please sign in to comment.