27 #include <linux/export.h>
28 #include <asm/unaligned.h>
38 static inline int hci_test_bit(
int nr,
void *
addr)
40 return *((
__u32 *) addr + (nr >> 5)) & ((
__u32) 1 << (nr & 31));
48 { 0x1000d9fe, 0x0000b00c },
53 { 0xbe000006, 0x00000001, 0x00000000, 0x00 },
55 { 0x00005200, 0x00000000, 0x00000000, 0x00 },
57 { 0xaab00200, 0x2b402aaa, 0x05220154, 0x00 },
59 { 0x000002be, 0x00000000, 0x00000000, 0x00 },
61 { 0x000000ea, 0x00000000, 0x00000000, 0x00 }
186 BT_DBG(
"hdev %p len %d", hdev, skb->
len);
196 if (
bt_cb(skb)->incoming)
202 if (
bt_cb(skb)->incoming)
251 static void send_monitor_event(
struct sk_buff *
skb)
314 __net_timestamp(skb);
324 static void send_monitor_replay(
struct sock *sk)
363 bt_cb(skb)->incoming = 1;
364 __net_timestamp(skb);
367 skb->
dev = (
void *) hdev;
376 BT_DBG(
"hdev %s event %d", hdev->
name, event);
382 skb = create_monitor_event(hdev, event);
384 send_monitor_event(skb);
402 if (
hci_pi(sk)->hdev == hdev) {
416 static int hci_sock_release(
struct socket *
sock)
418 struct sock *sk = sock->
sk;
421 BT_DBG(
"sock %p sk %p", sock, sk);
447 static int hci_sock_blacklist_add(
struct hci_dev *hdev,
void __user *
arg)
464 static int hci_sock_blacklist_del(
struct hci_dev *hdev,
void __user *arg)
482 static int hci_sock_bound_ioctl(
struct sock *sk,
unsigned int cmd,
514 return hci_sock_blacklist_add(hdev, (
void __user *) arg);
519 return hci_sock_blacklist_del(hdev, (
void __user *) arg);
523 return hdev->
ioctl(hdev, cmd, arg);
528 static int hci_sock_ioctl(
struct socket *sock,
unsigned int cmd,
531 struct sock *sk = sock->
sk;
535 BT_DBG(
"cmd %x arg %lx", cmd, arg);
584 err = hci_sock_bound_ioctl(sk, cmd, arg);
590 static int hci_sock_bind(
struct socket *sock,
struct sockaddr *addr,
594 struct sock *sk = sock->
sk;
598 BT_DBG(
"sock %p sk %p", sock, sk);
603 memset(&haddr, 0,
sizeof(haddr));
604 len =
min_t(
unsigned int,
sizeof(haddr), addr_len);
605 memcpy(&haddr, addr, len);
617 switch (haddr.hci_channel) {
661 send_monitor_replay(sk);
672 hci_pi(sk)->channel = haddr.hci_channel;
680 static int hci_sock_getname(
struct socket *sock,
struct sockaddr *addr,
681 int *addr_len,
int peer)
684 struct sock *sk = sock->
sk;
687 BT_DBG(
"sock %p sk %p", sock, sk);
694 *addr_len =
sizeof(*haddr);
703 static void hci_sock_cmsg(
struct sock *sk,
struct msghdr *
msg,
709 int incoming =
bt_cb(skb)->incoming;
722 skb_get_timestamp(skb, &tv);
727 if (!COMPAT_USE_64BIT_TIME &&
729 ctv.tv_sec = tv.tv_sec;
730 ctv.tv_usec = tv.tv_usec;
744 struct sock *sk = sock->
sk;
748 BT_DBG(
"sock %p, sk %p", sock, sk);
768 skb_reset_transport_header(skb);
773 hci_sock_cmsg(sk, msg, skb);
777 sock_recv_timestamp(msg, sk, skb);
783 return err ? : copied;
786 static int hci_sock_sendmsg(
struct kiocb *iocb,
struct socket *sock,
787 struct msghdr *msg,
size_t len)
789 struct sock *sk = sock->
sk;
794 BT_DBG(
"sock %p sk %p", sock, sk);
832 skb = bt_skb_send_alloc(sk, len, msg->
msg_flags & MSG_DONTWAIT, &err);
841 bt_cb(skb)->pkt_type = *((
unsigned char *) skb->
data);
843 skb->
dev = (
void *) hdev;
846 u16 opcode = get_unaligned_le16(skb->
data);
886 static int hci_sock_setsockopt(
struct socket *sock,
int level,
int optname,
887 char __user *optval,
unsigned int len)
890 struct sock *sk = sock->
sk;
891 int err = 0,
opt = 0;
893 BT_DBG(
"sk %p, opt %d", sk, optname);
912 hci_pi(sk)->cmsg_mask &= ~HCI_CMSG_DIR;
924 hci_pi(sk)->cmsg_mask &= ~HCI_CMSG_TSTAMP;
937 len =
min_t(
unsigned int, len,
sizeof(uf));
969 static int hci_sock_getsockopt(
struct socket *sock,
int level,
int optname,
970 char __user *optval,
int __user *optlen)
973 struct sock *sk = sock->
sk;
976 BT_DBG(
"sk %p, opt %d", sk, optname);
990 if (
hci_pi(sk)->cmsg_mask & HCI_CMSG_DIR)
1000 if (
hci_pi(sk)->cmsg_mask & HCI_CMSG_TSTAMP)
1013 memset(&uf, 0,
sizeof(uf));
1020 len =
min_t(
unsigned int, len,
sizeof(uf));
1035 static const struct proto_ops hci_sock_ops = {
1038 .release = hci_sock_release,
1039 .bind = hci_sock_bind,
1040 .getname = hci_sock_getname,
1041 .sendmsg = hci_sock_sendmsg,
1042 .recvmsg = hci_sock_recvmsg,
1043 .ioctl = hci_sock_ioctl,
1047 .setsockopt = hci_sock_setsockopt,
1048 .getsockopt = hci_sock_getsockopt,
1055 static struct proto hci_sk_proto = {
1071 sock->
ops = &hci_sock_ops;
1093 .create = hci_sock_create,
1106 BT_ERR(
"HCI socket registration failed");
1112 BT_ERR(
"Failed to create HCI proc file");
1117 BT_INFO(
"HCI socket layer initialized");
1130 BT_ERR(
"HCI socket unregistration failed");