1 /*
2  * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements.  See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership.  The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with the License.  You may obtain a copy of the License at
14  *
15  *  http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied.  See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  */
24 
25 #ifndef _HCI_H4_H_
26 #define _HCI_H4_H_
27 
28 #include <stdint.h>
29 
30 #define HCI_H4_NONE      0x00
31 #define HCI_H4_CMD       0x01
32 #define HCI_H4_ACL       0x02
33 #define HCI_H4_EVT       0x04
34 #define HCI_H4_ISO       0x05
35 
36 typedef void *(hci_h4_alloc_cmd)(void);
37 typedef void *(hci_h4_alloc_evt)(int);
38 typedef struct os_mbuf *(hci_h4_alloc_acl)(void);
39 typedef struct os_mbuf *(hci_h4_alloc_iso)(void);
40 
41 struct hci_h4_allocators {
42     hci_h4_alloc_cmd *cmd;
43     hci_h4_alloc_acl *acl;
44     hci_h4_alloc_evt *evt;
45     hci_h4_alloc_iso *iso;
46 };
47 
48 extern const struct hci_h4_allocators hci_h4_allocs_from_ll;
49 extern const struct hci_h4_allocators hci_h4_allocs_from_hs;
50 
51 typedef int (hci_h4_frame_cb)(uint8_t pkt_type, void *data);
52 
53 struct hci_h4_sm {
54     uint8_t state;
55     uint8_t pkt_type;
56     uint8_t min_len;
57     uint16_t len;
58     uint16_t exp_len;
59     uint8_t hdr[4];
60     union {
61         uint8_t *buf;
62         struct os_mbuf *om;
63     };
64 
65     const struct hci_h4_allocators *allocs;
66     hci_h4_frame_cb *frame_cb;
67 };
68 
69 void hci_h4_sm_init(struct hci_h4_sm *h4sm,
70                     const struct hci_h4_allocators *allocs,
71                     hci_h4_frame_cb *frame_cb);
72 
73 int hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len);
74 
75 #endif /* _HCI_H4_H_ */
76