nfc_vs.c revision 5c65c3a0f42e174e47fecd4e569606003217ff4e
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/******************************************************************************
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  Copyright (C) 2010-2013 Broadcom Corporation
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  Licensed under the Apache License, Version 2.0 (the "License");
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  you may not use this file except in compliance with the License.
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  You may obtain a copy of the License at:
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  http://www.apache.org/licenses/LICENSE-2.0
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  Unless required by applicable law or agreed to in writing, software
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  distributed under the License is distributed on an "AS IS" BASIS,
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  See the License for the specific language governing permissions and
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  limitations under the License.
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ******************************************************************************/
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/******************************************************************************
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  This file contains functions that NCI vendor specific interface with the
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  NFCC. On the receive side, it routes events to the appropriate handler
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  (callback). On the transmit side, it manages the command transmission.
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ******************************************************************************/
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string.h>
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gki.h"
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "nfc_target.h"
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if (NFC_INCLUDED == TRUE)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "nfc_int.h"
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/****************************************************************************
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)** Declarations
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)****************************************************************************/
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/*******************************************************************************
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)** Function         NFC_RegVSCback
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)** Description      This function is called to register or de-register a callback
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**                  function to receive Proprietary NCI response and notification
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**                  events.
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**                  The maximum number of callback functions allowed is NFC_NUM_VS_CBACKS
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)** Returns          tNFC_STATUS
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)**
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)*******************************************************************************/
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)tNFC_STATUS NFC_RegVSCback (BOOLEAN          is_register,
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                            tNFC_VS_CBACK   *p_cback)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    tNFC_STATUS status = NFC_STATUS_FAILED;
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int i;
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (is_register)
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    {
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        for (i = 0; i < NFC_NUM_VS_CBACKS; i++)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        {
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            /* find an empty spot to hold the callback function */
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            if (nfc_cb.p_vs_cb[i] == NULL)
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            {
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                nfc_cb.p_vs_cb[i]  = p_cback;
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                status             = NFC_STATUS_OK;
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                break;
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            }
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        }
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    else
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    {
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        for (i = 0; i < NFC_NUM_VS_CBACKS; i++)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        {
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            /* 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*******************************************************************************/
102tNFC_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