1 /******************************************************************************
2  *
3  *  Copyright 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 #pragma once
20 
21 #include "osi/include/allocator.h"
22 #include "stack/include/bt_hdr.h"
23 
24 typedef void (*packet_reassembled_cb)(BT_HDR* packet);
25 typedef void (*packet_fragmented_cb)(BT_HDR* packet,
26                                      bool send_transmit_finished);
27 
28 typedef struct {
29   // Called for every packet fragment.
30   packet_fragmented_cb fragmented;
31 
32   // Called for every completely reassembled packet.
33   packet_reassembled_cb reassembled;
34 } packet_fragmenter_callbacks_t;
35 
36 typedef struct packet_fragmenter_t {
37   // Initialize the fragmenter, specifying the |result_callbacks|.
38   void (*init)(const packet_fragmenter_callbacks_t* result_callbacks);
39 
40   // Release all resources associated with the fragmenter.
41   void (*cleanup)(void);
42 
43   // Fragments |packet| if necessary and hands off everything to the fragmented
44   // callback.
45   void (*fragment_and_dispatch)(BT_HDR* packet, uint16_t iso_buffer_size);
46   // If |packet| is a complete packet, forwards to the reassembled callback.
47   // Otherwise holds onto it until all fragments arrive, at which point the
48   // reassembled callback is called with the reassembled data.
49   void (*reassemble_and_dispatch)(BT_HDR* packet);
50 } packet_fragmenter_t;
51 
52 const packet_fragmenter_t* packet_fragmenter_get_interface();
53