sctp: translate host order to network order when setting a hmacid
[linux/fpc-iii.git] / drivers / isdn / mISDN / socket.c
blob5cefb479c7072359c5c7289d68063925da39797c
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 <linux/export.h>
21 #include "core.h"
23 static u_int *debug;
25 static struct proto mISDN_proto = {
26 .name = "misdn",
27 .owner = THIS_MODULE,
28 .obj_size = sizeof(struct mISDN_sock)
31 #define _pms(sk) ((struct mISDN_sock *)sk)
33 static struct mISDN_sock_list data_sockets = {
34 .lock = __RW_LOCK_UNLOCKED(data_sockets.lock)
37 static struct mISDN_sock_list base_sockets = {
38 .lock = __RW_LOCK_UNLOCKED(base_sockets.lock)
41 #define L2_HEADER_LEN 4
43 static inline struct sk_buff *
44 _l2_alloc_skb(unsigned int len, gfp_t gfp_mask)
46 struct sk_buff *skb;
48 skb = alloc_skb(len + L2_HEADER_LEN, gfp_mask);
49 if (likely(skb))
50 skb_reserve(skb, L2_HEADER_LEN);
51 return skb;
54 static void
55 mISDN_sock_link(struct mISDN_sock_list *l, struct sock *sk)
57 write_lock_bh(&l->lock);
58 sk_add_node(sk, &l->head);
59 write_unlock_bh(&l->lock);
62 static void mISDN_sock_unlink(struct mISDN_sock_list *l, struct sock *sk)
64 write_lock_bh(&l->lock);
65 sk_del_node_init(sk);
66 write_unlock_bh(&l->lock);
69 static int
70 mISDN_send(struct mISDNchannel *ch, struct sk_buff *skb)
72 struct mISDN_sock *msk;
73 int err;
75 msk = container_of(ch, struct mISDN_sock, ch);
76 if (*debug & DEBUG_SOCKET)
77 printk(KERN_DEBUG "%s len %d %p\n", __func__, skb->len, skb);
78 if (msk->sk.sk_state == MISDN_CLOSED)
79 return -EUNATCH;
80 __net_timestamp(skb);
81 err = sock_queue_rcv_skb(&msk->sk, skb);
82 if (err)
83 printk(KERN_WARNING "%s: error %d\n", __func__, err);
84 return err;
87 static int
88 mISDN_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
90 struct mISDN_sock *msk;
92 msk = container_of(ch, struct mISDN_sock, ch);
93 if (*debug & DEBUG_SOCKET)
94 printk(KERN_DEBUG "%s(%p, %x, %p)\n", __func__, ch, cmd, arg);
95 switch (cmd) {
96 case CLOSE_CHANNEL:
97 msk->sk.sk_state = MISDN_CLOSED;
98 break;
100 return 0;
103 static inline void
104 mISDN_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb)
106 struct timeval tv;
108 if (_pms(sk)->cmask & MISDN_TIME_STAMP) {
109 skb_get_timestamp(skb, &tv);
110 put_cmsg(msg, SOL_MISDN, MISDN_TIME_STAMP, sizeof(tv), &tv);
114 static int
115 mISDN_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
116 struct msghdr *msg, size_t len, int flags)
118 struct sk_buff *skb;
119 struct sock *sk = sock->sk;
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_name) {
138 struct sockaddr_mISDN *maddr = 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 msg->msg_namelen = sizeof(*maddr);
155 copied = skb->len + MISDN_HEADER_LEN;
156 if (len < copied) {
157 if (flags & MSG_PEEK)
158 atomic_dec(&skb->users);
159 else
160 skb_queue_head(&sk->sk_receive_queue, skb);
161 return -ENOSPC;
163 memcpy(skb_push(skb, MISDN_HEADER_LEN), mISDN_HEAD_P(skb),
164 MISDN_HEADER_LEN);
166 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
168 mISDN_sock_cmsg(sk, msg, skb);
170 skb_free_datagram(sk, skb);
172 return err ? : copied;
175 static int
176 mISDN_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
177 struct msghdr *msg, size_t len)
179 struct sock *sk = sock->sk;
180 struct sk_buff *skb;
181 int err = -ENOMEM;
182 struct sockaddr_mISDN *maddr;
184 if (*debug & DEBUG_SOCKET)
185 printk(KERN_DEBUG "%s: len %d flags %x ch %d proto %x\n",
186 __func__, (int)len, msg->msg_flags, _pms(sk)->ch.nr,
187 sk->sk_protocol);
189 if (msg->msg_flags & MSG_OOB)
190 return -EOPNOTSUPP;
192 if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_NOSIGNAL | MSG_ERRQUEUE))
193 return -EINVAL;
195 if (len < MISDN_HEADER_LEN)
196 return -EINVAL;
198 if (sk->sk_state != MISDN_BOUND)
199 return -EBADFD;
201 lock_sock(sk);
203 skb = _l2_alloc_skb(len, GFP_KERNEL);
204 if (!skb)
205 goto done;
207 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
208 err = -EFAULT;
209 goto done;
212 memcpy(mISDN_HEAD_P(skb), skb->data, MISDN_HEADER_LEN);
213 skb_pull(skb, MISDN_HEADER_LEN);
215 if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) {
216 /* if we have a address, we use it */
217 maddr = (struct sockaddr_mISDN *)msg->msg_name;
218 mISDN_HEAD_ID(skb) = maddr->channel;
219 } else { /* use default for L2 messages */
220 if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
221 (sk->sk_protocol == ISDN_P_LAPD_NT))
222 mISDN_HEAD_ID(skb) = _pms(sk)->ch.nr;
225 if (*debug & DEBUG_SOCKET)
226 printk(KERN_DEBUG "%s: ID:%x\n",
227 __func__, mISDN_HEAD_ID(skb));
229 err = -ENODEV;
230 if (!_pms(sk)->ch.peer)
231 goto done;
232 err = _pms(sk)->ch.recv(_pms(sk)->ch.peer, skb);
233 if (err)
234 goto done;
235 else {
236 skb = NULL;
237 err = len;
240 done:
241 if (skb)
242 kfree_skb(skb);
243 release_sock(sk);
244 return err;
247 static int
248 data_sock_release(struct socket *sock)
250 struct sock *sk = sock->sk;
252 if (*debug & DEBUG_SOCKET)
253 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
254 if (!sk)
255 return 0;
256 switch (sk->sk_protocol) {
257 case ISDN_P_TE_S0:
258 case ISDN_P_NT_S0:
259 case ISDN_P_TE_E1:
260 case ISDN_P_NT_E1:
261 if (sk->sk_state == MISDN_BOUND)
262 delete_channel(&_pms(sk)->ch);
263 else
264 mISDN_sock_unlink(&data_sockets, sk);
265 break;
266 case ISDN_P_LAPD_TE:
267 case ISDN_P_LAPD_NT:
268 case ISDN_P_B_RAW:
269 case ISDN_P_B_HDLC:
270 case ISDN_P_B_X75SLP:
271 case ISDN_P_B_L2DTMF:
272 case ISDN_P_B_L2DSP:
273 case ISDN_P_B_L2DSPHDLC:
274 delete_channel(&_pms(sk)->ch);
275 mISDN_sock_unlink(&data_sockets, sk);
276 break;
279 lock_sock(sk);
281 sock_orphan(sk);
282 skb_queue_purge(&sk->sk_receive_queue);
284 release_sock(sk);
285 sock_put(sk);
287 return 0;
290 static int
291 data_sock_ioctl_bound(struct sock *sk, unsigned int cmd, void __user *p)
293 struct mISDN_ctrl_req cq;
294 int err = -EINVAL, val[2];
295 struct mISDNchannel *bchan, *next;
297 lock_sock(sk);
298 if (!_pms(sk)->dev) {
299 err = -ENODEV;
300 goto done;
302 switch (cmd) {
303 case IMCTRLREQ:
304 if (copy_from_user(&cq, p, sizeof(cq))) {
305 err = -EFAULT;
306 break;
308 if ((sk->sk_protocol & ~ISDN_P_B_MASK) == ISDN_P_B_START) {
309 list_for_each_entry_safe(bchan, next,
310 &_pms(sk)->dev->bchannels, list) {
311 if (bchan->nr == cq.channel) {
312 err = bchan->ctrl(bchan,
313 CONTROL_CHANNEL, &cq);
314 break;
317 } else
318 err = _pms(sk)->dev->D.ctrl(&_pms(sk)->dev->D,
319 CONTROL_CHANNEL, &cq);
320 if (err)
321 break;
322 if (copy_to_user(p, &cq, sizeof(cq)))
323 err = -EFAULT;
324 break;
325 case IMCLEAR_L2:
326 if (sk->sk_protocol != ISDN_P_LAPD_NT) {
327 err = -EINVAL;
328 break;
330 val[0] = cmd;
331 if (get_user(val[1], (int __user *)p)) {
332 err = -EFAULT;
333 break;
335 err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
336 CONTROL_CHANNEL, val);
337 break;
338 case IMHOLD_L1:
339 if (sk->sk_protocol != ISDN_P_LAPD_NT
340 && sk->sk_protocol != ISDN_P_LAPD_TE) {
341 err = -EINVAL;
342 break;
344 val[0] = cmd;
345 if (get_user(val[1], (int __user *)p)) {
346 err = -EFAULT;
347 break;
349 err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
350 CONTROL_CHANNEL, val);
351 break;
352 default:
353 err = -EINVAL;
354 break;
356 done:
357 release_sock(sk);
358 return err;
361 static int
362 data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
364 int err = 0, id;
365 struct sock *sk = sock->sk;
366 struct mISDNdevice *dev;
367 struct mISDNversion ver;
369 switch (cmd) {
370 case IMGETVERSION:
371 ver.major = MISDN_MAJOR_VERSION;
372 ver.minor = MISDN_MINOR_VERSION;
373 ver.release = MISDN_RELEASE;
374 if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
375 err = -EFAULT;
376 break;
377 case IMGETCOUNT:
378 id = get_mdevice_count();
379 if (put_user(id, (int __user *)arg))
380 err = -EFAULT;
381 break;
382 case IMGETDEVINFO:
383 if (get_user(id, (int __user *)arg)) {
384 err = -EFAULT;
385 break;
387 dev = get_mdevice(id);
388 if (dev) {
389 struct mISDN_devinfo di;
391 memset(&di, 0, sizeof(di));
392 di.id = dev->id;
393 di.Dprotocols = dev->Dprotocols;
394 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
395 di.protocol = dev->D.protocol;
396 memcpy(di.channelmap, dev->channelmap,
397 sizeof(di.channelmap));
398 di.nrbchan = dev->nrbchan;
399 strcpy(di.name, dev_name(&dev->dev));
400 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
401 err = -EFAULT;
402 } else
403 err = -ENODEV;
404 break;
405 default:
406 if (sk->sk_state == MISDN_BOUND)
407 err = data_sock_ioctl_bound(sk, cmd,
408 (void __user *)arg);
409 else
410 err = -ENOTCONN;
412 return err;
415 static int data_sock_setsockopt(struct socket *sock, int level, int optname,
416 char __user *optval, unsigned int len)
418 struct sock *sk = sock->sk;
419 int err = 0, opt = 0;
421 if (*debug & DEBUG_SOCKET)
422 printk(KERN_DEBUG "%s(%p, %d, %x, %p, %d)\n", __func__, sock,
423 level, optname, optval, len);
425 lock_sock(sk);
427 switch (optname) {
428 case MISDN_TIME_STAMP:
429 if (get_user(opt, (int __user *)optval)) {
430 err = -EFAULT;
431 break;
434 if (opt)
435 _pms(sk)->cmask |= MISDN_TIME_STAMP;
436 else
437 _pms(sk)->cmask &= ~MISDN_TIME_STAMP;
438 break;
439 default:
440 err = -ENOPROTOOPT;
441 break;
443 release_sock(sk);
444 return err;
447 static int data_sock_getsockopt(struct socket *sock, int level, int optname,
448 char __user *optval, int __user *optlen)
450 struct sock *sk = sock->sk;
451 int len, opt;
453 if (get_user(len, optlen))
454 return -EFAULT;
456 if (len != sizeof(char))
457 return -EINVAL;
459 switch (optname) {
460 case MISDN_TIME_STAMP:
461 if (_pms(sk)->cmask & MISDN_TIME_STAMP)
462 opt = 1;
463 else
464 opt = 0;
466 if (put_user(opt, optval))
467 return -EFAULT;
468 break;
469 default:
470 return -ENOPROTOOPT;
473 return 0;
476 static int
477 data_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
479 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
480 struct sock *sk = sock->sk;
481 struct sock *csk;
482 int err = 0;
484 if (*debug & DEBUG_SOCKET)
485 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
486 if (addr_len != sizeof(struct sockaddr_mISDN))
487 return -EINVAL;
488 if (!maddr || maddr->family != AF_ISDN)
489 return -EINVAL;
491 lock_sock(sk);
493 if (_pms(sk)->dev) {
494 err = -EALREADY;
495 goto done;
497 _pms(sk)->dev = get_mdevice(maddr->dev);
498 if (!_pms(sk)->dev) {
499 err = -ENODEV;
500 goto done;
503 if (sk->sk_protocol < ISDN_P_B_START) {
504 read_lock_bh(&data_sockets.lock);
505 sk_for_each(csk, &data_sockets.head) {
506 if (sk == csk)
507 continue;
508 if (_pms(csk)->dev != _pms(sk)->dev)
509 continue;
510 if (csk->sk_protocol >= ISDN_P_B_START)
511 continue;
512 if (IS_ISDN_P_TE(csk->sk_protocol)
513 == IS_ISDN_P_TE(sk->sk_protocol))
514 continue;
515 read_unlock_bh(&data_sockets.lock);
516 err = -EBUSY;
517 goto done;
519 read_unlock_bh(&data_sockets.lock);
522 _pms(sk)->ch.send = mISDN_send;
523 _pms(sk)->ch.ctrl = mISDN_ctrl;
525 switch (sk->sk_protocol) {
526 case ISDN_P_TE_S0:
527 case ISDN_P_NT_S0:
528 case ISDN_P_TE_E1:
529 case ISDN_P_NT_E1:
530 mISDN_sock_unlink(&data_sockets, sk);
531 err = connect_layer1(_pms(sk)->dev, &_pms(sk)->ch,
532 sk->sk_protocol, maddr);
533 if (err)
534 mISDN_sock_link(&data_sockets, sk);
535 break;
536 case ISDN_P_LAPD_TE:
537 case ISDN_P_LAPD_NT:
538 err = create_l2entity(_pms(sk)->dev, &_pms(sk)->ch,
539 sk->sk_protocol, maddr);
540 break;
541 case ISDN_P_B_RAW:
542 case ISDN_P_B_HDLC:
543 case ISDN_P_B_X75SLP:
544 case ISDN_P_B_L2DTMF:
545 case ISDN_P_B_L2DSP:
546 case ISDN_P_B_L2DSPHDLC:
547 err = connect_Bstack(_pms(sk)->dev, &_pms(sk)->ch,
548 sk->sk_protocol, maddr);
549 break;
550 default:
551 err = -EPROTONOSUPPORT;
553 if (err)
554 goto done;
555 sk->sk_state = MISDN_BOUND;
556 _pms(sk)->ch.protocol = sk->sk_protocol;
558 done:
559 release_sock(sk);
560 return err;
563 static int
564 data_sock_getname(struct socket *sock, struct sockaddr *addr,
565 int *addr_len, int peer)
567 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
568 struct sock *sk = sock->sk;
570 if (!_pms(sk)->dev)
571 return -EBADFD;
573 lock_sock(sk);
575 *addr_len = sizeof(*maddr);
576 maddr->family = AF_ISDN;
577 maddr->dev = _pms(sk)->dev->id;
578 maddr->channel = _pms(sk)->ch.nr;
579 maddr->sapi = _pms(sk)->ch.addr & 0xff;
580 maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xff;
581 release_sock(sk);
582 return 0;
585 static const struct proto_ops data_sock_ops = {
586 .family = PF_ISDN,
587 .owner = THIS_MODULE,
588 .release = data_sock_release,
589 .ioctl = data_sock_ioctl,
590 .bind = data_sock_bind,
591 .getname = data_sock_getname,
592 .sendmsg = mISDN_sock_sendmsg,
593 .recvmsg = mISDN_sock_recvmsg,
594 .poll = datagram_poll,
595 .listen = sock_no_listen,
596 .shutdown = sock_no_shutdown,
597 .setsockopt = data_sock_setsockopt,
598 .getsockopt = data_sock_getsockopt,
599 .connect = sock_no_connect,
600 .socketpair = sock_no_socketpair,
601 .accept = sock_no_accept,
602 .mmap = sock_no_mmap
605 static int
606 data_sock_create(struct net *net, struct socket *sock, int protocol)
608 struct sock *sk;
610 if (sock->type != SOCK_DGRAM)
611 return -ESOCKTNOSUPPORT;
613 sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto);
614 if (!sk)
615 return -ENOMEM;
617 sock_init_data(sock, sk);
619 sock->ops = &data_sock_ops;
620 sock->state = SS_UNCONNECTED;
621 sock_reset_flag(sk, SOCK_ZAPPED);
623 sk->sk_protocol = protocol;
624 sk->sk_state = MISDN_OPEN;
625 mISDN_sock_link(&data_sockets, sk);
627 return 0;
630 static int
631 base_sock_release(struct socket *sock)
633 struct sock *sk = sock->sk;
635 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
636 if (!sk)
637 return 0;
639 mISDN_sock_unlink(&base_sockets, sk);
640 sock_orphan(sk);
641 sock_put(sk);
643 return 0;
646 static int
647 base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
649 int err = 0, id;
650 struct mISDNdevice *dev;
651 struct mISDNversion ver;
653 switch (cmd) {
654 case IMGETVERSION:
655 ver.major = MISDN_MAJOR_VERSION;
656 ver.minor = MISDN_MINOR_VERSION;
657 ver.release = MISDN_RELEASE;
658 if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
659 err = -EFAULT;
660 break;
661 case IMGETCOUNT:
662 id = get_mdevice_count();
663 if (put_user(id, (int __user *)arg))
664 err = -EFAULT;
665 break;
666 case IMGETDEVINFO:
667 if (get_user(id, (int __user *)arg)) {
668 err = -EFAULT;
669 break;
671 dev = get_mdevice(id);
672 if (dev) {
673 struct mISDN_devinfo di;
675 memset(&di, 0, sizeof(di));
676 di.id = dev->id;
677 di.Dprotocols = dev->Dprotocols;
678 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
679 di.protocol = dev->D.protocol;
680 memcpy(di.channelmap, dev->channelmap,
681 sizeof(di.channelmap));
682 di.nrbchan = dev->nrbchan;
683 strcpy(di.name, dev_name(&dev->dev));
684 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
685 err = -EFAULT;
686 } else
687 err = -ENODEV;
688 break;
689 case IMSETDEVNAME:
691 struct mISDN_devrename dn;
692 if (copy_from_user(&dn, (void __user *)arg,
693 sizeof(dn))) {
694 err = -EFAULT;
695 break;
697 dev = get_mdevice(dn.id);
698 if (dev)
699 err = device_rename(&dev->dev, dn.name);
700 else
701 err = -ENODEV;
703 break;
704 default:
705 err = -EINVAL;
707 return err;
710 static int
711 base_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
713 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
714 struct sock *sk = sock->sk;
715 int err = 0;
717 if (!maddr || maddr->family != AF_ISDN)
718 return -EINVAL;
720 lock_sock(sk);
722 if (_pms(sk)->dev) {
723 err = -EALREADY;
724 goto done;
727 _pms(sk)->dev = get_mdevice(maddr->dev);
728 if (!_pms(sk)->dev) {
729 err = -ENODEV;
730 goto done;
732 sk->sk_state = MISDN_BOUND;
734 done:
735 release_sock(sk);
736 return err;
739 static const struct proto_ops base_sock_ops = {
740 .family = PF_ISDN,
741 .owner = THIS_MODULE,
742 .release = base_sock_release,
743 .ioctl = base_sock_ioctl,
744 .bind = base_sock_bind,
745 .getname = sock_no_getname,
746 .sendmsg = sock_no_sendmsg,
747 .recvmsg = sock_no_recvmsg,
748 .poll = sock_no_poll,
749 .listen = sock_no_listen,
750 .shutdown = sock_no_shutdown,
751 .setsockopt = sock_no_setsockopt,
752 .getsockopt = sock_no_getsockopt,
753 .connect = sock_no_connect,
754 .socketpair = sock_no_socketpair,
755 .accept = sock_no_accept,
756 .mmap = sock_no_mmap
760 static int
761 base_sock_create(struct net *net, struct socket *sock, int protocol)
763 struct sock *sk;
765 if (sock->type != SOCK_RAW)
766 return -ESOCKTNOSUPPORT;
768 sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto);
769 if (!sk)
770 return -ENOMEM;
772 sock_init_data(sock, sk);
773 sock->ops = &base_sock_ops;
774 sock->state = SS_UNCONNECTED;
775 sock_reset_flag(sk, SOCK_ZAPPED);
776 sk->sk_protocol = protocol;
777 sk->sk_state = MISDN_OPEN;
778 mISDN_sock_link(&base_sockets, sk);
780 return 0;
783 static int
784 mISDN_sock_create(struct net *net, struct socket *sock, int proto, int kern)
786 int err = -EPROTONOSUPPORT;
788 switch (proto) {
789 case ISDN_P_BASE:
790 err = base_sock_create(net, sock, proto);
791 break;
792 case ISDN_P_TE_S0:
793 case ISDN_P_NT_S0:
794 case ISDN_P_TE_E1:
795 case ISDN_P_NT_E1:
796 case ISDN_P_LAPD_TE:
797 case ISDN_P_LAPD_NT:
798 case ISDN_P_B_RAW:
799 case ISDN_P_B_HDLC:
800 case ISDN_P_B_X75SLP:
801 case ISDN_P_B_L2DTMF:
802 case ISDN_P_B_L2DSP:
803 case ISDN_P_B_L2DSPHDLC:
804 err = data_sock_create(net, sock, proto);
805 break;
806 default:
807 return err;
810 return err;
813 static const struct net_proto_family mISDN_sock_family_ops = {
814 .owner = THIS_MODULE,
815 .family = PF_ISDN,
816 .create = mISDN_sock_create,
820 misdn_sock_init(u_int *deb)
822 int err;
824 debug = deb;
825 err = sock_register(&mISDN_sock_family_ops);
826 if (err)
827 printk(KERN_ERR "%s: error(%d)\n", __func__, err);
828 return err;
831 void
832 misdn_sock_cleanup(void)
834 sock_unregister(PF_ISDN);