Exemplo n.º 1
0
/*******************************************************************************
**
** Function         BTM_EnableTestMode
**
** Description      Send HCI the enable device under test command.
**
**                  Note: Controller can only be taken out of this mode by
**                      resetting the controller.
**
** Returns
**      BTM_SUCCESS         Command sent.
**      BTM_NO_RESOURCES    If out of resources to send the command.
**
**
*******************************************************************************/
tBTM_STATUS BTM_EnableTestMode(void)
{
    UINT8   cond;

    BTM_TRACE_EVENT ("BTM: BTM_EnableTestMode");

    /* set auto accept connection as this is needed during test mode */
    /* Allocate a buffer to hold HCI command */
    cond = HCI_DO_AUTO_ACCEPT_CONNECT;
    if (!btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP,
                                     HCI_FILTER_COND_NEW_DEVICE,
                                     &cond, sizeof(cond)))
    {
        return (BTM_NO_RESOURCES);
    }

    /* put device to connectable mode */
    if (!BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW,
                               BTM_DEFAULT_CONN_INTERVAL) == BTM_SUCCESS)
    {
        return BTM_NO_RESOURCES;
    }

    /* put device to discoverable mode */
    if (!BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW,
                                BTM_DEFAULT_DISC_INTERVAL) == BTM_SUCCESS)
    {
        return BTM_NO_RESOURCES;
    }

    /* mask off all of event from controller */
    hci_layer_get_interface()->transmit_command(
      hci_packet_factory_get_interface()->make_set_event_mask((const bt_event_mask_t *)("\x00\x00\x00\x00\x00\x00\x00\x00")),
      NULL,
      NULL,
      NULL);

    /* Send the HCI command */
    if (btsnd_hcic_enable_test_mode ())
        return (BTM_SUCCESS);
    else
        return (BTM_NO_RESOURCES);
}
/*******************************************************************************
**
** Function         PAN_Register
**
** Description      This function is called by the application to register
**                  its callbacks with PAN profile. The application then
**                  should set the PAN role explicitly.
**
** Parameters:      p_register - contains all callback function pointers
**
**
** Returns          none
**
*******************************************************************************/
void PAN_Register (tPAN_REGISTER *p_register)
{
    BTM_SetDiscoverability (BTM_GENERAL_DISCOVERABLE, 0, 0);
    BTM_SetConnectability (BTM_CONNECTABLE, 0, 0);

    pan_register_with_bnep ();

    if (!p_register)
        return;

    pan_cb.pan_conn_state_cb    = p_register->pan_conn_state_cb;
    pan_cb.pan_bridge_req_cb    = p_register->pan_bridge_req_cb;
    pan_cb.pan_data_buf_ind_cb  = p_register->pan_data_buf_ind_cb;
    pan_cb.pan_data_ind_cb      = p_register->pan_data_ind_cb;
    pan_cb.pan_pfilt_ind_cb     = p_register->pan_pfilt_ind_cb;
    pan_cb.pan_mfilt_ind_cb     = p_register->pan_mfilt_ind_cb;
    pan_cb.pan_tx_data_flow_cb  = p_register->pan_tx_data_flow_cb;

    return;
}
/*******************************************************************************
**
** Function         bta_pan_enable
**
** Description
**
**
**
** Returns          void
**
*******************************************************************************/
void bta_pan_enable(tBTA_PAN_DATA *p_data)
{
    tPAN_REGISTER reg_data;
    UINT16  initial_discoverability;
    UINT16  initial_connectability;
    UINT16  d_window;
    UINT16  d_interval;
    UINT16  c_window;
    UINT16  c_interval;

    bta_pan_cb.p_cback = p_data->api_enable.p_cback;

    reg_data.pan_conn_state_cb  = bta_pan_conn_state_cback;
    reg_data.pan_bridge_req_cb  = NULL;
    reg_data.pan_data_buf_ind_cb = bta_pan_data_buf_ind_cback;
    reg_data.pan_data_ind_cb = NULL;
    reg_data.pan_pfilt_ind_cb = bta_pan_pfilt_ind_cback;
    reg_data.pan_mfilt_ind_cb = bta_pan_mfilt_ind_cback;
    reg_data.pan_tx_data_flow_cb = bta_pan_data_flow_cb;

    /* read connectability and discoverability settings.
    Pan profile changes the settings. We have to change it back to
    be consistent with other bta subsystems */
    initial_connectability = BTM_ReadConnectability(&c_window, &c_interval);
    initial_discoverability = BTM_ReadDiscoverability(&d_window, &d_interval);


    PAN_Register (&reg_data);


    /* set it back to original value */
    BTM_SetDiscoverability(initial_discoverability, d_window, d_interval);
    BTM_SetConnectability(initial_connectability, c_window, c_interval);

    bta_pan_cb.flow_mask = bta_pan_co_init(&bta_pan_cb.q_level);
    bta_pan_cb.p_cback(BTA_PAN_ENABLE_EVT, NULL);

}