1 /* 2 * Copyright (c) 2018 The Linux Foundation. All rights reserved. 3 * 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: This implementation of init/deint functions for FTM services. 22 */ 23 24 #include <wlan_ftm_ucfg_api.h> 25 #include <wlan_cfg80211_ftm.h> 26 #include "../../core/src/wlan_ftm_svc_i.h" 27 #include <wlan_cmn.h> 28 #include <qdf_module.h> 29 30 QDF_STATUS ucfg_wlan_ftm_testmode_cmd(struct wlan_objmgr_pdev *pdev, 31 uint8_t *data, uint32_t len) 32 { 33 struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj; 34 uint8_t pdev_id; 35 36 ftm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev, 37 WLAN_UMAC_COMP_FTM); 38 if (!ftm_pdev_obj) { 39 ftm_err("Failed to get ftm pdev component"); 40 return QDF_STATUS_E_FAILURE; 41 } 42 43 ftm_pdev_obj->length = 0; 44 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 45 46 return wlan_ftm_cmd_send(pdev, data, len, pdev_id); 47 } 48 49 QDF_STATUS ucfg_wlan_ftm_testmode_rsp(struct wlan_objmgr_pdev *pdev, 50 uint8_t *data) 51 { 52 struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj; 53 uint32_t *len; 54 55 ftm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev, 56 WLAN_UMAC_COMP_FTM); 57 if (!ftm_pdev_obj) { 58 ftm_err("Failed to get ftm pdev component"); 59 return QDF_STATUS_E_FAILURE; 60 } 61 62 if (ftm_pdev_obj->length) { 63 len = (uint32_t *)data; 64 *len = ftm_pdev_obj->length; 65 qdf_mem_copy((data + 4), ftm_pdev_obj->data, 66 ftm_pdev_obj->length); 67 68 ftm_pdev_obj->length = 0; 69 return QDF_STATUS_SUCCESS; 70 } 71 72 return QDF_STATUS_E_FAILURE; 73 } 74 75 QDF_STATUS 76 wlan_ftm_process_utf_event(struct wlan_objmgr_pdev *pdev, 77 uint8_t *event_buf, uint32_t len) 78 { 79 struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj; 80 u_int16_t utf_datalen; 81 uint8_t *utf_data; 82 struct ftm_seg_hdr_info seghdr_info; 83 u_int8_t total_segments, current_seq; 84 85 ftm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev, 86 WLAN_UMAC_COMP_FTM); 87 if (!ftm_pdev_obj) { 88 ftm_err("Failed to get ftm pdev component"); 89 return QDF_STATUS_E_FAILURE; 90 } 91 92 utf_data = event_buf; 93 seghdr_info = *(struct ftm_seg_hdr_info *)(event_buf); 94 ftm_pdev_obj->current_seq = (seghdr_info.segment_info & 0xF); 95 96 current_seq = (seghdr_info.segment_info & 0xF); 97 total_segments = (seghdr_info.segment_info >> 4) & 0xF; 98 99 utf_datalen = len - sizeof(seghdr_info); 100 101 if (current_seq == 0) { 102 ftm_pdev_obj->expected_seq = 0; 103 ftm_pdev_obj->offset = 0; 104 } else { 105 if (ftm_pdev_obj->expected_seq != current_seq) { 106 ftm_debug("seq mismatch exp Seq %d got seq %d\n", 107 ftm_pdev_obj->expected_seq, current_seq); 108 } 109 } 110 111 qdf_mem_copy(&ftm_pdev_obj->data[ftm_pdev_obj->offset], 112 &utf_data[sizeof(seghdr_info)], utf_datalen); 113 114 ftm_pdev_obj->offset = ftm_pdev_obj->offset + utf_datalen; 115 ftm_pdev_obj->expected_seq++; 116 117 if (ftm_pdev_obj->expected_seq == total_segments) { 118 if (ftm_pdev_obj->offset != seghdr_info.len) { 119 ftm_debug("len mismatch len %zu total len %d\n", 120 ftm_pdev_obj->offset, seghdr_info.len); 121 } 122 123 ftm_pdev_obj->length = ftm_pdev_obj->offset; 124 125 /** 126 * If the repsonse is for a command from FTM daemon, 127 * send this repsonse data to cfg80211 128 */ 129 if (ftm_pdev_obj->cmd_type == WIFI_FTM_CMD_NL80211) { 130 if (wlan_cfg80211_ftm_rx_event(pdev, ftm_pdev_obj->data, 131 ftm_pdev_obj->length) != QDF_STATUS_SUCCESS) { 132 return QDF_STATUS_E_FAILURE; 133 } 134 ftm_pdev_obj->cmd_type = WIFI_FTM_CMD_UNKNOWN; 135 } 136 } 137 138 return QDF_STATUS_SUCCESS; 139 } 140