summaryrefslogtreecommitdiff
path: root/monitor/l2cap.c
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@tieto.com>2015-02-18 22:46:31 +0100
committerJohan Hedberg <johan.hedberg@intel.com>2015-02-19 10:17:53 +0200
commit3f4d92e9e45c697ed1bac5cc3551bfa6085c5cbe (patch)
tree85754201be018d052421c6d6ecd126e071e4a9a2 /monitor/l2cap.c
parentccea880efd748a62c210702e612264c171505978 (diff)
downloadbluez-3f4d92e9e45c697ed1bac5cc3551bfa6085c5cbe.tar.gz
monitor: Factor out channel selection to separate function
This allows to have conditions check in single place.
Diffstat (limited to 'monitor/l2cap.c')
-rw-r--r--monitor/l2cap.c85
1 files changed, 25 insertions, 60 deletions
diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index 0030a4c6e..342bd8e7b 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -223,7 +223,7 @@ static void assign_mode(const struct l2cap_frame *frame,
}
}
-static uint16_t get_psm(const struct l2cap_frame *frame)
+static int get_chan_data_index(const struct l2cap_frame *frame)
{
int i;
@@ -238,64 +238,44 @@ static uint16_t get_psm(const struct l2cap_frame *frame)
if (frame->in) {
if (chan_list[i].scid == frame->cid)
- return chan_list[i].psm;
+ return i;
} else {
if (chan_list[i].dcid == frame->cid)
- return chan_list[i].psm;
+ return i;
}
}
- return 0;
+ return -1;
}
-static uint8_t get_mode(const struct l2cap_frame *frame)
+static uint16_t get_psm(const struct l2cap_frame *frame)
{
- int i;
+ int i = get_chan_data_index(frame);
- for (i = 0; i < MAX_CHAN; i++) {
- if (chan_list[i].index != frame->index &&
- chan_list[i].ctrlid == 0)
- continue;
+ if (i < 0)
+ return 0;
- if (chan_list[i].handle != frame->handle &&
- chan_list[i].ctrlid != frame->index)
- continue;
+ return chan_list[i].psm;
+}
- if (frame->in) {
- if (chan_list[i].scid == frame->cid)
- return chan_list[i].mode;
- } else {
- if (chan_list[i].dcid == frame->cid)
- return chan_list[i].mode;
- }
- }
+static uint8_t get_mode(const struct l2cap_frame *frame)
+{
+ int i = get_chan_data_index(frame);
+
+ if (i < 0)
+ return 0;
- return 0;
+ return chan_list[i].mode;
}
static uint16_t get_chan(const struct l2cap_frame *frame)
{
- int i;
-
- for (i = 0; i < MAX_CHAN; i++) {
- if (chan_list[i].index != frame->index &&
- chan_list[i].ctrlid == 0)
- continue;
+ int i = get_chan_data_index(frame);
- if (chan_list[i].handle != frame->handle &&
- chan_list[i].ctrlid != frame->index)
- continue;
-
- if (frame->in) {
- if (chan_list[i].scid == frame->cid)
- return i;
- } else {
- if (chan_list[i].dcid == frame->cid)
- return i;
- }
- }
+ if (i < 0)
+ return 0;
- return 0;
+ return i;
}
static void assign_ext_ctrl(const struct l2cap_frame *frame,
@@ -326,27 +306,12 @@ static void assign_ext_ctrl(const struct l2cap_frame *frame,
static uint8_t get_ext_ctrl(const struct l2cap_frame *frame)
{
- int i;
+ int i = get_chan_data_index(frame);
- for (i = 0; i < MAX_CHAN; i++) {
- if (chan_list[i].index != frame->index &&
- chan_list[i].ctrlid == 0)
- continue;
-
- if (chan_list[i].handle != frame->handle &&
- chan_list[i].ctrlid != frame->index)
- continue;
-
- if (frame->in) {
- if (chan_list[i].scid == frame->cid)
- return chan_list[i].ext_ctrl;
- } else {
- if (chan_list[i].dcid == frame->cid)
- return chan_list[i].ext_ctrl;
- }
- }
+ if (i < 0)
+ return 0;
- return 0;
+ return chan_list[i].ext_ctrl;
}
static char *sar2str(uint8_t sar)