1 /*
2 * Copyright (C) 2017 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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holders nor the names of
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * 4. Any redistribution, use, or modification is done solely for
17 * personal benefit and not for any commercial purpose or for
18 * monetary gain.
19 *
20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * Please inquire about commercial licensing options at
34 * [email protected]
35 *
36 */
37
38 #define BTSTACK_FILE__ "btstack_chipset_zephyr.c"
39
40 /*
41 * btstack_chipset_zephyr.c
42 *
43 * Adapter to use CSR-based chipsets with BTstack
44 * SCO over HCI doesn't work over H4 connection and BTM805 module from Microchip Bluetooth Audio Developer Kit (CSR8811)
45 */
46
47 #include "btstack_chipset_zephyr.h"
48
49 #include <stddef.h> /* NULL */
50 #include <stdio.h>
51 #include <string.h> /* memcpy */
52
53 #include "btstack_control.h"
54 #include "btstack_debug.h"
55 #include "btstack_util.h"
56 #include "hci_transport.h"
57
58 // minimal Zpehyr init script to read static random address
59 static const uint8_t init_script[] = {
60 0x09, 0xfc, 0x00,
61 };
62 static const uint16_t init_script_size = sizeof(init_script);
63
64 //
65 static uint32_t init_script_offset = 0;
66
chipset_init(const void * config)67 static void chipset_init(const void * config){
68 UNUSED(config);
69 init_script_offset = 0;
70 }
71
chipset_next_command(uint8_t * hci_cmd_buffer)72 static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
73
74 while (true){
75
76 if (init_script_offset >= init_script_size) {
77 return BTSTACK_CHIPSET_DONE;
78 }
79
80 // copy command header
81 memcpy(&hci_cmd_buffer[0], (uint8_t *) &init_script[init_script_offset], 3);
82 init_script_offset += 3;
83 int payload_len = hci_cmd_buffer[2];
84 // copy command payload
85 memcpy(&hci_cmd_buffer[3], (uint8_t *) &init_script[init_script_offset], payload_len);
86
87 return BTSTACK_CHIPSET_VALID_COMMAND;
88 }
89 }
90
91
92 static const btstack_chipset_t btstack_chipset_zephyr = {
93 "Zephyr",
94 chipset_init,
95 chipset_next_command,
96 NULL, // chipset_set_baudrate_command,
97 NULL, // chipset_set_bd_addr_command not supported or implemented
98 };
99
100 // MARK: public API
btstack_chipset_zephyr_instance(void)101 const btstack_chipset_t * btstack_chipset_zephyr_instance(void){
102 return &btstack_chipset_zephyr;
103 }
104