mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-10 22:13:37 +00:00
implement iPhone control using BlueTool
This commit is contained in:
parent
2b37a727e9
commit
97addcc576
15
bt_control.h
Normal file
15
bt_control.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* bt_control.h
|
||||||
|
*
|
||||||
|
* BT Control API -- allows BT Daemon to initialize and control differnt hardware
|
||||||
|
*
|
||||||
|
* Created by Matthias Ringwald on 5/19/09.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 * (*names)(void *config); // <-- return hardware name
|
||||||
|
} bt_control_t;
|
134
bt_control_iphone.c
Normal file
134
bt_control_iphone.c
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* bt_control_iphone.c
|
||||||
|
*
|
||||||
|
* control Bluetooth module using BlueTool
|
||||||
|
*
|
||||||
|
* Created by Matthias Ringwald on 5/19/09.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bt_control_iphone.h"
|
||||||
|
|
||||||
|
#include <sys/utsname.h> // uname
|
||||||
|
#include <stdlib.h> // system
|
||||||
|
#include <stdio.h> // sscanf, printf
|
||||||
|
#include <fcntl.h> // open
|
||||||
|
#include <string.h> // strcpy, strcat, strncmp
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define BUFF_LEN 80
|
||||||
|
static char buffer[BUFF_LEN+1];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get machine name
|
||||||
|
*/
|
||||||
|
static struct utsname unmae_info;
|
||||||
|
static char *get_machine_name(void){
|
||||||
|
uname(&unmae_info);
|
||||||
|
return unmae_info.machine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* on iPhone/iPod touch
|
||||||
|
*/
|
||||||
|
static int iphone_valid(void *config){
|
||||||
|
char * machine = get_machine_name();
|
||||||
|
return strncmp("iPhone", machine, strlen("iPhone")) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * iphone_name(void *config){
|
||||||
|
return get_machine_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int iphone_on (void *config){
|
||||||
|
// get path to script
|
||||||
|
strcpy(buffer, "./etc/bluetool/");
|
||||||
|
char *machine = get_machine_name();
|
||||||
|
strcat(buffer, machine);
|
||||||
|
strcat(buffer, ".init.script");
|
||||||
|
|
||||||
|
// open script
|
||||||
|
int input = open(buffer, O_RDONLY);
|
||||||
|
int pos = 0;
|
||||||
|
int mirror = 0;
|
||||||
|
int store = 1;
|
||||||
|
while (1){
|
||||||
|
int chars = read(input, &buffer[pos], 1);
|
||||||
|
|
||||||
|
// end-of-line
|
||||||
|
if (chars == 0 || buffer[pos]=='\n' || buffer[pos]== '\r'){
|
||||||
|
if (store) {
|
||||||
|
// stored characters
|
||||||
|
write(fileno(stdout), buffer, pos+chars);
|
||||||
|
}
|
||||||
|
if (mirror) {
|
||||||
|
write(fileno(stdout), "\n", 1);
|
||||||
|
}
|
||||||
|
pos = 0;
|
||||||
|
mirror = 0;
|
||||||
|
store = 1;
|
||||||
|
if (chars) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mirror
|
||||||
|
if (mirror){
|
||||||
|
write(fileno(stdout), &buffer[pos], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// store
|
||||||
|
if (store) {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enough chars, check for pskey store command
|
||||||
|
if (mirror == 0 && pos == 9) {
|
||||||
|
if (strncmp(buffer, "csr -p 0x", 9) != 0) {
|
||||||
|
write(fileno(stdout), buffer, pos);
|
||||||
|
mirror = 1;
|
||||||
|
store = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check for "csr -p 0x002a=0x0011" (20)
|
||||||
|
if (mirror == 0 && store == 1 && pos == 20) {
|
||||||
|
int pskey, value;
|
||||||
|
store = 0;
|
||||||
|
if (sscanf(buffer, "csr -p 0x%x=0x%x", &pskey, &value) == 2){
|
||||||
|
if (pskey == 0x01f9) { // UART MODE
|
||||||
|
write(fileno(stdout), "Skipping: ", 10);
|
||||||
|
write(fileno(stdout), buffer, pos);
|
||||||
|
mirror = 1;
|
||||||
|
} else if (pskey == 0x01be) { // UART Baud
|
||||||
|
write(fileno(stdout), "Skipping: ", 10);
|
||||||
|
write(fileno(stdout), buffer, pos);
|
||||||
|
mirror = 1;
|
||||||
|
} else {
|
||||||
|
// dump buffer and start forwarding
|
||||||
|
write(fileno(stdout), buffer, pos);
|
||||||
|
mirror = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int iphone_off (void *config){
|
||||||
|
// power off
|
||||||
|
system ("echo \"power off\n quit\" | BlueTool");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// single instance
|
||||||
|
bt_control_t bt_control_iphone = {
|
||||||
|
iphone_on,
|
||||||
|
iphone_off,
|
||||||
|
iphone_valid,
|
||||||
|
iphone_name
|
||||||
|
};
|
12
bt_control_iphone.h
Normal file
12
bt_control_iphone.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* bt_control_iphone.h
|
||||||
|
*
|
||||||
|
* BT Control API implementation for the iPhone and the iPod Touch
|
||||||
|
*
|
||||||
|
* Created by Matthias Ringwald on 5/19/09.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bt_control.h"
|
||||||
|
|
||||||
|
extern bt_control_t bt_control_iphone;
|
||||||
|
|
@ -10,6 +10,8 @@
|
|||||||
9C46FBAF0FA8F31800ABEF05 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FBAE0FA8F31800ABEF05 /* main.c */; };
|
9C46FBAF0FA8F31800ABEF05 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FBAE0FA8F31800ABEF05 /* main.c */; };
|
||||||
9C46FC390FA906F700ABEF05 /* hci.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC340FA906F700ABEF05 /* hci.c */; };
|
9C46FC390FA906F700ABEF05 /* hci.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC340FA906F700ABEF05 /* hci.c */; };
|
||||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; };
|
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; };
|
||||||
|
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C88500C0FBF6702004980E4 /* l2cap.c */; };
|
||||||
|
9C8851E10FC3403F004980E4 /* bt_control_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C8851E00FC3403F004980E4 /* bt_control_iphone.c */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
@ -32,6 +34,12 @@
|
|||||||
9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci_transport_h4.c; path = src/hci_transport_h4.c; sourceTree = "<group>"; };
|
9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci_transport_h4.c; path = src/hci_transport_h4.c; sourceTree = "<group>"; };
|
||||||
9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport_h4.h; path = src/hci_transport_h4.h; sourceTree = "<group>"; };
|
9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport_h4.h; path = src/hci_transport_h4.h; sourceTree = "<group>"; };
|
||||||
9C46FC380FA906F700ABEF05 /* hci_transport.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport.h; path = src/hci_transport.h; sourceTree = "<group>"; };
|
9C46FC380FA906F700ABEF05 /* hci_transport.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport.h; path = src/hci_transport.h; sourceTree = "<group>"; };
|
||||||
|
9C88500C0FBF6702004980E4 /* l2cap.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = l2cap.c; path = src/l2cap.c; sourceTree = "<group>"; };
|
||||||
|
9C88500D0FBF6702004980E4 /* l2cap.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = l2cap.h; path = src/l2cap.h; sourceTree = "<group>"; };
|
||||||
|
9C8851DF0FC3403E004980E4 /* bt_control_iphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bt_control_iphone.h; sourceTree = "<group>"; };
|
||||||
|
9C8851E00FC3403F004980E4 /* bt_control_iphone.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bt_control_iphone.c; sourceTree = "<group>"; };
|
||||||
|
9C8851E20FC340F8004980E4 /* bt_control.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bt_control.h; sourceTree = "<group>"; };
|
||||||
|
9CA3C0900FB8B3C4005F48DE /* TODO.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TODO.txt; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -51,6 +59,7 @@
|
|||||||
08FB7795FE84155DC02AAC07 /* Source */,
|
08FB7795FE84155DC02AAC07 /* Source */,
|
||||||
C6A0FF2B0290797F04C91782 /* Documentation */,
|
C6A0FF2B0290797F04C91782 /* Documentation */,
|
||||||
1AB674ADFE9D54B511CA2CBB /* Products */,
|
1AB674ADFE9D54B511CA2CBB /* Products */,
|
||||||
|
9CA3C0900FB8B3C4005F48DE /* TODO.txt */,
|
||||||
);
|
);
|
||||||
name = project;
|
name = project;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -58,11 +67,16 @@
|
|||||||
08FB7795FE84155DC02AAC07 /* Source */ = {
|
08FB7795FE84155DC02AAC07 /* Source */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
9C8851E20FC340F8004980E4 /* bt_control.h */,
|
||||||
|
9C8851DF0FC3403E004980E4 /* bt_control_iphone.h */,
|
||||||
|
9C8851E00FC3403F004980E4 /* bt_control_iphone.c */,
|
||||||
9C46FC350FA906F700ABEF05 /* hci.h */,
|
9C46FC350FA906F700ABEF05 /* hci.h */,
|
||||||
9C46FC340FA906F700ABEF05 /* hci.c */,
|
9C46FC340FA906F700ABEF05 /* hci.c */,
|
||||||
|
9C46FC380FA906F700ABEF05 /* hci_transport.h */,
|
||||||
9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */,
|
9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */,
|
||||||
9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */,
|
9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */,
|
||||||
9C46FC380FA906F700ABEF05 /* hci_transport.h */,
|
9C88500C0FBF6702004980E4 /* l2cap.c */,
|
||||||
|
9C88500D0FBF6702004980E4 /* l2cap.h */,
|
||||||
9C46FBAE0FA8F31800ABEF05 /* main.c */,
|
9C46FBAE0FA8F31800ABEF05 /* main.c */,
|
||||||
);
|
);
|
||||||
name = Source;
|
name = Source;
|
||||||
@ -130,6 +144,8 @@
|
|||||||
9C46FBAF0FA8F31800ABEF05 /* main.c in Sources */,
|
9C46FBAF0FA8F31800ABEF05 /* main.c in Sources */,
|
||||||
9C46FC390FA906F700ABEF05 /* hci.c in Sources */,
|
9C46FC390FA906F700ABEF05 /* hci.c in Sources */,
|
||||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */,
|
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */,
|
||||||
|
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */,
|
||||||
|
9C8851E10FC3403F004980E4 /* bt_control_iphone.c in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
13
src/hci.c
13
src/hci.c
@ -89,6 +89,19 @@ static void *hci_daemon_thread(void *arg){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linked link list
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get link for given address
|
||||||
|
*
|
||||||
|
* @return connection OR NULL, if not found
|
||||||
|
*/
|
||||||
|
static hci_connection_t *link_for_addr(bd_addr_t addr){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler called by HCI transport
|
* Handler called by HCI transport
|
||||||
*/
|
*/
|
||||||
|
14
src/hci.h
14
src/hci.h
@ -12,22 +12,17 @@
|
|||||||
|
|
||||||
#include "hci_transport.h"
|
#include "hci_transport.h"
|
||||||
|
|
||||||
|
|
||||||
// helper for BT little endian format
|
// helper for BT little endian format
|
||||||
#define READ_BT_16( buffer, pos) (buffer[pos] | (buffer[pos+1] << 8))
|
#define READ_BT_16( buffer, pos) (buffer[pos] | (buffer[pos+1] << 8))
|
||||||
#define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16))
|
#define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16))
|
||||||
#define READ_BT_32( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16) | (((uint32_t) buffer[pos+3])) << 24)
|
#define READ_BT_32( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16) | (((uint32_t) buffer[pos+3])) << 24)
|
||||||
|
|
||||||
// #define STORE_BT_16( buffer, pos, value ) { buffer[pos] = (value) & 0xff; buffer[pos+1] = (value) >> 8; }
|
// packet header lengh
|
||||||
|
|
||||||
|
|
||||||
// packet headers
|
|
||||||
#define HCI_CMD_DATA_PKT_HDR 0x03
|
#define HCI_CMD_DATA_PKT_HDR 0x03
|
||||||
#define HCI_ACL_DATA_PKT_HDR 0x04
|
#define HCI_ACL_DATA_PKT_HDR 0x04
|
||||||
#define HCI_SCO_DATA_PKT_HDR 0x03
|
#define HCI_SCO_DATA_PKT_HDR 0x03
|
||||||
#define HCI_EVENT_PKT_HDR 0x02
|
#define HCI_EVENT_PKT_HDR 0x02
|
||||||
|
|
||||||
|
|
||||||
// Events from host controller to host
|
// Events from host controller to host
|
||||||
#define HCI_EVENT_INQUIRY_COMPLETE 0x01
|
#define HCI_EVENT_INQUIRY_COMPLETE 0x01
|
||||||
#define HCI_EVENT_INQUIRY_RESULT 0x02
|
#define HCI_EVENT_INQUIRY_RESULT 0x02
|
||||||
@ -65,6 +60,12 @@
|
|||||||
|
|
||||||
#define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == HCI_EVENT_COMMAND_COMPLETE && READ_BT_16(event,3) == cmd.opcode)
|
#define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == HCI_EVENT_COMMAND_COMPLETE && READ_BT_16(event,3) == cmd.opcode)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default INQ Mode
|
||||||
|
*/
|
||||||
|
#define HCI_INQUIRY_LAP 0x9E8B33L // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Length of a bluetooth device address.
|
* @brief Length of a bluetooth device address.
|
||||||
*/
|
*/
|
||||||
@ -178,4 +179,3 @@ extern hci_cmd_t hci_host_buffer_size;
|
|||||||
extern hci_cmd_t hci_write_authentication_enable;
|
extern hci_cmd_t hci_write_authentication_enable;
|
||||||
extern hci_cmd_t hci_write_page_timeout;
|
extern hci_cmd_t hci_write_page_timeout;
|
||||||
|
|
||||||
#define HCI_INQUIRY_LAP 0x9E8B33L // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC)
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* hci_transport.h
|
* hci_transport.h
|
||||||
*
|
*
|
||||||
* HCI Transport API -- allows hcid to use different transport protcols
|
* HCI Transport API -- allows BT Daemon to use different transport protcols
|
||||||
*
|
*
|
||||||
* Created by Matthias Ringwald on 4/29/09.
|
* Created by Matthias Ringwald on 4/29/09.
|
||||||
*
|
*
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* hci_h4_transport.c
|
* hci_h4_transport.c
|
||||||
*
|
*
|
||||||
* Created by Matthias Ringwald on 4/29/09.
|
* HCI Transport API implementation for basic H4 protocol
|
||||||
*
|
*
|
||||||
|
* Created by Matthias Ringwald on 4/29/09.
|
||||||
*/
|
*/
|
||||||
#include <termios.h> /* POSIX terminal control definitions */
|
#include <termios.h> /* POSIX terminal control definitions */
|
||||||
#include <fcntl.h> /* File control definitions */
|
#include <fcntl.h> /* File control definitions */
|
||||||
@ -211,7 +212,7 @@ static void dummy_handler(uint8_t *packet, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// single instance
|
// single instance
|
||||||
hci_transport_t hci_h4_transport = {
|
hci_transport_t hci_transport_h4 = {
|
||||||
h4_open,
|
h4_open,
|
||||||
h4_close,
|
h4_close,
|
||||||
h4_send_cmd_packet,
|
h4_send_cmd_packet,
|
||||||
|
@ -32,5 +32,4 @@
|
|||||||
#define HCI_EVENT_PACKET 0x04
|
#define HCI_EVENT_PACKET 0x04
|
||||||
|
|
||||||
|
|
||||||
|
extern hci_transport_t hci_transport_h4;
|
||||||
extern hci_transport_t hci_h4_transport;
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user