2009-07-01 21:55:08 +00:00
|
|
|
/*
|
|
|
|
* daemon.c
|
|
|
|
*
|
|
|
|
* Created by Matthias Ringwald on 7/1/09.
|
|
|
|
*
|
|
|
|
* BTstack background daemon
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-14 18:29:29 +00:00
|
|
|
#include "../config.h"
|
|
|
|
|
2009-07-01 21:55:08 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
|
|
#include "hci.h"
|
|
|
|
#include "hci_dump.h"
|
|
|
|
#include "l2cap.h"
|
2009-07-13 21:51:42 +00:00
|
|
|
#include "linked_list.h"
|
2009-07-01 21:55:08 +00:00
|
|
|
#include "run_loop.h"
|
|
|
|
#include "socket_server.h"
|
|
|
|
|
2009-07-11 10:37:48 +00:00
|
|
|
#ifdef USE_BLUETOOL
|
|
|
|
#include "bt_control_iphone.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TRANSPORT_H4
|
|
|
|
#include "hci_transport_h4.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TRANSPORT_USB
|
2009-07-09 18:49:43 +00:00
|
|
|
#include <libusb-1.0/libusb.h>
|
2009-07-11 10:37:48 +00:00
|
|
|
#include "hci_transport_usb.h"
|
|
|
|
#endif
|
2009-07-01 21:55:08 +00:00
|
|
|
|
|
|
|
static hci_transport_t * transport;
|
|
|
|
static hci_uart_config_t config;
|
|
|
|
|
2009-07-22 20:21:22 +00:00
|
|
|
static int daemon_packet_handler(connection_t *connection, uint8_t packet_type, uint8_t *data, uint16_t length){
|
|
|
|
switch (packet_type){
|
|
|
|
case HCI_COMMAND_DATA_PACKET:
|
|
|
|
hci_send_cmd_packet(data, length);
|
|
|
|
break;
|
|
|
|
case HCI_ACL_DATA_PACKET:
|
|
|
|
hci_send_acl_packet(data, length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-11 17:42:03 +00:00
|
|
|
int main (int argc, const char * argv[]){
|
2009-07-01 21:55:08 +00:00
|
|
|
|
|
|
|
bt_control_t * control = NULL;
|
|
|
|
|
2009-07-11 10:37:48 +00:00
|
|
|
#ifdef HAVE_TRANSPORT_H4
|
|
|
|
transport = hci_transport_h4_instance();
|
|
|
|
config.device_name = UART_DEVICE;
|
|
|
|
config.baudrate = UART_SPEED;
|
2009-07-01 21:55:08 +00:00
|
|
|
config.flowcontrol = 1;
|
2009-07-11 10:37:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TRANSPORT_USB
|
|
|
|
transport = hci_transport_usb_instance();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_BLUETOOL
|
2009-07-01 21:55:08 +00:00
|
|
|
control = &bt_control_iphone;
|
|
|
|
#endif
|
|
|
|
|
2009-07-14 18:29:29 +00:00
|
|
|
// @TODO allow configuration per HCI CMD
|
|
|
|
|
2009-07-16 20:12:42 +00:00
|
|
|
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
|
|
|
|
// hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
|
|
|
|
hci_dump_open(NULL, HCI_DUMP_STDOUT);
|
|
|
|
|
2009-07-01 21:55:08 +00:00
|
|
|
// init HCI
|
|
|
|
hci_init(transport, &config, control);
|
|
|
|
|
|
|
|
// init L2CAP
|
|
|
|
l2cap_init();
|
|
|
|
|
|
|
|
//
|
|
|
|
// register callbacks
|
|
|
|
//
|
2009-07-14 18:29:29 +00:00
|
|
|
hci_register_event_packet_handler(&socket_server_send_event_all);
|
|
|
|
hci_register_acl_packet_handler(&socket_server_send_acl_all);
|
2009-07-01 21:55:08 +00:00
|
|
|
|
2009-07-14 18:29:29 +00:00
|
|
|
// @TODO allow control per HCI CMD
|
2009-07-01 21:55:08 +00:00
|
|
|
// turn on
|
|
|
|
hci_power_control(HCI_POWER_ON);
|
|
|
|
|
2009-07-14 18:29:29 +00:00
|
|
|
// @TODO make choice of socket server configurable (TCP and/or Unix Domain Socket)
|
|
|
|
// @TODO make port and/or socket configurable per config.h
|
|
|
|
|
2009-07-01 21:55:08 +00:00
|
|
|
// create server
|
2009-07-09 18:49:43 +00:00
|
|
|
socket_server_create_tcp(1919);
|
2009-07-22 20:21:22 +00:00
|
|
|
socket_server_register_packet_callback(daemon_packet_handler);
|
2009-07-01 21:55:08 +00:00
|
|
|
|
|
|
|
// go!
|
|
|
|
run_loop_execute();
|
2009-07-14 18:29:29 +00:00
|
|
|
|
2009-07-01 21:55:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|