From 2285b7430ac652bff0d3c0d43a76fba3af1c56f0 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 23 Apr 2005 23:25:39 +0000 Subject: [PATCH] hcidump: Clear L2CAP states when receiving the HCI disconnect event --- tools/parser/hci.c | 5 +++++ tools/parser/l2cap.c | 46 ++++++++++++++++++++++++++++++++----------- tools/parser/parser.h | 2 ++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/tools/parser/hci.c b/tools/parser/hci.c index de27132e6..285215d71 100644 --- a/tools/parser/hci.c +++ b/tools/parser/hci.c @@ -2034,6 +2034,11 @@ static inline void event_dump(int level, struct frame *frm) } } + if (event == EVT_DISCONN_COMPLETE) { + evt_disconn_complete *evt = frm->ptr; + l2cap_clear(btohs(evt->handle)); + } + if (!(parser.flags & DUMP_VERBOSE)) { raw_dump(level, frm); return; diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c index f92a2e1e0..c3a0e95f2 100644 --- a/tools/parser/l2cap.c +++ b/tools/parser/l2cap.c @@ -50,6 +50,7 @@ typedef struct { static handle_info handle_table[HANDLE_TABLE_SIZE]; typedef struct { + uint16_t handle; uint16_t cid; uint16_t psm; uint16_t num; @@ -87,7 +88,7 @@ static struct frame *get_frame(uint16_t handle) return add_handle(handle); } -static void add_cid(int in, uint16_t cid, uint16_t psm) +static void add_cid(int in, uint16_t handle, uint16_t cid, uint16_t psm) { register cid_info *table = cid_table[in]; register int i, pos = -1; @@ -101,10 +102,11 @@ static void add_cid(int in, uint16_t cid, uint16_t psm) } if (pos >= 0) { - table[pos].cid = cid; - table[pos].psm = psm; - table[pos].num = num; - table[pos].mode = 0; + table[pos].handle = handle; + table[pos].cid = cid; + table[pos].psm = psm; + table[pos].num = num; + table[pos].mode = 0; } } @@ -124,15 +126,32 @@ static void del_cid(int in, uint16_t dcid, uint16_t scid) for (t = 0; t < 2; t++) { for (i = 0; i < CID_TABLE_SIZE; i++) if (cid_table[t][i].cid == cid[t]) { - cid_table[t][i].cid = 0; - cid_table[t][i].psm = 0; - cid_table[t][i].num = 0; - cid_table[t][i].mode = 0; + cid_table[t][i].handle = 0; + cid_table[t][i].cid = 0; + cid_table[t][i].psm = 0; + cid_table[t][i].num = 0; + cid_table[t][i].mode = 0; break; } } } +static void del_handle(uint16_t handle) +{ + register int t, i; + + for (t = 0; t < 2; t++) { + for (i = 0; i < CID_TABLE_SIZE; i++) + if (cid_table[t][i].handle == handle) { + cid_table[t][i].handle = 0; + cid_table[t][i].cid = 0; + cid_table[t][i].psm = 0; + cid_table[t][i].num = 0; + cid_table[t][i].mode = 0; + break; + } + } +} static uint16_t get_psm(int in, uint16_t cid) { register cid_info *table = cid_table[in]; @@ -353,7 +372,7 @@ static inline void conn_req(int level, struct frame *frm) uint16_t psm = btohs(h->psm); uint16_t scid = btohs(h->scid); - add_cid(frm->in, scid, psm); + add_cid(frm->in, frm->handle, scid, psm); if (p_filter(FILT_L2CAP)) return; @@ -373,7 +392,7 @@ static inline void conn_rsp(int level, struct frame *frm) switch (h->result) { case L2CAP_CR_SUCCESS: if ((psm = get_psm(!frm->in, scid))) - add_cid(frm->in, dcid, psm); + add_cid(frm->in, frm->handle, dcid, psm); break; case L2CAP_CR_PEND: @@ -880,3 +899,8 @@ void l2cap_dump(int level, struct frame *frm) } } } + +void l2cap_clear(uint16_t handle) +{ + del_handle(handle); +} diff --git a/tools/parser/parser.h b/tools/parser/parser.h index ef0cdb1df..96feee507 100644 --- a/tools/parser/parser.h +++ b/tools/parser/parser.h @@ -169,6 +169,8 @@ char *get_uuid_name(int uuid); void set_proto(uint16_t handle, uint16_t psm, uint8_t channel, uint32_t proto); uint32_t get_proto(uint16_t handle, uint16_t psm, uint8_t channel); +void l2cap_clear(uint16_t handle); + void ascii_dump(int level, struct frame *frm, int num); void hex_dump(int level, struct frame *frm, int num); void ext_dump(int level, struct frame *frm, int num); -- 2.47.3