From 475c8125ef8bd08f640a384990d9a8403144ebf4 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 3 May 2009 21:28:40 +0000 Subject: [PATCH] towards a basic test app --- src/hci.c | 35 ++++++++++++++++++++++++++++++++++- src/hci.h | 15 +++++++++++++-- src/hci_transport_h4.c | 8 ++++++-- src/main.c | 41 ++++++++++++++++++++++++++++++++++++----- 4 files changed, 89 insertions(+), 10 deletions(-) diff --git a/src/hci.c b/src/hci.c index c2cd010c1..1bc3c5f98 100644 --- a/src/hci.c +++ b/src/hci.c @@ -5,7 +5,40 @@ * */ +#include + #include "hci.h" -void hci_run(hci_transport_t *transport, void *config){ +static hci_transport_t *hci_transport; + +void hci_init(hci_transport_t *transport, void *config){ + + // reference to use transport layer implementation + hci_transport = transport; + + // open unix socket + + // wait for connections + + // enter loop + + // handle events } + +int hci_power_control(HCI_POWER_MODE power_mode){ + return 0; +} + +int hci_send_cmd(char *buffer, int size){ + return hci_transport->send_cmd_packet(buffer, size); +} + +void hci_run(){ + while (1) { + // construct file descriptor set to wait for + // select + + // for each ready file in FD - call handle_data + sleep(1); + } +} \ No newline at end of file diff --git a/src/hci.h b/src/hci.h index f91df93b4..33e7e9718 100644 --- a/src/hci.h +++ b/src/hci.h @@ -9,6 +9,17 @@ #include "hci_transport.h" -// run the hci daemon loop -void hci_run(hci_transport_t *transport, void *config); +typedef enum { + HCI_POWER_OFF = 0, + HCI_POWER_ON +} HCI_POWER_MODE; + +// set up HCI +void hci_init(hci_transport_t *transport, void *config); + +// power control +int hci_power_control(HCI_POWER_MODE mode); + +// run the hci daemon loop +void hci_run(); diff --git a/src/hci_transport_h4.c b/src/hci_transport_h4.c index 54a058a19..5b3ec4613 100644 --- a/src/hci_transport_h4.c +++ b/src/hci_transport_h4.c @@ -5,7 +5,7 @@ * */ -#include "hci_h4_transport.h" +#include "hci_transport_h4.h" // prototypes static int open(void *transport_config){ @@ -26,6 +26,7 @@ static int send_acl_packet(void *packet, int size){ static void register_event_packet_handler(void (*handler)(void *packet, int size)){ } + static void register_acl_packet_handler (void (*handler)(void *packet, int size)){ } @@ -43,7 +44,10 @@ static const char * get_transport_name(){ // private data -typedef struct { +typedef struct { + hci_uart_config_t *config; + void (*event_packet_handle)(void *packet, int size); + void (*acl_packet_handle)(void *packet, int size); } hci_h4_transport_private_t; // single instance diff --git a/src/main.c b/src/main.c index 5ba160409..c45d820fb 100644 --- a/src/main.c +++ b/src/main.c @@ -8,9 +8,25 @@ #include #include +#include + +#include #include "hci.h" -#include "hci_h4_transport.h" +#include "hci_transport_h4.h" + +static hci_transport_t * transport; +static hci_uart_config_t config; + + +#if 0 +static void *hci_daemon_thread(void *arg){ + printf("HCI Daemon started\n"); + hci_run(transport, &config); + return NULL; +} +#endif + int main (int argc, const char * argv[]) { @@ -21,16 +37,31 @@ int main (int argc, const char * argv[]) { } // H4 UART - hci_transport_t * transport = &hci_h4_transport; + transport = &hci_h4_transport; // Ancient Ericsson ROK 101 007 (ca. 2001) - hci_uart_config_t config; config.device_name = argv[1]; config.baudrate = 57600; config.flowcontrol = 1; - // Go - hci_run(transport, &config); +#if 0 + // create and start HCI daemon thread + pthread_t new_thread; + pthread_create(&new_thread, NULL, hci_daemon_thread, NULL); + + // open UNIX domain socket + while(1){ + sleep(1); + printf(".\n"); + } +#endif + + hci_init(transport, &config); + hci_power_control(HCI_POWER_ON); + // + // register callback + // + hci_run(); return 0; }