aboutsummaryrefslogtreecommitdiffstats
path: root/net/phonet/af_phonet.c
diff options
context:
space:
mode:
authorRemi Denis-Courmont <remi.denis-courmont@nokia.com>2008-09-22 23:05:19 -0400
committerDavid S. Miller <davem@davemloft.net>2008-09-22 23:05:19 -0400
commitba113a94b7503ee23ffe819e7045134b0c1d31de (patch)
treeb6236bbb36ffa311d7bc952066d2adc2b00c8d0c /net/phonet/af_phonet.c
parent8fb397406f6470f79040c41eec49af20900a9e3b (diff)
Phonet: common socket glue
This provides the socket API for the Phonet protocols family. Signed-off-by: Remi Denis-Courmont <remi.denis-courmont@nokia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/phonet/af_phonet.c')
-rw-r--r--net/phonet/af_phonet.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 5c729ba56939..ba54d53020ff 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -41,6 +41,8 @@ static inline void phonet_proto_put(struct phonet_protocol *pp);
41 41
42static int pn_socket_create(struct net *net, struct socket *sock, int protocol) 42static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
43{ 43{
44 struct sock *sk;
45 struct pn_sock *pn;
44 struct phonet_protocol *pnp; 46 struct phonet_protocol *pnp;
45 int err; 47 int err;
46 48
@@ -69,8 +71,22 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
69 goto out; 71 goto out;
70 } 72 }
71 73
72 /* TODO: create and init the struct sock */ 74 sk = sk_alloc(net, PF_PHONET, GFP_KERNEL, pnp->prot);
73 err = -EPROTONOSUPPORT; 75 if (sk == NULL) {
76 err = -ENOMEM;
77 goto out;
78 }
79
80 sock_init_data(sock, sk);
81 sock->state = SS_UNCONNECTED;
82 sock->ops = pnp->ops;
83 sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
84 sk->sk_protocol = protocol;
85 pn = pn_sk(sk);
86 pn->sobject = 0;
87 pn->resource = 0;
88 sk->sk_prot->init(sk);
89 err = 0;
74 90
75out: 91out:
76 phonet_proto_put(pnp); 92 phonet_proto_put(pnp);
@@ -94,6 +110,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
94 struct net_device *orig_dev) 110 struct net_device *orig_dev)
95{ 111{
96 struct phonethdr *ph; 112 struct phonethdr *ph;
113 struct sock *sk;
97 struct sockaddr_pn sa; 114 struct sockaddr_pn sa;
98 u16 len; 115 u16 len;
99 116
@@ -118,7 +135,12 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
118 if (pn_sockaddr_get_addr(&sa) == 0) 135 if (pn_sockaddr_get_addr(&sa) == 0)
119 goto out; /* currently, we cannot be device 0 */ 136 goto out; /* currently, we cannot be device 0 */
120 137
121 /* TODO: put packets to sockets backlog */ 138 sk = pn_find_sock_by_sa(&sa);
139 if (sk == NULL)
140 goto out;
141
142 /* Push data to the socket (or other sockets connected to it). */
143 return sk_receive_skb(sk, skb, 0);
122 144
123out: 145out:
124 kfree_skb(skb); 146 kfree_skb(skb);