1 /*
2 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /*
19 * DOC: Implements scan functionality for CM UTF
20 */
21
22 #ifdef FEATURE_CM_UTF_ENABLE
23 #include <wlan_cm_utf.h>
24 #include <qdf_str.h>
25
26 struct wlan_cm_utf_raw_bcn {
27 uint32_t channel_number;
28 int32_t rssi;
29 uint8_t band;
30 uint8_t bssid[QDF_MAC_ADDR_SIZE];
31 uint8_t ssid[WLAN_SSID_MAX_LEN];
32 };
33
wlan_cm_utf_scan_db_update(struct wlan_objmgr_vdev * vdev,void * buffer)34 static void wlan_cm_utf_scan_db_update(struct wlan_objmgr_vdev *vdev,
35 void *buffer)
36 {
37 struct wlan_objmgr_pdev *pdev;
38 struct wlan_cm_utf_raw_bcn *event = NULL;
39 struct mgmt_rx_event_params *rx_param = NULL;
40 struct wlan_objmgr_psoc *psoc;
41 char *buff = (char *)buffer;
42 char *token;
43 uint32_t frame_len = 0;
44 qdf_nbuf_t buf;
45 struct ie_ssid ssid;
46 struct ie_header *ie;
47 struct wlan_frame_hdr *hdr;
48
49 pdev = wlan_vdev_get_pdev(vdev);
50 if (!pdev) {
51 mlme_err("Pdev is Null");
52 return;
53 }
54
55 psoc = wlan_pdev_get_psoc(pdev);
56 if (!psoc) {
57 mlme_err("Psoc is Null");
58 return;
59 }
60
61 while ((token = qdf_str_sep(&buff, "\n")) != NULL) {
62 mlme_err("%s", token);
63 event = qdf_mem_malloc(sizeof(struct wlan_cm_utf_raw_bcn));
64 if (!event) {
65 mlme_err("Failed to allocate event memory");
66 return;
67 }
68 if (sscanf(token,
69 "%2x:%2x:%2x:%2x:%2x:%2x ,%u ,%u ,%u ,%s",
70 (unsigned int *)&event->bssid[0],
71 (unsigned int *)&event->bssid[1],
72 (unsigned int *)&event->bssid[2],
73 (unsigned int *)&event->bssid[3],
74 (unsigned int *)&event->bssid[4],
75 (unsigned int *)&event->bssid[5],
76 &event->channel_number,
77 (unsigned int *)&event->band,
78 &event->rssi,
79 event->ssid) != 10) {
80 goto free_buf;
81 }
82 ssid.ssid_id = 0; //Element id for ssid
83 ssid.ssid_len = strlen(event->ssid);
84 qdf_mem_copy(ssid.ssid, event->ssid, strlen(event->ssid));
85
86 rx_param = qdf_mem_malloc(sizeof(struct mgmt_rx_event_params));
87 if (!rx_param) {
88 mlme_err("Failed to allocate memory");
89 goto free_buf;
90 }
91
92 qdf_mem_zero(rx_param, sizeof(struct mgmt_rx_event_params));
93 rx_param->snr = event->rssi;
94 rx_param->channel = event->channel_number;
95 rx_param->chan_freq = wlan_reg_chan_band_to_freq(
96 pdev,
97 event->channel_number,
98 BIT(event->band));
99
100 rx_param->pdev_id = 0;
101 frame_len = sizeof(struct wlan_frame_hdr) +
102 sizeof(struct wlan_bcn_frame) -
103 sizeof(struct ie_header) +
104 sizeof(struct ie_header) + ssid.ssid_len;
105
106 buf = qdf_nbuf_alloc(NULL, frame_len, 0, 0, FALSE);
107 if (!buf) {
108 mlme_err("Failed to allocate buffer");
109 goto free_buf;
110 }
111
112 qdf_nbuf_set_pktlen(buf, frame_len);
113 qdf_mem_zero((uint8_t *)qdf_nbuf_data(buf), frame_len);
114
115 hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(buf);
116 qdf_mem_copy(hdr->i_addr3, event->bssid, QDF_MAC_ADDR_SIZE);
117 qdf_mem_copy(hdr->i_addr2, event->bssid, QDF_MAC_ADDR_SIZE);
118 ie = (struct ie_header *)(((uint8_t *)qdf_nbuf_data(buf))
119 + sizeof(struct wlan_frame_hdr)
120 + offsetof(struct wlan_bcn_frame, ie));
121
122 qdf_mem_copy(ie, &ssid, sizeof(struct ie_ssid));
123 tgt_scan_bcn_probe_rx_callback(psoc, NULL, buf,
124 rx_param, MGMT_BEACON);
125 free_buf:
126 if (event) {
127 qdf_mem_free(event);
128 event = NULL;
129 }
130 if (rx_param) {
131 qdf_mem_free(rx_param);
132 rx_param = NULL;
133 }
134 }
135 }
136
wlan_cm_utf_scan_db_update_show(qdf_debugfs_file_t m,void * v)137 int wlan_cm_utf_scan_db_update_show(qdf_debugfs_file_t m, void *v)
138 {
139 return 0;
140 }
141
wlan_cm_utf_scan_db_update_write(struct file * file,const char __user * buf,size_t count,loff_t * ppos)142 ssize_t wlan_cm_utf_scan_db_update_write(struct file *file,
143 const char __user *buf,
144 size_t count, loff_t *ppos)
145 {
146 struct wlan_cm_utf *cm_utf =
147 ((struct seq_file *)file->private_data)->private;
148 char *locbuf;
149
150 if ((!buf) || (count <= 0))
151 return -EFAULT;
152
153 locbuf = (char *)qdf_mem_malloc(count);
154
155 if (!locbuf)
156 return -EFAULT;
157
158 qdf_mem_zero(locbuf, count);
159
160 if (copy_from_user(locbuf, buf, count))
161 return -EFAULT;
162
163 wlan_cm_utf_scan_db_update(cm_utf->vdev, locbuf);
164 qdf_mem_free(locbuf);
165 return count;
166 }
167 #endif
168