mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-12 01:14:17 +00:00
ios: fix compile, streamine function names
This commit is contained in:
parent
fb55bd0acc
commit
d0b87bef91
@ -90,7 +90,7 @@
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <notify.h>
|
||||
#include "../port/ios/src/bt_control_iphone.h"
|
||||
#include "../port/ios/src/btstack_control_iphone.h"
|
||||
#include "../port/ios/src/platform_iphone.h"
|
||||
// support for "enforece wake device" in h4 - used by iOS power management
|
||||
extern void hci_transport_h4_iphone_set_enforce_wake_device(char *path);
|
||||
@ -919,13 +919,13 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
case BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
log_info("BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED %u", packet[3]);
|
||||
iphone_system_bt_set_enabled(packet[3]);
|
||||
hci_emit_system_bluetooth_enabled(iphone_system_bt_enabled());
|
||||
btstack_control_iphone_bt_set_enabled(packet[3]);
|
||||
hci_emit_system_bluetooth_enabled(btstack_control_iphone_bt_enabled());
|
||||
break;
|
||||
|
||||
case BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
log_info("BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED");
|
||||
hci_emit_system_bluetooth_enabled(iphone_system_bt_enabled());
|
||||
hci_emit_system_bluetooth_enabled(btstack_control_iphone_bt_enabled());
|
||||
break;
|
||||
#else
|
||||
case BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
@ -1963,8 +1963,8 @@ int main (int argc, char * const * argv){
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
control = &bt_control_iphone;
|
||||
if (bt_control_iphone_power_management_supported()){
|
||||
control = &btstack_control_iphone;
|
||||
if (btstack_control_iphone_power_management_supported()){
|
||||
hci_transport_h4_iphone_set_enforce_wake_device("/dev/btwake");
|
||||
}
|
||||
bluetooth_status_handler = platform_iphone_status_handler;
|
||||
|
@ -34,7 +34,7 @@ libBTstack_CFLAGS = -I$(BTSTACK_ROOT)/src/ble -I$(BTSTACK_ROOT)/src -I..
|
||||
TOOL_NAME = BTdaemon
|
||||
BTdaemon_FILES = \
|
||||
$(libBTstack_FILES) \
|
||||
bt_control_iphone.m \
|
||||
btstack_control_iphone.m \
|
||||
btstack_memory.c \
|
||||
btstack_memory_pool.c \
|
||||
daemon.c \
|
||||
|
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* bt_control_iphone.h
|
||||
* btstack_control_iphone.h
|
||||
*
|
||||
* BT Control API implementation for the iPhone and the iPod Touch
|
||||
*
|
||||
@ -50,16 +50,21 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern btstack_control_t bt_control_iphone;
|
||||
extern btstack_control_t btstack_control_iphone;
|
||||
|
||||
int bt_control_iphone_power_management_enabled(void);
|
||||
int bt_control_iphone_power_management_supported(void);
|
||||
// power management
|
||||
int btstack_control_iphone_power_management_enabled(void);
|
||||
int btstack_control_iphone_power_management_supported(void);
|
||||
|
||||
int iphone_system_bt_enabled(void);
|
||||
void iphone_system_bt_set_enabled(int enabled);
|
||||
// system bluetooth on/off
|
||||
int btstack_control_iphone_bt_enabled(void);
|
||||
void btstack_control_iphone_bt_set_enabled(int enabled);
|
||||
|
||||
int iphone_system_has_csr(void);
|
||||
int iphone_system_is_valid(void);
|
||||
// does device has Bluetooth support
|
||||
int btstack_control_iphone_is_valid(void);
|
||||
|
||||
// get default transport speed
|
||||
uint32_t btstack_control_iphone_get_transport_speed(void);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* bt_control_iphone.c
|
||||
* btstack_control_iphone.c
|
||||
*
|
||||
* control Bluetooth module using BlueTool
|
||||
*
|
||||
@ -47,7 +47,7 @@
|
||||
|
||||
#include "btstack_config.h"
|
||||
|
||||
#include "bt_control_iphone.h"
|
||||
#include "btstack_control_iphone.h"
|
||||
#include "hci_transport.h"
|
||||
#include "hci.h"
|
||||
#include "btstack_debug.h"
|
||||
@ -125,6 +125,7 @@ IOReturn IOCancelPowerChange ( io_connect_t kernelPort, long notificationID );
|
||||
static io_connect_t root_port = 0; // a reference to the Root Power Domain IOService
|
||||
static int power_notification_pipe_fds[2];
|
||||
static btstack_data_source_t power_notification_ds;
|
||||
static const hci_transport_config_uart_t * hci_transport_config_uart = NULL;
|
||||
|
||||
static void (*power_notification_callback)(POWER_NOTIFICATION_t event) = NULL;
|
||||
|
||||
@ -174,7 +175,7 @@ static char *get_machine_name(void){
|
||||
/**
|
||||
* on iPhone/iPod touch
|
||||
*/
|
||||
int iphone_system_is_valid(void){
|
||||
int btstack_control_iphone_is_valid(void){
|
||||
char * machine = get_machine_name();
|
||||
if (!strncmp("iPod1", machine, strlen("iPod1"))) return 0; // 1st gen touch no BT
|
||||
return 1;
|
||||
@ -203,6 +204,10 @@ static void ioregistry_get_info(void){
|
||||
log_info("transport-speed: %u\n", transport_speed);
|
||||
}
|
||||
|
||||
uint32_t btstack_control_iphone_get_transport_speed(void){
|
||||
return transport_speed;
|
||||
}
|
||||
|
||||
static int iphone_has_csr(void){
|
||||
// construct script path from device name
|
||||
char *machine = get_machine_name();
|
||||
@ -437,22 +442,27 @@ static void iphone_write_configscript(int fd, int baudrate){
|
||||
iphone_write_string(fd, "quit\n");
|
||||
}
|
||||
|
||||
static int iphone_on (const void *transport_config){
|
||||
// hci_transport_config_uart->baudrate_init == 0, if using native speed
|
||||
|
||||
log_info("iphone_on: entered\n");
|
||||
static void iphone_init(const void *transport_config){
|
||||
|
||||
hci_transport_config_uart = NULL;
|
||||
|
||||
// check for hci_transport_config_uart_t
|
||||
if (!transport_config) {
|
||||
log_error("iphone_on: no config!");
|
||||
return -1;
|
||||
log_error("iphone_init: no config!");
|
||||
return;
|
||||
}
|
||||
if (((hci_transport_config_t *)transport_config)->type != HCI_TRANSPORT_CONFIG_UART) {
|
||||
log_error("iphone_on: config not of type != HCI_TRANSPORT_CONFIG_UART!");
|
||||
return -1;
|
||||
log_error("iphone_init: config not of type != HCI_TRANSPORT_CONFIG_UART!");
|
||||
return;
|
||||
}
|
||||
|
||||
hci_transport_config_uart_t * hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
|
||||
hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
|
||||
}
|
||||
|
||||
static int iphone_on (void){
|
||||
// hci_transport_config_uart->baudrate_init == 0, if using native speed
|
||||
|
||||
log_info("iphone_on: entered\n");
|
||||
|
||||
// get local-mac-addr and transport-speed from IORegistry
|
||||
ioregistry_get_info();
|
||||
@ -472,7 +482,7 @@ static int iphone_on (const void *transport_config){
|
||||
bt_store_16(local_mac_address, 4, random());
|
||||
#endif
|
||||
|
||||
if (iphone_system_bt_enabled()){
|
||||
if (btstack_control_iphone_bt_enabled()){
|
||||
perror("iphone_on: System Bluetooth enabled!");
|
||||
return 1;
|
||||
}
|
||||
@ -571,12 +581,13 @@ static int iphone_on (const void *transport_config){
|
||||
};
|
||||
err = pclose(outputFile);
|
||||
|
||||
power_management_active = bt_control_iphone_power_management_supported();
|
||||
power_management_active = btstack_control_iphone_power_management_supported();
|
||||
|
||||
// moved to hci_transport_h4_iphone.c as hci_transport_config_uart is const now
|
||||
// if baud == 0, we're using system default: set in transport config
|
||||
if (hci_transport_config_uart->baudrate_init == 0) {
|
||||
hci_transport_config_uart->baudrate_init = transport_speed;
|
||||
}
|
||||
// if (hci_transport_config_uart->baudrate_init == 0) {
|
||||
// hci_transport_config_uart->baudrate_init = transport_speed;
|
||||
// }
|
||||
|
||||
// if we sleep for about 3 seconds, we miss a strage packet... but we don't care
|
||||
// sleep(3);
|
||||
@ -584,7 +595,7 @@ static int iphone_on (const void *transport_config){
|
||||
return err;
|
||||
}
|
||||
|
||||
static int iphone_off (void *config){
|
||||
static int iphone_off(void){
|
||||
|
||||
// power off (all models)
|
||||
log_info("iphone_off: turn off using BlueTool\n");
|
||||
@ -615,7 +626,7 @@ static int iphone_off (void *config){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iphone_sleep(void *config){
|
||||
static int iphone_sleep(void){
|
||||
|
||||
// will sleep by itself
|
||||
if (power_management_active) return 0;
|
||||
@ -625,7 +636,7 @@ static int iphone_sleep(void *config){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iphone_wake(void *config){
|
||||
static int iphone_wake(void){
|
||||
|
||||
// will wake by itself
|
||||
if (power_management_active) return 0;
|
||||
@ -738,7 +749,7 @@ void iphone_register_for_power_notifications(void (*cb)(POWER_NOTIFICATION_t eve
|
||||
btstack_run_loop_add_data_source(&power_notification_ds);
|
||||
}
|
||||
|
||||
int bt_control_iphone_power_management_supported(void){
|
||||
int btstack_control_iphone_power_management_supported(void){
|
||||
// only supported on Broadcom chipsets with iOS 4.0+
|
||||
if ( iphone_has_csr()) return 0;
|
||||
if (!iphone_os_at_least_40()) return 0;
|
||||
@ -746,12 +757,13 @@ int bt_control_iphone_power_management_supported(void){
|
||||
}
|
||||
|
||||
// direct access
|
||||
int bt_control_iphone_power_management_enabled(void){
|
||||
int btstack_control_iphone_power_management_enabled(void){
|
||||
return power_management_active;
|
||||
}
|
||||
|
||||
// single instance
|
||||
btstack_control_t bt_control_iphone = {
|
||||
btstack_control_t btstack_control_iphone = {
|
||||
.init = iphone_init,
|
||||
.on = iphone_on,
|
||||
.off = iphone_off,
|
||||
.sleep = iphone_sleep,
|
||||
@ -759,16 +771,13 @@ btstack_control_t bt_control_iphone = {
|
||||
.register_for_power_notifications = iphone_register_for_power_notifications
|
||||
};
|
||||
|
||||
int iphone_system_bt_enabled(void){
|
||||
int btstack_control_iphone_bt_enabled(void){
|
||||
return SBA_getBluetoothEnabled();
|
||||
}
|
||||
|
||||
void iphone_system_bt_set_enabled(int enabled)
|
||||
void btstack_control_iphone_bt_set_enabled(int enabled)
|
||||
{
|
||||
SBA_setBluetoothEnabled(enabled);
|
||||
sleep(2); // give change a chance
|
||||
}
|
||||
|
||||
int iphone_system_has_csr(void){
|
||||
return iphone_has_csr();
|
||||
}
|
@ -46,6 +46,7 @@
|
||||
*/
|
||||
|
||||
#include "btstack_config.h"
|
||||
#include "btstack_control_iphone.h"
|
||||
|
||||
#define SOCKET_DEVICE "com.apple.uart.bluetooth"
|
||||
#include <sys/socket.h>
|
||||
@ -132,7 +133,7 @@ static int read_pos;
|
||||
|
||||
static uint8_t hci_packet[1+HCI_PACKET_BUFFER_SIZE]; // packet type + max(acl header + acl payload, event header + event data)
|
||||
|
||||
static int h4_open(void *transport_config)
|
||||
static int h4_open(const void *transport_config)
|
||||
{
|
||||
hci_transport_config_uart = (hci_transport_config_uart_t *) transport_config;
|
||||
|
||||
@ -186,6 +187,12 @@ static int h4_open(void *transport_config)
|
||||
goto err_out3;
|
||||
}
|
||||
|
||||
uint32_t baud = hci_transport_config_uart->baudrate_init;
|
||||
// if baud == 0, we're using system default: set in transport config
|
||||
if (baud == 0) {
|
||||
baud = btstack_control_iphone_get_transport_speed();
|
||||
}
|
||||
|
||||
// make raw and set speed
|
||||
cfmakeraw(&toptions);
|
||||
speed_t brate = (speed_t) hci_transport_config_uart->baudrate_init;
|
||||
@ -228,7 +235,7 @@ err_out0:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int h4_close(void *transport_config){
|
||||
static int h4_close(const void *transport_config){
|
||||
// first remove run loop handler
|
||||
btstack_run_loop_remove_data_source(hci_transport_h4->ds);
|
||||
|
||||
|
@ -58,11 +58,12 @@ typedef enum {
|
||||
} POWER_NOTIFICATION_t;
|
||||
|
||||
typedef struct {
|
||||
int (*on) (const void *config); // <-- turn BT module on and configure
|
||||
int (*off) (const void *config); // <-- turn BT module off
|
||||
int (*sleep)(const void *config); // <-- put BT module to sleep - only to be called after ON
|
||||
int (*wake) (const void *config); // <-- wake BT module from sleep - only to be called after SLEEP
|
||||
void (*register_for_power_notifications)(void (*cb)(POWER_NOTIFICATION_t event));
|
||||
void (*init) (const void *config);
|
||||
int (*on) (void); // <-- turn BT module on and configure
|
||||
int (*off) (void); // <-- turn BT module off
|
||||
int (*sleep)(void); // <-- put BT module to sleep - only to be called after ON
|
||||
int (*wake) (void); // <-- wake BT module from sleep - only to be called after SLEEP
|
||||
void (*register_for_power_notifications)(void (*cb)(POWER_NOTIFICATION_t event));
|
||||
} btstack_control_t;
|
||||
|
||||
#if defined __cplusplus
|
||||
|
26
src/hci.c
26
src/hci.c
@ -50,7 +50,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
#include "../port/ios/src/bt_control_iphone.h"
|
||||
#include "../port/ios/src/btstack_control_iphone.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BLE
|
||||
@ -1956,11 +1956,13 @@ void hci_set_chipset(const btstack_chipset_t *chipset_driver){
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure Bluetooth hardware control. Has to be called before power on.
|
||||
* @brief Configure Bluetooth hardware control. Has to be called after hci_init() but before power on.
|
||||
*/
|
||||
void hci_set_control(const btstack_control_t *hardware_control){
|
||||
// references to used control implementation
|
||||
hci_stack->control = hardware_control;
|
||||
// init with transport config
|
||||
hardware_control->init(hci_stack->config);
|
||||
}
|
||||
|
||||
void hci_close(void){
|
||||
@ -2008,7 +2010,7 @@ static int hci_power_control_on(void){
|
||||
// power on
|
||||
int err = 0;
|
||||
if (hci_stack->control && hci_stack->control->on){
|
||||
err = (*hci_stack->control->on)(hci_stack->config);
|
||||
err = (*hci_stack->control->on)();
|
||||
}
|
||||
if (err){
|
||||
log_error( "POWER_ON failed");
|
||||
@ -2026,7 +2028,7 @@ static int hci_power_control_on(void){
|
||||
if (err){
|
||||
log_error( "HCI_INIT failed, turning Bluetooth off again");
|
||||
if (hci_stack->control && hci_stack->control->off){
|
||||
(*hci_stack->control->off)(hci_stack->config);
|
||||
(*hci_stack->control->off)();
|
||||
}
|
||||
hci_emit_hci_open_failed();
|
||||
return err;
|
||||
@ -2045,7 +2047,7 @@ static void hci_power_control_off(void){
|
||||
|
||||
// power off
|
||||
if (hci_stack->control && hci_stack->control->off){
|
||||
(*hci_stack->control->off)(hci_stack->config);
|
||||
(*hci_stack->control->off)();
|
||||
}
|
||||
|
||||
log_info("hci_power_control_off - control closed");
|
||||
@ -2066,7 +2068,7 @@ static void hci_power_control_sleep(void){
|
||||
|
||||
// sleep mode
|
||||
if (hci_stack->control && hci_stack->control->sleep){
|
||||
(*hci_stack->control->sleep)(hci_stack->config);
|
||||
(*hci_stack->control->sleep)();
|
||||
}
|
||||
|
||||
hci_stack->state = HCI_STATE_SLEEPING;
|
||||
@ -2078,7 +2080,7 @@ static int hci_power_control_wake(void){
|
||||
|
||||
// wake on
|
||||
if (hci_stack->control && hci_stack->control->wake){
|
||||
(*hci_stack->control->wake)(hci_stack->config);
|
||||
(*hci_stack->control->wake)();
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -2087,7 +2089,7 @@ static int hci_power_control_wake(void){
|
||||
if (err){
|
||||
log_error( "HCI_INIT failed, turning Bluetooth off again");
|
||||
if (hci_stack->control && hci_stack->control->off){
|
||||
(*hci_stack->control->off)(hci_stack->config);
|
||||
(*hci_stack->control->off)();
|
||||
}
|
||||
hci_emit_hci_open_failed();
|
||||
return err;
|
||||
@ -2186,7 +2188,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
// nothing to do, if H4 supports power management
|
||||
if (bt_control_iphone_power_management_enabled()){
|
||||
if (btstack_control_iphone_power_management_enabled()){
|
||||
hci_stack->state = HCI_STATE_INITIALIZING;
|
||||
hci_stack->substate = HCI_INIT_WRITE_SCAN_ENABLE; // init after sleep
|
||||
break;
|
||||
@ -2210,7 +2212,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
// nothing to do, if H4 supports power management
|
||||
if (bt_control_iphone_power_management_enabled()){
|
||||
if (btstack_control_iphone_power_management_enabled()){
|
||||
hci_stack->state = HCI_STATE_INITIALIZING;
|
||||
hci_stack->substate = HCI_INIT_AFTER_SLEEP;
|
||||
hci_update_scan_enable();
|
||||
@ -2668,7 +2670,7 @@ void hci_run(void){
|
||||
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
// don't close connections, if H4 supports power management
|
||||
if (bt_control_iphone_power_management_enabled()){
|
||||
if (btstack_control_iphone_power_management_enabled()){
|
||||
connection = NULL;
|
||||
}
|
||||
#endif
|
||||
@ -2702,7 +2704,7 @@ void hci_run(void){
|
||||
log_info("HCI_STATE_HALTING, calling sleep");
|
||||
#ifdef HAVE_PLATFORM_IPHONE_OS
|
||||
// don't actually go to sleep, if H4 supports power management
|
||||
if (bt_control_iphone_power_management_enabled()){
|
||||
if (btstack_control_iphone_power_management_enabled()){
|
||||
// SLEEP MODE reached
|
||||
hci_stack->state = HCI_STATE_SLEEPING;
|
||||
hci_emit_state();
|
||||
|
Loading…
x
Reference in New Issue
Block a user