19 #include <linux/slab.h>
20 #include <linux/export.h>
25 static struct proto mISDN_proto = {
28 .obj_size =
sizeof(
struct mISDN_sock)
31 #define _pms(sk) ((struct mISDN_sock *)sk)
33 static struct mISDN_sock_list data_sockets = {
37 static struct mISDN_sock_list base_sockets = {
41 #define L2_HEADER_LEN 4
55 mISDN_sock_link(
struct mISDN_sock_list *
l,
struct sock *
sk)
58 sk_add_node(sk, &l->
head);
62 static void mISDN_sock_unlink(
struct mISDN_sock_list *
l,
struct sock *
sk)
70 mISDN_send(
struct mISDNchannel *ch,
struct sk_buff *
skb)
72 struct mISDN_sock *
msk;
76 if (*
debug & DEBUG_SOCKET)
78 if (msk->sk.sk_state == MISDN_CLOSED)
88 mISDN_ctrl(
struct mISDNchannel *ch,
u_int cmd,
void *
arg)
90 struct mISDN_sock *
msk;
93 if (*
debug & DEBUG_SOCKET)
97 msk->sk.sk_state = MISDN_CLOSED;
109 skb_get_timestamp(skb, &tv);
119 struct sock *sk = sock->
sk;
124 if (*
debug & DEBUG_SOCKET)
126 __func__, (
int)len, flags,
_pms(sk)->ch.nr,
131 if (sk->sk_state == MISDN_CLOSED)
142 maddr->
dev =
_pms(sk)->dev->id;
145 maddr->
channel = (mISDN_HEAD_ID(skb) >> 16) & 0xff;
146 maddr->
tei = (mISDN_HEAD_ID(skb) >> 8) & 0xff;
147 maddr->
sapi = mISDN_HEAD_ID(skb) & 0xff;
150 maddr->
sapi =
_pms(sk)->ch.addr & 0xFF;
151 maddr->
tei = (
_pms(sk)->ch.addr >> 8) & 0xFF;
173 mISDN_sock_cmsg(sk, msg, skb);
177 return err ? : copied;
181 mISDN_sock_sendmsg(
struct kiocb *iocb,
struct socket *sock,
182 struct msghdr *msg,
size_t len)
184 struct sock *sk = sock->
sk;
189 if (*
debug & DEBUG_SOCKET)
203 if (sk->sk_state != MISDN_BOUND)
223 mISDN_HEAD_ID(skb) = maddr->
channel;
227 mISDN_HEAD_ID(skb) =
_pms(sk)->ch.nr;
230 if (*
debug & DEBUG_SOCKET)
232 __func__, mISDN_HEAD_ID(skb));
235 if (!
_pms(sk)->ch.peer)
237 err =
_pms(sk)->ch.recv(
_pms(sk)->ch.peer, skb);
253 data_sock_release(
struct socket *sock)
255 struct sock *sk = sock->
sk;
257 if (*
debug & DEBUG_SOCKET)
266 if (sk->sk_state == MISDN_BOUND)
269 mISDN_sock_unlink(&data_sockets, sk);
280 mISDN_sock_unlink(&data_sockets, sk);
296 data_sock_ioctl_bound(
struct sock *sk,
unsigned int cmd,
void __user *
p)
316 if (bchan->nr == cq.channel) {
317 err = bchan->ctrl(bchan,
336 if (
get_user(val[1], (
int __user *)p)) {
340 err =
_pms(sk)->dev->teimgr->ctrl(
_pms(sk)->
dev->teimgr,
350 if (
get_user(val[1], (
int __user *)p)) {
354 err =
_pms(sk)->dev->teimgr->ctrl(
_pms(sk)->
dev->teimgr,
367 data_sock_ioctl(
struct socket *sock,
unsigned int cmd,
unsigned long arg)
370 struct sock *sk = sock->
sk;
371 struct mISDNdevice *
dev;
384 if (
put_user(
id, (
int __user *)arg))
388 if (
get_user(
id, (
int __user *)arg)) {
396 memset(&di, 0,
sizeof(di));
398 di.Dprotocols = dev->Dprotocols;
400 di.protocol = dev->D.protocol;
401 memcpy(di.channelmap, dev->channelmap,
402 sizeof(di.channelmap));
403 di.nrbchan = dev->nrbchan;
404 strcpy(di.name, dev_name(&dev->dev));
411 if (sk->sk_state == MISDN_BOUND)
412 err = data_sock_ioctl_bound(sk, cmd,
420 static int data_sock_setsockopt(
struct socket *sock,
int level,
int optname,
421 char __user *optval,
unsigned int len)
423 struct sock *sk = sock->
sk;
424 int err = 0,
opt = 0;
426 if (*
debug & DEBUG_SOCKET)
428 level, optname, optval, len);
433 case MISDN_TIME_STAMP:
442 _pms(sk)->cmask &= ~MISDN_TIME_STAMP;
452 static int data_sock_getsockopt(
struct socket *sock,
int level,
int optname,
453 char __user *optval,
int __user *optlen)
455 struct sock *sk = sock->
sk;
461 if (len !=
sizeof(
char))
465 case MISDN_TIME_STAMP:
466 if (
_pms(sk)->cmask & MISDN_TIME_STAMP)
485 struct sock *sk = sock->
sk;
490 if (*
debug & DEBUG_SOCKET)
504 if (!
_pms(sk)->dev) {
514 if (
_pms(csk)->dev !=
_pms(sk)->dev)
528 _pms(sk)->ch.send = mISDN_send;
529 _pms(sk)->ch.ctrl = mISDN_ctrl;
536 mISDN_sock_unlink(&data_sockets, sk);
540 mISDN_sock_link(&data_sockets, sk);
561 sk->sk_state = MISDN_BOUND;
571 int *addr_len,
int peer)
574 struct sock *sk = sock->
sk;
581 *addr_len =
sizeof(*maddr);
582 maddr->
dev =
_pms(sk)->dev->id;
584 maddr->
sapi =
_pms(sk)->ch.addr & 0xff;
585 maddr->
tei = (
_pms(sk)->ch.addr >> 8) & 0xff;
590 static const struct proto_ops data_sock_ops = {
593 .release = data_sock_release,
594 .ioctl = data_sock_ioctl,
595 .bind = data_sock_bind,
596 .getname = data_sock_getname,
597 .sendmsg = mISDN_sock_sendmsg,
598 .recvmsg = mISDN_sock_recvmsg,
602 .setsockopt = data_sock_setsockopt,
603 .getsockopt = data_sock_getsockopt,
624 sock->
ops = &data_sock_ops;
629 sk->sk_state = MISDN_OPEN;
630 mISDN_sock_link(&data_sockets, sk);
636 base_sock_release(
struct socket *sock)
638 struct sock *sk = sock->
sk;
644 mISDN_sock_unlink(&base_sockets, sk);
652 base_sock_ioctl(
struct socket *sock,
unsigned int cmd,
unsigned long arg)
655 struct mISDNdevice *
dev;
668 if (
put_user(
id, (
int __user *)arg))
672 if (
get_user(
id, (
int __user *)arg)) {
680 memset(&di, 0,
sizeof(di));
682 di.Dprotocols = dev->Dprotocols;
684 di.protocol = dev->D.protocol;
685 memcpy(di.channelmap, dev->channelmap,
686 sizeof(di.channelmap));
687 di.nrbchan = dev->nrbchan;
688 strcpy(di.name, dev_name(&dev->dev));
716 base_sock_bind(
struct socket *sock,
struct sockaddr *addr,
int addr_len)
719 struct sock *sk = sock->
sk;
733 if (!
_pms(sk)->dev) {
737 sk->sk_state = MISDN_BOUND;
744 static const struct proto_ops base_sock_ops = {
747 .release = base_sock_release,
748 .ioctl = base_sock_ioctl,
749 .bind = base_sock_bind,
766 base_sock_create(
struct net *net,
struct socket *sock,
int protocol)
778 sock->
ops = &base_sock_ops;
782 sk->sk_state = MISDN_OPEN;
783 mISDN_sock_link(&base_sockets, sk);
789 mISDN_sock_create(
struct net *net,
struct socket *sock,
int proto,
int kern)
795 err = base_sock_create(net, sock, proto);
809 err = data_sock_create(net, sock, proto);
821 .create = mISDN_sock_create,