Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014 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 "sms_debug.h" |
| 30 | #include "csr_inside_api.h" |
| 31 | #include "sme_inside.h" |
| 32 | #include "nan_api.h" |
| 33 | #include "lim_api.h" |
| 34 | #include "cfg_api.h" |
| 35 | |
| 36 | /****************************************************************************** |
| 37 | * Function: sme_nan_register_callback |
| 38 | * |
| 39 | * Description: |
| 40 | * This function gets called when HDD wants register nan rsp callback with |
| 41 | * sme layer. |
| 42 | * |
| 43 | * Args: |
| 44 | * hHal and callback which needs to be registered. |
| 45 | * |
| 46 | * Returns: |
| 47 | * void |
| 48 | *****************************************************************************/ |
| 49 | void sme_nan_register_callback(tHalHandle hHal, NanCallback callback) |
| 50 | { |
| 51 | tpAniSirGlobal pMac = NULL; |
| 52 | |
| 53 | if (NULL == hHal) { |
| 54 | CDF_TRACE(CDF_MODULE_ID_SME, CDF_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_nan_request |
| 64 | * |
| 65 | * Description: |
| 66 | * This function gets called when HDD receives NAN vendor command |
| 67 | * from userspace |
| 68 | * |
| 69 | * Args: |
| 70 | * Nan Request structure ptr |
| 71 | * |
| 72 | * Returns: |
| 73 | * CDF_STATUS |
| 74 | *****************************************************************************/ |
| 75 | CDF_STATUS sme_nan_request(tpNanRequestReq input) |
| 76 | { |
| 77 | cds_msg_t msg; |
| 78 | tpNanRequest data; |
| 79 | size_t data_len; |
| 80 | |
| 81 | data_len = sizeof(tNanRequest) + input->request_data_len; |
| 82 | data = cdf_mem_malloc(data_len); |
| 83 | |
| 84 | if (data == NULL) { |
| 85 | CDF_TRACE(CDF_MODULE_ID_SME, CDF_TRACE_LEVEL_ERROR, |
| 86 | FL("Memory allocation failure")); |
| 87 | return CDF_STATUS_E_NOMEM; |
| 88 | } |
| 89 | |
| 90 | cdf_mem_zero(data, data_len); |
| 91 | data->request_data_len = input->request_data_len; |
| 92 | if (input->request_data_len) { |
| 93 | cdf_mem_copy(data->request_data, |
| 94 | input->request_data, input->request_data_len); |
| 95 | } |
| 96 | |
| 97 | msg.type = WMA_NAN_REQUEST; |
| 98 | msg.reserved = 0; |
| 99 | msg.bodyptr = data; |
| 100 | |
| 101 | if (CDF_STATUS_SUCCESS != cds_mq_post_message(CDF_MODULE_ID_WMA, &msg)) { |
| 102 | CDF_TRACE(CDF_MODULE_ID_SME, CDF_TRACE_LEVEL_ERROR, |
| 103 | FL |
| 104 | ("Not able to post WMA_NAN_REQUEST message to WMA")); |
| 105 | cdf_mem_free(data); |
| 106 | return CDF_STATUS_SUCCESS; |
| 107 | } |
| 108 | |
| 109 | return CDF_STATUS_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | /****************************************************************************** |
| 113 | * Function: sme_nan_event |
| 114 | * |
| 115 | * Description: |
| 116 | * This callback function will be called when SME received eWNI_SME_NAN_EVENT |
| 117 | * event from WMA |
| 118 | * |
| 119 | * Args: |
| 120 | * hHal - HAL handle for device |
| 121 | * pMsg - Message body passed from WMA; includes NAN header |
| 122 | * |
| 123 | * Returns: |
| 124 | * CDF_STATUS |
| 125 | ******************************************************************************/ |
| 126 | CDF_STATUS sme_nan_event(tHalHandle hHal, void *pMsg) |
| 127 | { |
| 128 | tpAniSirGlobal pMac = PMAC_STRUCT(hHal); |
| 129 | CDF_STATUS status = CDF_STATUS_SUCCESS; |
| 130 | |
| 131 | if (NULL == pMsg) { |
| 132 | CDF_TRACE(CDF_MODULE_ID_SME, CDF_TRACE_LEVEL_ERROR, |
| 133 | FL("msg ptr is NULL")); |
| 134 | status = CDF_STATUS_E_FAILURE; |
| 135 | } else { |
| 136 | CDF_TRACE(CDF_MODULE_ID_SME, CDF_TRACE_LEVEL_INFO_MED, |
| 137 | FL("SME: Received sme_nan_event")); |
| 138 | if (pMac->sme.nanCallback) { |
| 139 | pMac->sme.nanCallback(pMac->hHdd, |
| 140 | (tSirNanEvent *) pMsg); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | return status; |
| 145 | } |