Satyanarayana Dash | 4ad2ae0 | 2015-04-09 22:25:05 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #include "sme_Api.h" |
| 29 | #include "smsDebug.h" |
| 30 | #include "csrInsideApi.h" |
| 31 | #include "smeInside.h" |
| 32 | #include "limApi.h" |
| 33 | #include "cfgApi.h" |
| 34 | |
| 35 | /****************************************************************************** |
| 36 | * Function: sme_NanRegisterCallback |
| 37 | * |
| 38 | * Description: |
| 39 | * This function gets called when HDD wants register nan rsp callback with |
| 40 | * sme layer. |
| 41 | * |
| 42 | * Args: |
| 43 | * hHal and callback which needs to be registered. |
| 44 | * |
| 45 | * Returns: |
| 46 | * void |
| 47 | *****************************************************************************/ |
| 48 | void sme_NanRegisterCallback(tHalHandle hHal, NanCallback callback) |
| 49 | { |
| 50 | tpAniSirGlobal pMac = NULL; |
| 51 | |
| 52 | if (NULL == hHal) |
| 53 | { |
| 54 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, |
| 55 | FL("hHal is not valid")); |
| 56 | return; |
| 57 | } |
| 58 | pMac = PMAC_STRUCT(hHal); |
| 59 | pMac->sme.nanCallback = callback; |
| 60 | } |
| 61 | |
| 62 | /****************************************************************************** |
| 63 | * Function: sme_NanRequest |
| 64 | * |
| 65 | * Description: |
| 66 | * This function gets called when HDD receives NAN vendor command |
| 67 | * from userspace |
| 68 | * |
| 69 | * Args: |
| 70 | * hHal, Nan Request structure ptr and sessionId |
| 71 | * |
| 72 | * Returns: |
| 73 | * VOS_STATUS |
| 74 | *****************************************************************************/ |
| 75 | VOS_STATUS sme_NanRequest(tHalHandle hHalHandle, tpNanRequestReq input, |
| 76 | tANI_U32 sessionId) |
| 77 | { |
| 78 | tNanRequest *pNanReq = NULL; |
| 79 | size_t data_len; |
| 80 | tSmeCmd *pCommand; |
| 81 | tpAniSirGlobal pMac = PMAC_STRUCT(hHalHandle); |
| 82 | |
| 83 | pCommand = csrGetCommandBuffer(pMac); |
| 84 | if (NULL == pCommand) |
| 85 | { |
| 86 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, |
| 87 | FL("Failed to get command buffer for nan req")); |
| 88 | return eHAL_STATUS_RESOURCES; |
| 89 | } |
| 90 | |
| 91 | data_len = sizeof(tNanRequest) - sizeof(pNanReq->request_data) |
| 92 | + input->request_data_len; |
| 93 | pNanReq = vos_mem_malloc(data_len); |
| 94 | |
| 95 | if (pNanReq == NULL) |
| 96 | { |
| 97 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, |
| 98 | FL("Memory allocation failure, size : %zu"), data_len); |
| 99 | csrReleaseCommand(pMac, pCommand); |
| 100 | return eHAL_STATUS_RESOURCES; |
| 101 | } |
| 102 | |
| 103 | smsLog(pMac, LOG1, "Posting NAN command to csr queue"); |
| 104 | vos_mem_zero(pNanReq, data_len); |
| 105 | pNanReq->request_data_len = input->request_data_len; |
| 106 | vos_mem_copy(pNanReq->request_data, |
| 107 | input->request_data, |
| 108 | input->request_data_len); |
| 109 | |
| 110 | pCommand->command = eSmeCommandNanReq; |
| 111 | pCommand->sessionId = sessionId; |
| 112 | pCommand->u.pNanReq = pNanReq; |
| 113 | |
| 114 | if (!HAL_STATUS_SUCCESS(csrQueueSmeCommand(pMac, pCommand, TRUE))) |
| 115 | { |
| 116 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, |
| 117 | FL("failed to post eSmeCommandNanReq command")); |
| 118 | csrReleaseCommand(pMac, pCommand); |
| 119 | vos_mem_free(pNanReq); |
| 120 | return VOS_STATUS_E_FAILURE; |
| 121 | } |
| 122 | |
| 123 | return VOS_STATUS_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | /****************************************************************************** |
| 127 | * Function: sme_NanEvent |
| 128 | * |
| 129 | * Description: |
| 130 | * This callback function will be called when SME received eWNI_SME_NAN_EVENT |
| 131 | * event from WMA |
| 132 | * |
| 133 | * Args: |
| 134 | * hHal - HAL handle for device |
| 135 | * pMsg - Message body passed from WDA; includes NAN header |
| 136 | * |
| 137 | * Returns: |
| 138 | * VOS_STATUS |
| 139 | ******************************************************************************/ |
| 140 | VOS_STATUS sme_NanEvent(tHalHandle hHal, void* pMsg) |
| 141 | { |
| 142 | tpAniSirGlobal pMac = PMAC_STRUCT(hHal); |
| 143 | VOS_STATUS status = VOS_STATUS_SUCCESS; |
| 144 | |
| 145 | if (NULL == pMsg) |
| 146 | { |
| 147 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, |
| 148 | FL("msg ptr is NULL")); |
| 149 | status = VOS_STATUS_E_FAILURE; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_MED, |
| 154 | FL("SME: Received sme_NanEvent")); |
| 155 | if (pMac->sme.nanCallback) |
| 156 | { |
| 157 | pMac->sme.nanCallback(pMac->hHdd, (tSirNanEvent *)pMsg); |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, |
| 162 | FL("nanCallback is NULL")); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return status; |
| 167 | } |