--- /dev/null
+/*
+* C Implementation: testapp
+*
+* Description:
+*
+*
+* Author: root <root@ubuntu>, (C) 2008
+*
+* Copyright: See COPYING file that comes with this distribution
+*
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdint.h>
+#include "tiny_bt_hci_core.h"
+#include "tiny_bt_hci_cmd.h"
+#include "testcon.h"
+
+bt_address rem_bd_addr_array[HCI_MAX_DEV];
+bt_address rem_addr;
+int glob_count = 0;
+int stop = 0;
+connection_hci connection,*p_connection=&connection;
+
+void callback_app_read_bd_addr(bt_address *p_address)
+{
+ printf("Read address is :");
+ printba(p_address);
+ tiny_bt_read_local_name(&(p_connection->master.name), callback_app_read_local_name);
+}
+
+void callback_app_read_local_name(char *p_name)
+{
+ int i;
+
+ printf("read name is:");
+
+ for (i = 0; i < 8; i++) {
+ printf("%c", *(p_name+i));
+ }
+ printf("\n");
+ printf("waiting for connection\n");
+ tiny_bt_wait_for_connection(&p_connection->slave.bdaddr, callback_app_connection_request);
+}
+
+void callback_app_connection_request(bt_address *p_address)
+{
+ printf("Incoming connection request from:");
+ printba(p_address);
+ printf("for control:");
+ printba(&p_connection->slave.bdaddr);
+
+ /*TODO some restrictions*/
+ tiny_bt_accept_connection(p_address,&p_connection->handle,callback_app_connection_complete);
+}
+
+void callback_app_connection_complete(__u16 *p_handle)
+{
+ connection_state state = CONNECT;
+
+ p_connection->con_state = state;
+
+ printf("Connection complete handle:%d\n", *p_handle);
+
+ tiny_bt_disconnect_register(callback_app_disconnect);
+}
+
+void callback_app_disconnect(__u16 *p_handle, __u8 *p_reason)
+{
+ printf("disconnection handle %d was completed\n", *p_handle);
+ tiny_bt_finish();
+ stop = 1;
+}
+
+
+int main(int argc, char* argv[])
+{
+
+ if (tiny_bt_init(atoi(argv[1])) < 0) {
+ perror("device impossible to ititialize\n");
+ return -1;
+ }
+ printf("%d:in of main\n", atoi(argv[1]));
+
+ if (tiny_bt_read_bd_addr(&p_connection->master.bdaddr, callback_app_read_bd_addr) < 0) {
+ perror("tiny_bt_read_bd_addr error\n");
+ return -1;
+ }
+
+ while (1) {
+ if (stop)
+ break;
+ //ii--;
+ if (tiny_bt_process() < 0) {
+ perror("process error");
+ break;
+ }
+
+ }
+ printf("main finished\n");
+ return 0;
+}
+
--- /dev/null
+/*
+ * C++ Interface: testapp
+ *
+ * Description:
+ *
+ *
+ * Author: root <root@ubuntu>, (C) 2008
+ *
+ * Copyright: See COPYING file that comes with this distribution
+ */
+
+#ifndef __TESTCON
+#define __TESTCON
+
+extern void callback_app_read_bd_addr(bt_address *p_address);
+extern void callback_app_read_local_name(char *p_name);
+extern void callback_app_connection_request(bt_address *p_address);
+extern void callback_app_connection_complete(__u16 *p_handle);
+extern void callback_app_disconnect(__u16 *p_handle, __u8 *p_reason);
+
+#endif
+
static int global_index;
extern connection_hci connection;
/******************************HCI callback functions*********************/
-
+/*when propriate event has occured and this event was registered in evt_array
+* these callback_hci..... are callled , they explore event's data field and call
+* propriate upper protocol(or application) callback and also deliver, parameters
+* which has occured with inbound event */
static void callback_hci_all_commands(void *p_arg, void *p_recbuf)
{
evt_cmd_status *p_rp;
perror("command status error\n");
tiny_bt_finish();
//return -1;
- /*TODO call some app_callback and do something with error state */
+ /*TODO call some app_callback and do something with error state
+ * I only write out the inbound opcode , if any problem has occured
+ * it is not solve here yet. */
exit(1); // !!!!!!!!!!!!!!!!
}