summaryrefslogtreecommitdiff
path: root/net/phonet/af_phonet.c
diff options
context:
space:
mode:
authorRemi Denis-Courmont <remi.denis-courmont@nokia.com>2008-09-22 20:05:19 -0700
committerDavid S. Miller <davem@davemloft.net>2008-09-22 20:05:19 -0700
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);
static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
{
+ struct sock *sk;
+ struct pn_sock *pn;
struct phonet_protocol *pnp;
int err;
@@ -69,8 +71,22 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
goto out;
}
- /* TODO: create and init the struct sock */
- err = -EPROTONOSUPPORT;
+ sk = sk_alloc(net, PF_PHONET, GFP_KERNEL, pnp->prot);
+ if (sk == NULL) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ sock_init_data(sock, sk);
+ sock->state = SS_UNCONNECTED;
+ sock->ops = pnp->ops;
+ sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
+ sk->sk_protocol = protocol;
+ pn = pn_sk(sk);
+ pn->sobject = 0;
+ pn->resource = 0;
+ sk->sk_prot->init(sk);
+ err = 0;
out:
phonet_proto_put(pnp);
@@ -94,6 +110,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
struct net_device *orig_dev)
{
struct phonethdr *ph;
+ struct sock *sk;
struct sockaddr_pn sa;
u16 len;
@@ -118,7 +135,12 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
if (pn_sockaddr_get_addr(&sa) == 0)
goto out; /* currently, we cannot be device 0 */
- /* TODO: put packets to sockets backlog */
+ sk = pn_find_sock_by_sa(&sa);
+ if (sk == NULL)
+ goto out;
+
+ /* Push data to the socket (or other sockets connected to it). */
+ return sk_receive_skb(sk, skb, 0);
out:
kfree_skb(skb);