@@ -2034,6 +2034,98 @@ ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
20342034 }
20352035}
20362036
2037+ int ble_gatts_pending_req_auth (uint16_t conn_handle , uint16_t attr_handle ,
2038+ int authorize )
2039+ {
2040+ struct pending_attr * attr ;
2041+ struct pending_attr * pend_attr ;
2042+ ble_att_svr_access_fn * access_cb ;
2043+ int rc ;
2044+ uint8_t att_err = 0 ;
2045+ struct os_mbuf * txom ;
2046+ struct ble_att_prep_write_cmd * req ;
2047+
2048+ /* Silence warnings */
2049+ rc = 0 ;
2050+ pend_attr = NULL ;
2051+ txom = NULL ;
2052+
2053+ ble_hs_lock ();
2054+ SLIST_FOREACH (attr , & pending_attr_list , next ) {
2055+ if (attr -> conn_handle == conn_handle &&
2056+ attr -> entry -> ha_handle_id == attr_handle ) {
2057+ pend_attr = attr ;
2058+ SLIST_REMOVE (& pending_attr_list , attr , pending_attr , next );
2059+ }
2060+ }
2061+ ble_hs_unlock ();
2062+
2063+ if (!pend_attr ) {
2064+ /* No matching attribute was found on pending_attr_list */
2065+ return BLE_HS_ENOENT ;
2066+ }
2067+
2068+ if (pend_attr -> att_opcode == BLE_ATT_OP_WRITE_REQ ) {
2069+ rc = ble_att_svr_build_write_rsp (& pend_attr -> om , & txom , & att_err );
2070+ if (rc != 0 ) {
2071+ goto done ;
2072+ }
2073+ }
2074+
2075+ if (!authorize ) {
2076+ att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHOR ;
2077+ rc = BLE_HS_EAUTHOR ;
2078+ goto done ;
2079+ }
2080+
2081+ /* Prepare write request */
2082+ if (pend_attr -> att_opcode == BLE_ATT_OP_PREP_WRITE_REQ ) {
2083+ req = (struct ble_att_prep_write_cmd * )(pend_attr )-> om -> om_data ;
2084+ ble_hs_lock ();
2085+ rc = ble_att_svr_insert_prep_entry (conn_handle ,
2086+ le16toh (req -> bapc_handle ),
2087+ le16toh (req -> bapc_offset ),
2088+ pend_attr -> om , & att_err );
2089+ ble_hs_unlock ();
2090+ if (rc != 0 ) {
2091+ goto done ;
2092+ }
2093+ // txom = pend_attr->om;
2094+ // pend_attr->rxom = NULL;
2095+ os_mbuf_prepend (pend_attr -> om , 1 );
2096+ pend_attr -> om -> om_data [0 ] = BLE_ATT_OP_PREP_WRITE_RSP ;
2097+ rc = 0 ;
2098+ goto done ;
2099+ }
2100+
2101+ if (authorize ) {
2102+ access_cb = pend_attr -> entry -> ha_cb ;
2103+ rc = access_cb (pend_attr -> conn_handle , pend_attr -> entry -> ha_handle_id ,
2104+ pend_attr -> access_opcode , pend_attr -> offset ,
2105+ & pend_attr -> om , pend_attr -> entry -> ha_cb_arg );
2106+ }
2107+
2108+ if (rc != 0 ) {
2109+ att_err = rc ;
2110+ rc = BLE_HS_EAPP ;
2111+ }
2112+
2113+ if (pend_attr -> att_opcode == BLE_ATT_OP_WRITE_REQ ) {
2114+ /* read reuses the request buffer for the response */
2115+ ble_att_svr_tx_rsp (conn_handle , BLE_L2CAP_CID_ATT , rc , txom ,
2116+ pend_attr -> att_opcode , att_err , attr_handle );
2117+ return 0 ;
2118+ }
2119+
2120+ /* TODO: don't use BLE_L2CAP_CID_ATT, find a way to get cid */
2121+ done :
2122+ /* Write does not reuse request buffer for the response */
2123+ ble_att_svr_tx_rsp (conn_handle , BLE_L2CAP_CID_ATT , rc , pend_attr -> om ,
2124+ pend_attr -> att_opcode , att_err , attr_handle );
2125+
2126+ return 0 ;
2127+ }
2128+
20372129int
20382130ble_gatts_add_svcs (const struct ble_gatt_svc_def * svcs )
20392131{
0 commit comments