Commit 385434e7 authored by Saurabh Verma's avatar Saurabh Verma

wfadatad [WIP]: populate remote wifi data

parent 578cad4e
......@@ -43,8 +43,68 @@ int delm_spawn_getter(struct delm_private *p)
static int delm_func_1(void *priv)
{
//struct delm_private *p = (struct delm_private *)priv;
// Add one more BSS dataelement with some dummy values
struct delm_private *p = (struct delm_private *)priv;
int is_set = 0;
while(!is_set) {
sleep(5);
pthread_mutex_lock(&p->lock);
if(!p->getter_running) {
struct wifi_data_element *dm = p->dm;
struct wifi_network *net = &dm->network;
struct wifi_network_device *dev = &net->device[0];
struct wifi_radio_element *radio = &dev->radiolist[0];
struct wifi_bss_element *bss = &radio->bsslist[0];
//Add one more BSS element
radio->num_bss += 1;
radio = (struct wifi_radio_element *)realloc(radio, (radio->num_bss)*(sizeof(struct wifi_bss_element)));
struct wifi_bss_element *bss1 = &radio->bsslist[1];
memcpy(bss1, bss, sizeof(struct wifi_bss_element));
memcpy(bss1->bssid, bss->bssid, 6);
memcpy(bss1->ssid, bss->ssid, 32);
bss1->enabled = bss->enabled;
bss1->tx_ucast_bytes = bss->tx_ucast_bytes; //100;
bss1->rx_ucast_bytes = bss->rx_ucast_bytes; //200;
bss1->tx_mcast_bytes = bss->tx_mcast_bytes; //300;
bss1->rx_mcast_bytes = bss->rx_mcast_bytes; //400;
bss1->tx_bcast_bytes = bss->tx_bcast_bytes; //500;
bss1->rx_bcast_bytes = bss->rx_bcast_bytes; //600;
bss1->num_stations = 0;
bss1->stalist = NULL;
is_set = 1;
}
pthread_mutex_unlock(&p->lock);
}
return 0;
}
//static int delm_func_2(void *priv, void *remote_net)
static int delm_func_2(void *priv)
{
struct delm_private *p = (struct delm_private *)priv;
struct wifi_data_element *dm = p->dm;
struct wifi_network *net = &dm->network;
struct wifi_network_device *dev = &net->device[0];
struct wifi_network_device *remote_net = (struct wifi_network_device *)dev;
if(remote_net == NULL) {
fprintf(stdout, "Nothing to add on dataelement\n");
return 0;
}
int is_set = 0;
while(!is_set) {
pthread_mutex_lock(&p->lock);
if(!p->getter_running) {
is_set = 1;
}
net->num_devices += 1;
dm = (struct wifi_data_element *)realloc(dm, sizeof(struct wifi_data_element) + (net->num_devices)*(sizeof(struct wifi_network_device)));
// Add remote device data at index = net->num_devices
delm_add_device(remote_net, &net->device[net->num_devices]);
is_set = 1;
pthread_mutex_unlock(&p->lock);
}
return 0;
}
......@@ -120,5 +180,6 @@ struct plugin wfa_delm = {
.exit = delm_exit,
.ops = {
[PLUGIN_FUNC_1] = delm_func_1,
[PLUGIN_FUNC_2] = delm_func_2,
},
};
......@@ -29,6 +29,7 @@ struct delm_private {
DELM_OBJECT_PLACEHOLDER
};
int delm_add_device(struct wifi_network_device *remote_data, struct wifi_network_device *data);
extern int delm_publish_object(struct delm_private *p, const char *objname);
......
......@@ -96,6 +96,73 @@ int delm_get_sta_all(const char *ifname, struct wifi_sta_element **stalist,
return 0;
}
int delm_add_sta_all(struct wifi_sta_element **remote_sta, uint32_t remote_num_stas,
struct wifi_sta_element **stalist, uint32_t *num_stas)
{
#if 0
struct wifi_sta_element *out;
uint8_t stas[768] = {0};
struct wifi_sta s;
int nr = 128;
int ret;
int i;
ret = wifi_get_assoclist(ifname, stas, &nr);
if (ret)
return -1;
if (nr == 0) {
*num_stas = 0;
*stalist = NULL;
return 0;
}
out = calloc(nr, sizeof(struct wifi_sta_element));
if (!out)
return -1;
for (i = 0; i < remote_num_stas; i++) {
uint8_t *sta = &stas[i*6];
struct wifi_sta_element *e = out + i;
memset(&s, 0, sizeof(s));
ret = wifi_get_sta_info(ifname, sta, &s);
if (ret)
continue;
get_timestamp(NULL, e->tsp);
memcpy(e->macaddr, sta, 6);
e->rssi = s.rssi[0];
e->dl_est_thput = s.rx_thput;
e->ul_est_thput = s.tx_thput;
e->conn_time = s.conn_time;
e->tx_bytes = s.stats.tx_bytes;
e->rx_bytes = s.stats.rx_bytes;
e->tx_pkts = s.stats.tx_pkts;
e->rx_pkts = s.stats.rx_pkts;
e->tx_errors = s.stats.tx_fail_pkts;
e->rtx_pkts = s.stats.tx_rtx_pkts;
e->rx_errors = s.stats.rx_fail_pkts;
memcpy(e->caps.ht, s.caps.ht.byte, sizeof(e->caps.ht));
memcpy(e->caps.vht, s.caps.vht.byte, sizeof(e->caps.vht));
memcpy(e->caps.ht, s.caps.ht.byte, sizeof(e->caps.ht));
e->dl_rate = s.rx_rate.rate;
e->ul_rate = s.tx_rate.rate;
e->ul_utilization = s.tx_airtime;
e->dl_utilization = s.rx_airtime;
}
#endif
*num_stas = 0;
*stalist = NULL;
return 0;
}
int delm_get_bss(const char *ifname, struct wifi_bss_element *b)
{
struct wifi_ap_stats ap_stats;
......@@ -136,6 +203,29 @@ int delm_get_bss(const char *ifname, struct wifi_bss_element *b)
return ret;
}
int delm_add_bss(struct wifi_bss_element *remote_bss, struct wifi_bss_element *b)
{
int ret;
//wl_dump_capabilities(&bb, &bss->caps, bss->cbitmap);
memcpy(b->bssid, remote_bss->bssid, 6);
memcpy(b->ssid, remote_bss->ssid, 32);
//b->num_stations = ap.bss.load.sta_count;
get_timestamp(NULL, b->tsp);
b->enabled = remote_bss->enabled;
b->tx_ucast_bytes = remote_bss->tx_ucast_bytes;
b->rx_ucast_bytes = remote_bss->rx_ucast_bytes;
b->tx_mcast_bytes = remote_bss->tx_mcast_bytes;
b->rx_mcast_bytes = remote_bss->rx_mcast_bytes;
b->tx_bcast_bytes = remote_bss->tx_bcast_bytes;
b->rx_bcast_bytes = remote_bss->rx_bcast_bytes;
ret = delm_add_sta_all(&remote_bss->stalist, remote_bss->num_stations, &b->stalist, &b->num_stations);
return ret;
}
int delm_get_scanresults(const char *ifname,
struct wifi_scanres_element **scanlist, uint32_t *num_scanresult)
{
......@@ -268,12 +358,148 @@ int delm_get_scanresults(const char *ifname,
return 0;
}
int delm_add_scanresults(struct wifi_scanres_element **remote_scanlist, uint32_t remote_num_scanresult,
struct wifi_scanres_element **scanlist, uint32_t *num_scanresult)
{
struct wifi_scanres_element *out;
struct wifi_scanres_opclass_element *o;
struct wifi_scanres_neighbor_element *nbr /*, *nbrs */;
struct wifi_opclass supp_opclass[32] = {0};
struct wifi_bss *bss, *bsss;
int num_opclass;
int num = 128;
int idx = 0;
//int ret;
int i, j, k;
bsss = calloc(num, sizeof(struct wifi_bss));
if (!bsss)
return -1;
#if 0
ret = wifi_get_scan_results(ifname, bsss, &num);
if (ret) {
free(bsss);
return -1;
}
ret = wifi_get_supp_opclass(ifname, &num_opclass, supp_opclass);
if (ret) {
free(bsss);
return -1;
}
/* prepare output */
nbrs = calloc(num, sizeof(struct wifi_scanres_neighbor_element));
if (!nbrs) {
free(bsss);
return -1;
}
#endif
out = calloc(1, sizeof(struct wifi_scanres_element));
if (!out) {
free(bsss);
//free(nbrs);
return -1;
}
get_timestamp(NULL, out->tsp);
out->num_opclass_scanned = num_opclass;
out->opclass_scanlist = calloc(out->num_opclass_scanned,
sizeof(struct wifi_scanres_opclass_element));
if (!out->opclass_scanlist) {
out->num_opclass_scanned = 0;
free(bsss);
//free(nbrs);
return -1;
}
for (i = 0; i < out->num_opclass_scanned; i++) {
o = out->opclass_scanlist + i;
if (supp_opclass[i].bw != BW20) {
/* skip non-20Mhz opclass */
o->opclass = supp_opclass[i].g_opclass;
o->num_channels_scanned = 0;
o->channel_scanlist = NULL;
continue;
}
o->opclass = supp_opclass[i].g_opclass;
o->num_channels_scanned = supp_opclass[i].opchannel.num;
o->channel_scanlist = calloc(o->num_channels_scanned,
sizeof(struct wifi_scanres_channel_element));
if (!o->channel_scanlist) {
free(bsss);
//free(nbrs);
o->num_channels_scanned = 0;
return -1;
}
for (k = 0; k < num; k++) {
bss = bsss + k;
for (j = 0; j < o->num_channels_scanned; j++) {
get_timestamp(NULL, o->channel_scanlist[j].tsp);
o->channel_scanlist[j].channel =
supp_opclass[i].opchannel.ch[j];
o->channel_scanlist[j].utilization = 50; //FIXME
o->channel_scanlist[j].anpi = 100; //FIXME
if (bss->channel == supp_opclass[i].opchannel.ch[j]) {
/* add nbr for this channel */
struct wifi_scanres_neighbor_element *new;
new = realloc(o->channel_scanlist[j].nbrlist,
(o->channel_scanlist[j].num_neighbors + 1) * sizeof(*new));
if (!new) {
o->channel_scanlist[j].num_neighbors--;
fprintf(stderr, "realloc scannbr failed!\n");
break;
}
nbr = new + o->channel_scanlist[j].num_neighbors;
//nbr = &nbrs[idx++];
idx++;
memcpy(nbr->bssid, bss->bssid, 6);
memcpy(nbr->ssid, bss->ssid, 32);
nbr->rssi = bss->rssi;
nbr->bw = bss->curr_bw;
nbr->utilization = bss->load.utilization;
nbr->num_stations = bss->load.sta_count;
o->channel_scanlist[j].num_neighbors++;
o->channel_scanlist[j].nbrlist = new;
break;
}
}
}
}
*scanlist = out;
*num_scanresult = remote_num_scanresult;
return 0;
}
int delm_get_bksta(const char *ifname, struct wifi_backhaul_element *bksta)
{
//TODO
return 0;
}
int delm_add_bksta(struct wifi_backhaul_element *remote_bksta, struct wifi_backhaul_element *bksta)
{
memcpy(remote_bksta->macaddr, bksta->macaddr, 6);
return 0;
}
int delm_get_radio(struct wifi_netdev *ifs, const char *ifname,
struct wifi_radio_element *r)
{
......@@ -390,6 +616,67 @@ int delm_get_radio(struct wifi_netdev *ifs, const char *ifname,
return 0;
}
int delm_add_radio(struct wifi_radio_element *remote_radio,
struct wifi_radio_element *r)
{
int i, j;
int ret;
r->enabled = remote_radio->enabled;
r->anpi = remote_radio->anpi;
//TODO: utilization, num_bss
//memcpy(r->macaddr, radio.macaddr, 6); //TODO
/* current opclass */
r->num_curr_opclass = remote_radio->num_curr_opclass;
r->curr_opclass = calloc(r->num_curr_opclass,
sizeof(struct wifi_opclass_current_element));
if (!r->curr_opclass)
return -1;
for (i = 0; i < r->num_curr_opclass; i++) {
get_timestamp(NULL, r->curr_opclass[i].tsp);
r->curr_opclass[i].id = remote_radio->curr_opclass[i].id;
r->curr_opclass[i].channel = remote_radio->curr_opclass[i].channel;
r->curr_opclass[i].txpower = remote_radio->curr_opclass[i].txpower;
}
/* supported opclass */
r->num_supp_opclass = remote_radio->num_supp_opclass;
r->supp_opclass = calloc(r->num_supp_opclass,
sizeof(struct wifi_opclass_supported_element));
if (r->supp_opclass) {
for (i = 0; i < r->num_supp_opclass; i++) {
r->supp_opclass[i].id = remote_radio->supp_opclass[i].id;
r->supp_opclass[i].max_txpower = remote_radio->supp_opclass[i].max_txpower;
r->supp_opclass[i].num_exclude_channels = remote_radio->supp_opclass[i].num_exclude_channels;
strcpy(r->supp_opclass[i].exclude_chanlist, remote_radio->supp_opclass[i].exclude_chanlist);
}
}
/* scan results */ // TO DO
ret = delm_add_scanresults(&remote_radio->scanlist, &remote_radio->num_scanresult, &r->scanlist, &r->num_scanresult);
r->num_bss = remote_radio->num_bss;
r->bsslist = calloc(r->num_bss, sizeof(struct wifi_bss_element));
if (!r->bsslist)
return -1;
for (j = 0; j < r->num_bss; j++) {
ret = delm_add_bss(remote_radio->bsslist + j, r->bsslist + j);
}
/* backhaul sta(s) */
#if 0 /* Only one 'bksta' is supported in the WiFi Data Elements Std. */
for (j = 0; j < num_bk_iface; j++) {
ret = delm_get_bksta(bk_iface[j], r->bkstalist + j);
}
#else
ret = delm_add_bksta(&remote_radio->bksta, &r->bksta);
#endif
return 0;
}
int delm_get_device(struct wifi_netdev *ifs, struct wifi_network_device *dev)
{
int ret = 0;
......@@ -415,6 +702,29 @@ int delm_get_device(struct wifi_netdev *ifs, struct wifi_network_device *dev)
return ret;
}
int delm_add_device(struct wifi_network_device *remote_dev, struct wifi_network_device *dev)
{
int ret = 0;
int i;
if (!remote_dev || !dev)
return -1;
dev->num_radios = remote_dev->num_radios;
dev->radiolist = calloc(dev->num_radios,
sizeof(struct wifi_radio_element));
if (!dev->radiolist)
return -1;
for (i = 0; i < dev->num_radios; i++) {
//ret = delm_get_radio(ifs, ifs[i].radio, dev->radiolist + i);
ret = delm_add_radio(remote_dev->radiolist + i, dev->radiolist + i);
}
return ret;
}
int delm_get_all(struct wifi_netdev *ifs, struct wifi_data_element *dm)
{
return delm_get_device(ifs, &dm->network.device[0]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment