Skip to content

Commit 114f9f1

Browse files
Johan Hedbergholtmann
authored andcommitted
Bluetooth: L2CAP: Introduce proper defines for PSM ranges
Having proper defines makes the code a bit readable, it also avoids duplicating hard-coded values since these are also needed when auto-allocating PSM values (in a subsequent patch). Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent d10d34a commit 114f9f1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/net/bluetooth/l2cap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ struct l2cap_conn_rsp {
252252
#define L2CAP_PSM_3DSP 0x0021
253253
#define L2CAP_PSM_IPSP 0x0023 /* 6LoWPAN */
254254

255+
#define L2CAP_PSM_DYN_START 0x1001
256+
#define L2CAP_PSM_DYN_END 0xffff
257+
#define L2CAP_PSM_AUTO_END 0x10ff
258+
#define L2CAP_PSM_LE_DYN_START 0x0080
259+
#define L2CAP_PSM_LE_DYN_END 0x00ff
260+
255261
/* channel identifier */
256262
#define L2CAP_CID_SIGNALING 0x0001
257263
#define L2CAP_CID_CONN_LESS 0x0002

net/bluetooth/l2cap_sock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int l2cap_validate_bredr_psm(u16 psm)
5858
return -EINVAL;
5959

6060
/* Restrict usage of well-known PSMs */
61-
if (psm < 0x1001 && !capable(CAP_NET_BIND_SERVICE))
61+
if (psm < L2CAP_PSM_DYN_START && !capable(CAP_NET_BIND_SERVICE))
6262
return -EACCES;
6363

6464
return 0;
@@ -67,11 +67,11 @@ static int l2cap_validate_bredr_psm(u16 psm)
6767
static int l2cap_validate_le_psm(u16 psm)
6868
{
6969
/* Valid LE_PSM ranges are defined only until 0x00ff */
70-
if (psm > 0x00ff)
70+
if (psm > L2CAP_PSM_LE_DYN_END)
7171
return -EINVAL;
7272

7373
/* Restrict fixed, SIG assigned PSM values to CAP_NET_BIND_SERVICE */
74-
if (psm <= 0x007f && !capable(CAP_NET_BIND_SERVICE))
74+
if (psm < L2CAP_PSM_LE_DYN_START && !capable(CAP_NET_BIND_SERVICE))
7575
return -EACCES;
7676

7777
return 0;

0 commit comments

Comments
 (0)