1 /******************************************************************************
3 * Copyright (C) 2014 Google, Inc.
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
28 DATA_TYPE_COMMAND = 1,
34 typedef void (*data_ready_cb)(serial_data_type_t type);
37 // Called when the HAL detects inbound data.
38 // Data |type| may be ACL, SCO, or EVENT.
39 // Executes in the context of the thread supplied to |init|.
40 data_ready_cb data_ready;
43 // Called when the HAL detects inbound astronauts named Dave.
44 // HAL will deny all requests to open the pod bay doors after this.
45 dave_ready_cb dave_ready;
47 } hci_hal_callbacks_t;
49 typedef struct hci_hal_t {
50 // Initialize the HAL, with |upper_callbacks| and |upper_thread| to run in the context of.
51 bool (*init)(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper_thread);
53 // Connect to the underlying hardware, and let data start flowing.
55 // Disconnect from the underlying hardware, and close the HAL.
59 // Retrieve up to |max_size| bytes for ACL, SCO, or EVENT data packets into
60 // |buffer|, blocking until max_size bytes read if |block| is true.
61 // Only guaranteed to be correct in the context of a data_ready callback
62 // of the corresponding type.
63 size_t (*read_data)(serial_data_type_t type, uint8_t *buffer, size_t max_size, bool block);
64 // The upper layer must call this to notify the HAL that it has finished
65 // reading a packet of the specified |type|. Underlying implementations that
66 // use shared channels for multiple data types depend on this to know when
67 // to reinterpret the data stream.
68 void (*packet_finished)(serial_data_type_t type);
69 // Transmit COMMAND, ACL, or SCO data packets.
70 // |data| may not be NULL. |length| must be greater than zero.
73 // Depending on the underlying implementation, the byte right
74 // before the beginning of |data| may be borrowed during this call
75 // and then restored to its original value.
76 // This is safe in the bluetooth context, because there is always a buffer
77 // header that prefixes data you're sending.
78 uint16_t (*transmit_data)(serial_data_type_t type, uint8_t *data, uint16_t length);
81 // Gets the correct hal implementation, as compiled for.
82 const hci_hal_t *hci_hal_get_interface(void);
84 const hci_hal_t *hci_hal_h4_get_interface(void);
85 const hci_hal_t *hci_hal_h4_get_test_interface(vendor_t *vendor_interface);
87 const hci_hal_t *hci_hal_mct_get_interface(void);
88 const hci_hal_t *hci_hal_mct_get_test_interface(vendor_t *vendor_interface);