2 * C Implementation: bt_hw
4 * Description: hardweare function for sockets
7 * Author: root <root@ubuntu>, (C) 2008
9 * Copyright: See COPYING file that comes with this distribution
13 #include <sys/socket.h>
16 #include <sys/ioctl.h>
23 #include "hciembeded.h"
25 static int hw_dd; /*TODO: this is only for one socket connection */
27 int hw_bt_open_device(__u8 dev_id)
29 struct sockaddr_hci address;
34 if ((dd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
35 perror("socket no created");
36 return dd; /*it return -1 when socket isn't created*/
39 oldflag = fcntl(dd, F_GETFL, 0);
40 if (fcntl(dd, F_SETFL, oldflag | O_NONBLOCK) < 0) {
41 perror("problem with socket flag setting");
46 memset(&address, 0, sizeof(address));
47 address.hci_family = AF_BLUETOOTH;
48 address.hci_dev = dev_id;
49 if (bind(dd, (struct sockaddr *) &address, sizeof(address)) < 0) {
50 perror("Socket not binded to hci device");
55 if(ioctl(dd, HCISETRAW, 1) < 0) {
56 perror("error in ioctl HCISETRAW");
73 int hw_bt_write(__u8 *p_array, __u16 length)
75 while (write(hw_dd, p_array, length) < 0) {
76 perror("write interrupted");
77 if (errno == EAGAIN || errno == EINTR)
85 int hw_bt_read(__u8 *p_recbuf)
89 while ((len = read(hw_dd, p_recbuf,
90 sizeof(p_recbuf) * HCI_MAX_EVENT_SIZE)) < 0) {
95 perror("Problem with reading\n");