1 /****************************************************************************** 2 * 3 * Copyright (C) 2014 Google, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #ifndef _PACKET_FRAGMENTER_H_ 20 #define _PACKET_FRAGMENTER_H_ 21 22 #include "osi/allocator.h" 23 #include "stack/bt_types.h" 24 #include "hci/hci_layer.h" 25 26 typedef void (*transmit_finished_cb)(BT_HDR *packet, bool all_fragments_sent); 27 typedef void (*packet_reassembled_cb)(BT_HDR *packet); 28 typedef void (*packet_fragmented_cb)(BT_HDR *packet, bool send_transmit_finished); 29 30 typedef struct { 31 // Called for every packet fragment. 32 packet_fragmented_cb fragmented; 33 34 // Called for every completely reassembled packet. 35 packet_reassembled_cb reassembled; 36 37 // Called when the fragmenter finishes sending all requested fragments, 38 // but the packet has not been entirely sent. 39 transmit_finished_cb transmit_finished; 40 } packet_fragmenter_callbacks_t; 41 42 typedef struct packet_fragmenter_t { 43 // Initialize the fragmenter, specifying the |result_callbacks|. 44 void (*init)(const packet_fragmenter_callbacks_t *result_callbacks); 45 46 // Release all resources associated with the fragmenter. 47 void (*cleanup)(void); 48 49 // Check if Current fragmenter is ongoing 50 BT_HDR *(*fragment_current_packet)(void); 51 52 // Fragments |packet| if necessary and hands off everything to the fragmented callback. 53 void (*fragment_and_dispatch)(BT_HDR *packet); 54 // If |packet| is a complete packet, forwards to the reassembled callback. Otherwise 55 // holds onto it until all fragments arrive, at which point the reassembled callback is called 56 // with the reassembled data. 57 void (*reassemble_and_dispatch)(BT_HDR *packet); 58 } packet_fragmenter_t; 59 60 const packet_fragmenter_t *packet_fragmenter_get_interface(void); 61 62 #endif /* _PACKET_FRAGMENTER_H_ */ 63