bnep_sock.c
来自「蓝牙的各种编程接口和各种按理介绍,还有一些例子和说明」· C语言 代码 · 共 140 行
C
140 行
/* BlueNIC - Bluetooth PAN profile implementation for BlueZ Copyright (C) 2002 Sony Corporation Author: Johannes Loebbert <loebbert@sony.de> 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* * $Id: bnep_sock.c,v 1.4 2002/08/04 21:23:58 maxk 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/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 "bnep_common.h"#ifndef BNEP_DEBUG#undef BT_DBG#define BT_DBG( A... )#endifstatic int bnep_sock_release(struct socket *sock){ struct sock *sk = sock->sk; BT_DBG("sock %p sk %p", sock, sk); if (!sk) return 0; sock_orphan(sk); sock_put(sk); return 0;}static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg){ struct bnep_dev_ioctl_struct bnep_dev_ioctl; BT_DBG("cmd %x arg %lx", cmd, arg); switch (cmd) { case 0: if (copy_from_user(&bnep_dev_ioctl, (void *) arg, sizeof(bnep_dev_ioctl))) return -EFAULT; return bnep_dev_control(&bnep_dev_ioctl); }; return 0;}static struct proto_ops bnep_sock_ops = { family: PF_BLUETOOTH, release: bnep_sock_release, ioctl: bnep_sock_ioctl, bind: sock_no_bind, getname: sock_no_getname, sendmsg: sock_no_sendmsg, recvmsg: sock_no_recvmsg, poll: sock_no_poll, listen: sock_no_listen, shutdown: sock_no_shutdown, setsockopt: sock_no_setsockopt, getsockopt: sock_no_getsockopt, connect: sock_no_connect, socketpair: sock_no_socketpair, accept: sock_no_accept, mmap: sock_no_mmap};static int bnep_sock_create(struct socket *sock, int protocol){ struct sock *sk; BT_DBG("sock %p", sock); if (sock->type != SOCK_RAW) return -ESOCKTNOSUPPORT; sock->ops = &bnep_sock_ops; if (!(sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, 1))) return -ENOMEM; sock->state = SS_UNCONNECTED; sock_init_data(sock, sk); sk->destruct = NULL; sk->protocol = protocol; return 0;}static struct net_proto_family bnep_sock_family_ops = { family: PF_BLUETOOTH, create: bnep_sock_create};int bnep_sock_init(void){ bluez_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops); return 0;}int bnep_sock_cleanup(void){ if (bluez_sock_unregister(BTPROTO_BNEP)) BT_ERR("Can't unregister BNEP socket"); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?