1360243beSMatthias Ringwald /*
2360243beSMatthias Ringwald * Copyright (C) 2017 BlueKitchen GmbH
3360243beSMatthias Ringwald *
4360243beSMatthias Ringwald * Redistribution and use in source and binary forms, with or without
5360243beSMatthias Ringwald * modification, are permitted provided that the following conditions
6360243beSMatthias Ringwald * are met:
7360243beSMatthias Ringwald *
8360243beSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright
9360243beSMatthias Ringwald * notice, this list of conditions and the following disclaimer.
10360243beSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright
11360243beSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the
12360243beSMatthias Ringwald * documentation and/or other materials provided with the distribution.
13360243beSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of
14360243beSMatthias Ringwald * contributors may be used to endorse or promote products derived
15360243beSMatthias Ringwald * from this software without specific prior written permission.
16360243beSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for
17360243beSMatthias Ringwald * personal benefit and not for any commercial purpose or for
18360243beSMatthias Ringwald * monetary gain.
19360243beSMatthias Ringwald *
20360243beSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21360243beSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22360243beSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*2fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25360243beSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26360243beSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27360243beSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28360243beSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29360243beSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30360243beSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31360243beSMatthias Ringwald * SUCH DAMAGE.
32360243beSMatthias Ringwald *
33360243beSMatthias Ringwald * Please inquire about commercial licensing options at
34360243beSMatthias Ringwald * [email protected]
35360243beSMatthias Ringwald *
36360243beSMatthias Ringwald */
37360243beSMatthias Ringwald
38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "btstack_chipset_zephyr.c"
39360243beSMatthias Ringwald
40360243beSMatthias Ringwald /*
41360243beSMatthias Ringwald * btstack_chipset_zephyr.c
42360243beSMatthias Ringwald *
43360243beSMatthias Ringwald * Adapter to use CSR-based chipsets with BTstack
44360243beSMatthias Ringwald * SCO over HCI doesn't work over H4 connection and BTM805 module from Microchip Bluetooth Audio Developer Kit (CSR8811)
45360243beSMatthias Ringwald */
46360243beSMatthias Ringwald
47360243beSMatthias Ringwald #include "btstack_chipset_zephyr.h"
48360243beSMatthias Ringwald
49360243beSMatthias Ringwald #include <stddef.h> /* NULL */
50360243beSMatthias Ringwald #include <stdio.h>
51360243beSMatthias Ringwald #include <string.h> /* memcpy */
52360243beSMatthias Ringwald
53360243beSMatthias Ringwald #include "btstack_control.h"
54360243beSMatthias Ringwald #include "btstack_debug.h"
55360243beSMatthias Ringwald #include "btstack_util.h"
56360243beSMatthias Ringwald #include "hci_transport.h"
57360243beSMatthias Ringwald
58360243beSMatthias Ringwald // minimal Zpehyr init script to read static random address
59360243beSMatthias Ringwald static const uint8_t init_script[] = {
60360243beSMatthias Ringwald 0x09, 0xfc, 0x00,
61360243beSMatthias Ringwald };
62360243beSMatthias Ringwald static const uint16_t init_script_size = sizeof(init_script);
63360243beSMatthias Ringwald
64360243beSMatthias Ringwald //
65360243beSMatthias Ringwald static uint32_t init_script_offset = 0;
66360243beSMatthias Ringwald
chipset_init(const void * config)67360243beSMatthias Ringwald static void chipset_init(const void * config){
6862a563bbSMatthias Ringwald UNUSED(config);
69360243beSMatthias Ringwald init_script_offset = 0;
70360243beSMatthias Ringwald }
71360243beSMatthias Ringwald
chipset_next_command(uint8_t * hci_cmd_buffer)72360243beSMatthias Ringwald static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
73360243beSMatthias Ringwald
74ff3cc4a5SMatthias Ringwald while (true){
75360243beSMatthias Ringwald
76360243beSMatthias Ringwald if (init_script_offset >= init_script_size) {
77360243beSMatthias Ringwald return BTSTACK_CHIPSET_DONE;
78360243beSMatthias Ringwald }
79360243beSMatthias Ringwald
80360243beSMatthias Ringwald // copy command header
81360243beSMatthias Ringwald memcpy(&hci_cmd_buffer[0], (uint8_t *) &init_script[init_script_offset], 3);
82360243beSMatthias Ringwald init_script_offset += 3;
83360243beSMatthias Ringwald int payload_len = hci_cmd_buffer[2];
84360243beSMatthias Ringwald // copy command payload
85360243beSMatthias Ringwald memcpy(&hci_cmd_buffer[3], (uint8_t *) &init_script[init_script_offset], payload_len);
86360243beSMatthias Ringwald
87360243beSMatthias Ringwald return BTSTACK_CHIPSET_VALID_COMMAND;
88360243beSMatthias Ringwald }
89360243beSMatthias Ringwald }
90360243beSMatthias Ringwald
91360243beSMatthias Ringwald
92360243beSMatthias Ringwald static const btstack_chipset_t btstack_chipset_zephyr = {
93360243beSMatthias Ringwald "Zephyr",
94360243beSMatthias Ringwald chipset_init,
95360243beSMatthias Ringwald chipset_next_command,
96360243beSMatthias Ringwald NULL, // chipset_set_baudrate_command,
97360243beSMatthias Ringwald NULL, // chipset_set_bd_addr_command not supported or implemented
98360243beSMatthias Ringwald };
99360243beSMatthias Ringwald
100360243beSMatthias Ringwald // MARK: public API
btstack_chipset_zephyr_instance(void)101360243beSMatthias Ringwald const btstack_chipset_t * btstack_chipset_zephyr_instance(void){
102360243beSMatthias Ringwald return &btstack_chipset_zephyr;
103360243beSMatthias Ringwald }
104