mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-24 06:02:43 +00:00
fix iPhone initializing - now working
This commit is contained in:
parent
d3865d4eec
commit
b670f30d2c
@ -42,28 +42,20 @@ static const char * iphone_name(void *config){
|
|||||||
return get_machine_name();
|
return get_machine_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int iphone_on (void *config){
|
|
||||||
// get path to script
|
static int iphone_write_initscript (void *config, int output){
|
||||||
|
// construct script path from device name
|
||||||
strcpy(buffer, "/etc/bluetool/");
|
strcpy(buffer, "/etc/bluetool/");
|
||||||
char *machine = get_machine_name();
|
char *machine = get_machine_name();
|
||||||
strcat(buffer, machine);
|
strcat(buffer, machine);
|
||||||
strcat(buffer, ".init.script");
|
strcat(buffer, ".init.script");
|
||||||
|
|
||||||
// hack
|
|
||||||
// strcpy(buffer, "iPhone1,2.init.script");
|
|
||||||
|
|
||||||
// open script
|
// open script
|
||||||
int input = open(buffer, O_RDONLY);
|
int input = open(buffer, O_RDONLY);
|
||||||
|
|
||||||
// open tool
|
|
||||||
FILE * outputFile = popen("BlueTool", "r+");
|
|
||||||
int output = fileno(outputFile);
|
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int mirror = 0;
|
int mirror = 0;
|
||||||
int store = 1;
|
int store = 1;
|
||||||
struct timeval noTime;
|
|
||||||
bzero (&noTime, sizeof(struct timeval));
|
|
||||||
while (1){
|
while (1){
|
||||||
int chars = read(input, &buffer[pos], 1);
|
int chars = read(input, &buffer[pos], 1);
|
||||||
|
|
||||||
@ -72,11 +64,9 @@ static int iphone_on (void *config){
|
|||||||
if (store) {
|
if (store) {
|
||||||
// stored characters
|
// stored characters
|
||||||
write(output, buffer, pos+chars);
|
write(output, buffer, pos+chars);
|
||||||
write(fileno(stdout), buffer, pos+chars);
|
|
||||||
}
|
}
|
||||||
if (mirror) {
|
if (mirror) {
|
||||||
write(output, "\n", 1);
|
write(output, "\n", 1);
|
||||||
write(fileno(stdout), "\n", 1);
|
|
||||||
}
|
}
|
||||||
pos = 0;
|
pos = 0;
|
||||||
mirror = 0;
|
mirror = 0;
|
||||||
@ -91,7 +81,6 @@ static int iphone_on (void *config){
|
|||||||
// mirror
|
// mirror
|
||||||
if (mirror){
|
if (mirror){
|
||||||
write(output, &buffer[pos], 1);
|
write(output, &buffer[pos], 1);
|
||||||
write(fileno(stdout), &buffer[pos], 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// store
|
// store
|
||||||
@ -104,54 +93,62 @@ static int iphone_on (void *config){
|
|||||||
int pskey, value;
|
int pskey, value;
|
||||||
store = 0;
|
store = 0;
|
||||||
if (sscanf(buffer, "csr -p 0x%x=0x%x", &pskey, &value) == 2){
|
if (sscanf(buffer, "csr -p 0x%x=0x%x", &pskey, &value) == 2){
|
||||||
if (pskey == 0x01f9) { // UART MODE
|
switch (pskey) {
|
||||||
// write(output, buffer, pos);
|
case 0x01f9: // UART MODE
|
||||||
write(fileno(stdout), "Skipping: ", 10);
|
case 0x01c1: // Configure H5 mode
|
||||||
write(fileno(stdout), buffer, pos);
|
|
||||||
mirror = 0;
|
mirror = 0;
|
||||||
} else if (pskey == 0x01be) { // UART Baud
|
break;
|
||||||
// write(output, buffer, pos);
|
case 0x01be: // UART Baud
|
||||||
write(fileno(stdout), "Skipping: ", 10);
|
// use own settings
|
||||||
write(fileno(stdout), buffer, pos);
|
sprintf(buffer, "csr -p 0x01be=0x01d8\n"); // 115200 for now
|
||||||
|
write(output, buffer, pos+1);
|
||||||
mirror = 0;
|
mirror = 0;
|
||||||
} else {
|
break;
|
||||||
// dump buffer and start forwarding
|
default:
|
||||||
|
// anything else: dump buffer and start forwarding
|
||||||
write(output, buffer, pos);
|
write(output, buffer, pos);
|
||||||
write(fileno(stdout), buffer, pos);
|
|
||||||
mirror = 1;
|
mirror = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write(output, buffer, pos);
|
write(output, buffer, pos);
|
||||||
write(fileno(stdout), buffer, pos);
|
|
||||||
mirror = 1;
|
mirror = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// close ports
|
// close input
|
||||||
close(input);
|
close(input);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int iphone_on (void *config){
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// use tmp file
|
||||||
|
int output = open("/tmp/bt.init", O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
|
iphone_write_initscript(config, output);
|
||||||
|
close(output);
|
||||||
|
system ("BlueTool < /tmp/bt.init");
|
||||||
|
#else
|
||||||
|
// modify original script on the fly
|
||||||
|
FILE * outputFile = popen("BlueTool", "r+");
|
||||||
|
setvbuf(outputFile, NULL, _IONBF, 0);
|
||||||
|
int output = fileno(outputFile);
|
||||||
|
iphone_write_initscript(config, output);
|
||||||
|
|
||||||
// log output
|
// log output
|
||||||
int ready;
|
|
||||||
do {
|
|
||||||
fd_set fds;
|
|
||||||
FD_ZERO(&fds);
|
|
||||||
FD_SET(output,&fds);
|
|
||||||
ready=select(output+1,&fds,NULL,NULL,&noTime);
|
|
||||||
if (ready>0)
|
|
||||||
{
|
|
||||||
if (FD_ISSET(output,&fds)) {
|
|
||||||
char singlechar = fgetc(outputFile);
|
|
||||||
printf("%c", singlechar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (ready);
|
|
||||||
|
|
||||||
fflush(outputFile);
|
fflush(outputFile);
|
||||||
|
int singlechar;
|
||||||
|
while (1) {
|
||||||
|
singlechar = fgetc(outputFile);
|
||||||
|
if (singlechar == EOF) break;
|
||||||
|
printf("%c", singlechar);
|
||||||
|
};
|
||||||
pclose(outputFile);
|
pclose(outputFile);
|
||||||
|
|
||||||
// pause
|
#endif
|
||||||
sleep(3);
|
// if we sleep for about 3 seconds, we miss a strage packet
|
||||||
|
// sleep(3);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ hci_con_handle_t con_handle= 0;
|
|||||||
uint16_t dest_cid;
|
uint16_t dest_cid;
|
||||||
|
|
||||||
void event_handler(uint8_t *packet, int size){
|
void event_handler(uint8_t *packet, int size){
|
||||||
bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 };
|
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
|
||||||
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9};
|
bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
|
||||||
|
|
||||||
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
|
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user