diff --git a/Makefile.am b/Makefile.am index a455182bf..3a7d3b806 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,5 +5,5 @@ iphone_ip=@IPHONE_IP@ install-iphone: src/BTdaemon cp $< $<-signed export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $<-signed - scp $<-signed mobile@$(iphone_ip):/var/mobile/BTdaemon + scp $<-signed root@$(iphone_ip):/var/root/BTdaemon diff --git a/project.xcodeproj/project.pbxproj b/project.xcodeproj/project.pbxproj index 58169d9f1..ba4f55e93 100644 --- a/project.xcodeproj/project.pbxproj +++ b/project.xcodeproj/project.pbxproj @@ -56,7 +56,6 @@ 9CC152C61009052100223347 /* config.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = ""; }; 9CC813A00FFC0774002816F9 /* btstack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = btstack.h; path = src/btstack.h; sourceTree = ""; }; 9CC813A10FFC0774002816F9 /* btstack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = btstack.c; path = src/btstack.c; sourceTree = ""; }; - 9CC813A30FFC0A51002816F9 /* daemon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = daemon.h; path = src/daemon.h; sourceTree = ""; }; 9CC813A40FFC0A51002816F9 /* daemon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = daemon.c; path = src/daemon.c; sourceTree = ""; }; 9CEB22DC1005345400FA2B98 /* hci_transport_usb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = hci_transport_usb.h; path = src/hci_transport_usb.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -94,7 +93,6 @@ 9C7ECB830FCC85650085DAC5 /* bt_control_iphone.h */, 9CC813A00FFC0774002816F9 /* btstack.h */, 9CC813A10FFC0774002816F9 /* btstack.c */, - 9CC813A30FFC0A51002816F9 /* daemon.h */, 9CC813A40FFC0A51002816F9 /* daemon.c */, 9C46FC350FA906F700ABEF05 /* hci.h */, 9C46FC340FA906F700ABEF05 /* hci.c */, diff --git a/src/bt_control_iphone.c b/src/bt_control_iphone.c index 0df83ee4a..d819219f3 100644 --- a/src/bt_control_iphone.c +++ b/src/bt_control_iphone.c @@ -6,6 +6,8 @@ * Created by Matthias Ringwald on 5/19/09. */ +#include "../config.h" + #include "bt_control_iphone.h" #include "hci_transport.h" #include "hci.h" diff --git a/src/daemon.c b/src/daemon.c index 88e6bc2d7..ae5924a06 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -7,8 +7,6 @@ * */ -#include "daemon.h" - #include #include #include @@ -30,7 +28,6 @@ #include "run_loop.h" #include "socket_server.h" -#include "daemon.h" #ifdef USE_BLUETOOL #include "bt_control_iphone.h" diff --git a/src/hci_transport_h4.c b/src/hci_transport_h4.c index 769b2346f..6b4870d25 100644 --- a/src/hci_transport_h4.c +++ b/src/hci_transport_h4.c @@ -251,5 +251,5 @@ hci_transport_t * hci_transport_h4_instance() { hci_transport_h4->transport.register_acl_packet_handler = h4_register_acl_packet_handler; hci_transport_h4->transport.get_transport_name = h4_get_transport_name; } - return hci_transport_h4; + return (hci_transport_t *) hci_transport_h4; } diff --git a/src/socket_server.c b/src/socket_server.c index 4561aa8bb..5aedfd529 100644 --- a/src/socket_server.c +++ b/src/socket_server.c @@ -15,13 +15,39 @@ #include #include #include +#include #include #include #include +#include "hci.h" + #define MAX_PENDING_CONNECTIONS 10 #define DATA_BUF_SIZE 80 + +typedef struct packet_header { + uint16_t length; + uint8_t type; + uint8_t data[0]; +} packet_header_t; + +typedef enum { + SOCKET_W4_HEADER, + SOCKET_W4_DATA, +} SOCKET_STATE; + +typedef struct connection { + data_source_t ds; + struct connection * next; + SOCKET_STATE state; + uint16_t bytes_read; + uint16_t bytes_to_read; + char buffer[3+3+255]; // max HCI CMD + packet_header +} connection_t; + +connection_t *connections = NULL; + static char test_buffer[DATA_BUF_SIZE]; static int socket_server_echo_process(struct data_source *ds, int ready); @@ -61,28 +87,67 @@ static int socket_server_echo_process(struct data_source *ds, int ready) { return 0; } +#if 0 +static int socket_server_connection_process(struct data_source *ds, int ready) { + connection_t *conn = (connection_t *) ds; + int bytes_read = read(ds->fd, &conn->buffer[conn->bytes_read], + sizeof(packet_header_t) - conn->bytes_read); + if (bytes_read < 0){ + // + } + conn->bytes_read += bytes_read; + conn->bytes_to_read -= bytes_read; + if (conn->bytes_to_read > 0) { + return 0; + } + switch (conn->state){ + case SOCKET_W4_HEADER: + conn->state = SOCKET_W4_DATA; + conn->bytes_to_read = READ_BT_16( conn->buffer, 0); + break; + case SOCKET_W4_DATA: + // process packet !!! + + + // wait for next packet + conn->state = SOCKET_W4_HEADER; + conn->bytes_read = 0; + conn->bytes_to_read = sizeof(packet_header_t); + break; + } + return 0; +} +#endif static int socket_server_accept(struct data_source *socket_ds, int ready) { // create data_source_t - data_source_t *ds = malloc( sizeof(data_source_t)); - if (ds == NULL) return 0; - ds->fd = 0; - ds->process = socket_server_process; + connection_t * conn = malloc( sizeof(connection_t)); + if (conn == NULL) return 0; + conn->ds.fd = 0; + conn->ds.process = socket_server_process; - /* We have a new connection coming in! We'll - try to find a spot for it in connectlist. */ - ds->fd = accept(socket_ds->fd, NULL, NULL); - if (ds->fd < 0) { + // init state machine + conn->state = SOCKET_W4_HEADER; + conn->bytes_read = 0; + conn->bytes_to_read = 2; + + /* New connection coming in! */ + conn->ds.fd = accept(socket_ds->fd, NULL, NULL); + if (conn->ds.fd < 0) { perror("accept"); - free(ds); + free(conn); return 0; } // non-blocking ? // socket_server_set_non_blocking(ds->fd); + // store reference to this connection + conn->next = NULL; + connections = conn; + // add this socket to the run_loop - run_loop_add( ds ); + run_loop_add( &conn->ds ); return 0; }