2 * C Implementation: testapp
7 * Author: root <root@ubuntu>, (C) 2008
9 * Copyright: See COPYING file that comes with this distribution
17 #include "tiny_bt_hci_core.h"
18 #include "tiny_bt_hci_cmd.h"
21 bt_address rem_bd_addr_array[HCI_MAX_DEV];
25 connection_hci connection,*p_connection=&connection;
27 void callback_app_read_bd_addr(bt_address *p_address)
29 printf("Read address is :");
31 tiny_bt_read_local_name(&(p_connection->master.name), callback_app_read_local_name);
34 void callback_app_read_local_name(char *p_name)
38 printf("read name is:");
40 for (i = 0; i < 8; i++) {
41 printf("%c", *(p_name+i));
44 printf("waiting for connection\n");
45 tiny_bt_wait_for_connection(&p_connection->slave.bdaddr, callback_app_connection_request);
48 void callback_app_connection_request(bt_address *p_address)
50 printf("Incoming connection request from:");
52 printf("for control:");
53 printba(&p_connection->slave.bdaddr);
55 /*TODO some restrictions*/
56 tiny_bt_accept_connection(p_address,&p_connection->handle,callback_app_connection_complete);
59 void callback_app_connection_complete(__u16 *p_handle)
61 connection_state state = CONNECT;
63 p_connection->con_state = state;
65 printf("Connection complete handle:%d\n", *p_handle);
67 tiny_bt_disconnect_register(callback_app_disconnect);
70 void callback_app_disconnect(__u16 *p_handle, __u8 *p_reason)
72 printf("disconnection handle %d was completed\n", *p_handle);
78 int main(int argc, char* argv[])
81 if (tiny_bt_init(atoi(argv[1])) < 0) {
82 perror("device impossible to ititialize\n");
85 printf("%d:in of main\n", atoi(argv[1]));
87 if (tiny_bt_read_bd_addr(&p_connection->master.bdaddr, callback_app_read_bd_addr) < 0) {
88 perror("tiny_bt_read_bd_addr error\n");
96 if (tiny_bt_process() < 0) {
97 perror("process error");
102 printf("main finished\n");