Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / isdn / mISDN / socket.c
blob8e325227b4c01153715f396662aeebea5231a219
1 /*
3 * Author Karsten Keil <kkeil@novell.com>
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #include <linux/mISDNif.h>
19 #include <linux/slab.h>
20 #include "core.h"
22 static u_int *debug;
24 static struct proto mISDN_proto = {
25 .name = "misdn",
26 .owner = THIS_MODULE,
27 .obj_size = sizeof(struct mISDN_sock)
30 #define _pms(sk) ((struct mISDN_sock *)sk)
32 static struct mISDN_sock_list data_sockets = {
33 .lock = __RW_LOCK_UNLOCKED(data_sockets.lock)
36 static struct mISDN_sock_list base_sockets = {
37 .lock = __RW_LOCK_UNLOCKED(base_sockets.lock)
40 #define L2_HEADER_LEN 4
42 static inline struct sk_buff *
43 _l2_alloc_skb(unsigned int len, gfp_t gfp_mask)
45 struct sk_buff *skb;
47 skb = alloc_skb(len + L2_HEADER_LEN, gfp_mask);
48 if (likely(skb))
49 skb_reserve(skb, L2_HEADER_LEN);
50 return skb;
53 static void
54 mISDN_sock_link(struct mISDN_sock_list *l, struct sock *sk)
56 write_lock_bh(&l->lock);
57 sk_add_node(sk, &l->head);
58 write_unlock_bh(&l->lock);
61 static void mISDN_sock_unlink(struct mISDN_sock_list *l, struct sock *sk)
63 write_lock_bh(&l->lock);
64 sk_del_node_init(sk);
65 write_unlock_bh(&l->lock);
68 static int
69 mISDN_send(struct mISDNchannel *ch, struct sk_buff *skb)
71 struct mISDN_sock *msk;
72 int err;
74 msk = container_of(ch, struct mISDN_sock, ch);
75 if (*debug & DEBUG_SOCKET)
76 printk(KERN_DEBUG "%s len %d %p\n", __func__, skb->len, skb);
77 if (msk->sk.sk_state == MISDN_CLOSED)
78 return -EUNATCH;
79 __net_timestamp(skb);
80 err = sock_queue_rcv_skb(&msk->sk, skb);
81 if (err)
82 printk(KERN_WARNING "%s: error %d\n", __func__, err);
83 return err;
86 static int
87 mISDN_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
89 struct mISDN_sock *msk;
91 msk = container_of(ch, struct mISDN_sock, ch);
92 if (*debug & DEBUG_SOCKET)
93 printk(KERN_DEBUG "%s(%p, %x, %p)\n", __func__, ch, cmd, arg);
94 switch (cmd) {
95 case CLOSE_CHANNEL:
96 msk->sk.sk_state = MISDN_CLOSED;
97 break;
99 return 0;
102 static inline void
103 mISDN_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb)
105 struct timeval tv;
107 if (_pms(sk)->cmask & MISDN_TIME_STAMP) {
108 skb_get_timestamp(skb, &tv);
109 put_cmsg(msg, SOL_MISDN, MISDN_TIME_STAMP, sizeof(tv), &tv);
113 static int
114 mISDN_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
115 struct msghdr *msg, size_t len, int flags)
117 struct sk_buff *skb;
118 struct sock *sk = sock->sk;
119 struct sockaddr_mISDN *maddr;
121 int copied, err;
123 if (*debug & DEBUG_SOCKET)
124 printk(KERN_DEBUG "%s: len %d, flags %x ch.nr %d, proto %x\n",
125 __func__, (int)len, flags, _pms(sk)->ch.nr,
126 sk->sk_protocol);
127 if (flags & (MSG_OOB))
128 return -EOPNOTSUPP;
130 if (sk->sk_state == MISDN_CLOSED)
131 return 0;
133 skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &err);
134 if (!skb)
135 return err;
137 if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) {
138 msg->msg_namelen = sizeof(struct sockaddr_mISDN);
139 maddr = (struct sockaddr_mISDN *)msg->msg_name;
140 maddr->family = AF_ISDN;
141 maddr->dev = _pms(sk)->dev->id;
142 if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
143 (sk->sk_protocol == ISDN_P_LAPD_NT)) {
144 maddr->channel = (mISDN_HEAD_ID(skb) >> 16) & 0xff;
145 maddr->tei = (mISDN_HEAD_ID(skb) >> 8) & 0xff;
146 maddr->sapi = mISDN_HEAD_ID(skb) & 0xff;
147 } else {
148 maddr->channel = _pms(sk)->ch.nr;
149 maddr->sapi = _pms(sk)->ch.addr & 0xFF;
150 maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xFF;
152 } else {
153 if (msg->msg_namelen)
154 printk(KERN_WARNING "%s: too small namelen %d\n",
155 __func__, msg->msg_namelen);
156 msg->msg_namelen = 0;
159 copied = skb->len + MISDN_HEADER_LEN;
160 if (len < copied) {
161 if (flags & MSG_PEEK)
162 atomic_dec(&skb->users);
163 else
164 skb_queue_head(&sk->sk_receive_queue, skb);
165 return -ENOSPC;
167 memcpy(skb_push(skb, MISDN_HEADER_LEN), mISDN_HEAD_P(skb),
168 MISDN_HEADER_LEN);
170 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
172 mISDN_sock_cmsg(sk, msg, skb);
174 skb_free_datagram(sk, skb);
176 return err ? : copied;
179 static int
180 mISDN_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
181 struct msghdr *msg, size_t len)
183 struct sock *sk = sock->sk;
184 struct sk_buff *skb;
185 int err = -ENOMEM;
186 struct sockaddr_mISDN *maddr;
188 if (*debug & DEBUG_SOCKET)
189 printk(KERN_DEBUG "%s: len %d flags %x ch %d proto %x\n",
190 __func__, (int)len, msg->msg_flags, _pms(sk)->ch.nr,
191 sk->sk_protocol);
193 if (msg->msg_flags & MSG_OOB)
194 return -EOPNOTSUPP;
196 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE))
197 return -EINVAL;
199 if (len < MISDN_HEADER_LEN)
200 return -EINVAL;
202 if (sk->sk_state != MISDN_BOUND)
203 return -EBADFD;
205 lock_sock(sk);
207 skb = _l2_alloc_skb(len, GFP_KERNEL);
208 if (!skb)
209 goto done;
211 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
212 err = -EFAULT;
213 goto done;
216 memcpy(mISDN_HEAD_P(skb), skb->data, MISDN_HEADER_LEN);
217 skb_pull(skb, MISDN_HEADER_LEN);
219 if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) {
220 /* if we have a address, we use it */
221 maddr = (struct sockaddr_mISDN *)msg->msg_name;
222 mISDN_HEAD_ID(skb) = maddr->channel;
223 } else { /* use default for L2 messages */
224 if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
225 (sk->sk_protocol == ISDN_P_LAPD_NT))
226 mISDN_HEAD_ID(skb) = _pms(sk)->ch.nr;
229 if (*debug & DEBUG_SOCKET)
230 printk(KERN_DEBUG "%s: ID:%x\n",
231 __func__, mISDN_HEAD_ID(skb));
233 err = -ENODEV;
234 if (!_pms(sk)->ch.peer)
235 goto done;
236 err = _pms(sk)->ch.recv(_pms(sk)->ch.peer, skb);
237 if (err)
238 goto done;
239 else {
240 skb = NULL;
241 err = len;
244 done:
245 if (skb)
246 kfree_skb(skb);
247 release_sock(sk);
248 return err;
251 static int
252 data_sock_release(struct socket *sock)
254 struct sock *sk = sock->sk;
256 if (*debug & DEBUG_SOCKET)
257 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
258 if (!sk)
259 return 0;
260 switch (sk->sk_protocol) {
261 case ISDN_P_TE_S0:
262 case ISDN_P_NT_S0:
263 case ISDN_P_TE_E1:
264 case ISDN_P_NT_E1:
265 if (sk->sk_state == MISDN_BOUND)
266 delete_channel(&_pms(sk)->ch);
267 else
268 mISDN_sock_unlink(&data_sockets, sk);
269 break;
270 case ISDN_P_LAPD_TE:
271 case ISDN_P_LAPD_NT:
272 case ISDN_P_B_RAW:
273 case ISDN_P_B_HDLC:
274 case ISDN_P_B_X75SLP:
275 case ISDN_P_B_L2DTMF:
276 case ISDN_P_B_L2DSP:
277 case ISDN_P_B_L2DSPHDLC:
278 delete_channel(&_pms(sk)->ch);
279 mISDN_sock_unlink(&data_sockets, sk);
280 break;
283 lock_sock(sk);
285 sock_orphan(sk);
286 skb_queue_purge(&sk->sk_receive_queue);
288 release_sock(sk);
289 sock_put(sk);
291 return 0;
294 static int
295 data_sock_ioctl_bound(struct sock *sk, unsigned int cmd, void __user *p)
297 struct mISDN_ctrl_req cq;
298 int err = -EINVAL, val[2];
299 struct mISDNchannel *bchan, *next;
301 lock_sock(sk);
302 if (!_pms(sk)->dev) {
303 err = -ENODEV;
304 goto done;
306 switch (cmd) {
307 case IMCTRLREQ:
308 if (copy_from_user(&cq, p, sizeof(cq))) {
309 err = -EFAULT;
310 break;
312 if ((sk->sk_protocol & ~ISDN_P_B_MASK) == ISDN_P_B_START) {
313 list_for_each_entry_safe(bchan, next,
314 &_pms(sk)->dev->bchannels, list) {
315 if (bchan->nr == cq.channel) {
316 err = bchan->ctrl(bchan,
317 CONTROL_CHANNEL, &cq);
318 break;
321 } else
322 err = _pms(sk)->dev->D.ctrl(&_pms(sk)->dev->D,
323 CONTROL_CHANNEL, &cq);
324 if (err)
325 break;
326 if (copy_to_user(p, &cq, sizeof(cq)))
327 err = -EFAULT;
328 break;
329 case IMCLEAR_L2:
330 if (sk->sk_protocol != ISDN_P_LAPD_NT) {
331 err = -EINVAL;
332 break;
334 val[0] = cmd;
335 if (get_user(val[1], (int __user *)p)) {
336 err = -EFAULT;
337 break;
339 err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
340 CONTROL_CHANNEL, val);
341 break;
342 case IMHOLD_L1:
343 if (sk->sk_protocol != ISDN_P_LAPD_NT
344 && sk->sk_protocol != ISDN_P_LAPD_TE) {
345 err = -EINVAL;
346 break;
348 val[0] = cmd;
349 if (get_user(val[1], (int __user *)p)) {
350 err = -EFAULT;
351 break;
353 err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
354 CONTROL_CHANNEL, val);
355 break;
356 default:
357 err = -EINVAL;
358 break;
360 done:
361 release_sock(sk);
362 return err;
365 static int
366 data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
368 int err = 0, id;
369 struct sock *sk = sock->sk;
370 struct mISDNdevice *dev;
371 struct mISDNversion ver;
373 switch (cmd) {
374 case IMGETVERSION:
375 ver.major = MISDN_MAJOR_VERSION;
376 ver.minor = MISDN_MINOR_VERSION;
377 ver.release = MISDN_RELEASE;
378 if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
379 err = -EFAULT;
380 break;
381 case IMGETCOUNT:
382 id = get_mdevice_count();
383 if (put_user(id, (int __user *)arg))
384 err = -EFAULT;
385 break;
386 case IMGETDEVINFO:
387 if (get_user(id, (int __user *)arg)) {
388 err = -EFAULT;
389 break;
391 dev = get_mdevice(id);
392 if (dev) {
393 struct mISDN_devinfo di;
395 memset(&di, 0, sizeof(di));
396 di.id = dev->id;
397 di.Dprotocols = dev->Dprotocols;
398 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
399 di.protocol = dev->D.protocol;
400 memcpy(di.channelmap, dev->channelmap,
401 sizeof(di.channelmap));
402 di.nrbchan = dev->nrbchan;
403 strcpy(di.name, dev_name(&dev->dev));
404 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
405 err = -EFAULT;
406 } else
407 err = -ENODEV;
408 break;
409 default:
410 if (sk->sk_state == MISDN_BOUND)
411 err = data_sock_ioctl_bound(sk, cmd,
412 (void __user *)arg);
413 else
414 err = -ENOTCONN;
416 return err;
419 static int data_sock_setsockopt(struct socket *sock, int level, int optname,
420 char __user *optval, unsigned int len)
422 struct sock *sk = sock->sk;
423 int err = 0, opt = 0;
425 if (*debug & DEBUG_SOCKET)
426 printk(KERN_DEBUG "%s(%p, %d, %x, %p, %d)\n", __func__, sock,
427 level, optname, optval, len);
429 lock_sock(sk);
431 switch (optname) {
432 case MISDN_TIME_STAMP:
433 if (get_user(opt, (int __user *)optval)) {
434 err = -EFAULT;
435 break;
438 if (opt)
439 _pms(sk)->cmask |= MISDN_TIME_STAMP;
440 else
441 _pms(sk)->cmask &= ~MISDN_TIME_STAMP;
442 break;
443 default:
444 err = -ENOPROTOOPT;
445 break;
447 release_sock(sk);
448 return err;
451 static int data_sock_getsockopt(struct socket *sock, int level, int optname,
452 char __user *optval, int __user *optlen)
454 struct sock *sk = sock->sk;
455 int len, opt;
457 if (get_user(len, optlen))
458 return -EFAULT;
460 if (len != sizeof(char))
461 return -EINVAL;
463 switch (optname) {
464 case MISDN_TIME_STAMP:
465 if (_pms(sk)->cmask & MISDN_TIME_STAMP)
466 opt = 1;
467 else
468 opt = 0;
470 if (put_user(opt, optval))
471 return -EFAULT;
472 break;
473 default:
474 return -ENOPROTOOPT;
477 return 0;
480 static int
481 data_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
483 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
484 struct sock *sk = sock->sk;
485 struct hlist_node *node;
486 struct sock *csk;
487 int err = 0;
489 if (*debug & DEBUG_SOCKET)
490 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
491 if (addr_len != sizeof(struct sockaddr_mISDN))
492 return -EINVAL;
493 if (!maddr || maddr->family != AF_ISDN)
494 return -EINVAL;
496 lock_sock(sk);
498 if (_pms(sk)->dev) {
499 err = -EALREADY;
500 goto done;
502 _pms(sk)->dev = get_mdevice(maddr->dev);
503 if (!_pms(sk)->dev) {
504 err = -ENODEV;
505 goto done;
508 if (sk->sk_protocol < ISDN_P_B_START) {
509 read_lock_bh(&data_sockets.lock);
510 sk_for_each(csk, node, &data_sockets.head) {
511 if (sk == csk)
512 continue;
513 if (_pms(csk)->dev != _pms(sk)->dev)
514 continue;
515 if (csk->sk_protocol >= ISDN_P_B_START)
516 continue;
517 if (IS_ISDN_P_TE(csk->sk_protocol)
518 == IS_ISDN_P_TE(sk->sk_protocol))
519 continue;
520 read_unlock_bh(&data_sockets.lock);
521 err = -EBUSY;
522 goto done;
524 read_unlock_bh(&data_sockets.lock);
527 _pms(sk)->ch.send = mISDN_send;
528 _pms(sk)->ch.ctrl = mISDN_ctrl;
530 switch (sk->sk_protocol) {
531 case ISDN_P_TE_S0:
532 case ISDN_P_NT_S0:
533 case ISDN_P_TE_E1:
534 case ISDN_P_NT_E1:
535 mISDN_sock_unlink(&data_sockets, sk);
536 err = connect_layer1(_pms(sk)->dev, &_pms(sk)->ch,
537 sk->sk_protocol, maddr);
538 if (err)
539 mISDN_sock_link(&data_sockets, sk);
540 break;
541 case ISDN_P_LAPD_TE:
542 case ISDN_P_LAPD_NT:
543 err = create_l2entity(_pms(sk)->dev, &_pms(sk)->ch,
544 sk->sk_protocol, maddr);
545 break;
546 case ISDN_P_B_RAW:
547 case ISDN_P_B_HDLC:
548 case ISDN_P_B_X75SLP:
549 case ISDN_P_B_L2DTMF:
550 case ISDN_P_B_L2DSP:
551 case ISDN_P_B_L2DSPHDLC:
552 err = connect_Bstack(_pms(sk)->dev, &_pms(sk)->ch,
553 sk->sk_protocol, maddr);
554 break;
555 default:
556 err = -EPROTONOSUPPORT;
558 if (err)
559 goto done;
560 sk->sk_state = MISDN_BOUND;
561 _pms(sk)->ch.protocol = sk->sk_protocol;
563 done:
564 release_sock(sk);
565 return err;
568 static int
569 data_sock_getname(struct socket *sock, struct sockaddr *addr,
570 int *addr_len, int peer)
572 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
573 struct sock *sk = sock->sk;
575 if (!_pms(sk)->dev)
576 return -EBADFD;
578 lock_sock(sk);
580 *addr_len = sizeof(*maddr);
581 maddr->dev = _pms(sk)->dev->id;
582 maddr->channel = _pms(sk)->ch.nr;
583 maddr->sapi = _pms(sk)->ch.addr & 0xff;
584 maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xff;
585 release_sock(sk);
586 return 0;
589 static const struct proto_ops data_sock_ops = {
590 .family = PF_ISDN,
591 .owner = THIS_MODULE,
592 .release = data_sock_release,
593 .ioctl = data_sock_ioctl,
594 .bind = data_sock_bind,
595 .getname = data_sock_getname,
596 .sendmsg = mISDN_sock_sendmsg,
597 .recvmsg = mISDN_sock_recvmsg,
598 .poll = datagram_poll,
599 .listen = sock_no_listen,
600 .shutdown = sock_no_shutdown,
601 .setsockopt = data_sock_setsockopt,
602 .getsockopt = data_sock_getsockopt,
603 .connect = sock_no_connect,
604 .socketpair = sock_no_socketpair,
605 .accept = sock_no_accept,
606 .mmap = sock_no_mmap
609 static int
610 data_sock_create(struct net *net, struct socket *sock, int protocol)
612 struct sock *sk;
614 if (sock->type != SOCK_DGRAM)
615 return -ESOCKTNOSUPPORT;
617 sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto);
618 if (!sk)
619 return -ENOMEM;
621 sock_init_data(sock, sk);
623 sock->ops = &data_sock_ops;
624 sock->state = SS_UNCONNECTED;
625 sock_reset_flag(sk, SOCK_ZAPPED);
627 sk->sk_protocol = protocol;
628 sk->sk_state = MISDN_OPEN;
629 mISDN_sock_link(&data_sockets, sk);
631 return 0;
634 static int
635 base_sock_release(struct socket *sock)
637 struct sock *sk = sock->sk;
639 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
640 if (!sk)
641 return 0;
643 mISDN_sock_unlink(&base_sockets, sk);
644 sock_orphan(sk);
645 sock_put(sk);
647 return 0;
650 static int
651 base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
653 int err = 0, id;
654 struct mISDNdevice *dev;
655 struct mISDNversion ver;
657 switch (cmd) {
658 case IMGETVERSION:
659 ver.major = MISDN_MAJOR_VERSION;
660 ver.minor = MISDN_MINOR_VERSION;
661 ver.release = MISDN_RELEASE;
662 if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
663 err = -EFAULT;
664 break;
665 case IMGETCOUNT:
666 id = get_mdevice_count();
667 if (put_user(id, (int __user *)arg))
668 err = -EFAULT;
669 break;
670 case IMGETDEVINFO:
671 if (get_user(id, (int __user *)arg)) {
672 err = -EFAULT;
673 break;
675 dev = get_mdevice(id);
676 if (dev) {
677 struct mISDN_devinfo di;
679 memset(&di, 0, sizeof(di));
680 di.id = dev->id;
681 di.Dprotocols = dev->Dprotocols;
682 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
683 di.protocol = dev->D.protocol;
684 memcpy(di.channelmap, dev->channelmap,
685 sizeof(di.channelmap));
686 di.nrbchan = dev->nrbchan;
687 strcpy(di.name, dev_name(&dev->dev));
688 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
689 err = -EFAULT;
690 } else
691 err = -ENODEV;
692 break;
693 case IMSETDEVNAME:
695 struct mISDN_devrename dn;
696 if (copy_from_user(&dn, (void __user *)arg,
697 sizeof(dn))) {
698 err = -EFAULT;
699 break;
701 dev = get_mdevice(dn.id);
702 if (dev)
703 err = device_rename(&dev->dev, dn.name);
704 else
705 err = -ENODEV;
707 break;
708 default:
709 err = -EINVAL;
711 return err;
714 static int
715 base_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
717 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
718 struct sock *sk = sock->sk;
719 int err = 0;
721 if (!maddr || maddr->family != AF_ISDN)
722 return -EINVAL;
724 lock_sock(sk);
726 if (_pms(sk)->dev) {
727 err = -EALREADY;
728 goto done;
731 _pms(sk)->dev = get_mdevice(maddr->dev);
732 if (!_pms(sk)->dev) {
733 err = -ENODEV;
734 goto done;
736 sk->sk_state = MISDN_BOUND;
738 done:
739 release_sock(sk);
740 return err;
743 static const struct proto_ops base_sock_ops = {
744 .family = PF_ISDN,
745 .owner = THIS_MODULE,
746 .release = base_sock_release,
747 .ioctl = base_sock_ioctl,
748 .bind = base_sock_bind,
749 .getname = sock_no_getname,
750 .sendmsg = sock_no_sendmsg,
751 .recvmsg = sock_no_recvmsg,
752 .poll = sock_no_poll,
753 .listen = sock_no_listen,
754 .shutdown = sock_no_shutdown,
755 .setsockopt = sock_no_setsockopt,
756 .getsockopt = sock_no_getsockopt,
757 .connect = sock_no_connect,
758 .socketpair = sock_no_socketpair,
759 .accept = sock_no_accept,
760 .mmap = sock_no_mmap
764 static int
765 base_sock_create(struct net *net, struct socket *sock, int protocol)
767 struct sock *sk;
769 if (sock->type != SOCK_RAW)
770 return -ESOCKTNOSUPPORT;
772 sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto);
773 if (!sk)
774 return -ENOMEM;
776 sock_init_data(sock, sk);
777 sock->ops = &base_sock_ops;
778 sock->state = SS_UNCONNECTED;
779 sock_reset_flag(sk, SOCK_ZAPPED);
780 sk->sk_protocol = protocol;
781 sk->sk_state = MISDN_OPEN;
782 mISDN_sock_link(&base_sockets, sk);
784 return 0;
787 static int
788 mISDN_sock_create(struct net *net, struct socket *sock, int proto, int kern)
790 int err = -EPROTONOSUPPORT;
792 switch (proto) {
793 case ISDN_P_BASE:
794 err = base_sock_create(net, sock, proto);
795 break;
796 case ISDN_P_TE_S0:
797 case ISDN_P_NT_S0:
798 case ISDN_P_TE_E1:
799 case ISDN_P_NT_E1:
800 case ISDN_P_LAPD_TE:
801 case ISDN_P_LAPD_NT:
802 case ISDN_P_B_RAW:
803 case ISDN_P_B_HDLC:
804 case ISDN_P_B_X75SLP:
805 case ISDN_P_B_L2DTMF:
806 case ISDN_P_B_L2DSP:
807 case ISDN_P_B_L2DSPHDLC:
808 err = data_sock_create(net, sock, proto);
809 break;
810 default:
811 return err;
814 return err;
817 static const struct net_proto_family mISDN_sock_family_ops = {
818 .owner = THIS_MODULE,
819 .family = PF_ISDN,
820 .create = mISDN_sock_create,
824 misdn_sock_init(u_int *deb)
826 int err;
828 debug = deb;
829 err = sock_register(&mISDN_sock_family_ops);
830 if (err)
831 printk(KERN_ERR "%s: error(%d)\n", __func__, err);
832 return err;
835 void
836 misdn_sock_cleanup(void)
838 sock_unregister(PF_ISDN);