Added BlueZ build scripts
[ti-bt/build-utils.git] / patches / 0001-blueti-Add-TI-Logger-dump.patch
1 From a5b2ddf6c5f5abe7739d4d37193d9a7afe4a5acf Mon Sep 17 00:00:00 2001\r
2 From: Chen Ganir <chen.ganir@ti.com>\r
3 Date: Tue, 5 Jun 2012 16:21:00 +0300\r
4 Subject: [PATCH] blueti: Add TI Logger dump\r
5 \r
6 Read HCI vendor events of TI chip logger, and dump to file.\r
7 ---\r
8  parser/parser.c |   15 +++++++++\r
9  parser/parser.h |    4 +++\r
10  src/hcidump.c   |   98 ++++++++++++++++++++++++++++++++++++++++---------------\r
11  3 files changed, 91 insertions(+), 26 deletions(-)\r
12 \r
13 diff --git a/parser/parser.c b/parser/parser.c\r
14 index 0f36ee7..fcf3ef0 100644\r
15 --- a/parser/parser.c\r
16 +++ b/parser/parser.c\r
17 @@ -317,6 +317,21 @@ void ext_dump(int level, struct frame *frm, int num)\r
18         }\r
19  }\r
20  \r
21 +void tilogger_dump(int level, struct frame *frm)\r
22 +{\r
23 +       unsigned char *buf = frm->ptr;\r
24 +       int num = frm->len;\r
25 +       uint8_t type = buf[0];\r
26 +       uint8_t vendor = buf[1];\r
27 +       uint8_t siz = buf[2];\r
28 +       uint16_t opc = buf[3]+(buf[4]<<8);\r
29 +       uint8_t* dat = buf[5];\r
30 +\r
31 +       printf ("%2.2X %2.2X %2.2X %2.2X %2.2X \n",type, vendor, siz, opc, dat);\r
32 +\r
33 +}\r
34 +\r
35 +\r
36  void raw_ndump(int level, struct frame *frm, int num)\r
37  {\r
38         if (!frm->len)\r
39 diff --git a/parser/parser.h b/parser/parser.h\r
40 index 1130a5f..9ba3380 100644\r
41 --- a/parser/parser.h\r
42 +++ b/parser/parser.h\r
43 @@ -63,6 +63,7 @@ struct frame {\r
44  #define DUMP_BTSNOOP   0x1000\r
45  #define DUMP_PKTLOG    0x2000\r
46  #define DUMP_NOVENDOR  0x4000\r
47 +#define DUMP_TILOGGER  0x8000\r
48  #define DUMP_TYPE_MASK (DUMP_ASCII | DUMP_HEX | DUMP_EXT)\r
49  \r
50  /* Parser filter */\r
51 @@ -225,6 +226,7 @@ void raw_ndump(int level, struct frame *frm, int num);\r
52  \r
53  void lmp_dump(int level, struct frame *frm);\r
54  void hci_dump(int level, struct frame *frm);\r
55 +void tilogger_dump(int level, struct frame *frm);\r
56  void l2cap_dump(int level, struct frame *frm);\r
57  void rfcomm_dump(int level, struct frame *frm);\r
58  void sdp_dump(int level, struct frame *frm);\r
59 @@ -253,6 +255,8 @@ static inline void parse(struct frame *frm)\r
60         p_indent(-1, NULL);\r
61         if (parser.flags & DUMP_RAW)\r
62                 raw_dump(0, frm);\r
63 +       else if (parser.flags & DUMP_TILOGGER)\r
64 +               tilogger_dump(0,frm);\r
65         else\r
66                 hci_dump(0, frm);\r
67         fflush(stdout);\r
68 diff --git a/src/hcidump.c b/src/hcidump.c\r
69 index 089d444..2a7e32a 100644\r
70 --- a/src/hcidump.c\r
71 +++ b/src/hcidump.c\r
72 @@ -110,6 +110,14 @@ struct pktlog_hdr {\r
73  } __attribute__ ((packed));\r
74  #define PKTLOG_HDR_SIZE (sizeof(struct pktlog_hdr))\r
75  \r
76 +struct tilogger_pkt {\r
77 +       uint8_t type;\r
78 +       uint8_t vendor;\r
79 +       uint8_t size;\r
80 +       uint16_t opcode;\r
81 +       uint8_t  data[0];       /* Packet Data */\r
82 +} __attribute__ ((packed));\r
83 +\r
84  static inline int read_n(int fd, char *buf, int len)\r
85  {\r
86         int t = 0, w;\r
87 @@ -156,6 +164,7 @@ static int process_frames(int dev, int sock, int fd, unsigned long flags)\r
88         int nfds = 0;\r
89         char *buf, *ctrl;\r
90         int len, hdr_size = HCIDUMP_HDR_SIZE;\r
91 +       struct tilogger_pkt *tp;\r
92  \r
93         if (sock < 0)\r
94                 return -1;\r
95 @@ -193,33 +202,35 @@ static int process_frames(int dev, int sock, int fd, unsigned long flags)\r
96         memset(&msg, 0, sizeof(msg));\r
97  \r
98         if (mode == SERVER) {\r
99 -               struct btsnoop_hdr *hdr = (void *) buf;\r
100 +               if (flags & DUMP_BTSNOOP) {\r
101 +                       struct btsnoop_hdr *hdr = (void *) buf;\r
102  \r
103 -               btsnoop_version = 1;\r
104 -               btsnoop_type = 1002;\r
105 +                       btsnoop_version = 1;\r
106 +                       btsnoop_type = 1002;\r
107  \r
108 -               memcpy(hdr->id, btsnoop_id, sizeof(btsnoop_id));\r
109 -               hdr->version = htonl(btsnoop_version);\r
110 -               hdr->type = htonl(btsnoop_type);\r
111 +                       memcpy(hdr->id, btsnoop_id, sizeof(btsnoop_id));\r
112 +                       hdr->version = htonl(btsnoop_version);\r
113 +                       hdr->type = htonl(btsnoop_type);\r
114  \r
115 -               printf("btsnoop version: %d datalink type: %d\n",\r
116 -                                               btsnoop_version, btsnoop_type);\r
117 +                       printf("btsnoop version: %d datalink type: %d\n",\r
118 +                                                       btsnoop_version, btsnoop_type);\r
119  \r
120 -               len = write(fd, buf, BTSNOOP_HDR_SIZE);\r
121 -               if (len < 0) {\r
122 -                       perror("Can't create dump header");\r
123 -                       return -1;\r
124 -               }\r
125 +                       len = write(fd, buf, BTSNOOP_HDR_SIZE);\r
126 +                       if (len < 0) {\r
127 +                               perror("Can't create dump header");\r
128 +                               return -1;\r
129 +                       }\r
130  \r
131 -               if (len != BTSNOOP_HDR_SIZE) {\r
132 -                       fprintf(stderr, "Header size mismatch\n");\r
133 -                       return -1;\r
134 -               }\r
135 +                       if (len != BTSNOOP_HDR_SIZE) {\r
136 +                               fprintf(stderr, "Header size mismatch\n");\r
137 +                               return -1;\r
138 +                       }\r
139  \r
140 -               fds[nfds].fd = fd;\r
141 -               fds[nfds].events = POLLIN;\r
142 -               fds[nfds].revents = 0;\r
143 -               nfds++;\r
144 +                       fds[nfds].fd = fd;\r
145 +                       fds[nfds].events = POLLIN;\r
146 +                       fds[nfds].revents = 0;\r
147 +                       nfds++;\r
148 +               }\r
149         }\r
150  \r
151         fds[nfds].fd = sock;\r
152 @@ -312,13 +323,39 @@ static int process_frames(int dev, int sock, int fd, unsigned long flags)\r
153                                 if (pkt_type == HCI_COMMAND_PKT ||\r
154                                                 pkt_type == HCI_EVENT_PKT)\r
155                                         dp->flags |= ntohl(0x02);\r
156 +                       } else if (flags & DUMP_TILOGGER) {\r
157 +                               tp = (void *)frm.ptr;\r
158 +                               if (tp->type == HCI_EVENT_PKT && tp->vendor == 0xFF && tp->opcode == 0x0400) {\r
159 +                                       uint8_t* data=frm.ptr;\r
160 +                                       printf ("frm.len=%2.2X pkt_type=%2.2X vendor=%2.2X opcode=%2.2X size=%2.2X \n",frm.len, tp->type, tp->vendor, tp->opcode, tp->size);\r
161 +                                       for (i = 0;i<tp->size && i<10;i++) {\r
162 +                                               printf("%2.2X ", data[i]);\r
163 +                                       }\r
164 +                                       printf("\n");\r
165 +                                       if (flags & DUMP_HEX) {\r
166 +                                               unsigned char out[2];\r
167 +                                               int i;\r
168 +                                               for(i=0;i<tp->size-2;i++) {\r
169 +                                                       sprintf(out,"%02X",tp->data[i]);\r
170 +                                                       if (write_n(fd, out, 2) < 0) {\r
171 +                                                               perror("Write error");\r
172 +                                                               return -1;\r
173 +                                                       }\r
174 +                                               }\r
175 +                                       } else { /* if no flags, dump raw */\r
176 +                                               if (write_n(fd, &tp->data[0], tp->size-2) < 0) {\r
177 +                                                       perror("Write error");\r
178 +                                                       return -1;\r
179 +                                               }\r
180 +                                       }\r
181 +                               }\r
182 +                               continue;\r
183                         } else {\r
184                                 dh->len = htobs(frm.data_len);\r
185                                 dh->in  = frm.in;\r
186                                 dh->ts_sec  = htobl(frm.ts.tv_sec);\r
187                                 dh->ts_usec = htobl(frm.ts.tv_usec);\r
188                         }\r
189 -\r
190                         if (write_n(fd, buf, frm.data_len + hdr_size) < 0) {\r
191                                 perror("Write error");\r
192                                 return -1;\r
193 @@ -854,6 +891,7 @@ static void usage(void)\r
194         "  -a, --ascii                Dump data in ascii\n"\r
195         "  -x, --hex                  Dump data in hex\n"\r
196         "  -X, --ext                  Dump data in hex and ascii\n"\r
197 +       "  -T, --tilogger             Dump tilogger data\n"\r
198         "  -R, --raw                  Dump raw data\n"\r
199         "  -C, --cmtp=psm             PSM for CMTP\n"\r
200         "  -H, --hcrp=psm             PSM for HCRP\n"\r
201 @@ -895,6 +933,7 @@ static struct option main_options[] = {\r
202         { "nopermcheck",        0, 0, 'Z' },\r
203         { "ipv4",               0, 0, '4' },\r
204         { "ipv6",               0, 0, '6' },\r
205 +       { "tilogger",   0, 0, 'T' },\r
206         { "help",               0, 0, 'h' },\r
207         { "version",            0, 0, 'v' },\r
208         { 0 }\r
209 @@ -911,7 +950,7 @@ int main(int argc, char *argv[])\r
210         uint16_t obex_port;\r
211  \r
212         while ((opt = getopt_long(argc, argv,\r
213 -                               "i:l:p:m:w:r:d:taxXRC:H:O:P:S:D:A:YZ46hv",\r
214 +                               "i:l:p:m:w:r:d:taxTXRC:H:O:P:S:D:A:YZ46hv",\r
215                                 main_options, NULL)) != -1) {\r
216                 switch(opt) {\r
217                 case 'i':\r
218 @@ -968,6 +1007,10 @@ int main(int argc, char *argv[])\r
219                         flags |= DUMP_RAW;\r
220                         break;\r
221  \r
222 +               case 'T':\r
223 +                       flags |= DUMP_TILOGGER;\r
224 +                       break;\r
225 +\r
226                 case 'C': \r
227                         set_proto(0, atoi(optarg), 0, SDP_UUID_CMTP);\r
228                         break;\r
229 @@ -1060,13 +1103,16 @@ int main(int argc, char *argv[])\r
230                 break;\r
231  \r
232         case WRITE:\r
233 -               flags |= DUMP_BTSNOOP;\r
234 +               if ((flags & DUMP_TILOGGER) == 0)\r
235 +                       flags |= DUMP_BTSNOOP;\r
236                 process_frames(device, open_socket(device, flags),\r
237 -                               open_file(dump_file, mode, flags), flags);\r
238 +               open_file(dump_file, mode, flags), flags);\r
239                 break;\r
240  \r
241         case SERVER:\r
242 -               flags |= DUMP_BTSNOOP;\r
243 +               if ((flags & DUMP_TILOGGER) == 0)\r
244 +                       flags |= DUMP_BTSNOOP;\r
245 +\r
246                 init_parser(flags, filter, defpsm, defcompid, pppdump_fd, audio_fd);\r
247                 run_server(device, dump_addr, dump_port, flags);\r
248                 break;\r
249 -- \r
250 1.7.9.5\r
251 \r