mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-26 02:37:41 +00:00
posix-h4-zephyr: read static address via vendor specific command and use it
This commit is contained in:
parent
b1aa03799d
commit
360243be41
102
chipset/zephyr/btstack_chipset_zephyr.c
Normal file
102
chipset/zephyr/btstack_chipset_zephyr.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 BlueKitchen GmbH
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the copyright holders nor the names of
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
* 4. Any redistribution, use, or modification is done solely for
|
||||||
|
* personal benefit and not for any commercial purpose or for
|
||||||
|
* monetary gain.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
||||||
|
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* Please inquire about commercial licensing options at
|
||||||
|
* contact@bluekitchen-gmbh.com
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define __BTSTACK_FILE__ "btstack_chipset_zephyr.c"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* btstack_chipset_zephyr.c
|
||||||
|
*
|
||||||
|
* Adapter to use CSR-based chipsets with BTstack
|
||||||
|
* SCO over HCI doesn't work over H4 connection and BTM805 module from Microchip Bluetooth Audio Developer Kit (CSR8811)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "btstack_chipset_zephyr.h"
|
||||||
|
|
||||||
|
#include <stddef.h> /* NULL */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h> /* memcpy */
|
||||||
|
|
||||||
|
#include "btstack_control.h"
|
||||||
|
#include "btstack_debug.h"
|
||||||
|
#include "btstack_util.h"
|
||||||
|
#include "hci_transport.h"
|
||||||
|
|
||||||
|
// minimal Zpehyr init script to read static random address
|
||||||
|
static const uint8_t init_script[] = {
|
||||||
|
0x09, 0xfc, 0x00,
|
||||||
|
};
|
||||||
|
static const uint16_t init_script_size = sizeof(init_script);
|
||||||
|
|
||||||
|
//
|
||||||
|
static uint32_t init_script_offset = 0;
|
||||||
|
|
||||||
|
static void chipset_init(const void * config){
|
||||||
|
init_script_offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
|
||||||
|
|
||||||
|
while (1){
|
||||||
|
|
||||||
|
if (init_script_offset >= init_script_size) {
|
||||||
|
return BTSTACK_CHIPSET_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy command header
|
||||||
|
memcpy(&hci_cmd_buffer[0], (uint8_t *) &init_script[init_script_offset], 3);
|
||||||
|
init_script_offset += 3;
|
||||||
|
int payload_len = hci_cmd_buffer[2];
|
||||||
|
// copy command payload
|
||||||
|
memcpy(&hci_cmd_buffer[3], (uint8_t *) &init_script[init_script_offset], payload_len);
|
||||||
|
|
||||||
|
return BTSTACK_CHIPSET_VALID_COMMAND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const btstack_chipset_t btstack_chipset_zephyr = {
|
||||||
|
"Zephyr",
|
||||||
|
chipset_init,
|
||||||
|
chipset_next_command,
|
||||||
|
NULL, // chipset_set_baudrate_command,
|
||||||
|
NULL, // chipset_set_bd_addr_command not supported or implemented
|
||||||
|
};
|
||||||
|
|
||||||
|
// MARK: public API
|
||||||
|
const btstack_chipset_t * btstack_chipset_zephyr_instance(void){
|
||||||
|
return &btstack_chipset_zephyr;
|
||||||
|
}
|
64
chipset/zephyr/btstack_chipset_zephyr.h
Normal file
64
chipset/zephyr/btstack_chipset_zephyr.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 BlueKitchen GmbH
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the copyright holders nor the names of
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
* 4. Any redistribution, use, or modification is done solely for
|
||||||
|
* personal benefit and not for any commercial purpose or for
|
||||||
|
* monetary gain.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
||||||
|
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* Please inquire about commercial licensing options at
|
||||||
|
* contact@bluekitchen-gmbh.com
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* btstack_chipset_zephyr.c
|
||||||
|
*
|
||||||
|
* Adapter to use Zephyr-based Bluetooth Controllers with BTstack
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __BTSTACK_CHIPSET_ZEPHYR_H
|
||||||
|
#define __BTSTACK_CHIPSET_ZEPHYR_H
|
||||||
|
|
||||||
|
#if defined __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "btstack_chipset.h"
|
||||||
|
#include "bluetooth.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get chipset instance for Zephyr Controllers
|
||||||
|
*/
|
||||||
|
const btstack_chipset_t * btstack_chipset_zephyr_instance(void);
|
||||||
|
|
||||||
|
#if defined __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __BTSTACK_CHIPSET_ZEPHYR_H
|
@ -9,7 +9,7 @@ CORE += \
|
|||||||
le_device_db_fs.c \
|
le_device_db_fs.c \
|
||||||
main.c \
|
main.c \
|
||||||
btstack_stdin_posix.c \
|
btstack_stdin_posix.c \
|
||||||
wav_util.c \
|
btstack_chipset_zephyr.c \
|
||||||
|
|
||||||
# examples
|
# examples
|
||||||
include ${BTSTACK_ROOT}/example/Makefile.inc
|
include ${BTSTACK_ROOT}/example/Makefile.inc
|
||||||
@ -17,9 +17,11 @@ include ${BTSTACK_ROOT}/example/Makefile.inc
|
|||||||
CFLAGS += -g -Wall -Werror \
|
CFLAGS += -g -Wall -Werror \
|
||||||
-I$(BTSTACK_ROOT)/platform/embedded \
|
-I$(BTSTACK_ROOT)/platform/embedded \
|
||||||
-I$(BTSTACK_ROOT)/platform/posix \
|
-I$(BTSTACK_ROOT)/platform/posix \
|
||||||
|
-I$(BTSTACK_ROOT)/chipset/zephyr \
|
||||||
|
|
||||||
VPATH += ${BTSTACK_ROOT}/platform/posix
|
VPATH += ${BTSTACK_ROOT}/platform/posix
|
||||||
VPATH += ${BTSTACK_ROOT}/platform/embedded
|
VPATH += ${BTSTACK_ROOT}/platform/embedded
|
||||||
|
VPATH += ${BTSTACK_ROOT}/chipset/zephyr
|
||||||
|
|
||||||
# use pkg-config for portaudio
|
# use pkg-config for portaudio
|
||||||
# CFLAGS += $(shell pkg-config portaudio-2.0 --cflags) -DHAVE_PORTAUDIO
|
# CFLAGS += $(shell pkg-config portaudio-2.0 --cflags) -DHAVE_PORTAUDIO
|
||||||
@ -28,5 +30,5 @@ VPATH += ${BTSTACK_ROOT}/platform/embedded
|
|||||||
# CFLAGS += -I/usr/local/include -DHAVE_PORTAUDIO
|
# CFLAGS += -I/usr/local/include -DHAVE_PORTAUDIO
|
||||||
# LDFLAGS += -L/sw/lib -lportaudio -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,Carbon
|
# LDFLAGS += -L/sw/lib -lportaudio -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,Carbon
|
||||||
|
|
||||||
all: ${EXAMPLES}
|
all: ${EXAMPLES_USING_LE}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include "hci.h"
|
#include "hci.h"
|
||||||
#include "hci_dump.h"
|
#include "hci_dump.h"
|
||||||
#include "btstack_stdin.h"
|
#include "btstack_stdin.h"
|
||||||
|
#include "btstack_chipset_zephyr.h"
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
|
|
||||||
@ -74,14 +75,22 @@ static hci_transport_config_uart_t config = {
|
|||||||
|
|
||||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
|
static const uint8_t read_static_address_command_complete_prefix[] = { 0x0e, 0x1b, 0x01, 0x09, 0xfc };
|
||||||
|
static bd_addr_t static_address;
|
||||||
|
|
||||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
bd_addr_t addr;
|
bd_addr_t addr;
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
switch (hci_event_packet_get_type(packet)){
|
switch (hci_event_packet_get_type(packet)){
|
||||||
case BTSTACK_EVENT_STATE:
|
case BTSTACK_EVENT_STATE:
|
||||||
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break;
|
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break;
|
||||||
gap_local_bd_addr(addr);
|
printf("BTstack up and running as %s\n", bd_addr_to_str(static_address));
|
||||||
printf("BTstack up and running at %s\n", bd_addr_to_str(addr));
|
break;
|
||||||
|
case HCI_EVENT_COMMAND_COMPLETE:
|
||||||
|
if (memcmp(packet, read_static_address_command_complete_prefix, sizeof(read_static_address_command_complete_prefix)) == 0){
|
||||||
|
reverse_48(&packet[7], static_address);
|
||||||
|
gap_random_address_set(addr);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -136,6 +145,7 @@ int main(int argc, const char * argv[]){
|
|||||||
const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance();
|
const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance();
|
||||||
hci_init(transport, (void*) &config);
|
hci_init(transport, (void*) &config);
|
||||||
hci_set_link_key_db(link_key_db);
|
hci_set_link_key_db(link_key_db);
|
||||||
|
hci_set_chipset(btstack_chipset_zephyr_instance());
|
||||||
|
|
||||||
// inform about BTstack state
|
// inform about BTstack state
|
||||||
hci_event_callback_registration.callback = &packet_handler;
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user