Home | History | Annotate | Download | only in nci
      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  *  This file contains function of the NCI unit to format and send NCI
     23  *  commands (for DH).
     24  *
     25  ******************************************************************************/
     26 #include <string.h>
     27 #include "nfc_target.h"
     28 
     29 #if NFC_INCLUDED == TRUE
     30 #include "nci_defs.h"
     31 #include "nci_hmsgs.h"
     32 #include "nfc_api.h"
     33 #include "nfc_int.h"
     34 
     35 /*******************************************************************************
     36 **
     37 ** Function         nci_snd_core_reset
     38 **
     39 ** Description      compose and send CORE RESET command to command queue
     40 **
     41 ** Returns          status
     42 **
     43 *******************************************************************************/
     44 UINT8 nci_snd_core_reset (UINT8 reset_type)
     45 {
     46     BT_HDR *p;
     47     UINT8 *pp;
     48 
     49     if ((p = NCI_GET_CMD_BUF (NCI_CORE_PARAM_SIZE_RESET)) == NULL)
     50         return (NCI_STATUS_FAILED);
     51 
     52     p->event            = BT_EVT_TO_NFC_NCI;
     53     p->len              = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET;
     54     p->offset           = NCI_MSG_OFFSET_SIZE;
     55     p->layer_specific   = 0;
     56     pp                  = (UINT8 *) (p + 1) + p->offset;
     57 
     58     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
     59     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_RESET);
     60     UINT8_TO_STREAM (pp, NCI_CORE_PARAM_SIZE_RESET);
     61     UINT8_TO_STREAM (pp, reset_type);
     62 
     63     nfc_ncif_send_cmd (p);
     64     return (NCI_STATUS_OK);
     65 }
     66 
     67 /*******************************************************************************
     68 **
     69 ** Function         nci_snd_core_init
     70 **
     71 ** Description      compose and send CORE INIT command to command queue
     72 **
     73 ** Returns          status
     74 **
     75 *******************************************************************************/
     76 UINT8 nci_snd_core_init (void)
     77 {
     78     BT_HDR *p;
     79     UINT8 *pp;
     80 
     81     if ((p = NCI_GET_CMD_BUF (NCI_CORE_PARAM_SIZE_INIT)) == NULL)
     82         return (NCI_STATUS_FAILED);
     83 
     84     p->event            = BT_EVT_TO_NFC_NCI;
     85     p->len              = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_INIT;
     86     p->offset           = NCI_MSG_OFFSET_SIZE;
     87     p->layer_specific   = 0;
     88     pp                  = (UINT8 *) (p + 1) + p->offset;
     89 
     90     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
     91     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_INIT);
     92     UINT8_TO_STREAM (pp, NCI_CORE_PARAM_SIZE_INIT);
     93 
     94     nfc_ncif_send_cmd (p);
     95     return (NCI_STATUS_OK);
     96 }
     97 
     98 /*******************************************************************************
     99 **
    100 ** Function         nci_snd_core_get_config
    101 **
    102 ** Description      compose and send CORE GET_CONFIG command to command queue
    103 **
    104 ** Returns          status
    105 **
    106 *******************************************************************************/
    107 UINT8 nci_snd_core_get_config (UINT8 *param_ids, UINT8 num_ids)
    108 {
    109     BT_HDR *p;
    110     UINT8 *pp;
    111 
    112     if ((p = NCI_GET_CMD_BUF (num_ids)) == NULL)
    113         return (NCI_STATUS_FAILED);
    114 
    115     p->event            = BT_EVT_TO_NFC_NCI;
    116     p->len              = NCI_MSG_HDR_SIZE + num_ids + 1;
    117     p->offset           = NCI_MSG_OFFSET_SIZE;
    118     p->layer_specific   = 0;
    119     pp                  = (UINT8 *) (p + 1) + p->offset;
    120 
    121     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
    122     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_GET_CONFIG);
    123     UINT8_TO_STREAM (pp, (UINT8) (num_ids + 1));
    124     UINT8_TO_STREAM (pp, num_ids);
    125     ARRAY_TO_STREAM (pp, param_ids, num_ids);
    126 
    127     nfc_ncif_send_cmd (p);
    128     return (NCI_STATUS_OK);
    129 }
    130 
    131 /*******************************************************************************
    132 **
    133 ** Function         nci_snd_core_set_config
    134 **
    135 ** Description      compose and send CORE SET_CONFIG command to command queue
    136 **
    137 ** Returns          status
    138 **
    139 *******************************************************************************/
    140 UINT8 nci_snd_core_set_config (UINT8 *p_param_tlvs, UINT8 tlv_size)
    141 {
    142     BT_HDR *p;
    143     UINT8 *pp;
    144     UINT8  num = 0, ulen, len, *pt;
    145 
    146     if ((p = NCI_GET_CMD_BUF (tlv_size + 1)) == NULL)
    147         return (NCI_STATUS_FAILED);
    148 
    149     p->event    = BT_EVT_TO_NFC_NCI;
    150     p->len      = NCI_MSG_HDR_SIZE + tlv_size + 1;
    151     p->offset   = NCI_MSG_OFFSET_SIZE;
    152     pp          = (UINT8 *) (p + 1) + p->offset;
    153 
    154     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
    155     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_SET_CONFIG);
    156     UINT8_TO_STREAM (pp, (UINT8) (tlv_size + 1));
    157     len         = tlv_size;
    158     pt          = p_param_tlvs;
    159     while (len > 1)
    160     {
    161         len     -= 2;
    162         pt++;
    163         num++;
    164         ulen     = *pt++;
    165         pt      += ulen;
    166         if (len >= ulen)
    167         {
    168             len -= ulen;
    169         }
    170         else
    171         {
    172             GKI_freebuf (p);
    173             return NCI_STATUS_FAILED;
    174         }
    175     }
    176 
    177     UINT8_TO_STREAM (pp, num);
    178     ARRAY_TO_STREAM (pp, p_param_tlvs, tlv_size);
    179     nfc_ncif_send_cmd (p);
    180 
    181     return (NCI_STATUS_OK);
    182 }
    183 
    184 /*******************************************************************************
    185 **
    186 ** Function         nci_snd_core_conn_create
    187 **
    188 ** Description      compose and send CORE CONN_CREATE command to command queue
    189 **
    190 ** Returns          status
    191 **
    192 *******************************************************************************/
    193 UINT8 nci_snd_core_conn_create (UINT8 dest_type, UINT8 num_tlv, UINT8 tlv_size, UINT8 *p_param_tlvs)
    194 {
    195     BT_HDR *p;
    196     UINT8 *pp;
    197     UINT8 size = NCI_CORE_PARAM_SIZE_CON_CREATE+tlv_size;
    198 
    199     if ((p = NCI_GET_CMD_BUF (size)) == NULL)
    200         return (NCI_STATUS_FAILED);
    201 
    202     p->event            = BT_EVT_TO_NFC_NCI;
    203     p->len              = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_CON_CREATE;
    204     p->offset           = NCI_MSG_OFFSET_SIZE;
    205     p->layer_specific   = 0;
    206     pp                  = (UINT8 *) (p + 1) + p->offset;
    207 
    208     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
    209     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_CONN_CREATE);
    210     UINT8_TO_STREAM (pp, size);
    211     UINT8_TO_STREAM (pp, dest_type);
    212     UINT8_TO_STREAM (pp, num_tlv);
    213     if (tlv_size)
    214     {
    215         ARRAY_TO_STREAM (pp, p_param_tlvs, tlv_size);
    216         p->len         += tlv_size;
    217     }
    218 
    219     nfc_ncif_send_cmd (p);
    220     return (NCI_STATUS_OK);
    221 }
    222 
    223 /*******************************************************************************
    224 **
    225 ** Function         nci_snd_core_conn_close
    226 **
    227 ** Description      compose and send CORE CONN_CLOSE command to command queue
    228 **
    229 ** Returns          status
    230 **
    231 *******************************************************************************/
    232 UINT8 nci_snd_core_conn_close (UINT8 conn_id)
    233 {
    234     BT_HDR *p;
    235     UINT8 *pp;
    236 
    237     if ((p = NCI_GET_CMD_BUF (NCI_CORE_PARAM_SIZE_CON_CLOSE)) == NULL)
    238         return (NCI_STATUS_FAILED);
    239 
    240     p->event            = BT_EVT_TO_NFC_NCI;
    241     p->len              = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_CON_CLOSE;
    242     p->offset           = NCI_MSG_OFFSET_SIZE;
    243     p->layer_specific   = 0;
    244     pp                  = (UINT8 *) (p + 1) + p->offset;
    245 
    246     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
    247     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_CONN_CLOSE);
    248     UINT8_TO_STREAM (pp, NCI_CORE_PARAM_SIZE_CON_CLOSE);
    249     UINT8_TO_STREAM (pp, conn_id);
    250 
    251     nfc_ncif_send_cmd (p);
    252     return (NCI_STATUS_OK);
    253 }
    254 
    255 
    256 #if (NFC_NFCEE_INCLUDED == TRUE)
    257 #if (NFC_RW_ONLY == FALSE)
    258 /*******************************************************************************
    259 **
    260 ** Function         nci_snd_nfcee_discover
    261 **
    262 ** Description      compose and send NFCEE Management NFCEE_DISCOVER command
    263 **                  to command queue
    264 **
    265 ** Returns          status
    266 **
    267 *******************************************************************************/
    268 UINT8 nci_snd_nfcee_discover (UINT8 discover_action)
    269 {
    270     BT_HDR *p;
    271     UINT8 *pp;
    272 
    273     if ((p = NCI_GET_CMD_BUF (NCI_PARAM_SIZE_DISCOVER_NFCEE)) == NULL)
    274         return (NCI_STATUS_FAILED);
    275 
    276     p->event            = BT_EVT_TO_NFC_NCI;
    277     p->len              = NCI_MSG_HDR_SIZE + NCI_PARAM_SIZE_DISCOVER_NFCEE;
    278     p->offset           = NCI_MSG_OFFSET_SIZE;
    279     p->layer_specific   = 0;
    280     pp                  = (UINT8 *) (p + 1) + p->offset;
    281 
    282     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
    283     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_NFCEE_DISCOVER);
    284     UINT8_TO_STREAM (pp, NCI_PARAM_SIZE_DISCOVER_NFCEE);
    285     UINT8_TO_STREAM (pp, discover_action);
    286 
    287     nfc_ncif_send_cmd (p);
    288     return (NCI_STATUS_OK);
    289 }
    290 
    291 /*******************************************************************************
    292 **
    293 ** Function         nci_snd_nfcee_mode_set
    294 **
    295 ** Description      compose and send NFCEE Management NFCEE MODE SET command
    296 **                  to command queue
    297 **
    298 ** Returns          status
    299 **
    300 *******************************************************************************/
    301 UINT8 nci_snd_nfcee_mode_set (UINT8 nfcee_id, UINT8 nfcee_mode)
    302 {
    303     BT_HDR *p;
    304     UINT8 *pp;
    305 
    306     if ((p = NCI_GET_CMD_BUF (NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET)) == NULL)
    307         return (NCI_STATUS_FAILED);
    308 
    309     p->event            = BT_EVT_TO_NFC_NCI;
    310     p->len              = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET;
    311     p->offset           = NCI_MSG_OFFSET_SIZE;
    312     p->layer_specific   = 0;
    313     pp                  = (UINT8 *) (p + 1) + p->offset;
    314 
    315     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
    316     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_NFCEE_MODE_SET);
    317     UINT8_TO_STREAM (pp, NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET);
    318     UINT8_TO_STREAM (pp, nfcee_id);
    319     UINT8_TO_STREAM (pp, nfcee_mode);
    320 
    321     nfc_ncif_send_cmd (p);
    322     return (NCI_STATUS_OK);
    323 }
    324 #endif
    325 #endif
    326 
    327 /*******************************************************************************
    328 **
    329 ** Function         nci_snd_discover_cmd
    330 **
    331 ** Description      compose and send RF Management DISCOVER command to command queue
    332 **
    333 ** Returns          status
    334 **
    335 *******************************************************************************/
    336 UINT8 nci_snd_discover_cmd (UINT8 num, tNCI_DISCOVER_PARAMS *p_param)
    337 {
    338     BT_HDR *p;
    339     UINT8 *pp, *p_size, *p_start;
    340     int xx;
    341     int size;
    342 
    343     size   = num * sizeof (tNCI_DISCOVER_PARAMS) + 1;
    344     if ((p = NCI_GET_CMD_BUF (size)) == NULL)
    345         return (NCI_STATUS_FAILED);
    346 
    347     p->event            = BT_EVT_TO_NFC_NCI;
    348     p->offset           = NCI_MSG_OFFSET_SIZE;
    349     p->layer_specific   = 0;
    350     pp                  = (UINT8 *) (p + 1) + p->offset;
    351 
    352     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    353     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_DISCOVER);
    354     p_size  = pp;
    355     pp++;
    356     p_start = pp;
    357     UINT8_TO_STREAM (pp, num);
    358     for (xx=0; xx<num; xx++)
    359     {
    360         UINT8_TO_STREAM (pp, p_param[xx].type);
    361         UINT8_TO_STREAM (pp, p_param[xx].frequency);
    362     }
    363     *p_size = (UINT8) (pp - p_start);
    364     p->len  = NCI_MSG_HDR_SIZE + *p_size;
    365 
    366     nfc_ncif_send_cmd (p);
    367     return (NCI_STATUS_OK);
    368 }
    369 
    370 /*******************************************************************************
    371 **
    372 ** Function         nci_snd_discover_select_cmd
    373 **
    374 ** Description      compose and send RF Management DISCOVER SELECT command
    375 **                  to command queue
    376 **
    377 ** Returns          status
    378 **
    379 *******************************************************************************/
    380 UINT8 nci_snd_discover_select_cmd (UINT8 rf_disc_id, UINT8 protocol, UINT8 rf_interface)
    381 {
    382     BT_HDR *p;
    383     UINT8 *pp;
    384 
    385     if ((p = NCI_GET_CMD_BUF (NCI_DISCOVER_PARAM_SIZE_SELECT)) == NULL)
    386         return (NCI_STATUS_FAILED);
    387 
    388     p->event            = BT_EVT_TO_NFC_NCI;
    389     p->len              = NCI_MSG_HDR_SIZE + NCI_DISCOVER_PARAM_SIZE_SELECT;
    390     p->offset           = NCI_MSG_OFFSET_SIZE;
    391     p->layer_specific   = 0;
    392     pp                  = (UINT8 *) (p + 1) + p->offset;
    393 
    394     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    395     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_DISCOVER_SELECT);
    396     UINT8_TO_STREAM (pp, NCI_DISCOVER_PARAM_SIZE_SELECT);
    397     UINT8_TO_STREAM (pp, rf_disc_id);
    398     UINT8_TO_STREAM (pp, protocol);
    399     UINT8_TO_STREAM (pp, rf_interface);
    400 
    401     nfc_ncif_send_cmd (p);
    402     return (NCI_STATUS_OK);
    403 }
    404 
    405 /*******************************************************************************
    406 **
    407 ** Function         nci_snd_deactivate_cmd
    408 **
    409 ** Description      compose and send RF Management DEACTIVATE command
    410 **                  to command queue
    411 **
    412 ** Returns          status
    413 **
    414 *******************************************************************************/
    415 UINT8 nci_snd_deactivate_cmd (UINT8 de_act_type )
    416 {
    417     BT_HDR *p;
    418     UINT8 *pp;
    419 
    420     if ((p = NCI_GET_CMD_BUF (NCI_DISCOVER_PARAM_SIZE_DEACT)) == NULL)
    421         return (NCI_STATUS_FAILED);
    422 
    423     p->event            = BT_EVT_TO_NFC_NCI;
    424     p->len              = NCI_MSG_HDR_SIZE + NCI_DISCOVER_PARAM_SIZE_DEACT;
    425     p->offset           = NCI_MSG_OFFSET_SIZE;
    426     p->layer_specific   = 0;
    427     pp                  = (UINT8 *) (p + 1) + p->offset;
    428 
    429     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    430     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_DEACTIVATE);
    431     UINT8_TO_STREAM (pp, NCI_DISCOVER_PARAM_SIZE_DEACT);
    432     UINT8_TO_STREAM (pp, de_act_type);
    433 
    434     nfc_ncif_send_cmd (p);
    435     return (NCI_STATUS_OK);
    436 }
    437 
    438 /*******************************************************************************
    439 **
    440 ** Function         nci_snd_discover_map_cmd
    441 **
    442 ** Description      compose and send RF Management DISCOVER MAP command
    443 **                  to command queue
    444 **
    445 ** Returns          status
    446 **
    447 *******************************************************************************/
    448 UINT8 nci_snd_discover_map_cmd (UINT8 num, tNCI_DISCOVER_MAPS *p_maps)
    449 {
    450     BT_HDR *p;
    451     UINT8 *pp, *p_size, *p_start;
    452     int xx;
    453     int size;
    454 
    455     size = num * sizeof (tNCI_DISCOVER_MAPS) + 1;
    456 
    457     if ((p = NCI_GET_CMD_BUF (size)) == NULL)
    458         return (NCI_STATUS_FAILED);
    459 
    460     p->event            = BT_EVT_TO_NFC_NCI;
    461     p->offset           = NCI_MSG_OFFSET_SIZE;
    462     p->layer_specific   = 0;
    463     pp                  = (UINT8 *) (p + 1) + p->offset;
    464 
    465     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    466     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_DISCOVER_MAP);
    467     p_size  = pp;
    468     pp++;
    469     p_start = pp;
    470     UINT8_TO_STREAM (pp, num);
    471     for (xx = 0; xx < num; xx++)
    472     {
    473         UINT8_TO_STREAM (pp, p_maps[xx].protocol);
    474         UINT8_TO_STREAM (pp, p_maps[xx].mode);
    475         UINT8_TO_STREAM (pp, p_maps[xx].intf_type);
    476     }
    477     *p_size = (UINT8) (pp - p_start);
    478     p->len  = NCI_MSG_HDR_SIZE + *p_size;
    479     nfc_ncif_send_cmd (p);
    480     return (NCI_STATUS_OK);
    481 }
    482 /*******************************************************************************
    483 **
    484 ** Function         nci_snd_t3t_polling
    485 **
    486 ** Description      compose and send RF Management T3T POLLING command
    487 **                  to command queue
    488 **
    489 ** Returns          status
    490 **
    491 *******************************************************************************/
    492 UINT8 nci_snd_t3t_polling (UINT16 system_code, UINT8 rc, UINT8 tsn)
    493 {
    494     BT_HDR *p;
    495     UINT8 *pp;
    496 
    497     if ((p = NCI_GET_CMD_BUF (NCI_RF_PARAM_SIZE_T3T_POLLING)) == NULL)
    498         return (NCI_STATUS_FAILED);
    499 
    500     p->event            = BT_EVT_TO_NFC_NCI;
    501     p->len              = NCI_MSG_HDR_SIZE + NCI_RF_PARAM_SIZE_T3T_POLLING;
    502     p->offset           = NCI_MSG_OFFSET_SIZE;
    503     p->layer_specific   = 0;
    504     pp                  = (UINT8 *) (p + 1) + p->offset;
    505 
    506     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    507     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_T3T_POLLING);
    508     UINT8_TO_STREAM (pp, NCI_RF_PARAM_SIZE_T3T_POLLING);
    509     UINT16_TO_BE_STREAM (pp, system_code);
    510     UINT8_TO_STREAM (pp, rc);
    511     UINT8_TO_STREAM (pp, tsn);
    512 
    513     nfc_ncif_send_cmd (p);
    514     return (NCI_STATUS_OK);
    515 }
    516 
    517 /*******************************************************************************
    518 **
    519 ** Function         nci_snd_parameter_update_cmd
    520 **
    521 ** Description      compose and send RF Management RF Communication Parameter
    522 **                  Update commandto command queue
    523 **
    524 ** Returns          status
    525 **
    526 *******************************************************************************/
    527 UINT8 nci_snd_parameter_update_cmd (UINT8 *p_param_tlvs, UINT8 tlv_size)
    528 {
    529     BT_HDR *p;
    530     UINT8 *pp;
    531     UINT8  num = 0, ulen, len, *pt;
    532 
    533     if ((p = NCI_GET_CMD_BUF (tlv_size + 1)) == NULL)
    534         return (NCI_STATUS_FAILED);
    535 
    536     p->event    = BT_EVT_TO_NFC_NCI;
    537     p->len      = NCI_MSG_HDR_SIZE + tlv_size + 1;
    538     p->offset   = NCI_MSG_OFFSET_SIZE;
    539     pp          = (UINT8 *) (p + 1) + p->offset;
    540 
    541     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    542     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_PARAMETER_UPDATE);
    543     UINT8_TO_STREAM (pp, (UINT8) (tlv_size + 1));
    544     len         = tlv_size;
    545     pt          = p_param_tlvs;
    546     while (len > 1)
    547     {
    548         len     -= 2;
    549         pt++;
    550         num++;
    551         ulen     = *pt++;
    552         pt      += ulen;
    553         if (len >= ulen)
    554         {
    555             len -= ulen;
    556         }
    557         else
    558         {
    559             GKI_freebuf (p);
    560             return NCI_STATUS_FAILED;
    561         }
    562     }
    563 
    564     UINT8_TO_STREAM (pp, num);
    565     ARRAY_TO_STREAM (pp, p_param_tlvs, tlv_size);
    566     nfc_ncif_send_cmd (p);
    567 
    568     return (NCI_STATUS_OK);
    569 }
    570 
    571 #if (NFC_NFCEE_INCLUDED == TRUE)
    572 #if (NFC_RW_ONLY == FALSE)
    573 /*******************************************************************************
    574 **
    575 ** Function         nci_snd_set_routing_cmd
    576 **
    577 ** Description      compose and send RF Management SET_LISTEN_MODE_ROUTING command
    578 **                  to command queue
    579 **
    580 ** Returns          status
    581 **
    582 *******************************************************************************/
    583 UINT8 nci_snd_set_routing_cmd (BOOLEAN more, UINT8 target_handle, UINT8 num_tlv, UINT8 tlv_size, UINT8 *p_param_tlvs)
    584 {
    585     BT_HDR *p;
    586     UINT8 *pp;
    587     UINT8 size = tlv_size + 2;
    588 
    589     if (tlv_size == 0)
    590     {
    591         /* just to terminate routing table
    592          * 2 bytes (more=FALSE and num routing entries=0) */
    593         size = 2;
    594     }
    595 
    596     if ((p = NCI_GET_CMD_BUF(size)) == NULL)
    597         return (NCI_STATUS_FAILED);
    598 
    599     p->event            = BT_EVT_TO_NFC_NCI;
    600     p->offset           = NCI_MSG_OFFSET_SIZE;
    601     p->len              = NCI_MSG_HDR_SIZE + size;
    602     p->layer_specific   = 0;
    603     pp                  = (UINT8 *) (p + 1) + p->offset;
    604 
    605     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    606     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_SET_ROUTING);
    607     UINT8_TO_STREAM (pp, size);
    608     UINT8_TO_STREAM (pp, more);
    609     if (size == 2)
    610     {
    611         UINT8_TO_STREAM (pp, 0);
    612     }
    613     else
    614     {
    615         UINT8_TO_STREAM (pp, num_tlv);
    616         ARRAY_TO_STREAM (pp, p_param_tlvs, tlv_size);
    617     }
    618     nfc_ncif_send_cmd (p);
    619 
    620     return (NCI_STATUS_OK);
    621 }
    622 
    623 /*******************************************************************************
    624 **
    625 ** Function         nci_snd_get_routing_cmd
    626 **
    627 ** Description      compose and send RF Management GET_LISTEN_MODE_ROUTING command
    628 **                  to command queue
    629 **
    630 ** Returns          status
    631 **
    632 *******************************************************************************/
    633 UINT8 nci_snd_get_routing_cmd (void)
    634 {
    635     BT_HDR *p;
    636     UINT8 *pp;
    637     UINT8   param_size = 0;
    638 
    639     if ((p = NCI_GET_CMD_BUF (param_size)) == NULL)
    640         return (NCI_STATUS_FAILED);
    641 
    642     p->event            = BT_EVT_TO_NFC_NCI;
    643     p->len              = NCI_MSG_HDR_SIZE + param_size;
    644     p->offset           = NCI_MSG_OFFSET_SIZE;
    645     p->layer_specific   = 0;
    646     pp                  = (UINT8 *) (p + 1) + p->offset;
    647 
    648     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
    649     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_RF_GET_ROUTING);
    650     UINT8_TO_STREAM (pp, param_size);
    651 
    652     nfc_ncif_send_cmd (p);
    653     return (NCI_STATUS_OK);
    654 }
    655 #endif
    656 #endif
    657 
    658 
    659 #endif /* NFC_INCLUDED == TRUE*/
    660