Fix btsnoop crash when handling btmon 29/118229/1
authorSeungyoun Ju <sy39.ju@samsung.com>
Wed, 8 Mar 2017 07:28:52 +0000 (16:28 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Thu, 9 Mar 2017 08:44:12 +0000 (17:44 +0900)
[Model] Solis
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] btsnoop is crashed since new kernel is introduced because it
 brings new opcode.
[Cause & Measure] it should be skipped properly to make compatible btnsoop.
[Checking Method] Build and verification on target

[Team] System Connectivity
[Developer] Chanyeol Park
[Solution company] Samsung
[Change Type] Specification change

Change-Id: I245dbb1bedbab99e5a5e05289b42353ba76195b6

tools/btsnoop.c
tools/hcidump.c

index 06bc9d5..a9b7f3c 100644 (file)
@@ -277,6 +277,7 @@ close_input:
 }
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 #define BT_SNOOP_TYPE_HCI_PREFIX "btsnoop_type_hci"
+#define MAX_SUPPORTED_ADAPTER  16
 
 static void command_split(const char *input)
 {
@@ -287,7 +288,7 @@ static void command_split(const char *input)
        uint16_t index, max_index = 0;
        char write_file_name[255];
        struct btsnoop *btsnoop_read_file = NULL;
-       struct btsnoop *btsnoop_write_file[16];
+       struct btsnoop *btsnoop_write_file[MAX_SUPPORTED_ADAPTER] = { NULL };
        time_t t;
        struct tm tm;
        unsigned long num_packets = 0;
@@ -308,7 +309,7 @@ next_packet:
                                                                &pktlen))
                goto close_files;
 
-       if (opcode == 0xffff)
+       if (opcode == 0xffff || index >= MAX_SUPPORTED_ADAPTER)
                goto next_packet;
 
        switch (opcode) {
@@ -338,7 +339,13 @@ next_packet:
                btsnoop_unref(btsnoop_write_file[index]);
                btsnoop_write_file[index] = NULL;
                break;
-       default:
+
+       case BTSNOOP_OPCODE_COMMAND_PKT:
+       case BTSNOOP_OPCODE_EVENT_PKT:
+       case BTSNOOP_OPCODE_ACL_TX_PKT:
+       case BTSNOOP_OPCODE_ACL_RX_PKT:
+       case BTSNOOP_OPCODE_SCO_TX_PKT:
+       case BTSNOOP_OPCODE_SCO_RX_PKT:
                if (!btsnoop_write_file[index]) {
                        t = tv.tv_sec;
                        localtime_r(&t, &tm);
@@ -363,6 +370,8 @@ next_packet:
                btsnoop_write_hci(btsnoop_write_file[index], &tv, index,
                                                        opcode, buf, pktlen);
                break;
+       default:
+               printf("skip btmon opcode(%d)\n",opcode);
        }
        num_packets++;
 
index af8f592..ffb7499 100644 (file)
@@ -399,8 +399,10 @@ static void read_dump(int fd)
 
                if (err < 0)
                        goto failed;
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
                if (!err)
                        goto done;
+#endif
 
                frm.ptr = frm.data;
                frm.len = frm.data_len;