mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-01 04:20:33 +00:00
get bd_addr from IORegistry on iPod touch
This commit is contained in:
parent
72b8ef13ac
commit
e938d609c9
@ -4,18 +4,24 @@ SRCDIR = src
|
|||||||
VPATH = src
|
VPATH = src
|
||||||
|
|
||||||
# These paths must be changed to match the compilation environment
|
# These paths must be changed to match the compilation environment
|
||||||
SDK_PATH = /Developer/Platforms/iPhoneOS.platform/Developer
|
DEVELOPER_PATH = /Developer/Platforms/iPhoneOS.platform/Developer
|
||||||
SDK_VERSION = 2.1
|
SDK_VERSION = 2.1
|
||||||
|
SDK_PATH = $(DEVELOPER_PATH)/SDKs/iPhoneOS$(SDK_VERSION).sdk
|
||||||
GCC_VERSION = 4.0.1
|
GCC_VERSION = 4.0.1
|
||||||
|
|
||||||
#
|
#
|
||||||
CXX = $(SDK_PATH)/usr/bin/arm-apple-darwin9-gcc-$(GCC_VERSION)
|
CC = $(DEVELOPER_PATH)/usr/bin/arm-apple-darwin9-gcc-$(GCC_VERSION)
|
||||||
CXXFLAGS = -g0 -O2 -Wall -Werror -I. -Iinclude
|
CFLAGS = -g0 -O2 -Wall -Werror -I. -Iinclude \
|
||||||
|
-I$(SDK_PATH)/usr/include \
|
||||||
|
-I$(SDK_PATH)/usr/lib/gcc/arm-apple-darwin9/4.0.1/include \
|
||||||
|
-F$(SDK_PATH)/System/Library/Frameworks \
|
||||||
|
|
||||||
LDFLAGS = \
|
LDFLAGS = \
|
||||||
-multiply_defined suppress \
|
-multiply_defined suppress \
|
||||||
-I$(SDK_PATH)/SDKs/iPhoneOS$(SDK_VERSION).sdk/usr/include \
|
-L$(SDK_PATH)/usr/lib \
|
||||||
-I$(SDK_PATH)/SDKs/iPhoneOS$(SDK_VERSION).sdk/usr/lib/gcc/arm-apple-darwin9/4.0.1/include \
|
-framework CoreFoundation \
|
||||||
-L$(SDK_PATH)/SDKs/iPhoneOS$(SDK_VERSION).sdk/usr/lib \
|
-L$(SDK_PATH)/System/Library/Frameworks/IOKit.framework/Versions/A \
|
||||||
|
-lIOKit
|
||||||
|
|
||||||
SRCS = \
|
SRCS = \
|
||||||
bt_control_iphone.c \
|
bt_control_iphone.c \
|
||||||
@ -46,7 +52,7 @@ clean:
|
|||||||
$(SRCS): $(HEADERS)
|
$(SRCS): $(HEADERS)
|
||||||
|
|
||||||
$(NAME): $(SRCS)
|
$(NAME): $(SRCS)
|
||||||
$(CXX) $(CXXFLAGS) -o $(NAME) $(filter %.mm,$^) $(filter %.m,$^) $(filter %.c,$^) $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $(NAME) $(filter %.mm,$^) $(filter %.m,$^) $(filter %.c,$^) $(LDFLAGS)
|
||||||
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $(NAME)
|
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $(NAME)
|
||||||
ssh root@192.168.3.102 rm -f BTdaemon
|
ssh root@192.168.3.102 rm -f BTdaemon
|
||||||
scp $(NAME) root@192.168.3.102:/var/mobile
|
scp $(NAME) root@192.168.3.102:/var/mobile
|
||||||
|
@ -46,6 +46,31 @@ static const char * iphone_name(void *config){
|
|||||||
return get_machine_name();
|
return get_machine_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get BD_ADDR from IORegistry
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#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 bd_addr_t ioRegAddr;
|
||||||
|
static void ioregistry_get_bd_addr() {
|
||||||
|
mach_port_t mp;
|
||||||
|
IOMasterPort(MACH_PORT_NULL,&mp);
|
||||||
|
CFMutableDictionaryRef bt_matching = IOServiceNameMatching("bluetooth");
|
||||||
|
mach_port_t bt_service = IOServiceGetMatchingService(mp, bt_matching);
|
||||||
|
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
|
||||||
|
IOObjectRelease(bt_service);
|
||||||
|
}
|
||||||
|
#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);
|
||||||
write(fd, buffer, 21);
|
write(fd, buffer, 21);
|
||||||
@ -58,10 +83,7 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
|
|
||||||
// calculate baud rate (assume rate is multiply of 100)
|
// calculate baud rate (assume rate is multiply of 100)
|
||||||
uint32_t baud_key = (4096 * (uart_config->baudrate/100) + 4999) / 10000;
|
uint32_t baud_key = (4096 * (uart_config->baudrate/100) + 4999) / 10000;
|
||||||
printf("Baud key %u\n", baud_key);
|
// printf("Baud key %u\n", baud_key);
|
||||||
|
|
||||||
// pick random BT address
|
|
||||||
uint32_t random_nr = random();
|
|
||||||
|
|
||||||
// construct script path from device name
|
// construct script path from device name
|
||||||
strcpy(buffer, "/etc/bluetool/");
|
strcpy(buffer, "/etc/bluetool/");
|
||||||
@ -73,6 +95,8 @@ 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
|
||||||
|
ioregistry_get_bd_addr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// open script
|
// open script
|
||||||
@ -121,8 +145,8 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
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, "00:00:%.2x:%.2x:%.2x:%.2x\n", random_nr & 0xff, (random_nr >> 8) & 0xff,
|
sprintf(buffer, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", ioRegAddr[0], ioRegAddr[1],
|
||||||
(random_nr >> 16) & 0xff, (random_nr >> 24) & 0xff);
|
ioRegAddr[2], ioRegAddr[3], ioRegAddr[4], ioRegAddr[5]);
|
||||||
write(output, buffer, 18);
|
write(output, buffer, 18);
|
||||||
mirror = 0;
|
mirror = 0;
|
||||||
break;
|
break;
|
||||||
@ -176,6 +200,7 @@ static int iphone_write_initscript (void *config, int output){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int iphone_on (void *config){
|
static int iphone_on (void *config){
|
||||||
|
ioregistry_get_bd_addr();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// use tmp file
|
// use tmp file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user