Phonet: cleanup pipe enable socket option

The current code works like this:

  int garbage, status;
  socklen_t len = sizeof(status);

  /* enable pipe */
  setsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &garbage, sizeof(garbage));
  /* disable pipe */
  setsockopt(fd, SOL_PNPIPE, PNPIPE_DISABLE, &garbage, sizeof(garbage));
  /* get status */
  getsockopt(fd, SOL_PNPIPE, PNPIPE_INQ, &status, &len);

...which does not follow the usual socket option pattern. This patch
merges all three "options" into a single gettable&settable option,
before Linux 2.6.37 gets out:

  int status;
  socklen_t len = sizeof(status);

  /* enable pipe */
  status = 1;
  setsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &status, sizeof(status));
  /* disable pipe */
  status = 0;
  setsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &status, sizeof(status));
  /* get status */
  getsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &status, &len);

This also fixes the error code from EFAULT to ENOTCONN.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Cc: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Rémi Denis-Courmont 2010-10-08 04:02:02 +00:00 committed by David S. Miller
parent 6d8e74ed37
commit 03789f2672
3 changed files with 34 additions and 56 deletions

View file

@ -213,12 +213,9 @@ The implementation adds socket options at SOL_PNPIPE level:
It then updates the pipe state associated with the sequenced socket to It then updates the pipe state associated with the sequenced socket to
be PIPE_DISABLED. be PIPE_DISABLED.
PNPIPE_ENABLE PNPIPE_ENABLE accepts one integer value (int). If set to zero, the pipe
It follows the same sequence as above for enabling a pipe by sending is disabled. If the value is non-zero, the pipe is enabled. If the pipe
PNS_PEP_ENABLE_REQ initially and then sending PNS_PEP_ENABLED_IND after is not (yet) connected, ENOTCONN is error is returned.
getting responses from sequenced socket and remote-pep.
It will also update the pipe state associated with the sequenced socket
to PIPE_ENABLED.
PNPIPE_DESTROY PNPIPE_DESTROY
This will send out PNS_PEP_DISCONNECT_REQ on the sequenced socket and This will send out PNS_PEP_DISCONNECT_REQ on the sequenced socket and
@ -226,12 +223,6 @@ The implementation adds socket options at SOL_PNPIPE level:
It will also update the pipe state associated with the sequenced socket It will also update the pipe state associated with the sequenced socket
to PIPE_IDLE to PIPE_IDLE
PNPIPE_INQ
This getsocktopt allows the user-space running on the sequenced socket
to examine the pipe state associated with that socket ie. whether the
pipe is created (PIPE_DISABLED) or enabled (PIPE_ENABLED) or disabled
(PIPE_DISABLED) or no pipe exists (PIPE_IDLE).
After a pipe has been created and enabled successfully, the Pipe data can be After a pipe has been created and enabled successfully, the Pipe data can be
exchanged between the host-pep and remote-pep (modem). exchanged between the host-pep and remote-pep (modem).

View file

@ -38,9 +38,8 @@
#define PNPIPE_IFINDEX 2 #define PNPIPE_IFINDEX 2
#define PNPIPE_CREATE 3 #define PNPIPE_CREATE 3
#define PNPIPE_ENABLE 4 #define PNPIPE_ENABLE 4
#define PNPIPE_DISABLE 5 /* unused slot */
#define PNPIPE_DESTROY 6 #define PNPIPE_DESTROY 6
#define PNPIPE_INQ 7
#define PNADDR_ANY 0 #define PNADDR_ANY 0
#define PNADDR_BROADCAST 0xFC #define PNADDR_BROADCAST 0xFC

View file

@ -327,29 +327,20 @@ static int pipe_handler_send_ind(struct sock *sk, u16 dobj, u8 utid,
return pn_skb_send(sk, skb, &spn); return pn_skb_send(sk, skb, &spn);
} }
static int pipe_handler_enable_pipe(struct sock *sk, int cmd) static int pipe_handler_enable_pipe(struct sock *sk, int enable)
{ {
int ret;
struct pep_sock *pn = pep_sk(sk); struct pep_sock *pn = pep_sk(sk);
int utid, req;
switch (cmd) { if (enable) {
case PNPIPE_ENABLE: utid = PNS_PIPE_ENABLE_UTID;
ret = pipe_handler_send_req(sk, pn->pn_sk.sobject, req = PNS_PEP_ENABLE_REQ;
PNS_PIPE_ENABLE_UTID, PNS_PEP_ENABLE_REQ, } else {
pn->pipe_handle, GFP_ATOMIC); utid = PNS_PIPE_DISABLE_UTID;
break; req = PNS_PEP_DISABLE_REQ;
case PNPIPE_DISABLE:
ret = pipe_handler_send_req(sk, pn->pn_sk.sobject,
PNS_PIPE_DISABLE_UTID, PNS_PEP_DISABLE_REQ,
pn->pipe_handle, GFP_ATOMIC);
break;
default:
ret = -EINVAL;
} }
return pipe_handler_send_req(sk, pn->pn_sk.sobject, utid, req,
return ret; pn->pipe_handle, GFP_ATOMIC);
} }
static int pipe_handler_create_pipe(struct sock *sk, int pipe_handle, int cmd) static int pipe_handler_create_pipe(struct sock *sk, int pipe_handle, int cmd)
@ -1187,23 +1178,6 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
break; break;
} }
case PNPIPE_ENABLE:
if (pn->pipe_state != PIPE_DISABLED) {
err = -EFAULT;
break;
}
err = pipe_handler_enable_pipe(sk, PNPIPE_ENABLE);
break;
case PNPIPE_DISABLE:
if (pn->pipe_state != PIPE_ENABLED) {
err = -EFAULT;
break;
}
err = pipe_handler_enable_pipe(sk, PNPIPE_DISABLE);
break;
case PNPIPE_DESTROY: case PNPIPE_DESTROY:
if (pn->pipe_state < PIPE_DISABLED) { if (pn->pipe_state < PIPE_DISABLED) {
err = -EFAULT; err = -EFAULT;
@ -1239,6 +1213,17 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
err = 0; err = 0;
} }
goto out_norel; goto out_norel;
#ifdef CONFIG_PHONET_PIPECTRLR
case PNPIPE_ENABLE:
if (pn->pipe_state <= PIPE_IDLE) {
err = -ENOTCONN;
break;
}
err = pipe_handler_enable_pipe(sk, val);
break;
#endif
default: default:
err = -ENOPROTOOPT; err = -ENOPROTOOPT;
} }
@ -1264,15 +1249,18 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE; val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE;
break; break;
#ifdef CONFIG_PHONET_PIPECTRLR
case PNPIPE_INQ:
val = pn->pipe_state;
break;
#endif
case PNPIPE_IFINDEX: case PNPIPE_IFINDEX:
val = pn->ifindex; val = pn->ifindex;
break; break;
#ifdef CONFIG_PHONET_PIPECTRLR
case PNPIPE_ENABLE:
if (pn->pipe_state <= PIPE_IDLE)
return -ENOTCONN;
val = pn->pipe_state != PIPE_DISABLED;
break;
#endif
default: default:
return -ENOPROTOOPT; return -ENOPROTOOPT;
} }