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

Commit afd7152a authored by Myles Watson's avatar Myles Watson Committed by Automerger Merge Worker
Browse files

Merge "bnep: Pass addresses using const references" into main am: 797e2e89

parents 06d8dbaf 797e2e89
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -326,9 +326,9 @@ tBNEP_RESULT BNEP_Disconnect(uint16_t handle) {
 *                  BNEP_SUCCESS            - If written successfully
 *
 ******************************************************************************/
tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& dest_addr,
                           BT_HDR* p_buf, uint16_t protocol,
                           const RawAddress* p_src_addr, bool fw_ext_present) {
                           const RawAddress& src_addr, bool fw_ext_present) {
  tBNEP_CONN* p_bcb;
  uint8_t* p_data;

@@ -348,8 +348,8 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,

  /* Check if the packet should be filtered out */
  p_data = (uint8_t*)(p_buf + 1) + p_buf->offset;
  if (bnep_is_packet_allowed(p_bcb, p_dest_addr, protocol, fw_ext_present,
                             p_data, p_buf->len) != BNEP_SUCCESS) {
  if (bnep_is_packet_allowed(p_bcb, dest_addr, protocol, fw_ext_present, p_data,
                             p_buf->len) != BNEP_SUCCESS) {
    /*
    ** If packet is filtered and ext headers are present
    ** drop the data and forward the ext headers
@@ -404,7 +404,7 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
  }

  /* Build the BNEP header */
  bnepu_build_bnep_hdr(p_bcb, p_buf, protocol, p_src_addr, &p_dest_addr,
  bnepu_build_bnep_hdr(p_bcb, p_buf, protocol, src_addr, dest_addr,
                       fw_ext_present);

  /* Send the data or queue it up */
@@ -420,12 +420,12 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
 * Description      This function sends data over a BNEP connection
 *
 * Parameters:      handle       - handle of the connection to write
 *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
 *                  dest_addr    - BD_ADDR/Ethernet addr of the destination
 *                  p_data       - pointer to data start
 *                  protocol     - protocol type of the packet
 *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
 *                  src_addr     - (optional) BD_ADDR/ethernet address of the
 *                                 source
 *                                 (should be NULL if it is local BD Addr)
 *                                 (should be kEmpty if it is local BD Addr)
 *                  fw_ext_present - forwarded extensions present
 *
 * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
@@ -437,9 +437,9 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
 *                  BNEP_SUCCESS            - If written successfully
 *
 ******************************************************************************/
tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& dest_addr,
                        uint8_t* p_data, uint16_t len, uint16_t protocol,
                        const RawAddress* p_src_addr, bool fw_ext_present) {
                        const RawAddress& src_addr, bool fw_ext_present) {
  tBNEP_CONN* p_bcb;
  uint8_t* p;

@@ -454,8 +454,8 @@ tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
  p_bcb = &(bnep_cb.bcb[handle - 1]);

  /* Check if the packet should be filtered out */
  if (bnep_is_packet_allowed(p_bcb, p_dest_addr, protocol, fw_ext_present,
                             p_data, len) != BNEP_SUCCESS) {
  if (bnep_is_packet_allowed(p_bcb, dest_addr, protocol, fw_ext_present, p_data,
                             len) != BNEP_SUCCESS) {
    /*
    ** If packet is filtered and ext headers are present
    ** drop the data and forward the ext headers
@@ -510,7 +510,7 @@ tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
  memcpy(p, p_data, len);

  /* Build the BNEP header */
  bnepu_build_bnep_hdr(p_bcb, p_buf, protocol, p_src_addr, &p_dest_addr,
  bnepu_build_bnep_hdr(p_bcb, p_buf, protocol, src_addr, dest_addr,
                       fw_ext_present);

  /* Send the data or queue it up */
+3 −3
Original line number Diff line number Diff line
@@ -179,8 +179,8 @@ void bnepu_send_peer_our_filters(tBNEP_CONN* p_bcb);
void bnepu_send_peer_our_multi_filters(tBNEP_CONN* p_bcb);
bool bnepu_does_dest_support_prot(tBNEP_CONN* p_bcb, uint16_t protocol);
void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, uint16_t protocol,
                          const RawAddress* p_src_addr,
                          const RawAddress* p_dest_addr, bool ext_bit);
                          const RawAddress& src_addr,
                          const RawAddress& dest_addr, bool ext_bit);
void test_bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf,
                               uint16_t protocol, uint8_t* p_src_addr,
                               uint8_t* p_dest_addr, uint8_t type);
@@ -202,7 +202,7 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,
void bnep_sec_check_complete(const RawAddress* bd_addr, tBT_TRANSPORT trasnport,
                             void* p_ref_data);
tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
                                    const RawAddress& p_dest_addr,
                                    const RawAddress& dest_addr,
                                    uint16_t protocol, bool fw_ext_present,
                                    uint8_t* p_data, uint16_t org_len);

+13 −12
Original line number Diff line number Diff line
@@ -407,14 +407,14 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
            extension_present);

  /* Initialize addresses to 'not supplied' */
  const RawAddress *p_src_addr, *p_dst_addr;
  p_src_addr = p_dst_addr = NULL;
  RawAddress src_addr = RawAddress::kEmpty;
  RawAddress dst_addr = RawAddress::kEmpty;

  switch (type) {
    case BNEP_FRAME_GENERAL_ETHERNET:
      p_dst_addr = (RawAddress*)p;
      dst_addr = *(RawAddress*)p;
      p += BD_ADDR_LEN;
      p_src_addr = (RawAddress*)p;
      src_addr = *(RawAddress*)p;
      p += BD_ADDR_LEN;
      BE_STREAM_TO_UINT16(protocol, p);
      rem_len -= 14;
@@ -454,14 +454,14 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
      break;

    case BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY:
      p_src_addr = (RawAddress*)p;
      src_addr = *(RawAddress*)p;
      p += BD_ADDR_LEN;
      BE_STREAM_TO_UINT16(protocol, p);
      rem_len -= 8;
      break;

    case BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY:
      p_dst_addr = (RawAddress*)p;
      dst_addr = *(RawAddress*)p;
      p += BD_ADDR_LEN;
      BE_STREAM_TO_UINT16(protocol, p);
      rem_len -= 8;
@@ -489,9 +489,10 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
  p_buf->len = rem_len;

  /* Always give the upper layer MAC addresses */
  if (!p_src_addr) p_src_addr = &p_bcb->rem_bda;
  if (src_addr == RawAddress::kEmpty) src_addr = p_bcb->rem_bda;

  if (!p_dst_addr) p_dst_addr = controller_get_interface()->get_address();
  if (dst_addr == RawAddress::kEmpty)
    dst_addr = *controller_get_interface()->get_address();

  /* check whether there are any extensions to be forwarded */
  if (ext_type)
@@ -500,11 +501,11 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
    fw_ext_present = false;

  if (bnep_cb.p_data_buf_cb) {
    (*bnep_cb.p_data_buf_cb)(p_bcb->handle, *p_src_addr, *p_dst_addr, protocol,
                             p_buf, fw_ext_present);
    (*bnep_cb.p_data_buf_cb)(p_bcb->handle, src_addr, dst_addr, protocol, p_buf,
                             fw_ext_present);
  } else if (bnep_cb.p_data_ind_cb) {
    (*bnep_cb.p_data_ind_cb)(p_bcb->handle, *p_src_addr, *p_dst_addr, protocol,
                             p, rem_len, fw_ext_present);
    (*bnep_cb.p_data_ind_cb)(p_bcb->handle, src_addr, dst_addr, protocol, p,
                             rem_len, fw_ext_present);
    osi_free(p_buf);
  }
}
+18 −15
Original line number Diff line number Diff line
@@ -426,33 +426,36 @@ void bnepu_check_send_packet(tBNEP_CONN* p_bcb, BT_HDR* p_buf) {
 *
 ******************************************************************************/
void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, uint16_t protocol,
                          const RawAddress* p_src_addr,
                          const RawAddress* p_dest_addr, bool fw_ext_present) {
                          const RawAddress& src_addr,
                          const RawAddress& dest_addr, bool fw_ext_present) {
  const controller_t* controller = controller_get_interface();
  uint8_t ext_bit, *p = (uint8_t*)NULL;
  uint8_t type = BNEP_FRAME_COMPRESSED_ETHERNET;
  RawAddress source_addr = src_addr;

  ext_bit = fw_ext_present ? 0x80 : 0x00;

  if (p_src_addr && *p_src_addr != *controller->get_address())
  if (source_addr != RawAddress::kEmpty &&
      source_addr != *controller->get_address())
    type = BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY;

  if (*p_dest_addr != p_bcb->rem_bda)
  if (dest_addr != p_bcb->rem_bda)
    type = (type == BNEP_FRAME_COMPRESSED_ETHERNET)
               ? BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY
               : BNEP_FRAME_GENERAL_ETHERNET;

  if (!p_src_addr) p_src_addr = controller->get_address();
  if (source_addr == RawAddress::kEmpty)
    source_addr = *controller->get_address();

  switch (type) {
    case BNEP_FRAME_GENERAL_ETHERNET:
      p = bnepu_init_hdr(p_buf, 15,
                         (uint8_t)(ext_bit | BNEP_FRAME_GENERAL_ETHERNET));

      memcpy(p, p_dest_addr->address, BD_ADDR_LEN);
      memcpy(p, dest_addr.address, BD_ADDR_LEN);
      p += BD_ADDR_LEN;

      memcpy(p, p_src_addr->address, BD_ADDR_LEN);
      memcpy(p, source_addr.address, BD_ADDR_LEN);
      p += BD_ADDR_LEN;
      break;

@@ -466,7 +469,7 @@ void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, uint16_t protocol,
          p_buf, 9,
          (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY));

      memcpy(p, p_src_addr->address, BD_ADDR_LEN);
      memcpy(p, source_addr.address, BD_ADDR_LEN);
      p += BD_ADDR_LEN;
      break;

@@ -475,7 +478,7 @@ void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, uint16_t protocol,
          p_buf, 9,
          (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY));

      memcpy(p, p_dest_addr->address, BD_ADDR_LEN);
      memcpy(p, dest_addr.address, BD_ADDR_LEN);
      p += BD_ADDR_LEN;
      break;
  }
@@ -1187,7 +1190,7 @@ void bnep_sec_check_complete(const RawAddress* bd_addr, tBT_TRANSPORT trasnport,
 *
 ******************************************************************************/
tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
                                    const RawAddress& p_dest_addr,
                                    const RawAddress& dest_addr,
                                    uint16_t protocol, bool fw_ext_present,
                                    uint8_t* p_data, uint16_t org_len) {
  if (p_bcb->rcvd_num_filters) {
@@ -1233,7 +1236,7 @@ tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
  }

  /* Ckeck for multicast address filtering */
  if ((p_dest_addr.address[0] & 0x01) && p_bcb->rcvd_mcast_filters) {
  if ((dest_addr.address[0] & 0x01) && p_bcb->rcvd_mcast_filters) {
    uint16_t i;

    /* Check if every multicast should be filtered */
@@ -1241,9 +1244,9 @@ tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
      /* Check if the address is mentioned in the filter range */
      for (i = 0; i < p_bcb->rcvd_mcast_filters; i++) {
        if ((memcmp(p_bcb->rcvd_mcast_filter_start[i].address,
                    p_dest_addr.address, BD_ADDR_LEN) <= 0) &&
            (memcmp(p_bcb->rcvd_mcast_filter_end[i].address,
                    p_dest_addr.address, BD_ADDR_LEN) >= 0))
                    dest_addr.address, BD_ADDR_LEN) <= 0) &&
            (memcmp(p_bcb->rcvd_mcast_filter_end[i].address, dest_addr.address,
                    BD_ADDR_LEN) >= 0))
          break;
      }
    }
