]> rtime.felk.cvut.cz Git - tiny-bt.git/commitdiff
slavetest check socket function was added
authorDavid Plotek <ploted1@fel.cvut.cz>
Thu, 7 Aug 2008 08:41:33 +0000 (10:41 +0200)
committerDavid Plotek <ploted1@fel.cvut.cz>
Thu, 7 Aug 2008 08:41:33 +0000 (10:41 +0200)
src/hcidriver.c
src/hil2cap.c
testf/t2/slavetest.c

index 8f74f41feab853370c442b796730f4fb484ee3af..109e8522884f234091179dd644871174d9ffe110 100644 (file)
@@ -227,7 +227,7 @@ int hci_send_request(int dd, hci_request *p_req,int timeout){
                while((len=read(dd, recbuf, sizeof(recbuf)))<0){
                        if(errno == EAGAIN || errno == EINTR)
                                continue;
-                       perror("Problem with cmd sending");
+                       perror("Problem with cmd reading");
                        goto fail;
                }
                printf("Count of received bytes %d \n ",len);
index a79042c5b88849540a08ca7161a76f58642f7aea..f06184ccfed90c41ad69bf1700e7dc52cb7a6850 100644 (file)
@@ -235,7 +235,7 @@ int main(void){
        }
        p_connection->master=master;
        //p_connection->slave.bdaddr=remote_bd_addr_array[0];
-       fill_add(&prefered,0xE1,0x03,0x24,0x63,0x89,0x22);
+       fill_add(&prefered,0x31,0x16,0xCA,0x72,0x02,0x00);
        p_connection->slave.bdaddr=prefered;
        if(create_master_connection(p_connection)<0){
                printf("connection error");
index cf66c8052dc4940f00d8724d623b7ce5e52bf6c2..612d50120c65acb75286d0073cf3140d612e4a90 100644 (file)
 #include <sys/poll.h>
 #include <sys/ioctl.h>
 #include "hcidriver.h"
+#include "hil2cap.h"
 
 incoming_evt evt_array[MAX_CMD_STATE_REQUEST];
 int evt_id;
 int global_index;
+struct hci_filter nnf, oof; // the oldest and newest filters
 
-int add_evt_toarray(incoming_evt *p_evt){ //fcn add the request at the end of array or replace the oldest request
+
+int factorial(int num){
+       if(num==1) return 1;
+       return num*factorial(num-1);
+}
+
+int hci_open_device(int dev_id){
+       struct sockaddr_hci address;
+       int dd;
+
+       if((dd=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){
+               perror("socket no created");
+                return dd; //it return -1 when socket isn't created
+       }
+
+       memset(&address,0,sizeof(address));
+       address.hci_family=AF_BLUETOOTH;
+       address.hci_dev=dev_id;
+       if(bind(dd,(struct sockaddr *) &address, sizeof(address))<0){
+               perror("Socket not binded to hci device");
+               close(dd);
+               return -1;
+       }
+
+       return dd;
+}
+
+int hci_close_dev(int dd){
+       return close(dd);
+}
+
+int add_evt_toarray(incoming_evt *p_evt,struct hci_filter *p_pf,int *p_fchanged){ //fcn add the request at the end of array or replace the oldest request
        int i,sig=0,index=0;
        incoming_evt the_oldest=evt_array[0];
-       
+
+
+       if(!hci_filter_test_event(p_evt->evt_code,&nnf)){
+               *p_pf=nnf;
+               *p_fchanged=1; 
+               hci_filter_set_event(p_evt->evt_code,&nnf);
+       }
        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;
@@ -43,24 +82,47 @@ int add_evt_toarray(incoming_evt *p_evt){ //fcn add the request at the end of ar
        }
        if(!sig){
                //return -1;
-               evt_array[index]=*p_req;
+               evt_array[index]=*p_evt;
                global_index=index;     
        }
        return 0;
 }
 
-void rutine_con_req(void *arg){
+
+void rutine_con_req(void){
 
 
 }
 
-void rutine_cmd_status(void *arg){
+void rutine_cmd_status(void){
 
 
 }
 
-int check_socket(int *p_dd){
-
+int check_socket(int dd){
+       int len,j;
+       __u8 recbuf[HCI_MAX_EVENT_SIZE],*p_recbuf;
+       
+       while((len=read(dd, recbuf, sizeof(recbuf)))<0){
+                       if(errno == EAGAIN || errno == EINTR)
+                               printf("error in read EAGAIN or EINTR \n");
+                               continue;
+                       perror("Problem with cmd reading \n");
+                       return -1;
+               }
+       
+       if(len){
+               printf("Count of received bytes %d \n ",len);
+               for(j=0;j<len;j++){
+                       printf("%2.2X ",recbuf[j]);     
+               }
+               printf("\n");
+               
+       }
+       else{
+               printf("There is nothing on socket %d \n",dd);
+               return 0;
+       }
 
 return 0;
 }
@@ -71,53 +133,56 @@ return 0;
 int main(void){
 
        incoming_evt new_evt,*p_new_evt=&new_evt;
-       struct hci_filter nf, of;
-       int len;
+       int fchanged=0;
+       socklen_t len;
+       struct hci_filter pf;
        memset(evt_array,0,(sizeof(incoming_evt)*MAX_EVT_COUNT));
        evt_id=0;
        global_index=0;
        
-       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(0); // only for testig 1 
        
-       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){
+       len = sizeof(oof); //the oldest filter
+       if(getsockopt(dd, SOL_HCI, HCI_FILTER, &oof, &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_clear(&nnf);
+       hci_filter_set_ptype(HCI_EVENT_PKT, &nnf);
        //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;
-       }
-       
+
+       p_new_evt->id=evt_id++;
+       p_new_evt->actual_status=PERMANENT;
+       p_new_evt->evt_code = EVT_CMD_STATUS;
+       p_new_evt->p_serv_rutine=&rutine_cmd_status;
+       add_evt_toarray(p_new_evt,&pf,&fchanged);
+               
+       p_new_evt->id=evt_id++;
+       p_new_evt->actual_status=ESTABLISHED;
+       p_new_evt->evt_code = EVT_CONN_REQUEST;
+       p_new_evt->p_serv_rutine=&rutine_con_req;
+       add_evt_toarray(p_new_evt,&pf,&fchanged);
+               
        while(1){
+
+               if(fchanged){
+                       if(setsockopt(dd, SOL_HCI, HCI_FILTER, &nnf, sizeof(nnf))<0){
+                       printf("some problem with setsockopt: %d",dd);
+                       return -1;
+                       }
+                       fchanged=0;
+               }
                if(check_socket(dd)<0){
                        printf("problem with sock checking \n");
+                       setsockopt(dd, SOL_HCI, HCI_FILTER, &pf, sizeof(pf));
                        break;
                }
-                       
                
+               printf("I doing something %d \n",factorial(100));
+                               
 
        }
-       setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of));
+       setsockopt(dd, SOL_HCI, HCI_FILTER, &oof, sizeof(oof));
        hci_close_dev(dd);
 
 return 0;