Commit b3d62553 authored by Kumar Sanghvi's avatar Kumar Sanghvi Committed by David S. Miller

Phonet: 'connect' socket implementation for Pipe controller

Based on suggestion by Rémi Denis-Courmont to implement 'connect'
for Pipe controller logic,  this patch implements 'connect' socket
call for the Pipe controller logic.
The patch does following:-
- Removes setsockopts for PNPIPE_CREATE and PNPIPE_DESTROY
- Adds setsockopt for setting the Pipe handle value
- Implements connect socket call
- Updates the Pipe controller logic

User-space should now follow below sequence with Pipe controller:-
-socket
-bind
-setsockopt for PNPIPE_PIPE_HANDLE
-connect
-setsockopt for PNPIPE_ENCAP_IP
-setsockopt for PNPIPE_ENABLE

GPRS/3G data has been tested working fine with this.
Signed-off-by: default avatarKumar Sanghvi <kumar.sanghvi@stericsson.com>
Acked-by: default avatarRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7368ddf1
...@@ -36,10 +36,9 @@ ...@@ -36,10 +36,9 @@
/* Socket options for SOL_PNPIPE level */ /* Socket options for SOL_PNPIPE level */
#define PNPIPE_ENCAP 1 #define PNPIPE_ENCAP 1
#define PNPIPE_IFINDEX 2 #define PNPIPE_IFINDEX 2
#define PNPIPE_CREATE 3 #define PNPIPE_PIPE_HANDLE 3
#define PNPIPE_ENABLE 4 #define PNPIPE_ENABLE 4
/* unused slot */ /* unused slot */
#define PNPIPE_DESTROY 6
#define PNADDR_ANY 0 #define PNADDR_ANY 0
#define PNADDR_BROADCAST 0xFC #define PNADDR_BROADCAST 0xFC
......
...@@ -46,8 +46,8 @@ struct pep_sock { ...@@ -46,8 +46,8 @@ struct pep_sock {
u8 init_enable; /* auto-enable at creation */ u8 init_enable; /* auto-enable at creation */
u8 aligned; u8 aligned;
#ifdef CONFIG_PHONET_PIPECTRLR #ifdef CONFIG_PHONET_PIPECTRLR
u16 remote_pep;
u8 pipe_state; u8 pipe_state;
struct sockaddr_pn remote_pep;
#endif #endif
}; };
......
This diff is collapsed.
...@@ -225,6 +225,101 @@ static int pn_socket_autobind(struct socket *sock) ...@@ -225,6 +225,101 @@ static int pn_socket_autobind(struct socket *sock)
return 0; /* socket was already bound */ return 0; /* socket was already bound */
} }
#ifdef CONFIG_PHONET_PIPECTRLR
static int pn_socket_connect(struct socket *sock, struct sockaddr *addr,
int len, int flags)
{
struct sock *sk = sock->sk;
struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
long timeo;
int err;
if (len < sizeof(struct sockaddr_pn))
return -EINVAL;
if (spn->spn_family != AF_PHONET)
return -EAFNOSUPPORT;
lock_sock(sk);
switch (sock->state) {
case SS_UNCONNECTED:
sk->sk_state = TCP_CLOSE;
break;
case SS_CONNECTING:
switch (sk->sk_state) {
case TCP_SYN_RECV:
sock->state = SS_CONNECTED;
err = -EISCONN;
goto out;
case TCP_CLOSE:
err = -EALREADY;
if (flags & O_NONBLOCK)
goto out;
goto wait_connect;
}
break;
case SS_CONNECTED:
switch (sk->sk_state) {
case TCP_SYN_RECV:
err = -EISCONN;
goto out;
case TCP_CLOSE:
sock->state = SS_UNCONNECTED;
break;
}
break;
case SS_DISCONNECTING:
case SS_FREE:
break;
}
sk->sk_state = TCP_CLOSE;
sk_stream_kill_queues(sk);
sock->state = SS_CONNECTING;
err = sk->sk_prot->connect(sk, addr, len);
if (err < 0) {
sock->state = SS_UNCONNECTED;
sk->sk_state = TCP_CLOSE;
goto out;
}
err = -EINPROGRESS;
wait_connect:
if (sk->sk_state != TCP_SYN_RECV && (flags & O_NONBLOCK))
goto out;
timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
release_sock(sk);
err = -ERESTARTSYS;
timeo = wait_event_interruptible_timeout(*sk_sleep(sk),
sk->sk_state != TCP_CLOSE,
timeo);
lock_sock(sk);
if (timeo < 0)
goto out; /* -ERESTARTSYS */
err = -ETIMEDOUT;
if (timeo == 0 && sk->sk_state != TCP_SYN_RECV)
goto out;
if (sk->sk_state != TCP_SYN_RECV) {
sock->state = SS_UNCONNECTED;
err = sock_error(sk);
if (!err)
err = -ECONNREFUSED;
goto out;
}
sock->state = SS_CONNECTED;
err = 0;
out:
release_sock(sk);
return err;
}
#endif
static int pn_socket_accept(struct socket *sock, struct socket *newsock, static int pn_socket_accept(struct socket *sock, struct socket *newsock,
int flags) int flags)
{ {
...@@ -393,7 +488,11 @@ const struct proto_ops phonet_stream_ops = { ...@@ -393,7 +488,11 @@ const struct proto_ops phonet_stream_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.release = pn_socket_release, .release = pn_socket_release,
.bind = pn_socket_bind, .bind = pn_socket_bind,
#ifdef CONFIG_PHONET_PIPECTRLR
.connect = pn_socket_connect,
#else
.connect = sock_no_connect, .connect = sock_no_connect,
#endif
.socketpair = sock_no_socketpair, .socketpair = sock_no_socketpair,
.accept = pn_socket_accept, .accept = pn_socket_accept,
.getname = pn_socket_getname, .getname = pn_socket_getname,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment