/** * @brief Request emission of L2CAP_EVENT_CAN_SEND_NOW as soon as possible for server * @note L2CAP_EVENT_CAN_SEND_NOW might be emitted during call to this function * so packet handler should be ready to handle it * @param con_handle */ void att_dispatch_server_request_can_send_now_event(hci_con_handle_t con_handle){ subscriptions[ATT_SERVER].waiting_for_can_send = 1; if (!can_send_now_pending){ can_send_now_pending = 1; l2cap_request_can_send_fix_channel_now_event(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL); } }
static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size){ uint8_t index; uint8_t i; switch (packet_type){ case ATT_DATA_PACKET: // odd PDUs are sent from server to client - even PDUs are sent from client to server index = packet[0] & 1; // log_info("att_data_packet with opcode 0x%x", packet[0]); if (!subscriptions[index].packet_handler) return; subscriptions[index].packet_handler(packet_type, handle, packet, size); break; case HCI_EVENT_PACKET: if (packet[0] != L2CAP_EVENT_CAN_SEND_NOW) break; can_send_now_pending = 0; for (i = 0; i < ATT_MAX; i++){ index = (att_round_robin + i) & 1; if (subscriptions[index].packet_handler && subscriptions[index].waiting_for_can_send){ subscriptions[index].waiting_for_can_send = 0; subscriptions[index].packet_handler(packet_type, handle, packet, size); // fairness: prioritize next service att_round_robin = (index + 1) % ATT_MAX; // stop if client cannot send anymore if (!hci_can_send_acl_le_packet_now()) break; } } // check if more can send now events are needed if (!can_send_now_pending){ for (i = 0; i < ATT_MAX; i++){ if (subscriptions[i].packet_handler && subscriptions[i].waiting_for_can_send){ can_send_now_pending = 1; // note: con_handle is not used, so we can pass in anything l2cap_request_can_send_fix_channel_now_event(0, L2CAP_CID_ATTRIBUTE_PROTOCOL); break; } } } break; default: break; } }
/** * @brief Request emission of L2CAP_EVENT_CAN_SEND_NOW as soon as possible for server * @note L2CAP_EVENT_CAN_SEND_NOW might be emitted during call to this function * so packet handler should be ready to handle it * @param con_handle */ void att_dispatch_server_request_can_send_now_event(hci_con_handle_t con_handle){ att_server_waiting_for_can_send = 1; l2cap_request_can_send_fix_channel_now_event(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL); }