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