hci.c (33e6948b1254ceb02d68d53c2d586e29fb8c8b03) hci.c (81d2bdb29c84b49fd5680ddde8f039aee45655ae)
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

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

663 hci_stack->acl_fragmentation_pos = 0;
664 hci_stack->acl_fragmentation_total_size = 0;
665 }
666
667 // send packet
668 uint8_t * packet = &hci_stack->hci_packet_buffer[acl_header_pos];
669 const int size = current_acl_data_packet_length + 4;
670 hci_dump_packet(HCI_ACL_DATA_PACKET, 0, packet, size);
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

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

663 hci_stack->acl_fragmentation_pos = 0;
664 hci_stack->acl_fragmentation_total_size = 0;
665 }
666
667 // send packet
668 uint8_t * packet = &hci_stack->hci_packet_buffer[acl_header_pos];
669 const int size = current_acl_data_packet_length + 4;
670 hci_dump_packet(HCI_ACL_DATA_PACKET, 0, packet, size);
671 hci_stack->acl_fragmentation_tx_active = 1;
671 err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
672
673 log_debug("hci_send_acl_packet_fragments loop after send (more fragments %d)", more_fragments);
674
675 // done yet?
676 if (!more_fragments) break;
677
678 // can send more?
679 if (!hci_can_send_prepared_acl_packet_now(connection->con_handle)) return err;
680 }
681
682 log_debug("hci_send_acl_packet_fragments loop over");
683
684 // release buffer now for synchronous transport
685 if (hci_transport_synchronous()){
672 err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
673
674 log_debug("hci_send_acl_packet_fragments loop after send (more fragments %d)", more_fragments);
675
676 // done yet?
677 if (!more_fragments) break;
678
679 // can send more?
680 if (!hci_can_send_prepared_acl_packet_now(connection->con_handle)) return err;
681 }
682
683 log_debug("hci_send_acl_packet_fragments loop over");
684
685 // release buffer now for synchronous transport
686 if (hci_transport_synchronous()){
687 hci_stack->acl_fragmentation_tx_active = 0;
686 hci_release_packet_buffer();
687 hci_emit_transport_packet_sent();
688 }
689
690 return err;
691}
692
693// pre: caller has reserved the packet buffer

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

2246#endif
2247
2248 // HCI_EVENT_DISCONNECTION_COMPLETE
2249 // has been split, to first notify stack before shutting connection down
2250 // see end of function, too.
2251 case HCI_EVENT_DISCONNECTION_COMPLETE:
2252 if (packet[2]) break; // status != 0
2253 handle = little_endian_read_16(packet, 3);
688 hci_release_packet_buffer();
689 hci_emit_transport_packet_sent();
690 }
691
692 return err;
693}
694
695// pre: caller has reserved the packet buffer

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

2248#endif
2249
2250 // HCI_EVENT_DISCONNECTION_COMPLETE
2251 // has been split, to first notify stack before shutting connection down
2252 // see end of function, too.
2253 case HCI_EVENT_DISCONNECTION_COMPLETE:
2254 if (packet[2]) break; // status != 0
2255 handle = little_endian_read_16(packet, 3);
2254 // drop outgoing ACL fragments if it is for closed connection
2256 // drop outgoing ACL fragments if it is for closed connection and release buffer if tx not active
2255 if (hci_stack->acl_fragmentation_total_size > 0) {
2256 if (handle == READ_ACL_CONNECTION_HANDLE(hci_stack->hci_packet_buffer)){
2257 if (hci_stack->acl_fragmentation_total_size > 0) {
2258 if (handle == READ_ACL_CONNECTION_HANDLE(hci_stack->hci_packet_buffer)){
2257 log_info("hci: drop fragmented ACL data for closed connection");
2258 hci_stack->acl_fragmentation_total_size = 0;
2259 hci_stack->acl_fragmentation_pos = 0;
2259 int release_buffer = hci_stack->acl_fragmentation_tx_active == 0;
2260 log_info("drop fragmented ACL data for closed connection, release buffer %u", release_buffer);
2261 hci_stack->acl_fragmentation_total_size = 0;
2262 hci_stack->acl_fragmentation_pos = 0;
2263 if (release_buffer){
2264 hci_release_packet_buffer();
2265 }
2260 }
2261 }
2262
2263 // re-enable advertisements for le connections if active
2264 conn = hci_connection_for_handle(handle);
2265 if (!conn) break;
2266 conn->state = RECEIVED_DISCONNECTION_COMPLETE;
2267#ifdef ENABLE_BLE

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

2296#endif
2297
2298 case HCI_EVENT_TRANSPORT_PACKET_SENT:
2299 // release packet buffer only for asynchronous transport and if there are not further fragements
2300 if (hci_transport_synchronous()) {
2301 log_error("Synchronous HCI Transport shouldn't send HCI_EVENT_TRANSPORT_PACKET_SENT");
2302 return; // instead of break: to avoid re-entering hci_run()
2303 }
2266 }
2267 }
2268
2269 // re-enable advertisements for le connections if active
2270 conn = hci_connection_for_handle(handle);
2271 if (!conn) break;
2272 conn->state = RECEIVED_DISCONNECTION_COMPLETE;
2273#ifdef ENABLE_BLE

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

2302#endif
2303
2304 case HCI_EVENT_TRANSPORT_PACKET_SENT:
2305 // release packet buffer only for asynchronous transport and if there are not further fragements
2306 if (hci_transport_synchronous()) {
2307 log_error("Synchronous HCI Transport shouldn't send HCI_EVENT_TRANSPORT_PACKET_SENT");
2308 return; // instead of break: to avoid re-entering hci_run()
2309 }
2310 hci_stack->acl_fragmentation_tx_active = 0;
2304 if (hci_stack->acl_fragmentation_total_size) break;
2305 hci_release_packet_buffer();
2306
2307 // L2CAP receives this event via the hci_emit_event below
2308
2309#ifdef ENABLE_CLASSIC
2310 // For SCO, we do the can_send_now_check here
2311 hci_notify_if_sco_can_send_now();

--- 2611 unchanged lines hidden ---
2311 if (hci_stack->acl_fragmentation_total_size) break;
2312 hci_release_packet_buffer();
2313
2314 // L2CAP receives this event via the hci_emit_event below
2315
2316#ifdef ENABLE_CLASSIC
2317 // For SCO, we do the can_send_now_check here
2318 hci_notify_if_sco_can_send_now();

--- 2611 unchanged lines hidden ---