@@ -81,6 +81,46 @@ ble_att_svr_entry_free(struct ble_att_svr_entry *entry)
8181 os_memblock_put (& ble_att_svr_entry_pool , entry );
8282}
8383
84+ struct pending_attr_list_head pending_attr_list =
85+ SLIST_HEAD_INITIALIZER (pending_attr_list );
86+
87+ static void pending_att_prepare (uint16_t conn_handle ,
88+ struct ble_att_svr_entry * entry ,
89+ uint16_t offset , struct os_mbuf * om ,
90+ uint8_t access_opcode , uint8_t att_opcode )
91+ {
92+ struct pending_attr * pending ;
93+ struct pending_attr * e ;
94+ struct pending_attr * last ;
95+
96+ pending = malloc (sizeof (struct pending_attr ));
97+
98+ memset (pending , 0 , sizeof (* pending ));
99+
100+ pending -> conn_handle = conn_handle ;
101+ pending -> entry = (struct ble_att_svr_entry * ) entry ;
102+ pending -> offset = offset ;
103+ pending -> om = om ;
104+ pending -> access_opcode = access_opcode ;
105+ pending -> att_opcode = att_opcode ;
106+ ble_hs_lock ();
107+ if (SLIST_EMPTY (& pending_attr_list )) {
108+ SLIST_INSERT_HEAD (& pending_attr_list , pending , next );
109+ } else {
110+ last = NULL ;
111+ /* find last and insert at tail */
112+ SLIST_FOREACH (e , & pending_attr_list , next ) {
113+ if ((SLIST_NEXT (e , next ) = NULL )) {
114+ last = e ;
115+ SLIST_INSERT_AFTER (last , pending , next );
116+ }
117+ }
118+ }
119+ ble_hs_unlock ();
120+
121+ return ;
122+ }
123+
84124/**
85125 * Allocate the next handle id and return it.
86126 *
@@ -333,7 +373,19 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
333373 }
334374
335375 if (author ) {
336- /* XXX: Prompt user for authorization. */
376+ rc = ble_gap_authorize_event (conn_handle , entry -> ha_handle_id ,
377+ is_read );
378+ switch (rc ) {
379+ case BLE_GAP_AUTHORIZE_ACCEPT :
380+ break ;
381+
382+ case BLE_GAP_AUTHORIZE_REJECT :
383+ * out_att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHOR ;
384+ return BLE_HS_ATT_ERR (* out_att_err );
385+
386+ case BLE_GAP_AUTHORIZE_PENDING :
387+ return BLE_HS_EPENDING ;
388+ }
337389 }
338390
339391 return 0 ;
@@ -406,6 +458,11 @@ ble_att_svr_read(uint16_t conn_handle,
406458
407459 if (conn_handle != BLE_HS_CONN_HANDLE_NONE ) {
408460 rc = ble_att_svr_check_perms (conn_handle , 1 , entry , & att_err );
461+ if (rc == BLE_HS_EPENDING ) {
462+ pending_att_prepare (conn_handle , entry , offset , om ,
463+ BLE_ATT_ACCESS_OP_READ , BLE_ATT_OP_READ_REQ );
464+ return rc ;
465+ }
409466 if (rc != 0 ) {
410467 goto err ;
411468 }
@@ -532,6 +589,11 @@ ble_att_svr_write(uint16_t conn_handle, struct ble_att_svr_entry *entry,
532589
533590 if (conn_handle != BLE_HS_CONN_HANDLE_NONE ) {
534591 rc = ble_att_svr_check_perms (conn_handle , 0 , entry , & att_err );
592+ if (rc == BLE_HS_EPENDING ) {
593+ pending_att_prepare (conn_handle , entry , offset , * om ,
594+ BLE_ATT_ACCESS_OP_WRITE , BLE_ATT_OP_WRITE_REQ );
595+ return rc ;
596+ }
535597 if (rc != 0 ) {
536598 goto done ;
537599 }
@@ -621,7 +683,7 @@ ble_att_svr_tx_error_rsp(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txo
621683 * of the error message's attribute handle
622684 * field.
623685 */
624- static int
686+ int
625687ble_att_svr_tx_rsp (uint16_t conn_handle , uint16_t cid , int hs_status , struct os_mbuf * om ,
626688 uint8_t att_op , uint8_t err_status , uint16_t err_handle )
627689{
@@ -1502,6 +1564,9 @@ ble_att_svr_rx_read(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
15021564 }
15031565
15041566 rc = ble_att_svr_read_handle (conn_handle , err_handle , 0 , txom , & att_err );
1567+ if (rc == BLE_HS_EPENDING ) {
1568+ return rc ;
1569+ }
15051570 if (rc != 0 ) {
15061571 goto done ;
15071572 }
@@ -1553,6 +1618,9 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rx
15531618
15541619 rc = ble_att_svr_read_handle (conn_handle , err_handle , offset ,
15551620 txom , & att_err );
1621+ if (rc == BLE_HS_EPENDING ) {
1622+ return rc ;
1623+ }
15561624 if (rc != 0 ) {
15571625 goto done ;
15581626 }
@@ -2068,7 +2136,7 @@ ble_att_svr_rx_read_group_type(uint16_t conn_handle, uint16_t cid, struct os_mbu
20682136 return rc ;
20692137}
20702138
2071- static int
2139+ int
20722140ble_att_svr_build_write_rsp (struct os_mbuf * * rxom , struct os_mbuf * * out_txom ,
20732141 uint8_t * att_err )
20742142{
@@ -2135,6 +2203,9 @@ ble_att_svr_rx_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
21352203 os_mbuf_adj (* rxom , sizeof (* req ));
21362204
21372205 rc = ble_att_svr_write_handle (conn_handle , handle , 0 , rxom , & att_err );
2206+ if (rc == BLE_HS_EPENDING ) {
2207+ return rc ;
2208+ }
21382209 if (rc != 0 ) {
21392210 goto done ;
21402211 }
@@ -2481,6 +2552,11 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **r
24812552
24822553 /* <1>, <2>, <4>, <6> */
24832554 rc = ble_att_svr_check_perms (conn_handle , 0 , attr_entry , & att_err );
2555+ if (rc == BLE_HS_EPENDING ) {
2556+ pending_att_prepare (conn_handle , attr_entry , 0 , txom ,
2557+ 0 , BLE_ATT_OP_PREP_WRITE_REQ );
2558+ return rc ;
2559+ }
24842560 if (rc != 0 ) {
24852561 goto done ;
24862562 }
@@ -2942,6 +3018,7 @@ ble_att_svr_init(void)
29423018
29433019 STAILQ_INIT (& ble_att_svr_list );
29443020 STAILQ_INIT (& ble_att_svr_hidden_list );
3021+ SLIST_INIT (& pending_attr_list );
29453022
29463023 ble_att_svr_id = 0 ;
29473024
0 commit comments