3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2002-2011 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
44 static void add_segment(uint8_t bid, struct frame *frm, int len)
46 uint16_t handle = frm->handle, cid = frm->cid;
54 for (i = 0; i < TABLE_SIZE; i++) {
55 if (table[i].handle == handle && table[i].cid == cid) {
60 if (pos < 0 && !table[i].handle && !table[i].cid)
67 table[pos].handle = handle;
69 msg = &table[pos].msg[bid];
71 data = malloc(msg->data_len + len);
75 if (msg->data_len > 0)
76 memcpy(data, msg->data, msg->data_len);
78 memcpy(data + msg->data_len, frm->ptr, len);
83 msg->len = msg->data_len;
90 static void free_segment(uint8_t bid, struct frame *frm)
92 uint16_t handle = frm->handle, cid = frm->cid;
94 int i, len = 0, pos = -1;
99 for (i = 0; i < TABLE_SIZE; i++)
100 if (table[i].handle == handle && table[i].cid == cid) {
108 msg = &table[pos].msg[bid];
116 for (i = 0; i < 16; i++)
117 len += table[pos].msg[i].data_len;
120 table[pos].handle = 0;
125 static struct frame *get_segment(uint8_t bid, struct frame *frm)
127 uint16_t handle = frm->handle, cid = frm->cid;
133 for (i = 0; i < TABLE_SIZE; i++)
134 if (table[i].handle == handle && table[i].cid == cid)
135 return &table[i].msg[bid];
140 static char *bst2str(uint8_t bst)
144 return "complete CAPI Message";
146 return "segmented CAPI Message";
156 void cmtp_dump(int level, struct frame *frm)
162 while (frm->len > 0) {
165 bid = (hdr & 0x3c) >> 2;
167 switch ((hdr & 0xc0) >> 6) {
172 len = htons(get_u16(frm));
179 p_indent(level, frm);
181 printf("CMTP: %s: id %d len %d\n", bst2str(hdr & 0x03), bid, len);
183 switch (hdr & 0x03) {
185 add_segment(bid, frm, len);
186 msg = get_segment(bid, frm);
190 if (!p_filter(FILT_CAPI))
191 capi_dump(level + 1, msg);
193 raw_dump(level, msg);
195 free_segment(bid, frm);
198 add_segment(bid, frm, len);
201 free_segment(bid, frm);