]> rtime.felk.cvut.cz Git - tiny-bt.git/blobdiff - src/hil2cap.c
next new support functions were added and old ideas were deleted
[tiny-bt.git] / src / hil2cap.c
index d7e2b221f5e052a156cd84cacf8e29e26a429c3c..8162cc9b77d7d13e51399d6bea1f3a81e8c46d9f 100644 (file)
 
 cmd_state_request array_req[MAX_CMD_STATE_REQUEST];
 int cmd_req_id;
+int global_index;
 
 
 
 
-int create_master_connection(hci_dev_info *master){//establish connection and send a coutn of bytes every x second
+int create_master_connection(struct hci_dev_info *master){//establish connection and send a coutn of bytes every x second
         //array of open request which are in waiting state for appropriate event or answer
        connection_hci connection,*p_connection=&connection;
        p_connection->con_id=0;
@@ -40,14 +41,15 @@ int create_master_connection(hci_dev_info *master){//establish connection and se
 
        }
        
-
+       return 0;
 }
 
-int show_all_local_dev(hci_dev_info *master){ // and choose a master device which will initiate the connection
+int show_all_local_dev(struct hci_dev_info *master){ // and choose a master device which will initiate the connection
        int sock,i;
-       hci_dev_list_req dlist,*p_dlist=&dlist;
-       hci_dev_req *p_dreq;
+       struct hci_dev_list_req dlist,*p_dlist=&dlist;
+       struct hci_dev_req *p_dreq;
        
+       p_dlist->dev_num=HCI_MAX_DEV;
        p_dreq=p_dlist->dev_req;
        
        if((sock=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){ 
@@ -58,7 +60,7 @@ int show_all_local_dev(hci_dev_info *master){ // and choose a master device whic
                return -1;
        }
        if(p_dlist->dev_num > 0){
-               hci_dev_info dev_array[p_dlist->dev_num];
+               struct hci_dev_info dev_array[p_dlist->dev_num];
                for(i=0;i<p_dlist->dev_num;i++){
                        dev_array[i].dev_id=(p_dreq+i)->dev_id;
                        if(ioctl(sock, HCIGETDEVINFO, (void *) &dev_array[i])<0){
@@ -66,11 +68,11 @@ int show_all_local_dev(hci_dev_info *master){ // and choose a master device whic
                                continue;
                        }
                        int dd=hci_open_device(dev_array[i].dev_id);
-                       if(l2cap_call_cmd(READ_BD_ADDR_CMD_OP,dd)< 0){
+                       if(l2cap_call_cmd(READ_BD_ADDR_CMD_OP,dd,&dev_array[i].bdaddr)< 0){
                                printf("Error in call hci bd addr cmd \n");
                                return -1;
                        }
-                       if(l2cap_call_cmd(READ_LOCAL_NAME_CMD_OP,dd)< 0){
+                       if(l2cap_call_cmd(READ_LOCAL_NAME_CMD_OP,dd,&dev_array[i].name)< 0){
                                printf("Error in call hci bd addr cmd \n");
                                return -1;
                        }
@@ -82,17 +84,19 @@ int show_all_local_dev(hci_dev_info *master){ // and choose a master device whic
                printf("There is no hci device \n");
                return -1;
        }
+       return 0;
                
 }
 
-int l2cap_call_cmd(__u16 ocf_ogf,int dd){
+int l2cap_call_cmd(__u16 ocf_ogf,int dd, void *p_param){
        cmd_state_request new_req,*p_new_req=&new_req;
-
+       __u16 sw_opcode;
+       sw_opcode=swap_2_bytes(ocf_ogf);        
        switch(ocf_ogf){
        
        case READ_BD_ADDR_CMD_OP:{
                p_new_req->actual_status=ESTABLISHED;
-               p_new_req->id=cmd_rq_id++;
+               p_new_req->id=cmd_req_id++;
                p_new_req->req_opcode = ocf_ogf;
                p_new_req->evt_code = EVT_CMD_COMPLETE;
                p_new_req->p_serv_rutine=rutine_catch_bd_addr;
@@ -101,18 +105,37 @@ int l2cap_call_cmd(__u16 ocf_ogf,int dd){
                        printf("Mistake with req array adding \n ");
                        return -1;
                }
-               call_hci_read_bd_addr_cmd()
+               
+               if(call_hci_read_bd_addr_cmd(dd,(bt_address *)p_param,&sw_opcode)){
+                       printf("Mistake with bt addr cmd \n ");
+                       return -1;
+               }
+               req_fcn_remove();
+               return 0;
                
        
        }
        case READ_LOCAL_NAME_CMD_OP:{
+               p_new_req->actual_status=ESTABLISHED;
+               p_new_req->id=cmd_req_id++;
+               p_new_req->req_opcode = ocf_ogf;
+               p_new_req->evt_code = EVT_CMD_COMPLETE;
+               p_new_req->p_serv_rutine=rutine_catch_bd_addr;
 
+               if(req_fcn_add(p_new_req)<0){
+                       printf("Mistake with req array adding \n ");
+                       return -1;
+               }
+               if(call_hci_read_local_name_cmd(dd,p_param,&sw_opcode)){
+                       printf("Mistake with read local name cmd \n ");
+                       return -1;
+               }
+               req_fcn_remove();
+               return 0;
        }
-
-       
        }
        
-
+       return 0;
 }
 /* request array support functions */
 int req_fcn_add(cmd_state_request *p_req){ //fcn add the request at the end of array or replace the oldest request
@@ -120,21 +143,28 @@ int req_fcn_add(cmd_state_request *p_req){ //fcn add the request at the end of a
        cmd_state_request the_oldest=array_req[0];
        
        for(i=0;i<MAX_CMD_STATE_REQUEST;i++){
-               if(array_req[i]->actual_status==0 || array_req[i]->actual_status==3 ){
+               if((array_req[i].actual_status)==0 || array_req[i].actual_status==3 ){
                        array_req[i]=*p_req;
                        sig=1;
+                       global_index=i;
                        break;
                }
-               if(array_req[i]->id < the_oldest.id){ //the smallest id (oldest request) will stay here
+               if((array_req[i].id) < the_oldest.id){ //the smallest id (oldest request) will stay here
                        the_oldest = array_req[i];
                        index=i;
+                       
                }
        }
        if(!sig){
-               return -1;
-               array_req[index]=*p_req;        
+               //return -1;
+               array_req[index]=*p_req;
+               global_index=index;     
        }
-       return 1;
+       return 0;
+}
+
+void req_fcn_remove(void){
+       array_req[global_index].actual_status=DONE;
 }
 
 /* rutines for each command */
@@ -148,7 +178,12 @@ return (void*)0;
 int main(void){
        struct hci_dev_info master,*p_master=&master;
        cmd_req_id=0;
-       memset(array_req,0,(sizeof(cmd_state_request)*));
+       global_index=0;
+       memset(array_req,0,(sizeof(cmd_state_request)*MAX_CMD_STATE_REQUEST));
+       if(show_all_local_dev(p_master)<0){
+               printf("error no dev \n");
+               return -1;
+       }