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

Commit a6ce41a1 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Clean up PAN code

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I7152fcf35975ff6a88e16ad0465c49fcb86379b6
parent 6aadcedf
Loading
Loading
Loading
Loading
+0 −34
Original line number Original line Diff line number Diff line
@@ -60,22 +60,6 @@
 ******************************************************************************/
 ******************************************************************************/
extern uint8_t bta_pan_co_init(uint8_t* q_level);
extern uint8_t bta_pan_co_init(uint8_t* q_level);


/*******************************************************************************
 *
 * Function         bta_pan_co_open
 *
 * Description      This function is executed by PAN when a connection
 *                  is opened.  The phone can use this function to set
 *                  up data paths or perform any required initialization.
 *
 *
 * Returns          void
 *
 ******************************************************************************/
extern void bta_pan_co_open(uint16_t handle, uint8_t app_id,
                            tBTA_PAN_ROLE local_role, tBTA_PAN_ROLE peer_role,
                            const RawAddress& peer_addr);

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         bta_pan_co_close
 * Function         bta_pan_co_close
@@ -119,24 +103,6 @@ extern void bta_pan_co_tx_path(uint16_t handle, uint8_t app_id);
 ******************************************************************************/
 ******************************************************************************/
extern void bta_pan_co_rx_path(uint16_t handle, uint8_t app_id);
extern void bta_pan_co_rx_path(uint16_t handle, uint8_t app_id);


/*******************************************************************************
 *
 * Function         bta_pan_co_tx_write
 *
 * Description      This function is called by PAN to send data to the phone
 *                  when the TX path is configured to use a push interface.
 *                  The implementation of this function must copy the data to
 *                  the phone's memory.
 *
 *
 * Returns          void
 *
 ******************************************************************************/
extern void bta_pan_co_tx_write(uint16_t handle, uint8_t app_id,
                                const RawAddress& src, const RawAddress& dst,
                                uint16_t protocol, uint8_t* p_data,
                                uint16_t len, bool ext, bool forward);

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         bta_pan_co_rx_flow
 * Function         bta_pan_co_rx_flow
