]> rtime.felk.cvut.cz Git - tiny-bt.git/blobdiff - src2/tiny_bt_hci_core.c
outgoing data packet was modified. Now I can send packet and receive it on second...
[tiny-bt.git] / src2 / tiny_bt_hci_core.c
index 31abb0be4a93b0566cfeb4a8bfe70a2d1dfe181b..85117392e3e0eacfaa545e0796cb891125bd9a31 100644 (file)
@@ -31,8 +31,10 @@ static void callback_hci_all_commands(void *p_arg, void *p_recbuf)
 
        if (p_rp->status) {
                perror("command status error\n");
+               tiny_bt_finish();
                //return -1;
-               exit(-1); // !!!!!!!!!!!!!!!!
+               /*TODO call some app_callback and do something with error state */
+               exit(1); // !!!!!!!!!!!!!!!!
        }
                
        printf("command status with opcode: %d\n",p_rp->opcode);
@@ -92,7 +94,7 @@ static void callback_hci_create_connection(void *p_arg, void *p_recbuf)
        connection_complete_data *p_data = p_arg;
        evt_conn_complete *p_rp;
 
-       p_rp = (void *) (p_recbuf + 3);
+       p_rp = (void *) (p_recbuf);
        memcpy(p_data->p_handle, &p_rp->handle, 2);
        //memcpy(p_data->p_address,&p_rp->bdaddr,6);
        p_data->callback_app_connection_complete(p_data->p_handle);
@@ -226,6 +228,18 @@ int tiny_bt_init(__u8 dev_id)
        return 0;
 }
 
+int tiny_bt_finish()
+{      
+       int err;
+       
+       if ((err = hw_bt_close_dev()) < 0) {
+               perror("Impossible to close filedes\n");
+               return -1;
+       }
+       printf("filedescriptor was closed\n");
+       return 0;
+}
+
 int tiny_bt_process()
 {
        int len, j, index;
@@ -265,7 +279,16 @@ int tiny_bt_process()
                                        evt_array[index].p_callback(evt_array[index].p_data, p_recbuf);
                                        if (evt_array[index].actual_status != PERMANENT)
                                                evt_array[index].actual_status = DONE;
-                                       
+                               }
+
+                       } else if (p_hdr->evt == EVT_CONN_REQUEST) {
+                               if ((index = look_up_inarray(EVT_CONN_REQUEST, 0)) < 0) {
+                                       err = -1;
+                                       goto no_evt_exit;
+                               } else {
+                                       evt_array[index].p_callback(evt_array[index].p_data, p_recbuf);
+                                       if (evt_array[index].actual_status != PERMANENT)
+                                               evt_array[index].actual_status = DONE;
                                }
 
                        } else if (p_hdr->evt == EVT_MAX_SLOTS_CHANGE || p_hdr->evt == EVT_NUM_COMP_PKTS) {
@@ -307,6 +330,8 @@ int tiny_bt_process()
                                printf("%2.2X ", recbuf[j]);
                        }
                        printf("\n");
+                       /*TODO call some data callback for process data*/
+                       return 1;
                } else 
                        goto packet_wrong; 
        } else 
@@ -325,7 +350,7 @@ packet_wrong:
        return 0;
 
 no_data:
-       printf("There is no data on socket");
+       /*printf("There is no data on socket");*/
        return 0;
 }
 
@@ -563,9 +588,9 @@ int tiny_bt_disconnect(__u16 *p_handle, void(*callback_app_disconnect)(__u16 *p_
 
 }
 
-int tiny_bt_send_data(char *p_data, __u16 lenght, __u16 *p_chandle)
+int tiny_bt_send_data(char *p_data, __u16 lenght, __u16 *p_chandle, __u16 PB_flag, __u16 B_flag)
 {      
-       if (send_hci_data(p_data, lenght, p_chandle) < 0) {
+       if (send_hci_data(p_data, lenght, p_chandle, PB_flag, B_flag) < 0) {
                perror ("send_hci_cmd error\n");
                return -1;
        }