From b6e5a07555c3759a213a0a154cec9d2e43da2f57 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Sat, 26 Sep 2020 16:39:28 -0700 Subject: [PATCH] Introduce pL2CA_Error_Cb L2CAP notifies users error in ConnectRsp and ConfigRsp through this callback function (not linked so far). Next step is we send success through pL2CA_ConnectCfm_Cb and pL2CA_ConfigCfm_Cb. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I4456487d36248408fc1c31403d107baef05e3646 --- stack/avct/avct_l2c.cc | 17 ++++++++--------- stack/avct/avct_l2c_br.cc | 17 ++++++++--------- stack/avdt/avdt_l2c.cc | 17 ++++++++--------- stack/bnep/bnep_main.cc | 3 ++- stack/gap/gap_conn.cc | 2 ++ stack/gatt/gatt_main.cc | 22 +++++++++++++--------- stack/hid/hidd_conn.cc | 6 ++++-- stack/hid/hidh_conn.cc | 4 +++- stack/include/l2c_api.h | 16 ++++++++++++++-- stack/include/l2cdefs.h | 5 +++++ stack/rfcomm/rfc_l2cap_if.cc | 1 + stack/sdp/sdp_main.cc | 2 ++ 12 files changed, 70 insertions(+), 42 deletions(-) diff --git a/stack/avct/avct_l2c.cc b/stack/avct/avct_l2c.cc index 06427d2f8..b2d60b41b 100644 --- a/stack/avct/avct_l2c.cc +++ b/stack/avct/avct_l2c.cc @@ -39,17 +39,16 @@ void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); void avct_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); void avct_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); +static void avct_on_l2cap_error(uint16_t lcid, uint16_t result); /* L2CAP callback function structure */ -const tL2CAP_APPL_INFO avct_l2c_appl = {avct_l2c_connect_ind_cback, - avct_l2c_connect_cfm_cback, - avct_l2c_config_ind_cback, - avct_l2c_config_cfm_cback, - avct_l2c_disconnect_ind_cback, - avct_l2c_data_ind_cback, - avct_l2c_congestion_ind_cback, - NULL, - /* tL2CA_TX_COMPLETE_CB */}; +const tL2CAP_APPL_INFO avct_l2c_appl = { + avct_l2c_connect_ind_cback, avct_l2c_connect_cfm_cback, + avct_l2c_config_ind_cback, avct_l2c_config_cfm_cback, + avct_l2c_disconnect_ind_cback, avct_l2c_data_ind_cback, + avct_l2c_congestion_ind_cback, NULL, + avct_on_l2cap_error, +}; /******************************************************************************* * diff --git a/stack/avct/avct_l2c_br.cc b/stack/avct/avct_l2c_br.cc index 96d413b0f..e7327010c 100644 --- a/stack/avct/avct_l2c_br.cc +++ b/stack/avct/avct_l2c_br.cc @@ -40,17 +40,16 @@ void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avct_l2c_br_disconnect_ind_cback(uint16_t lcid, bool ack_needed); void avct_l2c_br_congestion_ind_cback(uint16_t lcid, bool is_congested); void avct_l2c_br_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); +void avct_br_on_l2cap_error(uint16_t lcid, uint16_t result); /* L2CAP callback function structure */ -const tL2CAP_APPL_INFO avct_l2c_br_appl = {avct_l2c_br_connect_ind_cback, - avct_l2c_br_connect_cfm_cback, - avct_l2c_br_config_ind_cback, - avct_l2c_br_config_cfm_cback, - avct_l2c_br_disconnect_ind_cback, - avct_l2c_br_data_ind_cback, - avct_l2c_br_congestion_ind_cback, - NULL, - /* tL2CA_TX_COMPLETE_CB */}; +const tL2CAP_APPL_INFO avct_l2c_br_appl = { + avct_l2c_br_connect_ind_cback, avct_l2c_br_connect_cfm_cback, + avct_l2c_br_config_ind_cback, avct_l2c_br_config_cfm_cback, + avct_l2c_br_disconnect_ind_cback, avct_l2c_br_data_ind_cback, + avct_l2c_br_congestion_ind_cback, NULL, + avct_br_on_l2cap_error, +}; /******************************************************************************* * diff --git a/stack/avdt/avdt_l2c.cc b/stack/avdt/avdt_l2c.cc index e1e19b5e4..571f4ff5f 100644 --- a/stack/avdt/avdt_l2c.cc +++ b/stack/avdt/avdt_l2c.cc @@ -42,17 +42,16 @@ void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); +static void avdt_on_l2cap_error(uint16_t lcid, uint16_t result); /* L2CAP callback function structure */ -const tL2CAP_APPL_INFO avdt_l2c_appl = {avdt_l2c_connect_ind_cback, - avdt_l2c_connect_cfm_cback, - avdt_l2c_config_ind_cback, - avdt_l2c_config_cfm_cback, - avdt_l2c_disconnect_ind_cback, - avdt_l2c_data_ind_cback, - avdt_l2c_congestion_ind_cback, - NULL, - /* tL2CA_TX_COMPLETE_CB */}; +const tL2CAP_APPL_INFO avdt_l2c_appl = { + avdt_l2c_connect_ind_cback, avdt_l2c_connect_cfm_cback, + avdt_l2c_config_ind_cback, avdt_l2c_config_cfm_cback, + avdt_l2c_disconnect_ind_cback, avdt_l2c_data_ind_cback, + avdt_l2c_congestion_ind_cback, NULL, + avdt_on_l2cap_error, +}; /******************************************************************************* * diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc index 6681e092c..df0cbcda0 100644 --- a/stack/bnep/bnep_main.cc +++ b/stack/bnep/bnep_main.cc @@ -59,7 +59,7 @@ static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t result); static void bnep_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); static void bnep_congestion_ind(uint16_t lcid, bool is_congested); - +static void bnep_on_l2cap_error(uint16_t l2cap_cid, uint16_t result); /******************************************************************************* * * Function bnep_register_with_l2cap @@ -83,6 +83,7 @@ tBNEP_RESULT bnep_register_with_l2cap(void) { bnep_cb.reg_info.pL2CA_DisconnectInd_Cb = bnep_disconnect_ind; bnep_cb.reg_info.pL2CA_DataInd_Cb = bnep_data_ind; bnep_cb.reg_info.pL2CA_CongestionStatus_Cb = bnep_congestion_ind; + bnep_cb.reg_info.pL2CA_Error_Cb = bnep_on_l2cap_error; /* Now, register with L2CAP */ if (!L2CA_Register2(BT_PSM_BNEP, bnep_cb.reg_info, false /* enable_snoop */, diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index 5c2e8b61b..49b6af094 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -90,6 +90,7 @@ static void gap_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); static void gap_congestion_ind(uint16_t lcid, bool is_congested); static void gap_tx_complete_ind(uint16_t l2cap_cid, uint16_t sdu_sent); +static void gap_on_l2cap_error(uint16_t l2cap_cid, uint16_t result); static tGAP_CCB* gap_find_ccb_by_cid(uint16_t cid); static tGAP_CCB* gap_find_ccb_by_handle(uint16_t handle); static tGAP_CCB* gap_allocate_ccb(void); @@ -116,6 +117,7 @@ void gap_conn_init(void) { conn.reg_info.pL2CA_DataInd_Cb = gap_data_ind; conn.reg_info.pL2CA_CongestionStatus_Cb = gap_congestion_ind; conn.reg_info.pL2CA_TxComplete_Cb = gap_tx_complete_ind; + conn.reg_info.pL2CA_Error_Cb = gap_on_l2cap_error; } /******************************************************************************* diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index e41fffded..92261aea8 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -62,15 +62,19 @@ static void gatt_l2cif_disconnect(uint16_t l2cap_cid); static void gatt_l2cif_data_ind_cback(uint16_t l2cap_cid, BT_HDR* p_msg); static void gatt_send_conn_cback(tGATT_TCB* p_tcb); static void gatt_l2cif_congest_cback(uint16_t cid, bool congested); - -static const tL2CAP_APPL_INFO dyn_info = {gatt_l2cif_connect_ind_cback, - gatt_l2cif_connect_cfm_cback, - gatt_l2cif_config_ind_cback, - gatt_l2cif_config_cfm_cback, - gatt_l2cif_disconnect_ind_cback, - gatt_l2cif_data_ind_cback, - gatt_l2cif_congest_cback, - NULL}; +static void gatt_on_l2cap_error(uint16_t lcid, uint16_t result); + +static const tL2CAP_APPL_INFO dyn_info = { + gatt_l2cif_connect_ind_cback, + gatt_l2cif_connect_cfm_cback, + gatt_l2cif_config_ind_cback, + gatt_l2cif_config_cfm_cback, + gatt_l2cif_disconnect_ind_cback, + gatt_l2cif_data_ind_cback, + gatt_l2cif_congest_cback, + NULL, + gatt_on_l2cap_error, +}; tGATT_CB gatt_cb; diff --git a/stack/hid/hidd_conn.cc b/stack/hid/hidd_conn.cc index d34c9c327..404d25a1c 100644 --- a/stack/hid/hidd_conn.cc +++ b/stack/hid/hidd_conn.cc @@ -48,12 +48,14 @@ static void hidd_l2cif_disconnect_ind(uint16_t cid, bool ack_needed); static void hidd_l2cif_disconnect(uint16_t cid); static void hidd_l2cif_data_ind(uint16_t cid, BT_HDR* p_msg); static void hidd_l2cif_cong_ind(uint16_t cid, bool congested); - +static void hidd_on_l2cap_error(uint16_t lcid, uint16_t result); static const tL2CAP_APPL_INFO dev_reg_info = { hidd_l2cif_connect_ind, hidd_l2cif_connect_cfm, hidd_l2cif_config_ind, hidd_l2cif_config_cfm, hidd_l2cif_disconnect_ind, hidd_l2cif_data_ind, - hidd_l2cif_cong_ind, NULL}; + hidd_l2cif_cong_ind, NULL, + hidd_on_l2cap_error, +}; /******************************************************************************* * diff --git a/stack/hid/hidh_conn.cc b/stack/hid/hidh_conn.cc index 0b4518ccd..741b68659 100644 --- a/stack/hid/hidh_conn.cc +++ b/stack/hid/hidh_conn.cc @@ -57,13 +57,15 @@ static void hidh_l2cif_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); static void hidh_l2cif_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); static void hidh_l2cif_disconnect(uint16_t l2cap_cid); static void hidh_l2cif_cong_ind(uint16_t l2cap_cid, bool congested); +static void hidh_on_l2cap_error(uint16_t l2cap_cid, uint16_t result); static const tL2CAP_APPL_INFO hst_reg_info = { hidh_l2cif_connect_ind, hidh_l2cif_connect_cfm, hidh_l2cif_config_ind, hidh_l2cif_config_cfm, hidh_l2cif_disconnect_ind, hidh_l2cif_data_ind, hidh_l2cif_cong_ind, NULL, - /* tL2CA_TX_COMPLETE_CB */}; + hidh_on_l2cap_error, +}; /******************************************************************************* * diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index c04b72ddd..becd7cacd 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -183,7 +183,8 @@ typedef void(tL2CA_CONNECT_IND_CB)(const RawAddress&, uint16_t, uint16_t, /* Connection confirmation callback prototype. Parameters are * Local CID - * Result - 0 = connected, non-zero means failure reason + * Result - 0 = connected + * If there is an error, tL2CA_ERROR_CB is invoked */ typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, uint16_t); @@ -195,7 +196,8 @@ typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*); /* Configuration confirm callback prototype. Parameters are * Local CID assigned to the connection - * Config result (L2CA_CONN_OK, ...) + * Config result (L2CA_CONN_OK) + * If there is an error, tL2CA_ERROR_CB is invoked */ typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, uint16_t); @@ -228,6 +230,15 @@ typedef void(tL2CA_CONGESTION_STATUS_CB)(uint16_t, bool); */ typedef void(tL2CA_TX_COMPLETE_CB)(uint16_t, uint16_t); +/* + * Notify the user when the remote send error result on ConnectRsp or ConfigRsp + * The parameters are: + * Local CID + * Error type (L2CAP_CONN_OTHER_ERROR for ConnectRsp, + * L2CAP_CFG_FAILED_NO_REASON for ConfigRsp) + */ +typedef void(tL2CA_ERROR_CB)(uint16_t, uint16_t); + /* Define the structure that applications use to register with * L2CAP. This structure includes callback functions. All functions * MUST be provided, with the exception of the "connect pending" @@ -242,6 +253,7 @@ typedef struct { tL2CA_DATA_IND_CB* pL2CA_DataInd_Cb; tL2CA_CONGESTION_STATUS_CB* pL2CA_CongestionStatus_Cb; tL2CA_TX_COMPLETE_CB* pL2CA_TxComplete_Cb; + tL2CA_ERROR_CB* pL2CA_Error_Cb; } tL2CAP_APPL_INFO; /* Define the structure that applications use to create or accept diff --git a/stack/include/l2cdefs.h b/stack/include/l2cdefs.h index 8ed021888..14a55fcba 100644 --- a/stack/include/l2cdefs.h +++ b/stack/include/l2cdefs.h @@ -93,6 +93,7 @@ #define L2CAP_CONN_NO_PSM 2 #define L2CAP_CONN_SECURITY_BLOCK 3 #define L2CAP_CONN_NO_RESOURCES 4 +#define L2CAP_CONN_OTHER_ERROR 5 #define L2CAP_CONN_TIMEOUT 0xEEEE /* Add a couple of our own for internal use */ #define L2CAP_CONN_NO_LINK 255 @@ -157,6 +158,10 @@ typedef uint8_t tL2CAP_LE_RESULT_CODE; #define L2CAP_CFG_UNKNOWN_OPTIONS 3 #define L2CAP_CFG_PENDING 4 +static_assert(L2CAP_CONN_OTHER_ERROR != L2CAP_CFG_FAILED_NO_REASON, + "Different error code should be provided for Connect error and " + "Config error"); + /* Define the L2CAP configuration option types */ #define L2CAP_CFG_TYPE_MTU 0x01 diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc index 9b7da9dbe..88321faa4 100644 --- a/stack/rfcomm/rfc_l2cap_if.cc +++ b/stack/rfcomm/rfc_l2cap_if.cc @@ -69,6 +69,7 @@ void rfcomm_l2cap_if_init(void) { p_l2c->pL2CA_DataInd_Cb = RFCOMM_BufDataInd; p_l2c->pL2CA_CongestionStatus_Cb = RFCOMM_CongestionStatusInd; p_l2c->pL2CA_TxComplete_Cb = NULL; + p_l2c->pL2CA_Error_Cb = rfc_on_l2cap_error; L2CA_Register(BT_PSM_RFCOMM, rfc_cb.rfc.reg_info, true /* enable_snoop */, nullptr, L2CAP_MTU_SIZE, 0); diff --git a/stack/sdp/sdp_main.cc b/stack/sdp/sdp_main.cc index 0a38f33be..cb6a46121 100644 --- a/stack/sdp/sdp_main.cc +++ b/stack/sdp/sdp_main.cc @@ -52,6 +52,7 @@ static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); static void sdp_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); static void sdp_connect_cfm(uint16_t l2cap_cid, uint16_t result); +static void sdp_on_l2cap_error(uint16_t l2cap_cid, uint16_t result); /******************************************************************************* * @@ -85,6 +86,7 @@ void sdp_init(void) { sdp_cb.reg_info.pL2CA_ConfigCfm_Cb = sdp_config_cfm; sdp_cb.reg_info.pL2CA_DisconnectInd_Cb = sdp_disconnect_ind; sdp_cb.reg_info.pL2CA_DataInd_Cb = sdp_data_ind; + sdp_cb.reg_info.pL2CA_Error_Cb = sdp_on_l2cap_error; /* Now, register with L2CAP */ if (!L2CA_Register2(SDP_PSM, sdp_cb.reg_info, true /* enable_snoop */, -- 2.11.0