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