commit c6d8ca20c2d06a0ff2d0eaf167e61419822a4f9e
parent 26411a02112a2a4389315c3708df9f0d8bcdbba7
Author: Bharatvaj H <bharatvajph@gmail.com>
Date: Thu, 7 Feb 2019 20:18:43 +0000
parent 26411a02112a2a4389315c3708df9f0d8bcdbba7
Author: Bharatvaj H <bharatvajph@gmail.com>
Date: Thu, 7 Feb 2019 20:18:43 +0000
Added discover api to wifi and console
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/forwarder/CMakeLists.txt b/forwarder/CMakeLists.txt @@ -15,3 +15,5 @@ target_link_libraries(forwarder ${COMM_LIBS}) target_link_libraries(forwarder ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(forwarder crossguid) target_link_libraries(forwarder -lbluetooth) +target_link_libraries(forwarder -lmnl) +target_link_libraries(forwarder /usr/local/lib/libwifi-scan.so)
diff --git a/forwarder/forwarder.cpp b/forwarder/forwarder.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) signal(SIGINT, exit_handler); //TODO get all wireless l = new WiFi("enp0s20f0u8"); - r = new Bluetooth(); + r = new Console(); //Wait for the initiators to connect //init and check status @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) return -1; } - r->discover(); + l->discover(); Connector c = Connector(*l, *r); c.setOnPipeCreated([](Network &l, Network &r){
diff --git a/forwarder/include/Console.hpp b/forwarder/include/Console.hpp @@ -2,6 +2,7 @@ #define _Console_H #include <iostream> +#include <vector> #include <Network.hpp> namespace wa { @@ -32,6 +33,10 @@ namespace wa { } return buffer; } + + std::vector<std::string> discover(){ + return std::vector<std::string>(); + } }; } #endif
diff --git a/forwarder/include/WiFi.hpp b/forwarder/include/WiFi.hpp @@ -2,11 +2,14 @@ #define _WIFI_H #include <iostream> +#include <cstdlib> #include <cstring> #include <unistd.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if.h> +#include <wifi_scan.h> + #include <Network.hpp> #include <comm.h> @@ -49,7 +52,20 @@ namespace wa { //TODO std::vector<std::string> discover() override{ - return std::vector<std::string>(); + std::vector<std::string> v; + int status, i; + struct bss_info bss[10]; + struct wifi_scan *wifi = wifi_scan_init("wlan0"); + + status=wifi_scan_all(wifi, bss, 10); + + for(i=0;i<status && i<10;++i) + printf("%s signal %d dBm seen %d ms ago status %s\n", + bss[i].ssid, bss[i].signal_mbm/100, bss[i].seen_ms_ago, + (bss[i].status==BSS_ASSOCIATED ? "associated" : "")); + + wifi_scan_close(wifi); + return v; } //TODO test
: bharatvaj/forwarder