mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-10 15:40:11 +00:00
added iPhone Bluetooth toggle functions
This commit is contained in:
parent
369d79a9c1
commit
2ed6235c61
@ -43,6 +43,6 @@
|
||||
typedef struct {
|
||||
int (*on)(void *config); // <-- turn BT module on and configure
|
||||
int (*off)(void *config); // <-- turn BT module off
|
||||
int (*valid)(void *confif); // <-- test if hardware can be supported
|
||||
const char * (*name)(void *config); // <-- return hardware name
|
||||
int (*valid)(void *config); // <-- test if hardware can be supported
|
||||
const char * (*name)(void *config); // <-- return hardware name
|
||||
} bt_control_t;
|
||||
|
@ -41,3 +41,6 @@
|
||||
|
||||
extern bt_control_t bt_control_iphone;
|
||||
|
||||
// control system Bluetooth
|
||||
int iphone_system_bt_enabled();
|
||||
void iphone_system_bt_set_enabled(int enabled);
|
||||
|
@ -35,6 +35,8 @@
|
||||
* control Bluetooth module using BlueTool
|
||||
*
|
||||
* Created by Matthias Ringwald on 5/19/09.
|
||||
*
|
||||
* Bluetooth Toggle by BigBoss
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
@ -70,6 +72,54 @@ kern_return_t IOObjectRelease(mach_port_t object);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// minimal BluetoothManager swiped from BigBoss SBSettings Toggle
|
||||
#import <Foundation/Foundation.h>
|
||||
@class UIDevice;
|
||||
@interface BluetoothManager : NSObject
|
||||
+ (BluetoothManager *) sharedInstance;
|
||||
- (void) setPowered:(BOOL)powered;
|
||||
- (void) setEnabled:(BOOL)enabled;
|
||||
- (BOOL) enabled;
|
||||
@end
|
||||
#define kAppBTServer CFSTR("com.apple.BTServer")
|
||||
#define kKeyBTPowered CFSTR("defaultPoweredState")
|
||||
#define kAppNetwork CFSTR("com.apple.preferences.network")
|
||||
#define kKeyBTNetwork CFSTR("bluetooth-network")
|
||||
|
||||
int iphone_system_bt_enabled(){
|
||||
if ([[BluetoothManager sharedInstance] enabled]) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void iphone_system_bt_set_enabled(int enabled)
|
||||
{
|
||||
/* Get a copy of the global bluetooth server */
|
||||
BluetoothManager *bm = [BluetoothManager sharedInstance];
|
||||
if ( [bm enabled] && enabled) return;
|
||||
if (![bm enabled] && !enabled) return;
|
||||
|
||||
if (enabled) {
|
||||
/* Store into preferences that bluetooth should start on system boot */
|
||||
CFPreferencesSetAppValue(kKeyBTNetwork, kCFBooleanTrue, kAppNetwork);
|
||||
|
||||
/* Turn bluetooth on */
|
||||
[bm setPowered:YES];
|
||||
} else {
|
||||
/* Store into preferences taht bluetooth should not start on system boot */
|
||||
CFPreferencesSetAppValue(kKeyBTNetwork, kCFBooleanFalse, kAppNetwork);
|
||||
|
||||
/* Turn bluetooth off */
|
||||
[bm setEnabled:NO];
|
||||
}
|
||||
/* Synchronize to preferences, e.g. write to disk, bluetooth settings */
|
||||
CFPreferencesAppSynchronize(kAppNetwork);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define BUFF_LEN 80
|
||||
static char buffer[BUFF_LEN+1];
|
||||
|
||||
@ -92,10 +142,9 @@ static char *get_machine_name(void){
|
||||
*/
|
||||
static int iphone_valid(void *config){
|
||||
char * machine = get_machine_name();
|
||||
if (!strncmp("iPhone", machine, strlen("iPhone" ))) return 1;
|
||||
if (!strncmp("iPod2,1", machine, strlen("iPod2,1"))) return 1;
|
||||
if (!strncmp("iPod3,1", machine, strlen("iPod3,1"))) return 1;
|
||||
return 0;
|
||||
if (!strncmp("iPhone", machine, strlen("iPhone" ))) return 1; // iPhone OK
|
||||
if (!strncmp("iPod1", machine, strlen("iPod1"))) return 0; // 1st gen touch no BT
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char * iphone_name(void *config){
|
||||
@ -276,16 +325,24 @@ static int iphone_write_initscript (hci_uart_config_t *uart_config, int output){
|
||||
}
|
||||
|
||||
static int iphone_on (void *transport_config){
|
||||
|
||||
// quick test if Bluetooth UART can be opened
|
||||
|
||||
hci_uart_config_t * hci_uart_config = (hci_uart_config_t*) transport_config;
|
||||
|
||||
#if 0
|
||||
// quick test if Bluetooth UART can be opened
|
||||
int fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (fd == -1) {
|
||||
perror("init_serialport: Unable to open port ");
|
||||
perror("iphone_on: Unable to open port ");
|
||||
perror(hci_uart_config->device_name);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
#else
|
||||
if (iphone_system_bt_enabled()){
|
||||
perror("iphone_on: System Bluetooth enabled!");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int err = 0;
|
||||
#if 0
|
||||
|
13
src/daemon.c
13
src/daemon.c
@ -118,6 +118,19 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
case BTSTACK_GET_VERSION:
|
||||
hci_emit_btstack_version();
|
||||
break;
|
||||
#ifdef USE_BLUETOOL
|
||||
case BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
iphone_system_bt_set_enabled(packet[3]);
|
||||
// fall through .. :)
|
||||
case BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
hci_emit_system_bluetooth_enabled(iphone_system_bt_enabled());
|
||||
break;
|
||||
#else
|
||||
case BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
case BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
hci_emit_system_bluetooth_enabled(0);
|
||||
break;
|
||||
#endif
|
||||
case L2CAP_CREATE_CHANNEL:
|
||||
bt_flip_addr(addr, &packet[3]);
|
||||
psm = READ_BT_16(packet, 9);
|
||||
|
12
src/hci.c
12
src/hci.c
@ -43,7 +43,8 @@
|
||||
#include "hci.h"
|
||||
#include "hci_dump.h"
|
||||
|
||||
#include <btstack/version.h>
|
||||
#include "../include/btstack/hci_cmds.h"
|
||||
#include "../include/btstack/version.h"
|
||||
|
||||
// temp
|
||||
#include "l2cap.h"
|
||||
@ -498,3 +499,12 @@ void hci_emit_btstack_version() {
|
||||
hci_stack.event_packet_handler(event, len);
|
||||
}
|
||||
|
||||
void hci_emit_system_bluetooth_enabled(uint8_t enabled){
|
||||
uint8_t len = 3;
|
||||
uint8_t event[len];
|
||||
event[0] = BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED;
|
||||
event[1] = len - 3;
|
||||
event[2] = enabled;
|
||||
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
|
||||
hci_stack.event_packet_handler(event, len);
|
||||
}
|
||||
|
@ -73,6 +73,12 @@
|
||||
// get BTstack version
|
||||
#define BTSTACK_GET_VERSION 0x04
|
||||
|
||||
// get system Bluetooth state
|
||||
#define BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED 0x05
|
||||
|
||||
// set system Bluetooth state
|
||||
#define BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED 0x06
|
||||
|
||||
// create l2cap channel: @param bd_addr(48), psm (16)
|
||||
#define L2CAP_CREATE_CHANNEL 0x20
|
||||
|
||||
@ -201,4 +207,4 @@ void hci_emit_l2cap_check_timeout(hci_connection_t *conn);
|
||||
void hci_emit_nr_connections_changed();
|
||||
void hci_emit_hci_open_failed();
|
||||
void hci_emit_btstack_version();
|
||||
|
||||
void hci_emit_system_bluetooth_enabled(uint8_t enabled);
|
||||
|
@ -268,7 +268,15 @@ OPCODE(OGF_BTSTACK, BTSTACK_SET_ACL_CAPTURE_MODE), "1"
|
||||
};
|
||||
|
||||
hci_cmd_t btstack_get_version = {
|
||||
OPCODE(OGF_BTSTACK, BTSTACK_GET_VERSION), ""
|
||||
OPCODE(OGF_BTSTACK, BTSTACK_GET_VERSION), ""
|
||||
};
|
||||
|
||||
hci_cmd_t btstack_get_system_bluetooth_enabled = {
|
||||
OPCODE(OGF_BTSTACK, BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED), ""
|
||||
};
|
||||
|
||||
hci_cmd_t btstack_set_system_bluetooth_enabled = {
|
||||
OPCODE(OGF_BTSTACK, BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED), "1"
|
||||
};
|
||||
|
||||
hci_cmd_t l2cap_create_channel = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user