Home | History | Annotate | Download | only in ee
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2013 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 
     20 /******************************************************************************
     21  *
     22  *  NFA interface to NFCEE - API functions
     23  *
     24  ******************************************************************************/
     25 #include <string.h>
     26 #include "nfa_ee_api.h"
     27 #include "nfa_ee_int.h"
     28 #include "nfa_sys_int.h"
     29 #include "nfa_dm_int.h"
     30 
     31 /*****************************************************************************
     32 **  APIs
     33 *****************************************************************************/
     34 /*******************************************************************************
     35 **
     36 ** Function         NFA_EeDiscover
     37 **
     38 ** Description      This function retrieves the NFCEE information from NFCC.
     39 **                  The NFCEE information is reported in NFA_EE_DISCOVER_EVT.
     40 **
     41 **                  This function may be called when a system supports removable
     42 **                  NFCEEs,
     43 **
     44 ** Returns          NFA_STATUS_OK if information is retrieved successfully
     45 **                  NFA_STATUS_FAILED If wrong state (retry later)
     46 **                  NFA_STATUS_INVALID_PARAM If bad parameter
     47 **
     48 *******************************************************************************/
     49 tNFA_STATUS NFA_EeDiscover(tNFA_EE_CBACK *p_cback)
     50 {
     51     tNFA_EE_API_DISCOVER *p_msg;
     52     tNFA_STATUS status = NFA_STATUS_FAILED;
     53 
     54     NFA_TRACE_API0 ("NFA_EeDiscover()");
     55 
     56     if (nfa_ee_cb.em_state != NFA_EE_EM_STATE_INIT_DONE)
     57     {
     58         NFA_TRACE_ERROR1 ("NFA_EeDiscover bad em state: %d", nfa_ee_cb.em_state);
     59         status = NFA_STATUS_FAILED;
     60     }
     61     else if ((nfa_ee_cb.p_ee_disc_cback != NULL) || (p_cback == NULL))
     62     {
     63         NFA_TRACE_ERROR0 ("NFA_EeDiscover() in progress or NULL callback function");
     64         status = NFA_STATUS_INVALID_PARAM;
     65     }
     66     else if ((p_msg = (tNFA_EE_API_DISCOVER *) GKI_getbuf (sizeof(tNFA_EE_API_DISCOVER))) != NULL)
     67     {
     68         p_msg->hdr.event    = NFA_EE_API_DISCOVER_EVT;
     69         p_msg->p_cback      = p_cback;
     70 
     71         nfa_sys_sendmsg (p_msg);
     72 
     73         status = NFA_STATUS_OK;
     74     }
     75 
     76     return status;
     77 }
     78 
     79 /*******************************************************************************
     80 **
     81 ** Function         NFA_EeGetInfo
     82 **
     83 ** Description      This function retrieves the NFCEE information from NFA.
     84 **                  The actual number of NFCEE is returned in p_num_nfcee
     85 **                  and NFCEE information is returned in p_info
     86 **
     87 ** Returns          NFA_STATUS_OK if information is retrieved successfully
     88 **                  NFA_STATUS_FAILED If wrong state (retry later)
     89 **                  NFA_STATUS_INVALID_PARAM If bad parameter
     90 **
     91 *******************************************************************************/
     92 tNFA_STATUS NFA_EeGetInfo(UINT8        *p_num_nfcee,
     93                           tNFA_EE_INFO *p_info)
     94 {
     95     int   xx, ret = nfa_ee_cb.cur_ee;
     96     tNFA_EE_ECB  *p_cb = nfa_ee_cb.ecb;
     97     UINT8   max_ret;
     98     UINT8   num_ret  = 0;
     99 
    100     NFA_TRACE_DEBUG2 ("NFA_EeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state, nfa_ee_cb.cur_ee);
    101     /* validate parameters */
    102     if (p_info == NULL || p_num_nfcee == NULL)
    103     {
    104         NFA_TRACE_ERROR0 ("NFA_EeGetInfo bad parameter");
    105         return (NFA_STATUS_INVALID_PARAM);
    106     }
    107     max_ret         = *p_num_nfcee;
    108     *p_num_nfcee = 0;
    109     if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT)
    110     {
    111         NFA_TRACE_ERROR1 ("NFA_EeGetInfo bad em state: %d", nfa_ee_cb.em_state);
    112         return (NFA_STATUS_FAILED);
    113     }
    114 
    115     /* compose output */
    116     for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++)
    117     {
    118         NFA_TRACE_DEBUG4 ("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x", xx, max_ret, num_ret, p_cb->ee_status);
    119         if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) || (p_cb->ee_status == NFA_EE_STATUS_REMOVED))
    120         {
    121             continue;
    122         }
    123         p_info->ee_handle       = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
    124         p_info->ee_status       = p_cb->ee_status;
    125         p_info->num_interface   = p_cb->num_interface;
    126         p_info->num_tlvs        = p_cb->num_tlvs;
    127         memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
    128         memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
    129         p_info++;
    130         num_ret++;
    131     }
    132     NFA_TRACE_DEBUG1 ("num_ret:%d", num_ret);
    133     *p_num_nfcee = num_ret;
    134     return (NFA_STATUS_OK);
    135 }
    136 
    137 /*******************************************************************************
    138 **
    139 ** Function         NFA_EeRegister
    140 **
    141 ** Description      This function registers a callback function to receive the
    142 **                  events from NFA-EE module.
    143 **
    144 ** Returns          NFA_STATUS_OK if successfully initiated
    145 **                  NFA_STATUS_FAILED otherwise
    146 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    147 **
    148 *******************************************************************************/
    149 tNFA_STATUS NFA_EeRegister(tNFA_EE_CBACK *p_cback)
    150 {
    151     tNFA_EE_API_REGISTER *p_msg;
    152     tNFA_STATUS status = NFA_STATUS_FAILED;
    153 
    154     NFA_TRACE_API0 ("NFA_EeRegister()");
    155 
    156     if (p_cback == NULL)
    157     {
    158         NFA_TRACE_ERROR0 ("NFA_EeRegister(): with NULL callback function");
    159         status = NFA_STATUS_INVALID_PARAM;
    160     }
    161     else if ((p_msg = (tNFA_EE_API_REGISTER *) GKI_getbuf (sizeof(tNFA_EE_API_REGISTER))) != NULL)
    162     {
    163         p_msg->hdr.event    = NFA_EE_API_REGISTER_EVT;
    164         p_msg->p_cback      = p_cback;
    165 
    166         nfa_sys_sendmsg (p_msg);
    167 
    168         status = NFA_STATUS_OK;
    169     }
    170 
    171     return status;
    172 }
    173 
    174 /*******************************************************************************
    175 **
    176 ** Function         NFA_EeDeregister
    177 **
    178 ** Description      This function de-registers the callback function
    179 **
    180 ** Returns          NFA_STATUS_OK if successfully initiated
    181 **                  NFA_STATUS_FAILED otherwise
    182 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    183 **
    184 *******************************************************************************/
    185 tNFA_STATUS NFA_EeDeregister(tNFA_EE_CBACK *p_cback)
    186 {
    187     tNFA_EE_API_DEREGISTER *p_msg;
    188     tNFA_STATUS status = NFA_STATUS_INVALID_PARAM;
    189     int         index  = NFA_EE_MAX_CBACKS;
    190     int         xx;
    191 
    192     for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++)
    193     {
    194         if (nfa_ee_cb.p_ee_cback[xx] == p_cback)
    195         {
    196             index   = xx;
    197             status  = NFA_STATUS_FAILED;
    198             break;
    199         }
    200     }
    201 
    202     NFA_TRACE_API2 ("NFA_EeDeregister() %d, status:%d", index, status);
    203     if ((status != NFA_STATUS_INVALID_PARAM) &&
    204         (p_msg = (tNFA_EE_API_DEREGISTER *) GKI_getbuf (sizeof(tNFA_EE_API_DEREGISTER))) != NULL)
    205     {
    206         p_msg->hdr.event = NFA_EE_API_DEREGISTER_EVT;
    207         p_msg->index     = index;
    208 
    209         nfa_sys_sendmsg (p_msg);
    210 
    211         status = NFA_STATUS_OK;
    212     }
    213 
    214     return status;
    215 }
    216 
    217 /*******************************************************************************
    218 **
    219 ** Function         NFA_EeModeSet
    220 **
    221 ** Description      This function is called to activate (mode = NFA_EE_MD_ACTIVATE)
    222 **                  or deactivate (mode = NFA_EE_MD_DEACTIVATE) the NFCEE
    223 **                  identified by the given ee_handle. The result of this
    224 **                  operation is reported with the NFA_EE_MODE_SET_EVT.
    225 **
    226 ** Returns          NFA_STATUS_OK if successfully initiated
    227 **                  NFA_STATUS_FAILED otherwise
    228 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    229 **
    230 *******************************************************************************/
    231 tNFA_STATUS NFA_EeModeSet(tNFA_HANDLE    ee_handle,
    232                           tNFA_EE_MD     mode)
    233 {
    234     tNFA_EE_API_MODE_SET *p_msg;
    235     tNFA_STATUS status = NFA_STATUS_FAILED;
    236     tNFA_EE_ECB *p_cb, *p_found = NULL;
    237     UINT32  xx;
    238     UINT8   nfcee_id = (ee_handle & 0xFF);
    239 
    240     p_cb = nfa_ee_cb.ecb;
    241     for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
    242     {
    243         if (nfcee_id == p_cb->nfcee_id)
    244         {
    245             p_found = p_cb;
    246             break;
    247         }
    248     }
    249     NFA_TRACE_API2 ("NFA_EeModeSet(): handle:<0x%x>, mode:0x%02X", ee_handle, mode);
    250 
    251     if (p_found == NULL)
    252     {
    253         NFA_TRACE_ERROR1 ("NFA_EeModeSet() invalid NFCEE:0x%04x", ee_handle);
    254         status = NFA_STATUS_INVALID_PARAM;
    255     }
    256     else if ((p_msg = (tNFA_EE_API_MODE_SET *) GKI_getbuf (sizeof(tNFA_EE_API_MODE_SET))) != NULL)
    257     {
    258         p_msg->hdr.event        = NFA_EE_API_MODE_SET_EVT;
    259         p_msg->nfcee_id         = nfcee_id;
    260         p_msg->mode             = mode;
    261         p_msg->p_cb             = p_found;
    262 
    263         nfa_sys_sendmsg (p_msg);
    264 
    265         status = NFA_STATUS_OK;
    266     }
    267 
    268 
    269     return status;
    270 }
    271 
    272 
    273 /*******************************************************************************
    274 **
    275 ** Function         NFA_EeSetDefaultTechRouting
    276 **
    277 ** Description      This function is called to add, change or remove the
    278 **                  default routing based on RF technology in the listen mode
    279 **                  routing table for the given ee_handle. The status of this
    280 **                  operation is reported as the NFA_EE_SET_TECH_CFG_EVT.
    281 **
    282 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
    283 **                  should happen before calling this function
    284 **
    285 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE function
    286 **                  to change the listen mode routing is called.
    287 **
    288 ** Returns          NFA_STATUS_OK if successfully initiated
    289 **                  NFA_STATUS_FAILED otherwise
    290 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    291 **
    292 *******************************************************************************/
    293 tNFA_STATUS NFA_EeSetDefaultTechRouting(tNFA_HANDLE          ee_handle,
    294                                         tNFA_TECHNOLOGY_MASK technologies_switch_on,
    295                                         tNFA_TECHNOLOGY_MASK technologies_switch_off,
    296                                         tNFA_TECHNOLOGY_MASK technologies_battery_off)
    297 {
    298     tNFA_EE_API_SET_TECH_CFG *p_msg;
    299     tNFA_STATUS status = NFA_STATUS_FAILED;
    300     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
    301     tNFA_EE_ECB *p_cb;
    302 
    303     NFA_TRACE_API4 ("NFA_EeSetDefaultTechRouting(): handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x>",
    304         ee_handle, technologies_switch_on, technologies_switch_off, technologies_battery_off);
    305     p_cb = nfa_ee_find_ecb (nfcee_id);
    306 
    307     if (p_cb == NULL)
    308     {
    309         NFA_TRACE_ERROR0 ("Bad ee_handle");
    310         status = NFA_STATUS_INVALID_PARAM;
    311     }
    312     else if ((p_msg = (tNFA_EE_API_SET_TECH_CFG *) GKI_getbuf (sizeof(tNFA_EE_API_SET_TECH_CFG))) != NULL)
    313     {
    314         p_msg->hdr.event                = NFA_EE_API_SET_TECH_CFG_EVT;
    315         p_msg->nfcee_id                 = nfcee_id;
    316         p_msg->p_cb                     = p_cb;
    317         p_msg->technologies_switch_on   = technologies_switch_on;
    318         p_msg->technologies_switch_off  = technologies_switch_off;
    319         p_msg->technologies_battery_off = technologies_battery_off;
    320 
    321         nfa_sys_sendmsg (p_msg);
    322 
    323         status = NFA_STATUS_OK;
    324     }
    325 
    326     return status;
    327 }
    328 
    329 /*******************************************************************************
    330 **
    331 ** Function         NFA_EeSetDefaultProtoRouting
    332 **
    333 ** Description      This function is called to add, change or remove the
    334 **                  default routing based on Protocol in the listen mode routing
    335 **                  table for the given ee_handle. The status of this
    336 **                  operation is reported as the NFA_EE_SET_PROTO_CFG_EVT.
    337 **
    338 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
    339 **                  should happen before calling this function
    340 **
    341 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE function
    342 **                  to change the listen mode routing is called.
    343 **
    344 ** Returns          NFA_STATUS_OK if successfully initiated
    345 **                  NFA_STATUS_FAILED otherwise
    346 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    347 **
    348 *******************************************************************************/
    349 tNFA_STATUS NFA_EeSetDefaultProtoRouting(tNFA_HANDLE         ee_handle,
    350                                          tNFA_PROTOCOL_MASK  protocols_switch_on,
    351                                          tNFA_PROTOCOL_MASK  protocols_switch_off,
    352                                          tNFA_PROTOCOL_MASK  protocols_battery_off)
    353 {
    354     tNFA_EE_API_SET_PROTO_CFG *p_msg;
    355     tNFA_STATUS status = NFA_STATUS_FAILED;
    356     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
    357     tNFA_EE_ECB *p_cb;
    358 
    359     NFA_TRACE_API4 ("NFA_EeSetDefaultProtoRouting(): handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x>",
    360         ee_handle, protocols_switch_on, protocols_switch_off, protocols_battery_off);
    361     p_cb = nfa_ee_find_ecb (nfcee_id);
    362 
    363     if (p_cb == NULL)
    364     {
    365         NFA_TRACE_ERROR0 ("Bad ee_handle");
    366         status = NFA_STATUS_INVALID_PARAM;
    367     }
    368     else if ((p_msg = (tNFA_EE_API_SET_PROTO_CFG *) GKI_getbuf (sizeof(tNFA_EE_API_SET_PROTO_CFG))) != NULL)
    369     {
    370         p_msg->hdr.event                = NFA_EE_API_SET_PROTO_CFG_EVT;
    371         p_msg->nfcee_id                 = nfcee_id;
    372         p_msg->p_cb                     = p_cb;
    373         p_msg->protocols_switch_on      = protocols_switch_on;
    374         p_msg->protocols_switch_off     = protocols_switch_off;
    375         p_msg->protocols_battery_off    = protocols_battery_off;
    376 
    377         nfa_sys_sendmsg (p_msg);
    378 
    379         status = NFA_STATUS_OK;
    380     }
    381 
    382     return status;
    383 }
    384 
    385 /*******************************************************************************
    386 **
    387 ** Function         NFA_EeAddAidRouting
    388 **
    389 ** Description      This function is called to add an AID entry in the
    390 **                  listen mode routing table in NFCC. The status of this
    391 **                  operation is reported as the NFA_EE_ADD_AID_EVT.
    392 **
    393 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
    394 **                  should happen before calling this function
    395 **
    396 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE function
    397 **                  to change the listen mode routing is called.
    398 **
    399 ** Returns          NFA_STATUS_OK if successfully initiated
    400 **                  NFA_STATUS_FAILED otherwise
    401 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    402 **
    403 *******************************************************************************/
    404 tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE          ee_handle,
    405                                 UINT8                aid_len,
    406                                 UINT8               *p_aid,
    407                                 tNFA_EE_PWR_STATE    power_state)
    408 {
    409     tNFA_EE_API_ADD_AID *p_msg;
    410     tNFA_STATUS status = NFA_STATUS_FAILED;
    411     UINT16 size = sizeof(tNFA_EE_API_ADD_AID) + aid_len;
    412     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
    413     tNFA_EE_ECB *p_cb;
    414 
    415     NFA_TRACE_API1 ("NFA_EeAddAidRouting(): handle:<0x%x>", ee_handle);
    416     p_cb = nfa_ee_find_ecb (nfcee_id);
    417 
    418     /* validate parameters - make sure the AID is in valid length range */
    419     if ((p_cb == NULL) || (aid_len == 0) || (p_aid == NULL) || (aid_len < NFA_MIN_AID_LEN) || (aid_len > NFA_MAX_AID_LEN))
    420     {
    421         NFA_TRACE_ERROR1 ("Bad ee_handle or AID (len=%d)", aid_len);
    422         status = NFA_STATUS_INVALID_PARAM;
    423     }
    424     else if ((p_msg = (tNFA_EE_API_ADD_AID *) GKI_getbuf (size)) != NULL)
    425     {
    426         NFA_TRACE_DEBUG2 ("aid:<%02x%02x>", p_aid[0], p_aid[1]);
    427         p_msg->hdr.event        = NFA_EE_API_ADD_AID_EVT;
    428         p_msg->nfcee_id         = nfcee_id;
    429         p_msg->p_cb             = p_cb;
    430         p_msg->aid_len          = aid_len;
    431         p_msg->power_state      = power_state;
    432         p_msg->p_aid            = (UINT8 *)(p_msg + 1);
    433         memcpy(p_msg->p_aid, p_aid, aid_len);
    434 
    435         nfa_sys_sendmsg (p_msg);
    436 
    437         status = NFA_STATUS_OK;
    438     }
    439 
    440     return status;
    441 }
    442 
    443 
    444 /*******************************************************************************
    445 **
    446 ** Function         NFA_EeRemoveAidRouting
    447 **
    448 ** Description      This function is called to remove the given AID entry from the
    449 **                  listen mode routing table. If the entry configures VS,
    450 **                  it is also removed. The status of this operation is reported
    451 **                  as the NFA_EE_REMOVE_AID_EVT.
    452 **
    453 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
    454 **                  should happen before calling this function
    455 **
    456 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE function
    457 **                  to change the listen mode routing is called.
    458 **
    459 ** Returns          NFA_STATUS_OK if successfully initiated
    460 **                  NFA_STATUS_FAILED otherwise
    461 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    462 **
    463 *******************************************************************************/
    464 tNFA_STATUS NFA_EeRemoveAidRouting(UINT8     aid_len,
    465                                    UINT8    *p_aid)
    466 {
    467     tNFA_EE_API_REMOVE_AID *p_msg;
    468     tNFA_STATUS status = NFA_STATUS_FAILED;
    469     UINT16 size = sizeof(tNFA_EE_API_REMOVE_AID) + aid_len;
    470 
    471     NFA_TRACE_API0 ("NFA_EeRemoveAidRouting()");
    472     if ((aid_len == 0) || (p_aid == NULL) || (aid_len > NFA_MAX_AID_LEN))
    473     {
    474         NFA_TRACE_ERROR0 ("Bad AID");
    475         status = NFA_STATUS_INVALID_PARAM;
    476     }
    477     else if ((p_msg = (tNFA_EE_API_REMOVE_AID *) GKI_getbuf (size)) != NULL)
    478     {
    479         p_msg->hdr.event        = NFA_EE_API_REMOVE_AID_EVT;
    480         p_msg->aid_len          = aid_len;
    481         p_msg->p_aid            = (UINT8 *)(p_msg + 1);
    482         memcpy(p_msg->p_aid, p_aid, aid_len);
    483 
    484         nfa_sys_sendmsg (p_msg);
    485 
    486         status = NFA_STATUS_OK;
    487     }
    488 
    489     return status;
    490 }
    491 
    492 /*******************************************************************************
    493 **
    494 ** Function         NFA_EeUpdateNow
    495 **
    496 ** Description      This function is called to send the current listen mode
    497 **                  routing table and VS configuration to the NFCC (without waiting
    498 **                  for NFA_EE_ROUT_TIMEOUT_VAL).
    499 **
    500 ** Returns          NFA_STATUS_OK if successfully initiated
    501 **                  NFA_STATUS_FAILED otherwise
    502 **
    503 *******************************************************************************/
    504 tNFA_STATUS NFA_EeUpdateNow(void)
    505 {
    506     BT_HDR *p_msg;
    507     tNFA_STATUS status = NFA_STATUS_FAILED;
    508 
    509     NFA_TRACE_API0 ("NFA_EeUpdateNow()");
    510     if ((p_msg = (BT_HDR *) GKI_getbuf (BT_HDR_SIZE)) != NULL)
    511     {
    512         p_msg->event    = NFA_EE_API_UPDATE_NOW_EVT;
    513 
    514         nfa_sys_sendmsg (p_msg);
    515 
    516         status = NFA_STATUS_OK;
    517     }
    518 
    519     return status;
    520 }
    521 
    522 
    523 /*******************************************************************************
    524 **
    525 ** Function         NFA_EeConnect
    526 **
    527 ** Description      Open connection to an NFCEE attached to the NFCC
    528 **
    529 **                  The status of this operation is
    530 **                  reported with the NFA_EE_CONNECT_EVT.
    531 **
    532 ** Returns          NFA_STATUS_OK if successfully initiated
    533 **                  NFA_STATUS_FAILED otherwise
    534 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    535 **
    536 *******************************************************************************/
    537 tNFA_STATUS NFA_EeConnect(tNFA_HANDLE    ee_handle,
    538                           UINT8          ee_interface,
    539                           tNFA_EE_CBACK *p_cback)
    540 {
    541     tNFA_EE_API_CONNECT *p_msg;
    542     tNFA_STATUS status = NFA_STATUS_FAILED;
    543     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
    544     tNFA_EE_ECB *p_cb;
    545 
    546     NFA_TRACE_API2 ("NFA_EeConnect(): handle:<0x%x> ee_interface:0x%x", ee_handle, ee_interface);
    547     p_cb = nfa_ee_find_ecb (nfcee_id);
    548 
    549     if ((p_cb == NULL) || (p_cback == NULL))
    550     {
    551         NFA_TRACE_ERROR0 ("Bad ee_handle or NULL callback function");
    552         status = NFA_STATUS_INVALID_PARAM;
    553     }
    554     else if ((p_msg = (tNFA_EE_API_CONNECT *) GKI_getbuf (sizeof(tNFA_EE_API_CONNECT))) != NULL)
    555     {
    556         p_msg->hdr.event        = NFA_EE_API_CONNECT_EVT;
    557         p_msg->nfcee_id         = nfcee_id;
    558         p_msg->p_cb             = p_cb;
    559         p_msg->ee_interface     = ee_interface;
    560         p_msg->p_cback          = p_cback;
    561 
    562         nfa_sys_sendmsg (p_msg);
    563 
    564         status = NFA_STATUS_OK;
    565     }
    566 
    567     return status;
    568 }
    569 
    570 /*******************************************************************************
    571 **
    572 ** Function         NFA_EeSendData
    573 **
    574 ** Description      Send data to the given NFCEE.
    575 **                  This function shall be called after NFA_EE_CONNECT_EVT is reported
    576 **                  and before NFA_EeDisconnect is called on the given ee_handle.
    577 **
    578 ** Returns          NFA_STATUS_OK if successfully initiated
    579 **                  NFA_STATUS_FAILED otherwise
    580 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    581 **
    582 *******************************************************************************/
    583 tNFA_STATUS NFA_EeSendData (tNFA_HANDLE  ee_handle,
    584                             UINT16       data_len,
    585                             UINT8       *p_data)
    586 {
    587     tNFA_EE_API_SEND_DATA *p_msg;
    588     tNFA_STATUS status = NFA_STATUS_FAILED;
    589     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
    590     tNFA_EE_ECB *p_cb;
    591 
    592     NFA_TRACE_API1 ("NFA_EeSendData(): handle:<0x%x>", ee_handle);
    593 
    594     p_cb = nfa_ee_find_ecb (nfcee_id);
    595 
    596     if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN) || (p_data == NULL))
    597     {
    598         NFA_TRACE_ERROR0 ("Bad ee_handle or NULL data");
    599         status = NFA_STATUS_INVALID_PARAM;
    600     }
    601     else if ((p_msg = (tNFA_EE_API_SEND_DATA *) GKI_getbuf ((UINT16)(sizeof(tNFA_EE_API_SEND_DATA) + data_len))) != NULL)
    602     {
    603         p_msg->hdr.event        = NFA_EE_API_SEND_DATA_EVT;
    604         p_msg->nfcee_id         = nfcee_id;
    605         p_msg->p_cb             = p_cb;
    606         p_msg->data_len         = data_len;
    607         p_msg->p_data           = (UINT8 *)(p_msg + 1);
    608         memcpy(p_msg->p_data, p_data, data_len);
    609 
    610         nfa_sys_sendmsg (p_msg);
    611 
    612         status = NFA_STATUS_OK;
    613     }
    614 
    615     return status;
    616 }
    617 
    618 /*******************************************************************************
    619 **
    620 ** Function         NFA_EeDisconnect
    621 **
    622 ** Description      Disconnect (if a connection is currently open) from an
    623 **                  NFCEE interface. The result of this operation is reported
    624 **                  with the NFA_EE_DISCONNECT_EVT.
    625 **
    626 ** Returns          NFA_STATUS_OK if successfully initiated
    627 **                  NFA_STATUS_FAILED otherwise
    628 **                  NFA_STATUS_INVALID_PARAM If bad parameter
    629 **
    630 *******************************************************************************/
    631 tNFA_STATUS NFA_EeDisconnect(tNFA_HANDLE ee_handle)
    632 {
    633     tNFA_EE_API_DISCONNECT *p_msg;
    634     tNFA_STATUS status = NFA_STATUS_FAILED;
    635     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
    636     tNFA_EE_ECB *p_cb;
    637 
    638     NFA_TRACE_API1 ("NFA_EeDisconnect(): handle:<0x%x>", ee_handle);
    639     p_cb = nfa_ee_find_ecb (nfcee_id);
    640 
    641     if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN))
    642     {
    643         NFA_TRACE_ERROR0 ("NFA_EeDisconnect() Bad ee_handle");
    644         status = NFA_STATUS_INVALID_PARAM;
    645     }
    646     else if ((p_msg = (tNFA_EE_API_DISCONNECT *) GKI_getbuf (sizeof(tNFA_EE_API_DISCONNECT))) != NULL)
    647     {
    648         p_msg->hdr.event        = NFA_EE_API_DISCONNECT_EVT;
    649         p_msg->nfcee_id         = nfcee_id;
    650         p_msg->p_cb             = p_cb;
    651 
    652         nfa_sys_sendmsg (p_msg);
    653 
    654         status = NFA_STATUS_OK;
    655     }
    656 
    657     return status;
    658 }
    659