mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
get rssi from iwinfo lib
This commit is contained in:
parent
eadbaa2765
commit
38052e76fb
5 changed files with 44 additions and 73 deletions
|
@ -42,7 +42,7 @@ SET(SOURCES
|
||||||
utils/utils.c include/rssi.h utils/rssi.c)
|
utils/utils.c include/rssi.h utils/rssi.c)
|
||||||
|
|
||||||
SET(LIBS
|
SET(LIBS
|
||||||
ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto)
|
ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto iwinfo)
|
||||||
|
|
||||||
ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h)
|
ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h)
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
int get_rssi_from_iwinfo(__uint8_t *client_addr);
|
int get_rssi_iwinfo(__uint8_t *client_addr);
|
||||||
|
|
||||||
int get_rssi_iwinfo();
|
|
||||||
|
|
||||||
#endif //DAWN_RSSI_H
|
#endif //DAWN_RSSI_H
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "networksocket.h"
|
#include "networksocket.h"
|
||||||
#include "ubus.h"
|
#include "ubus.h"
|
||||||
#include "dawn_uci.h"
|
#include "dawn_uci.h"
|
||||||
|
#include "rssi.h"
|
||||||
|
|
||||||
#define BUFSIZE 17
|
#define BUFSIZE 17
|
||||||
#define BUFSIZE_DIR 256
|
#define BUFSIZE_DIR 256
|
||||||
|
@ -124,8 +125,6 @@ void free(void *p)
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
//free_counter = 0;
|
//free_counter = 0;
|
||||||
|
|
||||||
get_rssi_iwinfo();
|
|
||||||
|
|
||||||
const char *ubus_socket = NULL;
|
const char *ubus_socket = NULL;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
|
|
|
@ -138,11 +138,13 @@ void kick_clients(uint8_t bssid[], uint32_t id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update rssi
|
// update rssi
|
||||||
int rssi = get_rssi_from_iwinfo(client_array[j].client_addr);
|
int rssi = get_rssi_iwinfo(client_array[j].client_addr);
|
||||||
if (rssi != INT_MIN) {
|
if (rssi != INT_MIN) {
|
||||||
pthread_mutex_unlock(&probe_array_mutex);
|
pthread_mutex_unlock(&probe_array_mutex);
|
||||||
if (!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) {
|
if (!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) {
|
||||||
printf("Failed to update RSSI!\n");
|
printf("Failed to update RSSI!\n");
|
||||||
|
} else {
|
||||||
|
printf("RSSI UPDATED: RSSI: %d\n\n", rssi);
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&probe_array_mutex);
|
pthread_mutex_lock(&probe_array_mutex);
|
||||||
|
|
||||||
|
|
103
src/utils/rssi.c
103
src/utils/rssi.c
|
@ -1,8 +1,11 @@
|
||||||
#include "rssi.h"
|
#include "rssi.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <iwinfo.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "ubus.h"
|
||||||
|
|
||||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||||
|
|
||||||
|
@ -10,92 +13,60 @@ int call_iwinfo(char *client_addr);
|
||||||
|
|
||||||
int parse_rssi(char *iwinfo_string);
|
int parse_rssi(char *iwinfo_string);
|
||||||
|
|
||||||
|
int get_rssi(const char *ifname, uint8_t *client_addr);
|
||||||
|
|
||||||
#define IWINFO_BUFSIZE 24 * 1024
|
#define IWINFO_BUFSIZE 24 * 1024
|
||||||
|
|
||||||
int get_rssi_iwinfo()
|
int get_rssi_iwinfo(__uint8_t *client_addr) {
|
||||||
{
|
|
||||||
|
DIR *dirp;
|
||||||
|
struct dirent *entry;
|
||||||
|
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||||
|
if (!dirp) {
|
||||||
|
fprintf(stderr, "No hostapd sockets!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rssi = INT_MIN;
|
||||||
|
|
||||||
|
while ((entry = readdir(dirp)) != NULL) {
|
||||||
|
if (entry->d_type == DT_SOCK) {
|
||||||
|
rssi = get_rssi(entry->d_name, client_addr);
|
||||||
|
if(rssi != INT_MIN)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dirp);
|
||||||
|
return rssi;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_rssi(const char *ifname, uint8_t *client_addr){
|
||||||
|
|
||||||
int i, len;
|
int i, len;
|
||||||
char buf[IWINFO_BUFSIZE];
|
char buf[IWINFO_BUFSIZE];
|
||||||
struct iwinfo_assoclist_entry *e;
|
struct iwinfo_assoclist_entry *e;
|
||||||
|
const struct iwinfo_ops *iw;
|
||||||
|
|
||||||
const struct iwinfo_ops *iw = NULL;
|
iw = iwinfo_backend(ifname);
|
||||||
iw = iwinfo_backend("wlan0");
|
|
||||||
|
|
||||||
if (iw->assoclist(ifname, buf, &len))
|
if (iw->assoclist(ifname, buf, &len))
|
||||||
{
|
{
|
||||||
printf("No information available\n");
|
printf("No information available\n");
|
||||||
return;
|
return INT_MIN;
|
||||||
}
|
}
|
||||||
else if (len <= 0)
|
else if (len <= 0)
|
||||||
{
|
{
|
||||||
printf("No station connected\n");
|
printf("No station connected\n");
|
||||||
return;
|
return INT_MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
|
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
|
||||||
{
|
{
|
||||||
e = (struct iwinfo_assoclist_entry *) &buf[i];
|
e = (struct iwinfo_assoclist_entry *) &buf[i];
|
||||||
|
|
||||||
printf("iwinfo rssi: %d\n", e->signal);
|
if(mac_is_equal(client_addr, e->mac))
|
||||||
}
|
return e->signal;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int get_rssi_from_iwinfo(__uint8_t *client_addr) {
|
|
||||||
char mac_buf[20];
|
|
||||||
sprintf(mac_buf, MACSTR, MAC2STR(client_addr));
|
|
||||||
char mac_buf_conv[20];
|
|
||||||
|
|
||||||
convert_mac(mac_buf, mac_buf_conv);
|
|
||||||
|
|
||||||
return call_iwinfo(mac_buf_conv);
|
|
||||||
}
|
|
||||||
|
|
||||||
int call_iwinfo(char *client_addr) {
|
|
||||||
// TODO: REFACTOR THIS! USE NET LINK... LOOK AT IWINFO
|
|
||||||
|
|
||||||
FILE *fp;
|
|
||||||
char path[1035];
|
|
||||||
|
|
||||||
int rssi = INT_MIN;
|
|
||||||
int command_length = 68;
|
|
||||||
char iwinfo_command[command_length];
|
|
||||||
char *first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep ";
|
|
||||||
size_t length_first_command = strlen(first_command);
|
|
||||||
memcpy(iwinfo_command, first_command, length_first_command);
|
|
||||||
memcpy(iwinfo_command + length_first_command, client_addr, strlen(client_addr));
|
|
||||||
iwinfo_command[command_length - 1] = '\0';
|
|
||||||
printf("iwinfo command:\n%s\n", iwinfo_command);
|
|
||||||
|
|
||||||
fp = popen(iwinfo_command, "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
printf("Failed to run command\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the output a line at a time - output it. */
|
return INT_MIN;
|
||||||
while (fgets(path, sizeof(path) - 1, fp) != NULL) {
|
|
||||||
rssi = parse_rssi(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* close */
|
|
||||||
pclose(fp);
|
|
||||||
|
|
||||||
return rssi;
|
|
||||||
}
|
|
||||||
|
|
||||||
int parse_rssi(char *iwinfo_string) {
|
|
||||||
char cut_1[] = " ";
|
|
||||||
char cut_2[] = "dBm";
|
|
||||||
char *p_1 = strstr(iwinfo_string, cut_1);
|
|
||||||
char *p_2 = strstr(iwinfo_string, cut_2);
|
|
||||||
int rssi = INT_MIN;
|
|
||||||
if (p_1 != NULL && p_2 != NULL) {
|
|
||||||
int length = (int) (p_2 - p_1);
|
|
||||||
char dest[length + 1];
|
|
||||||
memcpy(dest, p_1, (int) (p_2 - p_1));
|
|
||||||
dest[length] = '\0';
|
|
||||||
rssi = atoi(dest);
|
|
||||||
}
|
|
||||||
return rssi;
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue