Update of /cvsroot/linux-vax/kernel-2.4/net/bluetooth In directory usw-pr-cvs1:/tmp/cvs-serv30993/bluetooth Added Files: Config.in Makefile af_bluetooth.c hci_core.c hci_sock.c l2cap_core.c l2cap_proc.c lib.c syms.c Log Message: synch 2.4.15 commit 19 --- NEW FILE --- # # Bluetooth configuration # if [ "$CONFIG_NET" != "n" ]; then mainmenu_option next_comment comment 'Bluetooth support' dep_tristate 'Bluetooth subsystem support' CONFIG_BLUEZ $CONFIG_NET if [ "$CONFIG_BLUEZ" != "n" ]; then dep_tristate 'L2CAP protocol support' CONFIG_BLUEZ_L2CAP $CONFIG_BLUEZ source drivers/bluetooth/Config.in fi endmenu fi --- NEW FILE --- # # Makefile for the Bluetooth subsystem # O_TARGET := bluetooth.o list-multi := hci.o l2cap.o export-objs := syms.o hci-objs := af_bluetooth.o hci_core.o hci_sock.o lib.o syms.o l2cap-objs := l2cap_core.o l2cap_proc.o obj-$(CONFIG_BLUEZ) += hci.o obj-$(CONFIG_BLUEZ_L2CAP) += l2cap.o include $(TOPDIR)/Rules.make hci.o: $(hci-objs) $(LD) -r -o $@ $(hci-objs) l2cap.o: $(l2cap-objs) $(LD) -r -o $@ $(l2cap-objs) --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. */ /* * BlueZ Bluetooth address family and sockets. * * $Id: af_bluetooth.c,v 1.1 2002/04/09 16:22:03 atp Exp $ */ #define VERSION "1.1" #include <linux/config.h> #include <linux/module.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/major.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/skbuff.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <net/sock.h> #if defined(CONFIG_KMOD) #include <linux/kmod.h> #endif #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluez.h> /* Bluetooth sockets */ static struct net_proto_family *bluez_sock[BLUEZ_MAX_PROTO]; int bluez_sock_register(int proto, struct net_proto_family *ops) { if (proto > BLUEZ_MAX_PROTO) return -EINVAL; if (bluez_sock[proto]) return -EEXIST; bluez_sock[proto] = ops; return 0; } int bluez_sock_unregister(int proto) { if (proto > BLUEZ_MAX_PROTO) return -EINVAL; if (!bluez_sock[proto]) return -ENOENT; bluez_sock[proto] = NULL; return 0; } static int bluez_sock_create(struct socket *sock, int proto) { if (proto > BLUEZ_MAX_PROTO) return -EINVAL; #if defined(CONFIG_KMOD) if (!bluez_sock[proto]) { char module_name[30]; sprintf(module_name, "bt-proto-%d", proto); request_module(module_name); } #endif if (!bluez_sock[proto]) return -ENOENT; return bluez_sock[proto]->create(sock, proto); } void bluez_sock_link(struct bluez_sock_list *l, struct sock *sk) { write_lock(&l->lock); sk->next = l->head; l->head = sk; sock_hold(sk); write_unlock(&l->lock); } void bluez_sock_unlink(struct bluez_sock_list *l, struct sock *sk) { struct sock **skp; write_lock(&l->lock); for (skp = &l->head; *skp; skp = &((*skp)->next)) { if (*skp == sk) { *skp = sk->next; __sock_put(sk); break; } } write_unlock(&l->lock); } struct net_proto_family bluez_sock_family_ops = { PF_BLUETOOTH, bluez_sock_create }; int bluez_init(void) { INF("BlueZ HCI Core ver %s Copyright (C) 2000,2001 Qualcomm Inc", VERSION); INF("Written 2000,2001 by Maxim Krasnyansky <ma...@qu...>"); proc_mkdir("bluetooth", NULL); sock_register(&bluez_sock_family_ops); /* Init HCI Core */ hci_core_init(); /* Init sockets */ hci_sock_init(); return 0; } void bluez_cleanup(void) { /* Release socket */ hci_sock_cleanup(); /* Release core */ hci_core_cleanup(); sock_unregister(PF_BLUETOOTH); remove_proc_entry("bluetooth", NULL); } #ifdef MODULE module_init(bluez_init); module_exit(bluez_cleanup); MODULE_AUTHOR("Maxim Krasnyansky <ma...@qu...>"); MODULE_DESCRIPTION("BlueZ HCI Core ver " VERSION); #endif --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. [...1993 lines suppressed...] skb_queue_tail(&hdev->rx_q, skb); hci_sched_rx(hdev); return 0; } int hci_core_init(void) { /* Init locks */ spin_lock_init(&hdev_list_lock); return 0; } int hci_core_cleanup(void) { return 0; } MODULE_LICENSE("GPL"); --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. */ /* * BlueZ HCI socket layer. * * $Id: hci_sock.c,v 1.1 2002/04/09 16:22:03 atp Exp $ */ #include <linux/config.h> #include <linux/module.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/major.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/poll.h> #include <linux/fcntl.h> #include <linux/init.h> #include <linux/skbuff.h> #include <linux/tqueue.h> #include <linux/interrupt.h> #include <linux/socket.h> #include <linux/ioctl.h> #include <net/sock.h> #include <asm/system.h> #include <asm/uaccess.h> #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluez.h> #include <net/bluetooth/hci_core.h> #ifndef HCI_SOCK_DEBUG #undef DBG #define DBG( A... ) #endif /* HCI socket interface */ static struct bluez_sock_list hci_sk_list = { lock: RW_LOCK_UNLOCKED }; static struct sock *hci_sock_lookup(struct hci_dev *hdev) { struct sock *sk; read_lock(&hci_sk_list.lock); for (sk = hci_sk_list.head; sk; sk = sk->next) { if (hci_pi(sk)->hdev == hdev) break; } read_unlock(&hci_sk_list.lock); return sk; } /* Send frame to RAW socket */ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb) { struct sock * sk; DBG("hdev %p len %d", hdev, skb->len); read_lock(&hci_sk_list.lock); for (sk = hci_sk_list.head; sk; sk = sk->next) { struct hci_filter *flt; struct sk_buff *nskb; if (sk->state != BT_BOUND || hci_pi(sk)->hdev != hdev) continue; /* Don't send frame to the socket it came from */ if (skb->sk == sk) continue; /* Apply filter */ flt = &hci_pi(sk)->filter; if (!test_bit(skb->pkt_type, &flt->type_mask)) continue; if (skb->pkt_type == HCI_EVENT_PKT) { register int evt = (*(__u8 *)skb->data & 63); if (!test_bit(evt, &flt->event_mask)) continue; } if (!(nskb = skb_clone(skb, GFP_ATOMIC))) continue; /* Put type byte before the data */ memcpy(skb_push(nskb, 1), &nskb->pkt_type, 1); skb_queue_tail(&sk->receive_queue, nskb); sk->data_ready(sk, nskb->len); } read_unlock(&hci_sk_list.lock); } static int hci_sock_release(struct socket *sock) { struct sock *sk = sock->sk; struct hci_dev *hdev = hci_pi(sk)->hdev; DBG("sock %p sk %p", sock, sk); if (!sk) return 0; bluez_sock_unlink(&hci_sk_list, sk); if (hdev) { if (!hci_sock_lookup(hdev)) hdev->flags &= ~HCI_SOCK; hci_dev_put(hdev); } sock_orphan(sk); skb_queue_purge(&sk->receive_queue); skb_queue_purge(&sk->write_queue); sock_put(sk); MOD_DEC_USE_COUNT; return 0; } static int hci_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { struct sock *sk = sock->sk; struct hci_dev *hdev = hci_pi(sk)->hdev; __u32 mode; DBG("cmd %x arg %lx", cmd, arg); switch (cmd) { case HCIGETINFO: return hci_dev_info(arg); case HCIGETDEVLIST: return hci_dev_list(arg); case HCIDEVUP: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_open(arg); case HCIDEVDOWN: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_close(arg); case HCIDEVRESET: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_reset(arg); case HCIRESETSTAT: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_reset_stat(arg); case HCISETSCAN: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_setscan(arg); case HCISETAUTH: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_setauth(arg); case HCISETRAW: if (!capable(CAP_NET_ADMIN)) return -EACCES; if (!hdev) return -EBADFD; if (arg) mode = HCI_RAW; else mode = HCI_NORMAL; return hci_dev_setmode(hdev, mode); case HCISETPTYPE: if (!capable(CAP_NET_ADMIN)) return -EACCES; return hci_dev_setptype(arg); case HCIINQUIRY: return hci_inquiry(arg); case HCIGETCONNLIST: return hci_conn_list(arg); default: return -EINVAL; }; } static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) { struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr; struct sock *sk = sock->sk; struct hci_dev *hdev = NULL; DBG("sock %p sk %p", sock, sk); if (!haddr || haddr->hci_family != AF_BLUETOOTH) return -EINVAL; if (hci_pi(sk)->hdev) { /* Already bound */ return 0; } if (haddr->hci_dev != HCI_DEV_NONE) { if (!(hdev = hci_dev_get(haddr->hci_dev))) return -ENODEV; hdev->flags |= HCI_SOCK; } hci_pi(sk)->hdev = hdev; sk->state = BT_BOUND; return 0; } static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *addr_len, int peer) { struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr; struct sock *sk = sock->sk; DBG("sock %p sk %p", sock, sk); *addr_len = sizeof(*haddr); haddr->hci_family = AF_BLUETOOTH; haddr->hci_dev = hci_pi(sk)->hdev->id; return 0; } static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg, int len, struct scm_cookie *scm) { struct sock *sk = sock->sk; struct hci_dev *hdev = hci_pi(sk)->hdev; struct sk_buff *skb; int err; DBG("sock %p sk %p", sock, sk); if (msg->msg_flags & MSG_OOB) return -EOPNOTSUPP; if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE)) return -EINVAL; if (!hdev) return -EBADFD; if (!(skb = bluez_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err))) return err; if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) { kfree_skb(skb); return -EFAULT; } skb->dev = (void *) hdev; skb->pkt_type = *((unsigned char *) skb->data); skb_pull(skb, 1); /* Send frame to HCI core */ hci_send_raw(skb); return len; } static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb) { __u32 mask = hci_pi(sk)->cmsg_mask; if (mask & HCI_CMSG_DIR) put_cmsg(msg, SOL_HCI, HCI_CMSG_DIR, sizeof(int), &bluez_cb(skb)->incomming); } static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg, int len, int flags, struct scm_cookie *scm) { int noblock = flags & MSG_DONTWAIT; struct sock *sk = sock->sk; struct sk_buff *skb; int copied, err; DBG("sock %p sk %p", sock, sk); if (flags & (MSG_OOB | MSG_PEEK)) return -EOPNOTSUPP; if (!(skb = skb_recv_datagram(sk, flags, noblock, &err))) return err; msg->msg_namelen = 0; copied = skb->len; if (len < copied) { msg->msg_flags |= MSG_TRUNC; copied = len; } skb->h.raw = skb->data; err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); if (hci_pi(sk)->cmsg_mask) hci_sock_cmsg(sk, msg, skb); skb_free_datagram(sk, skb); return err ? : copied; } int hci_sock_setsockopt(struct socket *sock, int level, int optname, char *optval, int len) { struct sock *sk = sock->sk; struct hci_filter flt; int err = 0, opt = 0; DBG("sk %p, opt %d", sk, optname); lock_sock(sk); switch (optname) { case HCI_DATA_DIR: if (get_user(opt, (int *)optval)) return -EFAULT; if (opt) hci_pi(sk)->cmsg_mask |= HCI_CMSG_DIR; else hci_pi(sk)->cmsg_mask &= ~HCI_CMSG_DIR; break; case HCI_FILTER: len = MIN(len, sizeof(struct hci_filter)); if (copy_from_user(&flt, optval, len)) { err = -EFAULT; break; } memcpy(&hci_pi(sk)->filter, &flt, len); break; default: err = -ENOPROTOOPT; break; }; release_sock(sk); return err; } int hci_sock_getsockopt(struct socket *sock, int level, int optname, char *optval, int *optlen) { struct sock *sk = sock->sk; int len, opt; if (get_user(len, optlen)) return -EFAULT; switch (optname) { case HCI_DATA_DIR: if (hci_pi(sk)->cmsg_mask & HCI_CMSG_DIR) opt = 1; else opt = 0; if (put_user(opt, optval)) return -EFAULT; break; case HCI_FILTER: len = MIN(len, sizeof(struct hci_filter)); if (copy_to_user(optval, &hci_pi(sk)->filter, len)) return -EFAULT; break; default: return -ENOPROTOOPT; break; }; return 0; } struct proto_ops hci_sock_ops = { family: PF_BLUETOOTH, release: hci_sock_release, bind: hci_sock_bind, getname: hci_sock_getname, sendmsg: hci_sock_sendmsg, recvmsg: hci_sock_recvmsg, ioctl: hci_sock_ioctl, poll: datagram_poll, listen: sock_no_listen, shutdown: sock_no_shutdown, setsockopt: hci_sock_setsockopt, getsockopt: hci_sock_getsockopt, connect: sock_no_connect, socketpair: sock_no_socketpair, accept: sock_no_accept, mmap: sock_no_mmap }; static int hci_sock_create(struct socket *sock, int protocol) { struct sock *sk; DBG("sock %p", sock); if (sock->type != SOCK_RAW) return -ESOCKTNOSUPPORT; sock->ops = &hci_sock_ops; if (!(sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, 1))) return -ENOMEM; sock->state = SS_UNCONNECTED; sock_init_data(sock, sk); memset(&sk->protinfo, 0, sizeof(struct hci_pinfo)); sk->destruct = NULL; sk->protocol = protocol; sk->state = BT_OPEN; /* Initialize filter */ hci_pi(sk)->filter.type_mask = (1<<HCI_EVENT_PKT); hci_pi(sk)->filter.event_mask[0] = ~0L; hci_pi(sk)->filter.event_mask[1] = ~0L; bluez_sock_link(&hci_sk_list, sk); MOD_INC_USE_COUNT; return 0; } static int hci_sock_dev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct hci_dev *hdev = (struct hci_dev *) ptr; struct sk_buff *skb; DBG("hdev %s event %ld", hdev->name, event); /* Send event to sockets */ if ((skb = bluez_skb_alloc(HCI_EVENT_HDR_SIZE + EVT_HCI_DEV_EVENT_SIZE, GFP_ATOMIC))) { hci_event_hdr eh = { EVT_HCI_DEV_EVENT, EVT_HCI_DEV_EVENT_SIZE }; evt_hci_dev_event he = { event, hdev->id }; skb->pkt_type = HCI_EVENT_PKT; memcpy(skb_put(skb, HCI_EVENT_HDR_SIZE), &eh, HCI_EVENT_HDR_SIZE); memcpy(skb_put(skb, EVT_HCI_DEV_EVENT_SIZE), &he, EVT_HCI_DEV_EVENT_SIZE); hci_send_to_sock(NULL, skb); kfree_skb(skb); } if (event == HCI_DEV_UNREG) { struct sock *sk; /* Detach sockets from device */ read_lock(&hci_sk_list.lock); for (sk = hci_sk_list.head; sk; sk = sk->next) { if (hci_pi(sk)->hdev == hdev) { hci_pi(sk)->hdev = NULL; sk->err = EPIPE; sk->state = BT_OPEN; sk->state_change(sk); hci_dev_put(hdev); } } read_unlock(&hci_sk_list.lock); } return NOTIFY_DONE; } struct net_proto_family hci_sock_family_ops = { family: PF_BLUETOOTH, create: hci_sock_create }; struct notifier_block hci_sock_nblock = { notifier_call: hci_sock_dev_event }; int hci_sock_init(void) { if (bluez_sock_register(BTPROTO_HCI, &hci_sock_family_ops)) { ERR("Can't register HCI socket"); return -EPROTO; } hci_register_notifier(&hci_sock_nblock); return 0; } int hci_sock_cleanup(void) { if (bluez_sock_unregister(BTPROTO_HCI)) ERR("Can't unregister HCI socket"); hci_unregister_notifier(&hci_sock_nblock); return 0; } --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. [...2277 lines suppressed...] /* Free interface list and unlock HCI devices */ { struct list_head *list = &l2cap_iff_list; while (!list_empty(list)) { struct l2cap_iff *iff; iff = list_entry(list->next, struct l2cap_iff, list); l2cap_iff_del(iff->hdev); } } } module_init(l2cap_init); module_exit(l2cap_cleanup); MODULE_AUTHOR("Maxim Krasnyansky <ma...@qu...>"); MODULE_DESCRIPTION("BlueZ L2CAP ver " VERSION); MODULE_LICENSE("GPL"); --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. */ /* * BlueZ L2CAP proc fs support. * * $Id: l2cap_proc.c,v 1.1 2002/04/09 16:22:03 atp Exp $ */ #include <linux/config.h> #include <linux/module.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/major.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/poll.h> #include <linux/fcntl.h> #include <linux/init.h> #include <linux/skbuff.h> #include <linux/interrupt.h> #include <linux/socket.h> #include <linux/skbuff.h> #include <linux/proc_fs.h> #include <linux/list.h> #include <net/sock.h> #include <asm/system.h> #include <asm/uaccess.h> #include <net/bluetooth/bluez.h> #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h> #include <net/bluetooth/l2cap_core.h> #ifndef L2CAP_DEBUG #undef DBG #define DBG( A... ) #endif /* ----- PROC fs support ----- */ static int l2cap_conn_dump(char *buf, struct l2cap_iff *iff) { struct list_head *p; char *ptr = buf; list_for_each(p, &iff->conn_list) { struct l2cap_conn *c; c = list_entry(p, struct l2cap_conn, list); ptr += sprintf(ptr, " %p %d %p %p %s %s\n", c, c->state, c->iff, c->hconn, batostr(&c->src), batostr(&c->dst)); } return ptr - buf; } static int l2cap_iff_dump(char *buf) { struct list_head *p; char *ptr = buf; ptr += sprintf(ptr, "Interfaces:\n"); write_lock(&l2cap_rt_lock); list_for_each(p, &l2cap_iff_list) { struct l2cap_iff *iff; iff = list_entry(p, struct l2cap_iff, list); ptr += sprintf(ptr, " %s %p %p\n", iff->hdev->name, iff, iff->hdev); l2cap_iff_lock(iff); ptr += l2cap_conn_dump(ptr, iff); l2cap_iff_unlock(iff); } write_unlock(&l2cap_rt_lock); ptr += sprintf(ptr, "\n"); return ptr - buf; } static int l2cap_sock_dump(char *buf, struct bluez_sock_list *list) { struct l2cap_pinfo *pi; struct sock *sk; char *ptr = buf; ptr += sprintf(ptr, "Sockets:\n"); write_lock(&list->lock); for (sk = list->head; sk; sk = sk->next) { pi = l2cap_pi(sk); ptr += sprintf(ptr, " %p %d %p %d %s %s 0x%4.4x 0x%4.4x %d %d\n", sk, sk->state, pi->conn, pi->psm, batostr(&pi->src), batostr(&pi->dst), pi->scid, pi->dcid, pi->imtu, pi->omtu ); } write_unlock(&list->lock); ptr += sprintf(ptr, "\n"); return ptr - buf; } static int l2cap_read_proc(char *buf, char **start, off_t offset, int count, int *eof, void *priv) { char *ptr = buf; int len; DBG("count %d, offset %ld", count, offset); ptr += l2cap_iff_dump(ptr); ptr += l2cap_sock_dump(ptr, &l2cap_sk_list); len = ptr - buf; if (len <= count + offset) *eof = 1; *start = buf + offset; len -= offset; if (len > count) len = count; if (len < 0) len = 0; return len; } void l2cap_register_proc(void) { create_proc_read_entry("bluetooth/l2cap", 0, 0, l2cap_read_proc, NULL); } void l2cap_unregister_proc(void) { remove_proc_entry("bluetooth/l2cap", NULL); } --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. */ /* * BlueZ kernel library. * * $Id: lib.c,v 1.1 2002/04/09 16:22:03 atp Exp $ */ #include <linux/kernel.h> #include <linux/stddef.h> #include <linux/string.h> #include <asm/errno.h> #include <net/bluetooth/bluetooth.h> void bluez_dump(char *pref, __u8 *buf, int count) { char *ptr; char line[100]; int i; printk(KERN_INFO "%s: dump, len %d\n", pref, count); ptr = line; *ptr = 0; for (i = 0; i<count; i++) { ptr += sprintf(ptr, " %2.2X", buf[i]); if (i && !((i + 1) % 20)) { printk(KERN_INFO "%s:%s\n", pref, line); ptr = line; *ptr = 0; } } if (line[0]) printk(KERN_INFO "%s:%s\n", pref, line); } void baswap(bdaddr_t *dst, bdaddr_t *src) { unsigned char *d = (unsigned char *) dst; unsigned char *s = (unsigned char *) src; int i; for (i = 0; i < 6; i++) d[i] = s[5 - i]; } char *batostr(bdaddr_t *ba) { static char str[2][18]; static int i = 1; i ^= 1; sprintf(str[i], "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", ba->b[0], ba->b[1], ba->b[2], ba->b[3], ba->b[4], ba->b[5]); return str[i]; } /* Bluetooth error codes to Unix errno mapping */ int bterr(__u16 code) { switch (code) { case 0: return 0; case 0x01: return EBADRQC; case 0x02: return ENOTCONN; case 0x03: return EIO; case 0x04: return EHOSTDOWN; case 0x05: return EACCES; case 0x06: return EINVAL; case 0x07: return ENOMEM; case 0x08: return ETIMEDOUT; case 0x09: return EMLINK; case 0x0a: return EMLINK; case 0x0b: return EALREADY; case 0x0c: return EBUSY; case 0x0d: case 0x0e: case 0x0f: return ECONNREFUSED; case 0x10: return ETIMEDOUT; case 0x11: case 0x27: case 0x29: case 0x20: return EOPNOTSUPP; case 0x12: return EINVAL; case 0x13: case 0x14: case 0x15: return ECONNRESET; case 0x16: return ECONNABORTED; case 0x17: return ELOOP; case 0x18: return EACCES; case 0x1a: return EPROTONOSUPPORT; case 0x1b: return ECONNREFUSED; case 0x19: case 0x1e: case 0x23: case 0x24: case 0x25: return EPROTO; default: return ENOSYS; }; } --- NEW FILE --- /* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <ma...@qu...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. */ /* * BlueZ symbols. * * $Id: syms.c,v 1.1 2002/04/09 16:22:03 atp Exp $ */ #include <linux/config.h> #include <linux/module.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/skbuff.h> #include <linux/socket.h> #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluez.h> #include <net/bluetooth/hci_core.h> /* HCI Core */ EXPORT_SYMBOL(hci_register_dev); EXPORT_SYMBOL(hci_unregister_dev); EXPORT_SYMBOL(hci_register_proto); EXPORT_SYMBOL(hci_unregister_proto); EXPORT_SYMBOL(hci_register_notifier); EXPORT_SYMBOL(hci_unregister_notifier); EXPORT_SYMBOL(hci_connect); EXPORT_SYMBOL(hci_disconnect); EXPORT_SYMBOL(hci_dev_get); EXPORT_SYMBOL(hci_recv_frame); EXPORT_SYMBOL(hci_send_acl); EXPORT_SYMBOL(hci_send_sco); EXPORT_SYMBOL(hci_send_raw); /* BlueZ lib */ EXPORT_SYMBOL(bluez_dump); EXPORT_SYMBOL(baswap); EXPORT_SYMBOL(batostr); EXPORT_SYMBOL(bterr); /* BlueZ sockets */ EXPORT_SYMBOL(bluez_sock_register); EXPORT_SYMBOL(bluez_sock_unregister); EXPORT_SYMBOL(bluez_sock_link); EXPORT_SYMBOL(bluez_sock_unlink); |