fix bugs introduced yesterday

This commit is contained in:
matthias.ringwald 2009-07-12 15:33:07 +00:00
parent 74aad56003
commit b2ae9e32ee
6 changed files with 79 additions and 17 deletions

View File

@ -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

View File

@ -56,7 +56,6 @@
9CC152C61009052100223347 /* config.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
9CC813A00FFC0774002816F9 /* btstack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = btstack.h; path = src/btstack.h; sourceTree = "<group>"; };
9CC813A10FFC0774002816F9 /* btstack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = btstack.c; path = src/btstack.c; sourceTree = "<group>"; };
9CC813A30FFC0A51002816F9 /* daemon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = daemon.h; path = src/daemon.h; sourceTree = "<group>"; };
9CC813A40FFC0A51002816F9 /* daemon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = daemon.c; path = src/daemon.c; sourceTree = "<group>"; };
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 = "<group>"; };
/* 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 */,

View File

@ -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"

View File

@ -7,8 +7,6 @@
*
*/
#include "daemon.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@ -30,7 +28,6 @@
#include "run_loop.h"
#include "socket_server.h"
#include "daemon.h"
#ifdef USE_BLUETOOL
#include "bt_control_iphone.h"

View File

@ -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;
}

View File

@ -15,13 +15,39 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <sys/socket.h>
#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;
}