1e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************
2e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
3e9629bad30a9f478b336ab46b8e6e02f7f87af46Evan Chu *  Copyright (C) 2010-2014 Broadcom Corporation
4e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
5e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  Licensed under the Apache License, Version 2.0 (the "License");
6e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  you may not use this file except in compliance with the License.
7e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  You may obtain a copy of the License at:
8e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
9e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  http://www.apache.org/licenses/LICENSE-2.0
10e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
11e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
12e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
13e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  See the License for the specific language governing permissions and
15e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  limitations under the License.
16e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
17e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ******************************************************************************/
18e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
195c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen
20e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************
21e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
22e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *  This file contains the action functions for the NFA HCI.
23e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project *
24e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ******************************************************************************/
25e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include <string.h>
26e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "trace_api.h"
27e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfc_api.h"
28e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_sys.h"
29e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_sys_int.h"
30e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_hci_api.h"
31e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_hci_int.h"
325c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen#include "nfa_dm_int.h"
33e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_nv_co.h"
34e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_mem_co.h"
35e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "nfa_hci_defs.h"
36e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
37e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
38e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/* Static local functions       */
39e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_register (tNFA_HCI_EVENT_DATA *p_evt_data);
40e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_get_gate_pipe_list (tNFA_HCI_EVENT_DATA *p_evt_data);
41e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_alloc_gate (tNFA_HCI_EVENT_DATA *p_evt_data);
42e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_get_host_list (tNFA_HCI_EVENT_DATA *p_evt_data);
43e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_get_reg_value (tNFA_HCI_EVENT_DATA *p_evt_data);
44e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_set_reg_value (tNFA_HCI_EVENT_DATA *p_evt_data);
45e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_create_pipe (tNFA_HCI_EVENT_DATA *p_evt_data);
46e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_open_pipe (tNFA_HCI_EVENT_DATA *p_evt_data);
47e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_close_pipe (tNFA_HCI_EVENT_DATA *p_evt_data);
48e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_delete_pipe (tNFA_HCI_EVENT_DATA *p_evt_data);
49e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_send_event (tNFA_HCI_EVENT_DATA *p_evt_data);
50e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_send_cmd (tNFA_HCI_EVENT_DATA *p_evt_data);
51e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_send_rsp (tNFA_HCI_EVENT_DATA *p_evt_data);
52e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_add_static_pipe (tNFA_HCI_EVENT_DATA *p_evt_data);
53e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
54e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_handle_identity_mgmt_gate_pkt (UINT8 *p_data, tNFA_HCI_DYN_PIPE *p_pipe);
55e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_handle_loopback_gate_pkt (UINT8 *p_data, UINT16 data_len, tNFA_HCI_DYN_PIPE *p_pipe);
56e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_handle_connectivity_gate_pkt (UINT8 *p_data, UINT16 data_len, tNFA_HCI_DYN_PIPE *p_pipe);
57e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_handle_generic_gate_cmd (UINT8 *p_data, UINT8 data_len, tNFA_HCI_DYN_GATE *p_gate, tNFA_HCI_DYN_PIPE *p_pipe);
58e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_handle_generic_gate_rsp (UINT8 *p_data, UINT8 data_len, tNFA_HCI_DYN_GATE *p_gate, tNFA_HCI_DYN_PIPE *p_pipe);
59e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_handle_generic_gate_evt (UINT8 *p_data, UINT16 data_len, tNFA_HCI_DYN_GATE *p_gate, tNFA_HCI_DYN_PIPE *p_pipe);
60e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
61e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
62e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
63e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
64e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_check_pending_api_requests
65e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
66e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles pending API requests
67e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
68e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
69e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
70e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
71e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_check_pending_api_requests (void)
72e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
73e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    BT_HDR              *p_msg;
74e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVENT_DATA *p_evt_data;
75e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    BOOLEAN             b_free;
76e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
77e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* If busy, or API queue is empty, then exit */
78e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (  (nfa_hci_cb.hci_state != NFA_HCI_STATE_IDLE)
79e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        ||((p_msg = (BT_HDR *) GKI_dequeue (&nfa_hci_cb.hci_host_reset_api_q)) == NULL) )
80e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        return;
81e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
82e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Process API request */
83e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    p_evt_data = (tNFA_HCI_EVENT_DATA *)p_msg;
84e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
85e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Save the application handle */
86e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hci_cb.app_in_use = p_evt_data->comm.hci_handle;
87e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
88e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    b_free = TRUE;
89e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    switch (p_msg->event)
90e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
91e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_API_CREATE_PIPE_EVT:
92e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_api_create_pipe (p_evt_data) == FALSE)
93e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            b_free = FALSE;
94e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
95e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
96e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_API_GET_REGISTRY_EVT:
97e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_api_get_reg_value (p_evt_data) == FALSE)
98e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            b_free = FALSE;
99e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
100e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
101e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_API_SET_REGISTRY_EVT:
102e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_api_set_reg_value (p_evt_data) == FALSE)
103e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            b_free = FALSE;
104e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
105e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
106e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_API_SEND_CMD_EVT:
107e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_api_send_cmd (p_evt_data) == FALSE)
108e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            b_free = FALSE;
109e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
110e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_API_SEND_EVENT_EVT:
111e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_api_send_event (p_evt_data) == FALSE)
112e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            b_free = FALSE;
113e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
114e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
115e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
116e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (b_free)
117e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        GKI_freebuf (p_msg);
118e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
119e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
120e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
121e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
122e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_check_api_requests
123e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
124e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles API requests
125e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
126e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
127e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
128e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
129e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_check_api_requests (void)
130e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
131e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    BT_HDR              *p_msg;
132e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVENT_DATA *p_evt_data;
133e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
134e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    for ( ; ; )
135e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
136e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* If busy, or API queue is empty, then exit */
137e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (nfa_hci_cb.hci_state != NFA_HCI_STATE_IDLE)
138e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            ||((p_msg = (BT_HDR *) GKI_dequeue (&nfa_hci_cb.hci_api_q)) == NULL) )
139e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
140e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
141e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Process API request */
142e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_evt_data = (tNFA_HCI_EVENT_DATA *)p_msg;
143e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
144e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Save the application handle */
145e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.app_in_use = p_evt_data->comm.hci_handle;
146e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
147e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        switch (p_msg->event)
148e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
149e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_REGISTER_APP_EVT:
150e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_register (p_evt_data);
151e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
152e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
153e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_DEREGISTER_APP_EVT:
154e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_deregister (p_evt_data);
155e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
156e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
157e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_GET_APP_GATE_PIPE_EVT:
158e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_get_gate_pipe_list (p_evt_data);
159e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
160e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
161e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_ALLOC_GATE_EVT:
162e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_alloc_gate (p_evt_data);
163e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
164e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
165e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_DEALLOC_GATE_EVT:
166e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_dealloc_gate (p_evt_data);
167e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
168e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
169e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_GET_HOST_LIST_EVT:
170e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_get_host_list (p_evt_data);
171e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
172e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
173e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_GET_REGISTRY_EVT:
174e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_api_get_reg_value (p_evt_data) == FALSE)
175e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                continue;
176e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
177e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
178e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_SET_REGISTRY_EVT:
179e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_api_set_reg_value (p_evt_data) == FALSE)
180e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                continue;
181e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
182e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
183e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_CREATE_PIPE_EVT:
184e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project           if (nfa_hci_api_create_pipe (p_evt_data) == FALSE)
185e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project               continue;
186e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
187e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
188e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_OPEN_PIPE_EVT:
189e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_open_pipe (p_evt_data);
190e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
191e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
192e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_CLOSE_PIPE_EVT:
193e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_close_pipe (p_evt_data);
194e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
195e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
196e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_DELETE_PIPE_EVT:
197e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_delete_pipe (p_evt_data);
198e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
199e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
200e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_SEND_CMD_EVT:
201e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_api_send_cmd (p_evt_data) == FALSE)
202e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                continue;
203e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
204e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
205e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_SEND_RSP_EVT:
206e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_send_rsp (p_evt_data);
207e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
208e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
209e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_SEND_EVENT_EVT:
210e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_api_send_event (p_evt_data) == FALSE)
211e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                continue;
212e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
213e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
214e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_API_ADD_STATIC_PIPE_EVT:
215e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_api_add_static_pipe (p_evt_data);
216e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
217e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
218e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        default:
219e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_ERROR1 ("nfa_hci_check_api_requests ()  Unknown event: 0x%04x", p_msg->event);
220e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
221e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
222e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
223e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        GKI_freebuf (p_msg);
224e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
225e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
226e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
227e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
228e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
229e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_register
230e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
231e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to register the events for the given AID
232e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
233e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
234e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
235e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
236e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_register (tNFA_HCI_EVENT_DATA *p_evt_data)
237e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
238e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
239e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    char                *p_app_name  = p_evt_data->app_info.app_name;
240e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_CBACK      *p_cback     = p_evt_data->app_info.p_cback;
241e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    int                 xx,yy;
242e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               num_gates    = 0,num_pipes = 0;
243e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *pg = nfa_hci_cb.cfg.dyn_gates;
244e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
245e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* First, see if the application was already registered */
246e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    for (xx = 0; xx < NFA_HCI_MAX_APP_CB; xx++)
247e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
248e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (nfa_hci_cb.cfg.reg_app_names[xx][0] != 0)
249e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            && !strncmp (p_app_name, &nfa_hci_cb.cfg.reg_app_names[xx][0], strlen (p_app_name)) )
250e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
251e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_EVENT2 ("nfa_hci_api_register (%s)  Reusing: %u", p_app_name, xx);
252e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
253e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
254e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
255e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
256e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (xx != NFA_HCI_MAX_APP_CB)
257e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
258e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.app_in_use = (tNFA_HANDLE) (xx | NFA_HANDLE_GROUP_HCI);
259e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* The app was registered, find the number of gates and pipes associated to the app */
260e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
261e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        for ( yy = 0; yy < NFA_HCI_MAX_GATE_CB; yy++, pg++)
262e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
263e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (pg->gate_owner == nfa_hci_cb.app_in_use)
264e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
265e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                num_gates++;
266e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                num_pipes += nfa_hciu_count_pipes_on_gate (pg);
267e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
268e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
269e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
270e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
271e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
272e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Not registered, look for a free entry */
273e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        for (xx = 0; xx < NFA_HCI_MAX_APP_CB; xx++)
274e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
275e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.cfg.reg_app_names[xx][0] == 0)
276e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
277e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                memset (&nfa_hci_cb.cfg.reg_app_names[xx][0], 0, sizeof (nfa_hci_cb.cfg.reg_app_names[xx]));
278e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                BCM_STRNCPY_S (&nfa_hci_cb.cfg.reg_app_names[xx][0], sizeof (nfa_hci_cb.cfg.reg_app_names[xx]), p_app_name, NFA_MAX_HCI_APP_NAME_LEN);
279e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_cb.nv_write_needed = TRUE;
280e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_EVENT2 ("nfa_hci_api_register (%s)  Allocated: %u", p_app_name, xx);
281e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                break;
282e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
283e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
284e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
285e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (xx == NFA_HCI_MAX_APP_CB)
286e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
287e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_ERROR1 ("nfa_hci_api_register (%s)  NO ENTRIES", p_app_name);
288e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
289e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.hci_register.status = NFA_STATUS_FAILED;
290e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            p_evt_data->app_info.p_cback (NFA_HCI_REGISTER_EVT, &evt_data);
291e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
292e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
293e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
294e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
295e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.hci_register.num_pipes = num_pipes;
296e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.hci_register.num_gates = num_gates;
297e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hci_cb.p_app_cback[xx]      = p_cback;
298e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
299e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hci_cb.cfg.b_send_conn_evts[xx]  = p_evt_data->app_info.b_send_conn_evts;
300e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
301e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.hci_register.hci_handle = (tNFA_HANDLE) (xx | NFA_HANDLE_GROUP_HCI);
302e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
303e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.hci_register.status = NFA_STATUS_OK;
304e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
305e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* notify NFA_HCI_REGISTER_EVT to the application */
306e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    p_evt_data->app_info.p_cback (NFA_HCI_REGISTER_EVT, &evt_data);
307e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
308e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
309e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
310e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
311e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_deregister
312e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
313e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to deregister the given application
314e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
315e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
316e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
317e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
318e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_api_deregister (tNFA_HCI_EVENT_DATA *p_evt_data)
319e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
320e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
321e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_CBACK      *p_cback = NULL;
322e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    int                 xx;
323e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe;
324e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
325e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
326e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* If needed, find the application registration handle */
327e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_evt_data != NULL)
328e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
329e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        for (xx = 0; xx < NFA_HCI_MAX_APP_CB; xx++)
330e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
331e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (  (nfa_hci_cb.cfg.reg_app_names[xx][0] != 0)
332e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                && !strncmp (p_evt_data->app_info.app_name, &nfa_hci_cb.cfg.reg_app_names[xx][0], strlen (p_evt_data->app_info.app_name)) )
333e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
334e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_EVENT2 ("nfa_hci_api_deregister (%s) inx: %u", p_evt_data->app_info.app_name, xx);
335e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                break;
336e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
337e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
338e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
339e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (xx == NFA_HCI_MAX_APP_CB)
340e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
341e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_WARNING1 ("nfa_hci_api_deregister () Unknown app: %s", p_evt_data->app_info.app_name);
342e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
343e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
344e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.app_in_use = (tNFA_HANDLE) (xx | NFA_HANDLE_GROUP_HCI);
345e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_cback               = nfa_hci_cb.p_app_cback[xx];
346e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
347e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
348e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
349e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_sys_stop_timer (&nfa_hci_cb.timer);
350e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* We are recursing through deleting all the app's pipes and gates */
351e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_cback = nfa_hci_cb.p_app_cback[nfa_hci_cb.app_in_use & NFA_HANDLE_MASK];
352e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
353e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
354e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* See if any pipe is owned by this app */
3555c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    if (nfa_hciu_find_pipe_by_owner (nfa_hci_cb.app_in_use) == NULL)
356e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
357e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* No pipes, release all gates owned by this app */
358e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        while ((p_gate = nfa_hciu_find_gate_by_owner (nfa_hci_cb.app_in_use)) != NULL)
359e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_release_gate (p_gate->gate_id);
360e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
361e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        memset (&nfa_hci_cb.cfg.reg_app_names[nfa_hci_cb.app_in_use & NFA_HANDLE_MASK][0], 0, NFA_MAX_HCI_APP_NAME_LEN + 1);
362e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.p_app_cback[nfa_hci_cb.app_in_use & NFA_HANDLE_MASK]  = NULL;
363e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
364e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.nv_write_needed = TRUE;
365e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
366e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.hci_deregister.status = NFC_STATUS_OK;
367e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
368e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_cb.hci_state == NFA_HCI_STATE_APP_DEREGISTER)
369e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.hci_state = NFA_HCI_STATE_IDLE;
370e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
371e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* notify NFA_HCI_DEREGISTER_EVT to the application */
372e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (p_cback)
373e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            p_cback (NFA_HCI_DEREGISTER_EVT, &evt_data);
374e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
375e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else if ((p_pipe = nfa_hciu_find_active_pipe_by_owner (nfa_hci_cb.app_in_use)) == NULL)
376e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
377e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* No pipes, release all gates owned by this app */
378e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        while ((p_gate = nfa_hciu_find_gate_with_nopipes_by_owner (nfa_hci_cb.app_in_use)) != NULL)
379e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_release_gate (p_gate->gate_id);
380e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
381e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.p_app_cback[nfa_hci_cb.app_in_use & NFA_HANDLE_MASK]  = NULL;
382e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
383e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.nv_write_needed = TRUE;
384e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
385e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.hci_deregister.status = NFC_STATUS_FAILED;
386e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
387e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_cb.hci_state == NFA_HCI_STATE_APP_DEREGISTER)
388e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.hci_state = NFA_HCI_STATE_IDLE;
389e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
390e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* notify NFA_HCI_DEREGISTER_EVT to the application */
391e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (p_cback)
392e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            p_cback (NFA_HCI_DEREGISTER_EVT, &evt_data);
393e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
394e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
395e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
396e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Delete all active pipes created for the application before de registering
397e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        **/
398e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.hci_state = NFA_HCI_STATE_APP_DEREGISTER;
399e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
400e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_delete_pipe_cmd (p_pipe->pipe_id);
401e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
402e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
403e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
404e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
405e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
406e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_get_gate_pipe_list
407e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
408e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to get application allocated gates and
409e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  application created pipes
410e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
411e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
412e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
413e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
414e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_get_gate_pipe_list (tNFA_HCI_EVENT_DATA *p_evt_data)
415e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
416e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
417e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    int                 xx,yy;
418e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *pg = nfa_hci_cb.cfg.dyn_gates;
419e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *pp = nfa_hci_cb.cfg.dyn_pipes;
420e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
421e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.gates_pipes.num_gates = 0;
422e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.gates_pipes.num_pipes = 0;
423e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
424e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    for ( xx = 0; xx < NFA_HCI_MAX_GATE_CB; xx++, pg++)
425e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
426e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (pg->gate_owner == p_evt_data->get_gate_pipe_list.hci_handle)
427e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
428e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.gates_pipes.gate[evt_data.gates_pipes.num_gates++] = pg->gate_id;
429e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
430e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            pp = nfa_hci_cb.cfg.dyn_pipes;
431e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
432e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Loop through looking for a match */
433e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            for ( yy = 0; yy < NFA_HCI_MAX_PIPE_CB; yy++, pp++)
434e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
435e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (pp->local_gate == pg->gate_id)
436e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.gates_pipes.pipe[evt_data.gates_pipes.num_pipes++] = *(tNFA_HCI_PIPE_INFO*)pp;
437e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
438e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
439e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
4405c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen
4415c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    evt_data.gates_pipes.num_uicc_created_pipes = 0;
4425c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    /* Loop through all pipes that are connected to connectivity gate */
4435c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    for (xx = 0, pp = nfa_hci_cb.cfg.dyn_pipes; xx < NFA_HCI_MAX_PIPE_CB; xx++, pp++)
4445c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    {
4455c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        if (pp->pipe_id != 0  && pp->local_gate == NFA_HCI_CONNECTIVITY_GATE)
4465c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        {
4475c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            memcpy (&evt_data.gates_pipes.uicc_created_pipe [evt_data.gates_pipes.num_uicc_created_pipes++], pp, sizeof (tNFA_HCI_PIPE_INFO));
4485c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        }
4495c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        else if (pp->pipe_id != 0  && pp->local_gate == NFA_HCI_LOOP_BACK_GATE)
4505c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        {
4515c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            memcpy (&evt_data.gates_pipes.uicc_created_pipe [evt_data.gates_pipes.num_uicc_created_pipes++], pp, sizeof (tNFA_HCI_PIPE_INFO));
4525c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        }
453a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        else if (pp->pipe_id >= NFA_HCI_FIRST_DYNAMIC_PIPE  && pp->pipe_id <= NFA_HCI_LAST_DYNAMIC_PIPE  && pp->pipe_id && pp->local_gate >= NFA_HCI_FIRST_PROP_GATE && pp->local_gate <= NFA_HCI_LAST_PROP_GATE)
454a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        {
455a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            for (xx = 0, pg = nfa_hci_cb.cfg.dyn_gates; xx < NFA_HCI_MAX_GATE_CB; xx++, pg++)
456a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            {
457a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                if (pp->local_gate == pg->gate_id)
458a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                {
459a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                    if (!pg->gate_owner)
460a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                        memcpy (&evt_data.gates_pipes.uicc_created_pipe [evt_data.gates_pipes.num_uicc_created_pipes++], pp, sizeof (tNFA_HCI_PIPE_INFO));
461a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                    break;
462a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                }
463a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            }
464a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        }
4655c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    }
4665c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen
467e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.gates_pipes.status = NFA_STATUS_OK;
468e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
469e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* notify NFA_HCI_GET_GATE_PIPE_LIST_EVT to the application */
470e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_GET_GATE_PIPE_LIST_EVT, &evt_data, p_evt_data->get_gate_pipe_list.hci_handle);
471e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
472e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
473e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
474e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
475e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_alloc_gate
476e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
477a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu** Description      action function to allocate gate
478e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
479e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
480e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
481e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
482e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_alloc_gate (tNFA_HCI_EVENT_DATA *p_evt_data)
483e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
484e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HANDLE         app_handle = p_evt_data->comm.hci_handle;
485e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
486e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
487e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
488a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    p_gate = nfa_hciu_alloc_gate (p_evt_data->gate_info.gate, app_handle);
489a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu
490a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    if (p_gate)
491a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    {
492a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        if (!p_gate->gate_owner)
493a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        {
494a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            /* No app owns the gate yet */
495a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            p_gate->gate_owner = app_handle;
496a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        }
497a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        else if (p_gate->gate_owner != app_handle)
498a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        {
499a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            /* Some other app owns the gate */
500a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            p_gate = NULL;
501a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            NFA_TRACE_ERROR1 ("nfa_hci_api_alloc_gate (): The Gate (0X%02x) already taken!", p_evt_data->gate_info.gate);
502a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        }
503a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    }
504e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
505e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.allocated.gate   = p_gate ? p_gate->gate_id : 0;
506e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.allocated.status = p_gate ? NFA_STATUS_OK : NFA_STATUS_FAILED;
507e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
508e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* notify NFA_HCI_ALLOCATE_GATE_EVT to the application */
509e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_ALLOCATE_GATE_EVT, &evt_data, app_handle);
510e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
511e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
512e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
513e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
514e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_dealloc_gate
515e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
516e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to deallocate the given generic gate
517e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
518e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
519e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
520e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
521e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_api_dealloc_gate (tNFA_HCI_EVENT_DATA *p_evt_data)
522e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
523e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
524e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               gate_id;
525e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
526e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe;
527e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HANDLE         app_handle;
528e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
529e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* p_evt_data may be NULL if we are recursively deleting pipes */
530e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_evt_data)
531e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
532e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        gate_id    = p_evt_data->gate_dealloc.gate;
533e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        app_handle = p_evt_data->gate_dealloc.hci_handle;
534e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
535e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
536e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
537e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
538e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_sys_stop_timer (&nfa_hci_cb.timer);
539e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        gate_id    = nfa_hci_cb.local_gate_in_use;
540e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        app_handle = nfa_hci_cb.app_in_use;
541e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
542e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
543e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.deallocated.gate = gate_id;;
544e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
545e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    p_gate = nfa_hciu_find_gate_by_gid (gate_id);
546e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
547e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_gate == NULL)
548e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
549e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.deallocated.status = NFA_STATUS_UNKNOWN_GID;
550e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
551e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else if (p_gate->gate_owner != app_handle)
552e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
553e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.deallocated.status = NFA_STATUS_FAILED;
554e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
555e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
556e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
557e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* See if any pipe is owned by this app */
5585c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        if (nfa_hciu_find_pipe_on_gate (p_gate->gate_id) == NULL)
559e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
560e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_release_gate (p_gate->gate_id);
561e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
562e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.nv_write_needed  = TRUE;
563e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.deallocated.status = NFA_STATUS_OK;
564e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
565e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.hci_state == NFA_HCI_STATE_REMOVE_GATE)
566e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_cb.hci_state = NFA_HCI_STATE_IDLE;
567e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
568e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else if ((p_pipe = nfa_hciu_find_active_pipe_on_gate (p_gate->gate_id)) == NULL)
569e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
570e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* UICC is not active at the moment and cannot delete the pipe */
571e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.nv_write_needed  = TRUE;
572e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.deallocated.status = NFA_STATUS_FAILED;
573e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
574e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.hci_state == NFA_HCI_STATE_REMOVE_GATE)
575e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_cb.hci_state = NFA_HCI_STATE_IDLE;
576e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
577e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
578e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
579e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Delete pipes on the gate */
580e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.local_gate_in_use = gate_id;
581e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.app_in_use        = app_handle;
582e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.hci_state         = NFA_HCI_STATE_REMOVE_GATE;
583e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
584e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_delete_pipe_cmd (p_pipe->pipe_id);
585e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
586e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
587e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
588e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
589e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_DEALLOCATE_GATE_EVT, &evt_data, app_handle);
590e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
591e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
592e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
593e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
594e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_get_host_list
595e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
596e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to get the host list from HCI network
597e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
598e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
599e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
600e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
601e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_get_host_list (tNFA_HCI_EVENT_DATA *p_evt_data)
602e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
603e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               app_inx = p_evt_data->get_host_list.hci_handle & NFA_HANDLE_MASK;
604e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
605e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hci_cb.app_in_use = p_evt_data->get_host_list.hci_handle;
606e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
6075c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    /* Send Get Host List command on "Internal request" or requested by registered application with valid handle and callback function */
6085c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    if (  (nfa_hci_cb.app_in_use == NFA_HANDLE_INVALID)
6095c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        ||((app_inx < NFA_HCI_MAX_APP_CB) && (nfa_hci_cb.p_app_cback[app_inx] != NULL))  )
610e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
6115c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_HOST_LIST_INDEX);
612e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
613e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
614e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
615e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
616e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
617e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_create_pipe
618e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
619e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to create a pipe
620e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
621e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          TRUE, if the command is processed
622e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  FALSE, if command is queued for processing later
623e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
624e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
625e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_create_pipe (tNFA_HCI_EVENT_DATA *p_evt_data)
626e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
627e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate = nfa_hciu_find_gate_by_gid (p_evt_data->create_pipe.source_gate);
628e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
629a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    BOOLEAN             report_failed = FALSE;
630e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
631e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Verify that the app owns the gate that the pipe is being created on */
632a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    if (  (p_gate == NULL)
633a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        ||(p_gate->gate_owner != p_evt_data->create_pipe.hci_handle)  )
634a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    {
635a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        report_failed = TRUE;
636a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        NFA_TRACE_ERROR2 ("nfa_hci_api_create_pipe Cannot create pipe! APP: 0x%02x does not own the gate:0x%x", p_evt_data->create_pipe.hci_handle, p_evt_data->create_pipe.source_gate);
637a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    }
638a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    else if (nfa_hciu_check_pipe_between_gates (p_evt_data->create_pipe.source_gate, p_evt_data->create_pipe.dest_host, p_evt_data->create_pipe.dest_gate))
639a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    {
640a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        report_failed = TRUE;
641a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu        NFA_TRACE_ERROR0 ("nfa_hci_api_create_pipe : Cannot create multiple pipe between the same two gates!");
642a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    }
643a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu
644a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu    if (report_failed)
645e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
646e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.created.source_gate = p_evt_data->create_pipe.source_gate;
647e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.created.status = NFA_STATUS_FAILED;
648e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
649e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_to_app (NFA_HCI_CREATE_PIPE_EVT, &evt_data, p_evt_data->open_pipe.hci_handle);
650e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
651e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
652e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
653e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hciu_is_host_reseting (p_evt_data->create_pipe.dest_gate))
654e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
655e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            GKI_enqueue (&nfa_hci_cb.hci_host_reset_api_q, (BT_HDR *) p_evt_data);
656e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return FALSE;
657e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
658e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
659e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.local_gate_in_use  = p_evt_data->create_pipe.source_gate;
660e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.remote_gate_in_use = p_evt_data->create_pipe.dest_gate;
661e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.remote_host_in_use = p_evt_data->create_pipe.dest_host;
662e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.app_in_use         = p_evt_data->create_pipe.hci_handle;
663e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
664e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_create_pipe_cmd (p_evt_data->create_pipe.source_gate, p_evt_data->create_pipe.dest_host, p_evt_data->create_pipe.dest_gate);
665e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
666e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    return TRUE;
667e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
668e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
669e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
670e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
671e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_open_pipe
672e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
673e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to open a pipe
674e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
675e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
676e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
677e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
678e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_open_pipe (tNFA_HCI_EVENT_DATA *p_evt_data)
679e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
680e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
681e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->open_pipe.pipe);
682e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate = NULL;
683e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
684e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_pipe != NULL)
685e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_gate = nfa_hciu_find_gate_by_gid (p_pipe->local_gate);
686e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
687e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (  (p_pipe != NULL)
688e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(p_gate != NULL)
689e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(nfa_hciu_is_active_host (p_pipe->dest_host))
690e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(p_gate->gate_owner == p_evt_data->open_pipe.hci_handle))
691e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
692e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (p_pipe->pipe_state == NFA_HCI_PIPE_CLOSED)
693e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
694e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_open_pipe_cmd (p_evt_data->open_pipe.pipe);
695e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
696e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
697e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
698e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.opened.pipe   = p_evt_data->open_pipe.pipe;
699e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.opened.status = NFA_STATUS_OK;
700e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
701e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_to_app (NFA_HCI_OPEN_PIPE_EVT, &evt_data, p_evt_data->open_pipe.hci_handle);
702e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
703e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
704e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
705e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
706e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.opened.pipe   = p_evt_data->open_pipe.pipe;
707e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.opened.status = NFA_STATUS_FAILED;
708e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
709e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_to_app (NFA_HCI_OPEN_PIPE_EVT, &evt_data, p_evt_data->open_pipe.hci_handle);
710e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
711e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
712e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
713e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
714e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
715e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_get_reg_value
716e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
717e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to get the reg value of the specified index
718e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
719e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          TRUE, if the command is processed
720e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  FALSE, if command is queued for processing later
721e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
722e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
723e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_get_reg_value (tNFA_HCI_EVENT_DATA *p_evt_data)
724e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
725e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->get_registry.pipe);
726e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
727e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_STATUS         status = NFA_STATUS_FAILED;
728e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
729e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
730e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_pipe != NULL)
731e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
732e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_gate = nfa_hciu_find_gate_by_gid (p_pipe->local_gate);
733e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
734e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if ((p_gate != NULL) && (nfa_hciu_is_active_host (p_pipe->dest_host)) && (p_gate->gate_owner == p_evt_data->get_registry.hci_handle))
735e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
736e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.app_in_use        = p_evt_data->get_registry.hci_handle;
737e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
738e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hciu_is_host_reseting (p_pipe->dest_host))
739e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
740e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                GKI_enqueue (&nfa_hci_cb.hci_host_reset_api_q, (BT_HDR *) p_evt_data);
741e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                return FALSE;
742e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
743e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
744e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (p_pipe->pipe_state == NFA_HCI_PIPE_CLOSED)
745e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
746e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_WARNING1 ("nfa_hci_api_get_reg_value pipe:%d not open", p_evt_data->get_registry.pipe);
747e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
748e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
749e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
750e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if ((status = nfa_hciu_send_get_param_cmd (p_evt_data->get_registry.pipe, p_evt_data->get_registry.reg_inx)) == NFA_STATUS_OK)
751e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    return TRUE;
752e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
753e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
754e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
755e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
756e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.cmd_sent.status = status;
757e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
758e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Send NFA_HCI_CMD_SENT_EVT to notify failure */
759e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_CMD_SENT_EVT, &evt_data, p_evt_data->get_registry.hci_handle);
760e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    return TRUE;
761e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
762e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
763e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
764e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
765e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_set_reg_value
766e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
767e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to set the reg value at specified index
768e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
769e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          TRUE, if the command is processed
770e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  FALSE, if command is queued for processing later
771e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
772e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
773e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_set_reg_value (tNFA_HCI_EVENT_DATA *p_evt_data)
774e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
775e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->set_registry.pipe);
776e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
777e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_STATUS         status = NFA_STATUS_FAILED;
778e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
779e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
780e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_pipe != NULL)
781e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
782e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_gate = nfa_hciu_find_gate_by_gid (p_pipe->local_gate);
783e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
784e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if ((p_gate != NULL) && (nfa_hciu_is_active_host (p_pipe->dest_host)) && (p_gate->gate_owner == p_evt_data->set_registry.hci_handle))
785e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
786e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.app_in_use        = p_evt_data->set_registry.hci_handle;
787e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
788e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hciu_is_host_reseting (p_pipe->dest_host))
789e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
790e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                GKI_enqueue (&nfa_hci_cb.hci_host_reset_api_q, (BT_HDR *) p_evt_data);
791e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                return FALSE;
792e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
793e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
794e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (p_pipe->pipe_state == NFA_HCI_PIPE_CLOSED)
795e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
796e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_WARNING1 ("nfa_hci_api_set_reg_value pipe:%d not open", p_evt_data->set_registry.pipe);
797e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
798e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
799e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
800e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if ((status = nfa_hciu_send_set_param_cmd (p_evt_data->set_registry.pipe, p_evt_data->set_registry.reg_inx, p_evt_data->set_registry.size, p_evt_data->set_registry.data)) == NFA_STATUS_OK)
801e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    return TRUE;
802e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
803e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
804e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
805e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.cmd_sent.status = status;
806e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
807e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Send NFA_HCI_CMD_SENT_EVT to notify failure */
808e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_CMD_SENT_EVT, &evt_data, p_evt_data->set_registry.hci_handle);
809e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    return TRUE;
810e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
811e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
812e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
813e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
814e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
815e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_close_pipe
816e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
817e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to close a pipe
818e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
819e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
820e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
821e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
822e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_close_pipe (tNFA_HCI_EVENT_DATA *p_evt_data)
823e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
824e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
825e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->close_pipe.pipe);
826e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate = NULL;
827e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
828e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_pipe != NULL)
829e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_gate = nfa_hciu_find_gate_by_gid (p_pipe->local_gate);
830e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
831e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (  (p_pipe != NULL)
832e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(p_gate != NULL)
833e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(nfa_hciu_is_active_host (p_pipe->dest_host))
834e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(p_gate->gate_owner == p_evt_data->close_pipe.hci_handle)  )
835e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
836e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (p_pipe->pipe_state == NFA_HCI_PIPE_OPENED)
837e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
838e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_close_pipe_cmd (p_evt_data->close_pipe.pipe);
839e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
840e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
841e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
842e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.closed.status = NFA_STATUS_OK;
843e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.closed.pipe   = p_evt_data->close_pipe.pipe;
844e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
845e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_to_app (NFA_HCI_CLOSE_PIPE_EVT, &evt_data, p_evt_data->close_pipe.hci_handle);
846e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
847e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
848e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
849e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
850e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.closed.status = NFA_STATUS_FAILED;
851e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        evt_data.closed.pipe   = 0x00;
852e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
853e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_to_app (NFA_HCI_CLOSE_PIPE_EVT, &evt_data, p_evt_data->close_pipe.hci_handle);
854e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
855e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
856e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
857e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
858e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
859e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_delete_pipe
860e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
861e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to delete a pipe
862e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
863e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
864e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
865e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
866e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_delete_pipe (tNFA_HCI_EVENT_DATA *p_evt_data)
867e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
868e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
869e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->delete_pipe.pipe);
870e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate = NULL;
871e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
872e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_pipe != NULL)
873e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
874e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_gate = nfa_hciu_find_gate_by_gid (p_pipe->local_gate);
875e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (p_gate != NULL)
876e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            &&(p_gate->gate_owner == p_evt_data->delete_pipe.hci_handle)
877e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            &&(nfa_hciu_is_active_host (p_pipe->dest_host))  )
878e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
879e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_delete_pipe_cmd (p_evt_data->delete_pipe.pipe);
880e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
881e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
882e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
883e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
884e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.deleted.status = NFA_STATUS_FAILED;
885e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.deleted.pipe   = 0x00;
886e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_DELETE_PIPE_EVT, &evt_data, p_evt_data->close_pipe.hci_handle);
887e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
888e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
889e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
890e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
891e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_send_cmd
892e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
893e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to send command on the given pipe
894e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
895e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          TRUE, if the command is processed
896e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  FALSE, if command is queued for processing later
897e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
898e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
899e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_send_cmd (tNFA_HCI_EVENT_DATA *p_evt_data)
900e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
901e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_STATUS         status = NFA_STATUS_FAILED;
902e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe;
903e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
904e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HANDLE         app_handle;
905e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
906e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if ((p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->send_cmd.pipe)) != NULL)
907e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
908e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        app_handle = nfa_hciu_get_pipe_owner (p_evt_data->send_cmd.pipe);
909e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
910e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (nfa_hciu_is_active_host (p_pipe->dest_host))
9115c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&((app_handle == p_evt_data->send_cmd.hci_handle || p_pipe->local_gate == NFA_HCI_CONNECTIVITY_GATE))  )
912e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
913e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hciu_is_host_reseting (p_pipe->dest_host))
914e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
915e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                GKI_enqueue (&nfa_hci_cb.hci_host_reset_api_q, (BT_HDR *) p_evt_data);
916e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                return FALSE;
917e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
918e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
919e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (p_pipe->pipe_state == NFA_HCI_PIPE_OPENED)
920e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
921e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_cb.pipe_in_use = p_evt_data->send_cmd.pipe;
922e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if ((status = nfa_hciu_send_msg (p_pipe->pipe_id, NFA_HCI_COMMAND_TYPE, p_evt_data->send_cmd.cmd_code,
923e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                            p_evt_data->send_cmd.cmd_len, p_evt_data->send_cmd.data)) == NFA_STATUS_OK)
924e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    return TRUE;
925e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
926e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
927e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
928e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_WARNING1 ("nfa_hci_api_send_cmd pipe:%d not open", p_pipe->pipe_id);
929e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
930e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
931e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
932e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
933e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_WARNING1 ("nfa_hci_api_send_cmd pipe:%d Owned by different application or Destination host is not active",
934e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                p_pipe->pipe_id);
935e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
936e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
937e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
938e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
939e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        NFA_TRACE_WARNING1 ("nfa_hci_api_send_cmd pipe:%d not found", p_evt_data->send_cmd.pipe);
940e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
941e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
942e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.cmd_sent.status = status;
943e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
944e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Send NFA_HCI_CMD_SENT_EVT to notify failure */
945e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_CMD_SENT_EVT, &evt_data, p_evt_data->send_cmd.hci_handle);
946e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    return TRUE;
947e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
948e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
949e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
950e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
951e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_send_rsp
952e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
953e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to send response on the given pipe
954e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
955e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
956e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
957e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
958e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_send_rsp (tNFA_HCI_EVENT_DATA *p_evt_data)
959e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
960e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_STATUS         status = NFA_STATUS_FAILED;
961e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe;
962e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
963e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HANDLE         app_handle;
964e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
965e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if ((p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->send_rsp.pipe)) != NULL)
966e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
967e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        app_handle = nfa_hciu_get_pipe_owner (p_evt_data->send_rsp.pipe);
968e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
969e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (nfa_hciu_is_active_host (p_pipe->dest_host))
9705c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&((app_handle == p_evt_data->send_rsp.hci_handle || p_pipe->local_gate == NFA_HCI_CONNECTIVITY_GATE))  )
971e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
972e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (p_pipe->pipe_state == NFA_HCI_PIPE_OPENED)
973e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
974e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if ((status = nfa_hciu_send_msg (p_pipe->pipe_id, NFA_HCI_RESPONSE_TYPE, p_evt_data->send_rsp.response,
975e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                            p_evt_data->send_rsp.size, p_evt_data->send_rsp.data)) == NFA_STATUS_OK)
976e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    return;
977e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
978e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
979e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
980e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_WARNING1 ("nfa_hci_api_send_rsp pipe:%d not open", p_pipe->pipe_id);
981e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
982e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
983e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
984e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
985e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_WARNING1 ("nfa_hci_api_send_rsp pipe:%d Owned by different application or Destination host is not active",
986e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                p_pipe->pipe_id);
987e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
988e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
989e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
990e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
991e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        NFA_TRACE_WARNING1 ("nfa_hci_api_send_rsp pipe:%d not found", p_evt_data->send_rsp.pipe);
992e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
993e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
994e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.rsp_sent.status = status;
995e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
996e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Send NFA_HCI_RSP_SENT_EVT to notify failure */
997e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_RSP_SENT_EVT, &evt_data, p_evt_data->send_rsp.hci_handle);
998e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
999e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1000e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1001e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1002e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_send_event
1003e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1004e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to send an event to the given pipe
1005e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1006e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          TRUE, if the event is processed
1007e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  FALSE, if event is queued for processing later
1008e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1009e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1010e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic BOOLEAN nfa_hci_api_send_event (tNFA_HCI_EVENT_DATA *p_evt_data)
1011e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1012e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_STATUS         status = NFA_STATUS_FAILED;
1013e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe;
1014e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
1015e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HANDLE         app_handle;
1016e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1017e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if ((p_pipe = nfa_hciu_find_pipe_by_pid (p_evt_data->send_evt.pipe)) != NULL)
1018e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1019e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        app_handle = nfa_hciu_get_pipe_owner (p_evt_data->send_evt.pipe);
1020e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1021e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (nfa_hciu_is_active_host (p_pipe->dest_host))
10225c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&((app_handle == p_evt_data->send_evt.hci_handle || p_pipe->local_gate == NFA_HCI_CONNECTIVITY_GATE))  )
1023e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1024e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hciu_is_host_reseting (p_pipe->dest_host))
1025e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1026e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                GKI_enqueue (&nfa_hci_cb.hci_host_reset_api_q, (BT_HDR *) p_evt_data);
1027e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                return FALSE;
1028e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1029e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1030e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (p_pipe->pipe_state == NFA_HCI_PIPE_OPENED)
1031e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1032e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                status = nfa_hciu_send_msg (p_pipe->pipe_id, NFA_HCI_EVENT_TYPE, p_evt_data->send_evt.evt_code,
1033e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                            p_evt_data->send_evt.evt_len, p_evt_data->send_evt.p_evt_buf);
1034e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1035e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (status == NFA_STATUS_OK)
1036e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
10375c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                    if (p_pipe->local_gate == NFA_HCI_LOOP_BACK_GATE)
10385c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                    {
10395c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        nfa_hci_cb.w4_rsp_evt   = TRUE;
10405c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        nfa_hci_cb.hci_state    = NFA_HCI_STATE_WAIT_RSP;
10415c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                    }
10425c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen
1043e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    if (p_evt_data->send_evt.rsp_len)
1044e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    {
1045e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.pipe_in_use  = p_evt_data->send_evt.pipe;
1046e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.rsp_buf_size = p_evt_data->send_evt.rsp_len;
1047e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.p_rsp_buf    = p_evt_data->send_evt.p_rsp_buf;
1048e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        if (p_evt_data->send_evt.rsp_timeout)
1049e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        {
1050e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                            nfa_hci_cb.w4_rsp_evt   = TRUE;
1051e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                            nfa_hci_cb.hci_state    = NFA_HCI_STATE_WAIT_RSP;
1052e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                            nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, p_evt_data->send_evt.rsp_timeout);
1053e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        }
10545c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        else if (p_pipe->local_gate == NFA_HCI_LOOP_BACK_GATE)
10555c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        {
10565c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                            nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, p_nfa_hci_cfg->hcp_response_timeout);
10575c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        }
1058e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    }
1059e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    else
1060e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    {
10615c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        if (p_pipe->local_gate == NFA_HCI_LOOP_BACK_GATE)
10625c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        {
10635c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                            nfa_hci_cb.pipe_in_use  = p_evt_data->send_evt.pipe;
10645c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                            nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, p_nfa_hci_cfg->hcp_response_timeout);
10655c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                        }
1066e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.rsp_buf_size = 0;
1067e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.p_rsp_buf    = NULL;
1068e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    }
1069e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1070e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1071e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
1072e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1073e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                NFA_TRACE_WARNING1 ("nfa_hci_api_send_event pipe:%d not open", p_pipe->pipe_id);
1074e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1075e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1076e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
1077e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1078e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_WARNING1 ("nfa_hci_api_send_event pipe:%d Owned by different application or Destination host is not active",
1079e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                p_pipe->pipe_id);
1080e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1081e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1082e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
1083e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1084e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        NFA_TRACE_WARNING1 ("nfa_hci_api_send_event pipe:%d not found", p_evt_data->send_evt.pipe);
1085e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1086e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1087e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.evt_sent.status = status;
1088e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
10895c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    /* Send NFC_HCI_EVENT_SENT_EVT to notify status */
1090e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_EVENT_SENT_EVT, &evt_data, p_evt_data->send_evt.hci_handle);
1091e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    return TRUE;
1092e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1093e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1094e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1095e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1096e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_api_add_static_pipe
1097e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1098e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      action function to add static pipe
1099e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1100e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          None
1101e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1102e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1103e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectstatic void nfa_hci_api_add_static_pipe (tNFA_HCI_EVENT_DATA *p_evt_data)
1104e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1105e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *pg;
1106e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *pp;
1107e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
1108e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1109e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Allocate a proprietary gate */
1110e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if ((pg = nfa_hciu_alloc_gate (p_evt_data->add_static_pipe.gate, p_evt_data->add_static_pipe.hci_handle)) != NULL)
1111e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1112e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Assign new owner to the gate */
1113e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        pg->gate_owner = p_evt_data->add_static_pipe.hci_handle;
1114e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1115e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Add the dynamic pipe to the proprietary gate */
1116e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hciu_add_pipe_to_gate (p_evt_data->add_static_pipe.pipe,pg->gate_id, p_evt_data->add_static_pipe.host, p_evt_data->add_static_pipe.gate) != NFA_HCI_ANY_OK)
1117e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1118e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Unable to add the dynamic pipe, so release the gate */
1119e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_release_gate (pg->gate_id);
1120e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.pipe_added.status = NFA_STATUS_FAILED;
1121e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_to_app (NFA_HCI_ADD_STATIC_PIPE_EVT, &evt_data, p_evt_data->add_static_pipe.hci_handle);
1122e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
1123e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1124e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if ((pp = nfa_hciu_find_pipe_by_pid (p_evt_data->add_static_pipe.pipe)) != NULL)
1125e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1126e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* This pipe is always opened */
1127e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            pp->pipe_state = NFA_HCI_PIPE_OPENED;
1128e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.pipe_added.status = NFA_STATUS_OK;
1129e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_to_app (NFA_HCI_ADD_STATIC_PIPE_EVT, &evt_data, p_evt_data->add_static_pipe.hci_handle);
1130e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
1131e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1132e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1133e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* Unable to add static pipe */
1134e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    evt_data.pipe_added.status = NFA_STATUS_FAILED;
1135e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_to_app (NFA_HCI_ADD_STATIC_PIPE_EVT, &evt_data, p_evt_data->add_static_pipe.hci_handle);
1136e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1137e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1138e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1139e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1140e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1141e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_handle_link_mgm_gate_cmd
1142e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1143e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles incoming link management gate hci
1144e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  commands
1145e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1146e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
1147e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1148e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1149e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_handle_link_mgm_gate_cmd (UINT8 *p_data)
1150e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1151e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8       index;
1152e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8       data[2];
1153e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8       rsp_len = 0;
1154e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8       response = NFA_HCI_ANY_OK;
1155e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1156e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (  (nfa_hci_cb.cfg.link_mgmt_gate.pipe00_state != NFA_HCI_PIPE_OPENED)
1157e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        &&(nfa_hci_cb.inst != NFA_HCI_ANY_OPEN_PIPE) )
1158e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1159e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_msg (NFA_HCI_LINK_MANAGEMENT_PIPE, NFA_HCI_RESPONSE_TYPE, NFA_HCI_ANY_E_PIPE_NOT_OPENED, 0, NULL);
1160e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        return;
1161e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1162e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1163e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    switch (nfa_hci_cb.inst)
1164e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1165e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ANY_SET_PARAMETER:
1166e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (index, p_data);
1167e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1168e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (index == 1)
1169e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1170e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            STREAM_TO_UINT16 (nfa_hci_cb.cfg.link_mgmt_gate.rec_errors, p_data);
1171e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1172e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
1173e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            response = NFA_HCI_ANY_E_REG_PAR_UNKNOWN;
1174e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1175e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1176e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ANY_GET_PARAMETER:
1177e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (index, p_data);
1178e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (index == 1)
1179e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1180e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            data[0] = (UINT8) ((nfa_hci_cb.cfg.link_mgmt_gate.rec_errors >> 8) & 0x00FF);
1181e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            data[1] = (UINT8) (nfa_hci_cb.cfg.link_mgmt_gate.rec_errors & 0x000F);
1182e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            rsp_len = 2;
1183e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1184e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
1185e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            response = NFA_HCI_ANY_E_REG_PAR_UNKNOWN;
1186e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1187e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1188e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ANY_OPEN_PIPE:
1189e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        data[0]  = 0;
1190e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        rsp_len  = 1;
1191e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.cfg.link_mgmt_gate.pipe00_state = NFA_HCI_PIPE_OPENED;
1192e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1193e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1194e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ANY_CLOSE_PIPE:
1195e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.cfg.link_mgmt_gate.pipe00_state = NFA_HCI_PIPE_CLOSED;
1196e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1197e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1198e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    default:
1199e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        response = NFA_HCI_ANY_E_CMD_NOT_SUPPORTED;
1200e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1201e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1202e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1203e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_msg (NFA_HCI_LINK_MANAGEMENT_PIPE, NFA_HCI_RESPONSE_TYPE, response, rsp_len, data);
1204e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1205e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1206e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1207e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1208e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1209e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1210e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_handle_pipe_open_close_cmd
1211e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1212e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles all generic gates (excluding
1213e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**                  connectivity gate) commands
1214e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1215e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
1216e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1217e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1218e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_handle_pipe_open_close_cmd (tNFA_HCI_DYN_PIPE *p_pipe)
1219e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1220e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               data[1];
1221e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               rsp_len = 0;
1222e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_RESPONSE   response = NFA_HCI_ANY_OK;
1223e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
1224e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1225e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (nfa_hci_cb.inst == NFA_HCI_ANY_OPEN_PIPE)
1226e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1227e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if ((p_gate = nfa_hciu_find_gate_by_gid(p_pipe->local_gate)) != NULL)
1228e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            data[0] = nfa_hciu_count_open_pipes_on_gate (p_gate);
1229e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
1230e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            data[0] = 0;
1231e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1232e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_pipe->pipe_state = NFA_HCI_PIPE_OPENED;
1233e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        rsp_len = 1;
1234e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1235e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else if (nfa_hci_cb.inst == NFA_HCI_ANY_CLOSE_PIPE)
1236e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1237e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        p_pipe->pipe_state = NFA_HCI_PIPE_CLOSED;
1238e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1239e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1240e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_msg (p_pipe->pipe_id, NFA_HCI_RESPONSE_TYPE, response, rsp_len, data);
1241e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1242e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1243e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1244e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1245e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_handle_admin_gate_cmd
1246e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1247e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles incoming commands on ADMIN gate
1248e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1249e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
1250e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1251e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1252e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_handle_admin_gate_cmd (UINT8 *p_data)
1253e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1254e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               source_host, source_gate, dest_host, dest_gate, pipe;
1255e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               data = 0;
1256e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               rsp_len = 0;
1257e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_RESPONSE   response = NFA_HCI_ANY_OK;
1258e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *pgate;
1259e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
1260e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1261e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    switch (nfa_hci_cb.inst)
1262e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1263e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ANY_OPEN_PIPE:
1264e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.cfg.admin_gate.pipe01_state = NFA_HCI_PIPE_OPENED;
1265e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        data    = 0;
1266e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        rsp_len = 1;
1267e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1268e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1269e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ANY_CLOSE_PIPE:
1270e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.cfg.admin_gate.pipe01_state = NFA_HCI_PIPE_CLOSED;
1271e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Reopen the pipe immediately */
1272e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_msg (NFA_HCI_ADMIN_PIPE, NFA_HCI_RESPONSE_TYPE, response, rsp_len, &data);
1273e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hci_cb.app_in_use = NFA_HANDLE_INVALID;
1274e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_send_open_pipe_cmd (NFA_HCI_ADMIN_PIPE);
1275e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        return;
1276e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1277e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1278e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ADM_NOTIFY_PIPE_CREATED:
1279e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (source_host, p_data);
1280e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (source_gate, p_data);
1281e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (dest_host,   p_data);
1282e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (dest_gate,   p_data);
1283e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (pipe,        p_data);
1284e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1285e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (  (dest_gate == NFA_HCI_IDENTITY_MANAGEMENT_GATE)
1286e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            ||(dest_gate == NFA_HCI_LOOP_BACK_GATE) )
1287e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1288e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            response = nfa_hciu_add_pipe_to_static_gate (dest_gate, pipe, source_host, source_gate);
1289e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1290e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
1291e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1292e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if ((pgate = nfa_hciu_find_gate_by_gid (dest_gate)) != NULL)
1293e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1294e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* If the gate is valid, add the pipe to it  */
1295a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                if (nfa_hciu_check_pipe_between_gates (dest_gate, source_host, source_gate))
1296a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                {
1297a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                    /* Already, there is a pipe between these two gates, so will reject */
1298a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                    response = NFA_HCI_ANY_E_NOK;
1299a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                }
1300a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                else if ((response = nfa_hciu_add_pipe_to_gate (pipe, dest_gate, source_host, source_gate)) == NFA_HCI_ANY_OK)
1301e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1302e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    /* Tell the application a pipe was created with its gate */
1303e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1304e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.created.status       = NFA_STATUS_OK;
1305e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.created.pipe         = pipe;
1306e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.created.source_gate  = dest_gate;
1307e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.created.dest_host    = source_host;
1308e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.created.dest_gate    = source_gate;
1309e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1310e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_send_to_app (NFA_HCI_CREATE_PIPE_EVT, &evt_data, pgate->gate_owner);
1311e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1312e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1313e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
1314a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            {
1315e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                response = NFA_HCI_ANY_E_NOK;
1316a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                if ((dest_gate >= NFA_HCI_FIRST_PROP_GATE) && (dest_gate <= NFA_HCI_LAST_PROP_GATE))
1317a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                {
1318a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                    if (nfa_hciu_alloc_gate (dest_gate, 0))
1319a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                        response = nfa_hciu_add_pipe_to_gate (pipe, dest_gate, source_host, source_gate);
1320a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu                }
1321a24be4f06674b2707b57904deaa0dff5a95823bdEvan Chu            }
1322e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1323e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1324e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1325e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ADM_NOTIFY_PIPE_DELETED:
1326e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (pipe, p_data);
1327e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        response = nfa_hciu_release_pipe (pipe);
1328e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1329e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1330e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    case NFA_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED:
1331e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        STREAM_TO_UINT8 (source_host, p_data);
1332e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1333e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        nfa_hciu_remove_all_pipes_from_host (source_host);
1334e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1335e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (source_host == NFA_HCI_HOST_CONTROLLER)
1336e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1337e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.link_mgmt_gate.pipe00_state = NFA_HCI_PIPE_CLOSED;
1338e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.admin_gate.pipe01_state     = NFA_HCI_PIPE_CLOSED;
1339e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1340e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Reopen the admin pipe immediately */
1341e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.app_in_use = NFA_HANDLE_INVALID;
1342e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_open_pipe_cmd (NFA_HCI_ADMIN_PIPE);
1343e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
1344e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1345e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        else
1346e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1347e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (  (source_host >= NFA_HCI_HOST_ID_UICC0)
1348e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                &&(source_host < (NFA_HCI_HOST_ID_UICC0 + NFA_HCI_MAX_HOST_IN_NETWORK))  )
1349e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1350e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_cb.reset_host[source_host - NFA_HCI_HOST_ID_UICC0] = source_host;
1351e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1352e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1353e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1354e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1355e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    default:
1356e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        response = NFA_HCI_ANY_E_CMD_NOT_SUPPORTED;
1357e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        break;
1358e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1359e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1360e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    nfa_hciu_send_msg (NFA_HCI_ADMIN_PIPE, NFA_HCI_RESPONSE_TYPE, response, rsp_len, &data);
1361e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1362e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1363e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1364e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1365e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_handle_admin_gate_rsp
1366e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1367e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles response received on admin gate
1368e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1369e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
1370e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1371e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1372e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_handle_admin_gate_rsp (UINT8 *p_data, UINT8 data_len)
1373e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1374e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               source_host;
1375e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               source_gate = nfa_hci_cb.local_gate_in_use;
1376e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               dest_host   = nfa_hci_cb.remote_host_in_use;
1377e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               dest_gate   = nfa_hci_cb.remote_gate_in_use;
1378e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               pipe        = 0;
1379e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_STATUS         status;
1380e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_EVT_DATA   evt_data;
1381e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               default_session[NFA_HCI_SESSION_ID_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1382e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               host_count  = 0;
1383e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT8               host_id     = 0;
1384e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    UINT32              os_tick;
1385e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1386e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (BT_TRACE_VERBOSE == TRUE)
1387e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    NFA_TRACE_DEBUG4 ("nfa_hci_handle_admin_gate_rsp - LastCmdSent: %s  App: 0x%04x  Gate: 0x%02x  Pipe: 0x%02x",
1388e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                       nfa_hciu_instr_2_str(nfa_hci_cb.cmd_sent), nfa_hci_cb.app_in_use, nfa_hci_cb.local_gate_in_use, nfa_hci_cb.pipe_in_use);
1389e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#else
1390e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    NFA_TRACE_DEBUG4 ("nfa_hci_handle_admin_gate_rsp LastCmdSent: %u  App: 0x%04x  Gate: 0x%02x  Pipe: 0x%02x",
1391e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                       nfa_hci_cb.cmd_sent, nfa_hci_cb.app_in_use, nfa_hci_cb.local_gate_in_use, nfa_hci_cb.pipe_in_use);
1392e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif
1393e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1394e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    /* If starting up, handle events here */
1395e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP)
1396e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE)
13975c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_NETWK_ENABLE)
13985c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE_NETWK_ENABLE))
1399e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1400df5080d7feca9827fd0306471c54f52ecf185c22Evan Chu        if (nfa_hci_cb.inst == NFA_HCI_ANY_E_PIPE_NOT_OPENED)
1401df5080d7feca9827fd0306471c54f52ecf185c22Evan Chu        {
1402df5080d7feca9827fd0306471c54f52ecf185c22Evan Chu            nfa_hciu_send_open_pipe_cmd (NFA_HCI_ADMIN_PIPE);
1403df5080d7feca9827fd0306471c54f52ecf185c22Evan Chu            return;
1404df5080d7feca9827fd0306471c54f52ecf185c22Evan Chu        }
1405df5080d7feca9827fd0306471c54f52ecf185c22Evan Chu
1406e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_cb.inst != NFA_HCI_ANY_OK)
1407e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1408e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            NFA_TRACE_ERROR0 ("nfa_hci_handle_admin_gate_rsp - Initialization failed");
1409e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_startup_complete (NFA_STATUS_FAILED);
1410e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            return;
1411e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1412e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1413e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        switch (nfa_hci_cb.cmd_sent)
1414e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1415e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ANY_SET_PARAMETER:
1416e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.param_in_use == NFA_HCI_SESSION_IDENTITY_INDEX)
1417e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1418e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* Set WHITELIST */
1419855ae32a422fe508c56a9d33f4f65cf6bf77cd9ePrasad Karuppasamy                nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_WHITELIST_INDEX, p_nfa_hci_cfg->num_whitelist_host, p_nfa_hci_cfg->p_whitelist);
1420e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1421e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else if (nfa_hci_cb.param_in_use == NFA_HCI_WHITELIST_INDEX)
1422e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
14235c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP)
14245c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen                    ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE)  )
1425e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_dh_startup_complete ();
1426e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1427e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1428e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1429e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ANY_GET_PARAMETER:
1430e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.param_in_use == NFA_HCI_HOST_LIST_INDEX)
1431e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1432e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                host_count = 0;
1433e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                while (host_count < NFA_HCI_MAX_HOST_IN_NETWORK)
1434e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1435e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_cb.inactive_host[host_count] = NFA_HCI_HOST_ID_UICC0 + host_count;
1436e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    host_count++;
1437e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1438e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1439e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                host_count = 0;
1440e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* Collect active host in the Host Network */
1441e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                while (host_count < data_len)
1442e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1443e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    host_id = (UINT8) *p_data++;
1444e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1445e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    if (  (host_id >= NFA_HCI_HOST_ID_UICC0)
1446e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        &&(host_id < NFA_HCI_HOST_ID_UICC0 + NFA_HCI_MAX_HOST_IN_NETWORK)  )
1447e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    {
1448e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.inactive_host[host_id - NFA_HCI_HOST_ID_UICC0] = 0x00;
1449e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.reset_host[host_id - NFA_HCI_HOST_ID_UICC0] = 0x00;
1450e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    }
1451e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1452e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    host_count++;
1453e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1454e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_startup_complete (NFA_STATUS_OK);
1455e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1456e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else if (nfa_hci_cb.param_in_use == NFA_HCI_SESSION_IDENTITY_INDEX)
1457e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1458e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* The only parameter we get when initializing is the session ID. Check for match. */
1459e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (!memcmp ((UINT8 *) nfa_hci_cb.cfg.admin_gate.session_id, p_data, NFA_HCI_SESSION_ID_LEN) )
1460e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1461855ae32a422fe508c56a9d33f4f65cf6bf77cd9ePrasad Karuppasamy                    /* Session has not changed, Set WHITELIST */
1462855ae32a422fe508c56a9d33f4f65cf6bf77cd9ePrasad Karuppasamy                    nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_WHITELIST_INDEX, p_nfa_hci_cfg->num_whitelist_host, p_nfa_hci_cfg->p_whitelist);
1463e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1464e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                else
1465e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1466e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    /* Something wrong, NVRAM data could be corrupt or first start with default session id */
1467e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_send_clear_all_pipe_cmd ();
1468e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_cb.b_hci_netwk_reset = TRUE;
1469e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1470e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1471e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1472e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1473e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ANY_OPEN_PIPE:
1474e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.admin_gate.pipe01_state = NFA_HCI_PIPE_OPENED;
1475e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1476e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.b_hci_netwk_reset)
1477e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1478e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_cb.b_hci_netwk_reset = FALSE;
1479e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project               /* Session ID is reset, Set New session id */
1480e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                memcpy (&nfa_hci_cb.cfg.admin_gate.session_id[NFA_HCI_SESSION_ID_LEN / 2], nfa_hci_cb.cfg.admin_gate.session_id, (NFA_HCI_SESSION_ID_LEN / 2));
1481e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                os_tick = GKI_get_os_tick_count ();
1482e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                memcpy (nfa_hci_cb.cfg.admin_gate.session_id, (UINT8 *)&os_tick, (NFA_HCI_SESSION_ID_LEN / 2));
1483e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX, NFA_HCI_SESSION_ID_LEN, (UINT8 *) nfa_hci_cb.cfg.admin_gate.session_id);
1484e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1485e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
1486e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1487e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* First thing is to get the session ID */
1488e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX);
1489e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1490e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1491e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1492e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ADM_CLEAR_ALL_PIPE:
1493e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_remove_all_pipes_from_host (0);
1494e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.admin_gate.pipe01_state = NFA_HCI_PIPE_CLOSED;
1495e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.link_mgmt_gate.pipe00_state = NFA_HCI_PIPE_CLOSED;
1496e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.nv_write_needed = TRUE;
1497e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1498e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Open admin */
1499e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_open_pipe_cmd (NFA_HCI_ADMIN_PIPE);
1500e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1501e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1502e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1503e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    else
1504e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1505e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        status = (nfa_hci_cb.inst == NFA_HCI_ANY_OK) ? NFA_STATUS_OK : NFA_STATUS_FAILED;
1506e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1507e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        switch (nfa_hci_cb.cmd_sent)
1508e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        {
1509e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ANY_SET_PARAMETER:
1510e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.hci_state == NFA_HCI_STATE_APP_DEREGISTER)
1511e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_api_deregister (NULL);
1512e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else if (nfa_hci_cb.hci_state == NFA_HCI_STATE_REMOVE_GATE)
1513e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hci_api_dealloc_gate (NULL);
1514e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1515e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1516e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ANY_GET_PARAMETER:
1517e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.param_in_use == NFA_HCI_SESSION_IDENTITY_INDEX)
1518e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1519e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (!memcmp ((UINT8 *) default_session, p_data , NFA_HCI_SESSION_ID_LEN))
1520e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1521e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    memcpy (&nfa_hci_cb.cfg.admin_gate.session_id[(NFA_HCI_SESSION_ID_LEN / 2)], nfa_hci_cb.cfg.admin_gate.session_id, (NFA_HCI_SESSION_ID_LEN / 2));
1522e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    os_tick = GKI_get_os_tick_count ();
1523e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    memcpy (nfa_hci_cb.cfg.admin_gate.session_id, (UINT8 *) &os_tick, (NFA_HCI_SESSION_ID_LEN / 2));
1524e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_cb.nv_write_needed = TRUE;
1525e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX, NFA_HCI_SESSION_ID_LEN, (UINT8 *) nfa_hci_cb.cfg.admin_gate.session_id);
1526e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1527e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                else
1528e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1529e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    if (nfa_hci_cb.hci_state == NFA_HCI_STATE_APP_DEREGISTER)
1530e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_api_deregister (NULL);
1531e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    else if (nfa_hci_cb.hci_state == NFA_HCI_STATE_REMOVE_GATE)
1532e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_api_dealloc_gate (NULL);
1533e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1534e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1535e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else if (nfa_hci_cb.param_in_use == NFA_HCI_HOST_LIST_INDEX)
1536e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1537e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                evt_data.hosts.status    = status;
1538e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                evt_data.hosts.num_hosts = data_len;
1539e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                memcpy (evt_data.hosts.host, p_data, data_len);
1540e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1541e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                host_count = 0;
1542e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                while (host_count < NFA_HCI_MAX_HOST_IN_NETWORK)
1543e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1544e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_cb.inactive_host[host_count] = NFA_HCI_HOST_ID_UICC0 + host_count;
1545e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    host_count++;
1546e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1547e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1548e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                host_count = 0;
1549e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* Collect active host in the Host Network */
1550e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                while (host_count < data_len)
1551e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1552e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    host_id = (UINT8) *p_data++;
1553e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1554e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    if (  (host_id >= NFA_HCI_HOST_ID_UICC0)
1555e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        &&(host_id < NFA_HCI_HOST_ID_UICC0 + NFA_HCI_MAX_HOST_IN_NETWORK)  )
1556e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    {
1557e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.inactive_host[host_id - NFA_HCI_HOST_ID_UICC0] = 0x00;
1558e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                        nfa_hci_cb.reset_host[host_id - NFA_HCI_HOST_ID_UICC0] = 0x00;
1559e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    }
1560e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    host_count++;
1561e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1562e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (nfa_hciu_is_no_host_resetting ())
1563e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_check_pending_api_requests ();
1564e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hciu_send_to_app (NFA_HCI_HOST_LIST_EVT, &evt_data, nfa_hci_cb.app_in_use);
1565e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1566e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1567e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1568e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ADM_CREATE_PIPE:
1569e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (status == NFA_STATUS_OK)
1570e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1571e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                STREAM_TO_UINT8 (source_host, p_data);
1572e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                STREAM_TO_UINT8 (source_gate, p_data);
1573e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                STREAM_TO_UINT8 (dest_host,   p_data);
1574e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                STREAM_TO_UINT8 (dest_gate,   p_data);
1575e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                STREAM_TO_UINT8 (pipe,        p_data);
1576e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1577e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* Sanity check */
1578e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (source_gate != nfa_hci_cb.local_gate_in_use)
1579e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1580e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    NFA_TRACE_WARNING2 ("nfa_hci_handle_admin_gate_rsp sent create pipe with gate: %u got back: %u",
1581e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                                        nfa_hci_cb.local_gate_in_use, source_gate);
1582e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    break;
1583e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1584e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1585e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hciu_add_pipe_to_gate (pipe, source_gate, dest_host, dest_gate);
1586e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1587e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1588e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1589e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Tell the application his pipe was created or not */
1590e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.created.status       = status;
1591e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.created.pipe         = pipe;
1592e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.created.source_gate  = source_gate;
1593e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.created.dest_host    = dest_host;
1594e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            evt_data.created.dest_gate    = dest_gate;
1595e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1596e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_to_app (NFA_HCI_CREATE_PIPE_EVT, &evt_data, nfa_hci_cb.app_in_use);
1597e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1598e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1599e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ADM_DELETE_PIPE:
1600e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (status == NFA_STATUS_OK)
1601e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1602e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hciu_release_pipe (nfa_hci_cb.pipe_in_use);
1603e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1604e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* If only deleting one pipe, tell the app we are done */
1605e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (nfa_hci_cb.hci_state == NFA_HCI_STATE_IDLE)
1606e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1607e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.deleted.status         = status;
1608e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.deleted.pipe           = nfa_hci_cb.pipe_in_use;
1609e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1610e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_send_to_app (NFA_HCI_DELETE_PIPE_EVT, &evt_data, nfa_hci_cb.app_in_use);
1611e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1612e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                else if (nfa_hci_cb.hci_state == NFA_HCI_STATE_APP_DEREGISTER)
1613e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_api_deregister (NULL);
1614e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                else if (nfa_hci_cb.hci_state == NFA_HCI_STATE_REMOVE_GATE)
1615e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_api_dealloc_gate (NULL);
1616e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1617e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            else
1618e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1619e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* If only deleting one pipe, tell the app we are done */
1620e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                if (nfa_hci_cb.hci_state == NFA_HCI_STATE_IDLE)
1621e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1622e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.deleted.status         = status;
1623e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    evt_data.deleted.pipe           = nfa_hci_cb.pipe_in_use;
1624e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1625e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_send_to_app (NFA_HCI_DELETE_PIPE_EVT, &evt_data, nfa_hci_cb.app_in_use);
1626e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1627e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                else if (nfa_hci_cb.hci_state == NFA_HCI_STATE_APP_DEREGISTER)
1628e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1629e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_release_pipe (nfa_hci_cb.pipe_in_use);
1630e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_api_deregister (NULL);
1631e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1632e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                else if (nfa_hci_cb.hci_state == NFA_HCI_STATE_REMOVE_GATE)
1633e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                {
1634e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hciu_release_pipe (nfa_hci_cb.pipe_in_use);
1635e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                    nfa_hci_api_dealloc_gate (NULL);
1636e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                }
1637e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1638e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1639e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1640e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ANY_OPEN_PIPE:
1641e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.admin_gate.pipe01_state = status ? NFA_HCI_PIPE_CLOSED:NFA_HCI_PIPE_OPENED;
1642e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.nv_write_needed = TRUE;
1643e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            if (nfa_hci_cb.cfg.admin_gate.pipe01_state == NFA_HCI_PIPE_OPENED)
1644e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            {
1645e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                /* First thing is to get the session ID */
1646e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project                nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX);
1647e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            }
1648e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1649e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1650e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        case NFA_HCI_ADM_CLEAR_ALL_PIPE:
1651e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_remove_all_pipes_from_host (0);
1652e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.admin_gate.pipe01_state = NFA_HCI_PIPE_CLOSED;
1653e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.cfg.link_mgmt_gate.pipe00_state = NFA_HCI_PIPE_CLOSED;
1654e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hci_cb.nv_write_needed = TRUE;
1655e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            /* Open admin */
1656e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_open_pipe_cmd (NFA_HCI_ADMIN_PIPE);
1657e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            break;
1658e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1659e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        }
1660e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1661e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1662e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1663e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1664e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1665e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_handle_admin_gate_evt
1666e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1667e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles events received on admin gate
1668e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1669e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
1670e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1671e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1672e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_handle_admin_gate_evt (UINT8 *p_data)
1673e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
16745c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    tNFA_HCI_EVT_DATA           evt_data;
16755c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    tNFA_HCI_API_GET_HOST_LIST  *p_msg;
1676e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1677e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (nfa_hci_cb.inst != NFA_HCI_EVT_HOT_PLUG)
1678e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1679e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        NFA_TRACE_ERROR0 ("nfa_hci_handle_admin_gate_evt - Unknown event on ADMIN Pipe");
1680e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        return;
1681e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1682e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
16835c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    NFA_TRACE_DEBUG0 ("nfa_hci_handle_admin_gate_evt - HOT PLUG EVT event on ADMIN Pipe");
16845c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    nfa_hci_cb.num_hot_plug_evts++;
1685e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
16865c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_NETWK_ENABLE)
16875c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE_NETWK_ENABLE)  )
16885c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    {
16895c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        /* Received Hot Plug evt while waiting for other Host in the network to bootup after DH host bootup is complete */
16905c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        if (  (nfa_hci_cb.ee_disable_disc)
16915c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&(nfa_hci_cb.num_hot_plug_evts == (nfa_hci_cb.num_nfcee - 1))
16925c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&(nfa_hci_cb.num_ee_dis_req_ntf < (nfa_hci_cb.num_nfcee - 1))  )
16935c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        {
16945c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            /* Received expected number of Hot Plug event(s) before as many number of EE DISC REQ Ntf(s) are received */
16955c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            nfa_sys_stop_timer (&nfa_hci_cb.timer);
16965c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            /* Received HOT PLUG EVT(s), now wait some more time for EE DISC REQ Ntf(s) */
16975c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, p_nfa_hci_cfg->hci_netwk_enable_timeout);
16985c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        }
16995c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    }
17005c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    else if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP)
17015c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen             ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE)  )
17025c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    {
17035c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        /* Received Hot Plug evt during DH host bootup */
17045c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        if (  (nfa_hci_cb.ee_disable_disc)
17055c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&(nfa_hci_cb.num_hot_plug_evts == (nfa_hci_cb.num_nfcee - 1))
17065c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            &&(nfa_hci_cb.num_ee_dis_req_ntf < (nfa_hci_cb.num_nfcee - 1))  )
17075c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        {
17085c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            /* Received expected number of Hot Plug event(s) before as many number of EE DISC REQ Ntf(s) are received */
17095c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            nfa_hci_cb.w4_hci_netwk_init = FALSE;
17105c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        }
17115c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    }
17125c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    else
17135c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    {
17145c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        /* Received Hot Plug evt on UICC self reset */
17155c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        evt_data.rcvd_evt.evt_code = nfa_hci_cb.inst;
17165c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        /* Notify all registered application with the HOT_PLUG_EVT */
17175c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        nfa_hciu_send_to_all_apps (NFA_HCI_EVENT_RCVD_EVT, &evt_data);
17185c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen
17195c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        /* Send Get Host List after receiving any pending response */
17205c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        if ((p_msg = (tNFA_HCI_API_GET_HOST_LIST *) GKI_getbuf (sizeof (tNFA_HCI_API_GET_HOST_LIST))) != NULL)
17215c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        {
17225c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            p_msg->hdr.event    = NFA_HCI_API_GET_HOST_LIST_EVT;
17235c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            /* Set Invalid handle to identify this Get Host List command is internal */
17245c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            p_msg->hci_handle   = NFA_HANDLE_INVALID;
17255c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen
17265c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen            nfa_sys_sendmsg (p_msg);
17275c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen        }
17285c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen    }
1729e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project}
1730e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1731e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/*******************************************************************************
1732e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1733e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function         nfa_hci_handle_dyn_pipe_pkt
1734e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1735e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description      This function handles data received via dynamic pipe
1736e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1737e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns          none
1738e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project**
1739e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/
1740e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid nfa_hci_handle_dyn_pipe_pkt (UINT8 pipe_id, UINT8 *p_data, UINT16 data_len)
1741e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{
1742e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_PIPE   *p_pipe = nfa_hciu_find_pipe_by_pid (pipe_id);
1743e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    tNFA_HCI_DYN_GATE   *p_gate;
1744e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1745e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    if (p_pipe == NULL)
1746e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    {
1747e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        /* Invalid pipe ID */
1748e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        NFA_TRACE_ERROR1 ("nfa_hci_handle_dyn_pipe_pkt - Unknown pipe %d",pipe_id);
1749e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        if (nfa_hci_cb.type == NFA_HCI_COMMAND_TYPE)
1750e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project            nfa_hciu_send_msg (pipe_id, NFA_HCI_RESPONSE_TYPE, NFA_HCI_ANY_E_NOK, 0, NULL);
1751e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project        return;
1752e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project    }
1753e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project
1754e9df6ba5a8fcccf306a80b167