From 68d92d036ba7fc6538776879f5e24f8443e763cf Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 7 Jun 2009 15:45:31 +0000 Subject: [PATCH] add hci_read_bd_addr, don't turn on BT in hci_init(), add temp hack to get socket data --- src/hci.c | 13 ++++++++++--- src/hci.h | 4 +++- src/main.c | 4 ++-- src/socket_server.h | 8 +++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/hci.c b/src/hci.c index cff758d44..030149137 100644 --- a/src/hci.c +++ b/src/hci.c @@ -15,6 +15,7 @@ #define OPCODE(ogf, ocf) (ocf | ogf << 10) #define OGF_LINK_CONTROL 0x01 #define OGF_CONTROLLER_BASEBAND 0x03 +#define OGF_INFORMATIONAL_PARAMETERS 0x04 hci_cmd_t hci_inquiry = { OPCODE(OGF_LINK_CONTROL, 0x01), "311" @@ -54,6 +55,11 @@ hci_cmd_t hci_host_buffer_size = { // Host_ACL_Data_Packet_Length:, Host_Synchronous_Data_Packet_Length:, Host_Total_Num_ACL_Data_Packets:, Host_Total_Num_Synchronous_Data_Packets: }; +hci_cmd_t hci_read_bd_addr = { +OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), "" +// no params +}; + // the stack is here static hci_stack_t hci_stack; @@ -214,9 +220,6 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){ // register packet handlers with transport transport->register_event_packet_handler( event_handler); transport->register_acl_packet_handler( acl_handler); - - // turn on - hci_power_control(HCI_POWER_ON); } int hci_power_control(HCI_POWER_MODE power_mode){ @@ -241,6 +244,10 @@ int hci_power_control(HCI_POWER_MODE power_mode){ // power off hci_stack.control->off(hci_stack.config); } + + // trigger next/first action + hci_run(); + return 0; } diff --git a/src/hci.h b/src/hci.h index f218621f5..d0c150739 100644 --- a/src/hci.h +++ b/src/hci.h @@ -174,6 +174,7 @@ int hci_send_acl_packet(uint8_t *packet, int size); // helper extern void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value); extern void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value); +extern void bt_flip_addr(bd_addr_t dest, bd_addr_t src); extern hci_cmd_t hci_inquiry; extern hci_cmd_t hci_link_key_request_negative_reply; @@ -183,4 +184,5 @@ extern hci_cmd_t hci_create_connection; extern hci_cmd_t hci_host_buffer_size; extern hci_cmd_t hci_write_authentication_enable; extern hci_cmd_t hci_write_page_timeout; - +extern hci_cmd_t hci_read_bd_addr; + diff --git a/src/main.c b/src/main.c index 84a8a0392..aa99993f3 100644 --- a/src/main.c +++ b/src/main.c @@ -155,8 +155,8 @@ int main (int argc, const char * argv[]) { // init L2CAP l2cap_init(); - // trigger first hci action - hci_run(); + // turn on + hci_power_control(HCI_POWER_ON); // create server data_source_t *socket_server = socket_server_create_tcp(1919); diff --git a/src/socket_server.h b/src/socket_server.h index a7c8ccc13..aaad0898a 100644 --- a/src/socket_server.h +++ b/src/socket_server.h @@ -16,4 +16,10 @@ data_source_t * socket_server_create_tcp(int port); /** * create socket data_source for unix domain socket */ -data_source_t * socket_server_create_unix(char *path); \ No newline at end of file +data_source_t * socket_server_create_unix(char *path); + +/** + * register data available callback + * @todo: hack callback to allow data reception - replace with better architecture + */ +void socket_server_register_process_callback( int (*process_callback)(struct data_source *ds, int ready) );