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