Bluetooth: Check if mode is supported on getsockopt
authorJoão Paulo Rechi Vita <jprvita@profusion.mobi>
Sat, 1 May 2010 19:15:42 +0000 (16:15 -0300)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 10 May 2010 07:28:51 +0000 (09:28 +0200)
Add this check to getsockopt makes possible to fail early instead of
waiting until listen / connect.

Signed-off-by: João Paulo Rechi Vita <jprvita@profusion.mobi>
Acked-by: Gustavo F. Padovan <padovan@profusion.mobi>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/l2cap.c

index 1a32562adf46a932b18ff333b7d237894382fc5a..bf5bb7dc6abf262c5530109f20a4b1fd92cdcbda 100644 (file)
@@ -1814,9 +1814,22 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
                        break;
                }
 
+               l2cap_pi(sk)->mode = opts.mode;
+               switch (l2cap_pi(sk)->mode) {
+               case L2CAP_MODE_BASIC:
+                       break;
+               case L2CAP_MODE_ERTM:
+               case L2CAP_MODE_STREAMING:
+                       if (enable_ertm)
+                               break;
+                       /* fall through */
+               default:
+                       err = -EINVAL;
+                       break;
+               }
+
                l2cap_pi(sk)->imtu = opts.imtu;
                l2cap_pi(sk)->omtu = opts.omtu;
-               l2cap_pi(sk)->mode = opts.mode;
                l2cap_pi(sk)->fcs  = opts.fcs;
                l2cap_pi(sk)->max_tx = opts.max_tx;
                l2cap_pi(sk)->tx_win = (__u8)opts.txwin_size;