X-Git-Url: https://rtime.felk.cvut.cz/gitweb/tiny-bt.git/blobdiff_plain/9c8b02b8df6d9aba40d3947e07cde65a94fe8b0a..42bcee64136eb5ba8863125c06ec6da9968c6d47:/src/hcidriver.c diff --git a/src/hcidriver.c b/src/hcidriver.c index 109e852..823a545 100644 --- a/src/hcidriver.c +++ b/src/hcidriver.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #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); }