hci.c (1ef6bb52dcf8da873294c4cecd73e18c63a8c4aa) hci.c (fb37a842ea98c26e62c79cddf7c8d9662590cf7e)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 270 unchanged lines hidden (view full) ---

279 */
280static int nr_hci_connections(void){
281 int count = 0;
282 btstack_linked_item_t *it;
283 for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next, count++);
284 return count;
285}
286
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 270 unchanged lines hidden (view full) ---

279 */
280static int nr_hci_connections(void){
281 int count = 0;
282 btstack_linked_item_t *it;
283 for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next, count++);
284 return count;
285}
286
287/**
288 * Dummy handler called by HCI
289 */
290static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
291}
292
293uint8_t hci_number_outgoing_packets(hci_con_handle_t handle){
294 hci_connection_t * connection = hci_connection_for_handle(handle);
295 if (!connection) {
296 log_error("hci_number_outgoing_packets: connection for handle %u does not exist!", handle);
297 return 0;
298 }
299 return connection->num_acl_packets_sent;
300}

--- 1508 unchanged lines hidden (view full) ---

1809 * @brief Add event packet handler.
1810 */
1811void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
1812 btstack_linked_list_add_tail(&hci_stack->event_handlers, (btstack_linked_item_t*) callback_handler);
1813}
1814
1815
1816/** Register HCI packet handlers */
287uint8_t hci_number_outgoing_packets(hci_con_handle_t handle){
288 hci_connection_t * connection = hci_connection_for_handle(handle);
289 if (!connection) {
290 log_error("hci_number_outgoing_packets: connection for handle %u does not exist!", handle);
291 return 0;
292 }
293 return connection->num_acl_packets_sent;
294}

--- 1508 unchanged lines hidden (view full) ---

1803 * @brief Add event packet handler.
1804 */
1805void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
1806 btstack_linked_list_add_tail(&hci_stack->event_handlers, (btstack_linked_item_t*) callback_handler);
1807}
1808
1809
1810/** Register HCI packet handlers */
1817void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
1818 hci_stack->packet_handler = handler;
1811void hci_register_acl_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
1812 hci_stack->acl_packet_handler = handler;
1819}
1820
1821/**
1822 * @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
1823 */
1824void hci_register_sco_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
1825 hci_stack->sco_packet_handler = handler;
1826}

--- 45 unchanged lines hidden (view full) ---

1872 hci_stack->hci_transport = transport;
1873
1874 // reference to used config
1875 hci_stack->config = config;
1876
1877 // init used hardware control with NULL
1878 // init used chipset with NULL
1879
1813}
1814
1815/**
1816 * @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
1817 */
1818void hci_register_sco_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
1819 hci_stack->sco_packet_handler = handler;
1820}

--- 45 unchanged lines hidden (view full) ---

1866 hci_stack->hci_transport = transport;
1867
1868 // reference to used config
1869 hci_stack->config = config;
1870
1871 // init used hardware control with NULL
1872 // init used chipset with NULL
1873
1880 // higher level handler
1881 hci_stack->packet_handler = dummy_handler;
1882
1883 // store and open remote device db
1884 hci_stack->link_key_db = link_key_db;
1885 if (hci_stack->link_key_db) {
1886 hci_stack->link_key_db->open();
1887 }
1888
1889 // max acl payload size defined in config.h
1890 hci_stack->acl_data_packet_length = HCI_ACL_PAYLOAD_SIZE;

--- 983 unchanged lines hidden (view full) ---

2874
2875 return hci_send_cmd_packet(packet, size);
2876}
2877
2878// Create various non-HCI events.
2879// TODO: generalize, use table similar to hci_create_command
2880
2881static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
1874 // store and open remote device db
1875 hci_stack->link_key_db = link_key_db;
1876 if (hci_stack->link_key_db) {
1877 hci_stack->link_key_db->open();
1878 }
1879
1880 // max acl payload size defined in config.h
1881 hci_stack->acl_data_packet_length = HCI_ACL_PAYLOAD_SIZE;

--- 983 unchanged lines hidden (view full) ---

2865
2866 return hci_send_cmd_packet(packet, size);
2867}
2868
2869// Create various non-HCI events.
2870// TODO: generalize, use table similar to hci_create_command
2871
2872static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
2873 // dump packet
2882 if (dump) {
2883 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
2884 }
2874 if (dump) {
2875 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
2876 }
2885 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event));
2886
2877
2878 // dispatch to all event handlers
2887 btstack_linked_list_iterator_t it;
2888 btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers);
2889 while (btstack_linked_list_iterator_has_next(&it)){
2890 btstack_packet_callback_registration_t * entry = (btstack_packet_callback_registration_t*) btstack_linked_list_iterator_next(&it);
2891 entry->callback(HCI_EVENT_PACKET, event, size);
2892 }
2893}
2894
2895static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){
2879 btstack_linked_list_iterator_t it;
2880 btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers);
2881 while (btstack_linked_list_iterator_has_next(&it)){
2882 btstack_packet_callback_registration_t * entry = (btstack_packet_callback_registration_t*) btstack_linked_list_iterator_next(&it);
2883 entry->callback(HCI_EVENT_PACKET, event, size);
2884 }
2885}
2886
2887static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){
2896 hci_stack->packet_handler(HCI_ACL_DATA_PACKET, packet, size);
2888 if (!hci_stack->acl_packet_handler) return;
2889 hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, packet, size);
2897}
2898
2899void hci_emit_state(void){
2900 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state);
2901 uint8_t event[3];
2902 event[0] = BTSTACK_EVENT_STATE;
2903 event[1] = sizeof(event) - 2;
2904 event[2] = hci_stack->state;

--- 634 unchanged lines hidden ---
2890}
2891
2892void hci_emit_state(void){
2893 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state);
2894 uint8_t event[3];
2895 event[0] = BTSTACK_EVENT_STATE;
2896 event[1] = sizeof(event) - 2;
2897 event[2] = hci_stack->state;

--- 634 unchanged lines hidden ---