]> rtime.felk.cvut.cz Git - tiny-bt.git/commitdiff
begin part of slave main cycle with ansvering the incoming events
authorDavid Plotek <ploted1@fel.cvut.cz>
Thu, 24 Jul 2008 22:47:56 +0000 (00:47 +0200)
committerDavid Plotek <ploted1@fel.cvut.cz>
Thu, 24 Jul 2008 22:47:56 +0000 (00:47 +0200)
src/hil2cap.c
src/hil2cap.h
testf/t2/slavetest.c

index 02a4a44ee33515186fe979f801302e239351a271..a79042c5b88849540a08ca7161a76f58642f7aea 100644 (file)
@@ -216,6 +216,7 @@ int main(void){
        bt_address remote_bd_addr_array[HCI_MAX_DEV];
        memset(remote_bd_addr_array,0,(sizeof(bt_address)*HCI_MAX_DEV));
        connection_hci connection,*p_connection=&connection;
+       bt_address prefered;
        int remd_count,i;
        cmd_req_id=0;
        global_index=0;
@@ -233,8 +234,9 @@ int main(void){
                printba(&remote_bd_addr_array[i]);
        }
        p_connection->master=master;
-       p_connection->slave.bdaddr=remote_bd_addr_array[0];
-       
+       //p_connection->slave.bdaddr=remote_bd_addr_array[0];
+       fill_add(&prefered,0xE1,0x03,0x24,0x63,0x89,0x22);
+       p_connection->slave.bdaddr=prefered;
        if(create_master_connection(p_connection)<0){
                printf("connection error");
                return -1;
index 1434a4e5dac5ef2fc0dfe6d3b35eae8bc2f3ba08..826ab3e282dbac81647b15ab00234f95c1924d38 100644 (file)
 #define DISCONNECTED   0
 #define CONNECTED      1
 
-/* CMD request states*/
+/* CMD\EVT states*/
 #define FREE           0
 #define ESTABLISHED    1
-#define PENDING        2
+#define PERMANENT      2
 #define DONE           3
 
 /* CMD ocf and ogf */
@@ -41,6 +41,7 @@
 
 
 #define MAX_CMD_STATE_REQUEST 0x0F
+#define MAX_EVT_COUNT  128
 typedef struct{
        __u8 actual_status;
        __u8 id;
@@ -50,6 +51,12 @@ typedef struct{
 
 } __attribute__((packed)) cmd_state_request;
 
+typedef struct{
+       __u8 actual_status;
+       __u16 id;
+       __u16 evt_code;
+       void (*p_serv_rutine)(void);
+} __attribute__((packed)) incoming_evt;
 
 typedef struct{
        __u16 con_id;
index f1c1ac28f13e208c70725c038e8258fa6a22169e..cf66c8052dc4940f00d8724d623b7ce5e52bf6c2 100644 (file)
 #include <sys/ioctl.h>
 #include "hcidriver.h"
 
-cmd_state_request array_req[MAX_CMD_STATE_REQUEST];
-int cmd_req_id;
+incoming_evt evt_array[MAX_CMD_STATE_REQUEST];
+int evt_id;
 int global_index;
 
-int req_fcn_add(cmd_state_request *p_req){ //fcn add the request at the end of array or replace the oldest request
+int add_evt_toarray(incoming_evt *p_evt){ //fcn add the request at the end of array or replace the oldest request
        int i,sig=0,index=0;
-       cmd_state_request the_oldest=array_req[0];
+       incoming_evt the_oldest=evt_array[0];
        
-       for(i=0;i<MAX_CMD_STATE_REQUEST;i++){
-               if((array_req[i].actual_status)==0 || array_req[i].actual_status==3 ){
-                       array_req[i]=*p_req;
+       for(i=0;i<MAX_EVT_COUNT;i++){
+               if((evt_array[i].actual_status)==0 || evt_array[i].actual_status==3 ){
+                       evt_array[i]=*p_evt;
                        sig=1;
                        global_index=i;
                        break;
                }
-               if((array_req[i].id) < the_oldest.id){ //the smallest id (oldest request) will stay here
-                       the_oldest = array_req[i];
+               if((evt_array[i].id) < the_oldest.id){ //the smallest id (oldest request) will stay here
+                       the_oldest = evt_array[i];
                        index=i;
                        
                }
        }
        if(!sig){
                //return -1;
-               array_req[index]=*p_req;
+               evt_array[index]=*p_req;
                global_index=index;     
        }
        return 0;
@@ -54,27 +54,71 @@ void rutine_con_req(void *arg){
 
 }
 
+void rutine_cmd_status(void *arg){
+
+
+}
+
+int check_socket(int *p_dd){
+
+
+return 0;
+}
+
 
 
 
 int main(void){
 
-       cmd_state_request new_req,*p_new_req=&new_req;
-       memset(array_req,0,(sizeof(cmd_state_request)*MAX_CMD_STATE_REQUEST));
-       cmd_req_id=0;
+       incoming_evt new_evt,*p_new_evt=&new_evt;
+       struct hci_filter nf, of;
+       int len;
+       memset(evt_array,0,(sizeof(incoming_evt)*MAX_EVT_COUNT));
+       evt_id=0;
        global_index=0;
        
-       p_new_req->id=cmd_req_id++;
-       //p_new_req->req_opcode = ocf_ogf;
-       p_new_req->evt_code = EVT_CONN_REQUEST;
-       p_new_req->p_serv_rutine=&rutine_con_req;       
+       p_new_evt->id=evt_id++;
+       p_new_evt->actual_status=PERMANENT;
+       p_new_req->evt_code = EVT_CMD_STATUS;
+       p_new_req->p_serv_rutine=&rutine_cmd_status;
        
        
+       int dd=hci_open_device(1); // only for testig 1 
+       add_evt_toarray(p_new_evt);
+       p_new_evt->id=evt_id++;
+       p_new_evt->actual_status=ESTABLISHED;
+       p_new_req->evt_code = EVT_CONN_REQUEST;
+       p_new_req->p_serv_rutine=&rutine_con_req;
+
+       len = sizeof(of);
+       if(getsockopt(dd, SOL_HCI, HCI_FILTER, &of, &len)<0){
+               printf("some problem with getsockopt: %d",dd);
+               return -1;
+       }
 
+       hci_filter_clear(&nf);
+       hci_filter_set_ptype(HCI_EVENT_PKT, &nf);
+       hci_filter_set_event(EVT_CMD_STATUS, &nf);
+       //hci_filter_set_event(EVT_INQUIRY_RESULT_WITH_RSSI, &nf);
+       //hci_filter_set_event(p_req->event, &nf);
+       //hci_filter_set_opcode(*(p_req->p_OCF_OGF), &nf);
+       
+       if(setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf))<0){
+               printf("some problem with setsockopt: %d",dd);
+               return -1;
+       }
+       
        while(1){
+               if(check_socket(dd)<0){
+                       printf("problem with sock checking \n");
+                       break;
+               }
+                       
                
 
        }
+       setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of));
+       hci_close_dev(dd);
 
 return 0;
 }