[7570] wlbt: Fix SWARM warnings in wifi host
[GitHub/LineageOS/android_hardware_samsung_slsi_scsc_wifibt_wifi_hal.git] / wifi_hal.cpp
CommitLineData
7753f181
DD
1#include <errno.h>
2#include <stdint.h>
3#include <fcntl.h>
4#include <sys/socket.h>
5#include <netlink/genl/genl.h>
6#include <netlink/genl/family.h>
7#include <netlink/genl/ctrl.h>
8#include <linux/rtnetlink.h>
9#include <netpacket/packet.h>
10#include <linux/filter.h>
11#include <linux/errqueue.h>
12
13#include <linux/pkt_sched.h>
14#include <netlink/object-api.h>
15#include <netlink/netlink.h>
16#include <netlink/socket.h>
17#include <netlink/attr.h>
18#include <netlink/handlers.h>
19#include <netlink/msg.h>
20
21#include <dirent.h>
22#include <net/if.h>
23
24#include "sync.h"
25
26#define LOG_TAG "WifiHAL"
27
28#include <utils/Log.h>
29
30#include "wifi_hal.h"
31#include "common.h"
32#include "cpp_bindings.h"
33
34
35#define WIFI_HAL_CMD_SOCK_PORT 644
36#define WIFI_HAL_EVENT_SOCK_PORT 645
37
38#define FEATURE_SET 0
39#define FEATURE_SET_MATRIX 1
40#define ATTR_NODFS_VALUE 3
41
42static void internal_event_handler(wifi_handle handle, int events);
43static int internal_no_seq_check(nl_msg *msg, void *arg);
44static int internal_valid_message_handler(nl_msg *msg, void *arg);
45static int wifi_get_multicast_id(wifi_handle handle, const char *name, const char *group);
46static int wifi_add_membership(wifi_handle handle, const char *group);
47static wifi_error wifi_init_interfaces(wifi_handle handle);
48
49typedef enum wifi_attr {
50 ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET,
51 ANDR_WIFI_ATTRIBUTE_FEATURE_SET,
52 ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
53} wifi_attr_t;
54
55/* Initialize/Cleanup */
56
57void wifi_socket_set_local_port(struct nl_sock *sock, uint32_t port)
58{
59 uint32_t pid = getpid() & 0x3FFFFF;
60 nl_socket_set_local_port(sock, pid + (port << 22));
61}
62
63static nl_sock * wifi_create_nl_socket(int port)
64{
65 ALOGI("Creating socket");
66 struct nl_sock *sock = nl_socket_alloc();
67 if (sock == NULL) {
68 ALOGE("Could not create handle");
69 return NULL;
70 }
71
72 wifi_socket_set_local_port(sock, port);
73
de2a8779 74 ALOGI("Connecting socket");
7753f181
DD
75 if (nl_connect(sock, NETLINK_GENERIC)) {
76 ALOGE("Could not connect handle");
77 nl_socket_free(sock);
78 return NULL;
79 }
80
7753f181
DD
81 return sock;
82}
83
d59e4b54 84/* Initialize HAL function pointer table */
7753f181
DD
85wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn)
86{
87 if (fn == NULL) {
88 return WIFI_ERROR_UNKNOWN;
89 }
90 fn->wifi_initialize = wifi_initialize;
91 fn->wifi_cleanup = wifi_cleanup;
92 fn->wifi_event_loop = wifi_event_loop;
93 fn->wifi_get_supported_feature_set = wifi_get_supported_feature_set;
94 fn->wifi_get_concurrency_matrix = wifi_get_concurrency_matrix;
95 fn->wifi_set_scanning_mac_oui = wifi_set_scanning_mac_oui;
96 fn->wifi_get_ifaces = wifi_get_ifaces;
97 fn->wifi_get_iface_name = wifi_get_iface_name;
98 fn->wifi_start_gscan = wifi_start_gscan;
99 fn->wifi_stop_gscan = wifi_stop_gscan;
100 fn->wifi_get_cached_gscan_results = wifi_get_cached_gscan_results;
101 fn->wifi_set_bssid_hotlist = wifi_set_bssid_hotlist;
102 fn->wifi_reset_bssid_hotlist = wifi_reset_bssid_hotlist;
103 fn->wifi_set_significant_change_handler = wifi_set_significant_change_handler;
104 fn->wifi_reset_significant_change_handler = wifi_reset_significant_change_handler;
105 fn->wifi_get_gscan_capabilities = wifi_get_gscan_capabilities;
106 fn->wifi_get_link_stats = wifi_get_link_stats;
107 fn->wifi_get_valid_channels = wifi_get_valid_channels;
108 fn->wifi_rtt_range_request = wifi_rtt_range_request;
109 fn->wifi_rtt_range_cancel = wifi_rtt_range_cancel;
110 fn->wifi_get_rtt_capabilities = wifi_get_rtt_capabilities;
111 fn->wifi_set_nodfs_flag = wifi_set_nodfs_flag;
3c0c6ab1
PG
112 fn->wifi_start_sending_offloaded_packet = wifi_start_sending_offloaded_packet;
113 fn->wifi_stop_sending_offloaded_packet = wifi_stop_sending_offloaded_packet;
7753f181
DD
114 return WIFI_SUCCESS;
115}
116
117wifi_error wifi_initialize(wifi_handle *handle)
118{
119 srand(getpid());
120
121 ALOGI("Initializing wifi");
122 hal_info *info = (hal_info *)malloc(sizeof(hal_info));
123 if (info == NULL) {
124 ALOGE("Could not allocate hal_info");
125 return WIFI_ERROR_UNKNOWN;
126 }
127
128 memset(info, 0, sizeof(*info));
129
130 ALOGI("Creating socket");
131 if (socketpair(AF_UNIX, SOCK_STREAM, 0, info->cleanup_socks) == -1) {
132 ALOGE("Could not create cleanup sockets");
133 free(info);
134 return WIFI_ERROR_UNKNOWN;
135 }
136
137 struct nl_sock *cmd_sock = wifi_create_nl_socket(WIFI_HAL_CMD_SOCK_PORT);
138 if (cmd_sock == NULL) {
139 ALOGE("Could not create handle");
140 free(info);
141 return WIFI_ERROR_UNKNOWN;
142 }
143
144 struct nl_sock *event_sock = wifi_create_nl_socket(WIFI_HAL_EVENT_SOCK_PORT);
145 if (event_sock == NULL) {
146 ALOGE("Could not create handle");
147 nl_socket_free(cmd_sock);
148 free(info);
149 return WIFI_ERROR_UNKNOWN;
150 }
151
152 struct nl_cb *cb = nl_socket_get_cb(event_sock);
153 if (cb == NULL) {
154 ALOGE("Could not create handle");
155 nl_socket_free(cmd_sock);
156 nl_socket_free(event_sock);
157 free(info);
158 return WIFI_ERROR_UNKNOWN;
159 }
160
161// ALOGI("cb->refcnt = %d", cb->cb_refcnt);
162 nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, internal_no_seq_check, info);
163 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, internal_valid_message_handler, info);
164 nl_cb_put(cb);
165
166 info->cmd_sock = cmd_sock;
167 info->event_sock = event_sock;
168 info->clean_up = false;
169 info->in_event_loop = false;
170
171 info->event_cb = (cb_info *)malloc(sizeof(cb_info) * DEFAULT_EVENT_CB_SIZE);
172 info->alloc_event_cb = DEFAULT_EVENT_CB_SIZE;
173 info->num_event_cb = 0;
174
175 info->cmd = (cmd_info *)malloc(sizeof(cmd_info) * DEFAULT_CMD_SIZE);
176 info->alloc_cmd = DEFAULT_CMD_SIZE;
177 info->num_cmd = 0;
178
179 info->nl80211_family_id = genl_ctrl_resolve(cmd_sock, "nl80211");
180 if (info->nl80211_family_id < 0) {
181 ALOGE("Could not resolve nl80211 familty id");
182 nl_socket_free(cmd_sock);
183 nl_socket_free(event_sock);
184 free(info);
185 return WIFI_ERROR_UNKNOWN;
186 }
187
188 pthread_mutex_init(&info->cb_lock, NULL);
189
190 *handle = (wifi_handle) info;
191 ALOGD("wifi_initialize, handle = %p\n", handle);
192 ALOGD("wifi_initialize, *handle = %p\n", *handle);
193 ALOGD("wifi_initialize, info = %p\n", info);
194 ALOGD("wifi_initialize, *info = %pn", *info);
195 wifi_add_membership(*handle, "scan");
196 wifi_add_membership(*handle, "mlme");
197 wifi_add_membership(*handle, "regulatory");
198 wifi_add_membership(*handle, "vendor");
199
200 wifi_init_interfaces(*handle);
201 ALOGD("Found %d interfaces", info->num_interfaces);
202
203
204 ALOGI("Initialized Wifi HAL Successfully; vendor cmd = %d", NL80211_CMD_VENDOR);
205 return WIFI_SUCCESS;
206}
207
208static int wifi_add_membership(wifi_handle handle, const char *group)
209{
210 hal_info *info = getHalInfo(handle);
211
212 int id = wifi_get_multicast_id(handle, "nl80211", group);
213 if (id < 0) {
214 ALOGE("Could not find group %s", group);
215 return id;
216 }
217
218 int ret = nl_socket_add_membership(info->event_sock, id);
219 if (ret < 0) {
220 ALOGE("Could not add membership to group %s", group);
221 }
222
223 ALOGI("Successfully added membership for group %s", group);
224 return ret;
225}
226
227static void internal_cleaned_up_handler(wifi_handle handle)
228{
229 hal_info *info = getHalInfo(handle);
230 wifi_cleaned_up_handler cleaned_up_handler = info->cleaned_up_handler;
231
232 if (info->cmd_sock != 0) {
233 close(info->cleanup_socks[0]);
234 close(info->cleanup_socks[1]);
235 nl_socket_free(info->cmd_sock);
236 nl_socket_free(info->event_sock);
237 info->cmd_sock = NULL;
238 info->event_sock = NULL;
239 }
240
241 (*cleaned_up_handler)(handle);
242 pthread_mutex_destroy(&info->cb_lock);
243 free(info);
244
245 ALOGI("Internal cleanup completed");
246}
247
248void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler)
249{
250 hal_info *info = getHalInfo(handle);
251 char buf[64];
252
253 info->cleaned_up_handler = handler;
254 if (write(info->cleanup_socks[0], "Exit", 4) < 1) {
255 ALOGE("could not write to the cleanup socket");
256 } else {
257 // Listen to the response
258 // Hopefully we dont get errors or get hung up
259 // Not much can be done in that case, but assume that
260 // it has rx'ed the Exit message to exit the thread.
261 // As a fallback set the cleanup flag to TRUE
262 memset(buf, 0, sizeof(buf));
263 int result = read(info->cleanup_socks[0], buf, sizeof(buf));
264 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__, result, errno);
265 if (strncmp(buf, "Done", 4) == 0) {
266 ALOGE("Event processing terminated");
267 } else {
268 ALOGD("Rx'ed %s", buf);
269 }
270 }
271 info->clean_up = true;
272 pthread_mutex_lock(&info->cb_lock);
273
274 int bad_commands = 0;
275
7753f181
DD
276 while (info->num_cmd > bad_commands) {
277 int num_cmd = info->num_cmd;
278 cmd_info *cmdi = &(info->cmd[bad_commands]);
279 WifiCommand *cmd = cmdi->cmd;
280 if (cmd != NULL) {
281 pthread_mutex_unlock(&info->cb_lock);
282 cmd->cancel();
283 pthread_mutex_lock(&info->cb_lock);
284 /* release reference added when command is saved */
285 cmd->releaseRef();
286 if (num_cmd == info->num_cmd) {
287 bad_commands++;
288 }
289 }
290 }
291
292 for (int i = 0; i < info->num_event_cb; i++) {
293 cb_info *cbi = &(info->event_cb[i]);
294 WifiCommand *cmd = (WifiCommand *)cbi->cb_arg;
295 ALOGE("Leaked command %p", cmd);
296 }
297 pthread_mutex_unlock(&info->cb_lock);
298 internal_cleaned_up_handler(handle);
299}
300
301static int internal_pollin_handler(wifi_handle handle)
302{
303 hal_info *info = getHalInfo(handle);
304 ALOGI("even_loop info = %p", info);
305 struct nl_cb *cb = nl_socket_get_cb(info->event_sock);
306 int res = nl_recvmsgs(info->event_sock, cb);
307 ALOGD("nl_recvmsgs returned %d", res);
308 nl_cb_put(cb);
309 return res;
310}
311
312/* Run event handler */
313void wifi_event_loop(wifi_handle handle)
314{
315 hal_info *info = getHalInfo(handle);
316 ALOGI("even_loop info = %p", info);
317 ALOGI("even_loop info = %p", handle);
318 if (info->in_event_loop) {
319 return;
320 } else {
321 info->in_event_loop = true;
322 }
323
324 pollfd pfd[2];
325 memset(&pfd[0], 0, sizeof(pollfd) * 2);
326
327 pfd[0].fd = nl_socket_get_fd(info->event_sock);
328 pfd[0].events = POLLIN;
329 pfd[1].fd = info->cleanup_socks[1];
330 pfd[1].events = POLLIN;
331
332 char buf[2048];
333
334 do {
335 int timeout = -1; /* Infinite timeout */
336 pfd[0].revents = 0;
337 pfd[1].revents = 0;
338 int result = poll(pfd, 2, timeout);
339 if (result < 0) {
340 } else if (pfd[0].revents & POLLERR) {
341 ALOGE("POLL Error; error no = %d", errno);
342 int result2 = read(pfd[0].fd, buf, sizeof(buf));
343 ALOGE("Read after POLL returned %d, error no = %d", result2, errno);
344 } else if (pfd[0].revents & POLLHUP) {
345 ALOGE("Remote side hung up");
346 break;
347 } else if (pfd[0].revents & POLLIN) {
348 internal_pollin_handler(handle);
349 } else if (pfd[1].revents & POLLIN) {
350 memset(buf, 0, sizeof(buf));
351 int result2 = read(pfd[1].fd, buf, sizeof(buf));
352 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__, result2, errno);
353 if (strncmp(buf, "Exit", 4) == 0) {
354 ALOGD("Got a signal to exit!!!");
355 if (write(pfd[1].fd, "Done", 4) < 1) {
356 ALOGE("could not write to the cleanup socket");
357 }
358 break;
359 } else {
360 ALOGD("Rx'ed %s on the cleanup socket\n", buf);
361 }
362 } else {
363 ALOGE("Unknown event - %0x, %0x", pfd[0].revents, pfd[1].revents);
364 }
365 } while (!info->clean_up);
366 ALOGI("Exit %s", __FUNCTION__);
367}
368
369///////////////////////////////////////////////////////////////////////////////////////
370
371static int internal_no_seq_check(struct nl_msg *msg, void *arg)
372{
373 return NL_OK;
374}
375
376static int internal_valid_message_handler(nl_msg *msg, void *arg)
377{
378 wifi_handle handle = (wifi_handle)arg;
379 hal_info *info = getHalInfo(handle);
380 ALOGI("even_loop info = %p", handle);
381 ALOGD("internal_valid_message_handler, info = %p", info);
382
383 WifiEvent event(msg);
384 int res = event.parse();
385 if (res < 0) {
386 ALOGE("Failed to parse event: %d", res);
387 return NL_SKIP;
388 }
389
390 int cmd = event.get_cmd();
391 uint32_t vendor_id = 0;
392 int subcmd = 0;
393
394 if (cmd == NL80211_CMD_VENDOR) {
395 vendor_id = event.get_u32(NL80211_ATTR_VENDOR_ID);
396 subcmd = event.get_u32(NL80211_ATTR_VENDOR_SUBCMD);
397 ALOGI("event received %s, vendor_id = 0x%0x, subcmd = 0x%0x",
398 event.get_cmdString(), vendor_id, subcmd);
399 } else {
400 ALOGI("event received %s", event.get_cmdString());
401 }
402
403 //ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
404 //event.log();
405
7753f181 406 pthread_mutex_lock(&info->cb_lock);
3c0c6ab1 407
7753f181
DD
408 ALOGI("Number of events %d", info->num_event_cb);
409
410 for (int i = 0; i < info->num_event_cb; i++) {
411 if (cmd == info->event_cb[i].nl_cmd) {
412 if (cmd == NL80211_CMD_VENDOR
413 && ((vendor_id != info->event_cb[i].vendor_id)
414 || (subcmd != info->event_cb[i].vendor_subcmd)))
415 {
416 /* event for a different vendor, ignore it */
417 continue;
418 }
419
420 cb_info *cbi = &(info->event_cb[i]);
421 nl_recvmsg_msg_cb_t cb_func = cbi->cb_func;
422 void *cb_arg = cbi->cb_arg;
423 WifiCommand *cmd = (WifiCommand *)cbi->cb_arg;
424 if (cmd != NULL) {
425 cmd->addRef();
426 }
427
428 pthread_mutex_unlock(&info->cb_lock);
429 if (cb_func)
430 (*cb_func)(msg, cb_arg);
431 if (cmd != NULL) {
432 cmd->releaseRef();
433 }
434
435 return NL_OK;
436 }
437 }
438
439 pthread_mutex_unlock(&info->cb_lock);
440 return NL_OK;
441}
442
443///////////////////////////////////////////////////////////////////////////////////////
444
445class GetMulticastIdCommand : public WifiCommand
446{
447private:
448 const char *mName;
449 const char *mGroup;
450 int mId;
451public:
452 GetMulticastIdCommand(wifi_handle handle, const char *name, const char *group)
453 : WifiCommand(handle, 0)
454 {
455 mName = name;
456 mGroup = group;
457 mId = -1;
458 }
459
460 int getId() {
461 return mId;
462 }
463
464 virtual int create() {
465 int nlctrlFamily = genl_ctrl_resolve(mInfo->cmd_sock, "nlctrl");
466 ALOGI("ctrl family = %d", nlctrlFamily);
467 int ret = mMsg.create(nlctrlFamily, CTRL_CMD_GETFAMILY, 0, 0);
468 if (ret < 0) {
469 return ret;
470 }
471 ret = mMsg.put_string(CTRL_ATTR_FAMILY_NAME, mName);
472 return ret;
473 }
474
475 virtual int handleResponse(WifiEvent& reply) {
476
477 ALOGE("handling reponse in %s", __func__);
478
479 struct nlattr **tb = reply.attributes();
7753f181
DD
480 struct nlattr *mcgrp = NULL;
481 int i;
482
483 if (!tb[CTRL_ATTR_MCAST_GROUPS]) {
484 ALOGE("No multicast groups found");
485 return NL_SKIP;
486 } else {
487 ALOGE("Multicast groups attr size = %d", nla_len(tb[CTRL_ATTR_MCAST_GROUPS]));
488 }
489
490 for_each_attr(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
491
492 ALOGE("Processing group");
493 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
494 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, (nlattr *)nla_data(mcgrp),
495 nla_len(mcgrp), NULL);
496 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || !tb2[CTRL_ATTR_MCAST_GRP_ID]) {
497 continue;
498 }
499
500 char *grpName = (char *)nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]);
501 int grpNameLen = nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME]);
502
503 ALOGE("Found group name %s", grpName);
504
505 if (strncmp(grpName, mGroup, grpNameLen) != 0)
506 continue;
507
508 mId = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
509 break;
510 }
511
512 return NL_SKIP;
513 }
514
515};
516
517class SetPnoMacAddrOuiCommand : public WifiCommand {
518
519private:
520 byte *mOui;
521 feature_set *fset;
522 feature_set *feature_matrix;
523 int *fm_size;
524 int set_size_max;
525public:
526 SetPnoMacAddrOuiCommand(wifi_interface_handle handle, oui scan_oui)
527 : WifiCommand(handle, 0)
528 {
529 mOui = scan_oui;
530 }
531
532 int createRequest(WifiRequest& request, int subcmd, byte *scan_oui) {
533 int result = request.create(GOOGLE_OUI, subcmd);
534 if (result < 0) {
535 return result;
536 }
537
538 nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
539 result = request.put(ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI, scan_oui, DOT11_OUI_LEN);
540 if (result < 0) {
541 return result;
542 }
543
544 request.attr_end(data);
545 return WIFI_SUCCESS;
546
547 }
548
549 int start() {
550 ALOGD("Sending mac address OUI");
551 WifiRequest request(familyId(), ifaceId());
552 int result = createRequest(request, SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI, mOui);
553 if (result != WIFI_SUCCESS) {
554 ALOGE("failed to create request; result = %d", result);
555 return result;
556 }
557
558 result = requestResponse(request);
559 if (result != WIFI_SUCCESS) {
560 ALOGE("failed to set scanning mac OUI; result = %d", result);
561 }
562
563 return result;
564 }
565protected:
566 virtual int handleResponse(WifiEvent& reply) {
567 ALOGD("Request complete!");
568 /* Nothing to do on response! */
569 return NL_SKIP;
570 }
571};
572
573class SetNodfsCommand : public WifiCommand {
574
575private:
576 u32 mNoDfs;
577public:
578 SetNodfsCommand(wifi_interface_handle handle, u32 nodfs)
579 : WifiCommand(handle, 0) {
580 mNoDfs = nodfs;
581 }
582 virtual int create() {
583 int ret;
584
585 ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS);
586 if (ret < 0) {
587 ALOGE("Can't create message to send to driver - %d", ret);
588 return ret;
589 }
590
591 nlattr *data = mMsg.attr_start(NL80211_ATTR_VENDOR_DATA);
592 ret = mMsg.put_u32(ATTR_NODFS_VALUE, mNoDfs);
593 if (ret < 0) {
594 return ret;
595 }
596
597 mMsg.attr_end(data);
598 return WIFI_SUCCESS;
599 }
600};
601
602static int wifi_get_multicast_id(wifi_handle handle, const char *name, const char *group)
603{
604 GetMulticastIdCommand cmd(handle, name, group);
605 int res = cmd.requestResponse();
606 if (res < 0)
607 return res;
608 else
609 return cmd.getId();
610}
611
612/////////////////////////////////////////////////////////////////////////
613
614static bool is_wifi_interface(const char *name)
615{
616 if (strncmp(name, "wlan", 4) != 0 && strncmp(name, "p2p", 3) != 0) {
617 /* not a wifi interface; ignore it */
618 return false;
619 } else {
620 return true;
621 }
622}
623
624static int get_interface(const char *name, interface_info *info)
625{
626 strcpy(info->name, name);
627 info->id = if_nametoindex(name);
628 ALOGI("found an interface : %s, id = %d", name, info->id);
629 return WIFI_SUCCESS;
630}
631
632wifi_error wifi_init_interfaces(wifi_handle handle)
633{
634 hal_info *info = (hal_info *)handle;
635 ALOGD("wifi_init_interfaces, info = %p", info);
636
637 struct dirent *de;
638
639 DIR *d = opendir("/sys/class/net");
640 if (d == 0)
641 return WIFI_ERROR_UNKNOWN;
642
643 int n = 0;
644 while ((de = readdir(d))) {
645 if (de->d_name[0] == '.')
646 continue;
647 if (is_wifi_interface(de->d_name) ) {
648 n++;
649 }
650 }
651
652 closedir(d);
653
654 d = opendir("/sys/class/net");
655 if (d == 0)
656 return WIFI_ERROR_UNKNOWN;
657
658 info->interfaces = (interface_info **)malloc(sizeof(interface_info *) * n);
659
660 int i = 0;
661 while ((de = readdir(d))) {
662 if (de->d_name[0] == '.')
663 continue;
664 if (is_wifi_interface(de->d_name)) {
665 interface_info *ifinfo = (interface_info *)malloc(sizeof(interface_info));
666 if (get_interface(de->d_name, ifinfo) != WIFI_SUCCESS) {
667 free(ifinfo);
668 continue;
669 }
670 ifinfo->handle = handle;
671 info->interfaces[i] = ifinfo;
672 i++;
673 }
674 }
675
676 closedir(d);
677
678 info->num_interfaces = n;
679 return WIFI_SUCCESS;
680}
681
682wifi_error wifi_get_ifaces(wifi_handle handle, int *num, wifi_interface_handle **interfaces)
683{
684 hal_info *info = (hal_info *)handle;
685
686 *interfaces = (wifi_interface_handle *)info->interfaces;
687 *num = info->num_interfaces;
688
689 return WIFI_SUCCESS;
690}
691
692wifi_error wifi_get_iface_name(wifi_interface_handle handle, char *name, size_t size)
693{
694 interface_info *info = (interface_info *)handle;
695 strcpy(name, info->name);
696 return WIFI_SUCCESS;
697}
698
699wifi_error wifi_get_supported_feature_set(wifi_interface_handle handle, feature_set *set)
700{
701 return WIFI_ERROR_NOT_SUPPORTED;
702}
703
704wifi_error wifi_get_concurrency_matrix(wifi_interface_handle handle, int set_size_max,
705 feature_set set[], int *set_size)
706{
707 return WIFI_ERROR_NOT_SUPPORTED;
708}
709
710wifi_error wifi_set_scanning_mac_oui(wifi_interface_handle handle, oui scan_oui)
711{
712 SetPnoMacAddrOuiCommand command(handle, scan_oui);
713 return (wifi_error)command.start();
714
715}
716
717wifi_error wifi_set_nodfs_flag(wifi_interface_handle handle, u32 nodfs)
718{
719 SetNodfsCommand command(handle, nodfs);
720 return (wifi_error) command.requestResponse();
721}
722
723/////////////////////////////////////////////////////////////////////////////