Home | History | Annotate | Download | only in nfc
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2014 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 functions that NCI vendor specific interface with the
     23  *  NFCC. On the receive side, it routes events to the appropriate handler
     24  *  (callback). On the transmit side, it manages the command transmission.
     25  *
     26  ******************************************************************************/
     27 #include <string.h>
     28 #include "gki.h"
     29 #include "nfc_target.h"
     30 
     31 #if (NFC_INCLUDED == TRUE)
     32 #include "nfc_int.h"
     33 
     34 /****************************************************************************
     35 ** Declarations
     36 ****************************************************************************/
     37 
     38 
     39 
     40 /*******************************************************************************
     41 **
     42 ** Function         NFC_RegVSCback
     43 **
     44 ** Description      This function is called to register or de-register a callback
     45 **                  function to receive Proprietary NCI response and notification
     46 **                  events.
     47 **                  The maximum number of callback functions allowed is NFC_NUM_VS_CBACKS
     48 **
     49 ** Returns          tNFC_STATUS
     50 **
     51 *******************************************************************************/
     52 tNFC_STATUS NFC_RegVSCback (BOOLEAN          is_register,
     53                             tNFC_VS_CBACK   *p_cback)
     54 {
     55     tNFC_STATUS status = NFC_STATUS_FAILED;
     56     int i;
     57 
     58     if (is_register)
     59     {
     60         for (i = 0; i < NFC_NUM_VS_CBACKS; i++)
     61         {
     62             /* find an empty spot to hold the callback function */
     63             if (nfc_cb.p_vs_cb[i] == NULL)
     64             {
     65                 nfc_cb.p_vs_cb[i]  = p_cback;
     66                 status             = NFC_STATUS_OK;
     67                 break;
     68             }
     69         }
     70     }
     71     else
     72     {
     73         for (i = 0; i < NFC_NUM_VS_CBACKS; i++)
     74         {
     75             /* find the callback to de-register */
     76             if (nfc_cb.p_vs_cb[i] == p_cback)
     77             {
     78                 nfc_cb.p_vs_cb[i]  = NULL;
     79                 status             = NFC_STATUS_OK;
     80                 break;
     81             }
     82         }
     83     }
     84     return status;
     85 }
     86 
     87 
     88 /*******************************************************************************
     89 **
     90 ** Function         NFC_SendVsCommand
     91 **
     92 ** Description      This function is called to send the given vendor specific
     93 **                  command to NFCC. The response from NFCC is reported to the
     94 **                  given tNFC_VS_CBACK as (oid).
     95 **
     96 ** Parameters       oid - The opcode of the VS command.
     97 **                  p_data - The parameters for the VS command
     98 **
     99 ** Returns          tNFC_STATUS
    100 **
    101 *******************************************************************************/
    102 tNFC_STATUS NFC_SendVsCommand (UINT8          oid,
    103                                BT_HDR        *p_data,
    104                                tNFC_VS_CBACK *p_cback)
    105 {
    106     tNFC_STATUS     status = NFC_STATUS_OK;
    107     UINT8           *pp;
    108 
    109     /* Allow VSC with 0-length payload */
    110     if (p_data == NULL)
    111     {
    112         p_data = NCI_GET_CMD_BUF (0);
    113         if (p_data)
    114         {
    115             p_data->offset  = NCI_VSC_MSG_HDR_SIZE;
    116             p_data->len     = 0;
    117         }
    118     }
    119 
    120     /* Validate parameters */
    121     if ((p_data == NULL) || (p_data->offset < NCI_VSC_MSG_HDR_SIZE) || (p_data->len > NCI_MAX_VSC_SIZE))
    122     {
    123         NFC_TRACE_ERROR1 ("buffer offset must be >= %d", NCI_VSC_MSG_HDR_SIZE);
    124         if (p_data)
    125             GKI_freebuf (p_data);
    126         return NFC_STATUS_INVALID_PARAM;
    127     }
    128 
    129     p_data->event           = BT_EVT_TO_NFC_NCI;
    130     p_data->layer_specific  = NFC_WAIT_RSP_VSC;
    131     /* save the callback function in the BT_HDR, to receive the response */
    132     ((tNFC_NCI_VS_MSG *) p_data)->p_cback = p_cback;
    133 
    134     p_data->offset -= NCI_MSG_HDR_SIZE;
    135     pp              = (UINT8 *) (p_data + 1) + p_data->offset;
    136     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_PROP);
    137     NCI_MSG_BLD_HDR1 (pp, oid);
    138     *pp             = (UINT8) p_data->len;
    139     p_data->len    += NCI_MSG_HDR_SIZE;
    140     nfc_ncif_check_cmd_queue (p_data);
    141     return status;
    142 }
    143 
    144 
    145 
    146 
    147 #endif /* NFC_INCLUDED == TRUE */
    148