OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [bluetooth/] [bnep/] [sock.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
   BNEP implementation for Linux Bluetooth stack (BlueZ).
3
   Copyright (C) 2001-2002 Inventel Systemes
4
   Written 2001-2002 by
5
        David Libault  <david.libault@inventel.fr>
6
 
7
   Copyright (C) 2002 Maxim Krasnyanskiy <maxk@qualcomm.com>
8
 
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License version 2 as
11
   published by the Free Software Foundation;
12
 
13
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
16
   IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
17
   CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
18
   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19
   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
 
22
   ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23
   COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
24
   SOFTWARE IS DISCLAIMED.
25
*/
26
 
27
/*
28
 * $Id: sock.c,v 1.1.1.1 2004-04-15 01:17:08 phoenix Exp $
29
 */
30
 
31
#include <linux/config.h>
32
#include <linux/module.h>
33
 
34
#include <linux/types.h>
35
#include <linux/errno.h>
36
#include <linux/kernel.h>
37
#include <linux/major.h>
38
#include <linux/sched.h>
39
#include <linux/slab.h>
40
#include <linux/poll.h>
41
#include <linux/fcntl.h>
42
#include <linux/skbuff.h>
43
#include <linux/socket.h>
44
#include <linux/ioctl.h>
45
#include <linux/file.h>
46
#include <net/sock.h>
47
 
48
#include <asm/system.h>
49
#include <asm/uaccess.h>
50
 
51
#include "bnep.h"
52
 
53
#ifndef CONFIG_BLUEZ_BNEP_DEBUG
54
#undef  BT_DBG
55
#define BT_DBG( A... )
56
#endif
57
 
58
static int bnep_sock_release(struct socket *sock)
59
{
60
        struct sock *sk = sock->sk;
61
 
62
        BT_DBG("sock %p sk %p", sock, sk);
63
 
64
        if (!sk)
65
                return 0;
66
 
67
        sock_orphan(sk);
68
        sock_put(sk);
69
 
70
        MOD_DEC_USE_COUNT;
71
        return 0;
72
}
73
 
74
static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
75
{
76
        struct bnep_connlist_req cl;
77
        struct bnep_connadd_req  ca;
78
        struct bnep_conndel_req  cd;
79
        struct bnep_conninfo ci;
80
        struct socket *nsock;
81
        int err;
82
 
83
        BT_DBG("cmd %x arg %lx", cmd, arg);
84
 
85
        switch (cmd) {
86
        case BNEPCONNADD:
87
                if (!capable(CAP_NET_ADMIN))
88
                        return -EACCES;
89
 
90
                if (copy_from_user(&ca, (void *) arg, sizeof(ca)))
91
                        return -EFAULT;
92
 
93
                nsock = sockfd_lookup(ca.sock, &err);
94
                if (!nsock)
95
                        return err;
96
 
97
                if (nsock->sk->state != BT_CONNECTED) {
98
                        fput(nsock->file);
99
                        return -EBADFD;
100
                }
101
 
102
                err = bnep_add_connection(&ca, nsock);
103
                if (!err) {
104
                        if (copy_to_user((void *) arg, &ca, sizeof(ca)))
105
                                err = -EFAULT;
106
                } else
107
                        fput(nsock->file);
108
 
109
                return err;
110
 
111
        case BNEPCONNDEL:
112
                if (!capable(CAP_NET_ADMIN))
113
                        return -EACCES;
114
 
115
                if (copy_from_user(&cd, (void *) arg, sizeof(cd)))
116
                        return -EFAULT;
117
 
118
                return bnep_del_connection(&cd);
119
 
120
        case BNEPGETCONNLIST:
121
                if (copy_from_user(&cl, (void *) arg, sizeof(cl)))
122
                        return -EFAULT;
123
 
124
                if (cl.cnum <= 0)
125
                        return -EINVAL;
126
 
127
                err = bnep_get_connlist(&cl);
128
                if (!err && copy_to_user((void *) arg, &cl, sizeof(cl)))
129
                        return -EFAULT;
130
 
131
                return err;
132
 
133
        case BNEPGETCONNINFO:
134
                if (copy_from_user(&ci, (void *) arg, sizeof(ci)))
135
                        return -EFAULT;
136
 
137
                err = bnep_get_conninfo(&ci);
138
                if (!err && copy_to_user((void *) arg, &ci, sizeof(ci)))
139
                        return -EFAULT;
140
 
141
                return err;
142
 
143
        default:
144
                return -EINVAL;
145
        }
146
 
147
        return 0;
148
}
149
 
150
static struct proto_ops bnep_sock_ops = {
151
        family:     PF_BLUETOOTH,
152
        release:    bnep_sock_release,
153
        ioctl:      bnep_sock_ioctl,
154
        bind:       sock_no_bind,
155
        getname:    sock_no_getname,
156
        sendmsg:    sock_no_sendmsg,
157
        recvmsg:    sock_no_recvmsg,
158
        poll:       sock_no_poll,
159
        listen:     sock_no_listen,
160
        shutdown:   sock_no_shutdown,
161
        setsockopt: sock_no_setsockopt,
162
        getsockopt: sock_no_getsockopt,
163
        connect:    sock_no_connect,
164
        socketpair: sock_no_socketpair,
165
        accept:     sock_no_accept,
166
        mmap:       sock_no_mmap
167
};
168
 
169
static int bnep_sock_create(struct socket *sock, int protocol)
170
{
171
        struct sock *sk;
172
 
173
        BT_DBG("sock %p", sock);
174
 
175
        if (sock->type != SOCK_RAW)
176
                return -ESOCKTNOSUPPORT;
177
 
178
        sock->ops = &bnep_sock_ops;
179
 
180
        if (!(sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, 1)))
181
                return -ENOMEM;
182
 
183
        MOD_INC_USE_COUNT;
184
 
185
        sock->state = SS_UNCONNECTED;
186
        sock_init_data(sock, sk);
187
 
188
        sk->destruct = NULL;
189
        sk->protocol = protocol;
190
 
191
        return 0;
192
}
193
 
194
static struct net_proto_family bnep_sock_family_ops = {
195
        family: PF_BLUETOOTH,
196
        create: bnep_sock_create
197
};
198
 
199
int bnep_sock_init(void)
200
{
201
        bluez_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops);
202
        return 0;
203
}
204
 
205
int bnep_sock_cleanup(void)
206
{
207
        if (bluez_sock_unregister(BTPROTO_BNEP))
208
                BT_ERR("Can't unregister BNEP socket");
209
        return 0;
210
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.