]> rtime.felk.cvut.cz Git - tiny-bt.git/blobdiff - src/hcidriver.c
hcidriver.c:new non block cmd call.
[tiny-bt.git] / src / hcidriver.c
index 109e8522884f234091179dd644871174d9ffe110..823a545f4677985fafce5c1c1c563eab57b33298 100644 (file)
@@ -4,6 +4,8 @@
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <stdint.h>
+#include <fcntl.h>
 #include <sys/poll.h>
 #include <sys/ioctl.h>
 #include "hcidriver.h"
@@ -11,6 +13,7 @@
 
 
 
+
 /************************** hci command functions**************************/
 int call_hci_inquiry_cmd(int dd, void *p_addressarray,__u16 *p_ocf_ogf){
        inquiry_cp cmdp,*p_cmdp=&cmdp;
@@ -102,6 +105,24 @@ int call_hci_create_connection_cmd(int dd, bt_address *p_address, __u16 *p_ocf_o
        
 }
 
+int call_hci_accept_conn_req_cmd(int dd, bt_address *p_address, __u16 *p_ocf_ogf){
+       accept_conn_req_cp cmdp, *p_cmdp=&cmdp;
+       hci_request req,*p_req=&req;
+       
+       p_cmdp->bdaddr=*p_address;
+       p_cmdp->role=0x01;
+       memset(p_req,0,sizeof(req));
+       p_req->p_OCF_OGF=p_ocf_ogf;
+       p_req->p_cmdp=p_cmdp;
+       p_req->cmdp_len=ACCEPT_CONN_REQ_CP_SIZE;
+       
+       if(hci_send_command(dd,p_req)<0){
+               printf("problem with command sending\n");
+               return -1;
+       }
+       return 0;
+}
+
 
 /*******************************HCI main functions ********************************/
 
@@ -127,6 +148,34 @@ int hci_open_device(int dev_id){
        return dd;
 }
 
+int hci_open_device_nonblock(int dev_id){
+       struct sockaddr_hci address;
+       int dd;
+       int oldflag;
+
+       if((dd=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){
+               perror("socket no created");
+                return dd; //it return -1 when socket isn't created
+       }
+       
+       oldflag=fcntl(dd, F_GETFL, 0);
+        if(fcntl(dd, F_SETFL, oldflag | O_NONBLOCK) < 0){
+            printf("problem with socket flag setting");
+            return -1;
+        }
+
+       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);
 }