hci.c (d8e8f12ab0e5ab053da36a185d2453be032b7118) hci.c (63fa3374ea948e8b552c58c28010f42929b7da6e)
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

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

522
523 // done
524 hci_stack->acl_fragmentation_pos = 0;
525 hci_stack->acl_fragmentation_total_size = 0;
526
527 // release buffer now for synchronous transport
528 if (hci_transport_synchronous()){
529 hci_release_packet_buffer();
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

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

522
523 // done
524 hci_stack->acl_fragmentation_pos = 0;
525 hci_stack->acl_fragmentation_total_size = 0;
526
527 // release buffer now for synchronous transport
528 if (hci_transport_synchronous()){
529 hci_release_packet_buffer();
530 // notify upper stack that iit might be possible to send again
531 uint8_t event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0};
530 // notify upper stack that it might be possible to send again
531 uint8_t event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0};
532 hci_emit_event(&event[0], sizeof(event), 0); // don't dump
533 }
534
535 return err;
536}
537
538// pre: caller has reserved the packet buffer
539int hci_send_acl_packet_buffer(int size){

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

605 connection->num_sco_packets_sent++;
606 }
607
608 hci_dump_packet( HCI_SCO_DATA_PACKET, 0, packet, size);
609 int err = hci_stack->hci_transport->send_packet(HCI_SCO_DATA_PACKET, packet, size);
610
611 if (hci_transport_synchronous()){
612 hci_release_packet_buffer();
532 hci_emit_event(&event[0], sizeof(event), 0); // don't dump
533 }
534
535 return err;
536}
537
538// pre: caller has reserved the packet buffer
539int hci_send_acl_packet_buffer(int size){

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

605 connection->num_sco_packets_sent++;
606 }
607
608 hci_dump_packet( HCI_SCO_DATA_PACKET, 0, packet, size);
609 int err = hci_stack->hci_transport->send_packet(HCI_SCO_DATA_PACKET, packet, size);
610
611 if (hci_transport_synchronous()){
612 hci_release_packet_buffer();
613 // notify upper stack that iit might be possible to send again
614 uint8_t event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0};
613 // notify upper stack that it might be possible to send again
614 uint8_t event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0};
615 hci_emit_event(&event[0], sizeof(event), 0); // don't dump
616 }
617
618 return err;
619}
620
621static void acl_handler(uint8_t *packet, int size){
622

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

1678 case HCI_EVENT_ROLE_CHANGE:
1679 if (packet[2]) break; // status != 0
1680 handle = little_endian_read_16(packet, 3);
1681 conn = hci_connection_for_handle(handle);
1682 if (!conn) break; // no conn
1683 conn->role = packet[9];
1684 break;
1685
615 hci_emit_event(&event[0], sizeof(event), 0); // don't dump
616 }
617
618 return err;
619}
620
621static void acl_handler(uint8_t *packet, int size){
622

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

1678 case HCI_EVENT_ROLE_CHANGE:
1679 if (packet[2]) break; // status != 0
1680 handle = little_endian_read_16(packet, 3);
1681 conn = hci_connection_for_handle(handle);
1682 if (!conn) break; // no conn
1683 conn->role = packet[9];
1684 break;
1685
1686 case DAEMON_EVENT_HCI_PACKET_SENT:
1686 case HCI_EVENT_TRANSPORT_PACKET_SENT:
1687 // release packet buffer only for asynchronous transport and if there are not further fragements
1688 if (hci_transport_synchronous()) {
1687 // release packet buffer only for asynchronous transport and if there are not further fragements
1688 if (hci_transport_synchronous()) {
1689 log_error("Synchronous HCI Transport shouldn't send DAEMON_EVENT_HCI_PACKET_SENT");
1689 log_error("Synchronous HCI Transport shouldn't send HCI_EVENT_TRANSPORT_PACKET_SENT");
1690 return; // instead of break: to avoid re-entering hci_run()
1691 }
1692 if (hci_stack->acl_fragmentation_total_size) break;
1693 hci_release_packet_buffer();
1694
1690 return; // instead of break: to avoid re-entering hci_run()
1691 }
1692 if (hci_stack->acl_fragmentation_total_size) break;
1693 hci_release_packet_buffer();
1694
1695 // L2CAP receives this event via the hci_add_event_handler
1696 // For SCO, we do the can send now check here
1695 // L2CAP receives this event via the hci_emit_event below
1696
1697 // For SCO, we do the can_send_now_check here
1697 hci_notify_if_sco_can_send_now();
1698 break;
1699
1698 hci_notify_if_sco_can_send_now();
1699 break;
1700
1701 case HCI_EVENT_SCO_CAN_SEND_NOW:
1702 // For SCO, we do the can_send_now_check here
1703 hci_notify_if_sco_can_send_now();
1704 return;
1705
1700#ifdef ENABLE_BLE
1701 case HCI_EVENT_LE_META:
1702 switch (packet[2]){
1703 case HCI_SUBEVENT_LE_ADVERTISING_REPORT:
1704 log_info("advertising report received");
1705 if (hci_stack->le_scanning_state != LE_SCANNING) break;
1706 le_handle_advertisement_report(packet, size);
1707 break;

--- 1832 unchanged lines hidden ---
1706#ifdef ENABLE_BLE
1707 case HCI_EVENT_LE_META:
1708 switch (packet[2]){
1709 case HCI_SUBEVENT_LE_ADVERTISING_REPORT:
1710 log_info("advertising report received");
1711 if (hci_stack->le_scanning_state != LE_SCANNING) break;
1712 le_handle_advertisement_report(packet, size);
1713 break;

--- 1832 unchanged lines hidden ---