27 #include <linux/module.h>
28 #include <asm/ioctls.h>
33 #define VERSION "2.16"
36 #define BT_MAX_PROTO 8
41 static const char *
const bt_key_strings[
BT_MAX_PROTO] = {
42 "sk_lock-AF_BLUETOOTH-BTPROTO_L2CAP",
43 "sk_lock-AF_BLUETOOTH-BTPROTO_HCI",
44 "sk_lock-AF_BLUETOOTH-BTPROTO_SCO",
45 "sk_lock-AF_BLUETOOTH-BTPROTO_RFCOMM",
46 "sk_lock-AF_BLUETOOTH-BTPROTO_BNEP",
47 "sk_lock-AF_BLUETOOTH-BTPROTO_CMTP",
48 "sk_lock-AF_BLUETOOTH-BTPROTO_HIDP",
49 "sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP",
53 static const char *
const bt_slock_key_strings[
BT_MAX_PROTO] = {
54 "slock-AF_BLUETOOTH-BTPROTO_L2CAP",
55 "slock-AF_BLUETOOTH-BTPROTO_HCI",
56 "slock-AF_BLUETOOTH-BTPROTO_SCO",
57 "slock-AF_BLUETOOTH-BTPROTO_RFCOMM",
58 "slock-AF_BLUETOOTH-BTPROTO_BNEP",
59 "slock-AF_BLUETOOTH-BTPROTO_CMTP",
60 "slock-AF_BLUETOOTH-BTPROTO_HIDP",
61 "slock-AF_BLUETOOTH-BTPROTO_AVDTP",
70 bt_slock_key_strings[proto], &bt_slock_key[proto],
71 bt_key_strings[proto], &bt_lock_key[proto]);
87 bt_proto[
proto] = ops;
104 if (!bt_proto[proto])
126 if (!bt_proto[proto])
127 request_module(
"bt-proto-%d", proto);
133 if (bt_proto[proto] && try_module_get(bt_proto[proto]->
owner)) {
134 err = bt_proto[
proto]->
create(net, sock, proto, kern);
137 module_put(bt_proto[proto]->
owner);
148 sk_add_node(sk, &l->
head);
156 sk_del_node_init(sk);
163 BT_DBG(
"parent %p, sk %p", parent, sk);
167 bt_sk(sk)->parent = parent;
174 BT_DBG(
"sk %p state %d", sk, sk->sk_state);
176 list_del_init(&
bt_sk(sk)->accept_q);
177 bt_sk(sk)->parent->sk_ack_backlog--;
188 BT_DBG(
"parent %p", parent);
206 sock_graft(sk, newsock);
223 struct sock *
sk = sock->
sk;
228 BT_DBG(
"sock %p sk %p len %zu", sock, sk, len);
248 skb_reset_transport_header(skb);
251 sock_recv_ts_and_drops(msg, sk, skb);
255 return err ? : copied;
259 static long bt_sock_data_wait(
struct sock *
sk,
long timeo)
273 if (signal_pending(
current) || !timeo)
291 struct sock *sk = sock->
sk;
293 size_t target, copied = 0;
301 BT_DBG(
"sk %p size %zu", sk, size);
305 target = sock_rcvlowat(sk, flags &
MSG_WAITALL, size);
314 if (copied >= target)
317 err = sock_error(sk);
327 timeo = bt_sock_data_wait(sk, timeo);
330 err = sock_intr_errno(timeo);
336 chunk =
min_t(
unsigned int, skb->
len, size);
346 sock_recv_ts_and_drops(msg, sk, skb);
349 int skb_len = skb_headlen(skb);
351 if (chunk <= skb_len) {
352 __skb_pull(skb, chunk);
356 __skb_pull(skb, skb_len);
359 skb_walk_frags(skb, frag) {
360 if (chunk <= frag->
len) {
364 __skb_pull(frag, chunk);
366 }
else if (frag->
len) {
371 __skb_pull(frag, frag->
len);
391 return copied ? :
err;
395 static inline unsigned int bt_accept_poll(
struct sock *parent)
414 struct sock *sk = sock->
sk;
415 unsigned int mask = 0;
417 BT_DBG(
"sock %p, sk %p", sock, sk);
419 poll_wait(file, sk_sleep(sk), wait);
422 return bt_accept_poll(sk);
455 struct sock *sk = sock->
sk;
460 BT_DBG(
"sk %p cmd %x arg %lx", sk, cmd, arg);
467 amount = sk->
sk_sndbuf - sk_wmem_alloc_get(sk);
479 amount = skb ? skb->
len : 0;
510 while (sk->sk_state != state) {
517 err = sock_intr_errno(timeo);
526 err = sock_error(sk);
536 #ifdef CONFIG_PROC_FS
537 struct bt_seq_state {
541 static void *bt_seq_start(
struct seq_file *seq, loff_t *
pos)
544 struct bt_seq_state *
s =
seq->private;
551 static void *bt_seq_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
553 struct bt_seq_state *
s = seq->
private;
559 static void bt_seq_stop(
struct seq_file *seq,
void *
v)
562 struct bt_seq_state *
s =
seq->private;
568 static int bt_seq_show(
struct seq_file *seq,
void *
v)
570 struct bt_seq_state *
s = seq->
private;
572 bdaddr_t src_baswapped, dst_baswapped;
575 seq_puts(seq ,
"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
577 if (l->custom_seq_show) {
579 l->custom_seq_show(seq, v);
584 struct sock *sk = sk_entry(v);
589 seq_printf(seq,
"%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
592 sk_rmem_alloc_get(sk),
593 sk_wmem_alloc_get(sk),
600 if (l->custom_seq_show) {
602 l->custom_seq_show(seq, v);
611 .
start = bt_seq_start,
620 struct bt_seq_state *
s;
622 sk_list = PDE(inode)->data;
624 sizeof(
struct bt_seq_state));
634 int (* seq_show)(
struct seq_file *,
void *))
638 sk_list->custom_seq_show = seq_show;
640 sk_list->fops.owner = module;
641 sk_list->fops.open = bt_seq_open;
662 int (* seq_show)(
struct seq_file *,
void *))
677 .create = bt_sock_create,
680 static int __init bt_init(
void)
696 BT_INFO(
"HCI device and connection manager initialized");
724 static void __exit bt_exit(
void)