@@ -1255,7 +1258,7 @@ tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
    */
    if ((p_bcb->rcvd_mcast_filters == 0xFFFF) ||
        (i == p_bcb->rcvd_mcast_filters)) {
      VLOG(1) << "Ignoring multicast address " << p_dest_addr
      VLOG(1) << "Ignoring multicast address " << dest_addr
              << " in BNEP data write";
      return BNEP_IGNORE_CMD;
    }
+12 −14
Original line number Diff line number Diff line
@@ -274,13 +274,12 @@ tBNEP_RESULT BNEP_Disconnect(uint16_t handle);
 * Description      This function sends data in a GKI buffer on BNEP connection
 *
 * Parameters:      handle       - handle of the connection to write
 *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
 *                  dest_addr    - BD_ADDR/Ethernet addr of the destination
 *                  p_buf        - pointer to address of buffer with data
 *                  protocol     - protocol type of the packet
 *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
 *                                 source (should be NULL if it is the local BD
 *                                         Addr)
 *                  fw_ext_present - forwarded extensions present
 *                  src_addr     - (optional) BD_ADDR/ethernet address of the
 *                                 source (should be kEmpty if it is the local
 *BD Addr) fw_ext_present - forwarded extensions present
 *
 * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
 *                  BNEP_MTU_EXCEDED        - If the data length is greater
