mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-25 09:02:30 +00:00
Add support for modified BlueTool scripts on 3.0
This commit is contained in:
parent
a7425eb1ec
commit
c828bcdbdb
@ -20,13 +20,29 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
// minimal IOKit
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <Availability.h>
|
||||||
|
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_2_0
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#define IOKIT
|
||||||
|
#include <device/device_types.h>
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
kern_return_t IOMasterPort( mach_port_t bootstrapPort, mach_port_t * masterPort );
|
||||||
|
CFMutableDictionaryRef IOServiceNameMatching(const char * name );
|
||||||
|
CFTypeRef IORegistryEntrySearchCFProperty(mach_port_t entry, const io_name_t plane,
|
||||||
|
CFStringRef key, CFAllocatorRef allocator, UInt32 options );
|
||||||
|
mach_port_t IOServiceGetMatchingService(mach_port_t masterPort, CFDictionaryRef matching );
|
||||||
|
kern_return_t IOObjectRelease(mach_port_t object);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BUFF_LEN 80
|
#define BUFF_LEN 80
|
||||||
static char buffer[BUFF_LEN+1];
|
static char buffer[BUFF_LEN+1];
|
||||||
|
|
||||||
// bd addr for iPod touch -- undef if you have compiling problems
|
// bd addr from iphone/ipod IORegistry
|
||||||
#define iPodTouchSupport
|
// the Broadcom chipsets done store a BD_ADDR and the one on the iPhone
|
||||||
|
// is different to the one reported by About in the Settings app
|
||||||
static bd_addr_t ioRegAddr;
|
static bd_addr_t ioRegAddr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,18 +69,8 @@ static const char * iphone_name(void *config){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get BD_ADDR from IORegistry
|
// Get BD_ADDR from IORegistry
|
||||||
#if defined(__APPLE__) && defined(iPodTouchSupport)
|
|
||||||
#include <mach/mach.h>
|
|
||||||
#define IOKIT
|
|
||||||
#include <device/device_types.h>
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
|
||||||
kern_return_t IOMasterPort( mach_port_t bootstrapPort, mach_port_t * masterPort );
|
|
||||||
CFMutableDictionaryRef IOServiceNameMatching(const char * name );
|
|
||||||
CFTypeRef IORegistryEntrySearchCFProperty(mach_port_t entry, const io_name_t plane,
|
|
||||||
CFStringRef key, CFAllocatorRef allocator, UInt32 options );
|
|
||||||
mach_port_t IOServiceGetMatchingService(mach_port_t masterPort, CFDictionaryRef matching );
|
|
||||||
kern_return_t IOObjectRelease(mach_port_t object);
|
|
||||||
static void ioregistry_get_bd_addr() {
|
static void ioregistry_get_bd_addr() {
|
||||||
|
#ifdef IOKIT
|
||||||
mach_port_t mp;
|
mach_port_t mp;
|
||||||
IOMasterPort(MACH_PORT_NULL,&mp);
|
IOMasterPort(MACH_PORT_NULL,&mp);
|
||||||
CFMutableDictionaryRef bt_matching = IOServiceNameMatching("bluetooth");
|
CFMutableDictionaryRef bt_matching = IOServiceNameMatching("bluetooth");
|
||||||
@ -72,9 +78,14 @@ static void ioregistry_get_bd_addr() {
|
|||||||
CFTypeRef bt_typeref = IORegistryEntrySearchCFProperty(bt_service,"IODevicTree",CFSTR("local-mac-address"), kCFAllocatorDefault, 1);
|
CFTypeRef bt_typeref = IORegistryEntrySearchCFProperty(bt_service,"IODevicTree",CFSTR("local-mac-address"), kCFAllocatorDefault, 1);
|
||||||
CFDataGetBytes(bt_typeref,CFRangeMake(0,CFDataGetLength(bt_typeref)),ioRegAddr); // buffer needs to be unsigned char
|
CFDataGetBytes(bt_typeref,CFRangeMake(0,CFDataGetLength(bt_typeref)),ioRegAddr); // buffer needs to be unsigned char
|
||||||
IOObjectRelease(bt_service);
|
IOObjectRelease(bt_service);
|
||||||
}
|
#else
|
||||||
|
// use dummy addr if not on iphone/ipod touch
|
||||||
|
int i = 0;
|
||||||
|
for (i=0;i<6;i++) {
|
||||||
|
ioRegAddr[i] = i;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void iphone_set_pskey(int fd, int key, int value){
|
static void iphone_set_pskey(int fd, int key, int value){
|
||||||
sprintf(buffer, "csr -p 0x%04x=0x%04x\n", key, value);
|
sprintf(buffer, "csr -p 0x%04x=0x%04x\n", key, value);
|
||||||
@ -100,12 +111,11 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
} else {
|
} else {
|
||||||
// It's an iPod Touch (2G)
|
// It's an iPod Touch (2G)
|
||||||
strcat(buffer, ".boot.script");
|
strcat(buffer, ".boot.script");
|
||||||
// then, get bd_addr from IORegistry
|
|
||||||
#ifdef iPodTouchSupport
|
|
||||||
ioregistry_get_bd_addr();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get bd_addr from IORegistry
|
||||||
|
ioregistry_get_bd_addr();
|
||||||
|
|
||||||
// open script
|
// open script
|
||||||
int input = open(buffer, O_RDONLY);
|
int input = open(buffer, O_RDONLY);
|
||||||
|
|
||||||
@ -144,22 +154,33 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// iPhone - set BD_ADDR after "csr -i"
|
||||||
|
if (store == 1 && pos == 6 && strncmp(buffer, "csr -i", 6) == 0) {
|
||||||
|
store = 0;
|
||||||
|
write(output, buffer, pos); // "csr -i"
|
||||||
|
sprintf(buffer,"\ncsr -p 0x0001=0x00%.2x,0x%.2x%.2x,0x00%.2x,0x%.2x%.2x\n",
|
||||||
|
ioRegAddr[3], ioRegAddr[4], ioRegAddr[5], ioRegAddr[2], ioRegAddr[0], ioRegAddr[1]);
|
||||||
|
write(output, buffer, 42);
|
||||||
|
}
|
||||||
|
|
||||||
// iPod2,1
|
// iPod2,1
|
||||||
// check for "bcm -X" cmds
|
// check for "bcm -X" cmds
|
||||||
if (store == 1 && pos == 7){
|
if (store == 1 && pos == 6){
|
||||||
if (strncmp(buffer, "bcm -", 5) == 0) {
|
if (strncmp(buffer, "bcm -", 5) == 0) {
|
||||||
store = 0;
|
store = 0;
|
||||||
switch (buffer[5]){
|
switch (buffer[5]){
|
||||||
case 'a': // BT Address
|
case 'a': // BT Address
|
||||||
write(output, buffer, pos); // "bcm -a "
|
write(output, buffer, pos); // "bcm -a"
|
||||||
sprintf(buffer, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", ioRegAddr[0], ioRegAddr[1],
|
sprintf(buffer, " %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", ioRegAddr[0], ioRegAddr[1],
|
||||||
ioRegAddr[2], ioRegAddr[3], ioRegAddr[4], ioRegAddr[5]);
|
ioRegAddr[2], ioRegAddr[3], ioRegAddr[4], ioRegAddr[5]);
|
||||||
write(output, buffer, 18);
|
write(output, buffer, 18);
|
||||||
mirror = 0;
|
mirror = 0;
|
||||||
break;
|
break;
|
||||||
case 'b': // baud rate command
|
case 'b': // baud rate command OS 2.x
|
||||||
write(output, buffer, pos); // "bcm -b "
|
case 'B': // baud rate command OS 3.x
|
||||||
sprintf(buffer, "%u\n", uart_config->baudrate);
|
buffer[5] = 'b';
|
||||||
|
write(output, buffer, pos); // "bcm -b"
|
||||||
|
sprintf(buffer, " %u\n", uart_config->baudrate);
|
||||||
write(output, buffer, strlen(buffer));
|
write(output, buffer, strlen(buffer));
|
||||||
mirror = 0;
|
mirror = 0;
|
||||||
break;
|
break;
|
||||||
@ -174,7 +195,25 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// iPhone1,1 & iPhone 2,1:
|
// iPhone1,1 & iPhone 2,1: OS 3.x
|
||||||
|
// check for "csr -B" and "csr -T"
|
||||||
|
if (store == 1 && pos == 6){
|
||||||
|
if (strncmp(buffer, "csr -", 5) == 0) {
|
||||||
|
switch(buffer[5]){
|
||||||
|
case 'T': // Transport Mode
|
||||||
|
store = 0;
|
||||||
|
break;
|
||||||
|
case 'B': // Baud rate
|
||||||
|
iphone_set_pskey(output, 0x01be, baud_key);
|
||||||
|
store = 0;
|
||||||
|
break;
|
||||||
|
default: // wait for full command
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// iPhone1,1 & iPhone 2,1: OS 2.x
|
||||||
// check for "csr -p 0x1234=0x5678" (20)
|
// check for "csr -p 0x1234=0x5678" (20)
|
||||||
if (store == 1 && pos == 20) {
|
if (store == 1 && pos == 20) {
|
||||||
int pskey, value;
|
int pskey, value;
|
||||||
@ -208,7 +247,7 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
|
|
||||||
static int iphone_on (void *config){
|
static int iphone_on (void *config){
|
||||||
#if 0
|
#if 0
|
||||||
// use tmp file
|
// use tmp file for testing
|
||||||
int output = open("/tmp/bt.init", O_WRONLY | O_CREAT | O_TRUNC);
|
int output = open("/tmp/bt.init", O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
iphone_write_initscript(config, output);
|
iphone_write_initscript(config, output);
|
||||||
close(output);
|
close(output);
|
||||||
@ -231,7 +270,7 @@ static int iphone_on (void *config){
|
|||||||
pclose(outputFile);
|
pclose(outputFile);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// if we sleep for about 3 seconds, we miss a strage packet
|
// if we sleep for about 3 seconds, we miss a strage packet... but we don't care
|
||||||
// sleep(3);
|
// sleep(3);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user