Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09ce7758 authored by Jakub Rotkiewicz's avatar Jakub Rotkiewicz
Browse files

snoop_logger: fix acl and pdu length while filtering hfp packet

Bug: 329809288
Flag: EXEMPT - no logical change
Test: atest SnoopLoggerModuleTest
Change-Id: Ie93df09c9262ca4e8617d5f74389c9f2d38a3576
parent faba66e4
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -725,21 +725,30 @@ uint32_t SnoopLogger::PayloadStrip(profile_type_t current_profile, uint8_t* pack

uint32_t SnoopLogger::FilterProfilesHandleHfp(uint8_t* packet, uint32_t length, uint32_t totlen,
                                              uint32_t offset) {
  if ((totlen - offset) > cpbr_pat_len) {
    if (memcmp(&packet[offset], cpbr_pattern, cpbr_pat_len) == 0) {
  // CPBR packet
  if ((totlen - offset) > cpbr_pat_len &&
      memcmp(&packet[offset], cpbr_pattern, cpbr_pat_len) == 0) {
    length = offset + cpbr_pat_len + 1;
      packet[L2CAP_PDU_LENGTH_OFFSET] = offset + cpbr_pat_len - BASIC_L2CAP_HEADER_LENGTH;
    packet[ACL_LENGTH_OFFSET] = offset + cpbr_pat_len - BASIC_L2CAP_HEADER_LENGTH;
    packet[ACL_LENGTH_OFFSET + 1] = (offset + cpbr_pat_len - BASIC_L2CAP_HEADER_LENGTH) >> 8;

    packet[L2CAP_PDU_LENGTH_OFFSET] =
            offset + cpbr_pat_len - (ACL_HEADER_LENGTH + BASIC_L2CAP_HEADER_LENGTH);
    packet[L2CAP_PDU_LENGTH_OFFSET + 1] =
            (offset + cpbr_pat_len - (ACL_HEADER_LENGTH + BASIC_L2CAP_HEADER_LENGTH)) >> 8;
    return length;
  }

    if (memcmp(&packet[offset], clcc_pattern, clcc_pat_len) == 0) {
  // CLCC packet
  if ((totlen - offset) > clcc_pat_len &&
      memcmp(&packet[offset], clcc_pattern, clcc_pat_len) == 0) {
    length = offset + cpbr_pat_len + 1;
      packet[L2CAP_PDU_LENGTH_OFFSET] = offset + clcc_pat_len - BASIC_L2CAP_HEADER_LENGTH;
    packet[ACL_LENGTH_OFFSET] = offset + clcc_pat_len - BASIC_L2CAP_HEADER_LENGTH;
    packet[ACL_LENGTH_OFFSET + 1] = (offset + clcc_pat_len - BASIC_L2CAP_HEADER_LENGTH) >> 8;

    packet[L2CAP_PDU_LENGTH_OFFSET] =
            offset + clcc_pat_len - (ACL_HEADER_LENGTH + BASIC_L2CAP_HEADER_LENGTH);
    }
    packet[L2CAP_PDU_LENGTH_OFFSET + 1] =
            (offset + clcc_pat_len - (ACL_HEADER_LENGTH + BASIC_L2CAP_HEADER_LENGTH)) >> 8;
  }

  return length;
+14 −10
Original line number Diff line number Diff line
@@ -1392,7 +1392,7 @@ TEST_F(SnoopLoggerModuleTest, custom_socket_profiles_filtered_hfp_hf_test) {
  uint16_t conn_handle = 0x000b;
  uint16_t local_cid = 0x0043;
  uint16_t remote_cid = 0x3040;
  uint8_t dlci = 0x06;
  uint8_t dlci = 0x02;
  uint16_t psm = 0x0003;
  uint16_t profile_uuid_hfp_hf = 0x111f;
  bool flow = true;
@@ -1400,18 +1400,22 @@ TEST_F(SnoopLoggerModuleTest, custom_socket_profiles_filtered_hfp_hf_test) {
  const uint16_t HEADER_SIZE = 12;
  size_t expected_data_size = HEADER_SIZE + strlen(clcc_pattern.c_str());
  std::vector<uint8_t> kPhoneNumber = {
          0x0b, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x40, 0x30, 0x19, 0xff, 0x4f, 0x01, 0x0d,
          0x0a, 0x2b, 0x43, 0x4c, 0x43, 0x43, 0x3a, 0x20, 0x31, 0x2c, 0x31, 0x2c, 0x34,
          0x2c, 0x30, 0x2c, 0x30, 0x2c, 0x22, 0x2b, 0x39, 0x39, 0x31, 0x32, 0x33, 0x34,
          0x35, 0x36, 0x37, 0x38, 0x39, 0x22, 0x2c, 0x31, 0x34, 0x35, 0x0d, 0x0a, 0x49,
          0x0b, 0x00, 0x30, 0x00,  // ACL Header (Handle: 0x000b, PB flag: 0x00, Length: 48)
          0x2c, 0x00, 0x40, 0x30,  // L2CAP Header (Length: 44, CID: 0x3040)
          0x0b, 0xff, 0x4f, 0x01,  // RFCOMM
          // "\r\n+CLCC: 1,1,4,0,0,"+99123456789",145\r\n"
          0x0d, 0x0a, 0x2b, 0x43, 0x4c, 0x43, 0x43, 0x3a, 0x20, 0x31, 0x2c, 0x31, 0x2c, 0x34, 0x2c,
          0x30, 0x2c, 0x30, 0x2c, 0x22, 0x2b, 0x39, 0x39, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
          0x38, 0x39, 0x22, 0x2c, 0x31, 0x34, 0x35, 0x0d, 0x0a,
          0x86  // RFCOMM
  };

  std::vector<uint8_t> kExpectedPhoneNumber = {
          0x0b, 0x00, 0x30, 0x00, 0x0c, 0x00, 0x40, 0x30, 0x19, 0xff, 0x4f, 0x01, 0x0d,
          0x0a, 0x2b, 0x43, 0x4c, 0x43, 0x43, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  };
          0x0b, 0x00, 0x10, 0x00,  // ACL Header (Handle: 0x000b, PB flag: 0x00, Length: 16)
          0x0c, 0x00, 0x40, 0x30,  // L2CAP Header (Length: 12, CID: 0x3040)
          0x0b, 0xff, 0x4f, 0x01,  // RFCOMM
          // "\r\n+CLCC:"
          0x0d, 0x0a, 0x2b, 0x43, 0x4c, 0x43, 0x43, 0x3a};

  // Set pbap and map filtering modes
  ASSERT_TRUE(