Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Author Karsten Keil <kkeil@novell.com> |
| 5 | * |
| 6 | * Copyright 2008 by Karsten Keil <kkeil@novell.com> |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/mISDNif.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Paul Gortmaker | 5d76fc2 | 2011-07-10 12:23:16 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 12 | #include "core.h" |
| 13 | |
Hannes Eder | dfa96ec | 2008-12-12 21:13:45 -0800 | [diff] [blame] | 14 | static u_int *debug; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 15 | |
| 16 | static struct proto mISDN_proto = { |
| 17 | .name = "misdn", |
| 18 | .owner = THIS_MODULE, |
| 19 | .obj_size = sizeof(struct mISDN_sock) |
| 20 | }; |
| 21 | |
| 22 | #define _pms(sk) ((struct mISDN_sock *)sk) |
| 23 | |
| 24 | static struct mISDN_sock_list data_sockets = { |
| 25 | .lock = __RW_LOCK_UNLOCKED(data_sockets.lock) |
| 26 | }; |
| 27 | |
| 28 | static struct mISDN_sock_list base_sockets = { |
| 29 | .lock = __RW_LOCK_UNLOCKED(base_sockets.lock) |
| 30 | }; |
| 31 | |
| 32 | #define L2_HEADER_LEN 4 |
| 33 | |
| 34 | static inline struct sk_buff * |
| 35 | _l2_alloc_skb(unsigned int len, gfp_t gfp_mask) |
| 36 | { |
| 37 | struct sk_buff *skb; |
| 38 | |
| 39 | skb = alloc_skb(len + L2_HEADER_LEN, gfp_mask); |
| 40 | if (likely(skb)) |
| 41 | skb_reserve(skb, L2_HEADER_LEN); |
| 42 | return skb; |
| 43 | } |
| 44 | |
| 45 | static void |
| 46 | mISDN_sock_link(struct mISDN_sock_list *l, struct sock *sk) |
| 47 | { |
| 48 | write_lock_bh(&l->lock); |
| 49 | sk_add_node(sk, &l->head); |
| 50 | write_unlock_bh(&l->lock); |
| 51 | } |
| 52 | |
| 53 | static void mISDN_sock_unlink(struct mISDN_sock_list *l, struct sock *sk) |
| 54 | { |
| 55 | write_lock_bh(&l->lock); |
| 56 | sk_del_node_init(sk); |
| 57 | write_unlock_bh(&l->lock); |
| 58 | } |
| 59 | |
| 60 | static int |
| 61 | mISDN_send(struct mISDNchannel *ch, struct sk_buff *skb) |
| 62 | { |
| 63 | struct mISDN_sock *msk; |
| 64 | int err; |
| 65 | |
| 66 | msk = container_of(ch, struct mISDN_sock, ch); |
| 67 | if (*debug & DEBUG_SOCKET) |
| 68 | printk(KERN_DEBUG "%s len %d %p\n", __func__, skb->len, skb); |
| 69 | if (msk->sk.sk_state == MISDN_CLOSED) |
| 70 | return -EUNATCH; |
| 71 | __net_timestamp(skb); |
| 72 | err = sock_queue_rcv_skb(&msk->sk, skb); |
| 73 | if (err) |
| 74 | printk(KERN_WARNING "%s: error %d\n", __func__, err); |
| 75 | return err; |
| 76 | } |
| 77 | |
| 78 | static int |
| 79 | mISDN_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg) |
| 80 | { |
| 81 | struct mISDN_sock *msk; |
| 82 | |
| 83 | msk = container_of(ch, struct mISDN_sock, ch); |
| 84 | if (*debug & DEBUG_SOCKET) |
| 85 | printk(KERN_DEBUG "%s(%p, %x, %p)\n", __func__, ch, cmd, arg); |
| 86 | switch (cmd) { |
| 87 | case CLOSE_CHANNEL: |
| 88 | msk->sk.sk_state = MISDN_CLOSED; |
| 89 | break; |
| 90 | } |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static inline void |
| 95 | mISDN_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb) |
| 96 | { |
Deepa Dinamani | 13c6ee2 | 2019-02-02 07:34:48 -0800 | [diff] [blame] | 97 | struct __kernel_old_timeval tv; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 98 | |
| 99 | if (_pms(sk)->cmask & MISDN_TIME_STAMP) { |
| 100 | skb_get_timestamp(skb, &tv); |
| 101 | put_cmsg(msg, SOL_MISDN, MISDN_TIME_STAMP, sizeof(tv), &tv); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | static int |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 106 | mISDN_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, |
| 107 | int flags) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 108 | { |
| 109 | struct sk_buff *skb; |
| 110 | struct sock *sk = sock->sk; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 111 | |
| 112 | int copied, err; |
| 113 | |
| 114 | if (*debug & DEBUG_SOCKET) |
| 115 | printk(KERN_DEBUG "%s: len %d, flags %x ch.nr %d, proto %x\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 116 | __func__, (int)len, flags, _pms(sk)->ch.nr, |
| 117 | sk->sk_protocol); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 118 | if (flags & (MSG_OOB)) |
| 119 | return -EOPNOTSUPP; |
| 120 | |
| 121 | if (sk->sk_state == MISDN_CLOSED) |
| 122 | return 0; |
| 123 | |
| 124 | skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &err); |
| 125 | if (!skb) |
| 126 | return err; |
| 127 | |
Hannes Frederic Sowa | f3d3342 | 2013-11-21 03:14:22 +0100 | [diff] [blame] | 128 | if (msg->msg_name) { |
Steffen Hurrle | 342dfc3 | 2014-01-17 22:53:15 +0100 | [diff] [blame] | 129 | DECLARE_SOCKADDR(struct sockaddr_mISDN *, maddr, msg->msg_name); |
Hannes Frederic Sowa | f3d3342 | 2013-11-21 03:14:22 +0100 | [diff] [blame] | 130 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 131 | maddr->family = AF_ISDN; |
| 132 | maddr->dev = _pms(sk)->dev->id; |
| 133 | if ((sk->sk_protocol == ISDN_P_LAPD_TE) || |
| 134 | (sk->sk_protocol == ISDN_P_LAPD_NT)) { |
| 135 | maddr->channel = (mISDN_HEAD_ID(skb) >> 16) & 0xff; |
| 136 | maddr->tei = (mISDN_HEAD_ID(skb) >> 8) & 0xff; |
| 137 | maddr->sapi = mISDN_HEAD_ID(skb) & 0xff; |
| 138 | } else { |
| 139 | maddr->channel = _pms(sk)->ch.nr; |
| 140 | maddr->sapi = _pms(sk)->ch.addr & 0xFF; |
| 141 | maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xFF; |
| 142 | } |
Hannes Frederic Sowa | f3d3342 | 2013-11-21 03:14:22 +0100 | [diff] [blame] | 143 | msg->msg_namelen = sizeof(*maddr); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | copied = skb->len + MISDN_HEADER_LEN; |
| 147 | if (len < copied) { |
| 148 | if (flags & MSG_PEEK) |
Reshetova, Elena | 6335479 | 2017-06-30 13:07:58 +0300 | [diff] [blame] | 149 | refcount_dec(&skb->users); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 150 | else |
| 151 | skb_queue_head(&sk->sk_receive_queue, skb); |
| 152 | return -ENOSPC; |
| 153 | } |
| 154 | memcpy(skb_push(skb, MISDN_HEADER_LEN), mISDN_HEAD_P(skb), |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 155 | MISDN_HEADER_LEN); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 156 | |
David S. Miller | 51f3d02 | 2014-11-05 16:46:40 -0500 | [diff] [blame] | 157 | err = skb_copy_datagram_msg(skb, 0, msg, copied); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 158 | |
| 159 | mISDN_sock_cmsg(sk, msg, skb); |
| 160 | |
| 161 | skb_free_datagram(sk, skb); |
| 162 | |
| 163 | return err ? : copied; |
| 164 | } |
| 165 | |
| 166 | static int |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 167 | mISDN_sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 168 | { |
| 169 | struct sock *sk = sock->sk; |
| 170 | struct sk_buff *skb; |
| 171 | int err = -ENOMEM; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 172 | |
| 173 | if (*debug & DEBUG_SOCKET) |
| 174 | printk(KERN_DEBUG "%s: len %d flags %x ch %d proto %x\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 175 | __func__, (int)len, msg->msg_flags, _pms(sk)->ch.nr, |
| 176 | sk->sk_protocol); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 177 | |
| 178 | if (msg->msg_flags & MSG_OOB) |
| 179 | return -EOPNOTSUPP; |
| 180 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 181 | if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_NOSIGNAL | MSG_ERRQUEUE)) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 182 | return -EINVAL; |
| 183 | |
| 184 | if (len < MISDN_HEADER_LEN) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | if (sk->sk_state != MISDN_BOUND) |
| 188 | return -EBADFD; |
| 189 | |
| 190 | lock_sock(sk); |
| 191 | |
| 192 | skb = _l2_alloc_skb(len, GFP_KERNEL); |
| 193 | if (!skb) |
| 194 | goto done; |
| 195 | |
Al Viro | 6ce8e9c | 2014-04-06 21:25:44 -0400 | [diff] [blame] | 196 | if (memcpy_from_msg(skb_put(skb, len), msg, len)) { |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 197 | err = -EFAULT; |
Karsten Keil | 5df3b8b | 2009-05-22 11:04:52 +0000 | [diff] [blame] | 198 | goto done; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | memcpy(mISDN_HEAD_P(skb), skb->data, MISDN_HEADER_LEN); |
| 202 | skb_pull(skb, MISDN_HEADER_LEN); |
| 203 | |
| 204 | if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) { |
| 205 | /* if we have a address, we use it */ |
Steffen Hurrle | 342dfc3 | 2014-01-17 22:53:15 +0100 | [diff] [blame] | 206 | DECLARE_SOCKADDR(struct sockaddr_mISDN *, maddr, msg->msg_name); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 207 | mISDN_HEAD_ID(skb) = maddr->channel; |
| 208 | } else { /* use default for L2 messages */ |
| 209 | if ((sk->sk_protocol == ISDN_P_LAPD_TE) || |
| 210 | (sk->sk_protocol == ISDN_P_LAPD_NT)) |
Karsten Keil | eac74af | 2009-05-22 11:04:56 +0000 | [diff] [blame] | 211 | mISDN_HEAD_ID(skb) = _pms(sk)->ch.nr; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | if (*debug & DEBUG_SOCKET) |
| 215 | printk(KERN_DEBUG "%s: ID:%x\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 216 | __func__, mISDN_HEAD_ID(skb)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 217 | |
| 218 | err = -ENODEV; |
Karsten Keil | 5df3b8b | 2009-05-22 11:04:52 +0000 | [diff] [blame] | 219 | if (!_pms(sk)->ch.peer) |
| 220 | goto done; |
| 221 | err = _pms(sk)->ch.recv(_pms(sk)->ch.peer, skb); |
| 222 | if (err) |
| 223 | goto done; |
| 224 | else { |
| 225 | skb = NULL; |
| 226 | err = len; |
| 227 | } |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 228 | |
| 229 | done: |
zhong jiang | 66ab235 | 2018-09-20 22:27:28 +0800 | [diff] [blame] | 230 | kfree_skb(skb); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 231 | release_sock(sk); |
| 232 | return err; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static int |
| 236 | data_sock_release(struct socket *sock) |
| 237 | { |
| 238 | struct sock *sk = sock->sk; |
| 239 | |
| 240 | if (*debug & DEBUG_SOCKET) |
| 241 | printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk); |
| 242 | if (!sk) |
| 243 | return 0; |
| 244 | switch (sk->sk_protocol) { |
| 245 | case ISDN_P_TE_S0: |
| 246 | case ISDN_P_NT_S0: |
| 247 | case ISDN_P_TE_E1: |
| 248 | case ISDN_P_NT_E1: |
| 249 | if (sk->sk_state == MISDN_BOUND) |
| 250 | delete_channel(&_pms(sk)->ch); |
| 251 | else |
| 252 | mISDN_sock_unlink(&data_sockets, sk); |
| 253 | break; |
| 254 | case ISDN_P_LAPD_TE: |
| 255 | case ISDN_P_LAPD_NT: |
| 256 | case ISDN_P_B_RAW: |
| 257 | case ISDN_P_B_HDLC: |
| 258 | case ISDN_P_B_X75SLP: |
| 259 | case ISDN_P_B_L2DTMF: |
| 260 | case ISDN_P_B_L2DSP: |
| 261 | case ISDN_P_B_L2DSPHDLC: |
| 262 | delete_channel(&_pms(sk)->ch); |
| 263 | mISDN_sock_unlink(&data_sockets, sk); |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | lock_sock(sk); |
| 268 | |
| 269 | sock_orphan(sk); |
| 270 | skb_queue_purge(&sk->sk_receive_queue); |
| 271 | |
| 272 | release_sock(sk); |
| 273 | sock_put(sk); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | static int |
| 279 | data_sock_ioctl_bound(struct sock *sk, unsigned int cmd, void __user *p) |
| 280 | { |
| 281 | struct mISDN_ctrl_req cq; |
Andreas Eversberg | e73f6b2 | 2009-05-22 11:04:48 +0000 | [diff] [blame] | 282 | int err = -EINVAL, val[2]; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 283 | struct mISDNchannel *bchan, *next; |
| 284 | |
| 285 | lock_sock(sk); |
| 286 | if (!_pms(sk)->dev) { |
| 287 | err = -ENODEV; |
| 288 | goto done; |
| 289 | } |
| 290 | switch (cmd) { |
| 291 | case IMCTRLREQ: |
| 292 | if (copy_from_user(&cq, p, sizeof(cq))) { |
| 293 | err = -EFAULT; |
| 294 | break; |
| 295 | } |
| 296 | if ((sk->sk_protocol & ~ISDN_P_B_MASK) == ISDN_P_B_START) { |
| 297 | list_for_each_entry_safe(bchan, next, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 298 | &_pms(sk)->dev->bchannels, list) { |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 299 | if (bchan->nr == cq.channel) { |
| 300 | err = bchan->ctrl(bchan, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 301 | CONTROL_CHANNEL, &cq); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | } |
| 305 | } else |
| 306 | err = _pms(sk)->dev->D.ctrl(&_pms(sk)->dev->D, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 307 | CONTROL_CHANNEL, &cq); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 308 | if (err) |
| 309 | break; |
| 310 | if (copy_to_user(p, &cq, sizeof(cq))) |
| 311 | err = -EFAULT; |
| 312 | break; |
| 313 | case IMCLEAR_L2: |
| 314 | if (sk->sk_protocol != ISDN_P_LAPD_NT) { |
| 315 | err = -EINVAL; |
| 316 | break; |
| 317 | } |
Andreas Eversberg | e73f6b2 | 2009-05-22 11:04:48 +0000 | [diff] [blame] | 318 | val[0] = cmd; |
| 319 | if (get_user(val[1], (int __user *)p)) { |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 320 | err = -EFAULT; |
| 321 | break; |
| 322 | } |
| 323 | err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 324 | CONTROL_CHANNEL, val); |
Andreas Eversberg | e73f6b2 | 2009-05-22 11:04:48 +0000 | [diff] [blame] | 325 | break; |
| 326 | case IMHOLD_L1: |
| 327 | if (sk->sk_protocol != ISDN_P_LAPD_NT |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 328 | && sk->sk_protocol != ISDN_P_LAPD_TE) { |
Andreas Eversberg | e73f6b2 | 2009-05-22 11:04:48 +0000 | [diff] [blame] | 329 | err = -EINVAL; |
| 330 | break; |
| 331 | } |
| 332 | val[0] = cmd; |
| 333 | if (get_user(val[1], (int __user *)p)) { |
| 334 | err = -EFAULT; |
| 335 | break; |
| 336 | } |
| 337 | err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 338 | CONTROL_CHANNEL, val); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 339 | break; |
| 340 | default: |
| 341 | err = -EINVAL; |
| 342 | break; |
| 343 | } |
| 344 | done: |
| 345 | release_sock(sk); |
| 346 | return err; |
| 347 | } |
| 348 | |
| 349 | static int |
| 350 | data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 351 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 352 | int err = 0, id; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 353 | struct sock *sk = sock->sk; |
| 354 | struct mISDNdevice *dev; |
| 355 | struct mISDNversion ver; |
| 356 | |
| 357 | switch (cmd) { |
| 358 | case IMGETVERSION: |
| 359 | ver.major = MISDN_MAJOR_VERSION; |
| 360 | ver.minor = MISDN_MINOR_VERSION; |
| 361 | ver.release = MISDN_RELEASE; |
| 362 | if (copy_to_user((void __user *)arg, &ver, sizeof(ver))) |
| 363 | err = -EFAULT; |
| 364 | break; |
| 365 | case IMGETCOUNT: |
| 366 | id = get_mdevice_count(); |
| 367 | if (put_user(id, (int __user *)arg)) |
| 368 | err = -EFAULT; |
| 369 | break; |
| 370 | case IMGETDEVINFO: |
| 371 | if (get_user(id, (int __user *)arg)) { |
| 372 | err = -EFAULT; |
| 373 | break; |
| 374 | } |
| 375 | dev = get_mdevice(id); |
| 376 | if (dev) { |
| 377 | struct mISDN_devinfo di; |
| 378 | |
Kulikov Vasiliy | ce384d9 | 2010-10-29 23:04:33 +0000 | [diff] [blame] | 379 | memset(&di, 0, sizeof(di)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 380 | di.id = dev->id; |
| 381 | di.Dprotocols = dev->Dprotocols; |
| 382 | di.Bprotocols = dev->Bprotocols | get_all_Bprotocols(); |
| 383 | di.protocol = dev->D.protocol; |
| 384 | memcpy(di.channelmap, dev->channelmap, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 385 | sizeof(di.channelmap)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 386 | di.nrbchan = dev->nrbchan; |
Dan Carpenter | ccfb62f | 2019-05-22 11:45:13 +0300 | [diff] [blame] | 387 | strscpy(di.name, dev_name(&dev->dev), sizeof(di.name)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 388 | if (copy_to_user((void __user *)arg, &di, sizeof(di))) |
| 389 | err = -EFAULT; |
| 390 | } else |
| 391 | err = -ENODEV; |
| 392 | break; |
| 393 | default: |
| 394 | if (sk->sk_state == MISDN_BOUND) |
| 395 | err = data_sock_ioctl_bound(sk, cmd, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 396 | (void __user *)arg); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 397 | else |
| 398 | err = -ENOTCONN; |
| 399 | } |
| 400 | return err; |
| 401 | } |
| 402 | |
| 403 | static int data_sock_setsockopt(struct socket *sock, int level, int optname, |
Christoph Hellwig | a7b75c5 | 2020-07-23 08:09:07 +0200 | [diff] [blame] | 404 | sockptr_t optval, unsigned int len) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 405 | { |
| 406 | struct sock *sk = sock->sk; |
| 407 | int err = 0, opt = 0; |
| 408 | |
| 409 | if (*debug & DEBUG_SOCKET) |
David S. Miller | 2d6be17 | 2020-07-24 16:36:13 -0700 | [diff] [blame] | 410 | printk(KERN_DEBUG "%s(%p, %d, %x, optval, %d)\n", __func__, sock, |
| 411 | level, optname, len); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 412 | |
| 413 | lock_sock(sk); |
| 414 | |
| 415 | switch (optname) { |
| 416 | case MISDN_TIME_STAMP: |
Christoph Hellwig | a7b75c5 | 2020-07-23 08:09:07 +0200 | [diff] [blame] | 417 | if (copy_from_sockptr(&opt, optval, sizeof(int))) { |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 418 | err = -EFAULT; |
| 419 | break; |
| 420 | } |
| 421 | |
| 422 | if (opt) |
| 423 | _pms(sk)->cmask |= MISDN_TIME_STAMP; |
| 424 | else |
| 425 | _pms(sk)->cmask &= ~MISDN_TIME_STAMP; |
| 426 | break; |
| 427 | default: |
| 428 | err = -ENOPROTOOPT; |
| 429 | break; |
| 430 | } |
| 431 | release_sock(sk); |
| 432 | return err; |
| 433 | } |
| 434 | |
| 435 | static int data_sock_getsockopt(struct socket *sock, int level, int optname, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 436 | char __user *optval, int __user *optlen) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 437 | { |
| 438 | struct sock *sk = sock->sk; |
| 439 | int len, opt; |
| 440 | |
| 441 | if (get_user(len, optlen)) |
| 442 | return -EFAULT; |
| 443 | |
David S. Miller | 81b424d | 2011-04-17 16:48:53 -0700 | [diff] [blame] | 444 | if (len != sizeof(char)) |
| 445 | return -EINVAL; |
| 446 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 447 | switch (optname) { |
| 448 | case MISDN_TIME_STAMP: |
| 449 | if (_pms(sk)->cmask & MISDN_TIME_STAMP) |
| 450 | opt = 1; |
| 451 | else |
| 452 | opt = 0; |
| 453 | |
| 454 | if (put_user(opt, optval)) |
| 455 | return -EFAULT; |
| 456 | break; |
| 457 | default: |
| 458 | return -ENOPROTOOPT; |
| 459 | } |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | static int |
| 465 | data_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) |
| 466 | { |
| 467 | struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr; |
| 468 | struct sock *sk = sock->sk; |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 469 | struct sock *csk; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 470 | int err = 0; |
| 471 | |
| 472 | if (*debug & DEBUG_SOCKET) |
| 473 | printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk); |
| 474 | if (addr_len != sizeof(struct sockaddr_mISDN)) |
| 475 | return -EINVAL; |
| 476 | if (!maddr || maddr->family != AF_ISDN) |
| 477 | return -EINVAL; |
| 478 | |
| 479 | lock_sock(sk); |
| 480 | |
| 481 | if (_pms(sk)->dev) { |
| 482 | err = -EALREADY; |
| 483 | goto done; |
| 484 | } |
| 485 | _pms(sk)->dev = get_mdevice(maddr->dev); |
| 486 | if (!_pms(sk)->dev) { |
| 487 | err = -ENODEV; |
| 488 | goto done; |
| 489 | } |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 490 | |
Andreas Eversberg | 9a81255 | 2008-09-14 14:42:18 +0200 | [diff] [blame] | 491 | if (sk->sk_protocol < ISDN_P_B_START) { |
| 492 | read_lock_bh(&data_sockets.lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 493 | sk_for_each(csk, &data_sockets.head) { |
Andreas Eversberg | 9a81255 | 2008-09-14 14:42:18 +0200 | [diff] [blame] | 494 | if (sk == csk) |
| 495 | continue; |
| 496 | if (_pms(csk)->dev != _pms(sk)->dev) |
| 497 | continue; |
| 498 | if (csk->sk_protocol >= ISDN_P_B_START) |
| 499 | continue; |
| 500 | if (IS_ISDN_P_TE(csk->sk_protocol) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 501 | == IS_ISDN_P_TE(sk->sk_protocol)) |
Andreas Eversberg | 9a81255 | 2008-09-14 14:42:18 +0200 | [diff] [blame] | 502 | continue; |
| 503 | read_unlock_bh(&data_sockets.lock); |
| 504 | err = -EBUSY; |
| 505 | goto done; |
| 506 | } |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 507 | read_unlock_bh(&data_sockets.lock); |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 508 | } |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 509 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 510 | _pms(sk)->ch.send = mISDN_send; |
| 511 | _pms(sk)->ch.ctrl = mISDN_ctrl; |
| 512 | |
| 513 | switch (sk->sk_protocol) { |
| 514 | case ISDN_P_TE_S0: |
| 515 | case ISDN_P_NT_S0: |
| 516 | case ISDN_P_TE_E1: |
| 517 | case ISDN_P_NT_E1: |
| 518 | mISDN_sock_unlink(&data_sockets, sk); |
| 519 | err = connect_layer1(_pms(sk)->dev, &_pms(sk)->ch, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 520 | sk->sk_protocol, maddr); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 521 | if (err) |
| 522 | mISDN_sock_link(&data_sockets, sk); |
| 523 | break; |
| 524 | case ISDN_P_LAPD_TE: |
| 525 | case ISDN_P_LAPD_NT: |
| 526 | err = create_l2entity(_pms(sk)->dev, &_pms(sk)->ch, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 527 | sk->sk_protocol, maddr); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 528 | break; |
| 529 | case ISDN_P_B_RAW: |
| 530 | case ISDN_P_B_HDLC: |
| 531 | case ISDN_P_B_X75SLP: |
| 532 | case ISDN_P_B_L2DTMF: |
| 533 | case ISDN_P_B_L2DSP: |
| 534 | case ISDN_P_B_L2DSPHDLC: |
| 535 | err = connect_Bstack(_pms(sk)->dev, &_pms(sk)->ch, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 536 | sk->sk_protocol, maddr); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 537 | break; |
| 538 | default: |
| 539 | err = -EPROTONOSUPPORT; |
| 540 | } |
| 541 | if (err) |
| 542 | goto done; |
| 543 | sk->sk_state = MISDN_BOUND; |
| 544 | _pms(sk)->ch.protocol = sk->sk_protocol; |
| 545 | |
| 546 | done: |
| 547 | release_sock(sk); |
| 548 | return err; |
| 549 | } |
| 550 | |
| 551 | static int |
| 552 | data_sock_getname(struct socket *sock, struct sockaddr *addr, |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 553 | int peer) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 554 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 555 | struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 556 | struct sock *sk = sock->sk; |
| 557 | |
| 558 | if (!_pms(sk)->dev) |
| 559 | return -EBADFD; |
| 560 | |
| 561 | lock_sock(sk); |
| 562 | |
Dan Carpenter | d915209 | 2013-04-22 20:24:14 +0000 | [diff] [blame] | 563 | maddr->family = AF_ISDN; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 564 | maddr->dev = _pms(sk)->dev->id; |
| 565 | maddr->channel = _pms(sk)->ch.nr; |
| 566 | maddr->sapi = _pms(sk)->ch.addr & 0xff; |
| 567 | maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xff; |
| 568 | release_sock(sk); |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 569 | return sizeof(*maddr); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static const struct proto_ops data_sock_ops = { |
| 573 | .family = PF_ISDN, |
| 574 | .owner = THIS_MODULE, |
| 575 | .release = data_sock_release, |
| 576 | .ioctl = data_sock_ioctl, |
| 577 | .bind = data_sock_bind, |
| 578 | .getname = data_sock_getname, |
| 579 | .sendmsg = mISDN_sock_sendmsg, |
| 580 | .recvmsg = mISDN_sock_recvmsg, |
Linus Torvalds | a11e1d4 | 2018-06-28 09:43:44 -0700 | [diff] [blame] | 581 | .poll = datagram_poll, |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 582 | .listen = sock_no_listen, |
| 583 | .shutdown = sock_no_shutdown, |
| 584 | .setsockopt = data_sock_setsockopt, |
| 585 | .getsockopt = data_sock_getsockopt, |
| 586 | .connect = sock_no_connect, |
| 587 | .socketpair = sock_no_socketpair, |
| 588 | .accept = sock_no_accept, |
| 589 | .mmap = sock_no_mmap |
| 590 | }; |
| 591 | |
| 592 | static int |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 593 | data_sock_create(struct net *net, struct socket *sock, int protocol, int kern) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 594 | { |
| 595 | struct sock *sk; |
| 596 | |
| 597 | if (sock->type != SOCK_DGRAM) |
| 598 | return -ESOCKTNOSUPPORT; |
| 599 | |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 600 | sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto, kern); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 601 | if (!sk) |
| 602 | return -ENOMEM; |
| 603 | |
| 604 | sock_init_data(sock, sk); |
| 605 | |
| 606 | sock->ops = &data_sock_ops; |
| 607 | sock->state = SS_UNCONNECTED; |
| 608 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 609 | |
| 610 | sk->sk_protocol = protocol; |
| 611 | sk->sk_state = MISDN_OPEN; |
| 612 | mISDN_sock_link(&data_sockets, sk); |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static int |
| 618 | base_sock_release(struct socket *sock) |
| 619 | { |
| 620 | struct sock *sk = sock->sk; |
| 621 | |
| 622 | printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk); |
| 623 | if (!sk) |
| 624 | return 0; |
| 625 | |
| 626 | mISDN_sock_unlink(&base_sockets, sk); |
| 627 | sock_orphan(sk); |
| 628 | sock_put(sk); |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static int |
| 634 | base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 635 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 636 | int err = 0, id; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 637 | struct mISDNdevice *dev; |
| 638 | struct mISDNversion ver; |
| 639 | |
| 640 | switch (cmd) { |
| 641 | case IMGETVERSION: |
| 642 | ver.major = MISDN_MAJOR_VERSION; |
| 643 | ver.minor = MISDN_MINOR_VERSION; |
| 644 | ver.release = MISDN_RELEASE; |
| 645 | if (copy_to_user((void __user *)arg, &ver, sizeof(ver))) |
| 646 | err = -EFAULT; |
| 647 | break; |
| 648 | case IMGETCOUNT: |
| 649 | id = get_mdevice_count(); |
| 650 | if (put_user(id, (int __user *)arg)) |
| 651 | err = -EFAULT; |
| 652 | break; |
| 653 | case IMGETDEVINFO: |
| 654 | if (get_user(id, (int __user *)arg)) { |
| 655 | err = -EFAULT; |
| 656 | break; |
| 657 | } |
| 658 | dev = get_mdevice(id); |
| 659 | if (dev) { |
| 660 | struct mISDN_devinfo di; |
| 661 | |
Kulikov Vasiliy | ce384d9 | 2010-10-29 23:04:33 +0000 | [diff] [blame] | 662 | memset(&di, 0, sizeof(di)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 663 | di.id = dev->id; |
| 664 | di.Dprotocols = dev->Dprotocols; |
| 665 | di.Bprotocols = dev->Bprotocols | get_all_Bprotocols(); |
| 666 | di.protocol = dev->D.protocol; |
| 667 | memcpy(di.channelmap, dev->channelmap, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 668 | sizeof(di.channelmap)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 669 | di.nrbchan = dev->nrbchan; |
Dan Carpenter | ccfb62f | 2019-05-22 11:45:13 +0300 | [diff] [blame] | 670 | strscpy(di.name, dev_name(&dev->dev), sizeof(di.name)); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 671 | if (copy_to_user((void __user *)arg, &di, sizeof(di))) |
| 672 | err = -EFAULT; |
| 673 | } else |
| 674 | err = -ENODEV; |
| 675 | break; |
Matthias Urlichs | 8b6015f | 2008-08-12 10:12:09 +0200 | [diff] [blame] | 676 | case IMSETDEVNAME: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 677 | { |
| 678 | struct mISDN_devrename dn; |
| 679 | if (copy_from_user(&dn, (void __user *)arg, |
| 680 | sizeof(dn))) { |
| 681 | err = -EFAULT; |
| 682 | break; |
Matthias Urlichs | 8b6015f | 2008-08-12 10:12:09 +0200 | [diff] [blame] | 683 | } |
Dan Carpenter | ccfb62f | 2019-05-22 11:45:13 +0300 | [diff] [blame] | 684 | dn.name[sizeof(dn.name) - 1] = '\0'; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 685 | dev = get_mdevice(dn.id); |
| 686 | if (dev) |
| 687 | err = device_rename(&dev->dev, dn.name); |
| 688 | else |
| 689 | err = -ENODEV; |
| 690 | } |
| 691 | break; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 692 | default: |
| 693 | err = -EINVAL; |
| 694 | } |
| 695 | return err; |
| 696 | } |
| 697 | |
| 698 | static int |
| 699 | base_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) |
| 700 | { |
| 701 | struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr; |
| 702 | struct sock *sk = sock->sk; |
| 703 | int err = 0; |
| 704 | |
Tetsuo Handa | 238ffdc | 2019-04-12 19:52:36 +0900 | [diff] [blame] | 705 | if (addr_len < sizeof(struct sockaddr_mISDN)) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | |
Tetsuo Handa | 238ffdc | 2019-04-12 19:52:36 +0900 | [diff] [blame] | 708 | if (!maddr || maddr->family != AF_ISDN) |
Emrah Demir | b821646 | 2016-04-08 22:16:11 +0300 | [diff] [blame] | 709 | return -EINVAL; |
| 710 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 711 | lock_sock(sk); |
| 712 | |
| 713 | if (_pms(sk)->dev) { |
| 714 | err = -EALREADY; |
| 715 | goto done; |
| 716 | } |
| 717 | |
| 718 | _pms(sk)->dev = get_mdevice(maddr->dev); |
| 719 | if (!_pms(sk)->dev) { |
| 720 | err = -ENODEV; |
| 721 | goto done; |
| 722 | } |
| 723 | sk->sk_state = MISDN_BOUND; |
| 724 | |
| 725 | done: |
| 726 | release_sock(sk); |
| 727 | return err; |
| 728 | } |
| 729 | |
| 730 | static const struct proto_ops base_sock_ops = { |
| 731 | .family = PF_ISDN, |
| 732 | .owner = THIS_MODULE, |
| 733 | .release = base_sock_release, |
| 734 | .ioctl = base_sock_ioctl, |
| 735 | .bind = base_sock_bind, |
| 736 | .getname = sock_no_getname, |
| 737 | .sendmsg = sock_no_sendmsg, |
| 738 | .recvmsg = sock_no_recvmsg, |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 739 | .listen = sock_no_listen, |
| 740 | .shutdown = sock_no_shutdown, |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 741 | .connect = sock_no_connect, |
| 742 | .socketpair = sock_no_socketpair, |
| 743 | .accept = sock_no_accept, |
| 744 | .mmap = sock_no_mmap |
| 745 | }; |
| 746 | |
| 747 | |
| 748 | static int |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 749 | base_sock_create(struct net *net, struct socket *sock, int protocol, int kern) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 750 | { |
| 751 | struct sock *sk; |
| 752 | |
| 753 | if (sock->type != SOCK_RAW) |
| 754 | return -ESOCKTNOSUPPORT; |
Ori Nimron | b91ee4a | 2019-09-20 09:35:45 +0200 | [diff] [blame] | 755 | if (!capable(CAP_NET_RAW)) |
| 756 | return -EPERM; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 757 | |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 758 | sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto, kern); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 759 | if (!sk) |
| 760 | return -ENOMEM; |
| 761 | |
| 762 | sock_init_data(sock, sk); |
| 763 | sock->ops = &base_sock_ops; |
| 764 | sock->state = SS_UNCONNECTED; |
| 765 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 766 | sk->sk_protocol = protocol; |
| 767 | sk->sk_state = MISDN_OPEN; |
| 768 | mISDN_sock_link(&base_sockets, sk); |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static int |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 774 | mISDN_sock_create(struct net *net, struct socket *sock, int proto, int kern) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 775 | { |
| 776 | int err = -EPROTONOSUPPORT; |
| 777 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 778 | switch (proto) { |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 779 | case ISDN_P_BASE: |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 780 | err = base_sock_create(net, sock, proto, kern); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 781 | break; |
| 782 | case ISDN_P_TE_S0: |
| 783 | case ISDN_P_NT_S0: |
| 784 | case ISDN_P_TE_E1: |
| 785 | case ISDN_P_NT_E1: |
| 786 | case ISDN_P_LAPD_TE: |
| 787 | case ISDN_P_LAPD_NT: |
| 788 | case ISDN_P_B_RAW: |
| 789 | case ISDN_P_B_HDLC: |
| 790 | case ISDN_P_B_X75SLP: |
| 791 | case ISDN_P_B_L2DTMF: |
| 792 | case ISDN_P_B_L2DSP: |
| 793 | case ISDN_P_B_L2DSPHDLC: |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 794 | err = data_sock_create(net, sock, proto, kern); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 795 | break; |
| 796 | default: |
| 797 | return err; |
| 798 | } |
| 799 | |
| 800 | return err; |
| 801 | } |
| 802 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 803 | static const struct net_proto_family mISDN_sock_family_ops = { |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 804 | .owner = THIS_MODULE, |
| 805 | .family = PF_ISDN, |
| 806 | .create = mISDN_sock_create, |
| 807 | }; |
| 808 | |
| 809 | int |
| 810 | misdn_sock_init(u_int *deb) |
| 811 | { |
| 812 | int err; |
| 813 | |
| 814 | debug = deb; |
| 815 | err = sock_register(&mISDN_sock_family_ops); |
| 816 | if (err) |
| 817 | printk(KERN_ERR "%s: error(%d)\n", __func__, err); |
| 818 | return err; |
| 819 | } |
| 820 | |
| 821 | void |
| 822 | misdn_sock_cleanup(void) |
| 823 | { |
| 824 | sock_unregister(PF_ISDN); |
| 825 | } |