@@ -290,9 +289,9 @@ tBNEP_RESULT BNEP_Disconnect(uint16_t handle);
 *                  BNEP_SUCCESS            - If written successfully
 *
 ******************************************************************************/
tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& dest_addr,
                           BT_HDR* p_buf, uint16_t protocol,
                           const RawAddress* p_src_addr, bool fw_ext_present);
                           const RawAddress& src_addr, bool fw_ext_present);

/*******************************************************************************
 *
@@ -301,13 +300,12 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
 * Description      This function sends data over a BNEP connection
 *
 * Parameters:      handle       - handle of the connection to write
 *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
 *                  dest_addr    - BD_ADDR/Ethernet addr of the destination
 *                  p_data       - pointer to data start
 *                  protocol     - protocol type of the packet
 *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
 *                                 source (should be NULL if it is the local BD
 *                                 Addr)
 *                  fw_ext_present - forwarded extensions present
 *                  src_addr     - (optional) BD_ADDR/ethernet address of the
 *                                 source (should be kEmpty if it is the local
 *BD Addr) fw_ext_present - forwarded extensions present
 *
 * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
 *                  BNEP_MTU_EXCEDED        - If the data length is greater than
@@ -318,9 +316,9 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& p_dest_addr,
 *                  BNEP_SUCCESS            - If written successfully
 *
 ******************************************************************************/
tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& dest_addr,
                        uint8_t* p_data, uint16_t len, uint16_t protocol,
                        const RawAddress* p_src_addr, bool fw_ext_present);
                        const RawAddress& src_addr, bool fw_ext_present);

/*******************************************************************************
 *
Loading