+0 −2
Original line number Original line Diff line number Diff line
@@ -169,13 +169,11 @@ extern void bta_pan_disable(void);
extern void bta_pan_set_role(tBTA_PAN_DATA* p_data);
extern void bta_pan_set_role(tBTA_PAN_DATA* p_data);
extern void bta_pan_open(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_open(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_api_close(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_api_close(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_set_shutdown(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_rx_path(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_rx_path(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_tx_path(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_tx_path(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_tx_flow(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_tx_flow(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_conn_open(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_conn_open(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_conn_close(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_conn_close(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_writebuf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_write_buf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_write_buf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_free_buf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
extern void bta_pan_free_buf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);


+0 −68
Original line number Original line Diff line number Diff line
@@ -59,51 +59,6 @@ uint8_t bta_pan_co_init(uint8_t* q_level) {
  return (BTA_PAN_RX_PUSH_BUF | BTA_PAN_RX_PUSH | BTA_PAN_TX_PULL);
  return (BTA_PAN_RX_PUSH_BUF | BTA_PAN_RX_PUSH | BTA_PAN_TX_PULL);
}
}


/******************************************************************************
 *
 * Function         bta_pan_co_open
 *
 * Description
 *
 *
 *
 *
 *
 * Returns          void
 *
 ******************************************************************************/
void bta_pan_co_open(uint16_t handle, uint8_t app_id, tBTA_PAN_ROLE local_role,
                     tBTA_PAN_ROLE peer_role, const RawAddress& peer_addr) {
  BTIF_TRACE_API(
      "bta_pan_co_open:app_id:%d, local_role:%d, peer_role:%d, "
      "handle:%d",
      app_id, local_role, peer_role, handle);
  btpan_conn_t* conn = btpan_find_conn_addr(peer_addr);
  if (conn == NULL)
    conn = btpan_new_conn(handle, peer_addr, local_role, peer_role);
  if (conn) {
    BTIF_TRACE_DEBUG(
        "bta_pan_co_open:tap_fd:%d, open_count:%d, "
        "conn->handle:%d should = handle:%d, local_role:%d, remote_role:%d",
        btpan_cb.tap_fd, btpan_cb.open_count, conn->handle, handle,
        conn->local_role, conn->remote_role);
    // refresh the role & bt address

    btpan_cb.open_count++;
    conn->handle = handle;
    // conn->peer = peer_addr;
    if (btpan_cb.tap_fd < 0) {
      btpan_cb.tap_fd = btpan_tap_open();
      if (btpan_cb.tap_fd >= 0) create_tap_read_thread(btpan_cb.tap_fd);
    }
    if (btpan_cb.tap_fd >= 0) {
      btpan_cb.flow = 1;
      conn->state = PAN_STATE_OPEN;
      bta_pan_ci_rx_ready(handle);
    }
  }
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         bta_pan_co_close
 * Function         bta_pan_co_close
@@ -210,29 +165,6 @@ void bta_pan_co_rx_path(UNUSED_ATTR uint16_t handle,
  BTIF_TRACE_API("bta_pan_co_rx_path not used");
  BTIF_TRACE_API("bta_pan_co_rx_path not used");
}
}


/*******************************************************************************
 *
 * Function         bta_pan_co_tx_write
 *
 * Description      This function is called by PAN to send data to the phone
 *                  when the TX path is configured to use a push interface.
 *                  The implementation of this function must copy the data to
 *                  the phone's memory.
 *
 *
 * Returns          void
 *
 ******************************************************************************/
void bta_pan_co_tx_write(UNUSED_ATTR uint16_t handle,
                         UNUSED_ATTR uint8_t app_id,
                         UNUSED_ATTR const RawAddress& src,
                         UNUSED_ATTR const RawAddress& dst,
                         UNUSED_ATTR uint16_t protocol,
                         UNUSED_ATTR uint8_t* p_data, UNUSED_ATTR uint16_t len,
                         UNUSED_ATTR bool ext, UNUSED_ATTR bool forward) {
  BTIF_TRACE_API("bta_pan_co_tx_write not used");
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         bta_pan_co_rx_flow
 * Function         bta_pan_co_rx_flow
+0 −7
Original line number Original line Diff line number Diff line
@@ -33,10 +33,6 @@
 */
 */
#define PAN_ROLE_INACTIVE 0
#define PAN_ROLE_INACTIVE 0


/* Protocols supported by the host internal stack, are registered with SDP */
#define PAN_PROTOCOL_IP 0x0800
#define PAN_PROTOCOL_ARP 0x0806

#define PAN_PROFILE_VERSION 0x0100 /* Version 1.00 */
#define PAN_PROFILE_VERSION 0x0100 /* Version 1.00 */


/* Define the PAN Connection Control Block
/* Define the PAN Connection Control Block
@@ -103,9 +99,6 @@ extern void pan_conn_ind_cb(uint16_t handle, const RawAddress& p_bda,
                            bool is_role_change);
                            bool is_role_change);
extern void pan_connect_state_cb(uint16_t handle, const RawAddress& rem_bda,
extern void pan_connect_state_cb(uint16_t handle, const RawAddress& rem_bda,
                                 tBNEP_RESULT result, bool is_role_change);
                                 tBNEP_RESULT result, bool is_role_change);
extern void pan_data_ind_cb(uint16_t handle, const RawAddress& src,
                            const RawAddress& dst, uint16_t protocol,
                            uint8_t* p_data, uint16_t len, bool fw_ext_present);
extern void pan_data_buf_ind_cb(uint16_t handle, const RawAddress& src,
extern void pan_data_buf_ind_cb(uint16_t handle, const RawAddress& src,
                                const RawAddress& dst, uint16_t protocol,
                                const RawAddress& dst, uint16_t protocol,
                                BT_HDR* p_buf, bool ext);
                                BT_HDR* p_buf, bool ext);
+0 −94
Original line number Original line Diff line number Diff line
@@ -359,100 +359,6 @@ void pan_connect_state_cb(uint16_t handle,
  }
  }
}
}


/*******************************************************************************
 *
 * Function         pan_data_ind_cb
 *
 * Description      This function is registered with BNEP as data indication
 *                  callback. BNEP will call this when the peer sends any data
 *                  on this connection
 *
 * Parameters:      handle      - handle for the connection
 *                  src         - source BD Addr
 *                  dst         - destination BD Addr
 *                  protocol    - Network protocol of the Eth packet
 *                  p_data      - pointer to the data
 *                  len         - length of the data
 *                  fw_ext_present - to indicate whether the data contains any
 *                                         extension headers before the payload
 *
 * Returns          none
 *
 ******************************************************************************/
void pan_data_ind_cb(uint16_t handle, const RawAddress& src,
                     const RawAddress& dst, uint16_t protocol, uint8_t* p_data,
                     uint16_t len, bool ext) {
  tPAN_CONN* pcb;
  uint16_t i;
  bool forward;

  /*
  ** Check the connection status
  ** If the destination address is MAC broadcast send on all links
  ** except on the one received
  ** If the destination uuid is for NAP send to host system also
  ** If the destination address is one of the devices connected
  ** send the packet to over that link
  ** If the destination address is unknown and destination uuid is NAP
  ** send it to the host system
  */

  PAN_TRACE_EVENT("pan_data_ind_cb - for handle %d", handle);
  pcb = pan_get_pcb_by_handle(handle);
  if (!pcb) {
    PAN_TRACE_ERROR("PAN Data indication for wrong handle %d", handle);
    return;
  }

  if (pcb->con_state != PAN_STATE_CONNECTED) {
    PAN_TRACE_ERROR("PAN Data indication in wrong state %d for handle %d",
                    pcb->con_state, handle);
    return;
  }

  /* Check if it is broadcast packet */
  if (dst.address[0] & 0x01) {
    PAN_TRACE_DEBUG("PAN received broadcast packet on handle %d, src uuid 0x%x",
                    handle, pcb->src_uuid);
    for (i = 0; i < MAX_PAN_CONNS; i++) {
      if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED &&
          pan_cb.pcb[i].handle != handle &&
          pcb->src_uuid == pan_cb.pcb[i].src_uuid) {
        BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, &src, ext);
      }
    }

    if (pan_cb.pan_data_ind_cb)
      (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len,
                                ext, true);

    return;
  }

  /* Check if it is for any other PAN connection */
  for (i = 0; i < MAX_PAN_CONNS; i++) {
    if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED &&
        pcb->src_uuid == pan_cb.pcb[i].src_uuid) {
      if (pan_cb.pcb[i].rem_bda == dst) {
        BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, &src, ext);
        return;
      }
    }
  }

  if (pcb->src_uuid == UUID_SERVCLASS_NAP)
    forward = true;
  else
    forward = false;

  /* Send it over the LAN or give it to host software */
  if (pan_cb.pan_data_ind_cb)
    (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, ext,
                              forward);

  return;
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         pan_data_buf_ind_cb
 * Function         pan_data_buf_ind_cb